Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:16

0001 #ifndef CalibratedElectronProducer_h
0002 #define CalibratedElectronProducer_h
0003 
0004 #include <string>
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h"
0013 #include "CondFormats/GBRForest/interface/GBRForest.h"
0014 #include <TFile.h>
0015 
0016 class GBRForestGetterFromDB : public edm::one::EDAnalyzer<> {
0017 public:
0018   explicit GBRForestGetterFromDB(const edm::ParameterSet &);
0019   ~GBRForestGetterFromDB() override;
0020   void analyze(const edm::Event &, const edm::EventSetup &) override;
0021 
0022 private:
0023   std::string theGBRForestName;
0024   std::string theOutputFileName;
0025   std::string theOutputObjectName;
0026   edm::ESGetToken<GBRForest, GBRWrapperRcd> theGBRForestToken_;
0027 };
0028 
0029 GBRForestGetterFromDB::GBRForestGetterFromDB(const edm::ParameterSet &conf)
0030     : theGBRForestName(conf.getParameter<std::string>("grbForestName")),
0031       theOutputFileName(conf.getUntrackedParameter<std::string>("outputFileName")),
0032       theOutputObjectName(conf.getUntrackedParameter<std::string>(
0033           "outputObjectName", theGBRForestName.empty() ? "GBRForest" : theGBRForestName)),
0034       theGBRForestToken_(esConsumes()) {}
0035 
0036 GBRForestGetterFromDB::~GBRForestGetterFromDB() {}
0037 
0038 void GBRForestGetterFromDB::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0039   auto theGBRForestHandle = iSetup.getHandle(theGBRForestToken_);
0040   TFile *fOut = TFile::Open(theOutputFileName.c_str(), "RECREATE");
0041   fOut->WriteObject(theGBRForestHandle.product(), theOutputObjectName.c_str());
0042   fOut->Close();
0043   edm::LogPrint("GBRForestGetterFromDB") << "Wrote output to " << theOutputFileName;
0044 }
0045 
0046 #include "FWCore/Framework/interface/MakerMacros.h"
0047 DEFINE_FWK_MODULE(GBRForestGetterFromDB);
0048 
0049 #endif