CMS 3D CMS Logo

EcalLaserCondTools.cc
Go to the documentation of this file.
1 //emacs settings:-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  * $Id: EcalLaserCondTools.cc,v 1.2 2010/06/14 10:45:17 pgras Exp $
4  *
5  * author: Ph Gras. June, 2010
6  */
7 
9 
14 
18 
19 #include "hdf5.h"
20 
21 #include <string>
22 #include <fstream>
23 #include <algorithm>
24 #include <memory>
25 
27  : fout_(nullptr),
28  eventList_(nullptr),
29  eventListFileName_(ps.getParameter<std::string>("eventListFile")),
30  verb_(ps.getParameter<int>("verbosity")),
31  mode_(ps.getParameter<std::string>("mode")),
32  fnames_(ps.getParameter<std::vector<std::string> >("inputFiles")),
33  skipIov_(ps.getParameter<int>("skipIov")),
34  nIovs_(ps.getParameter<int>("nIovs")),
35  fromTime_(ps.getParameter<int>("fromTime")),
36  toTime_(ps.getParameter<int>("toTime")),
37  minP_(ps.getParameter<double>("transparencyMin")),
38  maxP_(ps.getParameter<double>("transparencyMax")) {
39  ferr_ = fopen("corr_errors.txt", "w");
40  fprintf(ferr_, "#t1\tdetid\tp1\tp2\tp3");
41 
42  if (!eventListFileName_.empty()) {
43  eventList_ = fopen(eventListFileName_.c_str(), "r");
44  if (eventList_ == nullptr)
45  throw cms::Exception("User") << "Failed to open file " << eventListFileName_ << "\n";
46  }
47 }
48 
50  if (ferr_)
51  fclose(ferr_);
52  if (fout_)
53  fclose(fout_);
54 }
55 
57  static bool done = false;
58 
59  if (done && (mode_ == "ascii_file_to_db" || mode_ == "hdf_file_to_db")) {
60  return;
61  }
62 
63  if (mode_ == "ascii_file_to_db") {
64  if (verb_ > 2)
65  std::cout << "ascii_file_to_db mode\n";
66 
67  if (!db_.isAvailable()) {
68  throw cms::Exception("CondDBAccess") << "Failed to connect to PoolDBOutputService\n";
69  }
70  FileReader corrReader(fnames_);
71  corrReader.setVerbosity(verb_);
72  fillDb(corrReader);
73  } else if (mode_ == "hdf_file_to_db") {
75  } else if (mode_ == "db_to_ascii_file") {
76  dbToAscii(es);
77  } else {
78  cms::Exception("InvalidParam") << "Value of parameter mode is not valid. Expecting ascii_file_to_db or read";
79  }
80 }
81 
83  cond::Time_t iovStart = 0;
84 
85  hid_t file, space, memspace;
86  hid_t dset_rawid, dset_t2, dset;
87 
88  hsize_t dims[2] = {};
89 
90  for (unsigned int ifile = 0; ifile < fnames_.size(); ++ifile) {
91  if (verb_) {
92  std::cout << " - converting file: " << fnames_[ifile] << "\n";
93  }
94 
95  file = H5Fopen(fnames_[ifile].c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
96 
97  dset_rawid = H5Dopen(file, "cmssw_id", H5P_DEFAULT);
98  space = H5Dget_space(dset_rawid);
99  H5Sget_simple_extent_dims(space, dims, nullptr);
100 
101  unsigned int nCrystals = dims[0];
102  int rawid[nCrystals];
103  herr_t status;
104 
105  status = H5Dread(dset_rawid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rawid);
106  if (status < 0)
107  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
108 
109  H5Dclose(dset_rawid);
110  H5Sclose(space);
111 
112  dset_t2 = H5Dopen(file, "t2", H5P_DEFAULT);
113  space = H5Dget_space(dset_t2);
114  H5Sget_simple_extent_dims(space, dims, nullptr);
115 
116  unsigned int nIovs = dims[0];
117  unsigned int nLME = dims[1];
118 
119  if (verb_) {
120  std::cout << "Number of crystals: " << nCrystals << "\n";
121  std::cout << "Number of IOVs: " << nIovs << "\n";
122  std::cout << "Number of Monitoring regions: " << nLME << "\n";
123  }
124 
125  int t1[nIovs], t3[nIovs], t2[nIovs][nLME];
126 
127  // -- reading data (cmsswid, t2, t1, t3, p2, p1, p3
128  if (verb_ > 1)
129  std::cout << " * reading t2 table "
130  << "\n";
131  status = H5Dread(dset_t2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t2[0]);
132  if (status < 0)
133  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
134 
135  H5Dclose(dset_t2);
136  //H5Sclose(space);
137 
138  if (verb_ > 1)
139  std::cout << " * reading t1 table "
140  << "\n";
141  dset = H5Dopen(file, "t1", H5P_DEFAULT);
142  status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t1);
143  if (status < 0)
144  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
145 
146  H5Dclose(dset);
147 
148  if (verb_ > 1)
149  std::cout << " * reading t3 table "
150  << "\n";
151  dset = H5Dopen(file, "t3", H5P_DEFAULT);
152  status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, t3);
153  if (status < 0)
154  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
155 
156  H5Dclose(dset);
157 
159 
160  // read crystal info IOV by IOV (otherwise too large)
161  float p1[nCrystals], p2[nCrystals], p3[nCrystals];
162  hsize_t iov_dim[1] = {nCrystals};
163  memspace = H5Screate_simple(1, iov_dim, nullptr);
164 
165  auto corrSet = std::make_unique<EcalLaserAPDPNRatios>();
166  for (unsigned int iIov = skipIov_; iIov < nIovs && iIov < unsigned(nIovs_); ++iIov) {
168  iovStart = uint64_t(t1[iIov]) << 32;
169  for (size_t iLme = 0; iLme < EcalLaserCondTools::nLmes; ++iLme) {
170  t.t1 = edm::Timestamp(uint64_t(t1[iIov]) << 32);
171  t.t2 = edm::Timestamp(uint64_t(t2[iIov][iLme]) << 32);
172  t.t3 = edm::Timestamp(uint64_t(t3[iIov]) << 32);
173  corrSet->setTime(iLme, t);
174  }
175 
176  hsize_t offset[2] = {iIov, 0}; // shift rows: iIov, columns: 0
177  hsize_t count[2] = {1, nCrystals}; // 1 row, nXtal columns
178 
179  dset = H5Dopen(file, "p1", H5P_DEFAULT);
180  space = H5Dget_space(dset);
181  status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset, nullptr, count, nullptr);
182  if (status < 0)
183  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
184 
185  status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p1);
186  if (status < 0)
187  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
188 
189  H5Dclose(dset);
190  //H5Sclose(space);
191 
192  dset = H5Dopen(file, "p2", H5P_DEFAULT);
193  space = H5Dget_space(dset);
194  status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset, nullptr, count, nullptr);
195  if (status < 0)
196  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
197 
198  status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p2);
199  if (status < 0)
200  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
201 
202  H5Dclose(dset);
203  // H5Sclose(space);
204 
205  dset = H5Dopen(file, "p3", H5P_DEFAULT);
206  space = H5Dget_space(dset);
207  status = H5Sselect_hyperslab(space, H5S_SELECT_SET, offset, nullptr, count, nullptr);
208  if (status < 0)
209  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
210 
211  status = H5Dread(dset, H5T_NATIVE_FLOAT, memspace, space, H5P_DEFAULT, p3);
212  if (status < 0)
213  throw cms::Exception("EcalLaserCondTool:HDF") << "Error while reading HD file.";
214  H5Dclose(dset);
215  H5Sclose(space);
216 
217  for (size_t iXtal = 0; iXtal < nCrystals; ++iXtal) {
218  DetId detid = rawid[iXtal];
219 
221  corr.p1 = p1[iXtal];
222  corr.p2 = p2[iXtal];
223  corr.p3 = p3[iXtal];
224 
225  if (!isfinite(corr.p1) || !isfinite(corr.p2) || !isfinite(corr.p3) || corr.p1 < minP_ || corr.p1 > maxP_ ||
226  corr.p2 < minP_ || corr.p2 > maxP_ || corr.p3 < minP_ || corr.p3 > maxP_) {
227  fprintf(ferr_, "%d %d %f %f %f\n", t1[iIov], (int)detid, corr.p1, corr.p2, corr.p3);
228  corr.p1 = corr.p2 = corr.p3 = 1;
229  }
230  corrSet->setValue((int)detid, corr);
231  }
232 
233  try {
234  //Write correction set in DB (one IOV):
235  //if (db_->isNewTagRequest("EcalLaserAPDPNRatiosRcd")) {
236  // if (verb_)
237  // std::cout << "First IOV, extending starting time.\n";
238  // iovStart = db_->beginOfTime();
239  //}
240  timeval t;
241  gettimeofday(&t, nullptr);
242  if (verb_ > 1)
243  std::cout << "[" << timeToString(t.tv_sec) << "] "
244  << "Write IOV " << iIov << " starting from " << timeToString(iovStart >> 32) << "... ";
245  db_->writeOne(corrSet.get(), iovStart, "EcalLaserAPDPNRatiosRcd");
246  } catch (const cms::Exception& e) {
247  if (verb_ > 1)
248  std::cout << "Failed. ";
249  std::cout << "Exception catched while writting to cond DB" << e.what() << "\n";
250  }
251  if (verb_ > 1)
252  std::cout << "Suceeded.\n";
253 
254  } // loop over IOVs
255 
256  H5Sclose(memspace);
257  H5Fclose(file);
258  } // loop over input files
259 }
260 
262  int iIov = 0;
263  int processedIovs = 0;
264  if (verb_ > 2)
265  std::cout << "Starting filling DB...\n";
266  int t1 = 0;
267  int t3 = 0;
268  int t2[nLmes];
269 
270  int prevT1 = 0;
271  int prevT3 = 0;
272  int prevT = 0;
273  int t = 0;
274  if (eventList_) {
275  int iline = 0;
276  while (!feof(eventList_)) {
277  //skips comment lines:
278  char c;
279  while (fscanf(eventList_, " %1[#]%*[^\n]\n", &c) == 1)
280  ++iline;
281 
282  int n = fscanf(eventList_, "%*d %*d %*d %d%*[^\n]\n", &t);
283  if (verb_ > 1)
284  std::cout << "Event time: t = " << t << ", " << timeToString(t) << "\n";
285  ++iline;
286  if (n != 1)
287  throw cms::Exception("User") << "Syntax error in event list file " << eventListFileName_ << " at line " << iline
288  << " " << n << " "
289  << ".\n";
290  if (t < prevT)
291  throw cms::Exception("User") << "Events in the event list file " << eventListFileName_
292  << " are not ordered in increased time as required! See line " << iline << "\n";
293  if (t == 0)
294  throw cms::Exception("User") << "Found an unexpected t = 0 time value "
295  "in the event list file"
296  << eventListFileName_ << " at line " << iline << "!\n";
297  //Look for IOV:
298  bool iovFound = true;
299  if (t <= t3) { //IOV already inserted for previous event.
300  if (verb_ > 1)
301  std::cout << "Event in same IOV than previous one.\n";
302  continue;
303  }
304 
305  while ((iovFound = r.readTime(t1, t2, t3)) && t3 < t) /*NOP*/
306  ;
307 
308  if (iovFound) {
309  if (t1 < prevT1 && t3 < prevT3)
310  throw cms::Exception("User")
311  << "IOVs in the correction ascii file are not ordered in increased time as required!\n";
312  else if (t1 < prevT1 || t3 < prevT3)
313  throw cms::Exception("User") << "Found interleaved IOVs in the correction ascii file!\n";
314  processIov(r, t1, t2, t3);
315  } else {
316  std::cout << "Warning: event beyond last IOV t3. Event time: " << timeToString(t)
317  << ". Last IOV t3: " << timeToString(t3) << "\n";
318  }
319  }
320  } else
321  while (r.readTime(t1, t2, t3)) {
322  ++iIov;
323  if (iIov <= skipIov_) {
324  std::cout << "Skipping IOV " << iIov << "\n";
325  continue;
326  } else if (processedIovs >= nIovs_) {
327  std::cout << "Requested number of IOVs, " << nIovs_ << ", processed.\n";
328  return;
329  } else {
330  processIov(r, t1, t2, t3);
331  ++processedIovs;
332  }
333  }
334 }
335 
337  static int iIov = 0;
338  ++iIov;
339 
340  // FILE* fdebug = 0;
341  // if(i==) fdebug = fopen("debug.txt", "w");
342 
343  // if(iIov <= skipIov_) { std::cout << "Skipping IOV " << iIov << "\n"; return; }
344 
345  cond::Time_t iovStart = 0;
346 
347  if (verb_ > 1) {
348  std::cout << "t1:" << t1 << "(" << timeToString(t1) << ") \n"
349  << "t3: " << t3 << "(" << timeToString(t3) << ")\nt2-t1: ";
350  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i)
351  std::cout << t2[i] - t1 << "\t";
352 
353  std::cout << "\n";
354  }
355  if (t1 < fromTime_) {
356  std::cout << "Skipping IOV " << iIov << ", "
357  << ", which is before 'fromTime'," << timeToString(fromTime_) << "(" << fromTime_ << ").\n";
358  return;
359  }
360 
361  if (toTime_ != -1 && t3 < toTime_) {
362  std::cout << "Skipping IOV " << iIov << ", "
363  << ", which is beyond 'toTime'," << timeToString(toTime_) << "(" << toTime_ << ").\n";
364  return;
365  }
366 
367  if (t1 == 0) {
368  std::cout << "Skipping IOV with t1 = 0"
369  << "\n";
370  return;
371  }
372 
373  auto corrSet = std::make_unique<EcalLaserAPDPNRatios>();
374 
376  iovStart = uint64_t(t1) << 32;
377  for (size_t i = 0; i < EcalLaserCondTools::nLmes; ++i) {
378  t.t1 = edm::Timestamp(uint64_t(t1) << 32);
379  t.t2 = edm::Timestamp(uint64_t(t2[i]) << 32);
380  t.t3 = edm::Timestamp(uint64_t(t3) << 32);
381  corrSet->setTime(i, t);
382  }
383 
384  constexpr int ncrystals = 75848;
385  std::set<int> detidList;
386  for (int i = 0; i < ncrystals; ++i) {
387  DetId detid;
388  //EcalLaserAPDPNRatios::EcalLaserAPDPNpair corr = {0, 0, 0};
390  if (verb_ > 2)
391  std::cout << "Reading " << toNth(i + 1) << " crystal\n";
392  if (!r.readPs(detid, corr)) {
393  throw cms::Exception("LasCor") << "Failed to read " << toNth(i + 1) << " crystal correction.\n";
394  }
395 
396  std::pair<std::set<int>::iterator, bool> res = detidList.insert(int(detid));
397 
398  if (!res.second) { //detid already processed
399  std::cout << "Duplicate det id, for IOV " << iIov << " t1 = " << t1 << " detid = " << int(detid) << "\n";
400  }
401 
402  if (!isfinite(corr.p1) || !isfinite(corr.p2) || !isfinite(corr.p3) || corr.p1 < minP_ || corr.p1 > maxP_ ||
403  corr.p2 < minP_ || corr.p2 > maxP_ || corr.p3 < minP_ || corr.p3 > maxP_) {
404  fprintf(ferr_, "%d %d %f %f %f\n", t1, (int)detid, corr.p1, corr.p2, corr.p3);
405  corr.p1 = corr.p2 = corr.p3 = 1;
406  }
407 
408  if (verb_ > 2) {
409  if (detid.subdetId() == EcalBarrel) {
410  std::cout << EBDetId(detid);
411  } else if (detid.subdetId() == EcalEndcap) {
412  std::cout << EEDetId(detid);
413  } else {
414  std::cout << (int)detid;
415  }
416  std::cout << ": "
417  << "p1 = " << corr.p1 << "\t"
418  << "p2 = " << corr.p2 << "\t"
419  << "p3 = " << corr.p3 << "\n";
420  }
421 
422  corrSet->setValue((int)detid, corr);
423  }
424 
425  try {
426  //Write correction set in DB (one IOV):
427  if (db_->isNewTagRequest("EcalLaserAPDPNRatiosRcd")) {
428  if (verb_)
429  std::cout << "First IOV, extending starting time.\n";
430 
431  iovStart = db_->beginOfTime();
432  }
433  timeval t;
434  gettimeofday(&t, nullptr);
435  if (verb_ > 1)
436  std::cout << "[" << timeToString(t.tv_sec) << "] "
437  << "Write IOV " << iIov << " starting from " << timeToString(iovStart >> 32) << "... ";
438  db_->writeOne(corrSet.get(), iovStart, "EcalLaserAPDPNRatiosRcd");
439  } catch (const cms::Exception& e) {
440  std::cout << "Failed.\nException cathed while writting to cond DB" << e.what() << "\n";
441  }
442  std::cout << "Suceeded.\n";
443 }
444 
446  for (;;) {
447  ++ifile_;
448  if (ifile_ >= fnames_.size()) {
449  if (verb_ > 1)
450  std::cout << "No more correction files.\n";
451 
452  return false;
453  }
454  if (verb_ > 1)
455  std::cout << "Opening file " << fnames_[ifile_] << "\n";
456 
457  f_ = fopen(fnames_[ifile_].c_str(), "r");
458  iline_ = 0;
459  if (f_ == nullptr) {
460  std::cerr << "Failed to open file " << fnames_[ifile_] << ". File skipped!\n";
461  } else {
462  return true;
463  }
464  }
465 }
466 
468  trim();
469  if ((f_ == nullptr || feof(f_)) && !nextFile()) {
470  if (verb_ > 1)
471  std::cout << "No more record\n";
472 
473  return false;
474  }
475  int i;
476  char* buf = nullptr;
477  size_t s = 0;
478  while ((i = fgetc(f_)) != 'T' && i != 'L' && i >= 0)
479  getline(&buf, &s, f_);
480  if (buf)
481  free(buf);
482  buf = nullptr;
483 
484  if (i == 'L') { //last record put 3 consecutive times starting from end of prev. IOV
485  t1 = t3;
486  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i)
487  t2[i] = t1 + 1;
488  t3 = t1 + 2;
489  return true;
490  }
491 
492  if (i != 'T') {
493  if (verb_ > 1)
494  std::cout << "No more record or bad line type/marker (getc returned " << i << ")\n";
495 
496  return false;
497  }
498 
500  int n = fscanf(f_, "%d %d", &t1, &t3);
501  for (int i = 0; i < EcalLaserCondTools::nLmes; ++i) {
502  int nn = fscanf(f_, "%d", &t2[i]);
503  if (nn != 1)
504  break;
505  n += nn;
506  }
507 
508  int nnn = fscanf(f_, " ");
509 
510  if (n != (2 + EcalLaserCondTools::nLmes) || nnn != 0)
511  throw cms::Exception("LasCorFile") << "File " << fnames_[ifile_] << " line " << iline_
512  << ": syntax error. Expecting 'T' marker followed by 94 values: "
513  << "t1 t2 t3(lme 1) t3(lme 2) ... t3(lme " << EcalLaserCondTools::nLmes << ")\n";
514 
515  return true;
516 }
517 
519  if (f_ == nullptr) {
520  if (verb_)
521  std::cout << "Requested to read p1..p3 parameter line while no file is closed.\n";
522 
523  return false;
524  }
525 
526  trim();
527  int i = fgetc(f_);
528 
529  if (i != 'P') {
530  if (verb_ && i >= 0)
531  std::cout << "File " << fnames_[ifile_] << " line " << iline_ << ": unexpected line type, '" << (char)i
532  << "' while expecting 'P'\n";
533 
534  if (verb_ && i < 0)
535  std::cout << "Failed to read p1..p3 parameter line\n";
536 
537  return false;
538  }
539 
540  int rawdetid;
541  int n = fscanf(f_, "%d %f %f %f\n", &rawdetid, &corr.p1, &corr.p2, &corr.p3);
542  ++iline_;
543 
544  if (n != 4) {
545  // corr.p2=corr.p1;
546  // corr.p3=corr.p1;
547  throw cms::Exception("I/O") << "Syntax error at line " << iline_ << "of file " << fnames_[ifile_] << " read " << n
548  << " values,"
549  << " raw id" << rawdetid << ": " << corr.p1 << ", " << corr.p2;
550  }
551  detid = rawdetid;
552  constexpr int ECALID = 3;
553  if (detid.det() != ECALID)
554  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
555  << " contains an invalid det ID (detector code is not ECAL!)\n";
556  if (detid.subdetId() == EcalBarrel) {
557  EBDetId ebDetId(detid);
558  if (!EBDetId::validDetId(ebDetId.ietaAbs(), ebDetId.iphi()))
559  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
560  << " contains an invalid det ID (detector code is not ECAL!)\n";
561  }
562  if (detid.subdetId() == EcalEndcap) {
563  EEDetId eeDetId(detid);
564  if (!EEDetId::validDetId(eeDetId.ix(), eeDetId.iy(), eeDetId.zside()))
565  throw cms::Exception("InvalidValue") << "Line " << iline_ << "of file " << fnames_[ifile_]
566  << " contains an invalid det ID (detector code is not ECAL!)\n";
567  }
568  ++iline_;
569  return true;
570 }
571 
573  if (f_ == nullptr)
574  return;
575  bool skipLine = false;
576  int c;
577  while ((c = fgetc(f_)) >= 0 && (c == ' ' || c == '\t' || c == '\n' || c == '#' || skipLine)) {
578  if (c == '#')
579  skipLine = true;
580  if (c == '\n') {
581  ++iline_;
582  skipLine = false;
583  }
584  }
585  ungetc(c, f_);
586 }
587 
589  std::stringstream s;
590  s << n;
591  if (n % 100 < 10 || n % 100 > 20) {
592  switch (n % 10) {
593  case 1:
594  s << "st";
595  break;
596  case 2:
597  s << "nd";
598  break;
599  case 3:
600  s << "rd";
601  break;
602  default:
603  s << "th";
604  }
605  } else {
606  s << "th";
607  }
608  return s.str();
609 }
610 
612  char buf[256];
613  struct tm lt;
614  localtime_r(&t, &lt);
615  strftime(buf, sizeof(buf), "%F %R:%S", &lt);
616  buf[sizeof(buf) - 1] = 0;
617  return std::string(buf);
618 }
619 
622  es.get<EcalLaserAPDPNRatiosRcd>().get(hCorr);
623 
624  const EcalLaserAPDPNRatios* corr = hCorr.product();
625 
626  const EcalLaserAPDPNRatios::EcalLaserAPDPNRatiosMap& p = corr->getLaserMap();
627  const EcalLaserAPDPNRatios::EcalLaserTimeStampMap& t = corr->getTimeMap();
628 
629  if (t.size() != EcalLaserCondTools::nLmes)
630  throw cms::Exception("LasCor") << "Unexpected number time parameter triplets\n";
631 
632  if (fout_ == nullptr) {
633  fout_ = fopen("corr_dump.txt", "w");
634  if (fout_ == nullptr)
635  throw cms::Exception("LasCor") << "Failed to create file corr_dump.txt\n";
636  }
637 
638  unsigned t1 = t[0].t1.unixTime();
639  unsigned t3 = t[0].t3.unixTime();
640  fprintf(fout_, "T %d\t%d", t1, t3);
641 
642  if (verb_)
643  std::cout << "Processing IOV " << t1 << " - " << t3 << "(" << timeToString(t1) << " - " << timeToString(t3) << "\n";
644 
645  for (unsigned i = 0; i < t.size(); ++i) {
646  if (t[i].t1.unixTime() != t1 || t[i].t3.unixTime() != t3) {
647  throw cms::Exception("LasCor") << "Inconsitency in t1, t3: "
648  << "t1(lme 1) =" << t1 << ", t1(lme " << (i + 1) << ") = " << t[i].t1.unixTime()
649  << ", t3(lme 1) =" << t3 << ", t3(lme " << (i + 1) << ") = " << t[i].t3.unixTime()
650  << "\n";
651  }
652  fprintf(fout_, "\t%d", t[i].t2.unixTime());
653  }
654  fputc('\n', fout_);
655  fflush(fout_);
656 
657  for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
658  if (ieta == 0)
659  continue;
660  for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
661  if (EBDetId::validDetId(ieta, iphi)) {
662  EBDetId detId(ieta, iphi);
664  fprintf(fout_, "P %d\t%f\t%f\t%f\n", (int)detId, corr.p1, corr.p2, corr.p3);
665  }
666  }
667  }
668 
669  for (int iZ = 1; iZ >= -1; --iZ) {
670  for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
671  for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
672  if (EEDetId::validDetId(iX, iY, iZ)) {
673  EEDetId detId(iX, iY, iZ);
675  fprintf(fout_, "P %d\t%f\t%f\t%f\n", (int)detId, corr.p1, corr.p2, corr.p3);
676  }
677  }
678  }
679  }
680 }
681 //DEFINE_FWK_MODULE(EcalLaserCondTools);
EBDetId::hashedIndex
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:82
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
EcalLaserAPDPNRatiosRcd
Definition: EcalLaserAPDPNRatiosRcd.h:24
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:215
ESHandle.h
EcalLaserCondTools::from_hdf_to_db
void from_hdf_to_db()
Definition: EcalLaserCondTools.cc:82
EcalLaserCondTools::FileReader
Definition: EcalLaserCondTools.h:63
EcalLaserCondTools::verb_
int verb_
Definition: EcalLaserCondTools.h:89
mps_update.status
status
Definition: mps_update.py:69
EBDetId
Definition: EBDetId.h:17
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalLaserCondTools::FileReader::nextFile
bool nextFile()
Definition: EcalLaserCondTools.cc:445
EBDetId.h
EEDetId.h
EcalLaserCondTools::dbToAscii
void dbToAscii(const edm::EventSetup &es)
Definition: EcalLaserCondTools.cc:620
cms::cuda::assert
assert(be >=bs)
EEDetId::IX_MIN
static const int IX_MIN
Definition: EEDetId.h:290
EEDetId::IY_MIN
static const int IY_MIN
Definition: EEDetId.h:294
EcalLaserCondTools::CorrReader::setVerbosity
void setVerbosity(int verb)
Definition: EcalLaserCondTools.h:57
EcalCondObjectContainer< EcalLaserAPDPNpair >
EEDetId::ix
int ix() const
Definition: EEDetId.h:77
EcalLaserCondTools::EcalLaserCondTools
EcalLaserCondTools(const edm::ParameterSet &)
Definition: EcalLaserCondTools.cc:26
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
EcalLaserCondTools::FileReader::ifile_
unsigned ifile_
Definition: EcalLaserCondTools.h:75
EcalBarrel
Definition: EcalSubdetector.h:10
EcalLaserCondTools::~EcalLaserCondTools
~EcalLaserCondTools() override
Definition: EcalLaserCondTools.cc:49
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
EcalLaserCondTools::timeToString
static std::string timeToString(time_t t)
Definition: EcalLaserCondTools.cc:611
EcalLaserCondTools::analyze
void analyze(const edm::Event &evt, const edm::EventSetup &es) override
Definition: EcalLaserCondTools.cc:56
EcalLaserCondTools::db_
edm::Service< cond::service::PoolDBOutputService > db_
Definition: EcalLaserCondTools.h:92
DetId
Definition: DetId.h:17
EcalLaserCondTools::eventListFileName_
std::string eventListFileName_
Definition: EcalLaserCondTools.h:88
alignCSCRings.s
s
Definition: alignCSCRings.py:92
EcalLaserCondTools::mode_
std::string mode_
Definition: EcalLaserCondTools.h:90
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
EcalLaserCondTools::toTime_
int toTime_
Definition: EcalLaserCondTools.h:96
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
EcalLaserCondTools::FileReader::f_
FILE * f_
Definition: EcalLaserCondTools.h:73
EcalLaserCondTools::processIov
void processIov(CorrReader &r, int t1, int t2[nLmes], int t3)
Definition: EcalLaserCondTools.cc:336
fileCollector.done
done
Definition: fileCollector.py:123
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
compare_using_db.ifile
ifile
Definition: compare_using_db.py:251
EcalLaserCondTools::CorrReader
Definition: EcalLaserCondTools.h:51
edm::ESHandle
Definition: DTSurvey.h:22
p2
double p2[4]
Definition: TauolaWrapper.h:90
EcalLaserCondTools::FileReader::readPs
bool readPs(DetId &rawdetid, EcalLaserAPDPNRatios::EcalLaserAPDPNpair &corr) override
Definition: EcalLaserCondTools.cc:518
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
EBDetId::MAX_IPHI
static const int MAX_IPHI
Definition: EBDetId.h:137
EEDetId::IY_MAX
static const int IY_MAX
Definition: EEDetId.h:302
EcalLaserCondTools::CorrReader::verb_
int verb_
Definition: EcalLaserCondTools.h:60
EEDetId::zside
int zside() const
Definition: EEDetId.h:71
EcalLaserCondTools::FileReader::readTime
bool readTime(int &t1, int t2[EcalLaserCondTools::nLmes], int &t3) override
Definition: EcalLaserCondTools.cc:467
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
EcalLaserAPDPNRatiosRcd.h
EcalLaserCondTools::maxP_
double maxP_
Definition: EcalLaserCondTools.h:97
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EEDetId
Definition: EEDetId.h:14
EcalLaserCondTools::fromTime_
int fromTime_
Definition: EcalLaserCondTools.h:95
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalEndcap
Definition: EcalSubdetector.h:10
EcalLaserCondTools::nIovs_
int nIovs_
Definition: EcalLaserCondTools.h:94
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
EcalLaserAPDPNRatios::EcalLaserAPDPNpair
Definition: EcalLaserAPDPNRatios.h:16
edm::ParameterSet
Definition: ParameterSet.h:47
ecaldqm::nCrystals
unsigned nCrystals(unsigned)
Definition: EcalDQMCommonUtils.cc:334
Event.h
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
EEDetId::hashedIndex
int hashedIndex() const
Definition: EEDetId.h:183
EEDetId::IX_MAX
static const int IX_MAX
Definition: EEDetId.h:298
createfilelist.int
int
Definition: createfilelist.py:10
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
EcalLaserCondTools.h
ntuplemaker.iline
iline
Definition: ntuplemaker.py:186
EcalLaserCondTools::toNth
static std::string toNth(int n)
Definition: EcalLaserCondTools.cc:588
EcalLaserCondTools::nLmes
static constexpr int nLmes
Definition: EcalLaserCondTools.h:28
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
p1
double p1[4]
Definition: TauolaWrapper.h:89
edm::EventSetup
Definition: EventSetup.h:58
EcalLaserAPDPNRatios::EcalLaserTimeStampMap
std::vector< EcalLaserTimeStamp > EcalLaserTimeStampMap
Definition: EcalLaserAPDPNRatios.h:34
get
#define get
res
Definition: Electron.h:6
EcalLaserCondTools::minP_
double minP_
Definition: EcalLaserCondTools.h:97
EEDetId::iy
int iy() const
Definition: EEDetId.h:83
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
alignCSCRings.r
r
Definition: alignCSCRings.py:93
EBDetId::validDetId
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
groupFilesInBlocks.nn
nn
Definition: groupFilesInBlocks.py:150
std
Definition: JetResolutionObject.h:76
EcalLaserCondTools::ferr_
FILE * ferr_
Definition: EcalLaserCondTools.h:98
EcalLaserCondTools::skipIov_
int skipIov_
Definition: EcalLaserCondTools.h:93
EcalLaserCondTools::FileReader::fnames_
std::vector< std::string > fnames_
Definition: EcalLaserCondTools.h:74
EcalLaserCondTools::FileReader::trim
void trim()
Definition: EcalLaserCondTools.cc:572
Exception
Definition: hltDiff.cc:245
cond::service::PoolDBOutputService::writeOne
Hash writeOne(const T *payload, Time_t time, const std::string &recordName)
Definition: PoolDBOutputService.h:63
EBDetId::ietaAbs
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
EventSetup.h
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:128
p3
double p3[4]
Definition: TauolaWrapper.h:91
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
EcalLaserCondTools::fnames_
std::vector< std::string > fnames_
Definition: EcalLaserCondTools.h:91
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
EBDetId::iphi
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
cms::Exception
Definition: Exception.h:70
EcalLaserAPDPNRatios
Definition: EcalLaserAPDPNRatios.h:14
EcalLaserCondTools::eventList_
FILE * eventList_
Definition: EcalLaserCondTools.h:87
EcalLaserCondTools::fillDb
void fillDb(CorrReader &r)
Definition: EcalLaserCondTools.cc:261
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
EcalLaserCondTools::fout_
FILE * fout_
Definition: EcalLaserCondTools.h:86
event
Definition: event.py:1
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
trim
static void trim(std::string &s)
Definition: DTCCablingMapProducer.cc:67
EcalLaserAPDPNRatios::EcalLaserTimeStamp
Definition: EcalLaserAPDPNRatios.h:24
EBDetId::MAX_IETA
static const int MAX_IETA
Definition: EBDetId.h:136
EcalLaserCondTools::FileReader::iline_
int iline_
Definition: EcalLaserCondTools.h:76
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
EBDetId::MIN_IPHI
static const int MIN_IPHI
Definition: EBDetId.h:135
edm::Timestamp
Definition: Timestamp.h:30