CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "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 &);
99  CaloGeometry const *GetGeometry();
100  CaloTopology const *GetTopology();
102 
107 
112 
113  void setTime(time_t _t) { timestamp_.now = _t; }
117 
118  std::string const &getName() const { return name_; }
119  bool onlineMode() const { return onlineMode_; }
120 
121  protected:
122  void print_(std::string const &, int = 0) const;
123 
126  bool booked_;
127 
130 
131  // common parameters
134 
135  private:
137  };
138 
139  typedef DQWorker *(*WorkerFactory)();
140 
141  // to be instantiated after the implementation of each worker module
143  public:
144  template <typename Worker>
145  struct Registration {
146  Registration(std::string const &_name) {
147  WorkerFactoryStore::singleton()->registerFactory(_name, []() -> DQWorker * { return new Worker(); });
148  }
149  };
150 
151  void registerFactory(std::string const &_name, WorkerFactory _f) { workerFactories_[_name] = _f; }
152  DQWorker *getWorker(std::string const &, int, edm::ParameterSet const &, edm::ParameterSet const &) const;
153 
154  static WorkerFactoryStore *singleton();
155 
156  private:
157  tbb::concurrent_unordered_map<std::string, WorkerFactory> workerFactories_;
158  };
159 
160 } // namespace ecaldqm
161 
162 #define DEFINE_ECALDQM_WORKER(TYPE) WorkerFactoryStore::Registration<TYPE> ecaldqm##TYPE##Registration(#TYPE)
163 
164 #endif
void setSetupObjectsEndLumi(edm::EventSetup const &)
Definition: DQWorker.cc:111
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomHandleEndLumi
Definition: DQWorker.h:110
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > elecMapHandleEndLumi
Definition: DQWorker.h:108
DQWorker * getWorker(std::string const &, int, edm::ParameterSet const &, edm::ParameterSet const &) const
Definition: DQWorker.cc:159
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 willConvertToEDM_
Definition: DQWorker.h:133
EcalDQMSetupObjects edso_
Definition: DQWorker.h:136
unsigned long long EventNumber_t
static WorkerFactoryStore * singleton()
Definition: DQWorker.cc:175
virtual void releaseMEs()
Definition: DQWorker.cc:90
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomHandle
Definition: DQWorker.h:105
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
unsigned int LuminosityBlockNumber_t
void setLumiNumber(edm::LuminosityBlockNumber_t _l)
Definition: DQWorker.h:115
CaloTopology const * GetTopology()
Definition: DQWorker.cc:136
EcalTrigTowerConstituentsMap const * GetTrigTowerMap()
Definition: DQWorker.cc:124
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: DQWorker.h:75
void setEventNumber(edm::EventNumber_t _e)
Definition: DQWorker.h:116
void registerFactory(std::string const &_name, WorkerFactory _f)
Definition: DQWorker.h:151
void setRunNumber(edm::RunNumber_t _r)
Definition: DQWorker.h:114
void print_(std::string const &, int=0) const
Definition: DQWorker.cc:154
edm::RunNumber_t iRun
Definition: DQWorker.h:47
virtual void bookMEs(DQMStore::IBooker &)
Definition: DQWorker.cc:96
bool onlineMode() const
Definition: DQWorker.h:119
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:142
virtual void setME(edm::ParameterSet const &)
Definition: DQWorker.cc:71
Timestamp timestamp_
Definition: DQWorker.h:128
void initialize(std::string const &_name, edm::ParameterSet const &)
Definition: DQWorker.cc:65
tbb::concurrent_unordered_map< std::string, WorkerFactory > workerFactories_
Definition: DQWorker.h:157
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > elecMapHandle
Definition: DQWorker.h:103
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:109
MESetCollection MEs_
Definition: DQWorker.h:125
std::string const & getName() const
Definition: DQWorker.h:118
virtual void setParams(edm::ParameterSet const &)
Definition: DQWorker.h:62
edm::ESGetToken< CaloTopology, CaloTopologyRecord > topoHandle
Definition: DQWorker.h:106
void setTokens(edm::ConsumesCollector &)
Definition: DQWorker.cc:53
edm::ESGetToken< CaloTopology, CaloTopologyRecord > topoHandleEndLumi
Definition: DQWorker.h:111
EcalElectronicsMapping const * GetElectronicsMap()
Definition: DQWorker.cc:118
void setVerbosity(int _verbosity)
Definition: DQWorker.h:57
unsigned int RunNumber_t
void setSetupObjects(edm::EventSetup const &)
Definition: DQWorker.cc:104
dqm::legacy::MonitorElement MonitorElement
Definition: DQWorker.h:55
CaloGeometry const * GetGeometry()
Definition: DQWorker.cc:130
virtual ~DQWorker() noexcept(false)
Definition: DQWorker.cc:34
DQWorker *(* WorkerFactory)()
Definition: DQWorker.h:139
void setTime(time_t _t)
Definition: DQWorker.h:113
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > ttMapHandle
Definition: DQWorker.h:104
Registration(std::string const &_name)
Definition: DQWorker.h:146
std::string name_
Definition: DQWorker.h:124
virtual void setSource(edm::ParameterSet const &)
Definition: DQWorker.h:61
Definition: Run.h:45