Go to the documentation of this file.00001 #include <memory>
00002 #include <string>
00003 #include <fstream>
00004 #include <iostream>
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/EDAnalyzer.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/MakerMacros.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/ServiceRegistry/interface/Service.h"
00011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00012 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayloadFromTable.h"
00013
00014 #include "CondFormats/PhysicsToolsObjects/interface/PerformanceWorkingPoint.h"
00015
00016
00017 class PhysicsPerformanceDBWriterFromFile_WPandPayload : public edm::EDAnalyzer
00018 {
00019 public:
00020 PhysicsPerformanceDBWriterFromFile_WPandPayload(const edm::ParameterSet&);
00021 virtual void beginJob();
00022 virtual void analyze(const edm::Event&, const edm::EventSetup&) {}
00023 virtual void endJob() {}
00024 ~PhysicsPerformanceDBWriterFromFile_WPandPayload() {}
00025
00026 private:
00027 std::string inputTxtFile;
00028 std::string rec1,rec2;
00029 };
00030
00031 PhysicsPerformanceDBWriterFromFile_WPandPayload::PhysicsPerformanceDBWriterFromFile_WPandPayload
00032 (const edm::ParameterSet& p)
00033 {
00034 inputTxtFile = p.getUntrackedParameter<std::string>("inputTxtFile");
00035 rec1 = p.getUntrackedParameter<std::string>("RecordPayload");
00036 rec2 = p.getUntrackedParameter<std::string>("RecordWP");
00037 }
00038
00039 void PhysicsPerformanceDBWriterFromFile_WPandPayload::beginJob()
00040 {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 std::ifstream in;
00056 std::cout << "Opening "<< inputTxtFile<<std::endl;
00057 in.open(inputTxtFile.c_str());
00058 std::string tagger;
00059 float cut;
00060
00061 std::string concreteType;
00062 std::string comment;
00063 std::vector<float> pl;
00064 int stride;
00065
00066 in >> tagger;
00067 std::cout << "WP Tagger is "<<tagger<<std::endl;
00068
00069 in >> cut;
00070 std::cout << "WP Cut is "<<cut<<std::endl;
00071
00072 in >> concreteType;
00073 std::cout << "concrete Type is "<<concreteType<<std::endl;
00074
00075
00076
00077
00078
00079 int nres, nbin;
00080 in >> nres;
00081 in >> nbin;
00082 std::cout <<" Results: " << nres<<" Binning variables: "<<nbin<<std::endl;
00083
00084 stride = nres+nbin*2;
00085
00086 int number=0;
00087
00088 std::vector<PerformanceResult::ResultType> res;
00089 std::vector<BinningVariables::BinningVariablesType> bin;
00090
00091 while (number<nres && !in.eof()) {
00092 int tmp;
00093 in>> tmp;
00094 res.push_back((PerformanceResult::ResultType)(tmp));
00095 number++;
00096 }
00097 if (number != nres){
00098 std::cout <<" Table not well formed"<<std::endl;
00099 }
00100 number=0;
00101 while (number<nbin && !in.eof()) {
00102 int tmp;
00103 in>> tmp;
00104 bin.push_back((BinningVariables::BinningVariablesType)(tmp));
00105 number++;
00106 }
00107 if (number != nbin){
00108 std::cout <<" Table not well formed"<<std::endl;
00109 }
00110
00111 number=0;
00112 while (!in.eof()){
00113 float temp;
00114 in >> temp;
00115 std::cout <<" Intersing "<<temp<< " in position "<<number<<std::endl;
00116 number++;
00117 pl.push_back(temp);
00118 }
00119
00120
00121
00122
00123 if (stride != nbin*2+nres){
00124 std::cout <<" Table not well formed"<<std::endl;
00125 }
00126 if ((number % stride) != 0){
00127 std::cout <<" Table not well formed"<<std::endl;
00128 }
00129
00130 std::cout <<" CLOSING "<<std::endl;
00131 in.close();
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 PerformanceWorkingPoint * wp = new PerformanceWorkingPoint(cut, tagger);
00146
00147 PerformancePayloadFromTable * btagpl = 0;
00148
00149 if (concreteType == "PerformancePayloadFromTable"){
00150 btagpl = new PerformancePayloadFromTable(res, bin, stride, pl);
00151 }else{
00152 std::cout <<" Non existing request: " <<concreteType<<std::endl;
00153 }
00154
00155 std::cout <<" Created the "<<concreteType <<" object"<<std::endl;
00156
00157 edm::Service<cond::service::PoolDBOutputService> s;
00158 if (s.isAvailable())
00159 {
00160 if (s->isNewTagRequest(rec1))
00161 {
00162 s->createNewIOV<PerformancePayload>(btagpl,
00163 s->beginOfTime(),
00164 s->endOfTime(),
00165 rec1);
00166 }
00167 else
00168 {
00169
00170 s->appendSinceTime<PerformancePayload>(btagpl,
00171
00172 111,
00173 rec1);
00174 }
00175 }
00176
00177
00178
00179 if (s.isAvailable())
00180 {
00181 if (s->isNewTagRequest(rec2))
00182 {
00183 s->createNewIOV<PerformanceWorkingPoint>(wp,
00184 s->beginOfTime(),
00185 s->endOfTime(),
00186 rec2);
00187 }
00188 else
00189 {
00190
00191 s->appendSinceTime<PerformanceWorkingPoint>(wp,
00193 111,
00194 rec2);
00195 }
00196 }
00197
00198
00199
00200 }
00201
00202 DEFINE_FWK_MODULE(PhysicsPerformanceDBWriterFromFile_WPandPayload);