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 
20 namespace edm {
21  class Run;
22  class LuminosityBlock;
23  class Event;
24  class EventSetup;
25  class ParameterSet;
27 } // namespace edm
28 
29 namespace ecaldqm {
30 
31  class WorkerFactoryStore;
32 
33  class DQWorker {
34  friend class WorkerFactoryStore;
35 
36  private:
37  struct Timestamp {
38  time_t now;
42  Timestamp() : now(0), iRun(0), iLumi(0), iEvt(0) {}
43  };
44 
45  protected:
48 
49  void setVerbosity(int _verbosity) { verbosity_ = _verbosity; }
50  void initialize(std::string const &_name, edm::ParameterSet const &);
51 
52  virtual void setME(edm::ParameterSet const &);
53  virtual void setSource(edm::ParameterSet const &) {} // for clients
54  virtual void setParams(edm::ParameterSet const &) {}
55 
56  public:
57  DQWorker();
58  virtual ~DQWorker() noexcept(false);
59 
60  static void fillDescriptions(edm::ParameterSetDescription &_desc);
61 
62  virtual void beginRun(edm::Run const &, edm::EventSetup const &) {}
63  virtual void endRun(edm::Run const &, edm::EventSetup const &) {}
64 
65  virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
66  virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) {}
67 
68  virtual void bookMEs(DQMStore::IBooker &);
69  virtual void releaseMEs();
70 
71  // old ecaldqmGetSetupObjects (old global vars)
72  // These are objects obtained from EventSetup and stored
73  // inside each module (which inherit from DQWorker).
74  // Before, EcalCommon functions could access these through
75  // global functions, but now we need to pass them from the
76  // modules to functions in EcalCommon, such as in
77  // EcalDQMCommonUtils, MESetBinningUtils, all MESets, etc.
78  //
79  // The global variables were removed as they were against
80  // CMSSW rules, and potentially led to undefined behavior
81  // (data race) at IOV boundaries. They also relied on a mutex
82  // which leads to poor multi-threading performance.
83  // Original issue here:
84  // https://github.com/cms-sw/cmssw/issues/28858
85  void setSetupObjects(edm::EventSetup const &);
88  CaloGeometry const *GetGeometry();
89  CaloTopology const *GetTopology();
91 
92  void setTime(time_t _t) { timestamp_.now = _t; }
96 
97  std::string const &getName() const { return name_; }
98  bool onlineMode() const { return onlineMode_; }
99 
100  protected:
101  void print_(std::string const &, int = 0) const;
102 
105  bool booked_;
106 
109 
110  // common parameters
113 
114  private:
116  };
117 
118  typedef DQWorker *(*WorkerFactory)();
119 
120  // to be instantiated after the implementation of each worker module
122  public:
123  template <typename Worker>
124  struct Registration {
125  Registration(std::string const &_name) {
126  WorkerFactoryStore::singleton()->registerFactory(_name, []() -> DQWorker * { return new Worker(); });
127  }
128  };
129 
130  void registerFactory(std::string const &_name, WorkerFactory _f) { workerFactories_[_name] = _f; }
131  DQWorker *getWorker(std::string const &, int, edm::ParameterSet const &, edm::ParameterSet const &) const;
132 
133  static WorkerFactoryStore *singleton();
134 
135  private:
136  tbb::concurrent_unordered_map<std::string, WorkerFactory> workerFactories_;
137  };
138 
139 } // namespace ecaldqm
140 
141 #define DEFINE_ECALDQM_WORKER(TYPE) WorkerFactoryStore::Registration<TYPE> ecaldqm##TYPE##Registration(#TYPE)
142 
143 #endif
EcalElectronicsMapping
Definition: EcalElectronicsMapping.h:28
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
funct::false
false
Definition: Factorize.h:29
ecaldqm
Definition: DQWorker.h:29
ecaldqm::WorkerFactoryStore::workerFactories_
tbb::concurrent_unordered_map< std::string, WorkerFactory > workerFactories_
Definition: DQWorker.h:136
ecaldqm::DQWorker::name_
std::string name_
Definition: DQWorker.h:103
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
ecaldqm::DQWorker::setLumiNumber
void setLumiNumber(edm::LuminosityBlockNumber_t _l)
Definition: DQWorker.h:94
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
MESet.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
ecaldqm::DQWorker::bookMEs
virtual void bookMEs(DQMStore::IBooker &)
Definition: DQWorker.cc:78
ecaldqm::WorkerFactoryStore::getWorker
DQWorker * getWorker(std::string const &, int, edm::ParameterSet const &, edm::ParameterSet const &) const
Definition: DQWorker.cc:145
ecaldqm::DQWorker::print_
void print_(std::string const &, int=0) const
Definition: DQWorker.cc:140
ecaldqm::DQWorker::booked_
bool booked_
Definition: DQWorker.h:105
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::GetElectronicsMap
const EcalElectronicsMapping * GetElectronicsMap()
Definition: DQWorker.cc:104
ecaldqm::DQWorker::releaseMEs
virtual void releaseMEs()
Definition: DQWorker.cc:72
ecaldqm::DQWorker
Definition: DQWorker.h:33
ecaldqm::DQWorker::setSetupObjects
void setSetupObjects(edm::EventSetup const &)
Definition: DQWorker.cc:86
CaloGeometry
Definition: CaloGeometry.h:21
ecaldqm::DQWorker::setEventNumber
void setEventNumber(edm::EventNumber_t _e)
Definition: DQWorker.h:95
ecaldqm::WorkerFactoryStore::Registration
Definition: DQWorker.h:124
dqm::legacy::DQMStore
Definition: DQMStore.h:727
ecaldqm::DQWorker::GetGeometry
const CaloGeometry * GetGeometry()
Definition: DQWorker.cc:116
ecaldqm::DQWorker::MonitorElement
dqm::legacy::MonitorElement MonitorElement
Definition: DQWorker.h:47
EventID.h
ecaldqm::DQWorker::onlineMode
bool onlineMode() const
Definition: DQWorker.h:98
LuminosityBlock
Event
ecaldqm::DQWorker::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &_desc)
Definition: DQWorker.cc:31
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:65
ecaldqm::WorkerFactory
DQWorker *(* WorkerFactory)()
Definition: DQWorker.h:118
ecaldqm::DQWorker::GetTrigTowerMap
const EcalTrigTowerConstituentsMap * GetTrigTowerMap()
Definition: DQWorker.cc:110
ecaldqm::DQWorker::MEs_
MESetCollection MEs_
Definition: DQWorker.h:104
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ecaldqm::WorkerFactoryStore
Definition: DQWorker.h:121
EcalTrigTowerConstituentsMap
Definition: EcalTrigTowerConstituentsMap.h:19
ecaldqm::DQWorker::onlineMode_
bool onlineMode_
Definition: DQWorker.h:111
ecaldqm::DQWorker::setVerbosity
void setVerbosity(int _verbosity)
Definition: DQWorker.h:49
ecaldqm::DQWorker::setParams
virtual void setParams(edm::ParameterSet const &)
Definition: DQWorker.h:54
ecaldqm::DQWorker::setRunNumber
void setRunNumber(edm::RunNumber_t _r)
Definition: DQWorker.h:93
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:47
ecaldqm::DQWorker::edso_
EcalDQMSetupObjects edso_
Definition: DQWorker.h:115
edm::EventSetup
Definition: EventSetup.h:58
ecaldqm::DQWorker::Timestamp::iRun
edm::RunNumber_t iRun
Definition: DQWorker.h:39
ecaldqm::WorkerFactoryStore::registerFactory
void registerFactory(std::string const &_name, WorkerFactory _f)
Definition: DQWorker.h:130
ecaldqm::DQWorker::willConvertToEDM_
bool willConvertToEDM_
Definition: DQWorker.h:112
ecaldqm::DQWorker::Timestamp::Timestamp
Timestamp()
Definition: DQWorker.h:42
ecaldqm::DQWorker::setME
virtual void setME(edm::ParameterSet const &)
Definition: DQWorker.cc:53
CaloTopology.h
ecaldqm::DQWorker::Timestamp::iLumi
edm::LuminosityBlockNumber_t iLumi
Definition: DQWorker.h:40
ecaldqm::DQWorker::beginRun
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
Definition: DQWorker.h:62
ecaldqm::DQWorker::getEcalDQMSetupObjects
const EcalDQMSetupObjects getEcalDQMSetupObjects()
Definition: DQWorker.cc:128
EcalTrigTowerConstituentsMap.h
ecaldqm::DQWorker::getName
const std::string & getName() const
Definition: DQWorker.h:97
ecaldqm::DQWorker::~DQWorker
virtual ~DQWorker() noexcept(false)
Definition: DQWorker.cc:28
ecaldqm::DQWorker::endLuminosityBlock
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Definition: DQWorker.h:66
ecaldqm::DQWorker::Timestamp
Definition: DQWorker.h:37
CaloGeometry.h
ecaldqm::DQWorker::timestamp_
Timestamp timestamp_
Definition: DQWorker.h:107
ParameterSetDescription
ecaldqm::DQWorker::verbosity_
int verbosity_
Definition: DQWorker.h:108
dqm::implementation::IBooker
Definition: DQMStore.h:43
ecaldqm::WorkerFactoryStore::singleton
static WorkerFactoryStore * singleton()
Definition: DQWorker.cc:161
ecaldqm::WorkerFactoryStore::Registration::Registration
Registration(std::string const &_name)
Definition: DQWorker.h:125
ecaldqm::DQWorker::Timestamp::iEvt
edm::EventNumber_t iEvt
Definition: DQWorker.h:41
EventSetup
ecaldqm::DQWorker::setTime
void setTime(time_t _t)
Definition: DQWorker.h:92
ecaldqm::DQWorker::setSource
virtual void setSource(edm::ParameterSet const &)
Definition: DQWorker.h:53
ecaldqm::DQWorker::Timestamp::now
time_t now
Definition: DQWorker.h:38
ecaldqm::DQWorker::endRun
virtual void endRun(edm::Run const &, edm::EventSetup const &)
Definition: DQWorker.h:63
RunID.h
ecaldqm::DQWorker::DQWorker
DQWorker()
Definition: DQWorker.cc:18
ecaldqm::DQWorker::DQMStore
dqm::legacy::DQMStore DQMStore
Definition: DQWorker.h:46
ecaldqm::DQWorker::GetTopology
const CaloTopology * GetTopology()
Definition: DQWorker.cc:122
Run