Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:11

0001 #ifndef DQWorker_H
0002 #define DQWorker_H
0003 
0004 #include <map>
0005 #include <string>
0006 #include <vector>
0007 
0008 #include "DQM/EcalCommon/interface/MESet.h"
0009 
0010 #include "DataFormats/Provenance/interface/EventID.h"
0011 #include "DataFormats/Provenance/interface/RunID.h"
0012 
0013 #include "oneapi/tbb/concurrent_unordered_map.h"
0014 
0015 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0016 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0017 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
0018 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0019 
0020 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0021 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0022 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0023 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0024 
0025 #include "FWCore/Framework/interface/ConsumesCollector.h"
0026 #include "FWCore/Framework/interface/ESHandle.h"
0027 namespace edm {
0028   class Run;
0029   class LuminosityBlock;
0030   class Event;
0031   class EventSetup;
0032   class ParameterSet;
0033   class ParameterSetDescription;
0034   class ConsumesCollector;
0035 }  // namespace edm
0036 
0037 namespace ecaldqm {
0038 
0039   class WorkerFactoryStore;
0040 
0041   class DQWorker {
0042     friend class WorkerFactoryStore;
0043 
0044   private:
0045     struct Timestamp {
0046       time_t now;
0047       edm::RunNumber_t iRun;
0048       edm::LuminosityBlockNumber_t iLumi;
0049       edm::EventNumber_t iEvt;
0050       Timestamp() : now(0), iRun(0), iLumi(0), iEvt(0) {}
0051     };
0052 
0053   protected:
0054     typedef dqm::legacy::DQMStore DQMStore;
0055     typedef dqm::legacy::MonitorElement MonitorElement;
0056 
0057     void setVerbosity(int _verbosity) { verbosity_ = _verbosity; }
0058     void initialize(std::string const &_name, edm::ParameterSet const &);
0059 
0060     virtual void setME(edm::ParameterSet const &);
0061     virtual void setSource(edm::ParameterSet const &) {}  // for clients
0062     virtual void setParams(edm::ParameterSet const &) {}
0063 
0064   public:
0065     DQWorker();
0066     virtual ~DQWorker() noexcept(false);
0067 
0068     static void fillDescriptions(edm::ParameterSetDescription &_desc);
0069     void setTokens(edm::ConsumesCollector &);
0070 
0071     virtual void beginRun(edm::Run const &, edm::EventSetup const &) {}
0072     virtual void endRun(edm::Run const &, edm::EventSetup const &) {}
0073 
0074     virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
0075     virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
0076 
0077     virtual void bookMEs(DQMStore::IBooker &);
0078     virtual void releaseMEs();
0079 
0080     // old ecaldqmGetSetupObjects (old global vars)
0081     // These are objects obtained from EventSetup and stored
0082     // inside each module (which inherit from DQWorker).
0083     // Before, EcalCommon functions could access these through
0084     // global functions, but now we need to pass them from the
0085     // modules to functions in EcalCommon, such as in
0086     // EcalDQMCommonUtils, MESetBinningUtils, all MESets, etc.
0087     //
0088     // The global variables were removed as they were against
0089     // CMSSW rules, and potentially led to undefined behavior
0090     // (data race) at IOV boundaries. They also relied on a mutex
0091     // which leads to poor multi-threading performance.
0092     // Original issue here:
0093     // https://github.com/cms-sw/cmssw/issues/28858
0094 
0095     void setSetupObjects(edm::EventSetup const &);
0096     void setSetupObjectsEndLumi(edm::EventSetup const &);
0097 
0098     bool checkElectronicsMap(bool = true);
0099     bool checkTrigTowerMap(bool = true);
0100     bool checkGeometry(bool = true);
0101     bool checkTopology(bool = true);
0102 
0103     EcalElectronicsMapping const *GetElectronicsMap();
0104     EcalTrigTowerConstituentsMap const *GetTrigTowerMap();
0105     CaloGeometry const *GetGeometry();
0106     CaloTopology const *GetTopology();
0107     EcalDQMSetupObjects const getEcalDQMSetupObjects();
0108 
0109     edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> elecMapHandle;
0110     edm::ESGetToken<EcalTrigTowerConstituentsMap, IdealGeometryRecord> ttMapHandle;
0111     edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomHandle;
0112     edm::ESGetToken<CaloTopology, CaloTopologyRecord> topoHandle;
0113 
0114     edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> elecMapHandleEndLumi;
0115     edm::ESGetToken<EcalTrigTowerConstituentsMap, IdealGeometryRecord> ttMapHandleEndLumi;
0116     edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geomHandleEndLumi;
0117     edm::ESGetToken<CaloTopology, CaloTopologyRecord> topoHandleEndLumi;
0118 
0119     void setTime(time_t _t) { timestamp_.now = _t; }
0120     void setRunNumber(edm::RunNumber_t _r) { timestamp_.iRun = _r; }
0121     void setLumiNumber(edm::LuminosityBlockNumber_t _l) { timestamp_.iLumi = _l; }
0122     void setEventNumber(edm::EventNumber_t _e) { timestamp_.iEvt = _e; }
0123 
0124     std::string const &getName() const { return name_; }
0125     bool onlineMode() const { return onlineMode_; }
0126 
0127   protected:
0128     void print_(std::string const &, int = 0) const;
0129 
0130     std::string name_;
0131     MESetCollection MEs_;
0132     bool booked_;
0133 
0134     Timestamp timestamp_;
0135     int verbosity_;
0136 
0137     // common parameters
0138     bool onlineMode_;
0139     bool willConvertToEDM_;
0140 
0141   private:
0142     EcalDQMSetupObjects edso_;
0143   };
0144 
0145   typedef DQWorker *(*WorkerFactory)();
0146 
0147   // to be instantiated after the implementation of each worker module
0148   class WorkerFactoryStore {
0149   public:
0150     template <typename Worker>
0151     struct Registration {
0152       Registration(std::string const &_name) {
0153         WorkerFactoryStore::singleton()->registerFactory(_name, []() -> DQWorker * { return new Worker(); });
0154       }
0155     };
0156 
0157     void registerFactory(std::string const &_name, WorkerFactory _f) { workerFactories_[_name] = _f; }
0158     DQWorker *getWorker(std::string const &, int, edm::ParameterSet const &, edm::ParameterSet const &) const;
0159 
0160     static WorkerFactoryStore *singleton();
0161 
0162   private:
0163     tbb::concurrent_unordered_map<std::string, WorkerFactory> workerFactories_;
0164   };
0165 
0166 }  // namespace ecaldqm
0167 
0168 #define DEFINE_ECALDQM_WORKER(TYPE) WorkerFactoryStore::Registration<TYPE> ecaldqm##TYPE##Registration(#TYPE)
0169 
0170 #endif