Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:44

0001 /*
0002  * \file SiStripAnalyser.cc
0003  *
0004  * \author  S. Dutta INFN-Pisa
0005  *
0006  */
0007 
0008 #include "SiStripAnalyser.h"
0009 
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/LuminosityBlock.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/ParameterSet/interface/FileInPath.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ServiceRegistry/interface/Service.h"
0016 #include "FWCore/Utilities/interface/InputTag.h"
0017 
0018 #include "DQMServices/Core/interface/DQMStore.h"
0019 
0020 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0021 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0022 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0023 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0024 
0025 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0026 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
0027 
0028 #include <cmath>
0029 #include <cstdio>
0030 #include <iomanip>
0031 #include <iostream>
0032 #include <sstream>
0033 #include <string>
0034 
0035 SiStripAnalyser::SiStripAnalyser(edm::ParameterSet const& ps)
0036     : condDataMon_{ps, consumesCollector()},
0037       actionExecutor_{ps},
0038       tkMapPSet_{ps.getParameter<edm::ParameterSet>("TkmapParameters")},
0039       summaryFrequency_{ps.getUntrackedParameter<int>("SummaryCreationFrequency", 1)},
0040       staticUpdateFrequency_{ps.getUntrackedParameter<int>("StaticUpdateFrequency", 1)},
0041       globalStatusFilling_{ps.getUntrackedParameter<int>("GlobalStatusFilling", 1)},
0042       shiftReportFrequency_{ps.getUntrackedParameter<int>("ShiftReportFrequency", 1)},
0043       rawDataToken_{consumes<FEDRawDataCollection>(ps.getUntrackedParameter<edm::InputTag>("RawDataTag"))},
0044       detCablingToken_(esConsumes<edm::Transition::BeginRun>()),
0045       tTopoToken_(esConsumes()),
0046       tTopoTokenELB_(esConsumes<edm::Transition::EndLuminosityBlock>()),
0047       tTopoTokenBR_(esConsumes<edm::Transition::BeginRun>()),
0048       tkDetMapToken_(esConsumes()),
0049       tkDetMapTokenELB_(esConsumes<edm::Transition::EndLuminosityBlock>()),
0050       tkDetMapTokenBR_(esConsumes<edm::Transition::BeginRun>()),
0051       printFaultyModuleList_{ps.getUntrackedParameter<bool>("PrintFaultyModuleList", true)} {
0052   std::string const localPath{"DQM/SiStripMonitorClient/test/loader.html"};
0053   std::ifstream fin{edm::FileInPath(localPath).fullPath(), std::ios::in};
0054   if (!fin) {
0055     std::cerr << "Input File: loader.html"
0056               << " could not be opened!" << std::endl;
0057     return;
0058   }
0059   edm::LogInfo("SiStripAnalyser") << " SiStripAnalyser::Creating SiStripAnalyser ";
0060 }
0061 
0062 SiStripAnalyser::~SiStripAnalyser() { edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser::Deleting SiStripAnalyser "; }
0063 
0064 void SiStripAnalyser::beginJob() {
0065   // Read the summary configuration file
0066   if (!actionExecutor_.readConfiguration()) {
0067     edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: Error to read configuration file!! Summary will "
0068                                        "not be produced!!!";
0069   }
0070 }
0071 
0072 void SiStripAnalyser::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0073   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: Begining of Run";
0074 
0075   // Check latest Fed cabling and create TrackerMapCreator
0076   if (fedCablingWatcher_.check(eSetup)) {
0077     edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser::beginRun: "
0078                                     << " Change in Cabling, recrated TrackerMap";
0079     detCabling_ = &eSetup.getData(detCablingToken_);
0080     if (!actionExecutor_.readTkMapConfiguration(
0081             detCabling_, &eSetup.getData(tkDetMapTokenBR_), &eSetup.getData(tTopoTokenBR_))) {
0082       edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: Error to read configuration file!! TrackerMap "
0083                                          "will not be produced!!!";
0084     }
0085   }
0086   condDataMon_.beginRun(run.run(), eSetup);
0087   if (globalStatusFilling_) {
0088     auto& dqm_store = *edm::Service<DQMStore>{};
0089     actionExecutor_.createStatus(dqm_store);
0090   }
0091 }
0092 
0093 void SiStripAnalyser::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) {
0094   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: Begin of LS transition";
0095 }
0096 
0097 void SiStripAnalyser::analyze(edm::Event const& e, edm::EventSetup const& eSetup) {
0098   ++nEvents_;
0099   if (nEvents_ == 1 && globalStatusFilling_ > 0) {
0100     checkTrackerFEDs(e);
0101     if (!trackerFEDsFound_) {
0102       actionExecutor_.fillDummyStatus();
0103       actionExecutor_.createDummyShiftReport();
0104     } else {
0105       auto& dqm_store = *edm::Service<DQMStore>{};
0106       actionExecutor_.fillStatus(dqm_store, detCabling_, &eSetup.getData(tkDetMapToken_), &eSetup.getData(tTopoToken_));
0107       if (shiftReportFrequency_ != -1)
0108         actionExecutor_.createShiftReport(dqm_store);
0109     }
0110   }
0111 }
0112 
0113 void SiStripAnalyser::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) {
0114   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: End of LS transition, "
0115                                      "performing the DQM client operation";
0116   ++nLumiSecs_;
0117 
0118   if (!trackerFEDsFound_) {
0119     actionExecutor_.fillDummyStatus();
0120     return;
0121   }
0122   endLumiAnalysisOn_ = true;
0123 
0124   std::cout << "====================================================== " << std::endl;
0125   std::cout << " ===> Iteration # " << nLumiSecs_ << " " << lumiSeg.luminosityBlock() << std::endl;
0126   std::cout << "====================================================== " << std::endl;
0127 
0128   auto& dqm_store = *edm::Service<DQMStore>{};
0129   // Fill Global Status
0130   if (globalStatusFilling_ > 0) {
0131     actionExecutor_.fillStatus(
0132         dqm_store, detCabling_, &eSetup.getData(tkDetMapTokenELB_), &eSetup.getData(tTopoTokenELB_));
0133   }
0134   // -- Create summary monitor elements according to the frequency
0135   if (summaryFrequency_ != -1 && nLumiSecs_ > 0 && nLumiSecs_ % summaryFrequency_ == 0) {
0136     std::cout << " Creating Summary " << std::endl;
0137     actionExecutor_.createSummary(dqm_store);
0138   }
0139   endLumiAnalysisOn_ = false;
0140 }
0141 
0142 void SiStripAnalyser::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0143   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: End of Run";
0144 }
0145 
0146 void SiStripAnalyser::endJob() {
0147   edm::LogInfo("SiStripAnalyser") << "SiStripAnalyser:: endjob called!";
0148   if (printFaultyModuleList_) {
0149     std::ostringstream str_val;
0150     auto& dqm_store = *edm::Service<DQMStore>{};
0151     actionExecutor_.printFaultyModuleList(dqm_store, str_val);
0152     std::cout << str_val.str() << std::endl;
0153   }
0154 }
0155 
0156 void SiStripAnalyser::checkTrackerFEDs(edm::Event const& e) {
0157   edm::Handle<FEDRawDataCollection> rawDataHandle;
0158   e.getByToken(rawDataToken_, rawDataHandle);
0159   if (!rawDataHandle.isValid())
0160     return;
0161 
0162   auto const& rawDataCollection = *rawDataHandle;
0163   constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
0164   constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
0165 
0166   for (int i = siStripFedIdMin; i <= siStripFedIdMax; ++i) {
0167     auto const& fedData = rawDataCollection.FEDData(i);
0168     if (fedData.size() && fedData.data()) {
0169       trackerFEDsFound_ = true;
0170       return;
0171     }
0172   }
0173 }
0174 #include "FWCore/Framework/interface/MakerMacros.h"
0175 DEFINE_FWK_MODULE(SiStripAnalyser);