Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-01 22:51:57

0001 #include <string>
0002 
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "DataFormats/Histograms/interface/MonitorElementCollection.h"
0007 
0008 template <typename BOOKERLIKE, typename ME, bool DOLUMI = false>
0009 class BookerFiller {
0010 public:
0011   BookerFiller(std::string folder, int howmany) {
0012     this->howmany = howmany;
0013     this->folder = folder;
0014   }
0015 
0016   BookerFiller(){};
0017 
0018   void bookall(BOOKERLIKE& ibooker) {
0019     mes_1D.clear();
0020     mes_2D.clear();
0021     mes_3D.clear();
0022 
0023     for (int i = 0; i < howmany; i++) {
0024       ibooker.setCurrentFolder(folder);
0025       auto num = std::to_string(i);
0026       // this does *not* test most of the booking API, just one ME of each kind.
0027       mes_1D.push_back(ibooker.bookFloat("float" + num));
0028       mes_1D.push_back(ibooker.bookInt("int" + num));
0029       mes_1D.push_back(ibooker.book1D("th1f" + num, "1D Float Histogram " + num, 101, -0.5, 100.5));
0030       mes_1D.push_back(ibooker.book1S("th1s" + num, "1D Short Histogram " + num, 101, -0.5, 100.5));
0031       mes_1D.push_back(ibooker.book1I("th1i" + num, "1D Integer Histogram " + num, 101, -0.5, 100.5));
0032       mes_1D.push_back(ibooker.book1DD("th1d" + num, "1D Double Histogram " + num, 101, -0.5, 100.5));
0033 
0034       mes_2D.push_back(ibooker.book2D("th2f" + num, "2D Float Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0035       mes_2D.push_back(ibooker.book2S("th2s" + num, "2D Short Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0036       mes_2D.push_back(ibooker.book2DD("th2d" + num, "2D Double Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0037       mes_2D.push_back(ibooker.book2I("th2i" + num, "2D Integer Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0038       mes_2D.push_back(
0039           ibooker.bookProfile("tprofile" + num, "1D Profile Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0040 
0041       mes_3D.push_back(
0042           ibooker.book3D("th3f" + num, "3D Float Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5, 3, -0.5, 2.5));
0043       mes_3D.push_back(ibooker.bookProfile2D(
0044           "thprofile2d" + num, "2D Profile Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5, 3, -0.5, 2.5));
0045 
0046       if (DOLUMI) {
0047         auto scope = typename BOOKERLIKE::UseLumiScope(ibooker);
0048         ibooker.setCurrentFolder(folder + "/lumi");
0049 
0050         mes_1D.push_back(ibooker.bookFloat("float" + num));
0051         mes_1D.push_back(ibooker.bookInt("int" + num));
0052         mes_1D.push_back(ibooker.book1D("th1f" + num, "1D Float Histogram " + num, 101, -0.5, 100.5));
0053         mes_1D.push_back(ibooker.book1S("th1s" + num, "1D Short Histogram " + num, 101, -0.5, 100.5));
0054         mes_1D.push_back(ibooker.book1I("th1i" + num, "1D Integer Histogram " + num, 101, -0.5, 100.5));
0055         mes_1D.push_back(ibooker.book1DD("th1d" + num, "1D Double Histogram " + num, 101, -0.5, 100.5));
0056 
0057         mes_2D.push_back(ibooker.book2D("th2f" + num, "2D Float Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0058         mes_2D.push_back(ibooker.book2S("th2s" + num, "2D Short Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0059         mes_2D.push_back(ibooker.book2DD("th2d" + num, "2D Double Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0060         mes_2D.push_back(ibooker.book2I("th2i" + num, "2D Integer Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0061         mes_2D.push_back(
0062             ibooker.bookProfile("tprofile" + num, "1D Profile Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5));
0063 
0064         mes_3D.push_back(
0065             ibooker.book3D("th3f" + num, "3D Float Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5, 3, -0.5, 2.5));
0066         mes_3D.push_back(ibooker.bookProfile2D(
0067             "thprofile2d" + num, "2D Profile Histogram " + num, 101, -0.5, 100.5, 11, -0.5, 10.5, 3, -0.5, 2.5));
0068       }
0069     }
0070   }
0071 
0072   void fillall(double x, double y, double z) const {
0073     for (auto me : mes_1D) {
0074       me->Fill(x);
0075     }
0076     for (auto me : mes_2D) {
0077       me->Fill(x, y);
0078     }
0079     for (auto me : mes_3D) {
0080       me->Fill(x, y, z);
0081     }
0082   }
0083 
0084   std::vector<ME*> mes_1D;
0085   std::vector<ME*> mes_2D;
0086   std::vector<ME*> mes_3D;
0087   std::string folder;
0088   int howmany;
0089 };
0090 
0091 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0092 class TestDQMEDAnalyzer : public DQMEDAnalyzer {
0093 public:
0094   explicit TestDQMEDAnalyzer(const edm::ParameterSet& iConfig)
0095       : mymes_(iConfig.getParameter<std::string>("folder"), iConfig.getParameter<int>("howmany")),
0096         myvalue_(iConfig.getParameter<double>("value")) {}
0097 
0098   ~TestDQMEDAnalyzer() override{};
0099 
0100   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0101     edm::ParameterSetDescription desc;
0102     desc.add<std::string>("folder", "Normal/test")->setComment("Where to put all the histograms");
0103     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0104     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0105     descriptions.add("test", desc);
0106   }
0107 
0108 private:
0109   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) override {
0110     mymes_.bookall(ibooker);
0111   }
0112 
0113   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {
0114     mymes_.fillall(iEvent.luminosityBlock(), iEvent.run(), myvalue_);
0115   }
0116 
0117   BookerFiller<DQMStore::IBooker, MonitorElement, /* DOLUMI */ true> mymes_;
0118   double myvalue_;
0119 };
0120 DEFINE_FWK_MODULE(TestDQMEDAnalyzer);
0121 
0122 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0123 class TestDQMOneEDAnalyzer : public DQMOneEDAnalyzer<> {
0124 public:
0125   explicit TestDQMOneEDAnalyzer(const edm::ParameterSet& iConfig)
0126       : mymes_(iConfig.getParameter<std::string>("folder"), iConfig.getParameter<int>("howmany")),
0127         myvalue_(iConfig.getParameter<double>("value")) {}
0128 
0129   ~TestDQMOneEDAnalyzer() override{};
0130 
0131   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0132     edm::ParameterSetDescription desc;
0133     desc.add<std::string>("folder", "One/testone")->setComment("Where to put all the histograms");
0134     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0135     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0136     descriptions.add("testone", desc);
0137   }
0138 
0139 private:
0140   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) override {
0141     mymes_.bookall(ibooker);
0142   }
0143 
0144   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {
0145     mymes_.fillall(iEvent.luminosityBlock(), iEvent.run(), myvalue_);
0146   }
0147 
0148   BookerFiller<DQMStore::IBooker, MonitorElement, /* DOLUMI */ true> mymes_;
0149   double myvalue_;
0150 };
0151 DEFINE_FWK_MODULE(TestDQMOneEDAnalyzer);
0152 
0153 class TestDQMOneFillRunEDAnalyzer : public DQMOneEDAnalyzer<> {
0154 public:
0155   explicit TestDQMOneFillRunEDAnalyzer(const edm::ParameterSet& iConfig)
0156       : mymes_(iConfig.getParameter<std::string>("folder"), iConfig.getParameter<int>("howmany")),
0157         myvalue_(iConfig.getParameter<double>("value")) {}
0158 
0159   ~TestDQMOneFillRunEDAnalyzer() override{};
0160 
0161   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0162     edm::ParameterSetDescription desc;
0163     desc.add<std::string>("folder", "One/testonefillrun")->setComment("Where to put all the histograms");
0164     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0165     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0166     descriptions.add("testonefillrun", desc);
0167   }
0168 
0169 private:
0170   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) override {
0171     mymes_.bookall(ibooker);
0172   }
0173 
0174   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {}
0175   void dqmEndRun(edm::Run const& run, edm::EventSetup const&) override { mymes_.fillall(0, run.run(), myvalue_); }
0176 
0177   BookerFiller<DQMStore::IBooker, MonitorElement> mymes_;
0178   double myvalue_;
0179 };
0180 DEFINE_FWK_MODULE(TestDQMOneFillRunEDAnalyzer);
0181 
0182 class TestDQMOneLumiEDAnalyzer : public DQMOneLumiEDAnalyzer<> {
0183 public:
0184   explicit TestDQMOneLumiEDAnalyzer(const edm::ParameterSet& iConfig)
0185       : mymes_(iConfig.getParameter<std::string>("folder"), iConfig.getParameter<int>("howmany")),
0186         myvalue_(iConfig.getParameter<double>("value")) {}
0187 
0188   ~TestDQMOneLumiEDAnalyzer() override{};
0189 
0190   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0191     edm::ParameterSetDescription desc;
0192     desc.add<std::string>("folder", "One/testonelumi")->setComment("Where to put all the histograms");
0193     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0194     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0195     descriptions.add("testonelumi", desc);
0196   }
0197 
0198 private:
0199   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) override {
0200     mymes_.bookall(ibooker);
0201   }
0202 
0203   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {
0204     mymes_.fillall(iEvent.luminosityBlock(), iEvent.run(), myvalue_);
0205   }
0206 
0207   BookerFiller<DQMStore::IBooker, MonitorElement, /* DOLUMI */ true> mymes_;
0208   double myvalue_;
0209 };
0210 DEFINE_FWK_MODULE(TestDQMOneLumiEDAnalyzer);
0211 
0212 class TestDQMOneLumiFillLumiEDAnalyzer : public DQMOneLumiEDAnalyzer<> {
0213 public:
0214   explicit TestDQMOneLumiFillLumiEDAnalyzer(const edm::ParameterSet& iConfig)
0215       : mymes_(iConfig.getParameter<std::string>("folder"), iConfig.getParameter<int>("howmany")),
0216         myvalue_(iConfig.getParameter<double>("value")) {}
0217 
0218   ~TestDQMOneLumiFillLumiEDAnalyzer() override{};
0219 
0220   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0221     edm::ParameterSetDescription desc;
0222     desc.add<std::string>("folder", "One/testonelumifilllumi")->setComment("Where to put all the histograms");
0223     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0224     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0225     descriptions.add("testonelumifilllumi", desc);
0226   }
0227 
0228 private:
0229   void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) override {
0230     mymes_.bookall(ibooker);
0231   }
0232 
0233   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {}
0234   void dqmBeginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) override {
0235     mymes_.fillall(lumi.luminosityBlock(), lumi.run(), myvalue_);
0236   }
0237 
0238   BookerFiller<DQMStore::IBooker, MonitorElement, /* DOLUMI */ true> mymes_;
0239   double myvalue_;
0240 };
0241 DEFINE_FWK_MODULE(TestDQMOneLumiFillLumiEDAnalyzer);
0242 
0243 #include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h"
0244 typedef BookerFiller<dqm::reco::DQMStore::IBooker, dqm::reco::MonitorElement> TestHistograms;
0245 
0246 class TestDQMGlobalEDAnalyzer : public DQMGlobalEDAnalyzer<TestHistograms> {
0247 public:
0248   explicit TestDQMGlobalEDAnalyzer(const edm::ParameterSet& iConfig)
0249       : folder_(iConfig.getParameter<std::string>("folder")),
0250         howmany_(iConfig.getParameter<int>("howmany")),
0251         myvalue_(iConfig.getParameter<double>("value")) {}
0252   ~TestDQMGlobalEDAnalyzer() override{};
0253 
0254   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0255     edm::ParameterSetDescription desc;
0256     desc.add<std::string>("folder", "Global/testglobal")->setComment("Where to put all the histograms");
0257     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0258     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0259     descriptions.add("testglobal", desc);
0260   }
0261 
0262 private:
0263   void bookHistograms(DQMStore::IBooker& ibooker,
0264                       edm::Run const&,
0265                       edm::EventSetup const&,
0266                       TestHistograms& h) const override {
0267     h.folder = this->folder_;
0268     h.howmany = this->howmany_;
0269     h.bookall(ibooker);
0270   }
0271 
0272   void dqmAnalyze(edm::Event const& iEvent, edm::EventSetup const&, TestHistograms const& h) const override {
0273     h.fillall(iEvent.luminosityBlock(), iEvent.run(), myvalue_);
0274   }
0275 
0276 private:
0277   std::string folder_;
0278   int howmany_;
0279   double myvalue_;
0280 };
0281 DEFINE_FWK_MODULE(TestDQMGlobalEDAnalyzer);
0282 
0283 class TestDQMGlobalRunSummaryEDAnalyzer : public DQMGlobalRunSummaryEDAnalyzer<TestHistograms, int> {
0284 public:
0285   explicit TestDQMGlobalRunSummaryEDAnalyzer(const edm::ParameterSet& iConfig)
0286       : folder_(iConfig.getParameter<std::string>("folder")),
0287         howmany_(iConfig.getParameter<int>("howmany")),
0288         myvalue_(iConfig.getParameter<double>("value")) {}
0289   ~TestDQMGlobalRunSummaryEDAnalyzer() override{};
0290 
0291   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0292     edm::ParameterSetDescription desc;
0293     desc.add<std::string>("folder", "Global/testglobal")->setComment("Where to put all the histograms");
0294     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0295     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0296     descriptions.add("testglobalrunsummary", desc);
0297   }
0298 
0299 private:
0300   std::shared_ptr<int> globalBeginRunSummary(edm::Run const&, edm::EventSetup const&) const override {
0301     return std::make_shared<int>(0);
0302   }
0303 
0304   void bookHistograms(DQMStore::IBooker& ibooker,
0305                       edm::Run const&,
0306                       edm::EventSetup const&,
0307                       TestHistograms& h) const override {
0308     h.folder = this->folder_;
0309     h.howmany = this->howmany_;
0310     h.bookall(ibooker);
0311   }
0312 
0313   void dqmAnalyze(edm::Event const& iEvent, edm::EventSetup const&, TestHistograms const& h) const override {
0314     h.fillall(iEvent.luminosityBlock(), iEvent.run(), myvalue_);
0315   }
0316 
0317   void streamEndRunSummary(edm::StreamID, edm::Run const&, edm::EventSetup const&, int* runSummaryCache) const override {
0318     (*runSummaryCache) += 1;
0319   }
0320 
0321   void globalEndRunSummary(edm::Run const&, edm::EventSetup const&, int* runSummaryCache) const override {}
0322 
0323   void dqmEndRun(edm::Run const& run,
0324                  edm::EventSetup const& setup,
0325                  TestHistograms const& h,
0326                  int const& runSummaryCache) const override {}
0327 
0328 private:
0329   std::string folder_;
0330   int howmany_;
0331   double myvalue_;
0332 };
0333 DEFINE_FWK_MODULE(TestDQMGlobalRunSummaryEDAnalyzer);
0334 
0335 #include "FWCore/Framework/interface/EDAnalyzer.h"
0336 class TestLegacyEDAnalyzer : public edm::EDAnalyzer {
0337 public:
0338   typedef dqm::legacy::DQMStore DQMStore;
0339   typedef dqm::legacy::MonitorElement MonitorElement;
0340 
0341   explicit TestLegacyEDAnalyzer(const edm::ParameterSet& iConfig)
0342       : mymes_(iConfig.getParameter<std::string>("folder"), iConfig.getParameter<int>("howmany")),
0343         myvalue_(iConfig.getParameter<double>("value")) {}
0344 
0345   ~TestLegacyEDAnalyzer() override{};
0346 
0347   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0348     edm::ParameterSetDescription desc;
0349     desc.add<std::string>("folder", "Legacy/testlegacy")->setComment("Where to put all the histograms");
0350     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0351     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0352     descriptions.add("testlegacy", desc);
0353   }
0354 
0355 private:
0356   void beginRun(edm::Run const&, edm::EventSetup const&) override {
0357     edm::Service<DQMStore> store;
0358     mymes_.bookall(*store);
0359   }
0360 
0361   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {
0362     mymes_.fillall(iEvent.luminosityBlock(), iEvent.run(), myvalue_);
0363   }
0364 
0365   BookerFiller<DQMStore, MonitorElement, /* DOLUMI */ true> mymes_;
0366   double myvalue_;
0367 };
0368 DEFINE_FWK_MODULE(TestLegacyEDAnalyzer);
0369 
0370 class TestLegacyFillRunEDAnalyzer : public edm::EDAnalyzer {
0371 public:
0372   typedef dqm::legacy::DQMStore DQMStore;
0373   typedef dqm::legacy::MonitorElement MonitorElement;
0374 
0375   explicit TestLegacyFillRunEDAnalyzer(const edm::ParameterSet& iConfig)
0376       : mymes_(iConfig.getParameter<std::string>("folder"), iConfig.getParameter<int>("howmany")),
0377         myvalue_(iConfig.getParameter<double>("value")) {}
0378 
0379   ~TestLegacyFillRunEDAnalyzer() override{};
0380 
0381   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0382     edm::ParameterSetDescription desc;
0383     desc.add<std::string>("folder", "Legacy/testlegacyfillrun")->setComment("Where to put all the histograms");
0384     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0385     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0386     descriptions.add("testlegacyfillrun", desc);
0387   }
0388 
0389 private:
0390   void beginRun(edm::Run const& run, edm::EventSetup const&) override {
0391     edm::Service<DQMStore> store;
0392     mymes_.bookall(*store);
0393     mymes_.fillall(0, run.run(), myvalue_);
0394   }
0395 
0396   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {}
0397 
0398   BookerFiller<DQMStore, MonitorElement> mymes_;
0399   double myvalue_;
0400 };
0401 DEFINE_FWK_MODULE(TestLegacyFillRunEDAnalyzer);
0402 
0403 class TestLegacyFillLumiEDAnalyzer : public edm::EDAnalyzer {
0404 public:
0405   typedef dqm::legacy::DQMStore DQMStore;
0406   typedef dqm::legacy::MonitorElement MonitorElement;
0407 
0408   explicit TestLegacyFillLumiEDAnalyzer(const edm::ParameterSet& iConfig)
0409       : mymes_(iConfig.getParameter<std::string>("folder"), iConfig.getParameter<int>("howmany")),
0410         myvalue_(iConfig.getParameter<double>("value")) {}
0411 
0412   ~TestLegacyFillLumiEDAnalyzer() override{};
0413 
0414   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0415     edm::ParameterSetDescription desc;
0416     desc.add<std::string>("folder", "Legacy/testlegacyfilllumi")->setComment("Where to put all the histograms");
0417     desc.add<int>("howmany", 1)->setComment("How many copies of each ME to put");
0418     desc.add<double>("value", 1)->setComment("Which value to use on the third axis (first two are lumi and run)");
0419     descriptions.add("testlegacyfilllumi", desc);
0420   }
0421 
0422 private:
0423   void beginRun(edm::Run const&, edm::EventSetup const&) override {
0424     edm::Service<DQMStore> store;
0425     mymes_.bookall(*store);
0426   }
0427 
0428   void beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const&) override {
0429     mymes_.fillall(lumi.luminosityBlock(), lumi.run(), myvalue_);
0430   }
0431 
0432   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {}
0433 
0434   BookerFiller<DQMStore, MonitorElement, /* DOLUMI */ true> mymes_;
0435   double myvalue_;
0436 };
0437 DEFINE_FWK_MODULE(TestLegacyFillLumiEDAnalyzer);