Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-27 06:44:03

0001 #include "DQM/EcalCommon/interface/DQWorker.h"
0002 
0003 #include "DQM/EcalCommon/interface/MESetUtils.h"
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 
0010 #include "DataFormats/Provenance/interface/EventID.h"
0011 
0012 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0013 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0014 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0015 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0016 
0017 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0018 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0019 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0020 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0021 #include "FWCore/Framework/interface/ConsumesCollector.h"
0022 
0023 namespace ecaldqm {
0024   DQWorker::DQWorker()
0025       : name_(""),
0026         MEs_(),
0027         booked_(false),
0028         timestamp_(),
0029         verbosity_(0),
0030         onlineMode_(false),
0031         willConvertToEDM_(true),
0032         edso_() {}
0033 
0034   DQWorker::~DQWorker() noexcept(false) {}
0035 
0036   /*static*/
0037   void DQWorker::fillDescriptions(edm::ParameterSetDescription &_desc) {
0038     _desc.addUntracked<bool>("onlineMode", false);
0039     _desc.addUntracked<bool>("willConvertToEDM", true);
0040 
0041     edm::ParameterSetDescription meParameters;
0042     edm::ParameterSetDescription meNodeParameters;
0043     fillMESetDescriptions(meNodeParameters);
0044     meParameters.addNode(
0045         edm::ParameterWildcard<edm::ParameterSetDescription>("*", edm::RequireZeroOrMore, false, meNodeParameters));
0046     _desc.addUntracked("MEs", meParameters);
0047 
0048     edm::ParameterSetDescription workerParameters;
0049     workerParameters.setUnknown();
0050     _desc.addUntracked("params", workerParameters);
0051   }
0052 
0053   void DQWorker::setTokens(edm::ConsumesCollector &_collector) {
0054     elecMapHandle = _collector.esConsumes<edm::Transition::BeginRun>();
0055     ttMapHandle = _collector.esConsumes<edm::Transition::BeginRun>();
0056     geomHandle = _collector.esConsumes<edm::Transition::BeginRun>();
0057     topoHandle = _collector.esConsumes<edm::Transition::BeginRun>();
0058 
0059     elecMapHandleEndLumi = _collector.esConsumes<edm::Transition::EndLuminosityBlock>();
0060     ttMapHandleEndLumi = _collector.esConsumes<edm::Transition::EndLuminosityBlock>();
0061     geomHandleEndLumi = _collector.esConsumes<edm::Transition::EndLuminosityBlock>();
0062     topoHandleEndLumi = _collector.esConsumes<edm::Transition::EndLuminosityBlock>();
0063   }
0064 
0065   void DQWorker::initialize(std::string const &_name, edm::ParameterSet const &_commonParams) {
0066     name_ = _name;
0067     onlineMode_ = _commonParams.getUntrackedParameter<bool>("onlineMode");
0068     willConvertToEDM_ = _commonParams.getUntrackedParameter<bool>("willConvertToEDM");
0069   }
0070 
0071   void DQWorker::setME(edm::ParameterSet const &_meParams) {
0072     std::vector<std::string> const &MENames(_meParams.getParameterNames());
0073 
0074     for (unsigned iME(0); iME != MENames.size(); iME++) {
0075       std::string name(MENames[iME]);
0076       edm::ParameterSet const &params(_meParams.getUntrackedParameterSet(name));
0077 
0078       if (!onlineMode_ && params.getUntrackedParameter<bool>("online"))
0079         continue;
0080 
0081       try {
0082         MEs_.insert(name, createMESet(params));
0083       } catch (std::exception &) {
0084         edm::LogError("EcalDQM") << "Exception caught while constructing MESet " << name;
0085         throw;
0086       }
0087     }
0088   }
0089 
0090   void DQWorker::releaseMEs() {
0091     for (MESetCollection::iterator mItr(MEs_.begin()); mItr != MEs_.end(); ++mItr)
0092       mItr->second->clear();
0093     booked_ = false;
0094   }
0095 
0096   void DQWorker::bookMEs(DQMStore::IBooker &_booker) {
0097     if (booked_)
0098       return;
0099     for (MESetCollection::iterator mItr(MEs_.begin()); mItr != MEs_.end(); ++mItr)
0100       mItr->second->book(_booker, GetElectronicsMap());
0101     booked_ = true;
0102   }
0103 
0104   void DQWorker::setSetupObjects(edm::EventSetup const &_es) {
0105     edso_.electronicsMap = &_es.getData(elecMapHandle);
0106     edso_.trigtowerMap = &_es.getData(ttMapHandle);
0107     edso_.geometry = &_es.getData(geomHandle);
0108     edso_.topology = &_es.getData(topoHandle);
0109   }
0110 
0111   void DQWorker::setSetupObjectsEndLumi(edm::EventSetup const &_es) {
0112     edso_.electronicsMap = &_es.getData(elecMapHandleEndLumi);
0113     edso_.trigtowerMap = &_es.getData(ttMapHandleEndLumi);
0114     edso_.geometry = &_es.getData(geomHandleEndLumi);
0115     edso_.topology = &_es.getData(topoHandleEndLumi);
0116   }
0117 
0118   bool DQWorker::checkElectronicsMap(bool doThrow /* = true*/) {
0119     if (edso_.electronicsMap)
0120       return true;
0121     if (doThrow)
0122       throw cms::Exception("InvalidCall") << "Electronics Mapping not initialized";
0123     return false;
0124   }
0125 
0126   bool DQWorker::checkTrigTowerMap(bool doThrow /* = true*/) {
0127     if (edso_.trigtowerMap)
0128       return true;
0129     if (doThrow)
0130       throw cms::Exception("InvalidCall") << "TrigTowerConstituentsMap not initialized";
0131     return false;
0132   }
0133 
0134   bool DQWorker::checkGeometry(bool doThrow /* = true*/) {
0135     if (edso_.geometry)
0136       return true;
0137     if (doThrow)
0138       throw cms::Exception("InvalidCall") << "CaloGeometry not initialized";
0139     return false;
0140   }
0141 
0142   bool DQWorker::checkTopology(bool doThrow /* = true*/) {
0143     if (edso_.topology)
0144       return true;
0145     if (doThrow)
0146       throw cms::Exception("InvalidCall") << "CaloTopology not initialized";
0147     return false;
0148   }
0149 
0150   EcalElectronicsMapping const *DQWorker::GetElectronicsMap() {
0151     checkElectronicsMap();
0152     return edso_.electronicsMap;
0153   }
0154 
0155   EcalTrigTowerConstituentsMap const *DQWorker::GetTrigTowerMap() {
0156     checkTrigTowerMap();
0157     return edso_.trigtowerMap;
0158   }
0159 
0160   CaloGeometry const *DQWorker::GetGeometry() {
0161     checkGeometry();
0162     return edso_.geometry;
0163   }
0164 
0165   CaloTopology const *DQWorker::GetTopology() {
0166     checkTopology();
0167     return edso_.topology;
0168   }
0169 
0170   EcalDQMSetupObjects const DQWorker::getEcalDQMSetupObjects() {
0171     checkElectronicsMap();
0172     checkTrigTowerMap();
0173     checkGeometry();
0174     checkTopology();
0175     return edso_;
0176   }
0177 
0178   void DQWorker::print_(std::string const &_message, int _threshold /* = 0*/) const {
0179     if (verbosity_ > _threshold)
0180       edm::LogInfo("EcalDQM") << name_ << ": " << _message;
0181   }
0182 
0183   DQWorker *WorkerFactoryStore::getWorker(std::string const &_name,
0184                                           int _verbosity,
0185                                           edm::ParameterSet const &_commonParams,
0186                                           edm::ParameterSet const &_workerParams) const {
0187     DQWorker *worker(workerFactories_.at(_name)());
0188     worker->setVerbosity(_verbosity);
0189     worker->initialize(_name, _commonParams);
0190     worker->setME(_workerParams.getUntrackedParameterSet("MEs"));
0191     if (_workerParams.existsAs<edm::ParameterSet>("sources", false))
0192       worker->setSource(_workerParams.getUntrackedParameterSet("sources"));
0193     if (_workerParams.existsAs<edm::ParameterSet>("params", false))
0194       worker->setParams(_workerParams.getUntrackedParameterSet("params"));
0195     return worker;
0196   }
0197 
0198   /*static*/
0199   WorkerFactoryStore *WorkerFactoryStore::singleton() {
0200     static WorkerFactoryStore workerFactoryStore;
0201     return &workerFactoryStore;
0202   }
0203 
0204 }  // namespace ecaldqm