Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:40

0001 
0002 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0003 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0004 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0005 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0006 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0007 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0008 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0009 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0010 #include "DQM/SiStripMonitorClient/interface/SiStripActionExecutor.h"
0011 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
0012 #include "DQM/SiStripMonitorSummary/interface/SiStripClassToMonitorCondData.h"
0013 #include "DQMServices/Core/interface/DQMStore.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/LuminosityBlock.h"
0016 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0017 #include "FWCore/Framework/interface/ESWatcher.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/LuminosityBlock.h"
0020 #include "FWCore/Framework/interface/Run.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "FWCore/ParameterSet/interface/FileInPath.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/Utilities/interface/EDGetToken.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 #include "FWCore/ServiceRegistry/interface/Service.h"
0027 
0028 #include <cmath>
0029 #include <cstdio>
0030 #include <iomanip>
0031 #include <iostream>
0032 #include <map>
0033 #include <vector>
0034 #include <sstream>
0035 #include <string>
0036 
0037 class SiStripWebInterface;
0038 class SiStripFedCabling;
0039 class SiStripDetCabling;
0040 class SiStripClassToMonitorCondData;
0041 class FEDRawDataCollection;
0042 
0043 class SiStripAnalyser
0044     : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0045 public:
0046   typedef dqm::harvesting::MonitorElement MonitorElement;
0047   typedef dqm::harvesting::DQMStore DQMStore;
0048 
0049   SiStripAnalyser(const edm::ParameterSet& ps);
0050   ~SiStripAnalyser() override;
0051 
0052 private:
0053   void beginJob() override;
0054   void beginRun(edm::Run const& run, edm::EventSetup const& eSetup) override;
0055   void analyze(edm::Event const& e, edm::EventSetup const& eSetup) override;
0056   void beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) override;
0057   void endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) override;
0058   void endRun(edm::Run const& run, edm::EventSetup const& eSetup) override;
0059   void endJob() override;
0060 
0061   void checkTrackerFEDs(edm::Event const& e);
0062 
0063   SiStripClassToMonitorCondData condDataMon_;
0064   SiStripActionExecutor actionExecutor_;
0065   edm::ParameterSet tkMapPSet_;
0066 
0067   int summaryFrequency_{-1};
0068   int staticUpdateFrequency_;
0069   int globalStatusFilling_;
0070   int shiftReportFrequency_;
0071 
0072   edm::EDGetTokenT<FEDRawDataCollection> rawDataToken_;
0073 
0074   std::string outputFilePath_;
0075   std::string outputFileName_;
0076 
0077   const SiStripDetCabling* detCabling_;
0078   edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> detCablingToken_;
0079   edm::ESWatcher<SiStripFedCablingRcd> fedCablingWatcher_;
0080   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_, tTopoTokenELB_, tTopoTokenBR_;
0081   edm::ESGetToken<TkDetMap, TrackerTopologyRcd> tkDetMapToken_, tkDetMapTokenELB_, tkDetMapTokenBR_;
0082   edm::ESGetToken<SiStripQuality, SiStripQualityRcd> stripQualityToken_;
0083 
0084   int nLumiSecs_{};
0085   int nEvents_{};
0086   bool trackerFEDsFound_{false};
0087   bool printFaultyModuleList_;
0088   bool endLumiAnalysisOn_{false};
0089 };
0090 
0091 SiStripAnalyser::SiStripAnalyser(edm::ParameterSet const& ps)
0092     : condDataMon_{ps, consumesCollector()},
0093       actionExecutor_{ps},
0094       tkMapPSet_{ps.getParameter<edm::ParameterSet>("TkmapParameters")},
0095       summaryFrequency_{ps.getUntrackedParameter<int>("SummaryCreationFrequency", 1)},
0096       staticUpdateFrequency_{ps.getUntrackedParameter<int>("StaticUpdateFrequency", 1)},
0097       globalStatusFilling_{ps.getUntrackedParameter<int>("GlobalStatusFilling", 1)},
0098       shiftReportFrequency_{ps.getUntrackedParameter<int>("ShiftReportFrequency", 1)},
0099       rawDataToken_{consumes<FEDRawDataCollection>(ps.getUntrackedParameter<edm::InputTag>("RawDataTag"))},
0100       detCablingToken_(esConsumes<edm::Transition::BeginRun>()),
0101       tTopoToken_(esConsumes()),
0102       tTopoTokenELB_(esConsumes<edm::Transition::EndLuminosityBlock>()),
0103       tTopoTokenBR_(esConsumes<edm::Transition::BeginRun>()),
0104       tkDetMapToken_(esConsumes()),
0105       tkDetMapTokenELB_(esConsumes<edm::Transition::EndLuminosityBlock>()),
0106       tkDetMapTokenBR_(esConsumes<edm::Transition::BeginRun>()),
0107       printFaultyModuleList_{ps.getUntrackedParameter<bool>("PrintFaultyModuleList", true)} {
0108   usesResource("DQMStore");
0109   std::string const localPath{"DQM/SiStripMonitorClient/test/loader.html"};
0110   std::ifstream fin{edm::FileInPath(localPath).fullPath(), std::ios::in};
0111   if (!fin) {
0112     std::cerr << "Input File: loader.html"
0113               << " could not be opened!" << std::endl;
0114     return;
0115   }
0116   edm::LogInfo("SiStripAnalyser") << " SiStripAnalyser::Creating SiStripAnalyser ";
0117 }
0118 
0119 SiStripAnalyser::~SiStripAnalyser() { edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser::Deleting SiStripAnalyser "; }
0120 
0121 void SiStripAnalyser::beginJob() {
0122   // Read the summary configuration file
0123   if (!actionExecutor_.readConfiguration()) {
0124     edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: Error to read configuration file!! Summary will "
0125                                        "not be produced!!!";
0126   }
0127 }
0128 
0129 void SiStripAnalyser::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0130   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: Begining of Run";
0131 
0132   // Check latest Fed cabling and create TrackerMapCreator
0133   if (fedCablingWatcher_.check(eSetup)) {
0134     edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser::beginRun: "
0135                                     << " Change in Cabling, recrated TrackerMap";
0136     detCabling_ = &eSetup.getData(detCablingToken_);
0137     if (!actionExecutor_.readTkMapConfiguration(
0138             detCabling_, &eSetup.getData(tkDetMapTokenBR_), &eSetup.getData(tTopoTokenBR_))) {
0139       edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: Error to read configuration file!! TrackerMap "
0140                                          "will not be produced!!!";
0141     }
0142   }
0143   condDataMon_.beginRun(run.run(), eSetup);
0144   if (globalStatusFilling_) {
0145     auto& dqm_store = *edm::Service<DQMStore>{};
0146     actionExecutor_.createStatus(dqm_store);
0147   }
0148 }
0149 
0150 void SiStripAnalyser::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) {
0151   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: Begin of LS transition";
0152 }
0153 
0154 void SiStripAnalyser::analyze(edm::Event const& e, edm::EventSetup const& eSetup) {
0155   ++nEvents_;
0156   if (nEvents_ == 1 && globalStatusFilling_ > 0) {
0157     checkTrackerFEDs(e);
0158     if (!trackerFEDsFound_) {
0159       actionExecutor_.fillDummyStatus();
0160       actionExecutor_.createDummyShiftReport();
0161     } else {
0162       auto& dqm_store = *edm::Service<DQMStore>{};
0163       actionExecutor_.fillStatus(dqm_store, detCabling_, &eSetup.getData(tkDetMapToken_), &eSetup.getData(tTopoToken_));
0164       if (shiftReportFrequency_ != -1)
0165         actionExecutor_.createShiftReport(dqm_store);
0166     }
0167   }
0168 }
0169 
0170 void SiStripAnalyser::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) {
0171   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: End of LS transition, "
0172                                      "performing the DQM client operation";
0173   ++nLumiSecs_;
0174 
0175   if (!trackerFEDsFound_) {
0176     actionExecutor_.fillDummyStatus();
0177     return;
0178   }
0179   endLumiAnalysisOn_ = true;
0180 
0181   std::cout << "====================================================== " << std::endl;
0182   std::cout << " ===> Iteration # " << nLumiSecs_ << " " << lumiSeg.luminosityBlock() << std::endl;
0183   std::cout << "====================================================== " << std::endl;
0184 
0185   auto& dqm_store = *edm::Service<DQMStore>{};
0186   // Fill Global Status
0187   if (globalStatusFilling_ > 0) {
0188     actionExecutor_.fillStatus(
0189         dqm_store, detCabling_, &eSetup.getData(tkDetMapTokenELB_), &eSetup.getData(tTopoTokenELB_));
0190   }
0191   // -- Create summary monitor elements according to the frequency
0192   if (summaryFrequency_ != -1 && nLumiSecs_ > 0 && nLumiSecs_ % summaryFrequency_ == 0) {
0193     std::cout << " Creating Summary " << std::endl;
0194     actionExecutor_.createSummary(dqm_store);
0195   }
0196   endLumiAnalysisOn_ = false;
0197 }
0198 
0199 void SiStripAnalyser::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0200   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: End of Run";
0201 }
0202 
0203 void SiStripAnalyser::endJob() {
0204   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: endjob called!";
0205   if (printFaultyModuleList_) {
0206     std::ostringstream str_val;
0207     auto& dqm_store = *edm::Service<DQMStore>{};
0208     actionExecutor_.printFaultyModuleList(dqm_store, str_val);
0209     std::cout << str_val.str() << std::endl;
0210   }
0211 }
0212 
0213 void SiStripAnalyser::checkTrackerFEDs(edm::Event const& e) {
0214   edm::Handle<FEDRawDataCollection> rawDataHandle;
0215   e.getByToken(rawDataToken_, rawDataHandle);
0216   if (!rawDataHandle.isValid())
0217     return;
0218 
0219   auto const& rawDataCollection = *rawDataHandle;
0220   constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
0221   constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
0222 
0223   for (int i = siStripFedIdMin; i <= siStripFedIdMax; ++i) {
0224     auto const& fedData = rawDataCollection.FEDData(i);
0225     if (fedData.size() && fedData.data()) {
0226       trackerFEDsFound_ = true;
0227       return;
0228     }
0229   }
0230 }
0231 #include "FWCore/Framework/interface/MakerMacros.h"
0232 DEFINE_FWK_MODULE(SiStripAnalyser);