Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-14 11:44:45

0001 
0002 /*----------------------------------------------------------------------
0003 
0004 Toy EDProducers and EDProducts for testing purposes only.
0005 
0006 ----------------------------------------------------------------------*/
0007 
0008 #include <stdexcept>
0009 #include <string>
0010 #include <iostream>
0011 #include <map>
0012 
0013 #include "CondFormats/Calibration/interface/Pedestals.h"
0014 #include "CondFormats/DataRecord/interface/PedestalsRcd.h"
0015 
0016 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 
0021 #include "TFile.h"
0022 
0023 using namespace std;
0024 
0025 namespace edmtest {
0026   class PedestalsAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0027   public:
0028     explicit PedestalsAnalyzer(edm::ParameterSet const& p)
0029         : thePedestalToken_(esConsumes()), theBeginRunPedestalToken_(esConsumes<edm::Transition::BeginRun>()) {
0030       edm::LogPrint("PedestalsAnalyzer") << "PedestalsAnalyzer";
0031     }
0032     explicit PedestalsAnalyzer(int i) { edm::LogPrint("PedestalsAnalyzer") << "PedestalsAnalyzer " << i; }
0033     virtual ~PedestalsAnalyzer() { edm::LogPrint("PedestalsAnalyzer") << "~PedestalsAnalyzer "; }
0034     virtual void beginJob() override;
0035     virtual void beginRun(const edm::Run&, const edm::EventSetup& context) override;
0036     virtual void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0037     virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
0038 
0039   private:
0040     const edm::ESGetToken<Pedestals, PedestalsRcd> thePedestalToken_, theBeginRunPedestalToken_;
0041   };
0042   void PedestalsAnalyzer::beginRun(const edm::Run&, const edm::EventSetup& context) {
0043     edm::LogPrint("PedestalsAnalyzer") << "###PedestalsAnalyzer::beginRun";
0044     edm::LogPrint("PedestalsAnalyzer") << "got context";
0045     auto const& myBeginRunPed = &context.getData(theBeginRunPedestalToken_);
0046     edm::LogPrint("PedestalsAnalyzer") << "Pedestals* " << myBeginRunPed;
0047   }
0048   void PedestalsAnalyzer::beginJob() { edm::LogPrint("PedestalsAnalyzer") << "###PedestalsAnalyzer::beginJob"; }
0049   void PedestalsAnalyzer::analyze(const edm::Event& e, const edm::EventSetup& context) {
0050     using namespace edm::eventsetup;
0051     // Context is not used.
0052     edm::LogPrint("PedestalsAnalyzer") << " I AM IN RUN NUMBER " << e.id().run();
0053     edm::LogPrint("PedestalsAnalyzer") << " ---EVENT NUMBER " << e.id().event();
0054     edm::eventsetup::EventSetupRecordKey recordKey(
0055         edm::eventsetup::EventSetupRecordKey::TypeTag::findType("PedestalsRcd"));
0056     if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) {
0057       //record not found
0058       edm::LogPrint("PedestalsAnalyzer") << "Record \"PedestalsRcd\" does not exist";
0059     }
0060     edm::LogPrint("PedestalsAnalyzer") << "got context";
0061     auto const& myped = &context.getData(thePedestalToken_);
0062     edm::LogPrint("PedestalsAnalyzer") << "Pedestals* " << myped;
0063     for (std::vector<Pedestals::Item>::const_iterator it = myped->m_pedestals.begin(); it != myped->m_pedestals.end();
0064          ++it)
0065       edm::LogPrint("PedestalsAnalyzer") << " mean: " << it->m_mean << " variance: " << it->m_variance;
0066     edm::LogPrint("PedestalsAnalyzer") << std::endl;
0067 
0068     TFile* f = TFile::Open("MyPedestal.xml", "recreate");
0069     f->WriteObjectAny(myped, "Pedestals", "Pedestals");
0070     f->Close();
0071   }
0072   void PedestalsAnalyzer::endRun(const edm::Run&, const edm::EventSetup&) {}
0073   DEFINE_FWK_MODULE(PedestalsAnalyzer);
0074 }  // namespace edmtest