CMS 3D CMS Logo

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(edm::StreamID, const edm::Event&, const edm::EventSetup&) const 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  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << "Opening " << inputTxtFile;
53  in.open(inputTxtFile.c_str());
54  std::string tagger;
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  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << "WP Tagger is " << tagger;
64 
65  in >> cut;
66  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << "WP Cut is " << cut;
67 
68  in >> concreteType;
69  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << "concrete Type is " << concreteType;
70 
71  // return ;
72 
73  // read # of results
74 
75  int nres, nbin;
76  in >> nres;
77  in >> nbin;
78  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload")
79  << " Results: " << nres << " Binning variables: " << nbin;
80 
81  stride = nres + nbin * 2;
82  if (!stride) {
83  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << " Malformed input file";
84  exit(1);
85  }
86 
87  int number = 0;
88 
89  std::vector<PerformanceResult::ResultType> res;
90  std::vector<BinningVariables::BinningVariablesType> bin;
91 
92  while (number < nres && !in.eof()) {
93  int tmp;
94  in >> tmp;
96  number++;
97  }
98  if (number != nres) {
99  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << "Table not well formed";
100  }
101  number = 0;
102  while (number < nbin && !in.eof()) {
103  int tmp;
104  in >> tmp;
106  number++;
107  }
108  if (number != nbin) {
109  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << "Table not well formed";
110  }
111 
112  number = 0;
113  while (!in.eof()) {
114  float temp;
115  in >> temp;
116  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload")
117  << " Intersing " << temp << " in position " << number;
118  number++;
119  pl.push_back(temp);
120  }
121 
122  //
123  // CHECKS
124  //
125  if (stride != nbin * 2 + nres) {
126  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << "Table not well formed";
127  }
128  if ((number % stride) != 0) {
129  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << "Table not well formed";
130  }
131  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << " CLOSING ";
132  in.close();
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(cut, tagger);
146 
148 
149  if (concreteType == "PerformancePayloadFromTable") {
150  btagpl = PerformancePayloadFromTable(res, bin, stride, pl);
151  } else {
152  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << " Non existing request: " << concreteType;
153  }
154 
155  edm::LogInfo("PhysicsPerformanceDBWriterFromFile_WPandPayload") << " Created the " << concreteType << " object";
156 
158  if (s.isAvailable()) {
159  s->writeOneIOV(btagpl, s->beginOfTime(), rec1);
160  // write also the WP
161  s->writeOneIOV(wp, s->beginOfTime(), rec2);
162  }
163 }
164 
Definition: Electron.h:6
void analyze(edm::StreamID, const edm::Event &, const edm::EventSetup &) const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
tmp
align.sh
Definition: createJobs.py:716
def exit(msg="")