Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:27

0001 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0002 
0003 #include "CondFormats/PhysicsToolsObjects/interface/PhysicsTGraphPayload.h"
0004 #include "CondFormats/PhysicsToolsObjects/test/TGraphWriter.h"
0005 
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 
0009 #include <TFile.h>
0010 #include <TGraph.h>
0011 
0012 TGraphWriter::TGraphWriter(const edm::ParameterSet& cfg)
0013     : moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
0014   edm::VParameterSet cfgJobs = cfg.getParameter<edm::VParameterSet>("jobs");
0015   for (edm::VParameterSet::const_iterator cfgJob = cfgJobs.begin(); cfgJob != cfgJobs.end(); ++cfgJob) {
0016     jobEntryType* job = new jobEntryType(*cfgJob);
0017     jobs_.push_back(job);
0018   }
0019 }
0020 
0021 TGraphWriter::~TGraphWriter() {
0022   for (std::vector<jobEntryType*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) {
0023     delete (*it);
0024   }
0025 }
0026 
0027 void TGraphWriter::analyze(const edm::Event&, const edm::EventSetup&) {
0028   std::cout << "<TGraphWriter::analyze (moduleLabel = " << moduleLabel_ << ")>:" << std::endl;
0029 
0030   for (std::vector<jobEntryType*>::iterator job = jobs_.begin(); job != jobs_.end(); ++job) {
0031     TFile* inputFile = new TFile((*job)->inputFileName_.data());
0032     std::cout << "reading TGraph = " << (*job)->graphName_ << " from ROOT file = " << (*job)->inputFileName_ << "."
0033               << std::endl;
0034     const TGraph* graph = dynamic_cast<TGraph*>(inputFile->Get((*job)->graphName_.data()));
0035     delete inputFile;
0036     if (!graph)
0037       throw cms::Exception("TGraphWriter") << " Failed to load TGraph = " << (*job)->graphName_.data()
0038                                            << " from file = " << (*job)->inputFileName_ << " !!\n";
0039     edm::Service<cond::service::PoolDBOutputService> dbService;
0040     if (!dbService.isAvailable())
0041       throw cms::Exception("TGraphWriter") << " Failed to access PoolDBOutputService !!\n";
0042     std::cout << " writing TGraph = " << (*job)->graphName_ << " to SQLlite file, record = " << (*job)->outputRecord_
0043               << "." << std::endl;
0044     PhysicsTGraphPayload graphPayload(*graph);
0045     delete graph;
0046     dbService->writeOneIOV(graphPayload, dbService->beginOfTime(), (*job)->outputRecord_);
0047   }
0048 
0049   std::cout << "done." << std::endl;
0050 }
0051 
0052 #include "FWCore/Framework/interface/MakerMacros.h"
0053 
0054 DEFINE_FWK_MODULE(TGraphWriter);