Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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