Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-07 04:53:56

0001 #include <stdexcept>
0002 #include <string>
0003 #include <iostream>
0004 #include <map>
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "CondFormats/RunInfo/interface/RunSummary.h"
0010 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
0011 
0012 using namespace std;
0013 
0014 namespace edmtest {
0015   class RunSummaryESAnalyzer : public edm::one::EDAnalyzer<> {
0016   private:
0017     const edm::ESGetToken<RunSummary, RunSummaryRcd> m_RunSummaryToken;
0018 
0019   public:
0020     explicit RunSummaryESAnalyzer(edm::ParameterSet const& p) : m_RunSummaryToken(esConsumes()) {
0021       edm::LogPrint("RunSummaryESAnalyzer") << "RunSummaryESAnalyzer" << std::endl;
0022     }
0023     explicit RunSummaryESAnalyzer(int i) {
0024       edm::LogPrint("RunSummaryESAnalyzer") << "RunSummaryESAnalyzer " << i << std::endl;
0025     }
0026     ~RunSummaryESAnalyzer() override { edm::LogPrint("RunSummaryESAnalyzer") << "~RunSummaryESAnalyzer " << std::endl; }
0027     void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0028 
0029   private:
0030   };
0031 
0032   void RunSummaryESAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0033     using namespace edm::eventsetup;
0034     edm::LogPrint("RunSummaryESAnalyzer") << "###RunSummaryESAnalyzer::analyze" << std::endl;
0035 
0036     // Context is not used.
0037     edm::LogPrint("RunSummaryESAnalyzer") << " I AM IN RUN NUMBER " << e.id().run() << std::endl;
0038     edm::LogPrint("RunSummaryESAnalyzer") << " ---EVENT NUMBER " << e.id().event() << std::endl;
0039     edm::eventsetup::EventSetupRecordKey recordKey(
0040         edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunSummaryRcd"));
0041     if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0042       //record not found
0043       edm::LogPrint("RunSummaryESAnalyzer") << "Record \"RunSummaryRcd"
0044                                             << "\" does not exist " << std::endl;
0045     }
0046     edm::LogPrint("RunSummaryESAnalyzer") << "got eshandle" << std::endl;
0047     edm::ESHandle<RunSummary> sum = context.getHandle(m_RunSummaryToken);
0048     edm::LogPrint("RunSummaryESAnalyzer") << "got context" << std::endl;
0049     const RunSummary* summary = sum.product();
0050     edm::LogPrint("RunSummaryESAnalyzer") << "got RunSummary* " << std::endl;
0051 
0052     edm::LogPrint("RunSummaryESAnalyzer") << "print  result" << std::endl;
0053     summary->printAllValues();
0054     std::vector<std::string> subdet = summary->getSubdtIn();
0055     edm::LogPrint("RunSummaryESAnalyzer") << "subdetector in the run " << std::endl;
0056     for (size_t i = 0; i < subdet.size(); i++) {
0057       edm::LogPrint("RunSummaryESAnalyzer") << "--> " << subdet[i] << std::endl;
0058     }
0059   }
0060   DEFINE_FWK_MODULE(RunSummaryESAnalyzer);
0061 }  // namespace edmtest