CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDbASCIIIO.cc
Go to the documentation of this file.
1 
2 //
3 // F.Ratnikov (UMd), Oct 28, 2005
4 // $Id: HcalDbASCIIIO.cc,v 1.56 2010/04/26 18:51:36 devildog Exp $
5 //
6 #include <vector>
7 #include <string>
8 #include <cstdio>
9 #include <sstream>
10 
15 
19 
20 namespace {
21  class DetIdLess {
22  public:
23  bool operator () (DetId fFirst, DetId fSecond) const {
24  HcalGenericDetId first (fFirst);
25  HcalGenericDetId second (fSecond);
26  if (first.genericSubdet () != second.genericSubdet ()) return first.genericSubdet () < second.genericSubdet ();
27  if (first.isHcalDetId ()) {
28  HcalDetId f1 (first);
29  HcalDetId s1 (second);
30  return f1.zside () != s1.zside () ? f1.zside () < s1.zside () :
31  f1.iphi () != s1.iphi () ? f1.iphi () < s1.iphi () :
32  f1.ietaAbs () != s1.ietaAbs () ? f1.ietaAbs () < s1.ietaAbs () :
33  f1.depth () < s1.depth ();
34  }
35  else {
36  return first.rawId() < second.rawId();
37  }
38  }
39  };
40  class HcalElectronicsIdLess {
41  public:
42  bool operator () (HcalElectronicsId first, HcalElectronicsId second) const {
43  return
44  first.readoutVMECrateId () != second.readoutVMECrateId () ? first.readoutVMECrateId () < second.readoutVMECrateId () :
45  first.htrSlot () != second.htrSlot () ? first.htrSlot () < second.htrSlot () :
46  first.htrTopBottom () != second.htrTopBottom () ? first.htrTopBottom () < second.htrTopBottom () :
47  first.fiberIndex () != second.fiberIndex () ? first.fiberIndex () < second.fiberIndex () :
48  first.fiberChanId () < second.fiberChanId ();
49  }
50  };
51 }
52 
53 std::vector <std::string> splitString (const std::string& fLine) {
54  std::vector <std::string> result;
55  int start = 0;
56  bool empty = true;
57  for (unsigned i = 0; i <= fLine.size (); i++) {
58  if (fLine [i] == ' ' || i == fLine.size ()) {
59  if (!empty) {
60  std::string item (fLine, start, i-start);
61  result.push_back (item);
62  empty = true;
63  }
64  start = i+1;
65  }
66  else {
67  if (empty) empty = false;
68  }
69  }
70  return result;
71 }
72 
73 DetId HcalDbASCIIIO::getId (const std::vector <std::string> & items) {
74  HcalText2DetIdConverter converter (items [3], items [0], items [1], items [2]);
75  return converter.getId ();
76 }
77 
78 void HcalDbASCIIIO::dumpId (std::ostream& fOutput, DetId id) {
79  HcalText2DetIdConverter converter (id);
80  char buffer [1024];
81  sprintf (buffer, " %15s %15s %15s %15s",
82  converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
83  fOutput << buffer;
84 }
85 
86 template<class T>
87 bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
88  std::istringstream iss(s);
89  return !(iss >> f >> t).fail();
90 }
91 
92 template <class T,class S>
93 bool getHcalObject (std::istream& fInput, T* fObject, S* fCondObject) {
94  if (!fObject) fObject = new T;
95  char buffer [1024];
96  while (fInput.getline(buffer, 1024)) {
97  if (buffer [0] == '#') continue; //ignore comment
98  std::vector <std::string> items = splitString (std::string (buffer));
99  if (items.size()==0) continue; // blank line
100  if (items.size () < 8) {
101  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values" << std::endl;
102  continue;
103  }
104  DetId id = HcalDbASCIIIO::getId (items);
105 
106 // if (fObject->exists(id) )
107 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
108 // else
109 // {
110  fCondObject = new S(id, atof (items [4].c_str()), atof (items [5].c_str()),
111  atof (items [6].c_str()), atof (items [7].c_str()));
112  fObject->addValues(*fCondObject);
113  delete fCondObject;
114  // }
115  }
116 
117  return true;
118 }
119 
120 template <class T>
121 bool dumpHcalObject (std::ostream& fOutput, const T& fObject) {
122  char buffer [1024];
123  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n", "eta", "phi", "dep", "det", "cap0", "cap1", "cap2", "cap3", "DetId");
124  fOutput << buffer;
125  std::vector<DetId> channels = fObject.getAllChannels ();
126  std::sort (channels.begin(), channels.end(), DetIdLess ());
127  for (std::vector<DetId>::iterator channel = channels.begin ();
128  channel != channels.end ();
129  channel++) {
130  const float* values = fObject.getValues (*channel)->getValues ();
131  if (values) {
132  HcalDbASCIIIO::dumpId (fOutput, *channel);
133  sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %10X\n",
134  values[0], values[1], values[2], values[3], channel->rawId ());
135  fOutput << buffer;
136  }
137  }
138  return true;
139 }
140 
141 template <class T,class S>
142 bool getHcalSingleFloatObject (std::istream& fInput, T* fObject, S* fCondObject) {
143  if (!fObject) fObject = new T;
144  char buffer [1024];
145  while (fInput.getline(buffer, 1024)) {
146  if (buffer [0] == '#') continue; //ignore comment
147  std::vector <std::string> items = splitString (std::string (buffer));
148  if (items.size()==0) continue; // blank line
149  if (items.size () < 5) {
150  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, value" << std::endl;
151  continue;
152  }
153  DetId id = HcalDbASCIIIO::getId (items);
154 
155 // if (fObject->exists(id) )
156 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
157 // else
158 // {
159  fCondObject = new S(id, atof (items [4].c_str()) );
160  fObject->addValues(*fCondObject);
161  delete fCondObject;
162  // }
163  }
164  return true;
165 }
166 
167 template <class T>
168 bool dumpHcalSingleFloatObject (std::ostream& fOutput, const T& fObject) {
169  char buffer [1024];
170  sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
171  fOutput << buffer;
172  std::vector<DetId> channels = fObject.getAllChannels ();
173  std::sort (channels.begin(), channels.end(), DetIdLess ());
174  for (std::vector<DetId>::iterator channel = channels.begin ();
175  channel != channels.end ();
176  channel++) {
177  const float value = fObject.getValues (*channel)->getValue ();
178  HcalDbASCIIIO::dumpId (fOutput, *channel);
179  sprintf (buffer, " %8.5f %10X\n",
180  value, channel->rawId ());
181  fOutput << buffer;
182  }
183  return true;
184 }
185 
186 template <class T,class S>
187 bool getHcalSingleIntObject (std::istream& fInput, T* fObject, S* fCondObject) {
188  if (!fObject) fObject = new T;
189  char buffer [1024];
190  while (fInput.getline(buffer, 1024)) {
191  if (buffer [0] == '#') continue; //ignore comment
192  std::vector <std::string> items = splitString (std::string (buffer));
193  if (items.size()==0) continue; // blank line
194  if (items.size () < 5) {
195  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, value" << std::endl;
196  continue;
197  }
198  DetId id = HcalDbASCIIIO::getId (items);
199 
200 // if (fObject->exists(id) )
201 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
202 // else
203 // {
204  fCondObject = new S(id, atoi (items [4].c_str()) );
205  fObject->addValues(*fCondObject);
206  delete fCondObject;
207  // }
208  }
209  return true;
210 }
211 
212 template <class T>
213 bool dumpHcalSingleIntObject (std::ostream& fOutput, const T& fObject) {
214  char buffer [1024];
215  sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
216  fOutput << buffer;
217  std::vector<DetId> channels = fObject.getAllChannels ();
218  std::sort (channels.begin(), channels.end(), DetIdLess ());
219  for (std::vector<DetId>::iterator channel = channels.begin ();
220  channel != channels.end ();
221  channel++) {
222  const int value = fObject.getValues (*channel)->getValue ();
223  HcalDbASCIIIO::dumpId (fOutput, *channel);
224  sprintf (buffer, " %15d %10X\n",
225  value, channel->rawId ());
226  fOutput << buffer;
227  }
228  return true;
229 }
230 
231 template <class T,class S>
232 bool getHcalMatrixObject (std::istream& fInput, T* fObject, S* fCondObject) {
233  if (!fObject) fObject = new T;
234  char buffer [1024];
235  while (fInput.getline(buffer, 1024)) {
236  if (buffer [0] == '#') continue; //ignore comment
237  std::vector <std::string> items = splitString (std::string (buffer));
238  if (items.size()==0) continue; // blank line
239  DetId firstid = HcalDbASCIIIO::getId (items);
240  fCondObject = new S(firstid.rawId());
241  for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), 0, j, atof(items[j+5].c_str()));
242  for(int i = 1; i != 40; i++){
243  fInput.getline(buffer, 1024);
244  items = splitString (std::string (buffer));
245  DetId id = HcalDbASCIIIO::getId (items);
246  if(id.rawId() != firstid.rawId()) break;//throw cms::Exception("Wrong number of elements");
247  for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), i%10, j, atof(items[j+5].c_str()));
248  }
249  fObject->addValues(*fCondObject);
250  delete fCondObject;
251  }
252  return true;
253 }
254 
255 template <class T>
256 bool dumpHcalMatrixObject (std::ostream& fOutput, const T& fObject) {
257  char buffer [1024];
258  sprintf (buffer, "# %5s %5s %5s %5s %5s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
259  "eta", "phi", "dep", "det", "capid","c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "DetId");
260  fOutput << buffer;
261  std::vector<DetId> channels = fObject.getAllChannels ();
262  std::sort (channels.begin(), channels.end(), DetIdLess ());
263  for (std::vector<DetId>::iterator channel = channels.begin ();
264  channel != channels.end ();
265  channel++) {
266  float thisline[10];
267  for(int m = 0; m != 4; m++){
268  for(int i = 0; i != 10; i++){
269  for(int j = 0; j != 10; j++){
270 // std::cout <<"test "<<(fObject.getValues(*channel))->getValue(0,0,0);
271  thisline[j] = fObject.getValues(*channel)->getValue(m,i,j);
272 // thisline[j] = fObject.getValues(*channel)->getValue(1,1,1);
273  }
274  HcalDbASCIIIO::dumpId (fOutput, *channel);
275  sprintf(buffer, " %5i %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
276  m, thisline[0], thisline[1], thisline[2], thisline[3], thisline[4], thisline[5], thisline[6], thisline[7],
277  thisline[8], thisline[9], channel->rawId());
278  fOutput << buffer;
279  }
280  }
281  }
282 
283  return true;
284 }
285 
286 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalGains* fObject) {return getHcalObject (fInput, fObject, new HcalGain);}
287 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalGains& fObject) {return dumpHcalObject (fOutput, fObject);}
288 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalGainWidths* fObject) {return getHcalObject (fInput, fObject, new HcalGainWidth);}
289 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalGainWidths& fObject) {return dumpHcalObject (fOutput, fObject);}
290 
291 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalRespCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalRespCorr); }
292 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalRespCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
293 
294 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLUTCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalLUTCorr); }
295 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLUTCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
296 
297 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPFCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalPFCorr); }
298 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPFCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
299 
300 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTimeCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalTimeCorr); }
301 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTimeCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
302 
303 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalZSThresholds* fObject) {return getHcalSingleIntObject (fInput, fObject, new HcalZSThreshold); }
304 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalZSThresholds& fObject) {return dumpHcalSingleIntObject (fOutput, fObject); }
305 
306 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalValidationCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalValidationCorr); }
307 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalValidationCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
308 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCholeskyMatrices* fObject) {return getHcalMatrixObject (fInput, fObject, new HcalCholeskyMatrix); }
309 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCholeskyMatrices& fObject) {return dumpHcalMatrixObject (fOutput, fObject); }
310 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCovarianceMatrices* fObject) {return getHcalMatrixObject (fInput, fObject, new HcalCovarianceMatrix); }
311 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCovarianceMatrices& fObject) {return dumpHcalMatrixObject (fOutput, fObject); }
312 
313 
314 
315 
316 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
317 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestals* fObject) {
318  if (!fObject) fObject = new HcalPedestals(false);
319  char buffer [1024];
320 
321  while (fInput.getline(buffer, 1024)) {
322  std::vector <std::string> items = splitString (std::string (buffer));
323  if (items.size()==0) continue; // blank line
324  else {
325  if (items[0] == "#U")
326  {
327  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
328  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
329  else
330  {
331  edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
332  fObject->setUnitADC(false);
333  }
334  break;
335  }
336  else
337  {
338  edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
339  return false;
340  }
341  }
342  }
343  while (fInput.getline(buffer, 1024)) {
344  if (buffer [0] == '#') continue;
345  std::vector <std::string> items = splitString (std::string (buffer));
346  if (items.size()==0) continue; // blank line
347  if (items.size () < 8) {
348  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
349  << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
350  << std::endl;
351  continue;
352  }
353  DetId id = getId (items);
354 
355 // if (fObject->exists(id) )
356 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
357 // else
358 // {
359 
360  if (items.size() < 12) // old format without widths
361  {
362  HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
363  atof (items [6].c_str()), atof (items [7].c_str()),
364  0., 0., 0., 0. );
365  fObject->addValues(*fCondObject);
366  delete fCondObject;
367  }
368  else // new format with widths
369  {
370  HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
371  atof (items [6].c_str()), atof (items [7].c_str()),
372  atof (items [8].c_str()), atof (items [9].c_str()),
373  atof (items [10].c_str()), atof (items [11].c_str()) );
374  fObject->addValues(*fCondObject);
375  delete fCondObject;
376  }
377 
378  // }
379  }
380  return true;
381 }
382 
383 
384 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestals& fObject) {
385  char buffer [1024];
386  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
387  else sprintf (buffer, "#U fC << this is the unit \n");
388  fOutput << buffer;
389 
390  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");
391  fOutput << buffer;
392 
393  std::vector<DetId> channels = fObject.getAllChannels ();
394  std::sort (channels.begin(), channels.end(), DetIdLess ());
395  for (std::vector<DetId>::iterator channel = channels.begin ();
396  channel != channels.end ();
397  channel++) {
398  const float* values = fObject.getValues (*channel)->getValues ();
399  if (values) {
400  dumpId (fOutput, *channel);
401  sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
402  values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
403  fOutput << buffer;
404  }
405  }
406  return true;
407 }
408 
409 
410 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
411 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalChannelQuality* fObject)
412 {
413  if (!fObject) fObject = new HcalChannelQuality;
414  char buffer [1024];
415  while (fInput.getline(buffer, 1024)) {
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 () < 6) {
420  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, base - either (hex) or (dec), value" << std::endl;
421  continue;
422  }
423  DetId id = getId (items);
424 
425 // if (fObject->exists(id) )
426 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
427 // else
428 // {
429  uint32_t mystatus;
430  if (items[4] == "(hex)")
431  sscanf(items[5].c_str(),"%X", &mystatus);
432  else if (items[4] == "(dec)")
433  sscanf(items[5].c_str(),"%u", &mystatus);
434  else
435  {
436  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
437  continue;
438  }
439 
440  HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus); //atoi (items [4].c_str()) );
441  fObject->addValues(*fCondObject);
442  delete fCondObject;
443  // }
444  }
445  return true;
446 }
447 
448 
449 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalChannelQuality& fObject) {
450  char buffer [1024];
451  sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
452  fOutput << buffer;
453  std::vector<DetId> channels = fObject.getAllChannels ();
454  std::sort (channels.begin(), channels.end(), DetIdLess ());
455  for (std::vector<DetId>::iterator channel = channels.begin ();
456  channel != channels.end ();
457  channel++) {
458  const int value = fObject.getValues (*channel)->getValue ();
459  dumpId (fOutput, *channel);
460  sprintf (buffer, "%6s %15X %10X\n", "(hex)",
461  value, channel->rawId ());
462  fOutput << buffer;
463  }
464  return true;
465 }
466 
467 
468 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
469 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalL1TriggerObjects* fObject)
470 {
471  if (!fObject) fObject = new HcalL1TriggerObjects;
472  char buffer [1024];
473 
474  while (fInput.getline(buffer, 1024)) {
475  if (buffer [0] == '#')
476  {
477  if (buffer [1] == 'T') // contains tag name
478  {
479  std::vector <std::string> items = splitString (std::string (buffer) );
480  fObject->setTagString(items[1]);
481  continue;
482  }
483  if (buffer [1] == 'A') // contains algo name
484  {
485  std::vector <std::string> items = splitString (std::string (buffer) );
486  fObject->setAlgoString(items[1]);
487  continue;
488  }
489  else continue; //ignore comment
490  }
491  std::vector <std::string> items = splitString (std::string (buffer));
492  if (items.size()==0) continue; // blank line
493  if (items.size () < 7) {
494  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
495  continue;
496  }
497  DetId id = getId (items);
498 
499  HcalL1TriggerObject* fCondObject = new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()) );
500 
501  fObject->addValues(*fCondObject);
502  delete fCondObject;
503  }
504  return true;
505 }
506 
507 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalL1TriggerObjects& fObject)
508 {
509  char buffer [1024];
510  //first print tag and algo
511  sprintf (buffer, "#T %s << this is the tag name \n", fObject.getTagString().c_str() );
512  fOutput << buffer;
513  sprintf (buffer, "#A %s << this is the algorithm name \n", fObject.getAlgoString().c_str() );
514  fOutput << buffer;
515 
516  //then the values
517  sprintf (buffer, "# %15s %15s %15s %15s %8s %13s %8s %10s\n",
518  "eta", "phi", "dep", "det", "ped", "respcorrgain", "flag",
519  "DetId");
520  fOutput << buffer;
521  std::vector<DetId> channels = fObject.getAllChannels ();
522  // std::sort (channels.begin(), channels.end(), DetIdLess ());
523  for (std::vector<DetId>::iterator channel = channels.begin ();
524  channel != channels.end ();
525  channel++) {
526  const HcalL1TriggerObject* item = fObject.getValues (*channel);
527  if (item) {
528  dumpId (fOutput, *channel);
529  sprintf (buffer, " %10.7f %10.7f %12d %10X\n",
530  item->getPedestal(), item->getRespGain(), item->getFlag(), channel->rawId ());
531  fOutput << buffer;
532  }
533  }
534  return true;
535 
536 }
537 
538 
539 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
540 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestalWidths* fObject) {
541  if (!fObject) fObject = new HcalPedestalWidths(false);
542  char buffer [1024];
543  int linecounter = 0;
544 
545  while (fInput.getline(buffer, 1024)) {
546  linecounter++;
547  std::vector <std::string> items = splitString (std::string (buffer));
548  if (items.size()==0) continue; // blank line
549  else {
550  if (items[0] == (std::string)"#U")
551  {
552  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
553  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
554  else
555  {
556  edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
557  fObject->setUnitADC(false);
558  }
559  break;
560  }
561  else
562  {
563  edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
564  return false;
565  }
566  }
567  }
568 
569  while (fInput.getline(buffer, 1024)) {
570  linecounter++;
571  if (buffer [0] == '#') continue; //ignore comment
572  std::vector <std::string> items = splitString (std::string (buffer));
573  if (items.size()==0) continue; // blank line
574  if (items.size () < 14) {
575  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
576  << " or 20 items: eta, phi, depth, subdet, 16x correlations"
577  << std::endl;
578  continue;
579  }
580  DetId id = getId (items);
581 
582 // if (fObject->exists(id) )
583 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
584 // else
585 // {
586 
587  if (items.size() < 20) //old format
588  {
590  values.setSigma (0, 0, atof (items [4].c_str()));
591  values.setSigma (1, 0, atof (items [5].c_str()));
592  values.setSigma (1, 1, atof (items [6].c_str()));
593  values.setSigma (2, 0, atof (items [7].c_str()));
594  values.setSigma (2, 1, atof (items [8].c_str()));
595  values.setSigma (2, 2, atof (items [9].c_str()));
596  values.setSigma (3, 0, atof (items [10].c_str()));
597  values.setSigma (3, 1, atof (items [11].c_str()));
598  values.setSigma (3, 2, atof (items [12].c_str()));
599  values.setSigma (3, 3, atof (items [13].c_str()));
600  values.setSigma (0, 1, 0.);
601  values.setSigma (0, 2, 0.);
602  values.setSigma (0, 3, 0.);
603  values.setSigma (1, 2, 0.);
604  values.setSigma (1, 3, 0.);
605  values.setSigma (2, 3, 0.);
606  fObject->addValues(values);
607  }
608  else // new format
609  {
611  values.setSigma (0, 0, atof (items [4].c_str()) );
612  values.setSigma (0, 1, atof (items [5].c_str()) );
613  values.setSigma (0, 2, atof (items [6].c_str()) );
614  values.setSigma (0, 3, atof (items [7].c_str()) );
615  values.setSigma (1, 0, atof (items [8].c_str()) );
616  values.setSigma (1, 1, atof (items [9].c_str()) );
617  values.setSigma (1, 2, atof (items [10].c_str()) );
618  values.setSigma (1, 3, atof (items [11].c_str()) );
619  values.setSigma (2, 0, atof (items [12].c_str()) );
620  values.setSigma (2, 1, atof (items [13].c_str()) );
621  values.setSigma (2, 2, atof (items [14].c_str()) );
622  values.setSigma (2, 3, atof (items [15].c_str()) );
623  values.setSigma (3, 0, atof (items [16].c_str()) );
624  values.setSigma (3, 1, atof (items [17].c_str()) );
625  values.setSigma (3, 2, atof (items [18].c_str()) );
626  values.setSigma (3, 3, atof (items [19].c_str()) );
627  fObject->addValues(values);
628  }
629 
630  // }
631  }
632  return true;
633 }
634 
635 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestalWidths& fObject) {
636  char buffer [1024];
637  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
638  else sprintf (buffer, "#U fC << this is the unit \n");
639  fOutput << buffer;
640 
641  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
642  "eta", "phi", "dep", "det",
643  "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",
644  "DetId");
645  fOutput << buffer;
646  std::vector<DetId> channels = fObject.getAllChannels ();
647  std::sort (channels.begin(), channels.end(), DetIdLess ());
648  for (std::vector<DetId>::iterator channel = channels.begin ();
649  channel != channels.end ();
650  channel++) {
651  const HcalPedestalWidth* item = fObject.getValues (*channel);
652  if (item) {
653  dumpId (fOutput, *channel);
654  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",
655  item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3),
656  item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
657  item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
658  item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
659  fOutput << buffer;
660  }
661  }
662  return true;
663 }
664 
665 
666 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
667 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalQIEData* fObject) {
668  char buffer [1024];
669  while (fInput.getline(buffer, 1024)) {
670  if (buffer [0] == '#') continue; //ignore comment
671  std::vector <std::string> items = splitString (std::string (buffer));
672  if (items.size()<1) continue;
673  if (items [0] == "SHAPE") { // basic shape
674  if (items.size () < 33) {
675  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;
676  continue;
677  }
678  float lowEdges [32];
679  int i = 32;
680  while (--i >= 0) lowEdges [i] = atof (items [i+1].c_str ());
681  // fObject->setShape (lowEdges);
682  }
683  else { // QIE parameters
684  if (items.size () < 36) {
685  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;
686  continue;
687  }
688  DetId id = getId (items);
689  fObject->sort ();
690  // try {
691  // fObject->getCoder (id);
692  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
693  // }
694 // catch (cms::Exception& e) {
695  HcalQIECoder coder (id.rawId ());
696  int index = 4;
697  for (unsigned capid = 0; capid < 4; capid++) {
698  for (unsigned range = 0; range < 4; range++) {
699  coder.setOffset (capid, range, atof (items [index++].c_str ()));
700  }
701  }
702  for (unsigned capid = 0; capid < 4; capid++) {
703  for (unsigned range = 0; range < 4; range++) {
704  coder.setSlope (capid, range, atof (items [index++].c_str ()));
705  }
706  }
707  fObject->addCoder (coder);
708 // }
709  }
710  }
711  fObject->sort ();
712  return true;
713 }
714 
715 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalQIEData& fObject) {
716  char buffer [1024];
717  fOutput << "# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
718  sprintf (buffer, "SHAPE ");
719  fOutput << buffer;
720  for (unsigned bin = 0; bin < 32; bin++) {
721  sprintf (buffer, " %8.5f", fObject.getShape ().lowEdge (bin));
722  fOutput << buffer;
723  }
724  fOutput << std::endl;
725 
726  fOutput << "# QIE data" << std::endl;
727  sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
728  "eta", "phi", "dep", "det",
729  "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
730  "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
731  fOutput << buffer;
732  std::vector<DetId> channels = fObject.getAllChannels ();
733  std::sort (channels.begin(), channels.end(), DetIdLess ());
734  for (std::vector<DetId>::iterator channel = channels.begin ();
735  channel != channels.end ();
736  channel++) {
737  const HcalQIECoder* coder = fObject.getCoder (*channel);
738  dumpId (fOutput, *channel);
739  for (unsigned capid = 0; capid < 4; capid++) {
740  for (unsigned range = 0; range < 4; range++) {
741  sprintf (buffer, " %8.5f", coder->offset (capid, range));
742  fOutput << buffer;
743  }
744  }
745  for (unsigned capid = 0; capid < 4; capid++) {
746  for (unsigned range = 0; range < 4; range++) {
747  sprintf (buffer, " %8.5f", coder->slope (capid, range));
748  fOutput << buffer;
749  }
750  }
751  fOutput << std::endl;
752  }
753  return true;
754 }
755 
756 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
757 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCalibrationQIEData* fObject) {
758  char buffer [1024];
759  while (fInput.getline(buffer, 1024)) {
760  if (buffer [0] == '#') continue; //ignore comment
761  std::vector <std::string> items = splitString (std::string (buffer));
762  if (items.size () < 36) {
763  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
764  continue;
765  }
766  DetId id = getId (items);
767  fObject->sort ();
768  // try {
769  // fObject->getCoder (id);
770  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
771  // }
772 // catch (cms::Exception& e) {
773  HcalCalibrationQIECoder coder (id.rawId ());
774  int index = 4;
775  float values [32];
776  for (unsigned bin = 0; bin < 32; bin++) {
777  values[bin] = atof (items [index++].c_str ());
778  }
779  coder.setMinCharges (values);
780  fObject->addCoder (coder);
781 // }
782  }
783  fObject->sort ();
784  return true;
785 }
786 
787 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
788  char buffer [1024];
789  fOutput << "# QIE data in calibration mode" << std::endl;
790  sprintf (buffer, "# %15s %15s %15s %15s %288s\n",
791  "eta", "phi", "dep", "det", "32 x charges");
792  fOutput << buffer;
793  std::vector<DetId> channels = fObject.getAllChannels ();
794  std::sort (channels.begin(), channels.end(), DetIdLess ());
795  for (std::vector<DetId>::iterator channel = channels.begin ();
796  channel != channels.end ();
797  channel++) {
798  const HcalCalibrationQIECoder* coder = fObject.getCoder (*channel);
799  if (coder) {
800  dumpId (fOutput, *channel);
801  const float* lowEdge = coder->minCharges ();
802  for (unsigned bin = 0; bin < 32; bin++) {
803  sprintf (buffer, " %8.5f", lowEdge [bin]);
804  fOutput << buffer;
805  }
806  fOutput << std::endl;
807  }
808  }
809  return true;
810 }
811 
812 
813 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
814 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalElectronicsMap* fObject) {
815  char buffer [1024];
816  while (fInput.getline(buffer, 1024)) {
817  if (buffer [0] == '#') continue; //ignore comment
818  std::vector <std::string> items = splitString (std::string (buffer));
819  if (items.size () < 12) {
820  if (items.size()==0) continue; // no warning here
821  if (items.size()<9) {
822  edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
823  continue;
824  }
825  if (items[8]=="NA" || items[8]=="NT") {
826  while (items.size()<12) items.push_back(""); // don't worry here
827  } else if (items[8]=="HT") {
828  if (items.size()==11) items.push_back("");
829  else {
830  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
831  << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
832  continue;
833  }
834  } else {
835  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
836  << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
837  continue;
838  }
839  }
840  // std::cout << "HcalElectronicsMap-> processing line: " << buffer << std::endl;
841  int crate = atoi (items [1].c_str());
842  int slot = atoi (items [2].c_str());
843  int top = 1;
844  if (items [3] == "b") top = 0;
845  int dcc = atoi (items [4].c_str());
846  int spigot = atoi (items [5].c_str());
847  HcalElectronicsId elId;
848  if (items[8] == "HT" || items[8] == "NT") {
849  int slb = atoi (items [6].c_str());
850  int slbCh = atoi (items [7].c_str());
851  elId=HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
852  } else {
853  int fiber = atoi (items [6].c_str());
854  int fiberCh = atoi (items [7].c_str());
855 
856  elId=HcalElectronicsId(fiberCh, fiber, spigot, dcc);
857  elId.setHTR (crate, slot, top);
858  }
859 
860  // first, handle undefined cases
861  if (items [8] == "NA") { // undefined channel
862  fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
863  } else if (items [8] == "NT") { // undefined trigger channel
865  } else {
866  HcalText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
867  if (converter.isHcalDetId ()) {
868  fObject->mapEId2chId (elId, converter.getId ());
869  }
870  else if (converter.isHcalTrigTowerDetId ()) {
871  fObject->mapEId2tId (elId, converter.getId ());
872  }
873  else if (converter.isHcalCalibDetId ()) {
874  fObject->mapEId2chId (elId, converter.getId ());
875  }
876  else if (converter.isHcalZDCDetId ()) {
877  fObject->mapEId2chId (elId, converter.getId ());
878  }
879  else {
880  edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: "
881  << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
882  }
883  }
884  }
885  fObject->sort ();
886  return true;
887 }
888 
889 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalElectronicsMap& fObject) {
890  std::vector<HcalElectronicsId> eids = fObject.allElectronicsId ();
891  char buf [1024];
892  // changes by Jared, 6.03.09/(included 25.03.09)
893  // sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
894  sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
895  "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
896  fOutput << buf << std::endl;
897 
898  for (unsigned i = 0; i < eids.size (); i++) {
899  HcalElectronicsId eid = eids[i];
900  if (eid.isTriggerChainId()) {
901  DetId trigger = fObject.lookupTrigger (eid);
902  if (trigger.rawId ()) {
903  HcalText2DetIdConverter converter (trigger);
904  // changes by Jared, 6.03.09/(included 25.03.09)
905  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
906  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
907  // i,
908  converter.getId().rawId(),
909  // changes by Jared, 6.03.09/(included 25.03.09)
910  // eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
911  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
912  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
913  );
914  fOutput << buf << std::endl;
915  }
916  } else {
917  DetId channel = fObject.lookup (eid);
918  if (channel.rawId()) {
919  HcalText2DetIdConverter converter (channel);
920  // changes by Jared, 6.03.09/(included 25.03.09)
921  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
922  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
923  // i,
924  converter.getId().rawId(),
925  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
926  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
927  );
928  fOutput << buf << std::endl;
929  }
930  }
931  }
932  return true;
933 }
934 
935 
936 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLutMetadata* fObject){
937  if (!fObject) fObject = new HcalLutMetadata;
938  char buffer [1024];
939  while (fInput.getline(buffer, 1024)) {
940  if (buffer [0] == '#') continue; //ignore comment
941  std::vector <std::string> items = splitString (std::string (buffer));
942  if (items.size()==0) continue; // blank line
943  // now get non-channel data
944  if (items.size() > 1 &&
945  items[0].find("RctLsb")!=std::string::npos){
946  fObject->setRctLsb( atof( items[1].c_str() ) );
947  continue;
948  }
949  if (items.size() > 1 &&
950  items[0].find("Gain")!=std::string::npos){
951  fObject->setNominalGain( atof( items[1].c_str() ) );
952  continue;
953  }
954  // now proceeed to per-channel data
955  if (items.size () < 7) {
956  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold" << std::endl;
957  continue;
958  }
959  DetId id = getId (items);
960 
961  HcalLutMetadatum * fCondObject = new HcalLutMetadatum(id,
962  atof (items [4].c_str()),
963  atoi (items [5].c_str()),
964  atoi (items [6].c_str()));
965  fObject->addValues(*fCondObject);
966  delete fCondObject;
967  }
968  return true;
969 }
970 
971 
972 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLutMetadata& fObject){
973  char buffer [1024];
974  const float _rctLsb = fObject.getRctLsb();
975  const float _gain = fObject.getNominalGain();
976  sprintf (buffer, "# %20s\n", "Non-channel data");
977  fOutput << buffer;
978  sprintf (buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
979  fOutput << buffer;
980  sprintf (buffer, "%8s %8.5f\n", "Gain", _gain);
981  fOutput << buffer;
982  sprintf (buffer, "# %15s %15s %15s %15s %8s %15s %19s %10s\n", "eta", "phi", "dep", "det", "Rcalib", "LutGranularity", "OutputLutThreshold", "DetId");
983  fOutput << buffer;
984  std::vector<DetId> channels = fObject.getAllChannels ();
985  std::sort (channels.begin(), channels.end(), DetIdLess ());
986  for (std::vector<DetId>::iterator channel = channels.begin ();
987  channel != channels.end ();
988  channel++) {
989  const float _rCalib = fObject.getValues (*channel)->getRCalib();
990  const uint8_t _lutGranularity = fObject.getValues (*channel)->getLutGranularity();
991  const uint8_t _outputLutThreshold = fObject.getValues (*channel)->getOutputLutThreshold();
992  dumpId (fOutput, *channel);
993  sprintf (buffer, " %8.5f %15d %19d %10X\n",
994  _rCalib,
995  _lutGranularity,
996  _outputLutThreshold,
997  channel->rawId ());
998  fOutput << buffer;
999  }
1000  return true;
1001 }
1002 
1003 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1004 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues * fObject) {
1005  if (!fObject) fObject = new HcalDcsValues;
1006  std::string buffer;
1007  while (getline(fInput, buffer)) {
1008  if (buffer.at(0) == '#') continue; //ignore comment
1009  std::vector <std::string> items = splitString (buffer);
1010  if (items.size()==0) continue; // blank line
1011 
1012  if (items.size() < 9) {
1013  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 9 items: subDet, side_ring, slice, type, subChannel, LS, Value, UpperLimit, LowerLimit" << std::endl;
1014  continue;
1015  }
1016 
1017  HcalOtherSubdetector subd;
1018  int sidering;
1019  unsigned int slice, subchan;
1020  switch (items[0].at(1)) {
1021  case 'B':
1022  subd = HcalDcsBarrel;
1023  break;
1024  case 'E':
1025  subd = HcalDcsEndcap;
1026  break;
1027  case 'F':
1028  subd = HcalDcsForward;
1029  break;
1030  case 'O':
1031  subd = HcalDcsOuter;
1032  break;
1033  default:
1034  continue;
1035  }
1036  //from_string<int>(subd, items[0], std::dec);
1037  from_string<int>(sidering, items[1], std::dec);
1038  from_string<unsigned int>(slice, items[2], std::dec);
1039  //from_string<int>(ty, items[3], std::dec);
1040  from_string<unsigned int>(subchan, items[4], std::dec);
1041 
1042  HcalDcsDetId newId(subd, sidering, slice,
1043  HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
1044 
1045  int LS;
1046  float val,upper,lower;
1047  from_string<int>(LS, items[5], std::dec);
1048  from_string<float>(val, items[6], std::dec);
1049  from_string<float>(upper, items[7], std::dec);
1050  from_string<float>(lower, items[8], std::dec);
1051 
1052  HcalDcsValue newVal(newId.rawId(),LS,val,upper,lower);
1053 // std::cout << buffer << '\n';
1054 // std::cout << subd << ' ' << sidering << ' ' << slice << ' '
1055 // << ty << ' ' << subchan << ' ' << LS << ' '
1056 // << val << ' ' << upper << ' ' << lower << '\n';
1057 // std::cout << newId ;
1058  if (!(fObject->addValue(newVal))) {
1059  edm::LogWarning("Data Error") << "Data from line " << buffer
1060  << "\nwas not added to the HcalDcsValues object." << std::endl;
1061  }
1062 // std::cout << std::endl;
1063  }
1064  fObject->sortAll();
1065  return true;
1066 }
1067 
1068 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput,
1069  HcalDcsValues const& fObject) {
1070  fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
1071  for(int subd = HcalDcsValues::HcalHB;
1072  subd <= HcalDcsValues::HcalHF; ++subd) {
1073 // std::cout << "subd: " << subd << '\n';
1074  HcalDcsValues::DcsSet const & vals=
1076  for (HcalDcsValues::DcsSet::const_iterator val = vals.begin();
1077  val != vals.end(); ++val) {
1078  HcalDcsDetId valId(val->DcsId());
1079 
1080  switch (valId.subdet()) {
1081  case HcalDcsBarrel:
1082  fOutput << "HB ";
1083  break;
1084  case HcalDcsEndcap:
1085  fOutput << "HE ";
1086  break;
1087  case HcalDcsOuter:
1088  fOutput << "HO ";
1089  break;
1090  case HcalDcsForward:
1091  fOutput << "HF ";
1092  break;
1093  default :
1094  fOutput << valId.subdet() << ' ';
1095  }
1096 
1097  if (valId.subdet() == HcalDcsOuter)
1098  fOutput << valId.ring() << ' ';
1099  else
1100  fOutput << valId.zside() << ' ';
1101 
1102  fOutput << valId.slice() << ' '
1103  << valId.typeString(valId.type()) << ' '
1104  << valId.subchannel() << ' ';
1105  fOutput << val->LS() << ' '
1106  << val->getValue() << ' '
1107  << val->getUpperLimit() << ' '
1108  << val->getLowerLimit() << ' ';
1109  fOutput << std::hex << val->DcsId() << std::dec << '\n';
1110 
1111 // std::cout << valId << ' '
1112 // << valId.subdet() << ' '
1113 // << val->LS() << ' ' << val->getValue() << ' '
1114 // << val->getUpperLimit() << ' ' << val->getLowerLimit()
1115 // << std::endl;
1116  }
1117  }
1118 
1119  return true;
1120 }
1121 
1122 
1123 // Format of the ASCII file:
1124 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1125 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1126 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalDcsMap* fObject) {
1127  char buffer [1024];
1128  while (fInput.getline(buffer, 1024)) {
1129  if (buffer [0] == '#') continue; //ignore comment
1130  std::vector <std::string> items = splitString (std::string (buffer));
1131  if (items.size () < 8) {
1132  if (items.size()==0) continue; // no warning here
1133  else {
1134  edm::LogError("MapFormat") << "HcalDcsMap-> Bad line: " << buffer
1135  << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
1136  continue;
1137  }
1138  }
1139  // std::cout << "HcalDcsMap-> processing line: " << buffer << std::endl;
1140  //int ring = atoi (items [1].c_str());
1141  int ring = atoi(items[1].c_str());
1142  unsigned int slice = atoi (items [2].c_str());
1143  unsigned int subchannel = atoi (items [3].c_str());
1145 // if(items[4].find("HV")!=std::string::npos){
1146 // type = HcalDcsDetId::HV;
1147 // }
1148 // else if (items[4].find("BV")!=std::string::npos){
1149 // type = HcalDcsDetId::BV;
1150 // }
1151 // else if (items[4].find("CATH")!=std::string::npos){
1152 // type = HcalDcsDetId::CATH;
1153 // }
1154 // else if (items[4].find("DYN7")!=std::string::npos){
1155 // type = HcalDcsDetId::DYN7;
1156 // }
1157 // else if (items[4].find("DYN8")!=std::string::npos){
1158 // type = HcalDcsDetId::DYN8;
1159 // }
1160 // else if (items[4].find("RM_TEMP")!=std::string::npos){
1161 // type = HcalDcsDetId::RM_TEMP;
1162 // }
1163 // else if (items[4].find("CCM_TEMP")!=std::string::npos){
1164 // type = HcalDcsDetId::CCM_TEMP;
1165 // }
1166 // else if (items[4].find("CALIB_TEMP")!=std::string::npos){
1167 // type = HcalDcsDetId::CALIB_TEMP;
1168 // }
1169 // else if (items[4].find("LVTTM_TEMP")!=std::string::npos){
1170 // type = HcalDcsDetId::LVTTM_TEMP;
1171 // }
1172 // else if (items[4].find("TEMP")!=std::string::npos){
1173 // type = HcalDcsDetId::TEMP;
1174 // }
1175 // else if (items[4].find("QPLL_LOCK")!=std::string::npos){
1176 // type = HcalDcsDetId::QPLL_LOCK;
1177 // }
1178 // else if (items[4].find("STATUS")!=std::string::npos){
1179 // type = HcalDcsDetId::STATUS;
1180 // }
1181 // else if (items[4].find("DCS_MAX")!=std::string::npos){
1182 // type = HcalDcsDetId::DCS_MAX;
1183 // }
1184 // else{
1185 // edm::LogError("MapFormat") << "HcalDcsMap-> Unknown DCS Type, line is not accepted: " << items[4];
1186 // continue;
1187 // }
1189  if (items[4].find("CALIB")!=std::string::npos){
1190  subdet = HcalCalibration;
1191  }
1192  else if (items[4].find("HB")!=std::string::npos){
1193  subdet = HcalDcsBarrel;
1194  }
1195  else if (items[4].find("HE")!=std::string::npos){
1196  subdet = HcalDcsEndcap;
1197  }
1198  else if (items[4].find("HO")!=std::string::npos){
1199  subdet = HcalDcsOuter;
1200  }
1201  else if (items[4].find("HF")!=std::string::npos){
1202  subdet = HcalDcsForward;
1203  }
1204  else{
1205  edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
1206  continue;
1207  }
1208  HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
1209  HcalText2DetIdConverter converter (items [4], items [5], items [6], items [7]);
1210  HcalDetId id(0);
1211  if (converter.isHcalDetId()){
1212  id = converter.getId();
1213  }
1214  else{
1215  edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: "
1216  << items [4] << '/'
1217  << items [5] << '/'
1218  << items [6] << '/'
1219  << items [7] << std::endl;
1220  continue;
1221  }
1222  fObject->mapGeomId2DcsId(id, dcsId);
1223  }
1224  fObject->sort ();
1225  return true;
1226 }
1227 
1228 // Format of the ASCII file:
1229 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1230 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1231 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalDcsMap& fObject) {
1232  char buf [1024];
1233  sprintf (buf, "# %7s %10s %6s %8s %7s %5s %5s %6s",
1234  "i", "side_ring", "slice", "subchan", "subdet", "ieta", "iphi", "depth");
1235  fOutput << buf << std::endl;
1237  unsigned int line_counter = 0;
1238  for (_line = fObject.beginById();
1239  _line != fObject.endById();
1240  ++_line) {
1241  HcalDcsDetId dcsId = _line.getHcalDcsDetId();
1242  //std::string _dcs_type = "DCSUNKNOWN";
1243  HcalText2DetIdConverter _converter(_line.getHcalDetId());
1244  sprintf (buf, " %8X %10d %6d %8d %7s %5s %5s %6s",
1245  line_counter,
1246  dcsId.ring(), // contains zside() already
1247  dcsId.slice(),
1248  dcsId.subchannel(),
1249  _converter.getFlavor().c_str(),
1250  _converter.getField1().c_str(),
1251  _converter.getField2().c_str(),
1252  _converter.getField3().c_str()
1253  );
1254  fOutput << buf << std::endl;
1255  ++line_counter;
1256  }
1257  return true;
1258 }
1259 
1260 
uint32_t getFlag() const
type
Definition: HCALResponse.h:22
float getPedestal() const
static const HcalDetId Undefined
Definition: HcalDetId.h:66
void setAlgoString(std::string fAlgo)
int i
Definition: DBlmapReader.cc:9
bool addValues(const Item &myItem, bool h2mode_=false)
int fiberIndex() const
get the fiber index [1-8] (which of eight fibers carried by a spigot) (valid only for non-trigger-cha...
void setUnitADC(bool isADC)
Definition: HcalPedestals.h:25
float slope(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:52
bool getHcalSingleIntObject(std::istream &fInput, T *fObject, S *fCondObject)
bool isADC() const
Definition: HcalPedestals.h:23
int subchannel() const
Definition: HcalDcsDetId.h:49
bool getHcalSingleFloatObject(std::istream &fInput, T *fObject, S *fCondObject)
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:38
uint8_t getOutputLutThreshold() const
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:205
bool getHcalMatrixObject(std::istream &fInput, T *fObject, S *fCondObject)
DcsSet const & getAllSubdetValues(DcsSubDet subd) const
int htrSlot() const
get the htr slot
bool dumpHcalSingleFloatObject(std::ostream &fOutput, const T &fObject)
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
const HcalQIEShape & getShape() const
get basic shape
Definition: HcalQIEData.h:36
uint8_t getLutGranularity() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
const HcalCalibrationQIECoder * getCoder(DetId fId) const
get QIE parameters
std::vector< std::string > splitString(const std::string &fLine)
float lowEdge(unsigned fAdc) const
Definition: HcalQIEShape.cc:39
bool setRctLsb(float rctlsb)
int readoutVMECrateId() const
get the readout VME crate number
void dumpId(std::ostream &fOutput, DetId id)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
U second(std::pair< T, U > const &p)
const_iterator endById(void) const
Definition: HcalDcsMap.cc:59
bool addCoder(const HcalQIECoder &fCoder, bool h2mode_=false)
Definition: HcalQIEData.h:42
std::vector< HcalDcsValue > DcsSet
Definition: HcalDcsValues.h:25
void setUnitADC(bool isADC)
float getRespGain() const
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom)
float offset(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:48
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:45
std::vector< DetId > getAllChannels() const
float getNominalGain() const
HcalDetId getHcalDetId(void)
Definition: HcalDcsMap.cc:98
tuple result
Definition: query.py:137
HcalOtherSubdetector
Definition: HcalAssistant.h:33
float getRCalib() const
int dccid() const
get the (Hcal local) DCC id
HcalDcsDetId getHcalDcsDetId(void)
Definition: HcalDcsMap.cc:94
int j
Definition: DBlmapReader.cc:9
bool dumpHcalMatrixObject(std::ostream &fOutput, const T &fObject)
double f[11][100]
int fiberChanId() const
get the fiber channel id (which of three channels on a readout fiber) (valid only for non-trigger-cha...
std::string getTagString() const
bool first
Definition: L1TdeRCT.cc:79
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
int spigot() const
get the spigot (input number on DCC)
static DcsType DcsTypeFromString(const std::string &str)
Definition: HcalDcsDetId.cc:31
int slbChannelIndex() const
get the SLB channel index (valid only for trigger-chain ids)
Definition: DetId.h:20
void setHTR(int crate, int slot, int tb)
std::string getAlgoString() const
std::vector< HcalElectronicsId > allElectronicsId() const
void sort()
Definition: HcalQIEData.h:44
void sort()
Definition: HcalDcsMap.h:62
int slice() const
Definition: HcalDcsDetId.h:47
float getRctLsb() const
bool isTriggerChainId() const
static const HcalTrigTowerDetId Undefined
bool addValue(HcalDcsValue const &newVal)
bool getHcalObject(std::istream &fInput, T *fObject, S *fCondObject)
bool getObject(std::istream &fInput, HcalPedestals *fObject)
DetId getId(const std::vector< std::string > &items)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
int slbSiteNumber() const
get the SLB site number (valid only for trigger-chain ids)
const float * getValues() const
get value for all capId = 0..3
Definition: HcalPedestal.h:17
bool dumpHcalObject(std::ostream &fOutput, const T &fObject)
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
const float * minCharges() const
void setTagString(std::string fTag)
string s
Definition: asciidump.py:422
uint32_t getValue() const
bool addCoder(const HcalCalibrationQIECoder &fCoder)
const Item * getValues(DetId fId) const
int ring() const
Definition: HcalDcsDetId.h:46
Readout chain identification for Hcal [31:26] Unused (so far) [25] Trigger-chain id flag [24:20] Read...
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
bool setNominalGain(float gain)
bool dumpHcalSingleIntObject(std::ostream &fOutput, const T &fObject)
bool from_string(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &))
list at
Definition: asciidump.py:428