File indexing completed on 2024-09-11 04:32:55
0001 #ifndef DQMServices_Core_DQMGlobalEDAnalyzer_h
0002 #define DQMServices_Core_DQMGlobalEDAnalyzer_h
0003
0004 #include "DQMServices/Core/interface/DQMStore.h"
0005 #include "DataFormats/Histograms/interface/DQMToken.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/Run.h"
0008 #include "FWCore/Framework/interface/global/EDProducer.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011
0012 template <typename H, typename... Args>
0013 class DQMGlobalEDAnalyzerBase
0014 : public edm::global::EDProducer<edm::RunCache<H>,
0015
0016
0017 edm::EndRunProducer,
0018 edm::Accumulator,
0019 Args...> {
0020 public:
0021 typedef dqm::reco::DQMStore DQMStore;
0022 typedef dqm::reco::MonitorElement MonitorElement;
0023
0024
0025 DQMGlobalEDAnalyzerBase() {
0026
0027 runToken_ = this->template produces<DQMToken, edm::Transition::EndRun>("DQMGenerationRecoRun");
0028 dqmstore_ = edm::Service<DQMStore>().operator->();
0029 }
0030
0031 std::shared_ptr<H> globalBeginRun(edm::Run const& run, edm::EventSetup const& setup) const final {
0032 auto h = std::make_shared<H>();
0033
0034 dqmBeginRun(run, setup, *h);
0035
0036
0037
0038 dqmstore_->bookTransaction(
0039 [&, this](DQMStore::IBooker& b) {
0040
0041 b.cd();
0042 bookHistograms(b, run, setup, *h);
0043 },
0044
0045
0046 meId(run),
0047 false);
0048 dqmstore_->initLumi(run.run(), 0, meId(run));
0049 dqmstore_->enterLumi(run.run(), 0, meId(run));
0050 return h;
0051 }
0052
0053 void accumulate(edm::StreamID id, edm::Event const& event, edm::EventSetup const& setup) const final {
0054 auto const& h = *this->runCache(event.getRun().index());
0055 dqmAnalyze(event, setup, h);
0056 }
0057
0058
0059
0060 void globalEndRun(edm::Run const&, edm::EventSetup const&) const final {}
0061
0062
0063 virtual void dqmBeginRun(edm::Run const&, edm::EventSetup const&, H&) const {}
0064 virtual void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&, H&) const = 0;
0065
0066 virtual void dqmAnalyze(edm::Event const&, edm::EventSetup const&, H const&) const = 0;
0067
0068 protected:
0069 DQMStore* dqmstore_;
0070 edm::EDPutTokenT<DQMToken> runToken_;
0071 uint64_t meId(edm::Run const& run) const { return (((uint64_t)run.run()) << 32) + this->moduleDescription().id(); }
0072 };
0073
0074
0075 template <typename H, typename... Args>
0076 class DQMGlobalEDAnalyzer : public DQMGlobalEDAnalyzerBase<H, Args...> {
0077 public:
0078 void globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup) const final {
0079 auto const& h = *this->runCache(run.index());
0080 dqmEndRun(run, setup, h);
0081 this->dqmstore_->leaveLumi(run.run(), 0, this->meId(run));
0082 run.emplace(this->runToken_);
0083 }
0084
0085 virtual void dqmEndRun(edm::Run const&, edm::EventSetup const&, H const&) const {}
0086 };
0087
0088
0089 template <typename H,
0090 typename RSC,
0091 typename... Args>
0092 class DQMGlobalRunSummaryEDAnalyzer : public DQMGlobalEDAnalyzerBase<H, edm::RunSummaryCache<RSC>, Args...> {
0093 public:
0094 void globalEndRunProduce(edm::Run& run, edm::EventSetup const& setup, RSC const* runSummaryCache) const final {
0095 auto const& h = *this->runCache(run.index());
0096 dqmEndRun(run, setup, h, *runSummaryCache);
0097 this->dqmstore_->leaveLumi(run.run(), 0, this->meId(run));
0098 run.emplace(this->runToken_);
0099 }
0100
0101 virtual void dqmEndRun(edm::Run const&, edm::EventSetup const&, H const&, RSC const&) const {}
0102 };
0103
0104 #endif