Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:53

0001 // -*- C++ -*-
0002 //
0003 // Package:    DummyFillDQMStore
0004 // Class:      DummyFillDQMStore
0005 //
0006 /**\class DummyFillDQMStore DummyFillDQMStore.cc DQMServices/DummyFillDQMStore/src/DummyFillDQMStore.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Christopher Jones
0015 //         Created:  Fri Apr 29 18:05:50 CDT 2011
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0024 
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 
0030 #include "FWCore/ServiceRegistry/interface/Service.h"
0031 
0032 //
0033 // class declaration
0034 //
0035 namespace {
0036   typedef dqm::legacy::MonitorElement MonitorElement;
0037   typedef dqm::legacy::DQMStore DQMStore;
0038 
0039   class FillerBase {
0040   public:
0041     virtual ~FillerBase() = default;
0042     virtual void fill() = 0;
0043     virtual void reset() = 0;
0044   };
0045 
0046   class TH1FFiller : public FillerBase {
0047   public:
0048     TH1FFiller(const edm::ParameterSet& iPSet, DQMStore& iStore, bool iSetLumiFlag)
0049         : m_min(iPSet.getUntrackedParameter<double>("lowX")), m_steps(iPSet.getUntrackedParameter<int>("nchX")) {
0050       std::string extension;
0051       if (iSetLumiFlag) {
0052         extension = "_lumi";
0053       }
0054       m_element = iStore.book1D(iPSet.getUntrackedParameter<std::string>("name") + extension,
0055                                 iPSet.getUntrackedParameter<std::string>("title") + extension,
0056                                 m_steps,
0057                                 m_min,
0058                                 iPSet.getUntrackedParameter<double>("highX"));
0059       m_valueToFill = iPSet.getUntrackedParameter<double>("value");
0060     }
0061 
0062     ~TH1FFiller() override{};
0063 
0064     void reset() override { m_element->Reset(); }
0065     void fill() override { m_element->Fill(m_valueToFill); }
0066 
0067   private:
0068     double m_valueToFill;
0069     double m_min;
0070     unsigned int m_steps;
0071     MonitorElement* m_element;
0072   };
0073 
0074   class TH2FFiller : public FillerBase {
0075   public:
0076     TH2FFiller(const edm::ParameterSet& iPSet, DQMStore& iStore, bool iSetLumiFlag)
0077         : m_min(iPSet.getUntrackedParameter<double>("lowX")), m_steps(iPSet.getUntrackedParameter<int>("nchX")) {
0078       std::string extension;
0079       if (iSetLumiFlag) {
0080         extension = "_lumi";
0081       }
0082       m_element = iStore.book2D(iPSet.getUntrackedParameter<std::string>("name") + extension,
0083                                 iPSet.getUntrackedParameter<std::string>("title") + extension,
0084                                 m_steps,
0085                                 m_min,
0086                                 iPSet.getUntrackedParameter<double>("highX"),
0087                                 iPSet.getUntrackedParameter<int>("nchY"),
0088                                 iPSet.getUntrackedParameter<double>("lowY"),
0089                                 iPSet.getUntrackedParameter<double>("highY"));
0090       m_valueToFill = iPSet.getUntrackedParameter<double>("value");
0091     }
0092 
0093     ~TH2FFiller() override{};
0094 
0095     void reset() override { m_element->Reset(); }
0096     void fill() override { m_element->Fill(m_valueToFill, m_valueToFill); }
0097 
0098   private:
0099     double m_valueToFill;
0100     double m_min;
0101     unsigned int m_steps;
0102     MonitorElement* m_element;
0103   };
0104 
0105 }  // namespace
0106 
0107 class DummyFillDQMStore : public DQMOneLumiEDAnalyzer<> {
0108 public:
0109   explicit DummyFillDQMStore(const edm::ParameterSet&);
0110   ~DummyFillDQMStore() override;
0111 
0112   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0113 
0114   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0115   void analyze(edm::Event const&, edm::EventSetup const&) override;
0116   void dqmEndRun(edm::Run const&, edm::EventSetup const&) override;
0117   void dqmBeginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0118   void dqmEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0119 
0120 private:
0121   // ----------member data ---------------------------
0122   edm::ParameterSet iConfig;
0123   std::vector<std::shared_ptr<FillerBase> > m_runFillers;
0124   std::vector<std::shared_ptr<FillerBase> > m_lumiFillers;
0125   bool m_fillRuns;
0126   bool m_fillLumis;
0127 };
0128 
0129 //
0130 // constants, enums and typedefs
0131 //
0132 
0133 //
0134 // static data member definitions
0135 //
0136 
0137 //
0138 // constructors and destructor
0139 //
0140 DummyFillDQMStore::DummyFillDQMStore(const edm::ParameterSet& iConfig)
0141     : m_fillRuns(iConfig.getUntrackedParameter<bool>("fillRuns")),
0142       m_fillLumis(iConfig.getUntrackedParameter<bool>("fillLumis")) {
0143   this->iConfig = iConfig;
0144 }
0145 
0146 void DummyFillDQMStore::bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) {
0147   // this is fine as long as we don't do concurrent booking.
0148   edm::Service<DQMStore> dstore;
0149 
0150   typedef std::vector<edm::ParameterSet> PSets;
0151   const PSets& elements = iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >("elements");
0152   if (m_fillRuns) {
0153     dstore->setScope(MonitorElementData::Scope::RUN);
0154     m_runFillers.clear();
0155     m_runFillers.reserve(elements.size());
0156     for (PSets::const_iterator it = elements.begin(), itEnd = elements.end(); it != itEnd; ++it) {
0157       switch (it->getUntrackedParameter<unsigned int>("type", 1)) {
0158         case 1:
0159           m_runFillers.push_back(std::shared_ptr<FillerBase>(new TH1FFiller(*it, *dstore, false)));
0160           break;
0161         case 2:
0162           m_runFillers.push_back(std::shared_ptr<FillerBase>(new TH2FFiller(*it, *dstore, false)));
0163           break;
0164       }
0165     }
0166   }
0167 
0168   if (m_fillLumis) {
0169     dstore->setScope(MonitorElementData::Scope::LUMI);
0170     m_lumiFillers.clear();
0171     m_lumiFillers.reserve(elements.size());
0172     for (PSets::const_iterator it = elements.begin(), itEnd = elements.end(); it != itEnd; ++it) {
0173       switch (it->getUntrackedParameter<unsigned int>("type", 1)) {
0174         case 1:
0175           m_lumiFillers.push_back(std::shared_ptr<FillerBase>(new TH1FFiller(*it, *dstore, true)));
0176           break;
0177         case 2:
0178           m_lumiFillers.push_back(std::shared_ptr<FillerBase>(new TH2FFiller(*it, *dstore, true)));
0179           break;
0180       }
0181     }
0182   }
0183 }
0184 
0185 DummyFillDQMStore::~DummyFillDQMStore() {
0186   // do anything here that needs to be done at desctruction time
0187   // (e.g. close files, deallocate resources etc.)
0188 }
0189 
0190 //
0191 // member functions
0192 //
0193 
0194 // ------------ method called to produce the data  ------------
0195 void DummyFillDQMStore::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0196   using namespace edm;
0197   /* This is an event example
0198    //Read 'ExampleData' from the Event
0199    Handle<ExampleData> pIn;
0200    iEvent.getByLabel("example",pIn);
0201 
0202    //Use the ExampleData to create an ExampleData2 which 
0203    // is put into the Event
0204    std::unique_ptr<ExampleData2> pOut(new ExampleData2(*pIn));
0205    iEvent.put(pOut);
0206 */
0207 
0208   /* this is an EventSetup example
0209    //Read SetupData from the SetupRecord in the EventSetup
0210    ESHandle<SetupData> pSetup;
0211    iSetup.get<SetupRecord>().get(pSetup);
0212 */
0213 }
0214 
0215 // ------------ method called when ending the processing of a run  ------------
0216 void DummyFillDQMStore::dqmEndRun(edm::Run const&, edm::EventSetup const&) {
0217   for (std::vector<std::shared_ptr<FillerBase> >::iterator it = m_runFillers.begin(), itEnd = m_runFillers.end();
0218        it != itEnd;
0219        ++it) {
0220     (*it)->fill();
0221   }
0222 }
0223 
0224 // ------------ method called when starting to processes a luminosity block  ------------
0225 void DummyFillDQMStore::dqmBeginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {
0226   for (std::vector<std::shared_ptr<FillerBase> >::iterator it = m_lumiFillers.begin(), itEnd = m_lumiFillers.end();
0227        it != itEnd;
0228        ++it) {
0229     (*it)->reset();
0230   }
0231 }
0232 
0233 // ------------ method called when ending the processing of a luminosity block  ------------
0234 void DummyFillDQMStore::dqmEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {
0235   for (std::vector<std::shared_ptr<FillerBase> >::iterator it = m_lumiFillers.begin(), itEnd = m_lumiFillers.end();
0236        it != itEnd;
0237        ++it) {
0238     (*it)->fill();
0239   }
0240 }
0241 
0242 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0243 void DummyFillDQMStore::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0244   //The following says we do not know what parameters are allowed so do no validation
0245   // Please change this to state exactly what you do use, even if it is no parameters
0246   edm::ParameterSetDescription desc;
0247   desc.setUnknown();
0248   descriptions.addDefault(desc);
0249 }
0250 
0251 //define this as a plug-in
0252 DEFINE_FWK_MODULE(DummyFillDQMStore);