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>()->initLumi(lumi.run(), lumi.luminosityBlock(), meId());
97  edm::Service<DQMStore>()->enterLumi(lumi.run(), lumi.luminosityBlock(), meId());
98  }
99 
100  void accumulate(edm::Event const& event, edm::EventSetup const& setup) final { analyze(event, setup); }
101 
103  edm::Service<DQMStore>()->leaveLumi(lumi.run(), lumi.luminosityBlock(), meId());
104  }
105 
107  edm::EventSetup const& setup,
109  lumi.emplace(context->global()->lumiToken_);
110  }
111 
112  void endRun(edm::Run const& run, edm::EventSetup const& setup) final {
113  edm::Service<DQMStore>()->leaveLumi(run.run(), /* lumi */ 0, meId());
114  }
116  run.emplace<DQMToken>(context->global()->runToken_);
117  }
118 
119  static void globalEndJob(DQMEDAnalyzerGlobalCache const*) {}
120 
121  // methods to be implemented by the user, in order of invocation
122  virtual void dqmBeginRun(edm::Run const&, edm::EventSetup const&) {}
123  virtual void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) = 0;
124  virtual void analyze(edm::Event const&, edm::EventSetup const&) {}
125 
126 protected:
129  unsigned int streamId_;
130  uint64_t meId() const { return (((uint64_t)streamId_) << 32) + this->moduleDescription().id(); }
131 };
132 
133 #endif // DQMServices_Core_DQMEDAnalyzer_h
virtual void analyze(edm::Event const &, edm::EventSetup const &)
dqm::reco::MonitorElement MonitorElement
Definition: DQMEDAnalyzer.h:45
static void globalEndLuminosityBlockProduce(edm::LuminosityBlock &lumi, edm::EventSetup const &setup, LuminosityBlockContext const *context)
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)=0
static std::mutex mutex
Definition: Proxy.cc:8
void endRun(edm::Run const &run, edm::EventSetup const &setup) final
void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) final
Definition: DQMEDAnalyzer.h:95
void beginStream(edm::StreamID id) final
Definition: DQMEDAnalyzer.h:62
static StreamID invalidStreamID()
Definition: StreamID.h:45
assert(be >=bs)
dqm::reco::DQMStore DQMStore
Definition: DQMEDAnalyzer.h:44
void accumulate(edm::Event const &event, edm::EventSetup const &setup) final
static void globalEndRunProduce(edm::Run &run, edm::EventSetup const &setup, RunContext const *context)
void beginRun(edm::Run const &run, edm::EventSetup const &setup) final
Definition: DQMEDAnalyzer.h:77
edm::EDPutTokenT< DQMToken > runToken_
Definition: DQMEDAnalyzer.h:33
T * makeStreamModule(edm::ParameterSet const &iPSet, DQMEDAnalyzerGlobalCache const *global)
Definition: DQMEDAnalyzer.h:15
edm::EDPutTokenT< DQMToken > runToken_
void endLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &setup) final
virtual void dqmBeginRun(edm::Run const &, edm::EventSetup const &)
unsigned int streamId_
virtual bool getCanSaveByLumi()
Definition: DQMEDAnalyzer.h:47
uint64_t meId() const
unsigned long long uint64_t
Definition: Time.h:13
static std::unique_ptr< DQMEDAnalyzerGlobalCache > initializeGlobalCache(edm::ParameterSet const &)
Definition: DQMEDAnalyzer.h:51
static void globalEndJob(DQMEDAnalyzerGlobalCache const *)
unsigned int value() const
Definition: StreamID.h:43
long double T
edm::EDPutTokenT< DQMToken > lumiToken_
Definition: DQMEDAnalyzer.h:32
constexpr bool isUninitialized() const noexcept
Definition: EDPutToken.h:100
Definition: event.py:1
Definition: Run.h:45
edm::EDPutTokenT< DQMToken > lumiToken_