Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-31 00:08:44

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiStripMonitorCluster
0004 // Class:      SiStripOfflineDQM
0005 //
0006 /**\class SiStripOfflineDQM SiStripOfflineDQM.cc
0007  DQM/SiStripMonitorCluster/src/SiStripOfflineDQM.cc
0008 
0009  Description: <one line class summary>
0010 
0011  Implementation:
0012      <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Samvel Khalatyan (ksamdev at gmail dot com)
0016 //         Created:  Wed Oct  5 16:42:34 CET 2006
0017 //
0018 //
0019 
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/Framework/interface/LuminosityBlock.h"
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023 #include "FWCore/ParameterSet/interface/FileInPath.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 
0026 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0027 
0028 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0029 
0030 #include "DQMServices/Core/interface/DQMStore.h"
0031 #include "DataFormats/Histograms/interface/DQMToken.h"
0032 
0033 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0034 #include "DQM/SiStripMonitorClient/interface/SiStripActionExecutor.h"
0035 
0036 #include "SiStripOfflineDQM.h"
0037 
0038 //Run Info
0039 #include "CondFormats/RunInfo/interface/RunInfo.h"
0040 #include "DQMServices/Core/interface/LegacyIOHelper.h"
0041 
0042 #include <iostream>
0043 #include <iomanip>
0044 #include <cstdio>
0045 #include <string>
0046 #include <sstream>
0047 #include <cmath>
0048 
0049 SiStripOfflineDQM::SiStripOfflineDQM(edm::ParameterSet const& pSet)
0050     : actionExecutor_{pSet},
0051       usedWithEDMtoMEConverter_{pSet.getUntrackedParameter<bool>("UsedWithEDMtoMEConverter", false)},
0052       createSummary_{pSet.getUntrackedParameter<bool>("CreateSummary", false)},
0053       createTkMap_{pSet.getUntrackedParameter<bool>("CreateTkMap", false)},
0054       createTkInfoFile_{pSet.getUntrackedParameter<bool>("CreateTkInfoFile", false)},
0055       inputFileName_{pSet.getUntrackedParameter<std::string>("InputFileName", "")},
0056       outputFileName_{pSet.getUntrackedParameter<std::string>("OutputFileName", "")},
0057       globalStatusFilling_{pSet.getUntrackedParameter<int>("GlobalStatusFilling", 1)},
0058       printFaultyModuleList_{pSet.getUntrackedParameter<bool>("PrintFaultyModuleList", false)},
0059       detCablingToken_{globalStatusFilling_ > 0 || createTkMap_
0060                            ? decltype(detCablingToken_){esConsumes<edm::Transition::EndRun>()}
0061                            : decltype(detCablingToken_){}},
0062       tTopoToken_{globalStatusFilling_ > 0 || createTkMap_
0063                       ? decltype(tTopoToken_){esConsumes<edm::Transition::EndRun>()}
0064                       : decltype(tTopoToken_){}},
0065       tkDetMapToken_{globalStatusFilling_ > 0 || createTkMap_
0066                          ? decltype(tkDetMapToken_){esConsumes<edm::Transition::EndRun>()}
0067                          : decltype(tkDetMapToken_){}},
0068       geomDetToken_{createTkMap_ && createTkInfoFile_ ? decltype(geomDetToken_){esConsumes<edm::Transition::EndRun>()}
0069                                                       : decltype(geomDetToken_){}},
0070       runInfoToken_{esConsumes<edm::Transition::BeginRun>()} {
0071   if (createTkMap_) {
0072     using QualityToken = edm::ESGetToken<SiStripQuality, SiStripQualityRcd>;
0073     for (const auto& ps : pSet.getUntrackedParameter<std::vector<edm::ParameterSet>>("TkMapOptions")) {
0074       edm::ParameterSet tkMapPSet = ps;
0075       const auto map_type = ps.getUntrackedParameter<std::string>("mapName", "");
0076       tkMapPSet.augment(pSet.getUntrackedParameter<edm::ParameterSet>("TkmapParameters"));
0077       const bool useSSQ = tkMapPSet.getUntrackedParameter<bool>("useSSQuality", false);
0078       auto token = useSSQ ? QualityToken{esConsumes<edm::Transition::EndRun>(
0079                                 edm::ESInputTag{"", tkMapPSet.getUntrackedParameter<std::string>("ssqLabel", "")})}
0080                           : QualityToken{};
0081       tkMapOptions_.emplace_back(map_type, std::move(tkMapPSet), useSSQ, std::move(token));
0082     }
0083   }
0084 
0085   if (createTkInfoFile_) {
0086     tkinfoTree_ = edm::Service<TFileService> { } -> make<TTree>("TkDetIdInfo", ""); }
0087 
0088   // explicit dependency to make sure the QTest reults needed here are present
0089   // already in endRun.
0090   consumes<DQMToken, edm::InRun>(edm::InputTag("siStripQTester", "DQMGenerationQTestRun"));
0091   consumes<DQMToken, edm::InLumi>(edm::InputTag("siStripQTester", "DQMGenerationQTestLumi"));
0092   usesResource("DQMStore");
0093   produces<DQMToken, edm::Transition::EndRun>("DQMGenerationSiStripAnalyserRun");
0094   produces<DQMToken, edm::Transition::EndLuminosityBlock>("DQMGenerationSiStripAnalyserLumi");
0095 }
0096 
0097 void SiStripOfflineDQM::beginJob() {
0098   // Essential: reads xml file to get the histogram names to create summary
0099   // Read the summary configuration file
0100   if (createSummary_) {
0101     if (!actionExecutor_.readConfiguration()) {
0102       edm::LogInfo("ReadConfigurationProblem") << "SiStripOfflineDQM:: Error to read configuration file!! Summary "
0103                                                   "will not be produced!!!";
0104       createSummary_ = false;
0105     }
0106   }
0107   edm::LogInfo("BeginJobDone") << "SiStripOfflineDQM::beginJob done";
0108 }
0109 
0110 void SiStripOfflineDQM::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0111   edm::LogInfo("BeginRun") << "SiStripOfflineDQM:: Begining of Run";
0112 
0113   int nFEDs = 0;
0114   if (eSetup.tryToGet<RunInfoRcd>()) {
0115     if (auto sumFED = eSetup.getHandle(runInfoToken_)) {
0116       constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
0117       constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
0118 
0119       for (auto const fedID : sumFED->m_fed_in) {
0120         if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
0121           ++nFEDs;
0122       }
0123     }
0124   }
0125   auto& dqm_store = *edm::Service<DQMStore>{};
0126   trackerFEDsFound_ = (nFEDs > 0);
0127   if (!usedWithEDMtoMEConverter_) {
0128     if (!openInputFile(dqm_store))
0129       createSummary_ = false;
0130   }
0131   if (globalStatusFilling_ > 0) {
0132     actionExecutor_.createStatus(dqm_store);
0133   }
0134 }
0135 
0136 void SiStripOfflineDQM::produce(edm::Event&, edm::EventSetup const&) {}
0137 
0138 void SiStripOfflineDQM::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {
0139   edm::LogInfo("EndLumiBlock") << "SiStripOfflineDQM::endLuminosityBlock";
0140   if (trackerFEDsFound_) {
0141     if (globalStatusFilling_ > 0) {
0142       auto& dqm_store = *edm::Service<DQMStore>{};
0143       actionExecutor_.fillStatusAtLumi(dqm_store);
0144     }
0145   }
0146 }
0147 
0148 void SiStripOfflineDQM::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0149   edm::LogInfo("EndOfRun") << "SiStripOfflineDQM::endRun";
0150 
0151   auto& dqm_store = *edm::Service<DQMStore>{};
0152   if (globalStatusFilling_ > 0) {
0153     actionExecutor_.createStatus(dqm_store);
0154     if (!trackerFEDsFound_) {
0155       actionExecutor_.fillDummyStatus();
0156       return;
0157     }
0158     // Fill Global Status
0159     actionExecutor_.fillStatus(
0160         dqm_store, &eSetup.getData(detCablingToken_), &eSetup.getData(tkDetMapToken_), &eSetup.getData(tTopoToken_));
0161   }
0162 
0163   if (usedWithEDMtoMEConverter_)
0164     return;
0165 
0166   // create Summary Plots
0167   if (createSummary_)
0168     actionExecutor_.createSummaryOffline(dqm_store);
0169 
0170   // Create TrackerMap
0171   if (createTkMap_) {
0172     if (actionExecutor_.readTkMapConfiguration(
0173             &eSetup.getData(detCablingToken_), &eSetup.getData(tkDetMapToken_), &eSetup.getData(tTopoToken_))) {
0174       std::vector<std::string> mapNames;
0175       for (const auto& mapOptions : tkMapOptions_) {
0176         edm::LogInfo("TkMapParameters") << mapOptions.pset;
0177         std::string map_type = mapOptions.type;
0178         actionExecutor_.createOfflineTkMap(
0179             mapOptions.pset, dqm_store, map_type, mapOptions.useSSQ ? &eSetup.getData(mapOptions.token) : nullptr);
0180         mapNames.push_back(map_type);
0181       }
0182       if (createTkInfoFile_) {
0183         actionExecutor_.createTkInfoFile(mapNames, tkinfoTree_, dqm_store, &eSetup.getData(geomDetToken_));
0184       }
0185     }
0186   }
0187 }
0188 
0189 void SiStripOfflineDQM::endJob() {
0190   edm::LogInfo("EndOfJob") << "SiStripOfflineDQM::endJob";
0191   if (usedWithEDMtoMEConverter_)
0192     return;
0193 
0194   if (printFaultyModuleList_) {
0195     std::ostringstream str_val;
0196     auto& dqm_store = *edm::Service<DQMStore>{};
0197     actionExecutor_.printFaultyModuleList(dqm_store, str_val);
0198     std::cout << str_val.str() << std::endl;
0199   }
0200 }
0201 
0202 bool SiStripOfflineDQM::openInputFile(DQMStore& dqm_store) {
0203   if (inputFileName_.empty()) {
0204     return false;
0205   }
0206   edm::LogInfo("OpenFile") << "SiStripOfflineDQM::openInputFile: Accessing root File" << inputFileName_;
0207   dqm::harvesting::DQMStore* temp = dynamic_cast<dqm::harvesting::DQMStore*>(&dqm_store);
0208   LegacyIOHelper leo(temp);
0209   return leo.open(inputFileName_);
0210 }
0211 
0212 #include "FWCore/Framework/interface/MakerMacros.h"
0213 DEFINE_FWK_MODULE(SiStripOfflineDQM);