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