1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "CondFormats/PhysicsToolsObjects/interface/PhysicsTGraphPayload.h"
#include "CondFormats/PhysicsToolsObjects/test/TGraphWriter.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Utilities/interface/Exception.h"
#include <TFile.h>
#include <TGraph.h>
TGraphWriter::TGraphWriter(const edm::ParameterSet& cfg)
: moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
edm::VParameterSet cfgJobs = cfg.getParameter<edm::VParameterSet>("jobs");
for (edm::VParameterSet::const_iterator cfgJob = cfgJobs.begin(); cfgJob != cfgJobs.end(); ++cfgJob) {
jobEntryType* job = new jobEntryType(*cfgJob);
jobs_.push_back(job);
}
}
TGraphWriter::~TGraphWriter() {
for (std::vector<jobEntryType*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) {
delete (*it);
}
}
void TGraphWriter::analyze(const edm::Event&, const edm::EventSetup&) {
std::cout << "<TGraphWriter::analyze (moduleLabel = " << moduleLabel_ << ")>:" << std::endl;
for (std::vector<jobEntryType*>::iterator job = jobs_.begin(); job != jobs_.end(); ++job) {
TFile* inputFile = new TFile((*job)->inputFileName_.data());
std::cout << "reading TGraph = " << (*job)->graphName_ << " from ROOT file = " << (*job)->inputFileName_ << "."
<< std::endl;
const TGraph* graph = dynamic_cast<TGraph*>(inputFile->Get((*job)->graphName_.data()));
delete inputFile;
if (!graph)
throw cms::Exception("TGraphWriter") << " Failed to load TGraph = " << (*job)->graphName_.data()
<< " from file = " << (*job)->inputFileName_ << " !!\n";
edm::Service<cond::service::PoolDBOutputService> dbService;
if (!dbService.isAvailable())
throw cms::Exception("TGraphWriter") << " Failed to access PoolDBOutputService !!\n";
std::cout << " writing TGraph = " << (*job)->graphName_ << " to SQLlite file, record = " << (*job)->outputRecord_
<< "." << std::endl;
PhysicsTGraphPayload graphPayload(*graph);
delete graph;
dbService->writeOneIOV(graphPayload, dbService->beginOfTime(), (*job)->outputRecord_);
}
std::cout << "done." << std::endl;
}
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(TGraphWriter);
|