File indexing completed on 2024-09-11 04:32:55
0001 #ifndef CORE_DQMED_HARVESTER_H
0002 #define CORE_DQMED_HARVESTER_H
0003
0004 #include "DQMServices/Core/interface/DQMStore.h"
0005
0006 #include "FWCore/Framework/interface/one/EDProducer.h"
0007
0008 #include "FWCore/Framework/interface/Run.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/EventSetup.h"
0011 #include "FWCore/Framework/interface/LuminosityBlock.h"
0012 #include "FWCore/Framework/interface/InputTagMatch.h"
0013 #include "FWCore/Framework/interface/GetterOfProducts.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 #include "FWCore/Utilities/interface/EDPutToken.h"
0017
0018 #include "DataFormats/Histograms/interface/DQMToken.h"
0019
0020 namespace edm {
0021 class VInputTagMatch {
0022 public:
0023 VInputTagMatch(std::vector<edm::InputTag> const &inputTags) {
0024 for (auto &tag : inputTags) {
0025 matchers_.emplace_back(InputTagMatch(tag));
0026 }
0027 }
0028
0029 bool operator()(edm::BranchDescription const &branchDescription) {
0030 for (auto &m : matchers_) {
0031 if (m(branchDescription)) {
0032 return true;
0033 }
0034 }
0035 return false;
0036 }
0037
0038 private:
0039 std::vector<InputTagMatch> matchers_;
0040 };
0041 }
0042
0043 class DQMEDHarvester
0044 : public edm::one::EDProducer<edm::EndLuminosityBlockProducer,
0045 edm::EndRunProducer,
0046 edm::EndProcessBlockProducer,
0047 edm::one::WatchLuminosityBlocks,
0048 edm::one::WatchRuns,
0049
0050
0051 edm::one::SharedResources,
0052 edm::Accumulator> {
0053 public:
0054 typedef dqm::harvesting::DQMStore DQMStore;
0055 typedef dqm::harvesting::MonitorElement MonitorElement;
0056
0057 protected:
0058 DQMStore *dqmstore_;
0059 edm::GetterOfProducts<DQMToken> jobmegetter_;
0060 edm::GetterOfProducts<DQMToken> runmegetter_;
0061 edm::GetterOfProducts<DQMToken> lumimegetter_;
0062 edm::EDPutTokenT<DQMToken> lumiToken_;
0063 edm::EDPutTokenT<DQMToken> runToken_;
0064 edm::EDPutTokenT<DQMToken> jobToken_;
0065
0066 public:
0067 DQMEDHarvester(edm::ParameterSet const &iConfig) {
0068 usesResource("DQMStore");
0069 dqmstore_ = edm::Service<DQMStore>().operator->();
0070
0071 auto inputgeneration = iConfig.getUntrackedParameter<std::string>("inputGeneration", "DQMGenerationReco");
0072 auto outputgeneration = iConfig.getUntrackedParameter<std::string>("outputGeneration", "DQMGenerationHarvesting");
0073
0074
0075 lumiToken_ = produces<DQMToken, edm::Transition::EndLuminosityBlock>(outputgeneration + "Lumi");
0076 runToken_ = produces<DQMToken, edm::Transition::EndRun>(outputgeneration + "Run");
0077 jobToken_ = produces<DQMToken, edm::Transition::EndProcessBlock>(outputgeneration + "Job");
0078
0079
0080 auto inputtags =
0081 iConfig.getUntrackedParameter<std::vector<edm::InputTag>>("inputMEs", std::vector<edm::InputTag>());
0082 if (inputtags.empty()) {
0083
0084 inputtags.push_back(edm::InputTag("", inputgeneration + "Job"));
0085 inputtags.push_back(edm::InputTag("", inputgeneration + "Run"));
0086 inputtags.push_back(edm::InputTag("", inputgeneration + "Lumi"));
0087 }
0088 jobmegetter_ = edm::GetterOfProducts<DQMToken>(edm::VInputTagMatch(inputtags), this, edm::InProcess);
0089 runmegetter_ = edm::GetterOfProducts<DQMToken>(edm::VInputTagMatch(inputtags), this, edm::InRun);
0090 lumimegetter_ = edm::GetterOfProducts<DQMToken>(edm::VInputTagMatch(inputtags), this, edm::InLumi);
0091 callWhenNewProductsRegistered([this](edm::BranchDescription const &bd) {
0092 jobmegetter_(bd);
0093 runmegetter_(bd);
0094 lumimegetter_(bd);
0095 });
0096 };
0097
0098 DQMEDHarvester() : DQMEDHarvester(edm::ParameterSet()) {}
0099
0100 void beginJob() override {}
0101
0102 void beginRun(edm::Run const &run, edm::EventSetup const &) override {
0103
0104
0105 }
0106
0107 void beginLuminosityBlock(edm::LuminosityBlock const &lumi, edm::EventSetup const &) final {
0108
0109
0110 }
0111
0112 void accumulate(edm::Event const &ev, edm::EventSetup const &es) final {
0113 dqmstore_->meBookerGetter([this, &ev, &es](DQMStore::IBooker &b, DQMStore::IGetter &g) {
0114 b.setScope(MonitorElementData::Scope::JOB);
0115 this->dqmAnalyze(b, g, ev, es);
0116 });
0117 }
0118
0119 void endLuminosityBlockProduce(edm::LuminosityBlock &lumi, edm::EventSetup const &es) final {
0120
0121
0122
0123
0124 dqmstore_->meBookerGetter([this, &lumi, &es](DQMStore::IBooker &b, DQMStore::IGetter &g) {
0125 b.setScope(MonitorElementData::Scope::JOB);
0126 this->dqmEndLuminosityBlock(b, g, lumi, es);
0127 });
0128
0129 lumi.put(lumiToken_, std::make_unique<DQMToken>());
0130 }
0131
0132 void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) final {}
0133
0134 void endRunProduce(edm::Run &run, edm::EventSetup const &es) final {
0135 dqmstore_->meBookerGetter([this, &run, &es](DQMStore::IBooker &b, DQMStore::IGetter &g) {
0136 b.setScope(MonitorElementData::Scope::JOB);
0137 this->dqmEndRun(b, g, run, es);
0138 });
0139
0140 run.put(runToken_, std::make_unique<DQMToken>());
0141 }
0142
0143 void endRun(edm::Run const &, edm::EventSetup const &) override {}
0144
0145 void endProcessBlockProduce(edm::ProcessBlock &) final {
0146 dqmstore_->meBookerGetter([this](DQMStore::IBooker &b, DQMStore::IGetter &g) {
0147 b.setScope(MonitorElementData::Scope::JOB);
0148 this->dqmEndJob(b, g);
0149 });
0150 };
0151
0152 ~DQMEDHarvester() override = default;
0153
0154
0155
0156
0157 virtual void dqmAnalyze(DQMStore::IBooker &, DQMStore::IGetter &, edm::Event const &, edm::EventSetup const &) {}
0158 virtual void dqmEndLuminosityBlock(DQMStore::IBooker &,
0159 DQMStore::IGetter &,
0160 edm::LuminosityBlock const &,
0161 edm::EventSetup const &) {};
0162
0163
0164
0165 virtual void dqmEndRun(DQMStore::IBooker &, DQMStore::IGetter &, edm::Run const &, edm::EventSetup const &) {}
0166 virtual void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) = 0;
0167 };
0168
0169 #endif