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