test
CMS 3D CMS Logo

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