CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhysicsPerformanceDBWriterFromFile_WPandPayload_IOV.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  unsigned long long iovBegin,iovEnd;
30 };
31 
34 {
35  inputTxtFile = p.getUntrackedParameter<std::string>("inputTxtFile");
36  rec1 = p.getUntrackedParameter<std::string>("RecordPayload");
37  rec2 = p.getUntrackedParameter<std::string>("RecordWP");
38  iovBegin = p.getParameter<unsigned long long>("IOVBegin");
39  iovEnd = p.getParameter<unsigned long long>("IOVEnd");
40 }
41 
43 {
44  //
45  // read object from file
46  //
47 
48  //
49  // File Format is
50  // - tagger name
51  // - cut
52  // - concrete class name
53  // - how many results and how many binning
54  // - their values
55  // - vector<float>
56  //
57 
58  std::ifstream in;
59  in.open(inputTxtFile.c_str());
60  std::string tagger;
61  float cut;
62 
63  std::string concreteType;
64  std::string comment;
65  std::vector<float> pl;
66  int stride;
67 
68  in >> tagger;
69  std::cout << "WP Tagger is "<<tagger<<std::endl;
70 
71  in >> cut;
72  std::cout << "WP Cut is "<<cut<<std::endl;
73 
74  in >> concreteType;
75  std::cout << "concrete Type is "<<concreteType<<std::endl;
76 
77  // return ;
78 
79  // read # of results
80 
81  int nres, nbin;
82  in >> nres;
83  in >> nbin;
84  std::cout <<" Results: " << nres<<" Binning variables: "<<nbin<<std::endl;
85 
86  stride = nres+nbin*2;
87 
88  int number=0;
89 
90  std::vector<PerformanceResult::ResultType> res;
91  std::vector<BinningVariables::BinningVariablesType> bin;
92 
93  while (number<nres && !in.eof()) {
94  int tmp;
95  in>> tmp;
96  res.push_back((PerformanceResult::ResultType)(tmp));
97  number++;
98  }
99  if (number != nres){
100  std::cout <<" Table not well formed"<<std::endl;
101  }
102  number=0;
103  while (number<nbin && !in.eof()) {
104  int tmp;
105  in>> tmp;
106  bin.push_back((BinningVariables::BinningVariablesType)(tmp));
107  number++;
108  }
109  if (number != nbin){
110  std::cout <<" Table not well formed"<<std::endl;
111  }
112 
113  number=0;
114  while (!in.eof()){
115  float temp;
116  in >> temp;
117  std::cout <<" Intersing "<<temp<< " in position "<<number<<std::endl;
118  number++;
119  pl.push_back(temp);
120  }
121 
122  //
123  // CHECKS
124  //
125  if (stride != nbin*2+nres){
126  std::cout <<" Table not well formed"<<std::endl;
127  }
128  if ((number % stride) != 0){
129  std::cout <<" Table not well formed"<<std::endl;
130  }
131 
132  in.close();
133 
134 
135  /* for (int k=0;k<(number/stride); k++){
136  for (int j=0; j<stride; j++){
137  std::cout << "Pos["<<k<<","<<j<<"] = "<<pl[k*stride+j]<<std::endl;
138  }
139  }
140  */
141 
142  //
143  // now create pl etc etc
144  //
145 
146  PerformanceWorkingPoint * wp = new PerformanceWorkingPoint(cut, tagger);
147 
148  PerformancePayloadFromTable * btagpl = 0;
149 
150  if (concreteType == "PerformancePayloadFromTable"){
151  btagpl = new PerformancePayloadFromTable(res, bin, stride, pl);
152  }else{
153  std::cout <<" Non existing request: " <<concreteType<<std::endl;
154  }
155 
156  std::cout <<" Created the "<<concreteType <<" object"<<std::endl;
157 
159  if (s.isAvailable())
160  {
161  if (s->isNewTagRequest(rec1))
162  {
163  s->createNewIOV<PerformancePayload>(btagpl,
164  // s->beginOfTime(),
165  // s->endOfTime(),
166  iovBegin,
167  iovEnd,
168  rec1);
169  }
170  else
171  {
172 
174  // JUST A STUPID PATCH
175  // 111,
176  iovBegin,
177  rec1);
178  }
179  }
180 
181  // write also the WP
182 
183  if (s.isAvailable())
184  {
185  if (s->isNewTagRequest(rec2))
186  {
188  // s->beginOfTime(),
189  // s->endOfTime(),
190  iovBegin,
191  iovEnd,
192  rec2);
193  }
194  else
195  {
196 
199  // 111,
200  iovBegin,
201  rec2);
202  }
203  }
204 
205 
206 
207 }
208 
T getParameter(std::string const &) const
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)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
tuple cout
Definition: gather_cfg.py:121
#define comment(par)
Definition: vmac.h:162