CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhysicsPerformanceDBWriterFromFile_WPandPayload.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 #include <fstream>
4 #include <iostream>
13 
15 
16 
18 {
19 public:
21  virtual void beginJob();
22  virtual void analyze(const edm::Event&, const edm::EventSetup&) {}
23  virtual void endJob() {}
25 
26 private:
27  std::string inputTxtFile;
28  std::string rec1,rec2;
29 };
30 
33 {
34  inputTxtFile = p.getUntrackedParameter<std::string>("inputTxtFile");
35  rec1 = p.getUntrackedParameter<std::string>("RecordPayload");
36  rec2 = p.getUntrackedParameter<std::string>("RecordWP");
37 }
38 
40 {
41  //
42  // read object from file
43  //
44 
45  //
46  // File Format is
47  // - tagger name
48  // - cut
49  // - concrete class name
50  // - how many results and how many binning
51  // - their values
52  // - vector<float>
53  //
54 
55  std::ifstream in;
56  std::cout << "Opening "<< inputTxtFile<<std::endl;
57  in.open(inputTxtFile.c_str());
58  std::string tagger;
59  float cut;
60 
61  std::string concreteType;
62  std::string comment;
63  std::vector<float> pl;
64  int stride;
65 
66  in >> tagger;
67  std::cout << "WP Tagger is "<<tagger<<std::endl;
68 
69  in >> cut;
70  std::cout << "WP Cut is "<<cut<<std::endl;
71 
72  in >> concreteType;
73  std::cout << "concrete Type is "<<concreteType<<std::endl;
74 
75  // return ;
76 
77  // read # of results
78 
79  int nres, nbin;
80  in >> nres;
81  in >> nbin;
82  std::cout <<" Results: " << nres<<" Binning variables: "<<nbin<<std::endl;
83 
84  stride = nres+nbin*2;
85 
86  int number=0;
87 
88  std::vector<PerformanceResult::ResultType> res;
89  std::vector<BinningVariables::BinningVariablesType> bin;
90 
91  while (number<nres && !in.eof()) {
92  int tmp;
93  in>> tmp;
94  res.push_back((PerformanceResult::ResultType)(tmp));
95  number++;
96  }
97  if (number != nres){
98  std::cout <<" Table not well formed"<<std::endl;
99  }
100  number=0;
101  while (number<nbin && !in.eof()) {
102  int tmp;
103  in>> tmp;
104  bin.push_back((BinningVariables::BinningVariablesType)(tmp));
105  number++;
106  }
107  if (number != nbin){
108  std::cout <<" Table not well formed"<<std::endl;
109  }
110 
111  number=0;
112  while (!in.eof()){
113  float temp;
114  in >> temp;
115  std::cout <<" Intersing "<<temp<< " in position "<<number<<std::endl;
116  number++;
117  pl.push_back(temp);
118  }
119 
120  //
121  // CHECKS
122  //
123  if (stride != nbin*2+nres){
124  std::cout <<" Table not well formed"<<std::endl;
125  }
126  if ((number % stride) != 0){
127  std::cout <<" Table not well formed"<<std::endl;
128  }
129 
130  std::cout <<" CLOSING "<<std::endl;
131  in.close();
132 
133 
134  /* for (int k=0;k<(number/stride); k++){
135  for (int j=0; j<stride; j++){
136  std::cout << "Pos["<<k<<","<<j<<"] = "<<pl[k*stride+j]<<std::endl;
137  }
138  }
139  */
140 
141  //
142  // now create pl etc etc
143  //
144 
145  PerformanceWorkingPoint * wp = new PerformanceWorkingPoint(cut, tagger);
146 
147  PerformancePayloadFromTable * btagpl = 0;
148 
149  if (concreteType == "PerformancePayloadFromTable"){
150  btagpl = new PerformancePayloadFromTable(res, bin, stride, pl);
151  }else{
152  std::cout <<" Non existing request: " <<concreteType<<std::endl;
153  }
154 
155  std::cout <<" Created the "<<concreteType <<" object"<<std::endl;
156 
158  if (s.isAvailable())
159  {
160  if (s->isNewTagRequest(rec1))
161  {
162  s->createNewIOV<PerformancePayload>(btagpl,
163  s->beginOfTime(),
164  s->endOfTime(),
165  rec1);
166  }
167  else
168  {
169 
171  // JUST A STUPID PATCH
172  111,
173  rec1);
174  }
175  }
176 
177  // write also the WP
178 
179  if (s.isAvailable())
180  {
181  if (s->isNewTagRequest(rec2))
182  {
184  s->beginOfTime(),
185  s->endOfTime(),
186  rec2);
187  }
188  else
189  {
190 
193  111,
194  rec2);
195  }
196  }
197 
198 
199 
200 }
201 
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:47
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple cout
Definition: gather_cfg.py:121
#define comment(par)
Definition: vmac.h:162