CMS 3D CMS Logo

CastorDbASCIIIO.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 
11 
15 
16 namespace CastorDbASCIIIO {
17  class DetIdLess {
18  public:
19  bool operator()(DetId fFirst, DetId fSecond) const {
20  HcalGenericDetId first(fFirst);
21  HcalGenericDetId second(fSecond);
22  if (first.genericSubdet() != second.genericSubdet())
23  return first.genericSubdet() < second.genericSubdet();
24  if (first.isHcalDetId()) {
26  HcalDetId s1(second);
27  return f1.zside() != s1.zside() ? f1.zside() < s1.zside()
28  : f1.iphi() != s1.iphi() ? f1.iphi() < s1.iphi()
29  : f1.ietaAbs() != s1.ietaAbs() ? f1.ietaAbs() < s1.ietaAbs()
30  : f1.depth() < s1.depth();
31  } else {
32  return first.rawId() < second.rawId();
33  }
34  }
35  };
37  public:
39  return first.readoutVMECrateId() != second.readoutVMECrateId()
40  ? first.readoutVMECrateId() < second.readoutVMECrateId()
41  : first.htrSlot() != second.htrSlot() ? first.htrSlot() < second.htrSlot()
42  : first.htrTopBottom() != second.htrTopBottom() ? first.htrTopBottom() < second.htrTopBottom()
43  : first.fiberIndex() != second.fiberIndex() ? first.fiberIndex() < second.fiberIndex()
44  : first.fiberChanId() < second.fiberChanId();
45  }
46  };
47 
48  std::vector<std::string> splitString(const std::string& fLine) {
49  std::vector<std::string> result;
50  int start = 0;
51  bool empty = true;
52  for (unsigned i = 0; i <= fLine.size(); i++) {
53  if (fLine[i] == ' ' || i == fLine.size()) {
54  if (!empty) {
55  std::string item(fLine, start, i - start);
56  result.push_back(item);
57  empty = true;
58  }
59  start = i + 1;
60  } else {
61  if (empty)
62  empty = false;
63  }
64  }
65  return result;
66  }
67 
68  DetId getId(const std::vector<std::string>& items) {
70  return converter.getId();
71  }
72 
73  void dumpId(std::ostream& fOutput, DetId id) {
75  char buffer[1024];
76  sprintf(buffer,
77  " %15s %15s %15s %15s",
78  converter.getField1().c_str(),
79  converter.getField2().c_str(),
80  converter.getField3().c_str(),
81  converter.getFlavor().c_str());
82  fOutput << buffer;
83  }
84 
85  template <class S, class T>
86  bool getCastorObject(std::istream& fInput, T& fObject) {
87  char buffer[1024];
88  while (fInput.getline(buffer, 1024)) {
89  if (buffer[0] == '#')
90  continue; //ignore comment
91  std::vector<std::string> items = splitString(std::string(buffer));
92  if (items.empty())
93  continue; // blank line
94  if (items.size() < 8) {
95  edm::LogWarning("Format Error") << "Bad line: " << buffer
96  << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
97  << std::endl;
98  continue;
99  }
100  DetId id = getId(items);
101 
102  // if (fObject->exists(id) )
103  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
104  // else
105  // {
106  S fCondObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atof(items[6].c_str()), atof(items[7].c_str()));
107  fObject.addValues(fCondObject);
108  // }
109  }
110 
111  return true;
112  }
113 
114  template <class T>
115  bool dumpCastorObject(std::ostream& fOutput, const T& fObject) {
116  char buffer[1024];
117  sprintf(buffer,
118  "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n",
119  "eta",
120  "phi",
121  "dep",
122  "det",
123  "cap0",
124  "cap1",
125  "cap2",
126  "cap3",
127  "DetId");
128  fOutput << buffer;
129  std::vector<DetId> channels = fObject.getAllChannels();
130  //std::sort (channels.begin(), channels.end(), DetIdLess ());
131  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
132  const float* values = fObject.getValues(*channel)->getValues();
133  if (values) {
134  dumpId(fOutput, *channel);
135  sprintf(
136  buffer, " %8.5f %8.5f %8.5f %8.5f %10X\n", values[0], values[1], values[2], values[3], channel->rawId());
137  fOutput << buffer;
138  }
139  }
140  return true;
141  }
142 
143  template <class S, class T>
144  bool getCastorSingleFloatObject(std::istream& fInput, T& fObject) {
145  char buffer[1024];
146  while (fInput.getline(buffer, 1024)) {
147  if (buffer[0] == '#')
148  continue; //ignore comment
149  std::vector<std::string> items = splitString(std::string(buffer));
150  if (items.empty())
151  continue; // blank line
152  if (items.size() < 5) {
153  edm::LogWarning("Format Error") << "Bad line: " << buffer
154  << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
155  continue;
156  }
157  DetId id = getId(items);
158 
159  // if (fObject->exists(id) )
160  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
161  // else
162  // {
163  S fCondObject(id, atof(items[4].c_str()));
164  fObject.addValues(fCondObject);
165  // }
166  }
167  return true;
168  }
169 
170  template <class T>
171  bool dumpCastorSingleFloatObject(std::ostream& fOutput, const T& fObject) {
172  char buffer[1024];
173  sprintf(buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
174  fOutput << buffer;
175  std::vector<DetId> channels = fObject.getAllChannels();
176  std::sort(channels.begin(), channels.end(), DetIdLess());
177  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
178  const float value = fObject.getValues(*channel)->getValue();
179  dumpId(fOutput, *channel);
180  sprintf(buffer, " %8.5f %10X\n", value, channel->rawId());
181  fOutput << buffer;
182  }
183  return true;
184  }
185 
186  template <class S, class T>
187  bool getCastorSingleIntObject(std::istream& fInput, T& fObject, S* fCondObject) {
188  char buffer[1024];
189  while (fInput.getline(buffer, 1024)) {
190  if (buffer[0] == '#')
191  continue; //ignore comment
192  std::vector<std::string> items = splitString(std::string(buffer));
193  if (items.empty())
194  continue; // blank line
195  if (items.size() < 5) {
196  edm::LogWarning("Format Error") << "Bad line: " << buffer
197  << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
198  continue;
199  }
200  DetId id = getId(items);
201 
202  // if (fObject->exists(id) )
203  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
204  // else
205  // {
206  fCondObject = new S(id, atoi(items[4].c_str()));
207  fObject.addValues(*fCondObject);
208  delete fCondObject;
209  // }
210  }
211  return true;
212  }
213 
214  template <class T>
215  bool dumpCastorSingleIntObject(std::ostream& fOutput, const T& fObject) {
216  char buffer[1024];
217  sprintf(buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
218  fOutput << buffer;
219  std::vector<DetId> channels = fObject.getAllChannels();
220  std::sort(channels.begin(), channels.end(), DetIdLess());
221  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
222  const int value = fObject.getValues(*channel)->getValue();
223  dumpId(fOutput, *channel);
224  sprintf(buffer, " %15d %10X\n", value, channel->rawId());
225  fOutput << buffer;
226  }
227  return true;
228  }
229 
230  bool getObject(std::istream& fInput, CastorGains& fObject) { return getCastorObject<CastorGain>(fInput, fObject); }
231  bool dumpObject(std::ostream& fOutput, const CastorGains& fObject) { return dumpCastorObject(fOutput, fObject); }
232  bool getObject(std::istream& fInput, CastorGainWidths& fObject) {
233  return getCastorObject<CastorGainWidth>(fInput, fObject);
234  }
235  bool dumpObject(std::ostream& fOutput, const CastorGainWidths& fObject) { return dumpCastorObject(fOutput, fObject); }
236 
237  bool getObject(std::istream& fInput, CastorSaturationCorrs& fObject) {
238  return getCastorSingleFloatObject<CastorSaturationCorr>(fInput, fObject);
239  }
240  bool dumpObject(std::ostream& fOutput, const CastorSaturationCorrs& fObject) {
241  return dumpCastorSingleFloatObject(fOutput, fObject);
242  }
243 
244  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
245  bool getObject(std::istream& fInput, CastorPedestals& fObject) {
246  char buffer[1024];
247 
248  while (fInput.getline(buffer, 1024)) {
249  std::vector<std::string> items = splitString(std::string(buffer));
250  if (items.empty())
251  continue; // blank line
252  else {
253  if (items[0] == "#U") {
254  if (items[1] == (std::string) "ADC")
255  fObject.setUnitADC(true);
256  else if (items[1] == (std::string) "fC")
257  fObject.setUnitADC(false);
258  else {
259  edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
260  fObject.setUnitADC(false);
261  }
262  break;
263  } else {
264  edm::LogWarning("Pedestal Unit Missing")
265  << "The unit for the pedestals is missing in the txt file." << std::endl;
266  return false;
267  }
268  }
269  }
270  while (fInput.getline(buffer, 1024)) {
271  if (buffer[0] == '#')
272  continue;
273  std::vector<std::string> items = splitString(std::string(buffer));
274  if (items.empty())
275  continue; // blank line
276  if (items.size() < 8) {
277  edm::LogWarning("Format Error")
278  << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
279  << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width" << std::endl;
280  continue;
281  }
282  DetId id = getId(items);
283 
284  // if (fObject.exists(id) )
285  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
286  // else
287  // {
288 
289  if (items.size() < 12) // old format without widths
290  {
291  CastorPedestal fCondObject(id,
292  atof(items[4].c_str()),
293  atof(items[5].c_str()),
294  atof(items[6].c_str()),
295  atof(items[7].c_str()),
296  0.,
297  0.,
298  0.,
299  0.);
300  fObject.addValues(fCondObject);
301  } else // new format with widths
302  {
303  CastorPedestal fCondObject(id,
304  atof(items[4].c_str()),
305  atof(items[5].c_str()),
306  atof(items[6].c_str()),
307  atof(items[7].c_str()),
308  atof(items[8].c_str()),
309  atof(items[9].c_str()),
310  atof(items[10].c_str()),
311  atof(items[11].c_str()));
312  fObject.addValues(fCondObject);
313  }
314 
315  // }
316  }
317  return true;
318  }
319 
320  bool dumpObject(std::ostream& fOutput, const CastorPedestals& fObject) {
321  char buffer[1024];
322  if (fObject.isADC())
323  sprintf(buffer, "#U ADC << this is the unit \n");
324  else
325  sprintf(buffer, "#U fC << this is the unit \n");
326  fOutput << buffer;
327 
328  sprintf(buffer,
329  "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
330  "eta",
331  "phi",
332  "dep",
333  "det",
334  "cap0",
335  "cap1",
336  "cap2",
337  "cap3",
338  "widthcap0",
339  "widthcap1",
340  "widthcap2",
341  "widthcap3",
342  "DetId");
343  fOutput << buffer;
344 
345  std::vector<DetId> channels = fObject.getAllChannels();
346  std::sort(channels.begin(), channels.end(), DetIdLess());
347  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
348  const float* values = fObject.getValues(*channel)->getValues();
349  if (values) {
350  dumpId(fOutput, *channel);
351  sprintf(buffer,
352  " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
353  values[0],
354  values[1],
355  values[2],
356  values[3],
357  values[4],
358  values[5],
359  values[6],
360  values[7],
361  channel->rawId());
362  fOutput << buffer;
363  }
364  }
365  return true;
366  }
367 
368  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
369  bool getObject(std::istream& fInput, CastorChannelQuality& fObject) {
370  char buffer[1024];
371  while (fInput.getline(buffer, 1024)) {
372  if (buffer[0] == '#')
373  continue; //ignore comment
374  std::vector<std::string> items = splitString(std::string(buffer));
375  if (items.empty())
376  continue; // blank line
377  if (items.size() < 5) {
378  edm::LogWarning("Format Error") << "Bad line: " << buffer
379  << "\n line must contain 5 items: eta, phi, depth, subdet, GOOD/BAD/HOT/DEAD"
380  << std::endl;
381  continue;
382  }
383  DetId id = getId(items);
384 
385  if (fObject.exists(id)) {
386  edm::LogWarning("Redefining Channel")
387  << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
388  continue;
389  }
390  // else
391  // {
392  uint32_t mystatus;
393  std::unique_ptr<CastorChannelStatus> fCondObject;
394  if (items[4].substr(0, 2) == "0x") {
395  sscanf(items[4].c_str(), "%X", &mystatus);
396  fCondObject = std::make_unique<CastorChannelStatus>(id, mystatus);
397  } else if (isalpha(items[4].c_str()[0])) {
398  fCondObject = std::make_unique<CastorChannelStatus>(id, items[4]);
399  } else {
400  sscanf(items[4].c_str(), "%u", &mystatus);
401  fCondObject = std::make_unique<CastorChannelStatus>(id, mystatus);
402  }
403  fObject.addValues(*fCondObject);
404  // }
405  }
406  return true;
407  }
408 
409  bool dumpObject(std::ostream& fOutput, const CastorChannelQuality& fObject) {
410  char buffer[1024];
411  sprintf(buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
412  fOutput << buffer;
413  std::vector<DetId> channels = fObject.getAllChannels();
414  std::sort(channels.begin(), channels.end(), DetIdLess());
415  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
416  const int value = fObject.getValues(*channel)->getValue();
417  dumpId(fOutput, *channel);
418  sprintf(buffer, " %15X %10X\n", value, channel->rawId());
419  fOutput << buffer;
420  }
421  return true;
422  }
423 
424  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
425  bool getObject(std::istream& fInput, CastorPedestalWidths& fObject) {
426  char buffer[1024];
427  int linecounter = 0;
428 
429  while (fInput.getline(buffer, 1024)) {
430  linecounter++;
431  std::vector<std::string> items = splitString(std::string(buffer));
432  if (items.empty())
433  continue; // blank line
434  else {
435  if (items[0] == (std::string) "#U") {
436  if (items[1] == (std::string) "ADC")
437  fObject.setUnitADC(true);
438  else if (items[1] == (std::string) "fC")
439  fObject.setUnitADC(false);
440  else {
441  edm::LogWarning("Pedestal Width Unit Error")
442  << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
443  fObject.setUnitADC(false);
444  }
445  break;
446  } else {
447  edm::LogWarning("Pedestal Width Unit Missing")
448  << "The unit for the pedestal widths is missing in the txt file." << std::endl;
449  return false;
450  }
451  }
452  }
453 
454  while (fInput.getline(buffer, 1024)) {
455  linecounter++;
456  if (buffer[0] == '#')
457  continue; //ignore comment
458  std::vector<std::string> items = splitString(std::string(buffer));
459  if (items.empty())
460  continue; // blank line
461  if (items.size() < 14) {
462  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter
463  << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
464  << " or 20 items: eta, phi, depth, subdet, 16x correlations" << std::endl;
465  continue;
466  }
467  DetId id = getId(items);
468 
469  // if (fObject.exists(id) )
470  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
471  // else
472  // {
473 
474  if (items.size() < 20) //old format
475  {
477  values.setSigma(0, 0, atof(items[4].c_str()));
478  values.setSigma(1, 0, atof(items[5].c_str()));
479  values.setSigma(1, 1, atof(items[6].c_str()));
480  values.setSigma(2, 0, atof(items[7].c_str()));
481  values.setSigma(2, 1, atof(items[8].c_str()));
482  values.setSigma(2, 2, atof(items[9].c_str()));
483  values.setSigma(3, 0, atof(items[10].c_str()));
484  values.setSigma(3, 1, atof(items[11].c_str()));
485  values.setSigma(3, 2, atof(items[12].c_str()));
486  values.setSigma(3, 3, atof(items[13].c_str()));
487  values.setSigma(0, 1, 0.);
488  values.setSigma(0, 2, 0.);
489  values.setSigma(0, 3, 0.);
490  values.setSigma(1, 2, 0.);
491  values.setSigma(1, 3, 0.);
492  values.setSigma(2, 3, 0.);
493  fObject.addValues(values);
494  } else // new format
495  {
497  values.setSigma(0, 0, atof(items[4].c_str()));
498  values.setSigma(0, 1, atof(items[5].c_str()));
499  values.setSigma(0, 2, atof(items[6].c_str()));
500  values.setSigma(0, 3, atof(items[7].c_str()));
501  values.setSigma(1, 0, atof(items[8].c_str()));
502  values.setSigma(1, 1, atof(items[9].c_str()));
503  values.setSigma(1, 2, atof(items[10].c_str()));
504  values.setSigma(1, 3, atof(items[11].c_str()));
505  values.setSigma(2, 0, atof(items[12].c_str()));
506  values.setSigma(2, 1, atof(items[13].c_str()));
507  values.setSigma(2, 2, atof(items[14].c_str()));
508  values.setSigma(2, 3, atof(items[15].c_str()));
509  values.setSigma(3, 0, atof(items[16].c_str()));
510  values.setSigma(3, 1, atof(items[17].c_str()));
511  values.setSigma(3, 2, atof(items[18].c_str()));
512  values.setSigma(3, 3, atof(items[19].c_str()));
513  fObject.addValues(values);
514  }
515 
516  // }
517  }
518  return true;
519  }
520 
521  bool dumpObject(std::ostream& fOutput, const CastorPedestalWidths& fObject) {
522  char buffer[1024];
523  if (fObject.isADC())
524  sprintf(buffer, "#U ADC << this is the unit \n");
525  else
526  sprintf(buffer, "#U fC << this is the unit \n");
527  fOutput << buffer;
528 
529  sprintf(buffer,
530  "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
531  "eta",
532  "phi",
533  "dep",
534  "det",
535  "cov_0_0",
536  "cov_0_1",
537  "cov_0_2",
538  "cov_0_3",
539  "cov_1_0",
540  "cov_1_1",
541  "cov_1_2",
542  "cov_1_3",
543  "cov_2_0",
544  "cov_2_1",
545  "cov_2_2",
546  "cov_2_3",
547  "cov_3_0",
548  "cov_3_1",
549  "cov_3_2",
550  "cov_3_3",
551  "DetId");
552  fOutput << buffer;
553  std::vector<DetId> channels = fObject.getAllChannels();
554  std::sort(channels.begin(), channels.end(), DetIdLess());
555  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
556  const CastorPedestalWidth* item = fObject.getValues(*channel);
557  if (item) {
558  dumpId(fOutput, *channel);
559  sprintf(
560  buffer,
561  " %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",
562  item->getSigma(0, 0),
563  item->getSigma(0, 1),
564  item->getSigma(0, 2),
565  item->getSigma(0, 3),
566  item->getSigma(1, 0),
567  item->getSigma(1, 1),
568  item->getSigma(1, 2),
569  item->getSigma(1, 3),
570  item->getSigma(2, 0),
571  item->getSigma(2, 1),
572  item->getSigma(2, 2),
573  item->getSigma(2, 3),
574  item->getSigma(3, 0),
575  item->getSigma(3, 1),
576  item->getSigma(3, 2),
577  item->getSigma(3, 3),
578  channel->rawId());
579  fOutput << buffer;
580  }
581  }
582  return true;
583  }
584 
585  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
586  bool getObject(std::istream& fInput, CastorQIEData& fObject) {
587  char buffer[1024];
588  while (fInput.getline(buffer, 1024)) {
589  if (buffer[0] == '#')
590  continue; //ignore comment
591  std::vector<std::string> items = splitString(std::string(buffer));
592  if (items.empty())
593  continue;
594  if (items[0] == "SHAPE") { // basic shape
595  if (items.size() < 33) {
596  edm::LogWarning("Format Error")
597  << "Bad line: " << buffer << "\n line must contain 33 items: SHAPE 32 x low QIE edges for first 32 bins"
598  << std::endl;
599  continue;
600  }
601  //float lowEdges [32];
602  //int i = 32;
603  //while (--i >= 0) lowEdges [i] = atof (items [i+1].c_str ());
604  // fObject.setShape (lowEdges);
605  } else { // QIE parameters
606  if (items.size() < 36) {
607  edm::LogWarning("Format Error") << "Bad line: " << buffer
608  << "\n line must contain 36 items: eta, phi, depth, subdet, 4 capId x 4 "
609  "Ranges x offsets, 4 capId x 4 Ranges x slopes"
610  << std::endl;
611  continue;
612  }
613  DetId id = getId(items);
614  fObject.sort();
615  // try {
616  // fObject.getCoder (id);
617  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
618  // }
619  // catch (cms::Exception& e) {
620  CastorQIECoder coder(id.rawId());
621  int index = 4;
622  for (unsigned capid = 0; capid < 4; capid++) {
623  for (unsigned range = 0; range < 4; range++) {
624  coder.setOffset(capid, range, atof(items[index++].c_str()));
625  }
626  }
627  for (unsigned capid = 0; capid < 4; capid++) {
628  for (unsigned range = 0; range < 4; range++) {
629  coder.setSlope(capid, range, atof(items[index++].c_str()));
630  }
631  }
632  fObject.addCoder(coder);
633  // }
634  }
635  }
636  fObject.sort();
637  return true;
638  }
639 
640  bool dumpObject(std::ostream& fOutput, const CastorQIEData& fObject) {
641  char buffer[1024];
642  fOutput << "# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
643  sprintf(buffer, "SHAPE ");
644  fOutput << buffer;
645  for (unsigned bin = 0; bin < 32; bin++) {
646  sprintf(buffer, " %8.5f", fObject.getShape().lowEdge(bin));
647  fOutput << buffer;
648  }
649  fOutput << std::endl;
650 
651  fOutput << "# QIE data" << std::endl;
652  sprintf(buffer,
653  "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
654  "eta",
655  "phi",
656  "dep",
657  "det",
658  "4 x offsets cap0",
659  "4 x offsets cap1",
660  "4 x offsets cap2",
661  "4 x offsets cap3",
662  "4 x slopes cap0",
663  "4 x slopes cap1",
664  "4 x slopes cap2",
665  "4 x slopes cap3");
666  fOutput << buffer;
667  std::vector<DetId> channels = fObject.getAllChannels();
668  std::sort(channels.begin(), channels.end(), DetIdLess());
669  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
670  const CastorQIECoder* coder = fObject.getCoder(*channel);
671  dumpId(fOutput, *channel);
672  for (unsigned capid = 0; capid < 4; capid++) {
673  for (unsigned range = 0; range < 4; range++) {
674  sprintf(buffer, " %8.5f", coder->offset(capid, range));
675  fOutput << buffer;
676  }
677  }
678  for (unsigned capid = 0; capid < 4; capid++) {
679  for (unsigned range = 0; range < 4; range++) {
680  sprintf(buffer, " %8.5f", coder->slope(capid, range));
681  fOutput << buffer;
682  }
683  }
684  fOutput << std::endl;
685  }
686  return true;
687  }
688 
689  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
690  bool getObject(std::istream& fInput, CastorCalibrationQIEData& fObject) {
691  char buffer[1024];
692  while (fInput.getline(buffer, 1024)) {
693  if (buffer[0] == '#')
694  continue; //ignore comment
695  std::vector<std::string> items = splitString(std::string(buffer));
696  if (items.size() < 36) {
697  edm::LogWarning("Format Error") << "Bad line: " << buffer
698  << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values"
699  << std::endl;
700  continue;
701  }
702  DetId id = getId(items);
703  fObject.sort();
704  // try {
705  // fObject.getCoder (id);
706  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
707  // }
708  // catch (cms::Exception& e) {
709  CastorCalibrationQIECoder coder(id.rawId());
710  int index = 4;
711  float values[32];
712  for (unsigned bin = 0; bin < 32; bin++) {
713  values[bin] = atof(items[index++].c_str());
714  }
715  coder.setMinCharges(values);
716  fObject.addCoder(coder);
717  // }
718  }
719  fObject.sort();
720  return true;
721  }
722 
723  bool dumpObject(std::ostream& fOutput, const CastorCalibrationQIEData& fObject) {
724  char buffer[1024];
725  fOutput << "# QIE data in calibration mode" << std::endl;
726  sprintf(buffer, "# %15s %15s %15s %15s %288s\n", "eta", "phi", "dep", "det", "32 x charges");
727  fOutput << buffer;
728  std::vector<DetId> channels = fObject.getAllChannels();
729  std::sort(channels.begin(), channels.end(), DetIdLess());
730  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
731  const CastorCalibrationQIECoder* coder = fObject.getCoder(*channel);
732  if (coder) {
733  dumpId(fOutput, *channel);
734  const float* lowEdge = coder->minCharges();
735  for (unsigned bin = 0; bin < 32; bin++) {
736  sprintf(buffer, " %8.5f", lowEdge[bin]);
737  fOutput << buffer;
738  }
739  fOutput << std::endl;
740  }
741  }
742  return true;
743  }
744 
745  // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
746  bool getObject(std::istream& fInput, CastorElectronicsMap& fObject) {
747  char buffer[1024];
748  while (fInput.getline(buffer, 1024)) {
749  if (buffer[0] == '#')
750  continue; //ignore comment
751  std::vector<std::string> items = splitString(std::string(buffer));
752  if (items.size() < 12) {
753  if (items.empty())
754  continue; // no warning here
755  if (items.size() < 9) {
756  edm::LogError("MapFormat") << "CastorElectronicsMap-> line too short: " << buffer;
757  continue;
758  }
759  if (items[8] == "NA" || items[8] == "NT") {
760  while (items.size() < 12)
761  items.push_back(""); // don't worry here
762  } else if (items[8] == "HT") {
763  if (items.size() == 11)
764  items.push_back("");
765  else {
766  edm::LogError("MapFormat") << "CastorElectronicsMap-> Bad line: " << buffer
767  << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber "
768  "fiberchan subdet=HT ieta iphi";
769  continue;
770  }
771  } else {
772  edm::LogError("MapFormat")
773  << "CastorElectronicsMap-> Bad line: " << buffer
774  << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
775  continue;
776  }
777  }
778  // std::cout << "CastorElectronicsMap-> processing line: " << buffer << std::endl;
779  int crate = atoi(items[1].c_str());
780  int slot = atoi(items[2].c_str());
781  int top = 1;
782  if (items[3] == "b")
783  top = 0;
784  int dcc = atoi(items[4].c_str());
785  int spigot = atoi(items[5].c_str());
786  CastorElectronicsId elId;
787  if (items[8] == "HT" || items[8] == "NT") {
788  int slb = atoi(items[6].c_str());
789  int slbCh = atoi(items[7].c_str());
790  elId = CastorElectronicsId(slbCh, slb, spigot, dcc, crate, slot, top);
791  } else {
792  int fiber = atoi(items[6].c_str());
793  int fiberCh = atoi(items[7].c_str());
794 
795  elId = CastorElectronicsId(fiberCh, fiber, spigot, dcc);
796  elId.setHTR(crate, slot, top);
797  }
798 
799  // first, handle undefined cases
800  if (items[8] == "NA") { // undefined channel
801  fObject.mapEId2chId(elId, DetId(HcalDetId::Undefined));
802  } else if (items[8] == "NT") { // undefined trigger channel
804  } else {
806  if (converter.isHcalCastorDetId()) {
807  fObject.mapEId2chId(elId, converter.getId());
808  } else {
809  edm::LogWarning("Format Error") << "CastorElectronicsMap-> Unknown subdetector: " << items[8] << '/'
810  << items[9] << '/' << items[10] << '/' << items[11] << std::endl;
811  }
812  }
813  }
814  fObject.sort();
815  return true;
816  }
817 
818  bool dumpObject(std::ostream& fOutput, const CastorElectronicsMap& fObject) {
819  std::vector<CastorElectronicsId> eids = fObject.allElectronicsId();
820  char buf[1024];
821  // changes by Jared, 6.03.09/(included 25.03.09)
822  // sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
823  sprintf(buf,
824  "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
825  "i",
826  "cr",
827  "sl",
828  "tb",
829  "dcc",
830  "spigot",
831  "fiber/slb",
832  "fibcha/slbcha",
833  "subdet",
834  "ieta",
835  "iphi",
836  "depth");
837  fOutput << buf << std::endl;
838 
839  for (unsigned i = 0; i < eids.size(); i++) {
840  CastorElectronicsId eid = eids[i];
841  if (eid.isTriggerChainId()) {
842  DetId trigger = fObject.lookupTrigger(eid);
843  if (trigger.rawId()) {
845  // changes by Jared, 6.03.09/(included 25.03.09)
846  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
847  sprintf(
848  buf,
849  " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
850  // i,
851  converter.getId().rawId(),
852  // changes by Jared, 6.03.09/(included 25.03.09)
853  // eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
854  eid.readoutVMECrateId(),
855  eid.htrSlot(),
856  eid.htrTopBottom() > 0 ? 't' : 'b',
857  eid.dccid(),
858  eid.spigot(),
859  eid.slbSiteNumber(),
860  eid.slbChannelIndex(),
861  converter.getFlavor().c_str(),
862  converter.getField1().c_str(),
863  converter.getField2().c_str(),
864  converter.getField3().c_str());
865  fOutput << buf << std::endl;
866  }
867  } else {
868  DetId channel = fObject.lookup(eid);
869  if (channel.rawId()) {
871  // changes by Jared, 6.03.09/(included 25.03.09)
872  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
873  sprintf(buf,
874  " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
875  // i,
876  converter.getId().rawId(),
877  eid.readoutVMECrateId(),
878  eid.htrSlot(),
879  eid.htrTopBottom() > 0 ? 't' : 'b',
880  eid.dccid(),
881  eid.spigot(),
882  eid.fiberIndex(),
883  eid.fiberChanId(),
884  converter.getFlavor().c_str(),
885  converter.getField1().c_str(),
886  converter.getField2().c_str(),
887  converter.getField3().c_str());
888  fOutput << buf << std::endl;
889  }
890  }
891  }
892  return true;
893  }
894 
895  bool getObject(std::istream& fInput, CastorRecoParams& fObject) {
896  char buffer[1024];
897  while (fInput.getline(buffer, 1024)) {
898  if (buffer[0] == '#')
899  continue; //ignore comment
900  std::vector<std::string> items = splitString(std::string(buffer));
901  if (items.empty())
902  continue; // blank line
903  if (items.size() < 6) {
904  edm::LogWarning("Format Error")
905  << "Bad line: " << buffer
906  << "\n line must contain 6 items: eta, phi, depth, subdet, firstSample, samplesToAdd" << std::endl;
907  continue;
908  }
909  DetId id = getId(items);
910 
911  CastorRecoParam fCondObject(id, atoi(items[4].c_str()), atoi(items[5].c_str()));
912  fObject.addValues(fCondObject);
913  }
914  return true;
915  }
916 
917  bool dumpObject(std::ostream& fOutput, const CastorRecoParams& fObject) {
918  char buffer[1024];
919  sprintf(buffer,
920  "# %15s %15s %15s %15s %18s %15s %10s\n",
921  "eta",
922  "phi",
923  "dep",
924  "det",
925  "firstSample",
926  "samplesToAdd",
927  "DetId");
928  fOutput << buffer;
929  std::vector<DetId> channels = fObject.getAllChannels();
930  std::sort(channels.begin(), channels.end(), DetIdLess());
931  for (std::vector<DetId>::iterator channel = channels.begin(); channel != channels.end(); ++channel) {
932  dumpId(fOutput, *channel);
933  sprintf(buffer,
934  " %15d %15d %16X\n",
935  fObject.getValues(*channel)->firstSample(),
936  fObject.getValues(*channel)->samplesToAdd(),
937  channel->rawId());
938  fOutput << buffer;
939  }
940  return true;
941  }
942 
943 } // namespace CastorDbASCIIIO
CastorDbASCIIIO::dumpCastorSingleFloatObject
bool dumpCastorSingleFloatObject(std::ostream &fOutput, const T &fObject)
Definition: CastorDbASCIIIO.cc:171
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
CastorDbASCIIIO::dumpId
void dumpId(std::ostream &fOutput, DetId id)
Definition: CastorDbASCIIIO.cc:73
HcalDetId::Undefined
static const HcalDetId Undefined
Definition: HcalDetId.h:273
CastorCondObjectContainer::getValues
const Item * getValues(DetId fId, bool throwOnFail=true) const
Definition: CastorCondObjectContainer.h:65
mps_fire.i
i
Definition: mps_fire.py:428
CastorCondObjectContainer::exists
const bool exists(DetId fId) const
Definition: CastorCondObjectContainer.h:88
CastorGainWidths
Definition: CastorGainWidths.h:18
start
Definition: start.py:1
MessageLogger.h
CastorPedestalWidths::setUnitADC
void setUnitADC(bool isADC)
Definition: CastorPedestalWidths.h:27
CastorText2DetIdConverter
Definition: CastorText2DetIdConverter.h:12
HcalGenericDetId
Definition: HcalGenericDetId.h:15
HcalDetId::iphi
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
CastorCalibrationQIEData::getCoder
const CastorCalibrationQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: CastorCalibrationQIEData.h:27
converter
Definition: CandidateProducer.h:25
CastorQIECoder::slope
float slope(unsigned fCapId, unsigned fRange) const
Definition: CastorQIECoder.cc:44
CastorPedestals::setUnitADC
void setUnitADC(bool isADC)
Definition: CastorPedestals.h:27
CastorPedestals::isADC
bool isADC() const
Definition: CastorPedestals.h:25
AllObjects.h
CastorQIECoder::setOffset
void setOffset(unsigned fCapId, unsigned fRange, float fValue)
Definition: CastorQIECoder.cc:46
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
HcalGenericDetId.h
HcalDetId::depth
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
CastorElectronicsId
Readout chain identification for Castor Bits for the readout chain : some names need change!...
Definition: CastorElectronicsId.h:20
CastorPedestal::getValues
const float * getValues() const
get value for all capId = 0..3
Definition: CastorPedestal.h:19
CastorPedestal
Definition: CastorPedestal.h:16
CastorPedestalWidth
Definition: CastorPedestalWidth.h:16
CastorQIEShape::lowEdge
float lowEdge(unsigned fAdc) const
Definition: CastorQIEShape.cc:34
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CastorCondObjectContainer::getAllChannels
std::vector< DetId > getAllChannels() const
Definition: CastorCondObjectContainer.h:119
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
CastorRecoParam
Definition: CastorRecoParam.h:13
CastorCalibrationQIECoder::setMinCharges
void setMinCharges(const float fValue[32])
Definition: CastorCalibrationQIECoder.cc:46
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
slb
static int slb(const HcalTriggerPrimitiveSample &theSample)
Definition: CastorUnpacker.cc:71
CastorDbASCIIIO
Definition: CastorDbASCIIIO.h:37
DetId
Definition: DetId.h:17
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
CastorElectronicsMap::sort
void sort()
Definition: CastorElectronicsMap.h:78
CastorElectronicsMap::mapEId2tId
bool mapEId2tId(CastorElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
Definition: CastorElectronicsMap.cc:201
CastorPedestalWidths::isADC
bool isADC() const
Definition: CastorPedestalWidths.h:25
CastorDbASCIIIO::getCastorObject
bool getCastorObject(std::istream &fInput, T &fObject)
Definition: CastorDbASCIIIO.cc:86
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
CastorPedestals
Definition: CastorPedestals.h:18
S
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:97
CastorElectronicsId.h
CastorDbASCIIIO::dumpObject
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
Definition: CastorDbASCIIIO.cc:320
CastorDbASCIIIO::getObject
bool getObject(std::istream &fInput, CastorPedestals &fObject)
Definition: CastorDbASCIIIO.cc:245
CastorElectronicsId::setHTR
void setHTR(int crate, int slot, int tb)
Definition: CastorElectronicsId.cc:56
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
CastorDbASCIIIO::CastorElectronicsIdLess::operator()
bool operator()(CastorElectronicsId first, CastorElectronicsId second) const
Definition: CastorDbASCIIIO.cc:38
HcalTrigTowerDetId::Undefined
static const HcalTrigTowerDetId Undefined
Definition: HcalTrigTowerDetId.h:62
CastorDbASCIIIO::DetIdLess::operator()
bool operator()(DetId fFirst, DetId fSecond) const
Definition: CastorDbASCIIIO.cc:19
HcalDetId
Definition: HcalDetId.h:12
CastorCondObjectContainer::addValues
bool addValues(const Item &myItem)
Definition: CastorCondObjectContainer.h:98
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
CastorCalibrationQIEData::addCoder
bool addCoder(const CastorCalibrationQIECoder &fCoder)
Definition: CastorCalibrationQIEData.h:31
CastorQIEData::getCoder
const CastorQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: CastorQIEData.h:37
CastorChannelStatus::getValue
uint32_t getValue() const
Definition: CastorChannelStatus.h:68
value
Definition: value.py:1
CastorRecoParams
Definition: CastorRecoParams.h:9
CastorDbASCIIIO::getCastorSingleIntObject
bool getCastorSingleIntObject(std::istream &fInput, T &fObject, S *fCondObject)
Definition: CastorDbASCIIIO.cc:187
CastorText2DetIdConverter.h
CastorGains
Definition: CastorGains.h:18
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
CastorQIEData::addCoder
bool addCoder(const CastorQIECoder &fCoder)
Definition: CastorQIEData.h:42
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
CastorQIECoder::setSlope
void setSlope(unsigned fCapId, unsigned fRange, float fValue)
Definition: CastorQIECoder.cc:54
visDQMUpload.buf
buf
Definition: visDQMUpload.py:160
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CastorChannelQuality
Definition: CastorChannelQuality.h:17
CastorDbASCIIIO::DetIdLess
Definition: CastorDbASCIIIO.cc:17
CastorQIEData::sort
void sort()
Definition: CastorQIEData.h:44
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
CastorDbASCIIIO.h
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CastorCalibrationQIEData::sort
void sort()
Definition: CastorCalibrationQIEData.h:33
T
long double T
Definition: Basic3DVectorLD.h:48
CastorElectronicsMap::lookup
const DetId lookup(CastorElectronicsId fId) const
lookup the logical detid associated with the given electronics id
Definition: CastorElectronicsMap.cc:105
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
ewkTauDQM_cfi.channels
channels
Definition: ewkTauDQM_cfi.py:14
CastorDbASCIIIO::getCastorSingleFloatObject
bool getCastorSingleFloatObject(std::istream &fInput, T &fObject)
Definition: CastorDbASCIIIO.cc:144
CastorDbASCIIIO::getId
DetId getId(const std::vector< std::string > &items)
Definition: CastorDbASCIIIO.cc:68
CastorDbASCIIIO::CastorElectronicsIdLess
Definition: CastorDbASCIIIO.cc:36
CastorPedestalWidths
Definition: CastorPedestalWidths.h:18
S
Definition: CSCDBL1TPParametersExtended.h:16
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
CastorElectronicsMap::lookupTrigger
const DetId lookupTrigger(CastorElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Definition: CastorElectronicsMap.cc:115
CastorQIECoder
Definition: CastorQIECoder.h:21
CastorQIECoder::offset
float offset(unsigned fCapId, unsigned fRange) const
Definition: CastorQIECoder.cc:42
trigger
Definition: HLTPrescaleTableCond.h:8
CastorElectronicsMap::mapEId2chId
bool mapEId2chId(CastorElectronicsId fElectronicsId, DetId fId)
Definition: CastorElectronicsMap.cc:216
CastorElectronicsMap
Definition: CastorElectronicsMap.h:30
CastorRecoParam::firstSample
unsigned int firstSample() const
Definition: CastorRecoParam.h:22
mps_fire.result
result
Definition: mps_fire.py:311
CastorDbASCIIIO::dumpCastorSingleIntObject
bool dumpCastorSingleIntObject(std::ostream &fOutput, const T &fObject)
Definition: CastorDbASCIIIO.cc:215
CastorSaturationCorrs
Definition: CastorSaturationCorrs.h:9
HcalDetId::ietaAbs
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
CastorCalibrationQIEData
Definition: CastorCalibrationQIEData.h:24
CastorQIEData
Definition: CastorQIEData.h:25
HcalDetId::zside
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219
CastorDbASCIIIO::splitString
std::vector< std::string > splitString(const std::string &fLine)
Definition: CastorDbASCIIIO.cc:48
CastorElectronicsMap::allElectronicsId
std::vector< CastorElectronicsId > allElectronicsId() const
Definition: CastorElectronicsMap.cc:149
CastorCalibrationQIECoder
Definition: CastorCalibrationQIECoder.h:17
CastorCalibrationQIECoder::minCharges
const float * minCharges() const
Definition: CastorCalibrationQIECoder.cc:35
CastorRecoParam::samplesToAdd
unsigned int samplesToAdd() const
Definition: CastorRecoParam.h:23
CastorDbASCIIIO::dumpCastorObject
bool dumpCastorObject(std::ostream &fOutput, const T &fObject)
Definition: CastorDbASCIIIO.cc:115
CastorQIEData::getShape
const CastorQIEShape & getShape() const
get basic shape
Definition: CastorQIEData.h:35