CMS 3D CMS Logo

HcalDbASCIIIO.cc
Go to the documentation of this file.
1 //
2 // F.Ratnikov (UMd), Oct 28, 2005
3 //
4 #include <vector>
5 #include <string>
6 #include <cstdio>
7 #include <sstream>
8 #include <memory>
9 #include <iostream>
10 
15 
19 
20 namespace {
21  class DetIdLess {
22  public:
23  bool operator()(DetId fFirst, DetId fSecond) const {
24  HcalGenericDetId first(fFirst);
25  HcalGenericDetId second(fSecond);
26  if (first.genericSubdet() != second.genericSubdet())
27  return first.genericSubdet() < second.genericSubdet();
28  if (first.isHcalDetId()) {
30  HcalDetId s1(second);
31  return f1.zside() != s1.zside() ? f1.zside() < s1.zside()
32  : f1.iphi() != s1.iphi() ? f1.iphi() < s1.iphi()
33  : f1.ietaAbs() != s1.ietaAbs() ? f1.ietaAbs() < s1.ietaAbs()
34  : f1.depth() < s1.depth();
35  } else {
36  return first.rawId() < second.rawId();
37  }
38  }
39  };
40  class HcalElectronicsIdLess {
41  public:
42  bool operator()(HcalElectronicsId first, HcalElectronicsId second) const {
43  return first.readoutVMECrateId() != second.readoutVMECrateId()
44  ? first.readoutVMECrateId() < second.readoutVMECrateId()
45  : first.htrSlot() != second.htrSlot() ? first.htrSlot() < second.htrSlot()
46  : first.htrTopBottom() != second.htrTopBottom() ? first.htrTopBottom() < second.htrTopBottom()
47  : first.fiberIndex() != second.fiberIndex() ? first.fiberIndex() < second.fiberIndex()
48  : first.fiberChanId() < second.fiberChanId();
49  }
50  };
51 } // namespace
52 
53 // ------------------------------ some little helpers ------------------------------
54 
55 std::vector<std::string> splitString(const std::string& fLine) {
56  std::vector<std::string> result;
57  int start = 0;
58  bool empty = true;
59  for (unsigned i = 0; i <= fLine.size(); i++) {
60  if (fLine[i] == ' ' || i == fLine.size()) {
61  if (!empty) {
62  std::string item(fLine, start, i - start);
63  result.push_back(item);
64  empty = true;
65  }
66  start = i + 1;
67  } else {
68  if (empty)
69  empty = false;
70  }
71  }
72  return result;
73 }
74 
75 std::vector<unsigned int> splitStringToIntByComma(const std::string& fLine) {
76  std::vector<unsigned int> result;
77  int start = 0;
78  bool empty = true;
79  for (unsigned i = 0; i <= fLine.size(); i++) {
80  if (fLine[i] == ',' || i == fLine.size()) {
81  if (!empty) {
82  std::string itemString(fLine, start, i - start);
83  result.push_back(atoi(itemString.c_str()));
84  empty = true;
85  }
86  start = i + 1;
87  } else {
88  if (empty)
89  empty = false;
90  }
91  }
92  return result;
93 }
94 
95 std::vector<float> splitStringToFloatByComma(const std::string& fLine) {
96  std::vector<float> result;
97  int start = 0;
98  bool empty = true;
99  for (unsigned i = 0; i <= fLine.size(); i++) {
100  if (fLine[i] == ',' || i == fLine.size()) {
101  if (!empty) {
102  std::string itemString(fLine, start, i - start);
103  result.push_back(atof(itemString.c_str()));
104  empty = true;
105  }
106  start = i + 1;
107  } else {
108  if (empty)
109  empty = false;
110  }
111  }
112  return result;
113 }
114 
115 std::vector<double> splitStringToDoubleByComma(const std::string& fLine) {
116  std::vector<double> result;
117  int start = 0;
118  bool empty = true;
119  for (unsigned i = 0; i <= fLine.size(); i++) {
120  if (fLine[i] == ',' || i == fLine.size()) {
121  if (!empty) {
122  std::string itemString(fLine, start, i - start);
123  result.push_back(atof(itemString.c_str()));
124  empty = true;
125  }
126  start = i + 1;
127  } else {
128  if (empty)
129  empty = false;
130  }
131  }
132  return result;
133 }
134 
135 DetId HcalDbASCIIIO::getId(const std::vector<std::string>& items) {
137  return converter.getId();
138 }
139 
140 void HcalDbASCIIIO::dumpId(std::ostream& fOutput, DetId id) {
142  char buffer[1024];
143  sprintf(buffer,
144  " %15s %15s %15s %15s",
145  converter.getField1().c_str(),
146  converter.getField2().c_str(),
147  converter.getField3().c_str(),
148  converter.getFlavor().c_str());
149  fOutput << buffer;
150 }
151 
152 void HcalDbASCIIIO::dumpIdShort(std::ostream& fOutput, DetId id) {
154  char buffer[1024];
155  sprintf(buffer,
156  " %5s %4s %4s %10s",
157  converter.getField1().c_str(),
158  converter.getField2().c_str(),
159  converter.getField3().c_str(),
160  converter.getFlavor().c_str());
161  fOutput << buffer;
162 }
163 
164 // ------------------------------ start templates ------------------------------
165 
166 template <class T>
167 bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
168  std::istringstream iss(s);
169  return !(iss >> f >> t).fail();
170 }
171 
172 template <class S, class T>
173 bool getHcalObject(std::istream& fInput, T* fObject) {
174  if (!fObject)
175  return false; //fObject = new T;
176  char buffer[1024];
177  while (fInput.getline(buffer, 1024)) {
178  if (buffer[0] == '#')
179  continue; //ignore comment
180  std::vector<std::string> items = splitString(std::string(buffer));
181  if (items.empty())
182  continue; // blank line
183  if (items.size() < 8) {
184  edm::LogWarning("Format Error") << "Bad line: " << buffer
185  << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
186  << std::endl;
187  continue;
188  }
190 
191  // if (fObject->exists(id) )
192  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
193  // else
194  // {
195  S fCondObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atof(items[6].c_str()), atof(items[7].c_str()));
196  fObject->addValues(fCondObject);
197  // }
198  }
199 
200  return true;
201 }
202 
203 template <class T>
204 bool dumpHcalObject(std::ostream& fOutput, const T& fObject) {
205  char buffer[1024];
206  sprintf(buffer,
207  "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n",
208  "eta",
209  "phi",
210  "dep",
211  "det",
212  "cap0",
213  "cap1",
214  "cap2",
215  "cap3",
216  "DetId");
217  fOutput << buffer;
218  std::vector<DetId> channels = fObject.getAllChannels();
219  std::sort(channels.begin(), channels.end(), DetIdLess());
220  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
221  const float* values = fObject.getValues(*channel)->getValues();
222  if (values) {
223  HcalDbASCIIIO::dumpId(fOutput, *channel);
224  sprintf(
225  buffer, " %10.7f %10.7f %10.7f %10.7f %10X\n", values[0], values[1], values[2], values[3], channel->rawId());
226  fOutput << buffer;
227  }
228  }
229  return true;
230 }
231 
232 template <class ObjectPrimitiveType, class S, class T>
233 bool getHcalSingleObject(std::istream& fInput, T* fObject) {
234  if (!fObject)
235  return false; //fObject = new T;
236  char buffer[1024];
237  while (fInput.getline(buffer, 1024)) {
238  if (buffer[0] == '#')
239  continue; //ignore comment
240  std::vector<std::string> items = splitString(std::string(buffer));
241  if (items.empty())
242  continue; // blank line
243  if (items.size() < 5) {
244  edm::LogWarning("Format Error") << "Bad line: " << buffer
245  << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
246  continue;
247  }
249 
250  // if (fObject->exists(id) )
251  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
252  // else
253  // {
254  std::stringstream ss(items[4]);
255  ObjectPrimitiveType x = 0; // usually int or float
256  ss >> x;
257  S fCondObject(id, x);
258  fObject->addValues(fCondObject);
259  // }
260  }
261  return true;
262 }
263 
264 template <class T>
265 bool dumpHcalSingleFloatObject(std::ostream& fOutput, const T& fObject) {
266  char buffer[1024];
267  sprintf(buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
268  fOutput << buffer;
269  std::vector<DetId> channels = fObject.getAllChannels();
270  std::sort(channels.begin(), channels.end(), DetIdLess());
271  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
272  const float value = fObject.getValues(*channel)->getValue();
273  HcalDbASCIIIO::dumpId(fOutput, *channel);
274  sprintf(buffer, " %8.5f %10X\n", value, channel->rawId());
275  fOutput << buffer;
276  }
277  return true;
278 }
279 
280 template <class T>
281 bool dumpHcalSingleIntObject(std::ostream& fOutput, const T& fObject) {
282  char buffer[1024];
283  sprintf(buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
284  fOutput << buffer;
285  std::vector<DetId> channels = fObject.getAllChannels();
286  std::sort(channels.begin(), channels.end(), DetIdLess());
287  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
288  const int value = fObject.getValues(*channel)->getValue();
289  HcalDbASCIIIO::dumpId(fOutput, *channel);
290  sprintf(buffer, " %15d %10X\n", value, channel->rawId());
291  fOutput << buffer;
292  }
293  return true;
294 }
295 
296 template <class S, class T>
297 bool getHcalMatrixObject(std::istream& fInput, T* fObject, S* fCondObject) {
298  if (!fObject)
299  return false; //fObject = new T;
300  char buffer[1024];
301  while (fInput.getline(buffer, 1024)) {
302  if (buffer[0] == '#')
303  continue; //ignore comment
304  std::vector<std::string> items = splitString(std::string(buffer));
305  if (items.empty())
306  continue; // blank line
307  DetId firstid = HcalDbASCIIIO::getId(items);
308  fCondObject = new S(firstid.rawId());
309  for (int j = 0; j != 10; j++)
310  fCondObject->setValue(atoi(items[4].c_str()), 0, j, atof(items[j + 5].c_str()));
311  for (int i = 1; i != 40; i++) {
312  fInput.getline(buffer, 1024);
315  if (id.rawId() != firstid.rawId())
316  break; //throw cms::Exception("Wrong number of elements");
317  for (int j = 0; j != 10; j++)
318  fCondObject->setValue(atoi(items[4].c_str()), i % 10, j, atof(items[j + 5].c_str()));
319  }
320  fObject->addValues(*fCondObject);
321  delete fCondObject;
322  }
323  return true;
324 }
325 
326 template <class T>
327 bool dumpHcalMatrixObject(std::ostream& fOutput, const T& fObject) {
328  char buffer[1024];
329  sprintf(buffer,
330  "# %5s %5s %5s %5s %5s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
331  "eta",
332  "phi",
333  "dep",
334  "det",
335  "capid",
336  "c0",
337  "c1",
338  "c2",
339  "c3",
340  "c4",
341  "c5",
342  "c6",
343  "c7",
344  "c8",
345  "c9",
346  "DetId");
347  fOutput << buffer;
348  std::vector<DetId> channels = fObject.getAllChannels();
349  std::sort(channels.begin(), channels.end(), DetIdLess());
350  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
351  float thisline[10];
352  for (int m = 0; m != 4; m++) {
353  for (int i = 0; i != 10; i++) {
354  for (int j = 0; j != 10; j++) {
355  // std::cout <<"test "<<(fObject.getValues(*channel))->getValue(0,0,0);
356  thisline[j] = fObject.getValues(*channel)->getValue(m, i, j);
357  // thisline[j] = fObject.getValues(*channel)->getValue(1,1,1);
358  }
359  HcalDbASCIIIO::dumpId(fOutput, *channel);
360  sprintf(buffer,
361  " %5i %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
362  m,
363  thisline[0],
364  thisline[1],
365  thisline[2],
366  thisline[3],
367  thisline[4],
368  thisline[5],
369  thisline[6],
370  thisline[7],
371  thisline[8],
372  thisline[9],
373  channel->rawId());
374  fOutput << buffer;
375  }
376  }
377  }
378 
379  return true;
380 }
381 
382 // ------------------------------ end templates ------------------------------
383 
384 namespace HcalDbASCIIIO {
385  bool getObject(std::istream& fInput, HcalGains* fObject) { return getHcalObject<HcalGain>(fInput, fObject); }
386  bool dumpObject(std::ostream& fOutput, const HcalGains& fObject) { return dumpHcalObject(fOutput, fObject); }
387  bool getObject(std::istream& fInput, HcalGainWidths* fObject) {
388  return getHcalObject<HcalGainWidth>(fInput, fObject);
389  }
390  bool dumpObject(std::ostream& fOutput, const HcalGainWidths& fObject) { return dumpHcalObject(fOutput, fObject); }
391 
392  bool getObject(std::istream& fInput, HcalRespCorrs* fObject) {
393  return getHcalSingleObject<float, HcalRespCorr>(fInput, fObject);
394  }
395  bool dumpObject(std::ostream& fOutput, const HcalRespCorrs& fObject) {
396  return dumpHcalSingleFloatObject(fOutput, fObject);
397  }
398 
399  bool getObject(std::istream& fInput, HcalLUTCorrs* fObject) {
400  return getHcalSingleObject<float, HcalLUTCorr>(fInput, fObject);
401  }
402  bool dumpObject(std::ostream& fOutput, const HcalLUTCorrs& fObject) {
403  return dumpHcalSingleFloatObject(fOutput, fObject);
404  }
405 
406  bool getObject(std::istream& fInput, HcalPFCorrs* fObject) {
407  return getHcalSingleObject<float, HcalPFCorr>(fInput, fObject);
408  }
409  bool dumpObject(std::ostream& fOutput, const HcalPFCorrs& fObject) {
410  return dumpHcalSingleFloatObject(fOutput, fObject);
411  }
412 
413  bool getObject(std::istream& fInput, HcalTimeCorrs* fObject) {
414  return getHcalSingleObject<float, HcalTimeCorr>(fInput, fObject);
415  }
416  bool dumpObject(std::ostream& fOutput, const HcalTimeCorrs& fObject) {
417  return dumpHcalSingleFloatObject(fOutput, fObject);
418  }
419 
420  bool getObject(std::istream& fInput, HcalZSThresholds* fObject) {
421  return getHcalSingleObject<int, HcalZSThreshold>(fInput, fObject);
422  }
423  bool dumpObject(std::ostream& fOutput, const HcalZSThresholds& fObject) {
424  return dumpHcalSingleIntObject(fOutput, fObject);
425  }
426 
427  bool getObject(std::istream& fInput, HcalZDCLowGainFractions* fObject) {
428  return getHcalSingleObject<float, HcalZDCLowGainFraction>(fInput, fObject);
429  }
430  bool dumpObject(std::ostream& fOutput, const HcalZDCLowGainFractions& fObject) {
431  return dumpHcalSingleFloatObject(fOutput, fObject);
432  }
433 
434  bool getObject(std::istream& fInput, HcalValidationCorrs* fObject) {
435  return getHcalSingleObject<float, HcalValidationCorr>(fInput, fObject);
436  }
437  bool dumpObject(std::ostream& fOutput, const HcalValidationCorrs& fObject) {
438  return dumpHcalSingleFloatObject(fOutput, fObject);
439  }
440 
441  bool getObject(std::istream& fInput, HcalQIETypes* fObject) {
442  return getHcalSingleObject<int, HcalQIEType>(fInput, fObject);
443  }
444  bool dumpObject(std::ostream& fOutput, const HcalQIETypes& fObject) {
445  return dumpHcalSingleIntObject(fOutput, fObject);
446  }
447 } // namespace HcalDbASCIIIO
448 
449 // ------------------------------ start specific implementations ------------------------------
450 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalRecoParams* fObject) {
451  if (!fObject)
452  return false; // fObject = new HcalRecoParams(); This was always useless...
453  char buffer[1024];
454  while (fInput.getline(buffer, 1024)) {
455  if (buffer[0] == '#')
456  continue; //ignore comment
457  std::vector<std::string> items = splitString(std::string(buffer));
458  if (items.empty())
459  continue; // blank line
460  if (items.size() < 6) {
461  edm::LogWarning("Format Error") << "Bad line: " << buffer
462  << "\n line must contain 6 items: eta, phi, depth, subdet, param1, param2"
463  << std::endl;
464  continue;
465  }
467 
468  int packingScheme = 0;
469  if (items.size() > 22) {
470  packingScheme = atoi(items[22].c_str());
471  }
472 
473  int param1 = 0;
474  int param2 = 0;
475  if (packingScheme == 0) {
476  param1 = atoi(items[4].c_str());
477  param2 = atoi(items[5].c_str());
478  } // packing scheme 0 (old format).
479 
480  if (packingScheme == 1) {
481  // 0 1 2 3 4 5 6 7 8 9
482  int aabits[6] = {1, 1, 8, 4, 4, 9};
483  int aamax[6] = {1, 1, 255, 15, 15, 511};
484 
485  int bbbits[10] = {1, 4, 1, 4, 1, 4, 4, 4, 4, 4};
486  int bbmax[10] = {1, 15, 1, 15, 1, 15, 15, 15, 15, 15};
487 
488  // param 1
489  int j = 0;
490  int aa;
491  int aashift = 0;
492  for (int i = 0; i < 6; i++) {
493  j = i + 7;
494  if (i == 2) {
495  float phase = atof(items[j].c_str());
496  float xphase = (phase + 32.0) * 4.0; // range of phase [-30.0,30.0]
497  aa = xphase;
498  } else {
499  aa = atoi(items[j].c_str());
500  }
501  if (aa > aamax[i] || aa < 0) {
502  edm::LogWarning("Format Error")
503  << "Bad line: " << buffer << "\n value for a" << i << " should be less than" << aamax[i] << std::endl;
504  }
505  param1 = param1 | aa << aashift;
506  aashift = aashift + aabits[i];
507  }
508 
509  // param 2
510  int bb;
511  int bbshift = 0;
512  for (int i = 0; i < 10; i++) {
513  j = i + 13;
514  bb = atoi(items[j].c_str());
515  if (bb > bbmax[i]) {
516  edm::LogWarning("Format Error")
517  << "Bad line: " << buffer << "\n value for b" << i << " should be less than" << bbmax[i] << std::endl;
518  }
519  param2 = param2 | bb << bbshift;
520  bbshift = bbshift + bbbits[i];
521  }
522  } // packing sheme 1.
523 
524  // HcalRecoParam* fCondObject = new HcalRecoParam(id, atoi (items [4].c_str()), atoi (items [5].c_str()) );
525 
526  // std::cout<<" buffer "<<buffer<<std::endl;
527  // std::cout<<" param1, param2 "<<param1<<" "<<param2<<std::endl;
528 
529  HcalRecoParam* fCondObject = new HcalRecoParam(id, param1, param2);
530  fObject->addValues(*fCondObject);
531  delete fCondObject;
532  }
533  return true;
534 }
535 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalRecoParams& fObject) {
536  char buffer[1024];
537  // sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
538  // fOutput << buffer;
539  std::vector<DetId> channels = fObject.getAllChannels();
540  std::sort(channels.begin(), channels.end(), DetIdLess());
541  int myCounter = 0;
542  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
543  myCounter++;
544  int param1 = fObject.getValues(*channel)->param1();
545  int param2 = fObject.getValues(*channel)->param2();
546  int packingScheme = fObject.getValues(*channel)->packingScheme();
547 
548  // std::cout<<" Param1 "<<Param1<<" Param2 "<<Param2<<" packing "<<packingScheme<<std::endl;
549 
550  if (packingScheme == 0) {
551  // old format
552  if (myCounter == 1) {
553  sprintf(buffer,
554  "# %15s %15s %15s %15s %18s %15s %10s\n",
555  "eta",
556  "phi",
557  "dep",
558  "det",
559  "firstSample",
560  "samplesToAdd",
561  "DetId");
562  }
563  HcalDbASCIIIO::dumpId(fOutput, *channel);
564  sprintf(buffer,
565  " %15d %15d %16X\n",
566  fObject.getValues(*channel)->firstSample(),
567  fObject.getValues(*channel)->samplesToAdd(),
568  channel->rawId());
569  fOutput << buffer;
570  }
571 
572  if (packingScheme == 1) {
573  if (myCounter == 1) {
574  char lineT[100], lineA[200], lineB[200];
575  //
576  sprintf(lineT, "#%50s", " ");
577  fOutput << lineT;
578  sprintf(lineA, " %31s", "a0: correctForPhaseContainment");
579  fOutput << lineA;
580  sprintf(lineB, " %36s", "b0: useLeakCorrection\n");
581  fOutput << lineB;
582  //
583  sprintf(lineT, "#%50s", " ");
584  fOutput << lineT;
585  sprintf(lineA, " %31s", "a1: correctForLeadingEdge");
586  fOutput << lineA;
587  sprintf(lineB, " %36s", "b1: leakCorrectionID\n");
588  fOutput << lineB;
589  //
590  sprintf(lineT, "#%50s", " ");
591  fOutput << lineT;
592  sprintf(lineA, " %31s", "a2: correctionPhaseNS");
593  fOutput << lineA;
594  sprintf(lineB, " %36s", "b2: correctForTimeslew\n");
595  fOutput << lineB;
596  //
597  sprintf(lineT, "#%50s", " ");
598  fOutput << lineT;
599  sprintf(lineA, " %31s", "a3: firstSample");
600  fOutput << lineA;
601  sprintf(lineB, " %36s", "b3: timeslewCorrectionID\n");
602  fOutput << lineB;
603  //
604  sprintf(lineT, "#%50s", " ");
605  fOutput << lineT;
606  sprintf(lineA, " %31s", "a4: samplesToAdd");
607  fOutput << lineA;
608  sprintf(lineB, " %36s", "b4: correctTiming\n");
609  fOutput << lineB;
610  //
611  sprintf(lineT, "#%50s", " ");
612  fOutput << lineT;
613  sprintf(lineA, " %31s", "a5: pulseShapeID");
614  fOutput << lineA;
615  sprintf(lineB, " %36s", "b5: firstAuxTS\n");
616  fOutput << lineB;
617  //
618  sprintf(lineT, "#%50s", " ");
619  fOutput << lineT;
620  sprintf(lineA, " %31s", " ");
621  fOutput << lineA;
622  sprintf(lineB, " %36s", "b6: specialCaseID\n");
623  fOutput << lineB;
624  //
625  sprintf(lineT, "#%50s", " ");
626  fOutput << lineT;
627  sprintf(lineA, " %31s", " ");
628  fOutput << lineA;
629  sprintf(lineB, " %36s", "b7: noiseFlaggingID\n");
630  fOutput << lineB;
631  //
632  sprintf(lineT, "#%50s", " ");
633  fOutput << lineT;
634  sprintf(lineA, " %31s", " ");
635  fOutput << lineA;
636  sprintf(lineB, " %36s", "b8: pileupCleaningID\n");
637  fOutput << lineB;
638 
639  sprintf(lineT, "#%50s", " ");
640  fOutput << lineT;
641  sprintf(lineA, " %31s", " ");
642  fOutput << lineA;
643  sprintf(lineB, " %36s", "b9: packingScheme\n");
644  fOutput << lineB;
645 
646  //
647  sprintf(lineT, "# %5s %4s %4s %10s %11s %10s %10s", "eta", "phi", "dep", "det", "param1", "param2", "DetId");
648  fOutput << lineT;
649 
650  sprintf(lineA, " %6s %4s %6s %4s %4s %4s", "a0", "a1", "a2", "a3", "a4", "a5");
651  fOutput << lineA;
652 
653  sprintf(lineB, " %6s %3s %3s %3s %3s %3s %3s %3s %3s\n", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8");
654  fOutput << lineB;
655  }
656 
657  HcalDbASCIIIO::dumpIdShort(fOutput, *channel);
658  sprintf(buffer, " %11d %10d %10X", param1, param2, channel->rawId());
659  fOutput << buffer;
660 
661  bool aa0 = fObject.getValues(*channel)->correctForPhaseContainment();
662  bool aa1 = fObject.getValues(*channel)->correctForLeadingEdge();
663  float aa2 = fObject.getValues(*channel)->correctionPhaseNS();
664  int aa3 = fObject.getValues(*channel)->firstSample();
665  int aa4 = fObject.getValues(*channel)->samplesToAdd();
666  int aa5 = fObject.getValues(*channel)->pulseShapeID();
667  sprintf(buffer, " %6d %4d %6.1f %4d %4d %4d", aa0, aa1, aa2, aa3, aa4, aa5);
668  fOutput << buffer;
669 
670  bool bb0 = fObject.getValues(*channel)->useLeakCorrection();
671  int bb1 = fObject.getValues(*channel)->leakCorrectionID();
672  bool bb2 = fObject.getValues(*channel)->correctForTimeslew();
673  int bb3 = fObject.getValues(*channel)->timeslewCorrectionID();
674  bool bb4 = fObject.getValues(*channel)->correctTiming();
675  int bb5 = fObject.getValues(*channel)->firstAuxTS();
676  int bb6 = fObject.getValues(*channel)->specialCaseID();
677  int bb7 = fObject.getValues(*channel)->noiseFlaggingID();
678  int bb8 = fObject.getValues(*channel)->pileupCleaningID();
679  int bb9 = fObject.getValues(*channel)->packingScheme();
680  sprintf(buffer, " %6d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n", bb0, bb1, bb2, bb3, bb4, bb5, bb6, bb7, bb8, bb9);
681  fOutput << buffer;
682  } // packingScheme 1.
683 
684  } // loop ever channels
685  return true;
686 }
687 
688 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalLongRecoParams* fObject) {
689  if (!fObject)
690  return false; // fObject = new HcalLongRecoParams();
691  char buffer[1024];
692  while (fInput.getline(buffer, 1024)) {
693  if (buffer[0] == '#')
694  continue; //ignore comment
695  std::vector<std::string> items = splitString(std::string(buffer));
696  if (items.empty())
697  continue; // blank line
698  if (items.size() < 5) {
699  edm::LogWarning("Format Error") << "Bad line: " << buffer
700  << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs"
701  << std::endl;
702  continue;
703  }
704  if (items.size() > 7) {
705  edm::LogWarning("Format Error")
706  << "Check line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs. "
707  << "\n ! signalTS and noiseTS must be of format <ts1,ts2,ts3,...> withOUT spaces. Ignoring line for safety"
708  << std::endl;
709  continue;
710  }
712 
713  std::vector<unsigned int> mySignalTS = splitStringToIntByComma(items[4]);
714  std::vector<unsigned int> myNoiseTS = splitStringToIntByComma(items[5]);
715 
716  HcalLongRecoParam* fCondObject = new HcalLongRecoParam(id, mySignalTS, myNoiseTS);
717  fObject->addValues(*fCondObject);
718  delete fCondObject;
719  }
720  return true;
721 }
722 
723 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalTimingParams* fObject) {
724  if (!fObject)
725  return false; // fObject = new HcalTimingParams();
726  char buffer[1024];
727  while (fInput.getline(buffer, 1024)) {
728  if (buffer[0] == '#')
729  continue; //ignore comment
730  std::vector<std::string> items = splitString(std::string(buffer));
731  if (items.empty())
732  continue; // blank line
733  if (items.size() < 7) {
734  edm::LogWarning("Format Error") << "Bad line: " << buffer
735  << "\n line must contain 7 items: eta, phi, depth, subdet, nhit, phase, rms,detid"
736  << std::endl;
737  continue;
738  }
739  //std::cout<<"items[3] "<<items [3]<<std::endl;
740  //std::cout<<"items[0] "<<items [0]<<std::endl;
741  //std::cout<<"items[1] "<<items [1]<<std::endl;
742  //std::cout<<"items[2] "<<items [2]<<std::endl;
743 
744  //std::cout<<"items[4] "<<items [4]<<std::endl;
745  //std::cout<<"items[5] "<<items [5]<<std::endl;
746  //std::cout<<"items[6] "<<items [6]<<std::endl;
748  //std::cout<<"calculated id "<<id.rawId()<<std::endl;
749  HcalTimingParam* fCondObject =
750  new HcalTimingParam(id, atoi(items[4].c_str()), atof(items[5].c_str()), atof(items[6].c_str()));
751  fObject->addValues(*fCondObject);
752  delete fCondObject;
753  }
754  return true;
755 }
756 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalTimingParams& fObject) {
757  char buffer[1024];
758  sprintf(
759  buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s\n", "eta", "phi", "dep", "det", "nhit", "mean", "rms", "DetId");
760  fOutput << buffer;
761  std::vector<DetId> channels = fObject.getAllChannels();
762  std::sort(channels.begin(), channels.end(), DetIdLess());
763  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
764  HcalDbASCIIIO::dumpId(fOutput, *channel);
765  sprintf(buffer,
766  " %15d %8.5f %8.5f %16X\n",
767  fObject.getValues(*channel)->nhits(),
768  fObject.getValues(*channel)->phase(),
769  fObject.getValues(*channel)->rms(),
770  channel->rawId());
771  fOutput << buffer;
772  }
773  return true;
774 }
775 
776 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalLongRecoParams& fObject) {
777  char buffer[1024];
778  sprintf(
779  buffer, "# %15s %15s %15s %15s %10s %10s %10s\n", "eta", "phi", "dep", "det", "signalTSs", "noiseTSs", "DetId");
780  fOutput << buffer;
781  std::vector<DetId> channels = fObject.getAllChannels();
782  std::sort(channels.begin(), channels.end(), DetIdLess());
783  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
784  HcalGenericDetId fId(*channel);
785  if (fId.isHcalZDCDetId()) {
786  std::vector<unsigned int> vSignalTS = fObject.getValues(*channel)->signalTS();
787  std::vector<unsigned int> vNoiseTS = fObject.getValues(*channel)->noiseTS();
788  HcalDbASCIIIO::dumpId(fOutput, *channel);
789  sprintf(buffer, " ");
790  fOutput << buffer;
791  for (unsigned int i = 0; i < vSignalTS.size(); i++) {
792  if (i > 0) {
793  sprintf(buffer, ",");
794  fOutput << buffer;
795  }
796  sprintf(buffer, "%u", vSignalTS.at(i));
797  fOutput << buffer;
798  }
799  sprintf(buffer, " ");
800  fOutput << buffer;
801  for (unsigned int i = 0; i < vNoiseTS.size(); i++) {
802  if (i > 0) {
803  sprintf(buffer, ",");
804  fOutput << buffer;
805  }
806  sprintf(buffer, "%u", vNoiseTS.at(i));
807  fOutput << buffer;
808  }
809  sprintf(buffer, " %10X\n", channel->rawId());
810  fOutput << buffer;
811  }
812  }
813  return true;
814 }
815 
816 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalMCParams* fObject) {
817  if (!fObject)
818  return false; // fObject = new HcalMCParams();
819  char buffer[1024];
820  while (fInput.getline(buffer, 1024)) {
821  if (buffer[0] == '#')
822  continue; //ignore comment
823  std::vector<std::string> items = splitString(std::string(buffer));
824  if (items.empty())
825  continue; // blank line
826  if (items.size() < 5) {
827  edm::LogWarning("Format Error") << "Bad line: " << buffer
828  << "\n line must contain 5 items: eta, phi, depth, subdet, signalShape"
829  << std::endl;
830  continue;
831  }
833 
834  int packingScheme = 0;
835  if (items.size() > 11) {
836  packingScheme = atoi(items[11].c_str());
837  }
838 
839  int param1 = 0;
840  if (packingScheme == 0) {
841  param1 = atoi(items[4].c_str());
842  }
843 
844  if (packingScheme == 1) {
845  int aabits[6] = {9, 1, 4, 8, 5, 4}; // 4 spear bits added to aabits[5]
846  int aamax[6] = {511, 1, 15, 255, 1, 16};
847  int j = 0;
848  int aa;
849  int aashift = 0;
850  for (int i = 0; i < 6; i++) {
851  j = i + 6;
852  if (i == 3) {
853  float phase = atof(items[j].c_str());
854  float xphase = (phase + 32.0) * 4.0; // range of phase [-30.0,30.0]
855  aa = xphase;
856  } else {
857  aa = atoi(items[j].c_str());
858  }
859  if (aa > aamax[i] || aa < 0) {
860  edm::LogWarning("Format Error")
861  << "Bad line: " << buffer << "\n value for a" << i << " should be less than" << aamax[i] << std::endl;
862  }
863 
864  param1 = param1 | aa << aashift;
865  aashift = aashift + aabits[i];
866  }
867  }
868 
869  HcalMCParam* fCondObject = new HcalMCParam(id, param1);
870  fObject->addValues(*fCondObject);
871  delete fCondObject;
872  }
873  return true;
874 }
875 
876 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalMCParams& fObject) {
877  char buffer[1024];
878  // sprintf (buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
879  // fOutput << buffer;
880  std::vector<DetId> channels = fObject.getAllChannels();
881  std::sort(channels.begin(), channels.end(), DetIdLess());
882  int myCounter = 0;
883  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
884  myCounter++;
885  ;
886  int packingScheme = fObject.getValues(*channel)->packingScheme();
887  if (packingScheme == 0) {
888  if (myCounter == 1) {
889  sprintf(buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
890  fOutput << buffer;
891  }
892  const int value = fObject.getValues(*channel)->signalShape();
893  HcalDbASCIIIO::dumpId(fOutput, *channel);
894  sprintf(buffer, " %10d %17X\n", value, channel->rawId());
895  fOutput << buffer;
896  } // packingScheme 0
897  if (packingScheme == 1) {
898  if (myCounter == 1) {
899  char lineT[100], lineA[200];
900  //
901  sprintf(lineT, "#%40s", " ");
902  fOutput << lineT;
903  sprintf(lineA, " %31s", "a0: signalShape\n");
904  fOutput << lineA;
905  sprintf(lineT, "#%40s", " ");
906  fOutput << lineT;
907  sprintf(lineA, " %31s", "a1: syncPhase\n");
908  fOutput << lineA;
909  sprintf(lineT, "#%40s", " ");
910  fOutput << lineT;
911  sprintf(lineA, " %31s", "a2: binOfMaximum\n");
912  fOutput << lineA;
913  sprintf(lineT, "#%40s", " ");
914  fOutput << lineT;
915  sprintf(lineA, " %31s", "a3: timePhase\n");
916  fOutput << lineA;
917  sprintf(lineT, "#%40s", " ");
918  fOutput << lineT;
919  sprintf(lineA, " %31s", "a4: timeSmearing\n");
920  fOutput << lineA;
921  sprintf(lineT, "#%40s", " ");
922  fOutput << lineT;
923  sprintf(lineA, " %31s", "a5: packingScheme\n");
924  fOutput << lineA;
925  sprintf(lineT, "# %5s %4s %4s %10s %11s %10s", "eta", "phi", "dep", "det", "param1", "DetId");
926  fOutput << lineT;
927  sprintf(lineA, " %6s %4s %4s %6s %4s %4s\n", "a0", "a1", "a2", "a3", "a4", "a5");
928  fOutput << lineA;
929  }
930  int param1 = fObject.getValues(*channel)->param1();
931  HcalDbASCIIIO::dumpIdShort(fOutput, *channel);
932  sprintf(buffer, " %11d %10X", param1, channel->rawId());
933  fOutput << buffer;
934  int aa0 = fObject.getValues(*channel)->signalShape();
935  bool aa1 = fObject.getValues(*channel)->syncPhase();
936  int aa2 = fObject.getValues(*channel)->binOfMaximum();
937  float aa3 = fObject.getValues(*channel)->timePhase();
938  bool aa4 = fObject.getValues(*channel)->timeSmearing();
939  int aa5 = fObject.getValues(*channel)->packingScheme();
940  sprintf(buffer, "%6d %4d %4d %6.1f %4d %4d\n", aa0, aa1, aa2, aa3, aa4, aa5);
941  fOutput << buffer;
942  }
943  }
944  return true;
945 }
946 
947 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalPedestals* fObject) {
948  char buffer[1024];
949 
950  while (fInput.getline(buffer, 1024)) {
951  std::vector<std::string> items = splitString(std::string(buffer));
952  if (items.empty())
953  continue; // blank line
954  else {
955  if (items[0] == "#U") {
956  if (items[1] == (std::string) "ADC")
957  fObject->setUnitADC(true);
958  else if (items[1] == (std::string) "fC")
959  fObject->setUnitADC(false);
960  else {
961  edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
962  fObject->setUnitADC(false);
963  }
964  break;
965  } else {
966  edm::LogWarning("Pedestal Unit Missing")
967  << "The unit for the pedestals is missing in the txt file." << std::endl;
968  return false;
969  }
970  }
971  }
972  while (fInput.getline(buffer, 1024)) {
973  if (buffer[0] == '#')
974  continue;
975  std::vector<std::string> items = splitString(std::string(buffer));
976  if (items.empty())
977  continue; // blank line
978  if (items.size() < 8) {
979  edm::LogWarning("Format Error")
980  << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
981  << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width" << std::endl;
982  continue;
983  }
984  DetId id = getId(items);
985 
986  // if (fObject->exists(id) )
987  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
988  // else
989  // {
990 
991  if (items.size() < 12) // old format without widths
992  {
993  HcalPedestal* fCondObject = new HcalPedestal(id,
994  atof(items[4].c_str()),
995  atof(items[5].c_str()),
996  atof(items[6].c_str()),
997  atof(items[7].c_str()),
998  0.,
999  0.,
1000  0.,
1001  0.);
1002  fObject->addValues(*fCondObject);
1003  delete fCondObject;
1004  } else // new format with widths
1005  {
1006  HcalPedestal* fCondObject = new HcalPedestal(id,
1007  atof(items[4].c_str()),
1008  atof(items[5].c_str()),
1009  atof(items[6].c_str()),
1010  atof(items[7].c_str()),
1011  atof(items[8].c_str()),
1012  atof(items[9].c_str()),
1013  atof(items[10].c_str()),
1014  atof(items[11].c_str()));
1015  fObject->addValues(*fCondObject);
1016  delete fCondObject;
1017  }
1018 
1019  // }
1020  }
1021  return true;
1022 }
1023 
1024 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalPedestals& fObject) {
1025  char buffer[1024];
1026  if (fObject.isADC())
1027  sprintf(buffer, "#U ADC << this is the unit \n");
1028  else
1029  sprintf(buffer, "#U fC << this is the unit \n");
1030  fOutput << buffer;
1031 
1032  sprintf(buffer,
1033  "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
1034  "eta",
1035  "phi",
1036  "dep",
1037  "det",
1038  "cap0",
1039  "cap1",
1040  "cap2",
1041  "cap3",
1042  "widthcap0",
1043  "widthcap1",
1044  "widthcap2",
1045  "widthcap3",
1046  "DetId");
1047  fOutput << buffer;
1048 
1049  std::vector<DetId> channels = fObject.getAllChannels();
1050  std::sort(channels.begin(), channels.end(), DetIdLess());
1051  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1052  const float* values = fObject.getValues(*channel)->getValues();
1053  if (values) {
1054  dumpId(fOutput, *channel);
1055  sprintf(buffer,
1056  " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
1057  values[0],
1058  values[1],
1059  values[2],
1060  values[3],
1061  values[4],
1062  values[5],
1063  values[6],
1064  values[7],
1065  channel->rawId());
1066  fOutput << buffer;
1067  }
1068  }
1069  return true;
1070 }
1071 
1072 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1073 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalChannelQuality* fObject) {
1074  if (!fObject)
1075  return false; //fObject = new HcalChannelQuality;
1076  char buffer[1024];
1077  while (fInput.getline(buffer, 1024)) {
1078  if (buffer[0] == '#')
1079  continue; //ignore comment
1080  std::vector<std::string> items = splitString(std::string(buffer));
1081  if (items.empty())
1082  continue; // blank line
1083  if (items.size() < 6) {
1084  edm::LogWarning("Format Error")
1085  << "Bad line: " << buffer
1086  << "\n line must contain 6 items: eta, phi, depth, subdet, base - either (hex) or (dec), value" << std::endl;
1087  continue;
1088  }
1089  DetId id = getId(items);
1090 
1091  // if (fObject->exists(id) )
1092  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1093  // else
1094  // {
1095  uint32_t mystatus;
1096  if (items[4] == "(hex)")
1097  sscanf(items[5].c_str(), "%X", &mystatus);
1098  else if (items[4] == "(dec)")
1099  sscanf(items[5].c_str(), "%u", &mystatus);
1100  else {
1101  edm::LogWarning("Format Error") << "Bad line: " << buffer
1102  << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
1103  continue;
1104  }
1105 
1106  HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus); //atoi (items [4].c_str()) );
1107  fObject->addValues(*fCondObject);
1108  delete fCondObject;
1109  // }
1110  }
1111  return true;
1112 }
1113 
1114 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalChannelQuality& fObject) {
1115  char buffer[1024];
1116  sprintf(buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
1117  fOutput << buffer;
1118  std::vector<DetId> channels = fObject.getAllChannels();
1119  std::sort(channels.begin(), channels.end(), DetIdLess());
1120  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1121  const int value = fObject.getValues(*channel)->getValue();
1122  dumpId(fOutput, *channel);
1123  sprintf(buffer, "%6s %15X %10X\n", "(hex)", value, channel->rawId());
1124  fOutput << buffer;
1125  }
1126  return true;
1127 }
1128 
1129 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1130 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalL1TriggerObjects* fObject) {
1131  char buffer[1024];
1132 
1133  while (fInput.getline(buffer, 1024)) {
1134  if (buffer[0] == '#') {
1135  if (buffer[1] == 'T') // contains tag name
1136  {
1137  std::vector<std::string> items = splitString(std::string(buffer));
1138  fObject->setTagString(items[1]);
1139  continue;
1140  }
1141  if (buffer[1] == 'A') // contains algo name
1142  {
1143  std::vector<std::string> items = splitString(std::string(buffer));
1144  fObject->setAlgoString(items[1]);
1145  continue;
1146  } else
1147  continue; //ignore comment
1148  }
1149  std::vector<std::string> items = splitString(std::string(buffer));
1150  if (items.empty())
1151  continue; // blank line
1152  if (items.size() < 7) {
1153  edm::LogWarning("Format Error")
1154  << "Bad line: " << buffer
1155  << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
1156  continue;
1157  }
1158  DetId id = getId(items);
1159 
1160  HcalL1TriggerObject* fCondObject =
1161  new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()));
1162 
1163  fObject->addValues(*fCondObject);
1164  delete fCondObject;
1165  }
1166  return true;
1167 }
1168 
1169 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalL1TriggerObjects& fObject) {
1170  char buffer[1024];
1171  //first print tag and algo
1172  sprintf(buffer, "#T %s << this is the tag name \n", fObject.getTagString().c_str());
1173  fOutput << buffer;
1174  sprintf(buffer, "#A %s << this is the algorithm name \n", fObject.getAlgoString().c_str());
1175  fOutput << buffer;
1176 
1177  //then the values
1178  sprintf(buffer,
1179  "# %15s %15s %15s %15s %8s %13s %8s %10s\n",
1180  "eta",
1181  "phi",
1182  "dep",
1183  "det",
1184  "ped",
1185  "respcorrgain",
1186  "flag",
1187  "DetId");
1188  fOutput << buffer;
1189  std::vector<DetId> channels = fObject.getAllChannels();
1190  // std::sort (channels.begin(), channels.end(), DetIdLess ());
1191  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1192  const HcalL1TriggerObject* item = fObject.getValues(*channel);
1193  if (item) {
1194  dumpId(fOutput, *channel);
1195  sprintf(buffer,
1196  " %12.7f %13.10f %12d %10X\n",
1197  item->getPedestal(),
1198  item->getRespGain(),
1199  item->getFlag(),
1200  channel->rawId());
1201  fOutput << buffer;
1202  }
1203  }
1204  return true;
1205 }
1206 
1207 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1208 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalPedestalWidths* fObject) {
1209  char buffer[1024];
1210  int linecounter = 0;
1211 
1212  while (fInput.getline(buffer, 1024)) {
1213  linecounter++;
1214  std::vector<std::string> items = splitString(std::string(buffer));
1215  if (items.empty())
1216  continue; // blank line
1217  else {
1218  if (items[0] == (std::string) "#U") {
1219  if (items[1] == (std::string) "ADC")
1220  fObject->setUnitADC(true);
1221  else if (items[1] == (std::string) "fC")
1222  fObject->setUnitADC(false);
1223  else {
1224  edm::LogWarning("Pedestal Width Unit Error")
1225  << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
1226  fObject->setUnitADC(false);
1227  }
1228  break;
1229  } else {
1230  edm::LogWarning("Pedestal Width Unit Missing")
1231  << "The unit for the pedestal widths is missing in the txt file." << std::endl;
1232  return false;
1233  }
1234  }
1235  }
1236 
1237  while (fInput.getline(buffer, 1024)) {
1238  linecounter++;
1239  if (buffer[0] == '#')
1240  continue; //ignore comment
1241  std::vector<std::string> items = splitString(std::string(buffer));
1242  if (items.empty())
1243  continue; // blank line
1244  if (items.size() < 14) {
1245  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter
1246  << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
1247  << " or 20 items: eta, phi, depth, subdet, 16x correlations" << std::endl;
1248  continue;
1249  }
1250  DetId id = getId(items);
1251 
1252  // if (fObject->exists(id) )
1253  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1254  // else
1255  // {
1256 
1257  if (items.size() < 20) //old format
1258  {
1260  values.setSigma(0, 0, atof(items[4].c_str()));
1261  values.setSigma(1, 0, atof(items[5].c_str()));
1262  values.setSigma(1, 1, atof(items[6].c_str()));
1263  values.setSigma(2, 0, atof(items[7].c_str()));
1264  values.setSigma(2, 1, atof(items[8].c_str()));
1265  values.setSigma(2, 2, atof(items[9].c_str()));
1266  values.setSigma(3, 0, atof(items[10].c_str()));
1267  values.setSigma(3, 1, atof(items[11].c_str()));
1268  values.setSigma(3, 2, atof(items[12].c_str()));
1269  values.setSigma(3, 3, atof(items[13].c_str()));
1270  values.setSigma(0, 1, 0.);
1271  values.setSigma(0, 2, 0.);
1272  values.setSigma(0, 3, 0.);
1273  values.setSigma(1, 2, 0.);
1274  values.setSigma(1, 3, 0.);
1275  values.setSigma(2, 3, 0.);
1276  fObject->addValues(values);
1277  } else // new format
1278  {
1280  values.setSigma(0, 0, atof(items[4].c_str()));
1281  values.setSigma(0, 1, atof(items[5].c_str()));
1282  values.setSigma(0, 2, atof(items[6].c_str()));
1283  values.setSigma(0, 3, atof(items[7].c_str()));
1284  values.setSigma(1, 0, atof(items[8].c_str()));
1285  values.setSigma(1, 1, atof(items[9].c_str()));
1286  values.setSigma(1, 2, atof(items[10].c_str()));
1287  values.setSigma(1, 3, atof(items[11].c_str()));
1288  values.setSigma(2, 0, atof(items[12].c_str()));
1289  values.setSigma(2, 1, atof(items[13].c_str()));
1290  values.setSigma(2, 2, atof(items[14].c_str()));
1291  values.setSigma(2, 3, atof(items[15].c_str()));
1292  values.setSigma(3, 0, atof(items[16].c_str()));
1293  values.setSigma(3, 1, atof(items[17].c_str()));
1294  values.setSigma(3, 2, atof(items[18].c_str()));
1295  values.setSigma(3, 3, atof(items[19].c_str()));
1296  fObject->addValues(values);
1297  }
1298 
1299  // }
1300  }
1301  return true;
1302 }
1303 
1304 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalPedestalWidths& fObject) {
1305  char buffer[1024];
1306  if (fObject.isADC())
1307  sprintf(buffer, "#U ADC << this is the unit \n");
1308  else
1309  sprintf(buffer, "#U fC << this is the unit \n");
1310  fOutput << buffer;
1311 
1312  sprintf(buffer,
1313  "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
1314  "eta",
1315  "phi",
1316  "dep",
1317  "det",
1318  "cov_0_0",
1319  "cov_0_1",
1320  "cov_0_2",
1321  "cov_0_3",
1322  "cov_1_0",
1323  "cov_1_1",
1324  "cov_1_2",
1325  "cov_1_3",
1326  "cov_2_0",
1327  "cov_2_1",
1328  "cov_2_2",
1329  "cov_2_3",
1330  "cov_3_0",
1331  "cov_3_1",
1332  "cov_3_2",
1333  "cov_3_3",
1334  "DetId");
1335  fOutput << buffer;
1336  std::vector<DetId> channels = fObject.getAllChannels();
1337  std::sort(channels.begin(), channels.end(), DetIdLess());
1338  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1339  const HcalPedestalWidth* item = fObject.getValues(*channel);
1340  if (item) {
1341  dumpId(fOutput, *channel);
1342  sprintf(buffer,
1343  " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
1344  item->getSigma(0, 0),
1345  item->getSigma(0, 1),
1346  item->getSigma(0, 2),
1347  item->getSigma(0, 3),
1348  item->getSigma(1, 0),
1349  item->getSigma(1, 1),
1350  item->getSigma(1, 2),
1351  item->getSigma(1, 3),
1352  item->getSigma(2, 0),
1353  item->getSigma(2, 1),
1354  item->getSigma(2, 2),
1355  item->getSigma(2, 3),
1356  item->getSigma(3, 0),
1357  item->getSigma(3, 1),
1358  item->getSigma(3, 2),
1359  item->getSigma(3, 3),
1360  channel->rawId());
1361  fOutput << buffer;
1362  }
1363  }
1364  return true;
1365 }
1366 
1367 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1368 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalQIEData* fObject) {
1369  char buffer[1024];
1370  while (fInput.getline(buffer, 1024)) {
1371  if (buffer[0] == '#')
1372  continue; //ignore comment
1373  std::vector<std::string> items = splitString(std::string(buffer));
1374  if (items.empty())
1375  continue;
1376  if (items[0] == "SHAPE") { // basic shape
1377  //this shape keyword is obsolete
1378  } else { // QIE parameters
1379  if (items.size() < 36) {
1380  edm::LogWarning("Format Error") << "Bad line: " << buffer
1381  << "\n line must contain 36 items: eta, phi, depth, subdet, 4 capId x 4 Ranges "
1382  "x offsets, 4 capId x 4 Ranges x slopes"
1383  << std::endl;
1384  continue;
1385  }
1386  DetId id = getId(items);
1387  fObject->sort();
1388  // try {
1389  // fObject->getCoder (id);
1390  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1391  // }
1392  // catch (cms::Exception& e) {
1393  HcalQIECoder coder(id.rawId());
1394  int index = 4;
1395  for (unsigned capid = 0; capid < 4; capid++) {
1396  for (unsigned range = 0; range < 4; range++) {
1397  coder.setOffset(capid, range, atof(items[index++].c_str()));
1398  }
1399  }
1400  for (unsigned capid = 0; capid < 4; capid++) {
1401  for (unsigned range = 0; range < 4; range++) {
1402  coder.setSlope(capid, range, atof(items[index++].c_str()));
1403  }
1404  }
1405 
1406  fObject->addCoder(coder);
1407  // }
1408  }
1409  }
1410  fObject->sort();
1411  return true;
1412 }
1413 
1414 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalQIEData& fObject) {
1415  char buffer[1024];
1416 
1417  fOutput << "# QIE data" << std::endl;
1418  sprintf(buffer,
1419  "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
1420  "eta",
1421  "phi",
1422  "dep",
1423  "det",
1424  "4 x offsets cap0",
1425  "4 x offsets cap1",
1426  "4 x offsets cap2",
1427  "4 x offsets cap3",
1428  "4 x slopes cap0",
1429  "4 x slopes cap1",
1430  "4 x slopes cap2",
1431  "4 x slopes cap3");
1432  fOutput << buffer;
1433  std::vector<DetId> channels = fObject.getAllChannels();
1434  std::sort(channels.begin(), channels.end(), DetIdLess());
1435  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1436  const HcalQIECoder* coder = fObject.getCoder(*channel);
1437  dumpId(fOutput, *channel);
1438  for (unsigned capid = 0; capid < 4; capid++) {
1439  for (unsigned range = 0; range < 4; range++) {
1440  sprintf(buffer, " %8.5f", coder->offset(capid, range));
1441  fOutput << buffer;
1442  }
1443  }
1444  for (unsigned capid = 0; capid < 4; capid++) {
1445  for (unsigned range = 0; range < 4; range++) {
1446  sprintf(buffer, " %8.5f", coder->slope(capid, range));
1447  fOutput << buffer;
1448  }
1449  }
1450  fOutput << std::endl;
1451  }
1452  return true;
1453 }
1454 
1455 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1456 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalCalibrationQIEData* fObject) {
1457  char buffer[1024];
1458  while (fInput.getline(buffer, 1024)) {
1459  if (buffer[0] == '#')
1460  continue; //ignore comment
1461  std::vector<std::string> items = splitString(std::string(buffer));
1462  if (items.size() < 36) {
1463  edm::LogWarning("Format Error") << "Bad line: " << buffer
1464  << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values"
1465  << std::endl;
1466  continue;
1467  }
1468  DetId id = getId(items);
1469  fObject->sort();
1470  // try {
1471  // fObject->getCoder (id);
1472  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1473  // }
1474  // catch (cms::Exception& e) {
1475  HcalCalibrationQIECoder coder(id.rawId());
1476  int index = 4;
1477  float values[32];
1478  for (unsigned bin = 0; bin < 32; bin++) {
1479  values[bin] = atof(items[index++].c_str());
1480  }
1481  coder.setMinCharges(values);
1482  fObject->addCoder(coder);
1483  // }
1484  }
1485  fObject->sort();
1486  return true;
1487 }
1488 
1489 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
1490  char buffer[1024];
1491  fOutput << "# QIE data in calibration mode" << std::endl;
1492  sprintf(buffer, "# %15s %15s %15s %15s %288s\n", "eta", "phi", "dep", "det", "32 x charges");
1493  fOutput << buffer;
1494  std::vector<DetId> channels = fObject.getAllChannels();
1495  std::sort(channels.begin(), channels.end(), DetIdLess());
1496  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1497  const HcalCalibrationQIECoder* coder = fObject.getCoder(*channel);
1498  if (coder) {
1499  dumpId(fOutput, *channel);
1500  const float* lowEdge = coder->minCharges();
1501  for (unsigned bin = 0; bin < 32; bin++) {
1502  sprintf(buffer, " %8.5f", lowEdge[bin]);
1503  fOutput << buffer;
1504  }
1505  fOutput << std::endl;
1506  }
1507  }
1508  return true;
1509 }
1510 
1511 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1512 namespace HcalDbASCIIIO {
1513  template <>
1514  std::unique_ptr<HcalElectronicsMap> createObject<HcalElectronicsMap>(std::istream& fInput) {
1515  HcalElectronicsMapAddons::Helper fObjectHelper;
1516  char buffer[1024];
1517  while (fInput.getline(buffer, 1024)) {
1518  if (buffer[0] == '#')
1519  continue; //ignore comment
1520  std::vector<std::string> items = splitString(std::string(buffer));
1521  if (items.size() < 12) {
1522  if (items.empty())
1523  continue; // no warning here
1524  if (items.size() < 9) {
1525  edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
1526  continue;
1527  }
1528  if (items[8] == "NA" || items[8] == "NT") {
1529  while (items.size() < 12)
1530  items.push_back(""); // don't worry here
1531  } else if (items[8] == "HT") {
1532  if (items.size() == 11)
1533  items.push_back("");
1534  else {
1535  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
1536  << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber "
1537  "fiberchan subdet=HT ieta iphi";
1538  continue;
1539  }
1540  } else {
1541  edm::LogError("MapFormat")
1542  << "HcalElectronicsMap-> Bad line: " << buffer
1543  << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
1544  continue;
1545  }
1546  }
1547  int crate = atoi(items[1].c_str());
1548  int slot = atoi(items[2].c_str());
1549  int top = 1;
1550  if (items[3] == "b")
1551  top = 0;
1552  int dcc = atoi(items[4].c_str());
1553  int spigot = atoi(items[5].c_str());
1554  HcalElectronicsId elId;
1555  if (items[3][0] == 'u') { // uTCA!
1556  int fiber = atoi(items[6].c_str());
1557  int fiberCh = atoi(items[7].c_str());
1558  bool isTrig = (items[8] == "HT" || items[8] == "NT");
1559  elId = HcalElectronicsId(crate, slot, fiber, fiberCh, isTrig);
1560  } else if (items[8] == "HT" || items[8] == "NT") {
1561  int slb = atoi(items[6].c_str());
1562  int slbCh = atoi(items[7].c_str());
1563  elId = HcalElectronicsId(slbCh, slb, spigot, dcc, crate, slot, top);
1564  } else {
1565  int fiber = atoi(items[6].c_str());
1566  int fiberCh = atoi(items[7].c_str());
1567 
1568  elId = HcalElectronicsId(fiberCh, fiber, spigot, dcc);
1569  elId.setHTR(crate, slot, top);
1570  }
1571 
1572  // first, handle undefined cases
1573  if (items[8] == "NA") { // undefined channel
1574  fObjectHelper.mapEId2chId(elId, DetId(HcalDetId::Undefined));
1575  } else if (items[8] == "NT") { // undefined trigger channel
1576  fObjectHelper.mapEId2tId(elId, DetId(HcalTrigTowerDetId::Undefined));
1577  } else {
1579  if (converter.isHcalDetId() or converter.isHcalCalibDetId() or converter.isHcalZDCDetId()) {
1580  fObjectHelper.mapEId2chId(elId, converter.getId());
1581  } else if (converter.isHcalTrigTowerDetId()) {
1582  fObjectHelper.mapEId2tId(elId, converter.getId());
1583  } else {
1584  edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: " << items[8] << '/' << items[9]
1585  << '/' << items[10] << '/' << items[11] << std::endl;
1586  }
1587  }
1588  }
1589  auto fObject = std::make_unique<HcalElectronicsMap>(fObjectHelper);
1590  return fObject;
1591  }
1592 } // namespace HcalDbASCIIIO
1593 
1594 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalElectronicsMap& fObject) {
1595  std::vector<HcalElectronicsId> eids = fObject.allElectronicsId();
1596  char buf[1024];
1597  // changes by Jared, 6.03.09/(included 25.03.09)
1598  // sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
1599  sprintf(buf,
1600  "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
1601  "i",
1602  "cr",
1603  "sl",
1604  "tb",
1605  "dcc",
1606  "spigot",
1607  "fiber/slb",
1608  "fibcha/slbcha",
1609  "subdet",
1610  "ieta",
1611  "iphi",
1612  "depth");
1613  fOutput << buf << std::endl;
1614 
1615  for (unsigned i = 0; i < eids.size(); i++) {
1616  HcalElectronicsId eid = eids[i];
1617  if (eid.isTriggerChainId()) {
1618  DetId trigger = fObject.lookupTrigger(eid);
1619  if (trigger.rawId()) {
1621  if (eid.isVMEid()) {
1622  // changes by Jared, 6.03.09/(included 25.03.09)
1623  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1624  sprintf(
1625  buf,
1626  " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1627  // i,
1628  converter.getId().rawId(),
1629  // changes by Jared, 6.03.09/(included 25.03.09)
1630  // eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1631  eid.readoutVMECrateId(),
1632  eid.htrSlot(),
1633  eid.htrTopBottom() > 0 ? 't' : 'b',
1634  eid.dccid(),
1635  eid.spigot(),
1636  eid.slbSiteNumber(),
1637  eid.slbChannelIndex(),
1638  converter.getFlavor().c_str(),
1639  converter.getField1().c_str(),
1640  converter.getField2().c_str(),
1641  converter.getField3().c_str());
1642  fOutput << buf << std::endl;
1643  } else if (eid.isUTCAid()) {
1644  sprintf(buf,
1645  " %7X %3d %3d u %4d %7d %10d %14d %7s %5s %5s %6s",
1646  converter.getId().rawId(),
1647  // eid.crateId(), eid.slot(), 0, eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1648  eid.crateId(),
1649  eid.slot(),
1650  0,
1651  0,
1652  eid.fiberIndex(),
1653  eid.fiberChanId(),
1654  converter.getFlavor().c_str(),
1655  converter.getField1().c_str(),
1656  converter.getField2().c_str(),
1657  converter.getField3().c_str());
1658  fOutput << buf << std::endl;
1659  } else {
1660  sprintf(buf, "NOT SUPPORTED!");
1661  fOutput << buf << std::endl;
1662  }
1663  }
1664  } else {
1665  DetId channel = fObject.lookup(eid);
1666  if (channel.rawId()) {
1668  if (eid.isVMEid()) {
1669  // changes by Jared, 6.03.09/(included 25.03.09)
1670  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1671  sprintf(buf,
1672  " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1673  // i,
1674  converter.getId().rawId(),
1675  eid.readoutVMECrateId(),
1676  eid.htrSlot(),
1677  eid.htrTopBottom() > 0 ? 't' : 'b',
1678  eid.dccid(),
1679  eid.spigot(),
1680  eid.fiberIndex(),
1681  eid.fiberChanId(),
1682  converter.getFlavor().c_str(),
1683  converter.getField1().c_str(),
1684  converter.getField2().c_str(),
1685  converter.getField3().c_str());
1686  } else {
1687  sprintf(buf,
1688  " %7X %3d %3d u %4d %7d %10d %14d %7s %5s %5s %6s",
1689  // i,
1690  converter.getId().rawId(),
1691  // eid.crateId(), eid.slot(), 0, eid.slot(), eid.fiberIndex(), eid.fiberChanId(),
1692  eid.crateId(),
1693  eid.slot(),
1694  0,
1695  0,
1696  eid.fiberIndex(),
1697  eid.fiberChanId(),
1698  converter.getFlavor().c_str(),
1699  converter.getField1().c_str(),
1700  converter.getField2().c_str(),
1701  converter.getField3().c_str());
1702  }
1703  fOutput << buf << std::endl;
1704  }
1705  }
1706  }
1707  return true;
1708 }
1709 
1710 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalLutMetadata* fObject) {
1711  if (!fObject)
1712  return false; //fObject = new HcalLutMetadata;
1713  char buffer[1024];
1714  while (fInput.getline(buffer, 1024)) {
1715  if (buffer[0] == '#')
1716  continue; //ignore comment
1717  std::vector<std::string> items = splitString(std::string(buffer));
1718  if (items.empty())
1719  continue; // blank line
1720  // now get non-channel data
1721  if (items.size() > 1 && items[0].find("RctLsb") != std::string::npos) {
1722  fObject->setRctLsb(atof(items[1].c_str()));
1723  continue;
1724  }
1725  if (items.size() > 1 && items[0].find("Gain") != std::string::npos) {
1726  fObject->setNominalGain(atof(items[1].c_str()));
1727  continue;
1728  }
1729  // now proceeed to per-channel data
1730  if (items.size() < 7) {
1731  edm::LogWarning("Format Error")
1732  << "Bad line: " << buffer
1733  << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold"
1734  << std::endl;
1735  continue;
1736  }
1737  DetId id = getId(items);
1738 
1739  HcalLutMetadatum* fCondObject =
1740  new HcalLutMetadatum(id, atof(items[4].c_str()), atoi(items[5].c_str()), atoi(items[6].c_str()));
1741  fObject->addValues(*fCondObject);
1742  delete fCondObject;
1743  }
1744  return true;
1745 }
1746 
1747 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalLutMetadata& fObject) {
1748  char buffer[1024];
1749  const float _rctLsb = fObject.getRctLsb();
1750  const float _gain = fObject.getNominalGain();
1751  sprintf(buffer, "# %20s\n", "Non-channel data");
1752  fOutput << buffer;
1753  sprintf(buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
1754  fOutput << buffer;
1755  sprintf(buffer, "%8s %8.5f\n", "Gain", _gain);
1756  fOutput << buffer;
1757  sprintf(buffer,
1758  "# %15s %15s %15s %15s %8s %15s %19s %10s\n",
1759  "eta",
1760  "phi",
1761  "dep",
1762  "det",
1763  "Rcalib",
1764  "LutGranularity",
1765  "OutputLutThreshold",
1766  "DetId");
1767  fOutput << buffer;
1768  std::vector<DetId> channels = fObject.getAllChannels();
1769  std::sort(channels.begin(), channels.end(), DetIdLess());
1770  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
1771  const float _rCalib = fObject.getValues(*channel)->getRCalib();
1772  const uint8_t _lutGranularity = fObject.getValues(*channel)->getLutGranularity();
1773  const uint8_t _outputLutThreshold = fObject.getValues(*channel)->getOutputLutThreshold();
1774  dumpId(fOutput, *channel);
1775  sprintf(buffer, " %8.5f %15d %19d %10X\n", _rCalib, _lutGranularity, _outputLutThreshold, channel->rawId());
1776  fOutput << buffer;
1777  }
1778  return true;
1779 }
1780 
1781 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1782 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues* fObject) {
1783  if (!fObject)
1784  return false; //fObject = new HcalDcsValues;
1786  while (getline(fInput, buffer)) {
1787  if (buffer.at(0) == '#')
1788  continue; //ignore comment
1789  std::vector<std::string> items = splitString(buffer);
1790  if (items.empty())
1791  continue; // blank line
1792 
1793  if (items.size() < 9) {
1794  edm::LogWarning("Format Error") << "Bad line: " << buffer
1795  << "\n line must contain 9 items: subDet, side_ring, slice, type, subChannel, "
1796  "LS, Value, UpperLimit, LowerLimit"
1797  << std::endl;
1798  continue;
1799  }
1800 
1801  HcalOtherSubdetector subd;
1802  int sidering;
1803  unsigned int slice, subchan;
1804  switch (items[0].at(1)) {
1805  case 'B':
1806  subd = HcalDcsBarrel;
1807  break;
1808  case 'E':
1809  subd = HcalDcsEndcap;
1810  break;
1811  case 'F':
1812  subd = HcalDcsForward;
1813  break;
1814  case 'O':
1815  subd = HcalDcsOuter;
1816  break;
1817  default:
1818  continue;
1819  }
1820  //from_string<int>(subd, items[0], std::dec);
1821  from_string<int>(sidering, items[1], std::dec);
1822  from_string<unsigned int>(slice, items[2], std::dec);
1823  //from_string<int>(ty, items[3], std::dec);
1824  from_string<unsigned int>(subchan, items[4], std::dec);
1825 
1826  HcalDcsDetId newId(subd, sidering, slice, HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
1827 
1828  int LS;
1829  float val, upper, lower;
1830  from_string<int>(LS, items[5], std::dec);
1831  from_string<float>(val, items[6], std::dec);
1832  from_string<float>(upper, items[7], std::dec);
1833  from_string<float>(lower, items[8], std::dec);
1834 
1835  HcalDcsValue newVal(newId.rawId(), LS, val, upper, lower);
1836  // std::cout << buffer << '\n';
1837  // std::cout << subd << ' ' << sidering << ' ' << slice << ' '
1838  // << ty << ' ' << subchan << ' ' << LS << ' '
1839  // << val << ' ' << upper << ' ' << lower << '\n';
1840  // std::cout << newId ;
1841  if (!(fObject->addValue(newVal))) {
1842  edm::LogWarning("Data Error") << "Data from line " << buffer << "\nwas not added to the HcalDcsValues object."
1843  << std::endl;
1844  }
1845  // std::cout << std::endl;
1846  }
1847  fObject->sortAll();
1848  return true;
1849 }
1850 
1851 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, HcalDcsValues const& fObject) {
1852  fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
1853  for (int subd = HcalDcsValues::HcalHB; subd <= HcalDcsValues::HcalHF; ++subd) {
1854  // std::cout << "subd: " << subd << '\n';
1856  for (HcalDcsValues::DcsSet::const_iterator val = vals.begin(); val != vals.end(); ++val) {
1857  HcalDcsDetId valId(val->DcsId());
1858 
1859  switch (valId.subdet()) {
1860  case HcalDcsBarrel:
1861  fOutput << "HB ";
1862  break;
1863  case HcalDcsEndcap:
1864  fOutput << "HE ";
1865  break;
1866  case HcalDcsOuter:
1867  fOutput << "HO ";
1868  break;
1869  case HcalDcsForward:
1870  fOutput << "HF ";
1871  break;
1872  default:
1873  fOutput << valId.subdet() << ' ';
1874  }
1875 
1876  if (valId.subdet() == HcalDcsOuter)
1877  fOutput << valId.ring() << ' ';
1878  else
1879  fOutput << valId.zside() << ' ';
1880 
1881  fOutput << valId.slice() << ' ' << valId.typeString(valId.type()) << ' ' << valId.subchannel() << ' ';
1882  fOutput << val->LS() << ' ' << val->getValue() << ' ' << val->getUpperLimit() << ' ' << val->getLowerLimit()
1883  << ' ';
1884  fOutput << std::hex << val->DcsId() << std::dec << '\n';
1885 
1886  // std::cout << valId << ' '
1887  // << valId.subdet() << ' '
1888  // << val->LS() << ' ' << val->getValue() << ' '
1889  // << val->getUpperLimit() << ' ' << val->getLowerLimit()
1890  // << std::endl;
1891  }
1892  }
1893 
1894  return true;
1895 }
1896 
1897 // Format of the ASCII file:
1898 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1899 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1900 namespace HcalDbASCIIIO {
1901  template <>
1902  std::unique_ptr<HcalDcsMap> createObject<HcalDcsMap>(std::istream& fInput) {
1903  char buffer[1024];
1904  HcalDcsMapAddons::Helper fObjectHelper;
1905  while (fInput.getline(buffer, 1024)) {
1906  if (buffer[0] == '#')
1907  continue; //ignore comment
1908  std::vector<std::string> items = splitString(std::string(buffer));
1909  if (items.size() < 8) {
1910  if (items.empty())
1911  continue; // no warning here
1912  else {
1913  edm::LogError("MapFormat")
1914  << "HcalDcsMap-> Bad line: " << buffer
1915  << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
1916  continue;
1917  }
1918  }
1919  int ring = atoi(items[1].c_str());
1920  unsigned int slice = atoi(items[2].c_str());
1921  unsigned int subchannel = atoi(items[3].c_str());
1924  if (items[4].find("CALIB") != std::string::npos) {
1925  subdet = HcalCalibration;
1926  } else if (items[4].find("HB") != std::string::npos) {
1927  subdet = HcalDcsBarrel;
1928  } else if (items[4].find("HE") != std::string::npos) {
1929  subdet = HcalDcsEndcap;
1930  } else if (items[4].find("HO") != std::string::npos) {
1931  subdet = HcalDcsOuter;
1932  } else if (items[4].find("HF") != std::string::npos) {
1933  subdet = HcalDcsForward;
1934  } else {
1935  edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
1936  continue;
1937  }
1938  HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
1940  HcalDetId id(0);
1941  if (converter.isHcalDetId()) {
1942  id = converter.getId();
1943  } else {
1944  edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: " << items[4] << '/' << items[5]
1945  << '/' << items[6] << '/' << items[7] << std::endl;
1946  continue;
1947  }
1948  fObjectHelper.mapGeomId2DcsId(id, dcsId);
1949  }
1950  auto fObject = std::make_unique<HcalDcsMap>(fObjectHelper);
1951  return fObject;
1952  }
1953 } // namespace HcalDbASCIIIO
1954 
1955 // Format of the ASCII file:
1956 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1957 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1958 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalDcsMap& fObject) {
1959  char buf[1024];
1960  sprintf(buf,
1961  "# %7s %10s %6s %8s %7s %5s %5s %6s",
1962  "i",
1963  "side_ring",
1964  "slice",
1965  "subchan",
1966  "subdet",
1967  "ieta",
1968  "iphi",
1969  "depth");
1970  fOutput << buf << std::endl;
1972  unsigned int line_counter = 0;
1973  for (_line = fObject.beginById(); _line != fObject.endById(); ++_line) {
1974  HcalDcsDetId dcsId = _line.getHcalDcsDetId();
1975  //std::string _dcs_type = "DCSUNKNOWN";
1976  HcalText2DetIdConverter _converter(_line.getHcalDetId());
1977  sprintf(buf,
1978  " %8X %10d %6d %8d %7s %5s %5s %6s",
1979  line_counter,
1980  dcsId.ring(), // contains zside() already
1981  dcsId.slice(),
1982  dcsId.subchannel(),
1983  _converter.getFlavor().c_str(),
1984  _converter.getField1().c_str(),
1985  _converter.getField2().c_str(),
1986  _converter.getField3().c_str());
1987  fOutput << buf << std::endl;
1988  ++line_counter;
1989  }
1990  return true;
1991 }
1992 
1993 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalFlagHFDigiTimeParams* fObject) {
1994  if (!fObject)
1995  return false; //fObject = new HcalFlagHFDigiTimeParams();
1996  char buffer[1024];
1997  while (fInput.getline(buffer, 1024)) {
1998  if (buffer[0] == '#')
1999  continue; //ignore comment
2000  std::vector<std::string> items = splitString(std::string(buffer));
2001  if (items.empty())
2002  continue; // blank line
2003  if (items.size() != 9) {
2004  edm::LogWarning("Format Error")
2005  << "Bad line: " << buffer
2006  << "\n line must contain at 9 least items: eta, phi, depth, subdet, firstSample, samplesToAdd, ExpectedPeak, "
2007  "MinEnergy, and a set of comma-separated coefficients"
2008  << std::endl;
2009  continue;
2010  }
2011  // expects (ieta, iphi, depth, subdet) as first four arguments
2013  std::vector<double> coef = splitStringToDoubleByComma(items[8]);
2014 
2015  HcalFlagHFDigiTimeParam* fCondObject = new HcalFlagHFDigiTimeParam(id,
2016  atoi(items[4].c_str()), //firstSample
2017  atoi(items[5].c_str()), //samplesToAdd
2018  atoi(items[6].c_str()), //expectedPeak
2019  atof(items[7].c_str()), // minEThreshold
2020  coef // coefficients
2021  );
2022  fObject->addValues(*fCondObject);
2023  delete fCondObject;
2024  }
2025  return true;
2026 } // getObject (HcalFlagHFDigiTime)
2027 
2028 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalFlagHFDigiTimeParams& fObject) {
2029  char buffer[1024];
2030  sprintf(buffer,
2031  "# %15s %15s %15s %15s %15s %15s %15s %15s %30s\n",
2032  "eta",
2033  "phi",
2034  "dep",
2035  "det",
2036  "FirstSample",
2037  "SamplesToAdd",
2038  "ExpectedPeak",
2039  "MinEnergy",
2040  "Coefficients");
2041  fOutput << buffer;
2042  std::vector<DetId> channels = fObject.getAllChannels();
2043  std::sort(channels.begin(), channels.end(), DetIdLess());
2044  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2045  // Dump out channel (ieta,iphi,depth,subdet) info
2046  HcalDbASCIIIO::dumpId(fOutput, *channel);
2047  // Dump out values for channel
2048  sprintf(buffer,
2049  " %15u %15u %15u %15f",
2050  fObject.getValues(*channel)->HFdigiflagFirstSample(),
2051  fObject.getValues(*channel)->HFdigiflagSamplesToAdd(),
2052  fObject.getValues(*channel)->HFdigiflagExpectedPeak(),
2053  fObject.getValues(*channel)->HFdigiflagMinEThreshold());
2054 
2055  fOutput << buffer; // dump flag reco values to buffer
2056  fOutput << " "; // simple spacer
2057 
2058  std::vector<double> coef = fObject.getValues(*channel)->HFdigiflagCoefficients();
2059  for (std::vector<double>::size_type x = 0; x < coef.size(); ++x) {
2060  // dump comma-separated list of coefficients
2061  fOutput << coef[x];
2062  if (x < coef.size() - 1) // add commas where necessary
2063  fOutput << ",";
2064  }
2065  sprintf(buffer, "\n");
2066  fOutput << buffer;
2067  }
2068  return true;
2069 }
2070 
2071 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2072 namespace HcalDbASCIIIO {
2073  template <>
2074  std::unique_ptr<HcalFrontEndMap> createObject<HcalFrontEndMap>(std::istream& fInput) {
2075  char buffer[1024];
2076  HcalFrontEndMapAddons::Helper fObjectHelper;
2077  unsigned int all(0), good(0);
2078  while (fInput.getline(buffer, 1024)) {
2079  ++all;
2080  if (buffer[0] == '#')
2081  continue; //ignore comment
2082  std::vector<std::string> items = splitString(std::string(buffer));
2083  if (items.size() != 6) {
2084  edm::LogError("Format Error") << "HcalFrontEndMap-> line ignored: " << buffer;
2085  continue;
2086  }
2087  ++good;
2089  int rm = atoi(items[5].c_str());
2090  fObjectHelper.loadObject(id, rm, items[4]);
2091  }
2092  edm::LogInfo("MapFormat") << "HcalFrontEndMap:: processed " << good << " records in " << all << " record"
2093  << std::endl;
2094  auto fObject = std::make_unique<HcalFrontEndMap>(fObjectHelper);
2095  return fObject;
2096  }
2097 } // namespace HcalDbASCIIIO
2098 
2099 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalFrontEndMap& fObject) {
2100  char buffer[1024];
2101  sprintf(buffer, "# %15s %15s %15s %15s %8s %8s\n", "eta", "phi", "dep", "det", "rbx", "rm");
2102  fOutput << buffer;
2103 
2104  std::vector<DetId> channels = fObject.allDetIds();
2105  std::sort(channels.begin(), channels.end(), DetIdLess());
2106  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2107  const std::string rbx = fObject.lookupRBX(*channel);
2108  const int rm = fObject.lookupRM(*channel);
2109  dumpId(fOutput, *channel);
2110  sprintf(buffer, " %8s %8d \n", rbx.c_str(), rm);
2111  fOutput << buffer;
2112  }
2113  return true;
2114 }
2115 
2116 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2117 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalSiPMParameters* fObject) {
2118  if (!fObject)
2119  return false;
2120  char buffer[1024];
2121  while (fInput.getline(buffer, 1024)) {
2122  if (buffer[0] == '#')
2123  continue; //ignore comment
2124  std::vector<std::string> items = splitString(std::string(buffer));
2125  if (items.empty())
2126  continue; // blank line
2127  if (items.size() < 9) {
2128  edm::LogWarning("Format Error") << "Bad line: " << buffer
2129  << "\n line must contain 9 items: eta, phi, depth, subdet, 5x values"
2130  << std::endl;
2131  continue;
2132  }
2134 
2136  atoi(items[4].c_str()),
2137  atof(items[5].c_str()),
2138  atof(items[6].c_str()),
2139  atoi(items[7].c_str()),
2140  atof(items[8].c_str()));
2141  fObject->addValues(*obj);
2142  delete obj;
2143  }
2144  return true;
2145 }
2146 
2147 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalSiPMParameters& fObject) {
2148  char buffer[1024];
2149  sprintf(buffer,
2150  "# %15s %15s %15s %15s %8s %15s %15s %8s %15s\n",
2151  "eta",
2152  "phi",
2153  "dep",
2154  "det",
2155  "type",
2156  "fcByPE",
2157  "darkCurrent",
2158  "auxi1",
2159  "auxi2");
2160  fOutput << buffer;
2161  std::vector<DetId> channels = fObject.getAllChannels();
2162  std::sort(channels.begin(), channels.end(), DetIdLess());
2163  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2164  const int type = fObject.getValues(*channel)->getType();
2165  const float fcByPE = fObject.getValues(*channel)->getFCByPE();
2166  const float darkC = fObject.getValues(*channel)->getDarkCurrent();
2167  const int auxi1 = fObject.getValues(*channel)->getauxi1();
2168  const float auxi2 = fObject.getValues(*channel)->getauxi2();
2169  HcalDbASCIIIO::dumpId(fOutput, *channel);
2170  sprintf(buffer, " %8d %15.6f %15.6f %8d %15.6f\n", type, fcByPE, darkC, auxi1, auxi2);
2171  fOutput << buffer;
2172  }
2173  return true;
2174 }
2175 
2176 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2177 namespace HcalDbASCIIIO {
2178  template <>
2179  std::unique_ptr<HcalSiPMCharacteristics> createObject<HcalSiPMCharacteristics>(std::istream& fInput) {
2180  char buffer[1024];
2182  unsigned int all(0), good(0);
2183  while (fInput.getline(buffer, 1024)) {
2184  ++all;
2185  if (buffer[0] == '#')
2186  continue; //ignore comment
2187  std::vector<std::string> items = splitString(std::string(buffer));
2188  if (items.size() != 8) {
2189  edm::LogError("MapFormat") << "HcalSiPMCharacteristics-> line ignored: " << buffer;
2190  continue;
2191  }
2192  ++good;
2193  // std::cout << "HcalSiPMCharacteristics-> processing line: " << buffer << std::endl;
2194  int type = atoi(items[0].c_str());
2195  int pixels = atoi(items[1].c_str());
2196  float parL0 = atof(items[2].c_str());
2197  float parL1 = atof(items[3].c_str());
2198  float parL2 = atof(items[4].c_str());
2199  float cTalk = atof(items[5].c_str());
2200  int auxi1 = atoi(items[6].c_str());
2201  float auxi2 = atof(items[7].c_str());
2202  fObjectHelper.loadObject(type, pixels, parL0, parL1, parL2, cTalk, auxi1, auxi2);
2203  }
2204  edm::LogInfo("MapFormat") << "HcalSiPMCharacteristics:: processed " << good << " records in " << all << " record"
2205  << std::endl;
2206  auto fObject = std::make_unique<HcalSiPMCharacteristics>(fObjectHelper);
2207  return fObject;
2208  }
2209 } // namespace HcalDbASCIIIO
2210 
2211 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalSiPMCharacteristics& fObject) {
2212  char buffer[1024];
2213  sprintf(buffer,
2214  "# %8s %8s %15s %15s %15s %15s %8s %15s\n",
2215  "type",
2216  "pixels",
2217  "parLin1",
2218  "parLin2",
2219  "parLin3",
2220  "crossTalk",
2221  "auxi1",
2222  "auxi2");
2223  fOutput << buffer;
2224 
2225  unsigned int size = fObject.getTypes();
2226  for (unsigned int k = 0; k < size; ++k) {
2227  const int type = fObject.getType(k);
2228  const int pixels = fObject.getPixels(type);
2229  const std::vector<float> pars = fObject.getNonLinearities(type);
2230  const float cTalk = fObject.getCrossTalk(type);
2231  const int auxi1 = fObject.getAuxi1(type);
2232  const float auxi2 = fObject.getAuxi2(type);
2233  const float par0 = (!pars.empty()) ? pars[0] : 0;
2234  const float par1 = (pars.size() > 1) ? pars[1] : 0;
2235  const float par2 = (pars.size() > 2) ? pars[2] : 0;
2236  sprintf(
2237  buffer, " %8d %8d %15.6e %15.6e %15.6e %15.6f %8d %15.6f\n", type, pixels, par0, par1, par2, cTalk, auxi1, auxi2);
2238  fOutput << buffer;
2239  }
2240  return true;
2241 }
2242 
2243 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2244 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalTPChannelParameters* fObject) {
2245  if (!fObject)
2246  return false;
2247  char buffer[1024];
2248  while (fInput.getline(buffer, 1024)) {
2249  if (buffer[0] == '#')
2250  continue; //ignore comment
2251  std::vector<std::string> items = splitString(std::string(buffer));
2252  if (items.empty())
2253  continue; // blank line
2254  if (items.size() < 8) {
2255  edm::LogWarning("Format Error") << "Bad line: " << buffer
2256  << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
2257  << std::endl;
2258  continue;
2259  }
2261 
2263  id.rawId(), atoi(items[4].c_str()), atoi(items[5].c_str()), atoi(items[6].c_str()), atoi(items[7].c_str()));
2264  fObject->addValues(*obj);
2265  delete obj;
2266  }
2267  return true;
2268 }
2269 
2270 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalTPChannelParameters& fObject) {
2271  char buffer[1024];
2272  sprintf(buffer,
2273  "# %15s %15s %15s %15s %15s %15s %15s %15s\n",
2274  "eta",
2275  "phi",
2276  "dep",
2277  "det",
2278  "Mask",
2279  "FGBitInfo",
2280  "auxi1",
2281  "auxi2");
2282  fOutput << buffer;
2283  std::vector<DetId> channels = fObject.getAllChannels();
2284  std::sort(channels.begin(), channels.end(), DetIdLess());
2285  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2286  const uint32_t mask = fObject.getValues(*channel)->getMask();
2287  const uint32_t fgBitInfo = fObject.getValues(*channel)->getFGBitInfo();
2288  const int auxi1 = fObject.getValues(*channel)->getauxi1();
2289  const int auxi2 = fObject.getValues(*channel)->getauxi2();
2290  HcalDbASCIIIO::dumpId(fOutput, *channel);
2291  sprintf(buffer, " %15d %15d %15d %15d \n", mask, fgBitInfo, auxi1, auxi2);
2292  fOutput << buffer;
2293  }
2294  return true;
2295 }
2296 
2297 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2298 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalTPParameters* fObject) {
2299  char buffer[1024];
2300  unsigned int all(0), good(0);
2301  while (fInput.getline(buffer, 1024)) {
2302  ++all;
2303  if (buffer[0] == '#')
2304  continue; //ignore comment
2305  std::vector<std::string> items = splitString(std::string(buffer));
2306  if (items.size() != 6) {
2307  edm::LogError("Format Error") << "HcalTPParameters-> line ignored: " << buffer;
2308  continue;
2309  }
2310  ++good;
2311  // std::cout << "HcalTPParameters-> processing line: " << buffer << std::endl;
2312  int version = atoi(items[0].c_str());
2313  int adcCut = atoi(items[1].c_str());
2314  uint64_t tdcMask = strtoull(items[2].c_str(), nullptr, 16);
2315  uint32_t tbits = atoi(items[3].c_str());
2316  int auxi1 = atoi(items[4].c_str());
2317  int auxi2 = atoi(items[5].c_str());
2318  fObject->loadObject(version, adcCut, tdcMask, tbits, auxi1, auxi2);
2319  break;
2320  }
2321  edm::LogInfo("MapFormat") << "HcalTPParameters:: processed " << good << " records in " << all << " record"
2322  << std::endl;
2323  return true;
2324 }
2325 
2326 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalTPParameters& fObject) {
2327  char buffer[1024];
2328  sprintf(
2329  buffer, "# %15s %15s %16s %15s %15s %15s\n", "FGAlgo_HBHE", "ADCThrHF", "TDCMaskHF", "STBitsHF", "auxi1", "auxi2");
2330  fOutput << buffer;
2331 
2332  const int version = fObject.getFGVersionHBHE();
2333  const int adcCut = fObject.getADCThresholdHF();
2334  const uint64_t tdcMask = fObject.getTDCMaskHF();
2335  const uint32_t tbits = fObject.getHFTriggerInfo();
2336  const int auxi1 = fObject.getAuxi1();
2337  const int auxi2 = fObject.getAuxi2();
2338 
2339  sprintf(buffer, " %15d %15d %16jx %15x %15d %15d\n", version, adcCut, tdcMask, tbits, auxi1, auxi2);
2340  fOutput << buffer;
2341 
2342  return true;
2343 }
2344 
2345 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2346 
2347 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalCalibrationsSet& fObject) {
2348  char buffer[1024];
2349  sprintf(buffer,
2350  "# %15s %15s %15s %15s %8s %8s %8s %8s %11s %11s %11s %11s %9s %9s %9s %9s %10s\n",
2351  "eta",
2352  "phi",
2353  "dep",
2354  "det",
2355  "pedcap0",
2356  "pedcap1",
2357  "pedcap2",
2358  "pedcap3",
2359  "effpedcap0",
2360  "effpedcap1",
2361  "effpedcap2",
2362  "effpedcap3",
2363  "gaincap0",
2364  "gaincap1",
2365  "gaincap2",
2366  "gaincap3",
2367  "DetId");
2368  fOutput << buffer;
2369 
2370  std::vector<DetId> channels = fObject.getAllChannels();
2371  std::sort(channels.begin(), channels.end(), DetIdLess());
2372  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2373  dumpId(fOutput, *channel);
2374  const HcalCalibrations& values = fObject.getCalibrations(*channel);
2375  sprintf(buffer,
2376  " %8.5f %8.5f %8.5f %8.5f %11.5f %11.5f %11.5f %11.5f %9.5f %9.5f %9.5f %9.5f %10X\n",
2377  values.pedestal(0),
2378  values.pedestal(1),
2379  values.pedestal(2),
2380  values.pedestal(3),
2381  values.effpedestal(0),
2382  values.effpedestal(1),
2383  values.effpedestal(2),
2384  values.effpedestal(3),
2385  values.respcorrgain(0),
2386  values.respcorrgain(1),
2387  values.respcorrgain(2),
2388  values.respcorrgain(3),
2389  channel->rawId());
2390  fOutput << buffer;
2391  }
2392  return true;
2393 }
2394 
2395 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput, const HcalCalibrationWidthsSet& fObject) {
2396  char buffer[1024];
2397  sprintf(buffer,
2398  "# %15s %15s %15s %15s %9s %9s %9s %9s %12s %12s %12s %12s %10s %10s %10s %10s %10s\n",
2399  "eta",
2400  "phi",
2401  "dep",
2402  "det",
2403  "pedwcap0",
2404  "pedwcap1",
2405  "pedwcap2",
2406  "pedwcap3",
2407  "effpedwcap0",
2408  "effpedwcap1",
2409  "effpedwcap2",
2410  "effpedwcap3",
2411  "gainwcap0",
2412  "gainwcap1",
2413  "gainwcap2",
2414  "gainwcap3",
2415  "DetId");
2416  fOutput << buffer;
2417 
2418  std::vector<DetId> channels = fObject.getAllChannels();
2419  std::sort(channels.begin(), channels.end(), DetIdLess());
2420  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
2421  dumpId(fOutput, *channel);
2422  const HcalCalibrationWidths& values = fObject.getCalibrationWidths(*channel);
2423  sprintf(buffer,
2424  " %9.5f %9.5f %9.5f %9.5f %12.5f %12.5f %12.5f %12.5f %10.5f %10.5f %10.5f %10.5f %10X\n",
2425  values.pedestal(0),
2426  values.pedestal(1),
2427  values.pedestal(2),
2428  values.pedestal(3),
2429  values.effpedestal(0),
2430  values.effpedestal(1),
2431  values.effpedestal(2),
2432  values.effpedestal(3),
2433  values.gain(0),
2434  values.gain(1),
2435  values.gain(2),
2436  values.gain(3),
2437  channel->rawId());
2438  fOutput << buffer;
2439  }
2440  return true;
2441 }
void dumpIdShort(std::ostream &fOutput, DetId id)
std::vector< double > HFdigiflagCoefficients() const
float getRCalib() const
std::string getAlgoString() const
size
Write out results.
std::unique_ptr< HcalFrontEndMap > createObject< HcalFrontEndMap >(std::istream &fInput)
int getADCThresholdHF() const
get ADC threshold fof TDC mask of HF
const float * minCharges() const
Definition: start.py:1
constexpr void setHTR(int crate, int slot, int tb)
constexpr unsigned int param1() const
Definition: HcalRecoParam.h:25
def rm(path, rec=False)
Definition: eostools.py:363
static const HcalDetId Undefined
Definition: HcalDetId.h:273
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
void setUnitADC(bool isADC)
Definition: HcalPedestals.h:32
constexpr unsigned int firstAuxTS() const
Definition: HcalRecoParam.h:40
bool from_string(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &))
int getFGVersionHBHE() const
get FineGrain Algorithm Version for HBHE
const HcalCalibrationQIECoder * getCoder(DetId fId) const
get QIE parameters
bool loadObject(DetId fId, int rm, std::string rbx)
load a new entry
bool timeSmearing() const
Definition: HcalMCParam.h:42
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
static int slb(const HcalTriggerPrimitiveSample &theSample)
int getAuxi1(int type) const
get auxiliary words
const HcalCalibrations & getCalibrations(const DetId id) const
uint32_t getMask() const
get mask for channel validity and self trigger information
uint32_t getHFTriggerInfo() const
get Self Trigger bits
constexpr unsigned int packingScheme() const
Definition: HcalRecoParam.h:44
uint8_t getLutGranularity() const
bool getHcalMatrixObject(std::istream &fInput, T *fObject, S *fCondObject)
std::vector< float > splitStringToFloatByComma(const std::string &fLine)
constexpr unsigned int specialCaseID() const
Definition: HcalRecoParam.h:41
constexpr unsigned int firstSample() const
Definition: HcalRecoParam.h:31
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
float getFCByPE() const
get fcByPE
std::vector< float > getNonLinearities(int type) const
get nonlinearity constants
uint8_t getOutputLutThreshold() const
std::vector< unsigned int > splitStringToIntByComma(const std::string &fLine)
float timePhase() const
Definition: HcalMCParam.h:41
float getDarkCurrent() const
get dark current
int slice() const
Definition: HcalDcsDetId.h:56
unsigned int param1() const
Definition: HcalMCParam.h:37
uint32_t HFdigiflagExpectedPeak() const
bool dumpHcalSingleFloatObject(std::ostream &fOutput, const T &fObject)
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
float getAuxi2(int type) const
std::vector< std::string > splitString(const std::string &fLine)
uint16_t size_type
constexpr bool correctForPhaseContainment() const
Definition: HcalRecoParam.h:28
bool addCoder(const HcalQIECoder &fCoder)
Definition: HcalQIEData.h:41
bool setRctLsb(float rctlsb)
constexpr uint32_t mask
Definition: gpuClustering.h:26
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:41
void dumpId(std::ostream &fOutput, DetId id)
const Item * getValues(DetId fId, bool throwOnFail=true) const
const float * getValues() const
get value for all capId = 0..3
Definition: HcalPedestal.h:18
U second(std::pair< T, U > const &p)
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:37
int ring() const
Definition: HcalDcsDetId.h:55
std::unique_ptr< HcalSiPMCharacteristics > createObject< HcalSiPMCharacteristics >(std::istream &fInput)
std::vector< HcalDcsValue > DcsSet
Definition: HcalDcsValues.h:27
constexpr bool correctForTimeslew() const
Definition: HcalRecoParam.h:37
constexpr bool correctForLeadingEdge() const
Definition: HcalRecoParam.h:29
float getCrossTalk(int type) const
get cross talk
void setUnitADC(bool isADC)
float rms() const
constexpr unsigned int pulseShapeID() const
Definition: HcalRecoParam.h:33
int subchannel() const
Definition: HcalDcsDetId.h:58
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
HcalDetId getHcalDetId(void)
Definition: HcalDcsMap.cc:88
const int lookupRM(DetId fId) const
brief lookup the RM associated with the given logical id
HcalOtherSubdetector
Definition: HcalAssistant.h:40
constexpr unsigned int timeslewCorrectionID() const
Definition: HcalRecoParam.h:38
float offset(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:47
constexpr bool correctTiming() const
Definition: HcalRecoParam.h:39
HcalDcsDetId getHcalDcsDetId(void)
Definition: HcalDcsMap.cc:86
bool dumpHcalMatrixObject(std::ostream &fOutput, const T &fObject)
std::vector< DetId > getAllChannels() const
double f[11][100]
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:143
uint64_t getTDCMaskHF() const
get TDC mask for HF
Definition: value.py:1
int getType(unsigned int k) const
constexpr float correctionPhaseNS() const
Definition: HcalRecoParam.h:30
float slope(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:49
unsigned int signalShape() const
Definition: HcalMCParam.h:38
int getAuxi2() const
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
std::vector< HcalElectronicsId > allElectronicsId() const
bool getHcalSingleObject(std::istream &fInput, T *fObject)
uint32_t getValue() const
bool operator()(const SiStripRecHit2D *a, const SiStripRecHit2D *b) const
std::vector< DetId > allDetIds() const
static DcsType DcsTypeFromString(const std::string &str)
Definition: HcalDcsDetId.cc:25
Log< level::Info, false > LogInfo
float phase() const
Definition: DetId.h:17
float getRctLsb() const
constexpr bool useLeakCorrection() const
Definition: HcalRecoParam.h:35
unsigned long long uint64_t
Definition: Time.h:13
bool getHcalObject(std::istream &fInput, T *fObject)
uint32_t HFdigiflagFirstSample() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
constexpr unsigned int samplesToAdd() const
Definition: HcalRecoParam.h:32
void sort()
Definition: HcalQIEData.h:43
bool isADC() const
Definition: HcalPedestals.h:30
const HcalCalibrationWidths & getCalibrationWidths(const DetId id) const
int getAuxi1() const
get Axiliary words
bool loadObject(int type, int pixels, float parLin1, float parLin2, float parLin3, float crossTalk, int auxi1=0, float auxi2=0)
std::vector< unsigned int > signalTS() const
float getauxi2() const
std::vector< DetId > getAllChannels() const
std::string getTagString() const
void loadObject(int version, int adcCut, uint64_t tdcMask, uint32_t tbits, int auxi1, int auxi2)
static const HcalTrigTowerDetId Undefined
bool addValue(HcalDcsValue const &newVal)
constexpr unsigned int noiseFlaggingID() const
Definition: HcalRecoParam.h:42
bool getObject(std::istream &fInput, HcalPedestals *fObject)
void setTagString(std::string const &fTag)
int getPixels(int type) const
get # of pixels
DetId getId(const std::vector< std::string > &items)
int getType() const
get SiPM type
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
constexpr unsigned int pileupCleaningID() const
Definition: HcalRecoParam.h:43
float x
bool dumpHcalObject(std::ostream &fOutput, const T &fObject)
DcsSet const & getAllSubdetValues(DcsSubDet subd) const
uint32_t getFGBitInfo() const
get FG bit information
unsigned int packingScheme() const
Definition: HcalMCParam.h:43
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Log< level::Warning, false > LogWarning
std::unique_ptr< HcalDcsMap > createObject< HcalDcsMap >(std::istream &fInput)
unsigned int binOfMaximum() const
Definition: HcalMCParam.h:40
bool addCoder(const HcalCalibrationQIECoder &fCoder)
unsigned int getTypes() const
get # of types
bool syncPhase() const
Definition: HcalMCParam.h:39
constexpr unsigned int leakCorrectionID() const
Definition: HcalRecoParam.h:36
bool addValues(const Item &myItem)
std::vector< DetId > getAllChannels() const
const_iterator endById(void) const
Definition: HcalDcsMap.cc:53
long double T
unsigned int nhits() const
void setAlgoString(std::string const &fAlgo)
std::unique_ptr< HcalElectronicsMap > createObject< HcalElectronicsMap >(std::istream &fInput)
const std::string lookupRBX(DetId fId) const
brief lookup the RBX associated with the given logical id
Readout chain identification for Hcal.
constexpr unsigned int param2() const
Definition: HcalRecoParam.h:26
float getNominalGain() const
std::vector< unsigned int > noiseTS() const
bool setNominalGain(float gain)
bool dumpHcalSingleIntObject(std::ostream &fOutput, const T &fObject)
uint32_t HFdigiflagSamplesToAdd() const
std::vector< double > splitStringToDoubleByComma(const std::string &fLine)