CMS 3D CMS Logo

DQWorker.h
Go to the documentation of this file.
1 #ifndef DQWorker_H
2 #define DQWorker_H
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 
9 
12 
13 #include "oneapi/tbb/concurrent_unordered_map.h"
14 
19 
24 
27 namespace edm {
28  class Run;
29  class LuminosityBlock;
30  class Event;
31  class EventSetup;
32  class ParameterSet;
34  class ConsumesCollector;
35 } // namespace edm
36 
37 namespace ecaldqm {
38 
39  class WorkerFactoryStore;
40 
41  class DQWorker {
42  friend class WorkerFactoryStore;
43 
44  private:
45  struct Timestamp {
46  time_t now;
50  Timestamp() : now(0), iRun(0), iLumi(0), iEvt(0) {}
51  };
52 
53  protected:
56 
57  void setVerbosity(int _verbosity) { verbosity_ = _verbosity; }
58  void initialize(std::string const &_name, edm::ParameterSet const &);
59 
60  virtual void setME(edm::ParameterSet const &);
61  virtual void setSource(edm::ParameterSet const &) {} // for clients
62  virtual void setParams(edm::ParameterSet const &) {}
63 
64  public:
65  DQWorker();
66  virtual ~DQWorker() noexcept(false);
67 
68  static void fillDescriptions(edm::ParameterSetDescription &_desc);
69  void setTokens(edm::ConsumesCollector &);
70 
71  virtual void beginRun(edm::Run const &, edm::EventSetup const &) {}
72  virtual void endRun(edm::Run const &, edm::EventSetup const &) {}
73 
74  virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
75  virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
76 
77  virtual void bookMEs(DQMStore::IBooker &);
78  virtual void releaseMEs();
79 
80  // old ecaldqmGetSetupObjects (old global vars)
81  // These are objects obtained from EventSetup and stored
82  // inside each module (which inherit from DQWorker).
83  // Before, EcalCommon functions could access these through
84  // global functions, but now we need to pass them from the
85  // modules to functions in EcalCommon, such as in
86  // EcalDQMCommonUtils, MESetBinningUtils, all MESets, etc.
87  //
88  // The global variables were removed as they were against
89  // CMSSW rules, and potentially led to undefined behavior
90  // (data race) at IOV boundaries. They also relied on a mutex
91  // which leads to poor multi-threading performance.
92  // Original issue here:
93  // https://github.com/cms-sw/cmssw/issues/28858
94 
95  void setSetupObjects(edm::EventSetup const &);
97 
98  bool checkElectronicsMap(bool = true);
99  bool checkTrigTowerMap(bool = true);
100  bool checkGeometry(bool = true);
101  bool checkTopology(bool = true);
102 
105  CaloGeometry const *GetGeometry();
106  CaloTopology const *GetTopology();
108 
113 
118 
119  void setTime(time_t _t) { timestamp_.now = _t; }
123 
124  std::string const &getName() const { return name_; }
125  bool onlineMode() const { return onlineMode_; }
126 
127  protected:
128  void print_(std::string const &, int = 0) const;
129 
132  bool booked_;
133 
136 
137  // common parameters
140 
141  private:
143  };
144 
145  typedef DQWorker *(*WorkerFactory)();
146 
147  // to be instantiated after the implementation of each worker module
149  public:
150  template <typename Worker>
151  struct Registration {
152  Registration(std::string const &_name) {
153  WorkerFactoryStore::singleton()->registerFactory(_name, []() -> DQWorker * { return new Worker(); });
154  }
155  };
156 
157  void registerFactory(std::string const &_name, WorkerFactory _f) { workerFactories_[_name] = _f; }
158  DQWorker *getWorker(std::string const &, int, edm::ParameterSet const &, edm::ParameterSet const &) const;
159 
160  static WorkerFactoryStore *singleton();
161 
162  private:
163  tbb::concurrent_unordered_map<std::string, WorkerFactory> workerFactories_;
164  };
165 
166 } // namespace ecaldqm
167 
168 #define DEFINE_ECALDQM_WORKER(TYPE) WorkerFactoryStore::Registration<TYPE> ecaldqm##TYPE##Registration(#TYPE)
169 
170 #endif
void setSetupObjectsEndLumi(edm::EventSetup const &)
Definition: DQWorker.cc:111
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomHandleEndLumi
Definition: DQWorker.h:116
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > elecMapHandleEndLumi
Definition: DQWorker.h:114
dqm::legacy::DQMStore DQMStore
Definition: DQWorker.h:54
virtual void endRun(edm::Run const &, edm::EventSetup const &)
Definition: DQWorker.h:72
edm::LuminosityBlockNumber_t iLumi
Definition: DQWorker.h:48
bool onlineMode() const
Definition: DQWorker.h:125
void print_(std::string const &, int=0) const
Definition: DQWorker.cc:178
bool checkElectronicsMap(bool=true)
Definition: DQWorker.cc:118
std::string const & getName() const
Definition: DQWorker.h:124
bool willConvertToEDM_
Definition: DQWorker.h:139
EcalDQMSetupObjects edso_
Definition: DQWorker.h:142
bool checkGeometry(bool=true)
Definition: DQWorker.cc:134
unsigned long long EventNumber_t
static WorkerFactoryStore * singleton()
Definition: DQWorker.cc:199
virtual void releaseMEs()
Definition: DQWorker.cc:90
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomHandle
Definition: DQWorker.h:111
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
Definition: DQWorker.h:71
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: DQWorker.h:74
CaloTopology const * GetTopology()
Definition: DQWorker.cc:165
CaloGeometry const * GetGeometry()
Definition: DQWorker.cc:160
unsigned int LuminosityBlockNumber_t
void setLumiNumber(edm::LuminosityBlockNumber_t _l)
Definition: DQWorker.h:121
DQWorker * getWorker(std::string const &, int, edm::ParameterSet const &, edm::ParameterSet const &) const
Definition: DQWorker.cc:183
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: DQWorker.h:75
void setEventNumber(edm::EventNumber_t _e)
Definition: DQWorker.h:122
void registerFactory(std::string const &_name, WorkerFactory _f)
Definition: DQWorker.h:157
DQWorker *(* WorkerFactory)()
Definition: DQWorker.h:145
void setRunNumber(edm::RunNumber_t _r)
Definition: DQWorker.h:120
edm::RunNumber_t iRun
Definition: DQWorker.h:47
virtual void bookMEs(DQMStore::IBooker &)
Definition: DQWorker.cc:96
EcalElectronicsMapping const * GetElectronicsMap()
Definition: DQWorker.cc:150
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:170
virtual void setME(edm::ParameterSet const &)
Definition: DQWorker.cc:71
Timestamp timestamp_
Definition: DQWorker.h:134
void initialize(std::string const &_name, edm::ParameterSet const &)
Definition: DQWorker.cc:65
tbb::concurrent_unordered_map< std::string, WorkerFactory > workerFactories_
Definition: DQWorker.h:163
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > elecMapHandle
Definition: DQWorker.h:109
static void fillDescriptions(edm::ParameterSetDescription &_desc)
Definition: DQWorker.cc:37
edm::EventNumber_t iEvt
Definition: DQWorker.h:49
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > ttMapHandleEndLumi
Definition: DQWorker.h:115
MESetCollection MEs_
Definition: DQWorker.h:131
virtual void setParams(edm::ParameterSet const &)
Definition: DQWorker.h:62
HLT enums.
edm::ESGetToken< CaloTopology, CaloTopologyRecord > topoHandle
Definition: DQWorker.h:112
void setTokens(edm::ConsumesCollector &)
Definition: DQWorker.cc:53
edm::ESGetToken< CaloTopology, CaloTopologyRecord > topoHandleEndLumi
Definition: DQWorker.h:117
void setVerbosity(int _verbosity)
Definition: DQWorker.h:57
unsigned int RunNumber_t
EcalTrigTowerConstituentsMap const * GetTrigTowerMap()
Definition: DQWorker.cc:155
void setSetupObjects(edm::EventSetup const &)
Definition: DQWorker.cc:104
dqm::legacy::MonitorElement MonitorElement
Definition: DQWorker.h:55
virtual ~DQWorker() noexcept(false)
Definition: DQWorker.cc:34
bool checkTrigTowerMap(bool=true)
Definition: DQWorker.cc:126
void setTime(time_t _t)
Definition: DQWorker.h:119
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > ttMapHandle
Definition: DQWorker.h:110
Registration(std::string const &_name)
Definition: DQWorker.h:152
std::string name_
Definition: DQWorker.h:130
bool checkTopology(bool=true)
Definition: DQWorker.cc:142
virtual void setSource(edm::ParameterSet const &)
Definition: DQWorker.h:61
Definition: Run.h:45