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