Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-30 04:10:26

0001 /*
0002  * Original author: A. Raval / A. Meyer - DESY
0003  * Rewritten by:    B. van Besien - CERN
0004  * Improved by:     S. Di Guida - INFN and Marconi University
0005  */
0006 
0007 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0008 #include "DataFormats/Scalers/interface/DcsStatus.h"
0009 #include "FWCore/Framework/interface/LuminosityBlock.h"
0010 #include "FWCore/Version/interface/GetReleaseVersion.h"
0011 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0012 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0013 #include "DQMServices/Core/interface/DQMStore.h"
0014 #include "DataFormats/OnlineMetaData/interface/DCSRecord.h"
0015 #include "DataFormats/Scalers/interface/DcsStatus.h"
0016 #include "DataFormats/TCDS/interface/TCDSRecord.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/Framework/interface/Run.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023 
0024 #include <string>
0025 #include <vector>
0026 
0027 #include <TSystem.h>
0028 
0029 class DQMProvInfo : public DQMOneEDAnalyzer<> {
0030 public:
0031   // Constructor
0032   DQMProvInfo(const edm::ParameterSet& ps);
0033   // Destructor
0034   ~DQMProvInfo() override = default;
0035 
0036 protected:
0037   void dqmBeginRun(const edm::Run& r, const edm::EventSetup& c) override;
0038   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0039   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0040 
0041 private:
0042   void bookHistogramsLhcInfo(DQMStore::IBooker&);
0043   void bookHistogramsEventInfo(DQMStore::IBooker&);
0044   void bookHistogramsProvInfo(DQMStore::IBooker&);
0045 
0046   void analyzeLhcInfo(const edm::Event& e);
0047   void analyzeEventInfo(const edm::Event& e);
0048   void analyzeProvInfo(const edm::Event& e);
0049 
0050   void fillDcsBitsFromDCSRecord(const DCSRecord&, bool* dcsBits);
0051   void fillDcsBitsFromDcsStatusCollection(const edm::Handle<DcsStatusCollection>&, bool* dcsBits);
0052   bool isPhysicsDeclared(bool* dcsBits);
0053 
0054   void blankAllLumiSections();
0055   void fillSummaryMapBin(int ls, int bin, double value);
0056   void setupLumiSection(int ls);
0057 
0058   // To max amount of lumisections we foresee for the plots
0059   // DQM GUI renderplugins provide scaling to actual amount
0060   const static int MAX_LUMIS = 6000;
0061 
0062   // Numbers of each of the vertical bins
0063   const static int VBIN_CSC_P = 1;
0064   const static int VBIN_CSC_M = 2;
0065   const static int VBIN_DT_0 = 3;
0066   const static int VBIN_DT_P = 4;
0067   const static int VBIN_DT_M = 5;
0068   const static int VBIN_EB_P = 6;
0069   const static int VBIN_EB_M = 7;
0070   const static int VBIN_EE_P = 8;
0071   const static int VBIN_EE_M = 9;
0072   const static int VBIN_ES_P = 10;
0073   const static int VBIN_ES_M = 11;
0074   const static int VBIN_HBHE_A = 12;
0075   const static int VBIN_HBHE_B = 13;
0076   const static int VBIN_HBHE_C = 14;
0077   const static int VBIN_HF = 15;
0078   const static int VBIN_HO = 16;
0079   const static int VBIN_BPIX = 17;
0080   const static int VBIN_FPIX = 18;
0081   const static int VBIN_RPC = 19;
0082   const static int VBIN_TIBTID = 20;
0083   const static int VBIN_TOB = 21;
0084   const static int VBIN_TEC_P = 22;
0085   const static int VBIN_TE_M = 23;
0086   const static int VBIN_CASTOR = 24;
0087   const static int VBIN_ZDC = 25;
0088   const static int VBIN_GEM_P = 26;
0089   const static int VBIN_GEM_M = 27;
0090 
0091   // Highest DCS bin, used for the length of the corresponding array.
0092   // We will have the indexes to this array the same as the vbins numbers.
0093   // (I.e. value at index 0 will not be used.)
0094   const static int MAX_DCS_VBINS = 27;
0095 
0096   const static int VBIN_PHYSICS_DECLARED = 28;
0097   const static int VBIN_MOMENTUM = 29;
0098   const static int VBIN_STABLE_BEAM = 30;
0099   const static int VBIN_VALID = 31;
0100 
0101   const static int MAX_VBINS = 31;
0102 
0103   // Beam momentum at flat top, used to determine if collisions are
0104   // occurring with the beams at the energy allowed for physics production.
0105   const static int MAX_MOMENTUM = 6800;
0106 
0107   // Beam momentum allowed offset: it is a momentum value subtracted to
0108   // maximum momentum in order to decrease the threshold for beams going to
0109   // collisions for physics production. This happens because BST sends from
0110   // time to time a value of the beam momentum slightly below the nominal values,
0111   // even during stable collisions: in this way, we provide a correct information
0112   // at the cost of not requiring the exact momentum being measured by BST.
0113   const static int MOMENTUM_OFFSET = 1;
0114 
0115   // Process parameters
0116   std::string subsystemname_;
0117   std::string provinfofolder_;
0118 
0119   edm::EDGetTokenT<DcsStatusCollection> dcsStatusCollection_;
0120   edm::EDGetTokenT<TCDSRecord> tcdsrecord_;
0121   edm::EDGetTokenT<DCSRecord> dcsRecordToken_;
0122 
0123   // MonitorElements for LhcInfo and corresponding variables
0124   MonitorElement* hBeamMode_;
0125   int beamMode_;
0126   MonitorElement* hIntensity1_;
0127   MonitorElement* hIntensity2_;
0128   MonitorElement* hLhcFill_;
0129   MonitorElement* hMomentum_;
0130 
0131   // MonitorElements for EventInfo and corresponding variables
0132   MonitorElement* reportSummary_;
0133   MonitorElement* reportSummaryMap_;
0134 
0135   // MonitorElements for ProvInfo and corresponding variables
0136   MonitorElement* versCMSSW_;
0137   MonitorElement* versGlobaltag_;
0138   std::string globalTag_;
0139   bool globalTagRetrieved_;
0140   MonitorElement* versRuntype_;
0141   std::string runType_;
0142   MonitorElement* hHltKey_;
0143   std::string hltKey_;
0144   MonitorElement* hostName_;
0145   MonitorElement* hIsCollisionsRun_;
0146   MonitorElement* processId_;  // The PID associated with this job
0147   MonitorElement* workingDir_;
0148 };
0149 
0150 // The LHC beam info used to come from FED812, but since the new TCDS this
0151 // info is in FED1024. We retrieve the BST record from the TCDS digis, and
0152 // we get the LHC beam info using a dedicated data format.
0153 
0154 const int DQMProvInfo::MAX_VBINS;
0155 const int DQMProvInfo::MAX_LUMIS;
0156 
0157 // Constructor
0158 DQMProvInfo::DQMProvInfo(const edm::ParameterSet& ps) {
0159   // Initialization of DQM parameters
0160   subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "Info");
0161   provinfofolder_ = ps.getUntrackedParameter<std::string>("provInfoFolder", "ProvInfo");
0162   runType_ = ps.getUntrackedParameter<std::string>("runType", "No run type selected");
0163 
0164   // Initialization of the input
0165   // Used to get the DCS bits:
0166   dcsStatusCollection_ =
0167       consumes<DcsStatusCollection>(ps.getUntrackedParameter<std::string>("dcsStatusCollection", "scalersRawToDigi"));
0168 
0169   // Used to get the BST record from the TCDS information
0170   tcdsrecord_ = consumes<TCDSRecord>(
0171       ps.getUntrackedParameter<edm::InputTag>("tcdsData", edm::InputTag("tcdsDigis", "tcdsRecord")));
0172 
0173   // Used to get the DCS bits:
0174   dcsRecordToken_ = consumes<DCSRecord>(
0175       ps.getUntrackedParameter<edm::InputTag>("dcsRecord", edm::InputTag("onlineMetaDataRawToDigi")));
0176 
0177   // Initialization of the global tag
0178   globalTag_ = "MODULE::DEFAULT";  // default
0179   globalTagRetrieved_ = false;     // set as soon as retrieved from first event
0180 }
0181 
0182 void DQMProvInfo::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iEventSetup) {
0183   // Here we do everything that needs to be done before the booking
0184   // Getting the HLT key from HLTConfigProvider:
0185   hltKey_ = "";
0186   HLTConfigProvider hltConfig;
0187   bool changed(true);
0188   if (!hltConfig.init(iRun, iEventSetup, "HLT", changed)) {
0189     edm::LogInfo("DQMProvInfo") << "errorHltConfigExtraction" << std::endl;
0190     hltKey_ = "error extraction";
0191   } else if (hltConfig.size() <= 0) {
0192     edm::LogInfo("DQMProvInfo") << "hltConfig" << std::endl;
0193     hltKey_ = "error key of length 0";
0194   } else {
0195     edm::LogInfo("DQMProvInfo") << "HLT key (run): " << hltConfig.tableName() << std::endl;
0196     hltKey_ = hltConfig.tableName();
0197   }
0198 }
0199 
0200 void DQMProvInfo::bookHistograms(DQMStore::IBooker& iBooker, edm::Run const& iRun, edm::EventSetup const& iEventSetup) {
0201   iBooker.cd();
0202   // This module will create elements in 3 different folders:
0203   // - Info/LhcInfo
0204   // - Info/EventInfo
0205   // - Info/ProvInfo
0206   // (string "Info" configurable through subsystemname_)
0207   // (string "Provinfo" configurable through provinfofolder_)
0208   iBooker.setCurrentFolder(subsystemname_ + "/LhcInfo/");
0209   bookHistogramsLhcInfo(iBooker);
0210 
0211   iBooker.setCurrentFolder(subsystemname_ + "/EventInfo/");
0212   bookHistogramsEventInfo(iBooker);
0213 
0214   iBooker.setCurrentFolder(subsystemname_ + "/" + provinfofolder_);
0215   bookHistogramsProvInfo(iBooker);
0216 }
0217 
0218 void DQMProvInfo::bookHistogramsLhcInfo(DQMStore::IBooker& iBooker) {
0219   // Element: beamMode
0220   // Beam parameters provided by BST are defined in:
0221   // https://edms.cern.ch/document/638899/2.0
0222   hBeamMode_ = iBooker.book1D("beamMode", "beamMode", MAX_LUMIS, 1., MAX_LUMIS + 1);
0223   hBeamMode_->getTH1F()->GetYaxis()->Set(21, 0.5, 21.5);
0224   hBeamMode_->getTH1F()->SetMaximum(21.5);
0225   hBeamMode_->setBinContent(0., 22.);  // Not clear, remove when testable
0226 
0227   hBeamMode_->setAxisTitle("Luminosity Section", 1);
0228   hBeamMode_->setBinLabel(1, "no mode", 2);
0229   hBeamMode_->setBinLabel(2, "setup", 2);
0230   hBeamMode_->setBinLabel(3, "inj pilot", 2);
0231   hBeamMode_->setBinLabel(4, "inj intr", 2);
0232   hBeamMode_->setBinLabel(5, "inj nomn", 2);
0233   hBeamMode_->setBinLabel(6, "pre ramp", 2);
0234   hBeamMode_->setBinLabel(7, "ramp", 2);
0235   hBeamMode_->setBinLabel(8, "flat top", 2);
0236   hBeamMode_->setBinLabel(9, "squeeze", 2);
0237   hBeamMode_->setBinLabel(10, "adjust", 2);
0238   hBeamMode_->setBinLabel(11, "stable", 2);
0239   hBeamMode_->setBinLabel(12, "unstable", 2);
0240   hBeamMode_->setBinLabel(13, "beam dump", 2);
0241   hBeamMode_->setBinLabel(14, "ramp down", 2);
0242   hBeamMode_->setBinLabel(15, "recovery", 2);
0243   hBeamMode_->setBinLabel(16, "inj dump", 2);
0244   hBeamMode_->setBinLabel(17, "circ dump", 2);
0245   hBeamMode_->setBinLabel(18, "abort", 2);
0246   hBeamMode_->setBinLabel(19, "cycling", 2);
0247   hBeamMode_->setBinLabel(20, "warn b-dump", 2);
0248   hBeamMode_->setBinLabel(21, "no beam", 2);
0249 
0250   // Element: intensity1
0251   hIntensity1_ = iBooker.book1D("intensity1", "Intensity Beam 1", MAX_LUMIS, 1., MAX_LUMIS + 1);
0252   hIntensity1_->setAxisTitle("Luminosity Section", 1);
0253   hIntensity1_->setAxisTitle("N [E10]", 2);
0254 
0255   // Element: intensity2
0256   hIntensity2_ = iBooker.book1D("intensity2", "Intensity Beam 2", MAX_LUMIS, 1., MAX_LUMIS + 1);
0257   hIntensity2_->setAxisTitle("Luminosity Section", 1);
0258   hIntensity2_->setAxisTitle("N [E10]", 2);
0259 
0260   // Element: lhcFill
0261   hLhcFill_ = iBooker.book1D("lhcFill", "LHC Fill Number", MAX_LUMIS, 1., MAX_LUMIS + 1);
0262   hLhcFill_->setAxisTitle("Luminosity Section", 1);
0263 
0264   // Element: momentum
0265   hMomentum_ = iBooker.book1D("momentum", "Beam Energy [GeV]", MAX_LUMIS, 1., MAX_LUMIS + 1);
0266   hMomentum_->setAxisTitle("Luminosity Section", 1);
0267 }
0268 
0269 void DQMProvInfo::bookHistogramsEventInfo(DQMStore::IBooker& iBooker) {
0270   // Element: reportSummary
0271   reportSummary_ = iBooker.bookFloat("reportSummary");
0272 
0273   // Element: reportSummaryMap   (this is the famous HV plot)
0274   reportSummaryMap_ = iBooker.book2D("reportSummaryMap",
0275                                      "DCS HV Status and Beam Status per Lumisection",
0276                                      MAX_LUMIS,
0277                                      0,
0278                                      MAX_LUMIS,
0279                                      MAX_VBINS,
0280                                      0.,
0281                                      MAX_VBINS);
0282   reportSummaryMap_->setAxisTitle("Luminosity Section");
0283 
0284   reportSummaryMap_->setBinLabel(VBIN_CSC_P, "CSC+", 2);
0285   reportSummaryMap_->setBinLabel(VBIN_CSC_M, "CSC-", 2);
0286   reportSummaryMap_->setBinLabel(VBIN_DT_0, "DT0", 2);
0287   reportSummaryMap_->setBinLabel(VBIN_DT_P, "DT+", 2);
0288   reportSummaryMap_->setBinLabel(VBIN_DT_M, "DT-", 2);
0289   reportSummaryMap_->setBinLabel(VBIN_EB_P, "EB+", 2);
0290   reportSummaryMap_->setBinLabel(VBIN_EB_M, "EB-", 2);
0291   reportSummaryMap_->setBinLabel(VBIN_EE_P, "EE+", 2);
0292   reportSummaryMap_->setBinLabel(VBIN_EE_M, "EE-", 2);
0293   reportSummaryMap_->setBinLabel(VBIN_ES_P, "ES+", 2);
0294   reportSummaryMap_->setBinLabel(VBIN_ES_M, "ES-", 2);
0295   reportSummaryMap_->setBinLabel(VBIN_HBHE_A, "HBHEa", 2);
0296   reportSummaryMap_->setBinLabel(VBIN_HBHE_B, "HBHEb", 2);
0297   reportSummaryMap_->setBinLabel(VBIN_HBHE_C, "HBHEc", 2);
0298   reportSummaryMap_->setBinLabel(VBIN_HF, "HF", 2);
0299   reportSummaryMap_->setBinLabel(VBIN_HO, "HO", 2);
0300   reportSummaryMap_->setBinLabel(VBIN_BPIX, "BPIX", 2);
0301   reportSummaryMap_->setBinLabel(VBIN_FPIX, "FPIX", 2);
0302   reportSummaryMap_->setBinLabel(VBIN_RPC, "RPC", 2);
0303   reportSummaryMap_->setBinLabel(VBIN_TIBTID, "TIBTID", 2);
0304   reportSummaryMap_->setBinLabel(VBIN_TOB, "TOB", 2);
0305   reportSummaryMap_->setBinLabel(VBIN_TEC_P, "TECp", 2);
0306   reportSummaryMap_->setBinLabel(VBIN_TE_M, "TECm", 2);
0307   reportSummaryMap_->setBinLabel(VBIN_CASTOR, "CASTOR", 2);
0308   reportSummaryMap_->setBinLabel(VBIN_ZDC, "ZDC", 2);
0309   reportSummaryMap_->setBinLabel(VBIN_GEM_P, "GEMp", 2);
0310   reportSummaryMap_->setBinLabel(VBIN_GEM_M, "GEMm", 2);
0311   reportSummaryMap_->setBinLabel(VBIN_PHYSICS_DECLARED, "PhysDecl", 2);
0312   reportSummaryMap_->setBinLabel(VBIN_MOMENTUM, "13.6 TeV", 2);
0313   reportSummaryMap_->setBinLabel(VBIN_STABLE_BEAM, "Stable B", 2);
0314   reportSummaryMap_->setBinLabel(VBIN_VALID, "Valid", 2);
0315 
0316   blankAllLumiSections();
0317 }
0318 
0319 void DQMProvInfo::bookHistogramsProvInfo(DQMStore::IBooker& iBooker) {
0320   // Note: Given that all these elements are only filled once per run, they
0321   //       are filled here right away. (except for isCollisionsRun)
0322 
0323   // Element: CMMSW
0324   versCMSSW_ = iBooker.bookString("CMSSW", edm::getReleaseVersion().c_str());
0325 
0326   // Element: Globaltag
0327   versGlobaltag_ = iBooker.bookString("Globaltag", globalTag_);
0328 
0329   // Element: RunType
0330   versRuntype_ = iBooker.bookString("Run Type", runType_);
0331 
0332   // Element: hltKey
0333   hHltKey_ = iBooker.bookString("hltKey", hltKey_);
0334 
0335   // Element: hostName
0336   hostName_ = iBooker.bookString("hostName", gSystem->HostName());
0337 
0338   // Element: isCollisionsRun (filled for real in EndLumi)
0339   hIsCollisionsRun_ = iBooker.bookInt("isCollisionsRun");
0340   hIsCollisionsRun_->Fill(0);
0341 
0342   // Element: processID
0343   processId_ = iBooker.bookInt("processID");
0344   processId_->Fill(gSystem->GetPid());
0345 
0346   // Element: workingDir
0347   workingDir_ = iBooker.bookString("workingDir", gSystem->pwd());
0348 }
0349 
0350 void DQMProvInfo::analyze(const edm::Event& event, const edm::EventSetup& c) {
0351   // This happens on an event by event base
0352   // We extract information from events, placing them in local variables
0353   // and then at the end of each lumisection, we fill them in the MonitorElement
0354   // (Except for the global tag, which we only extract from the first event we
0355   //  ever encounter and put in the MonitorElement right away)
0356 
0357   // We set the top value to "Valid" to 1 for each LS we encounter
0358   setupLumiSection(event.id().luminosityBlock());
0359 
0360   analyzeLhcInfo(event);
0361   analyzeEventInfo(event);
0362   analyzeProvInfo(event);
0363 }
0364 
0365 void DQMProvInfo::analyzeLhcInfo(const edm::Event& event) {
0366   unsigned int currentLSNumber = event.id().luminosityBlock();
0367   edm::Handle<TCDSRecord> tcdsData;
0368   event.getByToken(tcdsrecord_, tcdsData);
0369   // We unpack the TCDS record from TCDS
0370   if (tcdsData.isValid()) {
0371     //and we look at the BST information
0372     auto lhcFill = static_cast<int>(tcdsData->getBST().getLhcFill());
0373     beamMode_ = static_cast<int>(tcdsData->getBST().getBeamMode());
0374     auto momentum = static_cast<int>(tcdsData->getBST().getBeamMomentum());
0375     auto intensity1 = static_cast<int>(tcdsData->getBST().getIntensityBeam1());
0376     auto intensity2 = static_cast<int>(tcdsData->getBST().getIntensityBeam2());
0377 
0378     // Quite straightforward: Fill in the value for the LS in each plot:
0379     hLhcFill_->setBinContent(currentLSNumber, lhcFill);
0380     hBeamMode_->setBinContent(currentLSNumber, beamMode_);
0381     hMomentum_->setBinContent(currentLSNumber, momentum);
0382     hIntensity1_->setBinContent(currentLSNumber, intensity1);
0383     hIntensity2_->setBinContent(currentLSNumber, intensity2);
0384 
0385     // Part3: Using LHC status info, fill in VBIN_MOMENTUM and VBIN_STABLE_BEAM
0386     // Fill 13.6 TeV bit in y bin VBIN_MOMENTUM
0387     if (momentum >= MAX_MOMENTUM - MOMENTUM_OFFSET) {
0388       fillSummaryMapBin(currentLSNumber, VBIN_MOMENTUM, 1.);
0389     } else {
0390       fillSummaryMapBin(currentLSNumber, VBIN_MOMENTUM, 0.);
0391     }
0392 
0393     // Fill stable beams bit in y bin VBIN_STABLE_BEAM
0394     if (beamMode_ == 11) {
0395       hIsCollisionsRun_->Fill(1);
0396       reportSummary_->Fill(1.);
0397       fillSummaryMapBin(currentLSNumber, VBIN_STABLE_BEAM, 1.);
0398     } else {
0399       reportSummary_->Fill(0.);
0400       fillSummaryMapBin(currentLSNumber, VBIN_STABLE_BEAM, 0.);
0401     }
0402   } else {
0403     edm::LogWarning("DQMProvInfo") << "TCDS Data inaccessible.";
0404   }
0405 }
0406 
0407 void DQMProvInfo::analyzeEventInfo(const edm::Event& event) {
0408   unsigned int currentLSNumber = event.id().luminosityBlock();
0409   // Part 1:
0410   // If FED#735 is available use it to extract DcsStatusCollection.
0411   // If not, use softFED#1022 to extract DCSRecord.
0412 
0413   edm::Handle<DcsStatusCollection> dcsStatusCollection;
0414   event.getByToken(dcsStatusCollection_, dcsStatusCollection);
0415   edm::Handle<DCSRecord> dcsRecord;
0416   event.getByToken(dcsRecordToken_, dcsRecord);
0417 
0418   // Populate dcsBits array with received information.
0419   bool dcsBits[MAX_DCS_VBINS + 1] = {};
0420 
0421   if (dcsStatusCollection.isValid() && !dcsStatusCollection->empty()) {
0422     edm::LogInfo("DQMProvInfo") << "Using FED#735 for reading DCS bits" << std::endl;
0423     fillDcsBitsFromDcsStatusCollection(dcsStatusCollection, dcsBits);
0424   } else if (dcsRecord.isValid()) {
0425     edm::LogInfo("DQMProvInfo") << "Using softFED#1022 for reading DCS bits" << std::endl;
0426     fillDcsBitsFromDCSRecord(*dcsRecord, dcsBits);
0427   } else {
0428     edm::LogError("DQMProvInfo") << "No DCS information found!" << std::endl;
0429   }
0430 
0431   // Part 2: Compute the PhysicsDeclared bit from the event
0432   auto physicsDeclared = isPhysicsDeclared(dcsBits);
0433 
0434   // Some info-level logging
0435   edm::LogInfo("DQMProvInfo") << "Physics declared bit: " << physicsDeclared << std::endl;
0436 
0437   // Part 1: Physics declared bit in y bin VBIN_PHYSICS_DECLARED
0438   // This also is used as the global value of the summary.
0439   if (physicsDeclared) {
0440     fillSummaryMapBin(currentLSNumber, VBIN_PHYSICS_DECLARED, 1.);
0441   } else {
0442     fillSummaryMapBin(currentLSNumber, VBIN_PHYSICS_DECLARED, 0.);
0443   }
0444 
0445   // Part2: DCS bits in y bins 1 to MAX_DCS_VBINS
0446   for (int vbin = 1; vbin <= MAX_DCS_VBINS; vbin++) {
0447     if (dcsBits[vbin]) {
0448       fillSummaryMapBin(currentLSNumber, vbin, 1.);
0449     } else {
0450       fillSummaryMapBin(currentLSNumber, vbin, 0.);
0451     }
0452   }
0453 }
0454 
0455 void DQMProvInfo::analyzeProvInfo(const edm::Event& event) {
0456   // Only trying to retrieve the global tag for the first event we ever
0457   // encounter.
0458   if (!globalTagRetrieved_) {
0459     // Getting the real process name for the given event
0460     std::string processName = event.processHistory()[event.processHistory().size() - 1].processName();
0461     // Getting parameters for that process
0462     edm::ParameterSet ps;
0463     event.getProcessParameterSet(processName, ps);
0464     // Getting the global tag
0465     globalTag_ = ps.getParameterSet("PoolDBESSource@GlobalTag").getParameter<std::string>("globaltag");
0466     versGlobaltag_->Fill(globalTag_);
0467     // Finaly: Setting globalTagRetrieved_ to true, since we got it now
0468     globalTagRetrieved_ = true;
0469   }
0470 }
0471 
0472 void DQMProvInfo::fillDcsBitsFromDCSRecord(const DCSRecord& dcsRecord, bool* dcsBits) {
0473   dcsBits[VBIN_CSC_P] = dcsRecord.highVoltageReady(DCSRecord::Partition::CSCp);
0474   dcsBits[VBIN_CSC_M] = dcsRecord.highVoltageReady(DCSRecord::Partition::CSCm);
0475   dcsBits[VBIN_DT_0] = dcsRecord.highVoltageReady(DCSRecord::Partition::DT0);
0476   dcsBits[VBIN_DT_P] = dcsRecord.highVoltageReady(DCSRecord::Partition::DTp);
0477   dcsBits[VBIN_DT_M] = dcsRecord.highVoltageReady(DCSRecord::Partition::DTm);
0478   dcsBits[VBIN_EB_P] = dcsRecord.highVoltageReady(DCSRecord::Partition::EBp);
0479   dcsBits[VBIN_EB_M] = dcsRecord.highVoltageReady(DCSRecord::Partition::EBm);
0480   dcsBits[VBIN_EE_P] = dcsRecord.highVoltageReady(DCSRecord::Partition::EEp);
0481   dcsBits[VBIN_EE_M] = dcsRecord.highVoltageReady(DCSRecord::Partition::EEm);
0482   dcsBits[VBIN_ES_P] = dcsRecord.highVoltageReady(DCSRecord::Partition::ESp);
0483   dcsBits[VBIN_ES_M] = dcsRecord.highVoltageReady(DCSRecord::Partition::ESm);
0484   dcsBits[VBIN_HBHE_A] = dcsRecord.highVoltageReady(DCSRecord::Partition::HBHEa);
0485   dcsBits[VBIN_HBHE_B] = dcsRecord.highVoltageReady(DCSRecord::Partition::HBHEb);
0486   dcsBits[VBIN_HBHE_C] = dcsRecord.highVoltageReady(DCSRecord::Partition::HBHEc);
0487   dcsBits[VBIN_HF] = dcsRecord.highVoltageReady(DCSRecord::Partition::HF);
0488   dcsBits[VBIN_HO] = dcsRecord.highVoltageReady(DCSRecord::Partition::HO);
0489   dcsBits[VBIN_BPIX] = dcsRecord.highVoltageReady(DCSRecord::Partition::BPIX);
0490   dcsBits[VBIN_FPIX] = dcsRecord.highVoltageReady(DCSRecord::Partition::FPIX);
0491   dcsBits[VBIN_RPC] = dcsRecord.highVoltageReady(DCSRecord::Partition::RPC);
0492   dcsBits[VBIN_TIBTID] = dcsRecord.highVoltageReady(DCSRecord::Partition::TIBTID);
0493   dcsBits[VBIN_TOB] = dcsRecord.highVoltageReady(DCSRecord::Partition::TOB);
0494   dcsBits[VBIN_TEC_P] = dcsRecord.highVoltageReady(DCSRecord::Partition::TECp);
0495   dcsBits[VBIN_TE_M] = dcsRecord.highVoltageReady(DCSRecord::Partition::TECm);
0496   dcsBits[VBIN_CASTOR] = dcsRecord.highVoltageReady(DCSRecord::Partition::CASTOR);
0497   dcsBits[VBIN_ZDC] = dcsRecord.highVoltageReady(DCSRecord::Partition::ZDC);
0498   dcsBits[VBIN_GEM_P] = dcsRecord.highVoltageReady(DCSRecord::Partition::GEMp);
0499   dcsBits[VBIN_GEM_M] = dcsRecord.highVoltageReady(DCSRecord::Partition::GEMm);
0500 }
0501 
0502 void DQMProvInfo::fillDcsBitsFromDcsStatusCollection(const edm::Handle<DcsStatusCollection>& dcsStatusCollection,
0503                                                      bool* dcsBits) {
0504   // Loop over the DCSStatus entries in the DcsStatusCollection
0505   // (Typically there is only one)
0506   bool first = true;
0507   for (auto const& dcsStatusItr : *dcsStatusCollection) {
0508     // By default all the bits are false. We put all the bits on true only
0509     // for the first DCSStatus that we encounter:
0510     if (first) {
0511       for (int vbin = 1; vbin <= MAX_DCS_VBINS; vbin++) {
0512         dcsBits[vbin] = true;
0513       }
0514       first = false;
0515     }
0516     dcsBits[VBIN_CSC_P] &= dcsStatusItr.ready(DcsStatus::CSCp);
0517     dcsBits[VBIN_CSC_M] &= dcsStatusItr.ready(DcsStatus::CSCm);
0518     dcsBits[VBIN_DT_0] &= dcsStatusItr.ready(DcsStatus::DT0);
0519     dcsBits[VBIN_DT_P] &= dcsStatusItr.ready(DcsStatus::DTp);
0520     dcsBits[VBIN_DT_M] &= dcsStatusItr.ready(DcsStatus::DTm);
0521     dcsBits[VBIN_EB_P] &= dcsStatusItr.ready(DcsStatus::EBp);
0522     dcsBits[VBIN_EB_M] &= dcsStatusItr.ready(DcsStatus::EBm);
0523     dcsBits[VBIN_EE_P] &= dcsStatusItr.ready(DcsStatus::EEp);
0524     dcsBits[VBIN_EE_M] &= dcsStatusItr.ready(DcsStatus::EEm);
0525     dcsBits[VBIN_ES_P] &= dcsStatusItr.ready(DcsStatus::ESp);
0526     dcsBits[VBIN_ES_M] &= dcsStatusItr.ready(DcsStatus::ESm);
0527     dcsBits[VBIN_HBHE_A] &= dcsStatusItr.ready(DcsStatus::HBHEa);
0528     dcsBits[VBIN_HBHE_B] &= dcsStatusItr.ready(DcsStatus::HBHEb);
0529     dcsBits[VBIN_HBHE_C] &= dcsStatusItr.ready(DcsStatus::HBHEc);
0530     dcsBits[VBIN_HF] &= dcsStatusItr.ready(DcsStatus::HF);
0531     dcsBits[VBIN_HO] &= dcsStatusItr.ready(DcsStatus::HO);
0532     dcsBits[VBIN_BPIX] &= dcsStatusItr.ready(DcsStatus::BPIX);
0533     dcsBits[VBIN_FPIX] &= dcsStatusItr.ready(DcsStatus::FPIX);
0534     dcsBits[VBIN_RPC] &= dcsStatusItr.ready(DcsStatus::RPC);
0535     dcsBits[VBIN_TIBTID] &= dcsStatusItr.ready(DcsStatus::TIBTID);
0536     dcsBits[VBIN_TOB] &= dcsStatusItr.ready(DcsStatus::TOB);
0537     dcsBits[VBIN_TEC_P] &= dcsStatusItr.ready(DcsStatus::TECp);
0538     dcsBits[VBIN_TE_M] &= dcsStatusItr.ready(DcsStatus::TECm);
0539     dcsBits[VBIN_CASTOR] &= dcsStatusItr.ready(DcsStatus::CASTOR);
0540     dcsBits[VBIN_ZDC] &= dcsStatusItr.ready(DcsStatus::ZDC);
0541     //dcsBits[VBIN_GEM_P] &= dcsStatusItr.ready(DcsStatus::GEMp);  // GEMp and GEMm are not implemented
0542     //dcsBits[VBIN_GEM_M] &= dcsStatusItr.ready(DcsStatus::GEMm);
0543 
0544     // Some info-level logging
0545     edm::LogInfo("DQMProvInfo") << "DCS status: 0x" << std::hex << dcsStatusItr.ready() << std::dec << std::endl;
0546   }
0547 }
0548 
0549 bool DQMProvInfo::isPhysicsDeclared(bool* dcsBits) {
0550   // Compute the PhysicsDeclared bit from the event
0551   // The bit is set to to true if:
0552   // - the LHC is in stable beams
0553   // - all the pixel and strips partitions have DCSStatus ON
0554   // - at least one muon partition has DCSStatus ON
0555   // Basically: we do an AND of the physicsDeclared of ALL events.
0556   // As soon as one value is not "1", physicsDeclared_ becomes false.
0557   return (beamMode_ == 11) &&
0558          (dcsBits[VBIN_BPIX] && dcsBits[VBIN_FPIX] && dcsBits[VBIN_TIBTID] && dcsBits[VBIN_TOB] &&
0559           dcsBits[VBIN_TEC_P] && dcsBits[VBIN_TE_M]) &&
0560          (dcsBits[VBIN_CSC_P] || dcsBits[VBIN_CSC_M] || dcsBits[VBIN_DT_0] || dcsBits[VBIN_DT_P] ||
0561           dcsBits[VBIN_DT_M] || dcsBits[VBIN_RPC] || dcsBits[VBIN_GEM_P] || dcsBits[VBIN_GEM_M]);
0562 }
0563 
0564 void DQMProvInfo::blankAllLumiSections() {
0565   // Initially we want all lumisection to be blank (-1) and
0566   // white instead of red which is misleading.
0567   for (int ls = 0; ls < MAX_LUMIS; ls++) {
0568     // Color all the bins white (-1)
0569     for (int vBin = 1; vBin <= MAX_VBINS; vBin++) {
0570       reportSummaryMap_->setBinContent(ls, vBin, -1.);
0571     }
0572   }
0573 }
0574 
0575 void DQMProvInfo::fillSummaryMapBin(int ls, int bin, double value) {
0576   // All lumis are initialized as -1 (white).
0577   // We'll set them to red (0) whenever we see a 0 -- else, the value should be
0578   // green (1).
0579   // This need to be atomic, DQMOneEDAnalyzer for this reason.
0580   double current = reportSummaryMap_->getBinContent(ls, bin);
0581   if (current == -1) {
0582     reportSummaryMap_->setBinContent(ls, bin, value);
0583   } else if (value < current) {
0584     reportSummaryMap_->setBinContent(ls, bin, value);
0585   }  // else: ignore, keep min value.
0586 }
0587 
0588 void DQMProvInfo::setupLumiSection(int currentLSNumber) {
0589   if (reportSummaryMap_->getBinContent(currentLSNumber, VBIN_VALID) < 1.) {
0590     reportSummaryMap_->setBinContent(currentLSNumber, VBIN_VALID, 1.);
0591 
0592     // Mark all lower LS as invalid, if they are not set valid yet.
0593     // This is a hint for the render plugin to show the correct range.
0594     for (int ls = 1; ls < currentLSNumber; ls++) {
0595       if (reportSummaryMap_->getBinContent(ls, VBIN_VALID) == -1.) {
0596         reportSummaryMap_->setBinContent(ls, VBIN_VALID, 0.);
0597       }
0598     }
0599   }
0600 }
0601 
0602 #include "FWCore/PluginManager/interface/ModuleDef.h"
0603 #include "FWCore/Framework/interface/MakerMacros.h"
0604 DEFINE_FWK_MODULE(DQMProvInfo);