CMS 3D CMS Logo

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