CMS 3D CMS Logo

SiPixelGenErrorDBObjectReader.cc
Go to the documentation of this file.
1 // This reader still does not work so well.
2 // The formatting of readout is wrong.
3 // The comparison only works if the ascii files are available.
4 // I do not know how to access the internal numbers in a usefull way?
5 #include <iomanip>
6 #include <fstream>
7 #include <iostream>
8 #include <cmath>
9 #include <memory>
10 
14 
18 
21 
25 
30 
32 public:
35 
36 private:
37  void beginJob() override;
38  void analyze(const edm::Event&, const edm::EventSetup&) override;
39  void endJob() override;
40 
44 
46 };
47 
49  : theGenErrorCalibrationLocation(iConfig.getParameter<std::string>("siPixelGenErrorCalibrationLocation")),
50  theDetailedGenErrorDBErrorOutput(iConfig.getParameter<bool>("wantDetailedGenErrorDBErrorOutput")),
51  theFullGenErrorDBOutput(iConfig.getParameter<bool>("wantFullGenErrorDBOutput")),
52  genErrToken_(esConsumes()) {}
53 
55 
57 
59  edm::LogPrint("SiPixelGenErrorDBObjectReader") << "\nLoading ... " << std::endl;
60 
61  SiPixelGenErrorDBObject dbobject = *&iSetup.getData(genErrToken_);
63 
64  // these seem to be the only variables I can get directly from the object class
65  edm::LogPrint("SiPixelGenErrorDBObjectReader")
66  << " DBObject version " << dbobject.version() << " index " << dbobject.index() << " max " << dbobject.maxIndex()
67  << " fail " << dbobject.fail() << " numOfTeml " << dbobject.numOfTempl() << std::endl;
68 
70  edm::LogPrint("SiPixelGenErrorDBObjectReader") << "Map info" << std::endl;
71  std::vector<short> tempMapId;
72  std::map<unsigned int, short> templMap = dbobject.getGenErrorIDs();
73  for (std::map<unsigned int, short>::const_iterator it = templMap.begin(); it != templMap.end(); ++it) {
74  if (tempMapId.empty())
75  tempMapId.push_back(it->second);
76  for (unsigned int i = 0; i < tempMapId.size(); ++i) {
77  if (tempMapId[i] == it->second)
78  continue;
79  else if (i == tempMapId.size() - 1) {
80  tempMapId.push_back(it->second);
81  break;
82  }
83  }
84 
85  edm::LogPrint("SiPixelGenErrorDBObjectReader") << "DetId: " << it->first << " GenErrorID: " << it->second << "\n";
86  }
87 
88  edm::LogPrint("SiPixelGenErrorDBObjectReader") << "\nMap stores GenError Id(s): ";
89  for (unsigned int vindex = 0; vindex < tempMapId.size(); ++vindex)
90  edm::LogPrint("SiPixelGenErrorDBObjectReader") << tempMapId[vindex] << " ";
91  edm::LogPrint("SiPixelGenErrorDBObjectReader") << std::endl;
92  }
93 
94  // if the dircetory is an empty string ignore file comparison
95  if (theGenErrorCalibrationLocation.empty()) {
96  edm::LogPrint("SiPixelGenErrorDBObjectReader")
97  << " no file for camparison defined, comparison will be skipped " << std::endl;
98 
99  } else { // do the file comparision
100 
101  bool error = false;
102  int numOfTempl = dbobject.numOfTempl();
103  int index = 0;
104  float tempnum = 0, diff = 0;
105  float tol = 1.0E-23;
106  bool givenErrorMsg = false;
107 
108  edm::LogPrint("SiPixelGenErrorDBObjectReader")
109  << "\nChecking GenError DB object version " << dbobject.version() << " containing " << numOfTempl
110  << " calibration(s) at " << dbobject.sVector()[index + 22] << "T\n";
111 
112  for (int i = 0; i < numOfTempl; ++i) {
113  //Removes header in db object from diff
114  index += 20;
115 
116  //Tell the person viewing the output what the GenError ID and version are -- note that version is only valid for >=13
117  // Does not work correctly for data
118  edm::LogPrint("SiPixelGenErrorDBObjectReader")
119  << "Calibration " << i + 1 << " of " << numOfTempl << ", with GenError ID " << dbobject.sVector()[index]
120  << "\tand Version " << dbobject.sVector()[index + 1] << "\t-------- " << std::endl;
121 
122  //Opening the text-based GenError calibration
123  std::ostringstream tout;
124  tout << theGenErrorCalibrationLocation.c_str() << "generror_summary_zp" << std::setw(4) << std::setfill('0')
125  << std::right << dbobject.sVector()[index] << ".out" << std::ends;
126 
127  std::string temp = tout.str();
128  std::ifstream in_file(temp.c_str(), std::ios::in);
129 
130  edm::LogPrint("SiPixelGenErrorDBObjectReader")
131  << " open file " << tout.str() << " " << in_file.is_open() << std::endl;
132 
133  if (in_file.is_open()) {
134  //Removes header in textfile from diff
135  //First read in from the text file -- this will be compared with index = 20
136  in_file >> tempnum;
137 
138  //Read until the end of the current text file
139  while (!in_file.eof()) {
140  //Calculate the difference between the text file and the db object
141  diff = std::abs(tempnum - dbobject.sVector()[index]);
142 
143  //Is there a difference?
144  if (diff > tol) {
145  //We have the if statement to output the message only once
146  if (!givenErrorMsg)
147  edm::LogPrint("SiPixelGenErrorDBObjectReader") << "does NOT match\n";
148  //If there is an error we want to display a message upon completion
149  error = true;
150  givenErrorMsg = true;
151  //Do we want more detailed output?
153  edm::LogPrint("SiPixelGenErrorDBObjectReader")
154  << "from file = " << tempnum << "\t from dbobject = " << dbobject.sVector()[index]
155  << "\tdiff = " << diff << "\t db index = " << index << std::endl;
156  }
157  }
158  //Go to the next entries
159  in_file >> tempnum;
160  ++index;
161  }
162  //There were no errors, the two files match.
163  if (!givenErrorMsg)
164  edm::LogPrint("SiPixelGenErrorDBObjectReader") << "MATCHES\n";
165  } else { //end current file
166  edm::LogPrint("SiPixelGenErrorDBObjectReader")
167  << " ERROR: cannot open file, comparison will be stopped" << std::endl;
168  break;
169  }
170  in_file.close();
171  givenErrorMsg = false;
172 
173  } //end loop over all files
174 
176  edm::LogPrint("SiPixelGenErrorDBObjectReader")
177  << "\nThe were differences found between the files and the database.\n"
178  << "If you would like more detailed information please set\n"
179  << "wantDetailedOutput = True in the cfg file. If you would like a\n"
180  << "full output of the contents of the database file please set\n"
181  << "wantFullOutput = True. Make sure that you pipe the output to a\n"
182  << "log file. This could take a few minutes.\n\n";
183 
184  } // if compare
185 
186  // Try to interpret the object
187  std::vector<SiPixelGenErrorStore> thePixelGenError;
188  bool status = SiPixelGenError::pushfile(*db, thePixelGenError);
189  edm::LogPrint("SiPixelGenErrorDBObjectReader")
190  << " status = " << status << " size = " << thePixelGenError.size() << std::endl;
191 
192  SiPixelGenError genError(thePixelGenError);
193  // these are all 0 because qbin() was not run.
194  edm::LogPrint("SiPixelGenErrorDBObjectReader")
195  << " some values " << genError.lorxwidth() << " " << genError.lorywidth() << " " << std::endl;
196 
197  // Print the full object, I think it does not work, the print is for templates.
199  edm::LogPrint("SiPixelGenErrorDBObjectReader") << dbobject << std::endl;
200 }
201 
203 
204 // I think this was written for templates and not for genErrors
205 // so it does not work correctly.
206 std::ostream& operator<<(std::ostream& s, const SiPixelGenErrorDBObject& dbobject) {
208  int index = 0;
210  int txsize[4] = {7, 13, 0, 0};
211  int tysize[4] = {21, 21, 0, 0};
213  int entries[4] = {0};
215  int i, j, k, l, m, n, entry_it;
217  int sizeSetter = 1, generrorVersion = 0;
218 
219  edm::LogPrint("SiPixelGenErrorDBObjectReader") << "\n\nDBobject version: " << dbobject.version() << std::endl;
220 
221  for (m = 0; m < dbobject.numOfTempl(); ++m) {
222  //To change the size of the output based on which GenError version we are using"
223  generrorVersion = (int)dbobject.sVector_[index + 21];
224 
225  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " GenError version " << generrorVersion << " " << m << std::endl;
226 
227  if (generrorVersion <= 10) {
228  edm::LogPrint("SiPixelGenErrorDBObjectReader")
229  << "*****WARNING***** This code will not format this GenError version properly *****WARNING*****\n";
230  sizeSetter = 0;
231  } else if (generrorVersion <= 16)
232  sizeSetter = 1;
233  else
234  edm::LogPrint("SiPixelGenErrorDBObjectReader")
235  << "*****WARNING***** This code has not been tested at formatting this version *****WARNING*****\n";
236 
237  edm::LogPrint("SiPixelGenErrorDBObjectReader")
238  << "\n\n*********************************************************************************************"
239  << std::endl;
240  edm::LogPrint("SiPixelGenErrorDBObjectReader")
241  << "*************** Reading GenError ID " << dbobject.sVector_[index + 20] << "\t(" << m + 1
242  << "/" << dbobject.numOfTempl_ << ") ***************" << std::endl;
243  edm::LogPrint("SiPixelGenErrorDBObjectReader")
244  << "*********************************************************************************************\n\n"
245  << std::endl;
246 
247  //Header Title
248  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Header Title" << std::endl;
250  for (n = 0; n < 20; ++n) {
251  temp.f = dbobject.sVector_[index];
252  s << temp.c[0] << temp.c[1] << temp.c[2] << temp.c[3];
253  ++index;
254  }
255 
256  entries[0] = (int)dbobject.sVector_[index + 3]; // Y
257  entries[1] = (int)(dbobject.sVector_[index + 4] * dbobject.sVector_[index + 5]); // X
258 
259  //Header
260  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Header " << std::endl;
261  s << dbobject.sVector_[index] << "\t" << dbobject.sVector_[index + 1] << "\t" << dbobject.sVector_[index + 2]
262  << "\t" << dbobject.sVector_[index + 3] << "\t" << dbobject.sVector_[index + 4] << "\t"
263  << dbobject.sVector_[index + 5] << "\t" << dbobject.sVector_[index + 6] << "\t" << dbobject.sVector_[index + 7]
264  << "\t" << dbobject.sVector_[index + 8] << "\t" << dbobject.sVector_[index + 9] << "\t"
265  << dbobject.sVector_[index + 10] << "\t" << dbobject.sVector_[index + 11] << "\t" << dbobject.sVector_[index + 12]
266  << "\t" << dbobject.sVector_[index + 13] << "\t" << dbobject.sVector_[index + 14] << "\t"
267  << dbobject.sVector_[index + 15] << "\t" << dbobject.sVector_[index + 16] << std::endl;
268  index += 17;
269 
270  //Loop over By,Bx,Fy,Fx
271  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " ByBxFyFx" << std::endl;
272  for (entry_it = 0; entry_it < 4; ++entry_it) {
273  //Run,costrk,qavg,...,clslenx
274  for (i = 0; i < entries[entry_it]; ++i) {
275  s << dbobject.sVector_[index] << "\t" << dbobject.sVector_[index + 1] << "\t" << dbobject.sVector_[index + 2]
276  << "\t" << dbobject.sVector_[index + 3] << "\n"
277  << dbobject.sVector_[index + 4] << "\t" << dbobject.sVector_[index + 5] << "\t"
278  << dbobject.sVector_[index + 6] << "\t" << dbobject.sVector_[index + 7] << "\t"
279  << dbobject.sVector_[index + 8] << "\t" << dbobject.sVector_[index + 9] << "\t"
280  << dbobject.sVector_[index + 10] << "\t" << dbobject.sVector_[index + 11] << "\n"
281  << dbobject.sVector_[index + 12] << "\t" << dbobject.sVector_[index + 13] << "\t"
282  << dbobject.sVector_[index + 14] << "\t" << dbobject.sVector_[index + 15] << "\t"
283  << dbobject.sVector_[index + 16] << "\t" << dbobject.sVector_[index + 17] << "\t"
284  << dbobject.sVector_[index + 18] << std::endl;
285  index += 19;
286  //YPar
287  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " YPar" << std::endl;
288  for (j = 0; j < 2; ++j) {
289  for (k = 0; k < 5; ++k) {
290  s << dbobject.sVector_[index] << "\t";
291  ++index;
292  }
293  s << std::endl;
294  }
295  //YTemp
296  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " YTemp" << std::endl;
297  for (j = 0; j < 9; ++j) {
298  for (k = 0; k < tysize[sizeSetter]; ++k) {
299  s << dbobject.sVector_[index] << "\t";
300  ++index;
301  }
302  s << std::endl;
303  }
304  //XPar
305  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " XPar" << std::endl;
306  for (j = 0; j < 2; ++j) {
307  for (k = 0; k < 5; ++k) {
308  s << dbobject.sVector_[index] << "\t";
309  ++index;
310  }
311  s << std::endl;
312  }
313  //XTemp
314  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Xtemp" << std::endl;
315  for (j = 0; j < 9; ++j) {
316  for (k = 0; k < txsize[sizeSetter]; ++k) {
317  s << dbobject.sVector_[index] << "\t";
318  ++index;
319  }
320  s << std::endl;
321  }
322  //Y average reco params
323  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Y average reco params " << std::endl;
324  for (j = 0; j < 4; ++j) {
325  for (k = 0; k < 4; ++k) {
326  s << dbobject.sVector_[index] << "\t";
327  ++index;
328  }
329  s << std::endl;
330  }
331  //Yflpar
332  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Yflar " << std::endl;
333  for (j = 0; j < 4; ++j) {
334  for (k = 0; k < 6; ++k) {
335  s << dbobject.sVector_[index] << "\t";
336  ++index;
337  }
338  s << std::endl;
339  }
340  //X average reco params
341  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " X average reco params" << std::endl;
342  for (j = 0; j < 4; ++j) {
343  for (k = 0; k < 4; ++k) {
344  s << dbobject.sVector_[index] << "\t";
345  ++index;
346  }
347  s << std::endl;
348  }
349  //Xflpar
350  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Xflar" << std::endl;
351  for (j = 0; j < 4; ++j) {
352  for (k = 0; k < 6; ++k) {
353  s << dbobject.sVector_[index] << "\t";
354  ++index;
355  }
356  s << std::endl;
357  }
358  //Chi2X,Y
359  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " XY chi2" << std::endl;
360  for (j = 0; j < 4; ++j) {
361  for (k = 0; k < 2; ++k) {
362  for (l = 0; l < 2; ++l) {
363  s << dbobject.sVector_[index] << "\t";
364  ++index;
365  }
366  }
367  s << std::endl;
368  }
369  //Y average Chi2 params
370  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Y chi2" << std::endl;
371  for (j = 0; j < 4; ++j) {
372  for (k = 0; k < 4; ++k) {
373  s << dbobject.sVector_[index] << "\t";
374  ++index;
375  }
376  s << std::endl;
377  }
378  //X average Chi2 params
379  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " X chi2" << std::endl;
380  for (j = 0; j < 4; ++j) {
381  for (k = 0; k < 4; ++k) {
382  s << dbobject.sVector_[index] << "\t";
383  ++index;
384  }
385  s << std::endl;
386  }
387  //Y average reco params for CPE Generic
388  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Y reco params for generic" << std::endl;
389  for (j = 0; j < 4; ++j) {
390  for (k = 0; k < 4; ++k) {
391  s << dbobject.sVector_[index] << "\t";
392  ++index;
393  }
394  s << std::endl;
395  }
396  //X average reco params for CPE Generic
397  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " X reco params for generic" << std::endl;
398  for (j = 0; j < 4; ++j) {
399  for (k = 0; k < 4; ++k) {
400  s << dbobject.sVector_[index] << "\t";
401  ++index;
402  }
403  s << std::endl;
404  }
405  //SpareX,Y
406  edm::LogPrint("SiPixelGenErrorDBObjectReader") << " Spare " << std::endl;
407  for (j = 0; j < 20; ++j) {
408  s << dbobject.sVector_[index] << "\t";
409  ++index;
410  if (j == 9 || j == 19)
411  s << std::endl;
412  }
413  }
414  }
415  }
416  return s;
417 }
418 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::ostream & operator<<(std::ostream &s, const SiPixelGenErrorDBObject &dbobject)
static bool pushfile(int filenum, std::vector< SiPixelGenErrorStore > &pixelTemp, std::string dir="")
void analyze(const edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< SiPixelGenErrorDBObject, SiPixelGenErrorDBObjectRcd > genErrToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
float lorxwidth()
signed lorentz x-width (microns)
Log< level::Warning, true > LogPrint
SiPixelGenErrorDBObjectReader(const edm::ParameterSet &)
std::vector< float > sVector() const
~SiPixelGenErrorDBObjectReader() override
float lorywidth()
signed lorentz y-width (microns)
const std::map< unsigned int, short > & getGenErrorIDs() const