Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-02 04:38:16

0001 #ifndef CONDCORE_RUNINFOPLUGINS_RUNINFOPAYLOADINSPECTORHELPER_H
0002 #define CONDCORE_RUNINFOPLUGINS_RUNINFOPAYLOADINSPECTORHELPER_H
0003 
0004 #include <vector>
0005 #include <string>
0006 #include <ctime>
0007 #include "TH1.h"
0008 #include "TH2.h"
0009 #include "TStyle.h"
0010 #include "TPaveText.h"
0011 #include "TStyle.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 // for the FED intervals
0015 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0016 
0017 #define MK_P(a, b) std::make_pair(a, b)
0018 
0019 namespace RunInfoPI {
0020 
0021   enum state { k_fake = 0, k_valid = 1, k_invalid = 2 };
0022 
0023   // values are taken from https://github.com/cms-sw/cmssw/blob/master/MagneticField/GeomBuilder/plugins/VolumeBasedMagneticFieldESProducerFromDB.cc#L74-L75
0024   constexpr std::array<int, 7> nominalCurrents{{-1, 0, 9558, 14416, 16819, 18268, 19262}};
0025   constexpr std::array<float, 7> nominalFields{{3.8, 0., 2., 3., 3.5, 3.8, 4.}};
0026 
0027   // all parameter than can be displayed
0028   enum parameters {
0029     m_run,                   // int
0030     m_start_time_ll,         // long long;
0031     m_stop_time_ll,          // long long
0032     m_start_current,         // float
0033     m_stop_current,          // float
0034     m_avg_current,           // float
0035     m_max_current,           // float
0036     m_min_current,           // float
0037     m_run_interval_seconds,  // float
0038     m_fedIN,                 // unsigned int
0039     m_BField,                // float
0040     END_OF_TYPES
0041   };
0042 
0043   /************************************************/
0044   inline float theBField(const float current) {
0045     // logic is taken from https://github.com/cms-sw/cmssw/blob/master/MagneticField/GeomBuilder/plugins/VolumeBasedMagneticFieldESProducerFromDB.cc#L156
0046 
0047     int i = 0;
0048     for (; i < (int)nominalFields.size() - 1; i++) {
0049       if (2 * current < nominalCurrents[i] + nominalCurrents[i + 1]) {
0050         return nominalFields[i];
0051       }
0052     }
0053     return nominalFields[i];
0054   }
0055 
0056   /************************************************/
0057   inline float runDuration(const std::shared_ptr<RunInfo>& payload) {
0058     // calculation of the run duration in seconds
0059     time_t start_time = payload->m_start_time_ll;
0060     ctime(&start_time);
0061     time_t end_time = payload->m_stop_time_ll;
0062     ctime(&end_time);
0063     return difftime(end_time, start_time) / 1.0e+6;
0064   }
0065 
0066   /************************************************/
0067   inline std::string runStartTime(const std::shared_ptr<RunInfo>& payload) {
0068     const time_t start_time = payload->m_start_time_ll / 1.0e+6;
0069     return std::asctime(std::gmtime(&start_time));
0070   }
0071 
0072   /************************************************/
0073   inline std::string runEndTime(const std::shared_ptr<RunInfo>& payload) {
0074     const time_t end_time = payload->m_stop_time_ll / 1.0e+6;
0075     return std::asctime(std::gmtime(&end_time));
0076   }
0077 
0078   /************************************************/
0079   inline std::string getStringFromTypeEnum(const parameters& parameter) {
0080     switch (parameter) {
0081       case m_run:
0082         return "run number";
0083       case m_start_time_ll:
0084         return "start time";
0085       case m_stop_time_ll:
0086         return "stop time";
0087       case m_start_current:
0088         return "start current [A]";
0089       case m_stop_current:
0090         return "stop current [A]";
0091       case m_avg_current:
0092         return "average current [A]";
0093       case m_max_current:
0094         return "max current [A]";
0095       case m_min_current:
0096         return "min current [A]";
0097       case m_run_interval_seconds:
0098         return "run duration [s]";
0099       case m_fedIN:
0100         return "n. FEDs";
0101       case m_BField:
0102         return "B-field intensity [T]";
0103       default:
0104         return "should never be here";
0105     }
0106   }
0107 
0108   /************************************************/
0109   inline void reportSummaryMapPalette(TH2* obj) {
0110     static int pcol[20];
0111 
0112     float rgb[20][3];
0113 
0114     for (int i = 0; i < 20; i++) {
0115       if (i < 17) {
0116         rgb[i][0] = 0.80 + 0.01 * i;
0117         rgb[i][1] = 0.00 + 0.03 * i;
0118         rgb[i][2] = 0.00;
0119       } else if (i < 19) {
0120         rgb[i][0] = 0.80 + 0.01 * i;
0121         rgb[i][1] = 0.00 + 0.03 * i + 0.15 + 0.10 * (i - 17);
0122         rgb[i][2] = 0.00;
0123       } else if (i == 19) {
0124         rgb[i][0] = 0.00;
0125         rgb[i][1] = 0.80;
0126         rgb[i][2] = 0.00;
0127       }
0128       pcol[i] = TColor::GetColor(rgb[i][0], rgb[i][1], rgb[i][2]);
0129     }
0130 
0131     gStyle->SetPalette(20, pcol);
0132 
0133     if (obj) {
0134       obj->SetMinimum(-1.e-15);
0135       obj->SetMaximum(+1.0);
0136       obj->SetOption("colz");
0137     }
0138   }
0139 
0140   // FED bounds
0141   enum DET {
0142     SIPIXEL,
0143     SISTRIP,
0144     PRESHOWER,
0145     TOTEMRP_H,
0146     CTPPSDIAMOND,
0147     TOTEMRP_V,
0148     TOTEMRP_T,
0149     ECAL,
0150     CASTOR,
0151     HCAL,
0152     CSC,
0153     RPC,
0154     HCALPHASE1,
0155     SIPIXELPHASE1,
0156     GEM
0157   };
0158 
0159   using FEDMAP_T = std::map<RunInfoPI::DET, std::pair<int, int> >;
0160 
0161   inline FEDMAP_T buildFEDBounds() {
0162     static RunInfoPI::FEDMAP_T fb;
0163     fb.insert(MK_P(SIPIXEL, MK_P(FEDNumbering::MINSiPixelFEDID, FEDNumbering::MAXSiPixelFEDID)));
0164     fb.insert(MK_P(SISTRIP, MK_P(FEDNumbering::MINSiStripFEDID, FEDNumbering::MAXSiStripFEDID)));
0165     fb.insert(MK_P(PRESHOWER, MK_P(FEDNumbering::MINPreShowerFEDID, FEDNumbering::MAXPreShowerFEDID)));
0166     fb.insert(MK_P(TOTEMRP_H, MK_P(FEDNumbering::MINTotemRPHorizontalFEDID, FEDNumbering::MAXTotemRPHorizontalFEDID)));
0167     fb.insert(MK_P(CTPPSDIAMOND, MK_P(FEDNumbering::MINCTPPSDiamondFEDID, FEDNumbering::MAXCTPPSDiamondFEDID)));
0168     fb.insert(MK_P(TOTEMRP_V, MK_P(FEDNumbering::MINTotemRPVerticalFEDID, FEDNumbering::MAXTotemRPVerticalFEDID)));
0169     fb.insert(MK_P(TOTEMRP_T,
0170                    MK_P(FEDNumbering::MINTotemRPTimingVerticalFEDID, FEDNumbering::MAXTotemRPTimingVerticalFEDID)));
0171     fb.insert(MK_P(ECAL, MK_P(FEDNumbering::MINECALFEDID, FEDNumbering::MAXECALFEDID)));
0172     fb.insert(MK_P(CASTOR, MK_P(FEDNumbering::MINCASTORFEDID, FEDNumbering::MAXCASTORFEDID)));
0173     fb.insert(MK_P(HCAL, MK_P(FEDNumbering::MINHCALFEDID, FEDNumbering::MAXHCALFEDID)));
0174     fb.insert(MK_P(CSC, MK_P(FEDNumbering::MINCSCFEDID, FEDNumbering::MAXCSCFEDID)));
0175     fb.insert(MK_P(RPC, MK_P(FEDNumbering::MINRPCFEDID, FEDNumbering::MAXRPCFEDID)));
0176     fb.insert(MK_P(HCALPHASE1, MK_P(FEDNumbering::MINHCALuTCAFEDID, FEDNumbering::MAXHCALuTCAFEDID)));
0177     fb.insert(MK_P(SIPIXELPHASE1, MK_P(FEDNumbering::MINSiPixeluTCAFEDID, FEDNumbering::MAXSiPixeluTCAFEDID)));
0178     fb.insert(MK_P(GEM, MK_P(FEDNumbering::MINGEMFEDID, FEDNumbering::MAXGEMFEDID)));
0179     return fb;
0180   }
0181 };  // namespace RunInfoPI
0182 #endif