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 "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
ecaldqm::DQWorker::topoHandle
edm::ESGetToken< CaloTopology, CaloTopologyRecord > topoHandle
Definition: DQWorker.h:106
ecaldqm::DQWorker::setSetupObjectsEndLumi
void setSetupObjectsEndLumi(edm::EventSetup const &)
Definition: DQWorker.cc:111
EcalElectronicsMapping
Definition: EcalElectronicsMapping.h:28
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
ecaldqm::DQWorker::setTokens
void setTokens(edm::ConsumesCollector &)
Definition: DQWorker.cc:53
funct::false
false
Definition: Factorize.h:29
ecaldqm
Definition: DQWorker.h:37
ecaldqm::WorkerFactoryStore::workerFactories_
tbb::concurrent_unordered_map< std::string, WorkerFactory > workerFactories_
Definition: DQWorker.h:157
ESHandle.h
ecaldqm::DQWorker::name_
std::string name_
Definition: DQWorker.h:124
ecaldqm::DQWorker::geomHandle
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomHandle
Definition: DQWorker.h:105
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
ecaldqm::DQWorker::setLumiNumber
void setLumiNumber(edm::LuminosityBlockNumber_t _l)
Definition: DQWorker.h:115
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
ecaldqm::DQWorker::ttMapHandle
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > ttMapHandle
Definition: DQWorker.h:104
MESet.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
ecaldqm::DQWorker::bookMEs
virtual void bookMEs(DQMStore::IBooker &)
Definition: DQWorker.cc:96
ecaldqm::WorkerFactoryStore::getWorker
DQWorker * getWorker(std::string const &, int, edm::ParameterSet const &, edm::ParameterSet const &) const
Definition: DQWorker.cc:159
ecaldqm::DQWorker::print_
void print_(std::string const &, int=0) const
Definition: DQWorker.cc:154
ecaldqm::DQWorker::booked_
bool booked_
Definition: DQWorker.h:126
ecaldqm::DQWorker::geomHandleEndLumi
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geomHandleEndLumi
Definition: DQWorker.h:110
watchdog.const
const
Definition: watchdog.py:83
edm::LuminosityBlockNumber_t
unsigned int LuminosityBlockNumber_t
Definition: RunLumiEventNumber.h:13
CaloTopology
Definition: CaloTopology.h:19
ecaldqm::DQWorker::elecMapHandleEndLumi
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > elecMapHandleEndLumi
Definition: DQWorker.h:108
ecaldqm::DQWorker::GetElectronicsMap
const EcalElectronicsMapping * GetElectronicsMap()
Definition: DQWorker.cc:118
ecaldqm::DQWorker::releaseMEs
virtual void releaseMEs()
Definition: DQWorker.cc:90
ecaldqm::DQWorker
Definition: DQWorker.h:41
ecaldqm::DQWorker::setSetupObjects
void setSetupObjects(edm::EventSetup const &)
Definition: DQWorker.cc:104
CaloGeometry
Definition: CaloGeometry.h:21
ecaldqm::DQWorker::setEventNumber
void setEventNumber(edm::EventNumber_t _e)
Definition: DQWorker.h:116
ecaldqm::WorkerFactoryStore::Registration
Definition: DQWorker.h:145
dqm::legacy::DQMStore
Definition: DQMStore.h:728
ecaldqm::DQWorker::GetGeometry
const CaloGeometry * GetGeometry()
Definition: DQWorker.cc:130
ecaldqm::DQWorker::MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: DQWorker.h:55
EventID.h
EcalMappingRcd.h
ecaldqm::DQWorker::onlineMode
bool onlineMode() const
Definition: DQWorker.h:119
LuminosityBlock
Event
ecaldqm::DQWorker::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &_desc)
Definition: DQWorker.cc:37
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
ecaldqm::DQWorker::beginLuminosityBlock
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: DQWorker.h:74
ecaldqm::WorkerFactory
DQWorker *(* WorkerFactory)()
Definition: DQWorker.h:139
ecaldqm::DQWorker::elecMapHandle
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd > elecMapHandle
Definition: DQWorker.h:103
ecaldqm::DQWorker::GetTrigTowerMap
const EcalTrigTowerConstituentsMap * GetTrigTowerMap()
Definition: DQWorker.cc:124
ecaldqm::DQWorker::MEs_
MESetCollection MEs_
Definition: DQWorker.h:125
CaloGeometryRecord.h
ecaldqm::WorkerFactoryStore
Definition: DQWorker.h:142
EcalTrigTowerConstituentsMap
Definition: EcalTrigTowerConstituentsMap.h:19
ecaldqm::DQWorker::onlineMode_
bool onlineMode_
Definition: DQWorker.h:132
ecaldqm::DQWorker::setVerbosity
void setVerbosity(int _verbosity)
Definition: DQWorker.h:57
ecaldqm::DQWorker::setParams
virtual void setParams(edm::ParameterSet const &)
Definition: DQWorker.h:62
ecaldqm::DQWorker::setRunNumber
void setRunNumber(edm::RunNumber_t _r)
Definition: DQWorker.h:114
edm::ParameterSet
Definition: ParameterSet.h:47
ParameterSet
Definition: Functions.h:16
ecaldqm::MESetCollection
Definition: MESet.h:380
ecaldqm::EcalDQMSetupObjects
Definition: MESet.h:33
EcalElectronicsMapping.h
ecaldqm::DQWorker::initialize
void initialize(std::string const &_name, edm::ParameterSet const &)
Definition: DQWorker.cc:65
IdealGeometryRecord.h
ecaldqm::DQWorker::edso_
EcalDQMSetupObjects edso_
Definition: DQWorker.h:136
edm::EventSetup
Definition: EventSetup.h:58
ecaldqm::DQWorker::Timestamp::iRun
edm::RunNumber_t iRun
Definition: DQWorker.h:47
ecaldqm::WorkerFactoryStore::registerFactory
void registerFactory(std::string const &_name, WorkerFactory _f)
Definition: DQWorker.h:151
ecaldqm::DQWorker::willConvertToEDM_
bool willConvertToEDM_
Definition: DQWorker.h:133
ecaldqm::DQWorker::Timestamp::Timestamp
Timestamp()
Definition: DQWorker.h:50
edm::ESGetToken< EcalElectronicsMapping, EcalMappingRcd >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ecaldqm::DQWorker::setME
virtual void setME(edm::ParameterSet const &)
Definition: DQWorker.cc:71
CaloTopology.h
ecaldqm::DQWorker::Timestamp::iLumi
edm::LuminosityBlockNumber_t iLumi
Definition: DQWorker.h:48
ecaldqm::DQWorker::beginRun
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
Definition: DQWorker.h:71
ecaldqm::DQWorker::getEcalDQMSetupObjects
const EcalDQMSetupObjects getEcalDQMSetupObjects()
Definition: DQWorker.cc:142
CaloTopologyRecord.h
EcalTrigTowerConstituentsMap.h
ecaldqm::DQWorker::getName
const std::string & getName() const
Definition: DQWorker.h:118
ecaldqm::DQWorker::~DQWorker
virtual ~DQWorker() noexcept(false)
Definition: DQWorker.cc:34
ecaldqm::DQWorker::endLuminosityBlock
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: DQWorker.h:75
ecaldqm::DQWorker::Timestamp
Definition: DQWorker.h:45
CaloGeometry.h
ecaldqm::DQWorker::timestamp_
Timestamp timestamp_
Definition: DQWorker.h:128
ParameterSetDescription
ecaldqm::DQWorker::verbosity_
int verbosity_
Definition: DQWorker.h:129
dqm::implementation::IBooker
Definition: DQMStore.h:43
ecaldqm::WorkerFactoryStore::singleton
static WorkerFactoryStore * singleton()
Definition: DQWorker.cc:175
ecaldqm::WorkerFactoryStore::Registration::Registration
Registration(std::string const &_name)
Definition: DQWorker.h:146
ecaldqm::DQWorker::Timestamp::iEvt
edm::EventNumber_t iEvt
Definition: DQWorker.h:49
ConsumesCollector.h
EventSetup
ecaldqm::DQWorker::setTime
void setTime(time_t _t)
Definition: DQWorker.h:113
ecaldqm::DQWorker::topoHandleEndLumi
edm::ESGetToken< CaloTopology, CaloTopologyRecord > topoHandleEndLumi
Definition: DQWorker.h:111
ecaldqm::DQWorker::ttMapHandleEndLumi
edm::ESGetToken< EcalTrigTowerConstituentsMap, IdealGeometryRecord > ttMapHandleEndLumi
Definition: DQWorker.h:109
ecaldqm::DQWorker::setSource
virtual void setSource(edm::ParameterSet const &)
Definition: DQWorker.h:61
ecaldqm::DQWorker::Timestamp::now
time_t now
Definition: DQWorker.h:46
ecaldqm::DQWorker::endRun
virtual void endRun(edm::Run const &, edm::EventSetup const &)
Definition: DQWorker.h:72
RunID.h
ecaldqm::DQWorker::DQWorker
DQWorker()
Definition: DQWorker.cc:24
ecaldqm::DQWorker::DQMStore
dqm::legacy::DQMStore DQMStore
Definition: DQWorker.h:54
ecaldqm::DQWorker::GetTopology
const CaloTopology * GetTopology()
Definition: DQWorker.cc:136
Run