CMS 3D CMS Logo

DQMEDAnalyzer.h
Go to the documentation of this file.
1 #ifndef DQMServices_Core_DQMEDAnalyzer_h
2 #define DQMServices_Core_DQMEDAnalyzer_h
3 
5 
7 
8 // If we declare a global cache (which is not absolutely needed right now, but
9 // might be in the future), the framework will try to pass it to the
10 // constructor. But, we don't want to change all subsystem code whenever we
11 // change that implementation detail, so instead we hack the framework to not
12 // do that. See issue #27125.
13 namespace edm::stream::impl {
14  template <typename T>
16  return new T(iPSet);
17  }
18 } // namespace edm::stream::impl
19 
27 
29  // slightly overkill for now, but we might want to putt the full DQMStore
30  // here at some point.
34 };
35 
39 class DQMEDAnalyzer : public edm::stream::EDProducer<edm::GlobalCache<DQMEDAnalyzerGlobalCache>,
40  edm::EndRunProducer,
41  edm::EndLuminosityBlockProducer,
42  edm::Accumulator> {
43 public:
46 
47  virtual bool getCanSaveByLumi() { return true; }
48 
49  // framework calls in the order of invocation
50 
51  static std::unique_ptr<DQMEDAnalyzerGlobalCache> initializeGlobalCache(edm::ParameterSet const&) {
52  return std::make_unique<DQMEDAnalyzerGlobalCache>();
53  }
54 
56  // for whatever reason we need the explicit `template` keyword here.
57  runToken_ = this->template produces<DQMToken, edm::Transition::EndRun>("DQMGenerationRecoRun");
58  lumiToken_ = this->template produces<DQMToken, edm::Transition::EndLuminosityBlock>("DQMGenerationRecoLumi");
60  }
61 
62  void beginStream(edm::StreamID id) final {
64  this->streamId_ = id.value();
65  // now, since we can't access the global cache in the constructor (we
66  // blocked that above to not expose the cache to the subsystem code,
67  // we need to store the tokens here.
68  // This also requires locking, since the streams will run in parallel.
69  // See https://github.com/cms-sw/cmssw/issues/27291#issuecomment-505909101
70  auto lock = std::scoped_lock(globalCache()->master_);
71  if (globalCache()->runToken_.isUninitialized()) {
72  globalCache()->lumiToken_ = lumiToken_;
73  globalCache()->runToken_ = runToken_;
74  }
75  }
76 
77  void beginRun(edm::Run const& run, edm::EventSetup const& setup) final {
78  // if we run booking multiple times because there are multiple runs in a
79  // job, this is needed to make sure all existing MEs are in a valid state
80  // before the booking code runs.
81  edm::Service<DQMStore>()->initLumi(run.run(), /* lumi */ 0, meId());
82  edm::Service<DQMStore>()->enterLumi(run.run(), /* lumi */ 0, meId());
84  edm::Service<DQMStore>()->bookTransaction(
85  [this, &run, &setup](DQMStore::IBooker& booker) {
86  booker.cd();
87  this->bookHistograms(booker, run, setup);
88  },
89  meId(),
90  this->getCanSaveByLumi());
91  edm::Service<DQMStore>()->initLumi(run.run(), /* lumi */ 0, meId());
92  edm::Service<DQMStore>()->enterLumi(run.run(), /* lumi */ 0, meId());
93  }
94 
96  edm::Service<DQMStore>()->enterLumi(lumi.run(), lumi.luminosityBlock(), meId());
97  }
98 
99  void accumulate(edm::Event const& event, edm::EventSetup const& setup) final { analyze(event, setup); }
100 
102  edm::Service<DQMStore>()->leaveLumi(lumi.run(), lumi.luminosityBlock(), meId());
103  }
104 
106  edm::EventSetup const& setup,
107  LuminosityBlockContext const* context) {
108  lumi.emplace(context->global()->lumiToken_);
109  }
110 
111  void endRun(edm::Run const& run, edm::EventSetup const& setup) final {
112  edm::Service<DQMStore>()->leaveLumi(run.run(), /* lumi */ 0, meId());
113  }
114  static void globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup, RunContext const* context) {
115  run.emplace<DQMToken>(context->global()->runToken_);
116  }
117 
118  static void globalEndJob(DQMEDAnalyzerGlobalCache const*) {}
119 
120  // methods to be implemented by the user, in order of invocation
121  virtual void dqmBeginRun(edm::Run const&, edm::EventSetup const&) {}
122  virtual void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) = 0;
123  virtual void analyze(edm::Event const&, edm::EventSetup const&) {}
124 
125 protected:
128  unsigned int streamId_;
129  uint64_t meId() const { return (((uint64_t)streamId_) << 32) + this->moduleDescription().id(); }
130 };
131 
132 #endif // DQMServices_Core_DQMEDAnalyzer_h
edm::StreamID
Definition: StreamID.h:30
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
DQMEDAnalyzer::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) final
Definition: DQMEDAnalyzer.h:95
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
DQMEDAnalyzer::globalEndRunProduce
static void globalEndRunProduce(edm::Run &run, edm::EventSetup const &setup, RunContext const *context)
Definition: DQMEDAnalyzer.h:114
edm::EDPutTokenT< DQMToken >
DQMEDAnalyzer::beginStream
void beginStream(edm::StreamID id) final
Definition: DQMEDAnalyzer.h:62
DQMEDAnalyzer::getCanSaveByLumi
virtual bool getCanSaveByLumi()
Definition: DQMEDAnalyzer.h:47
cms::cuda::assert
assert(be >=bs)
EDProducer.h
DQMStore.h
DQMEDAnalyzer::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) final
Definition: DQMEDAnalyzer.h:101
edm::StreamID::value
unsigned int value() const
Definition: StreamID.h:43
DQMEDAnalyzer::endRun
void endRun(edm::Run const &run, edm::EventSetup const &setup) final
Definition: DQMEDAnalyzer.h:111
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
makeGlobal.h
edm::stream::RunContextT
Definition: Contexts.h:31
DQMEDAnalyzer::DQMEDAnalyzer
DQMEDAnalyzer()
Definition: DQMEDAnalyzer.h:55
dqm::legacy::DQMStore
Definition: DQMStore.h:727
DQMEDAnalyzerGlobalCache
Definition: DQMEDAnalyzer.h:28
DQMToken.h
Service.h
edm::stream::LuminosityBlockContextT::global
G const * global() const
Definition: Contexts.h:50
DQMToken
Definition: DQMToken.h:21
Run.h
dqm::implementation::NavigatorBase::cd
virtual void cd()
Definition: DQMStore.cc:29
edm::stream::impl::makeStreamModule
T * makeStreamModule(edm::ParameterSet const &iPSet, DQMEDAnalyzerGlobalCache const *global)
Definition: DQMEDAnalyzer.h:15
DQMEDAnalyzerGlobalCache::runToken_
edm::EDPutTokenT< DQMToken > runToken_
Definition: DQMEDAnalyzer.h:33
DQMEDAnalyzer
Definition: DQMEDAnalyzer.py:1
DQMEDAnalyzer::runToken_
edm::EDPutTokenT< DQMToken > runToken_
Definition: DQMEDAnalyzer.h:126
edm::ParameterSet
Definition: ParameterSet.h:47
DQMEDAnalyzer::globalEndJob
static void globalEndJob(DQMEDAnalyzerGlobalCache const *)
Definition: DQMEDAnalyzer.h:118
DQMEDAnalyzer::lumiToken_
edm::EDPutTokenT< DQMToken > lumiToken_
Definition: DQMEDAnalyzer.h:127
DQMEDAnalyzer::DQMStore
dqm::reco::DQMStore DQMStore
Definition: DQMEDAnalyzer.h:44
Event.h
CommonMethods.lock
def lock()
Definition: CommonMethods.py:82
edm::StreamID::invalidStreamID
static StreamID invalidStreamID()
Definition: StreamID.h:45
edm::Service
Definition: Service.h:30
DQMEDAnalyzer::analyze
virtual void analyze(edm::Event const &, edm::EventSetup const &)
Definition: DQMEDAnalyzer.h:123
DQMEDAnalyzer::initializeGlobalCache
static std::unique_ptr< DQMEDAnalyzerGlobalCache > initializeGlobalCache(edm::ParameterSet const &)
Definition: DQMEDAnalyzer.h:51
mutex
static std::mutex mutex
Definition: Proxy.cc:8
edm::stream::EDProducer
Definition: EDProducer.h:38
DQMEDAnalyzer::accumulate
void accumulate(edm::Event const &event, edm::EventSetup const &setup) final
Definition: DQMEDAnalyzer.h:99
edm::EventSetup
Definition: EventSetup.h:58
DQMEDAnalyzer::bookHistograms
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)=0
edm::stream::impl
Definition: DQMEDAnalyzer.h:13
edm::stream::LuminosityBlockContextT
Definition: Contexts.h:43
writedatasetfile.run
run
Definition: writedatasetfile.py:27
DQMEDAnalyzer::MonitorElement
dqm::reco::MonitorElement MonitorElement
Definition: DQMEDAnalyzer.h:45
DQMEDAnalyzerGlobalCache::master_
std::mutex master_
Definition: DQMEDAnalyzer.h:31
T
long double T
Definition: Basic3DVectorLD.h:48
DQMEDAnalyzerGlobalCache::lumiToken_
edm::EDPutTokenT< DQMToken > lumiToken_
Definition: DQMEDAnalyzer.h:32
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::EDPutTokenT::isUninitialized
bool isUninitialized() const
Definition: EDPutToken.h:78
dqm::implementation::IBooker
Definition: DQMStore.h:43
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
DQMEDAnalyzer::beginRun
void beginRun(edm::Run const &run, edm::EventSetup const &setup) final
Definition: DQMEDAnalyzer.h:77
ParameterSet.h
DQMEDAnalyzer::globalEndLuminosityBlockProduce
static void globalEndLuminosityBlockProduce(edm::LuminosityBlock &lumi, edm::EventSetup const &setup, LuminosityBlockContext const *context)
Definition: DQMEDAnalyzer.h:105
DQMEDAnalyzer::meId
uint64_t meId() const
Definition: DQMEDAnalyzer.h:129
DQMEDAnalyzer::streamId_
unsigned int streamId_
Definition: DQMEDAnalyzer.h:128
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
lumi
Definition: LumiSectionData.h:20
DQMEDAnalyzer::dqmBeginRun
virtual void dqmBeginRun(edm::Run const &, edm::EventSetup const &)
Definition: DQMEDAnalyzer.h:121
edm::stream::RunContextT::global
G const * global() const
Definition: Contexts.h:35