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() override;
22  virtual void analyze(const edm::Event&, const edm::EventSetup&) override {}
23  virtual void endJob() override {}
25 
26 private:
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());
59  float cut;
60 
61  std::string concreteType;
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  if (! stride)
86  {
87  std::cout << " Malformed input file" << std::endl;
88  exit(1);
89  }
90 
91  int number=0;
92 
93  std::vector<PerformanceResult::ResultType> res;
94  std::vector<BinningVariables::BinningVariablesType> bin;
95 
96  while (number<nres && !in.eof()) {
97  int tmp;
98  in>> tmp;
99  res.push_back((PerformanceResult::ResultType)(tmp));
100  number++;
101  }
102  if (number != nres){
103  std::cout <<" Table not well formed"<<std::endl;
104  }
105  number=0;
106  while (number<nbin && !in.eof()) {
107  int tmp;
108  in>> tmp;
109  bin.push_back((BinningVariables::BinningVariablesType)(tmp));
110  number++;
111  }
112  if (number != nbin){
113  std::cout <<" Table not well formed"<<std::endl;
114  }
115 
116  number=0;
117  while (!in.eof()){
118  float temp;
119  in >> temp;
120  std::cout <<" Intersing "<<temp<< " in position "<<number<<std::endl;
121  number++;
122  pl.push_back(temp);
123  }
124 
125  //
126  // CHECKS
127  //
128  if (stride != nbin*2+nres){
129  std::cout <<" Table not well formed"<<std::endl;
130  }
131  if ((number % stride) != 0){
132  std::cout <<" Table not well formed"<<std::endl;
133  }
134 
135  std::cout <<" CLOSING "<<std::endl;
136  in.close();
137 
138 
139  /* for (int k=0;k<(number/stride); k++){
140  for (int j=0; j<stride; j++){
141  std::cout << "Pos["<<k<<","<<j<<"] = "<<pl[k*stride+j]<<std::endl;
142  }
143  }
144  */
145 
146  //
147  // now create pl etc etc
148  //
149 
150  PerformanceWorkingPoint * wp = new PerformanceWorkingPoint(cut, tagger);
151 
152  PerformancePayloadFromTable * btagpl = 0;
153 
154  if (concreteType == "PerformancePayloadFromTable"){
155  btagpl = new PerformancePayloadFromTable(res, bin, stride, pl);
156  }else{
157  std::cout <<" Non existing request: " <<concreteType<<std::endl;
158  }
159 
160  std::cout <<" Created the "<<concreteType <<" object"<<std::endl;
161 
163  if (s.isAvailable())
164  {
165  if (s->isNewTagRequest(rec1))
166  {
167  s->createNewIOV<PerformancePayload>(btagpl,
168  s->beginOfTime(),
169  s->endOfTime(),
170  rec1);
171  }
172  else
173  {
174 
176  // JUST A STUPID PATCH
177  111,
178  rec1);
179  }
180  }
181 
182  // write also the WP
183 
184  if (s.isAvailable())
185  {
186  if (s->isNewTagRequest(rec2))
187  {
189  s->beginOfTime(),
190  s->endOfTime(),
191  rec2);
192  }
193  else
194  {
195 
198  111,
199  rec2);
200  }
201  }
202 
203 
204 
205 }
206 
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:46
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 &) override
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple cout
Definition: gather_cfg.py:145
#define comment(par)
Definition: vmac.h:161