Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-11 03:56:56

0001 // system includes
0002 #include <iostream>
0003 #include <sstream>
0004 
0005 // user includes
0006 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0007 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
0008 #include "CalibFormats/SiStripObjects/interface/SiStripRegionCabling.h"
0009 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0010 #include "CalibTracker/Records/interface/SiStripFecCablingRcd.h"
0011 #include "CalibTracker/Records/interface/SiStripRegionCablingRcd.h"
0012 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
0013 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 
0021 class SiStripFedCablingReader : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0022 public:
0023   SiStripFedCablingReader(const edm::ParameterSet&);
0024   ~SiStripFedCablingReader() override = default;
0025 
0026   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0027   void endRun(const edm::Run&, const edm::EventSetup&) override{};
0028   void analyze(const edm::Event&, const edm::EventSetup&) override{};
0029 
0030 private:
0031   bool printFecCabling_;
0032   bool printDetCabling_;
0033   bool printRegionCabling_;
0034   const edm::ESGetToken<SiStripFedCabling, SiStripFedCablingRcd> fedCablingToken_;
0035   const edm::ESGetToken<SiStripFecCabling, SiStripFecCablingRcd> fecCablingToken_;
0036   const edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> detCablingToken_;
0037   const edm::ESGetToken<SiStripRegionCabling, SiStripRegionCablingRcd> regionCablingToken_;
0038   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0039 };
0040 
0041 // -----------------------------------------------------------------------------
0042 //
0043 SiStripFedCablingReader::SiStripFedCablingReader(const edm::ParameterSet& pset)
0044     : printFecCabling_(pset.getUntrackedParameter<bool>("PrintFecCabling", false)),
0045       printDetCabling_(pset.getUntrackedParameter<bool>("PrintDetCabling", false)),
0046       printRegionCabling_(pset.getUntrackedParameter<bool>("PrintRegionCabling", false)),
0047       fedCablingToken_(esConsumes<edm::Transition::BeginRun>()),
0048       fecCablingToken_(esConsumes<edm::Transition::BeginRun>()),
0049       detCablingToken_(esConsumes<edm::Transition::BeginRun>()),
0050       regionCablingToken_(esConsumes<edm::Transition::BeginRun>()),
0051       tTopoToken_(esConsumes<edm::Transition::BeginRun>()) {}
0052 
0053 // -----------------------------------------------------------------------------
0054 //
0055 void SiStripFedCablingReader::beginRun(const edm::Run& run, const edm::EventSetup& setup) {
0056   auto const fedRec = setup.tryToGet<SiStripFedCablingRcd>();
0057   auto const fecRec = setup.tryToGet<SiStripFecCablingRcd>();
0058   auto const detRec = setup.tryToGet<SiStripDetCablingRcd>();
0059   auto const regRec = setup.tryToGet<SiStripRegionCablingRcd>();
0060 
0061   edm::ESHandle<SiStripFedCabling> fed;
0062   if (fedRec) {
0063     edm::LogVerbatim("SiStripFedCablingReader") << "[SiStripFedCablingReader::" << __func__ << "]"
0064                                                 << " Retrieving FED cabling...";
0065     fed = setup.getHandle(fedCablingToken_);
0066   }
0067 
0068   edm::ESHandle<SiStripFecCabling> fec;
0069   if (fecRec) {
0070     edm::LogVerbatim("SiStripFedCablingReader") << "[SiStripFedCablingReader::" << __func__ << "]"
0071                                                 << " Retrieving FEC cabling...";
0072     fec = setup.getHandle(fecCablingToken_);
0073   }
0074 
0075   edm::ESHandle<SiStripDetCabling> det;
0076   if (detRec) {
0077     edm::LogVerbatim("SiStripFedCablingReader") << "[SiStripFedCablingReader::" << __func__ << "]"
0078                                                 << " Retrieving DET cabling...";
0079     det = setup.getHandle(detCablingToken_);
0080   }
0081 
0082   edm::ESHandle<SiStripRegionCabling> region;
0083   if (regRec) {
0084     edm::LogVerbatim("SiStripFedCablingReader") << "[SiStripFedCablingReader::" << __func__ << "]"
0085                                                 << " Retrieving REGION cabling...";
0086     region = setup.getHandle(regionCablingToken_);
0087   }
0088 
0089   if (!fed.isValid()) {
0090     edm::LogError("SiStripFedCablingReader") << " Invalid handle to FED cabling object: ";
0091     return;
0092   }
0093 
0094   {
0095     std::stringstream ss;
0096     ss << "[SiStripFedCablingReader::" << __func__ << "]"
0097        << " VERBOSE DEBUG" << std::endl;
0098     if (fedRec) {
0099       fed->print(ss, &setup.getData(tTopoToken_));
0100     }
0101     ss << std::endl;
0102     if (fecRec && printFecCabling_ && fec.isValid()) {
0103       fec->print(ss);
0104     }
0105     ss << std::endl;
0106     if (detRec && printDetCabling_ && det.isValid()) {
0107       det->print(ss);
0108     }
0109     ss << std::endl;
0110     if (regRec && printRegionCabling_ && region.isValid()) {
0111       region->print(ss);
0112     }
0113     ss << std::endl;
0114     edm::LogVerbatim("SiStripFedCablingReader") << ss.str();
0115   }
0116 
0117   if (fedRec) {
0118     std::stringstream ss;
0119     ss << "[SiStripFedCablingReader::" << __func__ << "]"
0120        << " TERSE DEBUG" << std::endl;
0121     fed->terse(ss);
0122     ss << std::endl;
0123     edm::LogVerbatim("SiStripFedCablingReader") << ss.str();
0124   }
0125 
0126   if (fedRec) {
0127     std::stringstream ss;
0128     ss << "[SiStripFedCablingReader::" << __func__ << "]"
0129        << " SUMMARY DEBUG" << std::endl;
0130     fed->summary(ss, &setup.getData(tTopoToken_));
0131     ss << std::endl;
0132     edm::LogVerbatim("SiStripFedCablingReader") << ss.str();
0133   }
0134 }
0135 
0136 #include "FWCore/PluginManager/interface/ModuleDef.h"
0137 #include "FWCore/Framework/interface/MakerMacros.h"
0138 
0139 DEFINE_FWK_MODULE(SiStripFedCablingReader);