Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:09

0001 #include "DQM/TrackingMonitorClient/plugins/TrackingAnalyzer.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "FWCore/Framework/interface/LuminosityBlock.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "FWCore/ParameterSet/interface/FileInPath.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 
0012 #include "DQMServices/Core/interface/DQMStore.h"
0013 
0014 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0015 
0016 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0017 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0018 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0019 
0020 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
0021 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0022 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0023 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0024 
0025 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0026 #include "DQM/TrackingMonitorClient/interface/TrackingActionExecutor.h"
0027 #include "DQM/TrackingMonitorClient/interface/TrackingUtility.h"
0028 
0029 #include <iomanip>
0030 #include <cstdio>
0031 #include <string>
0032 #include <sstream>
0033 #include <cmath>
0034 
0035 #define BUF_SIZE 256
0036 
0037 //
0038 // -- Constructor
0039 //
0040 TrackingAnalyser::TrackingAnalyser(edm::ParameterSet const& ps)
0041     : verbose_(ps.getUntrackedParameter<bool>("verbose", false)),
0042       fedCablingToken_(esConsumes<SiStripFedCabling, SiStripFedCablingRcd, edm::Transition::BeginRun>()),
0043       detCablingToken_(esConsumes<SiStripDetCabling, SiStripDetCablingRcd, edm::Transition::BeginRun>()) {
0044   edm::LogInfo("TrackingAnalyser") << "Creating TrackingAnalyser ";
0045 
0046   // Get TkMap ParameterSet
0047   //  tkMapPSet_ = ps.getParameter<edm::ParameterSet>("TkmapParameters");
0048 
0049   std::string localPath = std::string("DQM/TrackingMonitorClient/test/loader.html");
0050   std::ifstream fin(edm::FileInPath(localPath).fullPath().c_str(), std::ios::in);
0051   char buf[BUF_SIZE];
0052 
0053   if (!fin) {
0054     edm::LogError("TrackingAnalyzer") << "Input File: loader.html"
0055                                       << " could not be opened!" << std::endl;
0056     return;
0057   }
0058 
0059   while (fin.getline(buf, BUF_SIZE, '\n')) {  // pops off the newline character
0060     html_out_ << buf;
0061   }
0062   fin.close();
0063 
0064   staticUpdateFrequency_ = ps.getUntrackedParameter<int>("StaticUpdateFrequency", 1);
0065   globalStatusFilling_ = ps.getUntrackedParameter<int>("GlobalStatusFilling", 1);
0066   shiftReportFrequency_ = ps.getUntrackedParameter<int>("ShiftReportFrequency", 1);
0067 
0068   edm::InputTag rawDataTag = ps.getUntrackedParameter<edm::InputTag>("RawDataTag");
0069   rawDataToken_ = consumes<FEDRawDataCollection>(rawDataTag);
0070 
0071   // instantiate web interface
0072   actionExecutor_ = new TrackingActionExecutor(ps);
0073   trackerFEDsFound_ = false;
0074   trackerFEDsWdataFound_ = false;
0075 
0076   nFEDinfoDir_ = ps.getParameter<std::string>("nFEDinfoDir");
0077   nFEDinVsLSname_ = ps.getParameter<std::string>("nFEDinVsLSname");
0078   nFEDinWdataVsLSname_ = ps.getParameter<std::string>("nFEDinWdataVsLSname");
0079 }
0080 //
0081 // -- Destructor
0082 //
0083 TrackingAnalyser::~TrackingAnalyser() { edm::LogInfo("TrackingAnalyser") << "Deleting TrackingAnalyser "; }
0084 //
0085 // -- Begin Job
0086 //
0087 void TrackingAnalyser::beginJob() { nLumiSecs_ = 0; }
0088 //
0089 // -- Begin Run
0090 //
0091 void TrackingAnalyser::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0092   edm::LogInfo("TrackingAnalyser") << " Begining of Run";
0093 
0094   // Check latest Fed cabling and create TrackerMapCreator
0095   if (fedCablingWatcher_.check(eSetup)) {  //this should check if cabling record has changed
0096     edm::LogInfo("TrackingAnalyser") << "beginRun: "
0097                                      << " Change in Cabling, recrated TrackerMap";
0098     fedCabling_ = &eSetup.getData(fedCablingToken_);
0099     detCabling_ = &eSetup.getData(detCablingToken_);
0100   }
0101 }
0102 //
0103 // -- Begin Luminosity Block
0104 //
0105 void TrackingAnalyser::dqmBeginLuminosityBlock(DQMStore::IBooker& ibooker_,
0106                                                DQMStore::IGetter& igetter_,
0107                                                edm::LuminosityBlock const& lumiSeg,
0108                                                edm::EventSetup const& eSetup) {
0109   edm::LogInfo("TrackingAnalyser") << " Begin of LS transition";
0110 }
0111 
0112 //
0113 // -- End Luminosity Block
0114 //
0115 void TrackingAnalyser::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker_,
0116                                              DQMStore::IGetter& igetter_,
0117                                              edm::LuminosityBlock const& lumiSeg,
0118                                              edm::EventSetup const& eSetup) {
0119   edm::LogInfo("TrackingAnalyser") << " End of LS transition, performing the DQM client operation";
0120 
0121   nLumiSecs_++;
0122 
0123   if (verbose_)
0124     edm::LogInfo("TrackingAnalyser") << "[TrackingAnalyser::endLuminosityBlock] globalStatusFilling_ "
0125                                      << (globalStatusFilling_ ? "YES" : "NOPE") << std::endl;
0126   if (globalStatusFilling_)
0127     actionExecutor_->createGlobalStatus(ibooker_, igetter_);
0128 
0129   double iLS = lumiSeg.id().luminosityBlock();
0130   checkTrackerFEDsInLS(igetter_, iLS);
0131   checkTrackerFEDsWdataInLS(igetter_, iLS);
0132   if (verbose_)
0133     edm::LogInfo("TrackingAnalyser") << "endLuminosityBlock trackerFEDsFound_ " << (trackerFEDsFound_ ? "YES" : "NOPE")
0134                                      << std::endl;
0135   if (verbose_)
0136     edm::LogInfo("TrackingAnalyser") << "endLuminosityBlock trackerFEDsWdataFound_ "
0137                                      << (trackerFEDsWdataFound_ ? "YES" : "NOPE") << std::endl;
0138 
0139   if (!trackerFEDsFound_) {
0140     actionExecutor_->fillDummyGlobalStatus();
0141     actionExecutor_->createDummyShiftReport();
0142   } else {
0143     if (trackerFEDsWdataFound_) {
0144       actionExecutor_->fillGlobalStatus(ibooker_, igetter_);
0145       if (shiftReportFrequency_ != -1)
0146         actionExecutor_->createShiftReport(ibooker_, igetter_);
0147     }
0148   }
0149 
0150   if (!trackerFEDsFound_) {
0151     actionExecutor_->fillDummyLSStatus();
0152     return;
0153   }
0154 
0155   if (verbose_)
0156     edm::LogInfo("TrackingAnalyser") << "====================================================== " << std::endl;
0157   if (verbose_)
0158     edm::LogInfo("TrackingAnalyser") << " ===> Iteration # " << nLumiSecs_ << " " << lumiSeg.luminosityBlock()
0159                                      << std::endl;
0160   if (verbose_)
0161     edm::LogInfo("TrackingAnalyser") << "====================================================== " << std::endl;
0162 }
0163 
0164 //
0165 // -- End Job
0166 //
0167 void TrackingAnalyser::dqmEndJob(DQMStore::IBooker& ibooker_, DQMStore::IGetter& igetter_) {
0168   edm::LogInfo("TrackingAnalyser") << " endjob called!";
0169 
0170   if (globalStatusFilling_)
0171     actionExecutor_->createGlobalStatus(ibooker_, igetter_);
0172   // Fill Global Status
0173   if (globalStatusFilling_ > 0) {
0174     actionExecutor_->fillGlobalStatus(ibooker_, igetter_);
0175   }
0176 }
0177 //
0178 // Check Tracker FEDs
0179 //
0180 void TrackingAnalyser::checkTrackerFEDsInLS(DQMStore::IGetter& igetter, double iLS) {
0181   double nFEDinLS = 0.;
0182   MonitorElement* tmpME = igetter.get(nFEDinfoDir_ + "/" + nFEDinVsLSname_);
0183   if (tmpME) {
0184     TProfile* tmpP = tmpME->getTProfile();
0185     size_t ibin = tmpP->GetXaxis()->FindBin(iLS);
0186     if (verbose_)
0187       edm::LogInfo("TrackingAnalyser") << "iLS: " << iLS << " ibin: " << ibin;
0188     nFEDinLS = tmpME->getBinContent(ibin);
0189     if (verbose_)
0190       edm::LogInfo("TrackingAnalyser") << " ---> nFEDinLS: " << nFEDinLS;
0191   }
0192 
0193   trackerFEDsFound_ = (nFEDinLS > 0);
0194   if (verbose_)
0195     edm::LogInfo("TrackingAnalyser") << " ---> trackerFEDsFound_: " << trackerFEDsFound_ << std::endl;
0196 }
0197 
0198 void TrackingAnalyser::checkTrackerFEDsWdataInLS(DQMStore::IGetter& igetter, double iLS) {
0199   double nFEDinLS = 0.;
0200   MonitorElement* tmpME = igetter.get(nFEDinfoDir_ + "/" + nFEDinWdataVsLSname_);
0201   if (verbose_)
0202     edm::LogInfo("TrackingAnalyser") << "found " << nFEDinfoDir_ << "/" << nFEDinWdataVsLSname_ << " ? "
0203                                      << (tmpME ? "YES" : "NOPE") << std::endl;
0204   if (tmpME) {
0205     TProfile* tmpP = tmpME->getTProfile();
0206     size_t ibin = tmpP->GetXaxis()->FindBin(iLS);
0207     if (verbose_)
0208       edm::LogInfo("TrackingAnalyser") << "iLS: " << iLS << " ibin: " << ibin;
0209     nFEDinLS = tmpME->getBinContent(ibin);
0210     if (verbose_)
0211       edm::LogInfo("TrackingAnalyser") << " ---> nFEDinLS: " << nFEDinLS;
0212   }
0213 
0214   trackerFEDsWdataFound_ = (nFEDinLS > 0);
0215   if (verbose_)
0216     edm::LogInfo("TrackingAnalyser") << " ---> trackerFEDsWdataFound_: " << trackerFEDsWdataFound_ << std::endl;
0217 }
0218 
0219 #include "FWCore/Framework/interface/MakerMacros.h"
0220 DEFINE_FWK_MODULE(TrackingAnalyser);