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