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.8 2012/11/14 13:28:53 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 5 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 5 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 bool getObject (std::istream& fInput, CastorSaturationCorrs* fObject) {return getCastorSingleFloatObject (fInput, fObject, new CastorSaturationCorr);}
228 bool dumpObject (std::ostream& fOutput, const CastorSaturationCorrs& fObject) {return dumpCastorSingleFloatObject (fOutput, fObject);}
229 
230 
231 
232 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
233 bool getObject (std::istream& fInput, CastorPedestals* fObject) {
234  if (!fObject) fObject = new CastorPedestals(false);
235  char buffer [1024];
236 
237  while (fInput.getline(buffer, 1024)) {
238  std::vector <std::string> items = splitString (std::string (buffer));
239  if (items.size()==0) continue; // blank line
240  else {
241  if (items[0] == "#U")
242  {
243  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
244  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
245  else
246  {
247  edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
248  fObject->setUnitADC(false);
249  }
250  break;
251  }
252  else
253  {
254  edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
255  return false;
256  }
257  }
258  }
259  while (fInput.getline(buffer, 1024)) {
260  if (buffer [0] == '#') continue;
261  std::vector <std::string> items = splitString (std::string (buffer));
262  if (items.size()==0) continue; // blank line
263  if (items.size () < 8) {
264  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
265  << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
266  << std::endl;
267  continue;
268  }
269  DetId id = getId (items);
270 
271 // if (fObject->exists(id) )
272 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
273 // else
274 // {
275 
276  if (items.size() < 12) // old format without widths
277  {
278  CastorPedestal* fCondObject = new CastorPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
279  atof (items [6].c_str()), atof (items [7].c_str()),
280  0., 0., 0., 0. );
281  fObject->addValues(*fCondObject);
282  delete fCondObject;
283  }
284  else // new format with widths
285  {
286  CastorPedestal* fCondObject = new CastorPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
287  atof (items [6].c_str()), atof (items [7].c_str()),
288  atof (items [8].c_str()), atof (items [9].c_str()),
289  atof (items [10].c_str()), atof (items [11].c_str()) );
290  fObject->addValues(*fCondObject);
291  delete fCondObject;
292  }
293 
294  // }
295  }
296  return true;
297 }
298 
299 
300 bool dumpObject (std::ostream& fOutput, const CastorPedestals& fObject) {
301  char buffer [1024];
302  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
303  else sprintf (buffer, "#U fC << this is the unit \n");
304  fOutput << buffer;
305 
306  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");
307  fOutput << buffer;
308 
309  std::vector<DetId> channels = fObject.getAllChannels ();
310  std::sort (channels.begin(), channels.end(), DetIdLess ());
311  for (std::vector<DetId>::iterator channel = channels.begin ();
312  channel != channels.end ();
313  channel++) {
314  const float* values = fObject.getValues (*channel)->getValues ();
315  if (values) {
316  dumpId (fOutput, *channel);
317  sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
318  values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
319  fOutput << buffer;
320  }
321  }
322  return true;
323 }
324 
325 
326 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
327 bool getObject (std::istream& fInput, CastorChannelQuality* fObject)
328 {
329  if (!fObject) fObject = new CastorChannelQuality;
330  char buffer [1024];
331  while (fInput.getline(buffer, 1024)) {
332  if (buffer [0] == '#') continue; //ignore comment
333  std::vector <std::string> items = splitString (std::string (buffer));
334  if (items.size()==0) continue; // blank line
335  if (items.size () < 5) {
336  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, GOOD/BAD/HOT/DEAD" << std::endl;
337  continue;
338  }
339  DetId id = getId (items);
340 
341  if (fObject->exists(id) ) {
342  edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
343  continue;
344  }
345 // else
346 // {
347  uint32_t mystatus;
348  CastorChannelStatus* fCondObject = NULL;
349  if (items[4].substr(0,2)=="0x") {
350  sscanf(items[4].c_str(),"%X", &mystatus);
351  fCondObject = new CastorChannelStatus(id,mystatus);
352  }
353  else if (isalpha(items[4].c_str()[0])) {
354  fCondObject = new CastorChannelStatus(id, items[4]);
355  }
356  else {
357  sscanf(items[4].c_str(),"%u", &mystatus);
358  fCondObject = new CastorChannelStatus(id,mystatus);
359  }
360  fObject->addValues(*fCondObject);
361  delete fCondObject;
362  // }
363  }
364  return true;
365 }
366 
367 
368 bool dumpObject (std::ostream& fOutput, const CastorChannelQuality& fObject) {
369  char buffer [1024];
370  sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
371  fOutput << buffer;
372  std::vector<DetId> channels = fObject.getAllChannels ();
373  std::sort (channels.begin(), channels.end(), DetIdLess ());
374  for (std::vector<DetId>::iterator channel = channels.begin ();
375  channel != channels.end ();
376  channel++) {
377  const int value = fObject.getValues (*channel)->getValue ();
378  dumpId (fOutput, *channel);
379  sprintf (buffer, " %15X %10X\n",
380  value, channel->rawId ());
381  fOutput << buffer;
382  }
383  return true;
384 }
385 
386 
387 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
388 bool getObject (std::istream& fInput, CastorPedestalWidths* fObject) {
389  if (!fObject) fObject = new CastorPedestalWidths(false);
390  char buffer [1024];
391  int linecounter = 0;
392 
393  while (fInput.getline(buffer, 1024)) {
394  linecounter++;
395  std::vector <std::string> items = splitString (std::string (buffer));
396  if (items.size()==0) continue; // blank line
397  else {
398  if (items[0] == (std::string)"#U")
399  {
400  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
401  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
402  else
403  {
404  edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
405  fObject->setUnitADC(false);
406  }
407  break;
408  }
409  else
410  {
411  edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
412  return false;
413  }
414  }
415  }
416 
417  while (fInput.getline(buffer, 1024)) {
418  linecounter++;
419  if (buffer [0] == '#') continue; //ignore comment
420  std::vector <std::string> items = splitString (std::string (buffer));
421  if (items.size()==0) continue; // blank line
422  if (items.size () < 14) {
423  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
424  << " or 20 items: eta, phi, depth, subdet, 16x correlations"
425  << std::endl;
426  continue;
427  }
428  DetId id = getId (items);
429 
430 // if (fObject->exists(id) )
431 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
432 // else
433 // {
434 
435  if (items.size() < 20) //old format
436  {
438  values.setSigma (0, 0, atof (items [4].c_str()));
439  values.setSigma (1, 0, atof (items [5].c_str()));
440  values.setSigma (1, 1, atof (items [6].c_str()));
441  values.setSigma (2, 0, atof (items [7].c_str()));
442  values.setSigma (2, 1, atof (items [8].c_str()));
443  values.setSigma (2, 2, atof (items [9].c_str()));
444  values.setSigma (3, 0, atof (items [10].c_str()));
445  values.setSigma (3, 1, atof (items [11].c_str()));
446  values.setSigma (3, 2, atof (items [12].c_str()));
447  values.setSigma (3, 3, atof (items [13].c_str()));
448  values.setSigma (0, 1, 0.);
449  values.setSigma (0, 2, 0.);
450  values.setSigma (0, 3, 0.);
451  values.setSigma (1, 2, 0.);
452  values.setSigma (1, 3, 0.);
453  values.setSigma (2, 3, 0.);
454  fObject->addValues(values);
455  }
456  else // new format
457  {
459  values.setSigma (0, 0, atof (items [4].c_str()) );
460  values.setSigma (0, 1, atof (items [5].c_str()) );
461  values.setSigma (0, 2, atof (items [6].c_str()) );
462  values.setSigma (0, 3, atof (items [7].c_str()) );
463  values.setSigma (1, 0, atof (items [8].c_str()) );
464  values.setSigma (1, 1, atof (items [9].c_str()) );
465  values.setSigma (1, 2, atof (items [10].c_str()) );
466  values.setSigma (1, 3, atof (items [11].c_str()) );
467  values.setSigma (2, 0, atof (items [12].c_str()) );
468  values.setSigma (2, 1, atof (items [13].c_str()) );
469  values.setSigma (2, 2, atof (items [14].c_str()) );
470  values.setSigma (2, 3, atof (items [15].c_str()) );
471  values.setSigma (3, 0, atof (items [16].c_str()) );
472  values.setSigma (3, 1, atof (items [17].c_str()) );
473  values.setSigma (3, 2, atof (items [18].c_str()) );
474  values.setSigma (3, 3, atof (items [19].c_str()) );
475  fObject->addValues(values);
476  }
477 
478  // }
479  }
480  return true;
481 }
482 
483 bool dumpObject (std::ostream& fOutput, const CastorPedestalWidths& fObject) {
484  char buffer [1024];
485  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
486  else sprintf (buffer, "#U fC << this is the unit \n");
487  fOutput << buffer;
488 
489  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
490  "eta", "phi", "dep", "det",
491  "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",
492  "DetId");
493  fOutput << buffer;
494  std::vector<DetId> channels = fObject.getAllChannels ();
495  std::sort (channels.begin(), channels.end(), DetIdLess ());
496  for (std::vector<DetId>::iterator channel = channels.begin ();
497  channel != channels.end ();
498  channel++) {
499  const CastorPedestalWidth* item = fObject.getValues (*channel);
500  if (item) {
501  dumpId (fOutput, *channel);
502  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",
503  item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3),
504  item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
505  item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
506  item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
507  fOutput << buffer;
508  }
509  }
510  return true;
511 }
512 
513 
514 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
515 bool getObject (std::istream& fInput, CastorQIEData* fObject) {
516  char buffer [1024];
517  while (fInput.getline(buffer, 1024)) {
518  if (buffer [0] == '#') continue; //ignore comment
519  std::vector <std::string> items = splitString (std::string (buffer));
520  if (items.size()<1) continue;
521  if (items [0] == "SHAPE") { // basic shape
522  if (items.size () < 33) {
523  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;
524  continue;
525  }
526  //float lowEdges [32];
527  //int i = 32;
528  //while (--i >= 0) lowEdges [i] = atof (items [i+1].c_str ());
529  // fObject->setShape (lowEdges);
530  }
531  else { // QIE parameters
532  if (items.size () < 36) {
533  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;
534  continue;
535  }
536  DetId id = getId (items);
537  fObject->sort ();
538  // try {
539  // fObject->getCoder (id);
540  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
541  // }
542 // catch (cms::Exception& e) {
543  CastorQIECoder coder (id.rawId ());
544  int index = 4;
545  for (unsigned capid = 0; capid < 4; capid++) {
546  for (unsigned range = 0; range < 4; range++) {
547  coder.setOffset (capid, range, atof (items [index++].c_str ()));
548  }
549  }
550  for (unsigned capid = 0; capid < 4; capid++) {
551  for (unsigned range = 0; range < 4; range++) {
552  coder.setSlope (capid, range, atof (items [index++].c_str ()));
553  }
554  }
555  fObject->addCoder (coder);
556 // }
557  }
558  }
559  fObject->sort ();
560  return true;
561 }
562 
563 bool dumpObject (std::ostream& fOutput, const CastorQIEData& fObject) {
564  char buffer [1024];
565  fOutput << "# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
566  sprintf (buffer, "SHAPE ");
567  fOutput << buffer;
568  for (unsigned bin = 0; bin < 32; bin++) {
569  sprintf (buffer, " %8.5f", fObject.getShape ().lowEdge (bin));
570  fOutput << buffer;
571  }
572  fOutput << std::endl;
573 
574  fOutput << "# QIE data" << std::endl;
575  sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
576  "eta", "phi", "dep", "det",
577  "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
578  "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
579  fOutput << buffer;
580  std::vector<DetId> channels = fObject.getAllChannels ();
581  std::sort (channels.begin(), channels.end(), DetIdLess ());
582  for (std::vector<DetId>::iterator channel = channels.begin ();
583  channel != channels.end ();
584  channel++) {
585  const CastorQIECoder* coder = fObject.getCoder (*channel);
586  dumpId (fOutput, *channel);
587  for (unsigned capid = 0; capid < 4; capid++) {
588  for (unsigned range = 0; range < 4; range++) {
589  sprintf (buffer, " %8.5f", coder->offset (capid, range));
590  fOutput << buffer;
591  }
592  }
593  for (unsigned capid = 0; capid < 4; capid++) {
594  for (unsigned range = 0; range < 4; range++) {
595  sprintf (buffer, " %8.5f", coder->slope (capid, range));
596  fOutput << buffer;
597  }
598  }
599  fOutput << std::endl;
600  }
601  return true;
602 }
603 
604 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
605 bool getObject (std::istream& fInput, CastorCalibrationQIEData* fObject) {
606  char buffer [1024];
607  while (fInput.getline(buffer, 1024)) {
608  if (buffer [0] == '#') continue; //ignore comment
609  std::vector <std::string> items = splitString (std::string (buffer));
610  if (items.size () < 36) {
611  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
612  continue;
613  }
614  DetId id = getId (items);
615  fObject->sort ();
616  // try {
617  // fObject->getCoder (id);
618  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
619  // }
620 // catch (cms::Exception& e) {
621  CastorCalibrationQIECoder coder (id.rawId ());
622  int index = 4;
623  float values [32];
624  for (unsigned bin = 0; bin < 32; bin++) {
625  values[bin] = atof (items [index++].c_str ());
626  }
627  coder.setMinCharges (values);
628  fObject->addCoder (coder);
629 // }
630  }
631  fObject->sort ();
632  return true;
633 }
634 
635 bool dumpObject (std::ostream& fOutput, const CastorCalibrationQIEData& fObject) {
636  char buffer [1024];
637  fOutput << "# QIE data in calibration mode" << std::endl;
638  sprintf (buffer, "# %15s %15s %15s %15s %288s\n",
639  "eta", "phi", "dep", "det", "32 x charges");
640  fOutput << buffer;
641  std::vector<DetId> channels = fObject.getAllChannels ();
642  std::sort (channels.begin(), channels.end(), DetIdLess ());
643  for (std::vector<DetId>::iterator channel = channels.begin ();
644  channel != channels.end ();
645  channel++) {
646  const CastorCalibrationQIECoder* coder = fObject.getCoder (*channel);
647  if (coder) {
648  dumpId (fOutput, *channel);
649  const float* lowEdge = coder->minCharges ();
650  for (unsigned bin = 0; bin < 32; bin++) {
651  sprintf (buffer, " %8.5f", lowEdge [bin]);
652  fOutput << buffer;
653  }
654  fOutput << std::endl;
655  }
656  }
657  return true;
658 }
659 
660 
661 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
662 bool getObject (std::istream& fInput, CastorElectronicsMap* fObject) {
663  char buffer [1024];
664  while (fInput.getline(buffer, 1024)) {
665  if (buffer [0] == '#') continue; //ignore comment
666  std::vector <std::string> items = splitString (std::string (buffer));
667  if (items.size () < 12) {
668  if (items.size()==0) continue; // no warning here
669  if (items.size()<9) {
670  edm::LogError("MapFormat") << "CastorElectronicsMap-> line too short: " << buffer;
671  continue;
672  }
673  if (items[8]=="NA" || items[8]=="NT") {
674  while (items.size()<12) items.push_back(""); // don't worry here
675  } else if (items[8]=="HT") {
676  if (items.size()==11) items.push_back("");
677  else {
678  edm::LogError("MapFormat") << "CastorElectronicsMap-> Bad line: " << buffer
679  << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
680  continue;
681  }
682  } else {
683  edm::LogError("MapFormat") << "CastorElectronicsMap-> Bad line: " << buffer
684  << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
685  continue;
686  }
687  }
688  // std::cout << "CastorElectronicsMap-> processing line: " << buffer << std::endl;
689  int crate = atoi (items [1].c_str());
690  int slot = atoi (items [2].c_str());
691  int top = 1;
692  if (items [3] == "b") top = 0;
693  int dcc = atoi (items [4].c_str());
694  int spigot = atoi (items [5].c_str());
695  CastorElectronicsId elId;
696  if (items[8] == "HT" || items[8] == "NT") {
697  int slb = atoi (items [6].c_str());
698  int slbCh = atoi (items [7].c_str());
699  elId=CastorElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
700  } else {
701  int fiber = atoi (items [6].c_str());
702  int fiberCh = atoi (items [7].c_str());
703 
704  elId=CastorElectronicsId(fiberCh, fiber, spigot, dcc);
705  elId.setHTR (crate, slot, top);
706  }
707 
708  // first, handle undefined cases
709  if (items [8] == "NA") { // undefined channel
710  fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
711  } else if (items [8] == "NT") { // undefined trigger channel
713  } else {
714  CastorText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
715  if (converter.isHcalCastorDetId ()) {
716  fObject->mapEId2chId (elId, converter.getId ());
717  }
718  else {
719  edm::LogWarning("Format Error") << "CastorElectronicsMap-> Unknown subdetector: "
720  << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
721  }
722  }
723  }
724  fObject->sort ();
725  return true;
726 }
727 
728 bool dumpObject (std::ostream& fOutput, const CastorElectronicsMap& fObject) {
729  std::vector<CastorElectronicsId> eids = fObject.allElectronicsId ();
730  char buf [1024];
731  // changes by Jared, 6.03.09/(included 25.03.09)
732  // sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
733  sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
734  "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
735  fOutput << buf << std::endl;
736 
737  for (unsigned i = 0; i < eids.size (); i++) {
738  CastorElectronicsId eid = eids[i];
739  if (eid.isTriggerChainId()) {
740  DetId trigger = fObject.lookupTrigger (eid);
741  if (trigger.rawId ()) {
742  CastorText2DetIdConverter converter (trigger);
743  // changes by Jared, 6.03.09/(included 25.03.09)
744  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
745  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
746  // i,
747  converter.getId().rawId(),
748  // changes by Jared, 6.03.09/(included 25.03.09)
749  // eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
750  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
751  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
752  );
753  fOutput << buf << std::endl;
754  }
755  } else {
756  DetId channel = fObject.lookup (eid);
757  if (channel.rawId()) {
758  CastorText2DetIdConverter converter (channel);
759  // changes by Jared, 6.03.09/(included 25.03.09)
760  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
761  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
762  // i,
763  converter.getId().rawId(),
764  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
765  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
766  );
767  fOutput << buf << std::endl;
768  }
769  }
770  }
771  return true;
772 }
773 
774 bool getObject (std::istream& fInput, CastorRecoParams* fObject) {
775  if (!fObject) fObject = new CastorRecoParams();
776  char buffer [1024];
777  while (fInput.getline(buffer, 1024)) {
778  if (buffer [0] == '#') continue; //ignore comment
779  std::vector <std::string> items = splitString (std::string (buffer));
780  if (items.size()==0) continue; // blank line
781  if (items.size () < 6) {
782  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, firstSample, samplesToAdd" << std::endl;
783  continue;
784  }
785  DetId id = getId (items);
786 
787  CastorRecoParam* fCondObject = new CastorRecoParam(id, atoi (items [4].c_str()), atoi (items [5].c_str()) );
788  fObject->addValues(*fCondObject);
789  delete fCondObject;
790  }
791  return true;
792 }
793 
794 bool dumpObject (std::ostream& fOutput, const CastorRecoParams& fObject) {
795  char buffer [1024];
796  sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
797  fOutput << buffer;
798  std::vector<DetId> channels = fObject.getAllChannels ();
799  std::sort (channels.begin(), channels.end(), DetIdLess ());
800  for (std::vector<DetId>::iterator channel = channels.begin();channel != channels.end();channel++) {
801  dumpId (fOutput, *channel);
802  sprintf (buffer, " %15d %15d %16X\n",
803  fObject.getValues (*channel)->firstSample(), fObject.getValues (*channel)->samplesToAdd(), channel->rawId ());
804  fOutput << buffer;
805  }
806  return true;
807 }
808 
809 }
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
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 first
Definition: L1TdeRCT.cc:94
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
unsigned int firstSample() const
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)
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:44