CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
17 public:
19  void beginJob() override;
20  void analyze(const edm::Event&, const edm::EventSetup&) override {}
21  void endJob() override {}
23 
24 private:
27 };
28 
30  const edm::ParameterSet& p) {
31  inputTxtFile = p.getUntrackedParameter<std::string>("inputTxtFile");
32  rec1 = p.getUntrackedParameter<std::string>("RecordPayload");
33  rec2 = p.getUntrackedParameter<std::string>("RecordWP");
34 }
35 
37  //
38  // read object from file
39  //
40 
41  //
42  // File Format is
43  // - tagger name
44  // - cut
45  // - concrete class name
46  // - how many results and how many binning
47  // - their values
48  // - vector<float>
49  //
50 
51  std::ifstream in;
52  std::cout << "Opening " << inputTxtFile << std::endl;
53  in.open(inputTxtFile.c_str());
55  float cut;
56 
57  std::string concreteType;
58  std::string comment;
59  std::vector<float> pl;
60  int stride;
61 
62  in >> tagger;
63  std::cout << "WP Tagger is " << tagger << std::endl;
64 
65  in >> cut;
66  std::cout << "WP Cut is " << cut << std::endl;
67 
68  in >> concreteType;
69  std::cout << "concrete Type is " << concreteType << std::endl;
70 
71  // return ;
72 
73  // read # of results
74 
75  int nres, nbin;
76  in >> nres;
77  in >> nbin;
78  std::cout << " Results: " << nres << " Binning variables: " << nbin << std::endl;
79 
80  stride = nres + nbin * 2;
81  if (!stride) {
82  std::cout << " Malformed input file" << std::endl;
83  exit(1);
84  }
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  /* for (int k=0;k<(number/stride); k++){
134  for (int j=0; j<stride; j++){
135  std::cout << "Pos["<<k<<","<<j<<"] = "<<pl[k*stride+j]<<std::endl;
136  }
137  }
138  */
139 
140  //
141  // now create pl etc etc
142  //
143 
144  PerformanceWorkingPoint* wp = new PerformanceWorkingPoint(cut, tagger);
145 
146  PerformancePayloadFromTable* btagpl = nullptr;
147 
148  if (concreteType == "PerformancePayloadFromTable") {
149  btagpl = new PerformancePayloadFromTable(res, bin, stride, pl);
150  } else {
151  std::cout << " Non existing request: " << concreteType << std::endl;
152  }
153 
154  std::cout << " Created the " << concreteType << " object" << std::endl;
155 
157  if (s.isAvailable()) {
158  if (s->isNewTagRequest(rec1)) {
159  s->createNewIOV<PerformancePayload>(btagpl, s->beginOfTime(), s->endOfTime(), rec1);
160  } else {
162  // JUST A STUPID PATCH
163  111,
164  rec1);
165  }
166  }
167 
168  // write also the WP
169 
170  if (s.isAvailable()) {
171  if (s->isNewTagRequest(rec2)) {
173  } else {
176  111,
177  rec2);
178  }
179  }
180 }
181 
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void appendSinceTime(const T *payloadPtr, cond::Time_t sinceTime, const std::string &recordName)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:40
void analyze(const edm::Event &, const edm::EventSetup &) override
tuple cout
Definition: gather_cfg.py:144
tmp
align.sh
Definition: createJobs.py:716
void createNewIOV(const T *payloadPtr, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)