File indexing completed on 2024-04-06 12:02:27
0001 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0002
0003 #include "CondFormats/PhysicsToolsObjects/interface/PhysicsTFormulaPayload.h"
0004 #include "CondFormats/PhysicsToolsObjects/test/TFormulaWriter.h"
0005
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008
0009 #include <TFile.h>
0010 #include <TFormula.h>
0011
0012 TFormulaWriter::TFormulaWriter(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 TFormulaWriter::~TFormulaWriter() {
0022 for (std::vector<jobEntryType*>::iterator it = jobs_.begin(); it != jobs_.end(); ++it) {
0023 delete (*it);
0024 }
0025 }
0026
0027 void TFormulaWriter::analyze(const edm::Event&, const edm::EventSetup&) {
0028 std::cout << "<TFormulaWriter::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 TFormula = " << (*job)->formulaName_ << " from ROOT file = " << (*job)->inputFileName_ << "."
0033 << std::endl;
0034 const TFormula* formula = dynamic_cast<TFormula*>(inputFile->Get((*job)->formulaName_.data()));
0035 std::cout << "the formula is " << formula->GetExpFormula("p") << std::endl;
0036 delete inputFile;
0037 if (!formula)
0038 throw cms::Exception("TFormulaWriter") << " Failed to load TFormula = " << (*job)->formulaName_.data()
0039 << " from file = " << (*job)->inputFileName_ << " !!\n";
0040 edm::Service<cond::service::PoolDBOutputService> dbService;
0041 if (!dbService.isAvailable())
0042 throw cms::Exception("TFormulaWriter") << " Failed to access PoolDBOutputService !!\n";
0043 std::cout << " writing TFormula = " << (*job)->formulaName_
0044 << " to SQLlite file, record = " << (*job)->outputRecord_ << "." << std::endl;
0045 typedef std::pair<float, float> vfloat;
0046 std::vector<vfloat> limits;
0047 limits.push_back(vfloat(0., 1.e+6));
0048 std::vector<std::string> formulas;
0049 formulas.push_back((formula->GetExpFormula("p")).Data());
0050 PhysicsTFormulaPayload formulaPayload(limits, formulas);
0051 delete formula;
0052 dbService->writeOneIOV(formulaPayload, dbService->beginOfTime(), (*job)->outputRecord_);
0053 }
0054
0055 std::cout << "done." << std::endl;
0056 }
0057
0058 #include "FWCore/Framework/interface/MakerMacros.h"
0059
0060 DEFINE_FWK_MODULE(TFormulaWriter);