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 // F.Ratnikov (UMd), Oct 28, 2005
3 //
4 #include <vector>
5 #include <string>
6 #include <cstdio>
7 #include <sstream>
8 
13 
17 
18 namespace {
19  class DetIdLess {
20  public:
21  bool operator () (DetId fFirst, DetId fSecond) const {
22  HcalGenericDetId first (fFirst);
23  HcalGenericDetId second (fSecond);
24  if (first.genericSubdet () != second.genericSubdet ()) return first.genericSubdet () < second.genericSubdet ();
25  if (first.isHcalDetId ()) {
26  HcalDetId f1 (first);
27  HcalDetId s1 (second);
28  return f1.zside () != s1.zside () ? f1.zside () < s1.zside () :
29  f1.iphi () != s1.iphi () ? f1.iphi () < s1.iphi () :
30  f1.ietaAbs () != s1.ietaAbs () ? f1.ietaAbs () < s1.ietaAbs () :
31  f1.depth () < s1.depth ();
32  }
33  else {
34  return first.rawId() < second.rawId();
35  }
36  }
37  };
38  class HcalElectronicsIdLess {
39  public:
40  bool operator () (HcalElectronicsId first, HcalElectronicsId second) const {
41  return
42  first.readoutVMECrateId () != second.readoutVMECrateId () ? first.readoutVMECrateId () < second.readoutVMECrateId () :
43  first.htrSlot () != second.htrSlot () ? first.htrSlot () < second.htrSlot () :
44  first.htrTopBottom () != second.htrTopBottom () ? first.htrTopBottom () < second.htrTopBottom () :
45  first.fiberIndex () != second.fiberIndex () ? first.fiberIndex () < second.fiberIndex () :
46  first.fiberChanId () < second.fiberChanId ();
47  }
48  };
49 }
50 
51 // ------------------------------ some little helpers ------------------------------
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 std::vector <unsigned int> splitStringToIntByComma (const std::string& fLine) {
74  std::vector <unsigned int> result;
75  int start = 0;
76  bool empty = true;
77  for (unsigned i = 0; i <= fLine.size (); i++) {
78  if (fLine [i] == ',' || i == fLine.size ()) {
79  if (!empty) {
80  std::string itemString (fLine, start, i-start);
81  result.push_back (atoi (itemString.c_str()) );
82  empty = true;
83  }
84  start = i+1;
85  }
86  else {
87  if (empty) empty = false;
88  }
89  }
90  return result;
91 }
92 
93 std::vector <float> splitStringToFloatByComma (const std::string& fLine) {
94  std::vector <float> result;
95  int start = 0;
96  bool empty = true;
97  for (unsigned i = 0; i <= fLine.size (); i++) {
98  if (fLine [i] == ',' || i == fLine.size ()) {
99  if (!empty) {
100  std::string itemString (fLine, start, i-start);
101  result.push_back (atof (itemString.c_str()) );
102  empty = true;
103  }
104  start = i+1;
105  }
106  else {
107  if (empty) empty = false;
108  }
109  }
110  return result;
111 }
112 
113 std::vector <double> splitStringToDoubleByComma (const std::string& fLine) {
114  std::vector <double> result;
115  int start = 0;
116  bool empty = true;
117  for (unsigned i = 0; i <= fLine.size (); i++) {
118  if (fLine [i] == ',' || i == fLine.size ()) {
119  if (!empty) {
120  std::string itemString (fLine, start, i-start);
121  result.push_back (atof (itemString.c_str()) );
122  empty = true;
123  }
124  start = i+1;
125  }
126  else {
127  if (empty) empty = false;
128  }
129  }
130  return result;
131 }
132 
133 DetId HcalDbASCIIIO::getId (const std::vector <std::string> & items) {
134  HcalText2DetIdConverter converter (items [3], items [0], items [1], items [2]);
135  return converter.getId ();
136 }
137 
138 void HcalDbASCIIIO::dumpId (std::ostream& fOutput, DetId id) {
139  HcalText2DetIdConverter converter (id);
140  char buffer [1024];
141  sprintf (buffer, " %15s %15s %15s %15s",
142  converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
143  fOutput << buffer;
144 }
145 
146 void HcalDbASCIIIO::dumpIdShort (std::ostream& fOutput, DetId id) {
147  HcalText2DetIdConverter converter (id);
148  char buffer [1024];
149  sprintf (buffer, " %5s %4s %4s %10s",
150  converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
151  fOutput << buffer;
152 }
153 
154 
155 // ------------------------------ start templates ------------------------------
156 
157 template<class T>
158 bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
159  std::istringstream iss(s);
160  return !(iss >> f >> t).fail();
161 }
162 
163 template <class T,class S>
164 bool getHcalObject (std::istream& fInput, T* fObject, S* fCondObject) {
165  if (!fObject) return false; //fObject = new T;
166  char buffer [1024];
167  while (fInput.getline(buffer, 1024)) {
168  if (buffer [0] == '#') continue; //ignore comment
169  std::vector <std::string> items = splitString (std::string (buffer));
170  if (items.size()==0) continue; // blank line
171  if (items.size () < 8) {
172  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values" << std::endl;
173  continue;
174  }
175  DetId id = HcalDbASCIIIO::getId (items);
176 
177 // if (fObject->exists(id) )
178 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
179 // else
180 // {
181  fCondObject = new S(id, atof (items [4].c_str()), atof (items [5].c_str()),
182  atof (items [6].c_str()), atof (items [7].c_str()));
183  fObject->addValues(*fCondObject);
184  delete fCondObject;
185  // }
186  }
187 
188  return true;
189 }
190 
191 template <class T>
192 bool dumpHcalObject (std::ostream& fOutput, const T& fObject) {
193  char buffer [1024];
194  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n", "eta", "phi", "dep", "det", "cap0", "cap1", "cap2", "cap3", "DetId");
195  fOutput << buffer;
196  std::vector<DetId> channels = fObject.getAllChannels ();
197  std::sort (channels.begin(), channels.end(), DetIdLess ());
198  for (std::vector<DetId>::iterator channel = channels.begin ();
199  channel != channels.end ();
200  ++channel) {
201  const float* values = fObject.getValues (*channel)->getValues ();
202  if (values) {
203  HcalDbASCIIIO::dumpId (fOutput, *channel);
204  sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %10X\n",
205  values[0], values[1], values[2], values[3], channel->rawId ());
206  fOutput << buffer;
207  }
208  }
209  return true;
210 }
211 
212 template <class T,class S>
213 bool getHcalSingleFloatObject (std::istream& fInput, T* fObject, S* fCondObject) {
214  if (!fObject) return false; //fObject = new T;
215  char buffer [1024];
216  while (fInput.getline(buffer, 1024)) {
217  if (buffer [0] == '#') continue; //ignore comment
218  std::vector <std::string> items = splitString (std::string (buffer));
219  if (items.size()==0) continue; // blank line
220  if (items.size () < 5) {
221  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
222  continue;
223  }
224  DetId id = HcalDbASCIIIO::getId (items);
225 
226 // if (fObject->exists(id) )
227 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
228 // else
229 // {
230  fCondObject = new S(id, atof (items [4].c_str()) );
231  fObject->addValues(*fCondObject);
232  delete fCondObject;
233  // }
234  }
235  return true;
236 }
237 
238 template <class T>
239 bool dumpHcalSingleFloatObject (std::ostream& fOutput, const T& fObject) {
240  char buffer [1024];
241  sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
242  fOutput << buffer;
243  std::vector<DetId> channels = fObject.getAllChannels ();
244  std::sort (channels.begin(), channels.end(), DetIdLess ());
245  for (std::vector<DetId>::iterator channel = channels.begin ();
246  channel != channels.end ();
247  ++channel) {
248  const float value = fObject.getValues (*channel)->getValue ();
249  HcalDbASCIIIO::dumpId (fOutput, *channel);
250  sprintf (buffer, " %8.5f %10X\n",
251  value, channel->rawId ());
252  fOutput << buffer;
253  }
254  return true;
255 }
256 
257 template <class T,class S>
258 bool getHcalSingleIntObject (std::istream& fInput, T* fObject, S* fCondObject) {
259  if (!fObject) return false; //fObject = new T;
260  char buffer [1024];
261  while (fInput.getline(buffer, 1024)) {
262  if (buffer [0] == '#') continue; //ignore comment
263  std::vector <std::string> items = splitString (std::string (buffer));
264  if (items.size()==0) continue; // blank line
265  if (items.size () < 5) {
266  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
267  continue;
268  }
269  DetId id = HcalDbASCIIIO::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  fCondObject = new S(id, atoi (items [4].c_str()) );
276  fObject->addValues(*fCondObject);
277  delete fCondObject;
278  // }
279  }
280  return true;
281 }
282 
283 template <class T>
284 bool dumpHcalSingleIntObject (std::ostream& fOutput, const T& fObject) {
285  char buffer [1024];
286  sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
287  fOutput << buffer;
288  std::vector<DetId> channels = fObject.getAllChannels ();
289  std::sort (channels.begin(), channels.end(), DetIdLess ());
290  for (std::vector<DetId>::iterator channel = channels.begin ();
291  channel != channels.end ();
292  ++channel) {
293  const int value = fObject.getValues (*channel)->getValue ();
294  HcalDbASCIIIO::dumpId (fOutput, *channel);
295  sprintf (buffer, " %15d %10X\n",
296  value, channel->rawId ());
297  fOutput << buffer;
298  }
299  return true;
300 }
301 
302 template <class T,class S>
303 bool getHcalMatrixObject (std::istream& fInput, T* fObject, S* fCondObject) {
304  if (!fObject) return false; //fObject = new T;
305  char buffer [1024];
306  while (fInput.getline(buffer, 1024)) {
307  if (buffer [0] == '#') continue; //ignore comment
308  std::vector <std::string> items = splitString (std::string (buffer));
309  if (items.size()==0) continue; // blank line
310  DetId firstid = HcalDbASCIIIO::getId (items);
311  fCondObject = new S(firstid.rawId());
312  for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), 0, j, atof(items[j+5].c_str()));
313  for(int i = 1; i != 40; i++){
314  fInput.getline(buffer, 1024);
315  items = splitString (std::string (buffer));
316  DetId id = HcalDbASCIIIO::getId (items);
317  if(id.rawId() != firstid.rawId()) break;//throw cms::Exception("Wrong number of elements");
318  for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), i%10, j, atof(items[j+5].c_str()));
319  }
320  fObject->addValues(*fCondObject);
321  delete fCondObject;
322  }
323  return true;
324 }
325 
326 template <class T>
327 bool dumpHcalMatrixObject (std::ostream& fOutput, const T& fObject) {
328  char buffer [1024];
329  sprintf (buffer, "# %5s %5s %5s %5s %5s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
330  "eta", "phi", "dep", "det", "capid","c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "DetId");
331  fOutput << buffer;
332  std::vector<DetId> channels = fObject.getAllChannels ();
333  std::sort (channels.begin(), channels.end(), DetIdLess ());
334  for (std::vector<DetId>::iterator channel = channels.begin ();
335  channel != channels.end ();
336  ++channel) {
337  float thisline[10];
338  for(int m = 0; m != 4; m++){
339  for(int i = 0; i != 10; i++){
340  for(int j = 0; j != 10; j++){
341 // std::cout <<"test "<<(fObject.getValues(*channel))->getValue(0,0,0);
342  thisline[j] = fObject.getValues(*channel)->getValue(m,i,j);
343 // thisline[j] = fObject.getValues(*channel)->getValue(1,1,1);
344  }
345  HcalDbASCIIIO::dumpId (fOutput, *channel);
346  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",
347  m, thisline[0], thisline[1], thisline[2], thisline[3], thisline[4], thisline[5], thisline[6], thisline[7],
348  thisline[8], thisline[9], channel->rawId());
349  fOutput << buffer;
350  }
351  }
352  }
353 
354  return true;
355 }
356 
357 // ------------------------------ end templates ------------------------------
358 
359 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalGains* fObject) {return getHcalObject (fInput, fObject, new HcalGain);}
360 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalGains& fObject) {return dumpHcalObject (fOutput, fObject);}
361 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalGainWidths* fObject) {return getHcalObject (fInput, fObject, new HcalGainWidth);}
362 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalGainWidths& fObject) {return dumpHcalObject (fOutput, fObject);}
363 
364 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalRespCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalRespCorr); }
365 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalRespCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
366 
367 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLUTCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalLUTCorr); }
368 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLUTCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
369 
370 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPFCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalPFCorr); }
371 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPFCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
372 
373 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTimeCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalTimeCorr); }
374 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTimeCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
375 
376 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalZSThresholds* fObject) {return getHcalSingleIntObject (fInput, fObject, new HcalZSThreshold); }
377 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalZSThresholds& fObject) {return dumpHcalSingleIntObject (fOutput, fObject); }
378 
379 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalZDCLowGainFractions* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalZDCLowGainFraction); }
380 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalZDCLowGainFractions& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
381 
382 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalValidationCorrs* fObject) {return getHcalSingleFloatObject (fInput, fObject, new HcalValidationCorr); }
383 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalValidationCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
384 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCholeskyMatrices* fObject) {return getHcalMatrixObject (fInput, fObject, new HcalCholeskyMatrix); }
385 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCholeskyMatrices& fObject) {return dumpHcalMatrixObject (fOutput, fObject); }
386 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCovarianceMatrices* fObject) {return getHcalMatrixObject (fInput, fObject, new HcalCovarianceMatrix); }
387 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCovarianceMatrices& fObject) {return dumpHcalMatrixObject (fOutput, fObject); }
388 
389 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalQIETypes* fObject) {return getHcalSingleIntObject (fInput, fObject, new HcalQIEType); }
390 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalQIETypes& fObject) {return dumpHcalSingleIntObject (fOutput, fObject); }
391 
392 // ------------------------------ start specific implementations ------------------------------
393 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalRecoParams* fObject)
394 {
395  if (!fObject) return false; // fObject = new HcalRecoParams(); This was always useless...
396  char buffer [1024];
397  while (fInput.getline(buffer, 1024)) {
398  if (buffer [0] == '#') continue; //ignore comment
399  std::vector <std::string> items = splitString (std::string (buffer));
400  if (items.size()==0) continue; // blank line
401  if (items.size () < 6) {
402  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, param1, param2" << std::endl;
403  continue;
404  }
405  DetId id = HcalDbASCIIIO::getId (items);
406 
407  int packingScheme =0;
408  if(items.size ()>22) {
409  packingScheme = atoi (items [22].c_str());
410  }
411 
412  int param1=0;
413  int param2=0;
414  if(packingScheme==0) {
415  param1=atoi (items [4].c_str());
416  param2=atoi (items [5].c_str());
417  } // packing scheme 0 (old format).
418 
419  if(packingScheme==1) {
420  // 0 1 2 3 4 5 6 7 8 9
421  int aabits[6]= {1,1, 8, 4, 4, 9};
422  int aamax[ 6]= {1,1,255,15,15,511};
423 
424  int bbbits[10]={1, 4,1, 4,1, 4, 4, 4, 4, 4};
425  int bbmax [10]={1,15,1,15,1,15,15,15,15,15};
426 
427  // param 1
428  int j=0;
429  int aa;
430  int aashift=0;
431  for(int i=0; i<6; i++) {
432  j=i+7;
433  if(i==2) {
434  float phase=atof (items [j].c_str());
435  float xphase=(phase+32.0)*4.0; // range of phase [-30.0,30.0]
436  aa=xphase;
437  } else {
438  aa=atoi (items [j].c_str());
439  }
440  if(aa>aamax[i] || aa<0) {
441  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for a"<<i<<" should be less than"<<aamax[i]<< std::endl;
442  }
443  param1=param1|aa<<aashift;
444  aashift=aashift+aabits[i];
445  }
446 
447  // param 2
448  int bb;
449  int bbshift=0;
450  for(int i=0; i<10; i++) {
451  j=i+13;
452  bb=atoi (items [j].c_str());
453  if(bb>bbmax[i]) {
454  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for b"<<i<<" should be less than"<<bbmax[i]<< std::endl;
455  }
456  param2=param2|bb<<bbshift;
457  bbshift=bbshift+bbbits[i];
458  }
459  } // packing sheme 1.
460 
461  // HcalRecoParam* fCondObject = new HcalRecoParam(id, atoi (items [4].c_str()), atoi (items [5].c_str()) );
462 
463  // std::cout<<" buffer "<<buffer<<std::endl;
464  // std::cout<<" param1, param2 "<<param1<<" "<<param2<<std::endl;
465 
466  HcalRecoParam* fCondObject = new HcalRecoParam(id, param1, param2 );
467  fObject->addValues(*fCondObject);
468  delete fCondObject;
469  }
470  return true;
471 }
472 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalRecoParams& fObject)
473 {
474  char buffer [1024];
475  // sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
476  // fOutput << buffer;
477  std::vector<DetId> channels = fObject.getAllChannels ();
478  std::sort (channels.begin(), channels.end(), DetIdLess ());
479  int myCounter=0;
480  for (std::vector<DetId>::iterator channel = channels.begin ();
481  channel != channels.end ();
482  ++channel) {
483  myCounter++;
484  int param1=fObject.getValues (*channel)->param1();
485  int param2=fObject.getValues (*channel)->param2();
486  int packingScheme=fObject.getValues (*channel)->packingScheme();
487 
488  // std::cout<<" Param1 "<<Param1<<" Param2 "<<Param2<<" packing "<<packingScheme<<std::endl;
489 
490  if(packingScheme==0) {
491  // old format
492  if(myCounter==1) {
493  sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
494  }
495  HcalDbASCIIIO::dumpId(fOutput, *channel);
496  sprintf (buffer, " %15d %15d %16X\n",
497  fObject.getValues (*channel)->firstSample(), fObject.getValues (*channel)->samplesToAdd(), channel->rawId ());
498  fOutput << buffer;
499  }
500 
501  if(packingScheme==1) {
502 
503  if(myCounter==1) {
504  char lineT[100],lineA[200],lineB[200];
505  //
506  sprintf (lineT, "#%50s"," "); fOutput << lineT;
507  sprintf (lineA, " %31s","a0: correctForPhaseContainment"); fOutput << lineA;
508  sprintf (lineB, " %36s","b0: useLeakCorrection\n"); fOutput << lineB;
509  //
510  sprintf (lineT, "#%50s"," "); fOutput << lineT;
511  sprintf (lineA, " %31s","a1: correctForLeadingEdge"); fOutput << lineA;
512  sprintf (lineB, " %36s","b1: leakCorrectionID\n"); fOutput << lineB;
513  //
514  sprintf (lineT, "#%50s"," "); fOutput << lineT;
515  sprintf (lineA, " %31s","a2: correctionPhaseNS"); fOutput << lineA;
516  sprintf (lineB, " %36s","b2: correctForTimeslew\n"); fOutput << lineB;
517  //
518  sprintf (lineT, "#%50s"," "); fOutput << lineT;
519  sprintf (lineA, " %31s","a3: firstSample"); fOutput << lineA;
520  sprintf (lineB, " %36s","b3: timeslewCorrectionID\n"); fOutput << lineB;
521  //
522  sprintf (lineT, "#%50s"," "); fOutput << lineT;
523  sprintf (lineA, " %31s","a4: samplesToAdd"); fOutput << lineA;
524  sprintf (lineB, " %36s","b4: correctTiming\n"); fOutput << lineB;
525  //
526  sprintf (lineT, "#%50s"," "); fOutput << lineT;
527  sprintf (lineA, " %31s","a5: pulseShapeID"); fOutput << lineA;
528  sprintf (lineB, " %36s","b5: firstAuxTS\n"); fOutput << lineB;
529  //
530  sprintf (lineT, "#%50s"," "); fOutput << lineT;
531  sprintf (lineA, " %31s"," "); fOutput << lineA;
532  sprintf (lineB, " %36s","b6: specialCaseID\n"); fOutput << lineB;
533  //
534  sprintf (lineT, "#%50s"," "); fOutput << lineT;
535  sprintf (lineA, " %31s"," "); fOutput << lineA;
536  sprintf (lineB, " %36s","b7: noiseFlaggingID\n"); fOutput << lineB;
537  //
538  sprintf (lineT, "#%50s"," "); fOutput << lineT;
539  sprintf (lineA, " %31s"," "); fOutput << lineA;
540  sprintf (lineB, " %36s","b8: pileupCleaningID\n"); fOutput << lineB;
541 
542  sprintf (lineT, "#%50s"," "); fOutput << lineT;
543  sprintf (lineA, " %31s"," "); fOutput << lineA;
544  sprintf (lineB, " %36s","b9: packingScheme\n"); fOutput << lineB;
545 
546  //
547  sprintf (lineT, "# %5s %4s %4s %10s %11s %10s %10s", "eta", "phi", "dep", "det", "param1", "param2", "DetId");
548  fOutput << lineT;
549 
550  sprintf (lineA, " %6s %4s %6s %4s %4s %4s", "a0", "a1", "a2", "a3", "a4", "a5");
551  fOutput << lineA;
552 
553  sprintf (lineB, " %6s %3s %3s %3s %3s %3s %3s %3s %3s\n", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8");
554  fOutput << lineB;
555  }
556 
557  HcalDbASCIIIO::dumpIdShort(fOutput, *channel);
558  sprintf (buffer, " %11d %10d %10X", param1, param2, channel->rawId ());
559  fOutput << buffer;
560 
561  bool aa0=fObject.getValues (*channel)->correctForPhaseContainment();
562  bool aa1=fObject.getValues (*channel)->correctForLeadingEdge();
563  float aa2=fObject.getValues (*channel)->correctionPhaseNS();
564  int aa3=fObject.getValues (*channel)->firstSample();
565  int aa4=fObject.getValues (*channel)->samplesToAdd();
566  int aa5=fObject.getValues (*channel)->pulseShapeID();
567  sprintf (buffer, " %6d %4d %6.1f %4d %4d %4d",aa0,aa1,aa2,aa3,aa4,aa5);
568  fOutput << buffer;
569 
570  bool bb0=fObject.getValues (*channel)->useLeakCorrection();
571  int bb1=fObject.getValues (*channel)->leakCorrectionID();
572  bool bb2=fObject.getValues (*channel)->correctForTimeslew();
573  int bb3=fObject.getValues (*channel)->timeslewCorrectionID();
574  bool bb4=fObject.getValues (*channel)->correctTiming();
575  int bb5=fObject.getValues (*channel)->firstAuxTS();
576  int bb6=fObject.getValues (*channel)->specialCaseID();
577  int bb7=fObject.getValues (*channel)->noiseFlaggingID();
578  int bb8=fObject.getValues (*channel)->pileupCleaningID();
579  int bb9=fObject.getValues (*channel)->packingScheme();
580  sprintf(buffer," %6d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",bb0,bb1,bb2,bb3,bb4,bb5,bb6,bb7,bb8,bb9);
581  fOutput << buffer;
582  } // packingScheme 1.
583 
584  } // loop ever channels
585  return true;
586 }
587 
588 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLongRecoParams* fObject)
589 {
590  if (!fObject) return false; // fObject = new HcalLongRecoParams();
591  char buffer [1024];
592  while (fInput.getline(buffer, 1024)) {
593  if (buffer [0] == '#') continue; //ignore comment
594  std::vector <std::string> items = splitString (std::string (buffer));
595  if (items.size()==0) continue; // blank line
596  if (items.size() < 5) {
597  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs" << std::endl;
598  continue;
599  }
600  if (items.size() > 7) {
601  edm::LogWarning("Format Problem ?") << "Check line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs. "
602  << "\n ! signalTS and noiseTS must be of format <ts1,ts2,ts3,...> withOUT spaces. Ignoring line for safety" << std::endl;
603  continue;
604  }
605  DetId id = HcalDbASCIIIO::getId (items);
606 
607  std::vector<unsigned int> mySignalTS = splitStringToIntByComma(items[4]);
608  std::vector<unsigned int> myNoiseTS = splitStringToIntByComma(items[5]);
609 
610  HcalLongRecoParam* fCondObject = new HcalLongRecoParam(id, mySignalTS, myNoiseTS );
611  fObject->addValues(*fCondObject);
612  delete fCondObject;
613  }
614  return true;
615 }
616 
617 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTimingParams* fObject)
618 {
619  if (!fObject) return false; // fObject = new HcalTimingParams();
620  char buffer [1024];
621  while (fInput.getline(buffer, 1024)) {
622  if (buffer [0] == '#') continue; //ignore comment
623  std::vector <std::string> items = splitString (std::string (buffer));
624  if (items.size()==0) continue; // blank line
625  if (items.size () < 7) {
626  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, nhit, phase, rms,detid" << std::endl;
627  continue;
628  }
629  //std::cout<<"items[3] "<<items [3]<<std::endl;
630  //std::cout<<"items[0] "<<items [0]<<std::endl;
631  //std::cout<<"items[1] "<<items [1]<<std::endl;
632  //std::cout<<"items[2] "<<items [2]<<std::endl;
633 
634  //std::cout<<"items[4] "<<items [4]<<std::endl;
635  //std::cout<<"items[5] "<<items [5]<<std::endl;
636  //std::cout<<"items[6] "<<items [6]<<std::endl;
637  DetId id = HcalDbASCIIIO::getId (items);
638  //std::cout<<"calculated id "<<id.rawId()<<std::endl;
639  HcalTimingParam* fCondObject = new HcalTimingParam(id, atoi (items [4].c_str()), atof (items [5].c_str()), atof (items [6].c_str()));
640  fObject->addValues(*fCondObject);
641  delete fCondObject;
642  }
643  return true;
644 }
645 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTimingParams& fObject)
646 {
647  char buffer [1024];
648  sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s\n", "eta", "phi", "dep", "det", "nhit", "mean","rms" ,"DetId");
649  fOutput << buffer;
650  std::vector<DetId> channels = fObject.getAllChannels ();
651  std::sort (channels.begin(), channels.end(), DetIdLess ());
652  for (std::vector<DetId>::iterator channel = channels.begin ();
653  channel != channels.end ();
654  ++channel) {
655  HcalDbASCIIIO::dumpId (fOutput, *channel);
656  sprintf (buffer, " %15d %8.5f %8.5f %16X\n",
657  fObject.getValues (*channel)->nhits(), fObject.getValues (*channel)->phase(),fObject.getValues(*channel)->rms(),channel->rawId ());
658  fOutput << buffer;
659  }
660  return true;
661 }
662 
663 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLongRecoParams& fObject)
664 {
665  char buffer [1024];
666  sprintf (buffer, "# %15s %15s %15s %15s %10s %10s %10s\n", "eta", "phi", "dep", "det", "signalTSs", "noiseTSs", "DetId");
667  fOutput << buffer;
668  std::vector<DetId> channels = fObject.getAllChannels ();
669  std::sort (channels.begin(), channels.end(), DetIdLess ());
670  for (std::vector<DetId>::iterator channel = channels.begin ();
671  channel != channels.end ();
672  ++channel) {
673  HcalGenericDetId fId(*channel);
674  if (fId.isHcalZDCDetId())
675  {
676  std::vector<unsigned int> vSignalTS = fObject.getValues (*channel)->signalTS();
677  std::vector<unsigned int> vNoiseTS = fObject.getValues (*channel)->noiseTS();
678  HcalDbASCIIIO::dumpId (fOutput, *channel);
679  sprintf (buffer, " ");
680  fOutput << buffer;
681  for (unsigned int i=0; i<vSignalTS.size(); i++)
682  {
683  if (i>0) {sprintf (buffer, ","); fOutput << buffer;}
684  sprintf (buffer, "%u", vSignalTS.at(i));
685  fOutput << buffer;
686  }
687  sprintf (buffer, " ");
688  fOutput << buffer;
689  for (unsigned int i=0; i<vNoiseTS.size(); i++)
690  {
691  if (i>0) { sprintf (buffer, ","); fOutput << buffer;}
692  sprintf (buffer, "%u", vNoiseTS.at(i));
693  fOutput << buffer;
694  }
695  sprintf (buffer, " %10X\n", channel->rawId ());
696  fOutput << buffer;
697  }
698  }
699  return true;
700 }
701 
702 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalMCParams* fObject)
703 {
704  if (!fObject) return false; // fObject = new HcalMCParams();
705  char buffer [1024];
706  while (fInput.getline(buffer, 1024)) {
707  if (buffer [0] == '#') continue; //ignore comment
708  std::vector <std::string> items = splitString (std::string (buffer));
709  if (items.size()==0) continue; // blank line
710  if (items.size () < 5) {
711  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, signalShape" << std::endl;
712  continue;
713  }
714  DetId id = HcalDbASCIIIO::getId (items);
715 
716  int packingScheme=0;
717  if(items.size ()>11) {
718  packingScheme = atoi (items [11].c_str());
719  }
720 
721  int param1=0;
722  if(packingScheme==0) {
723  param1=atoi (items [4].c_str());
724  }
725 
726  if(packingScheme==1) {
727  int aabits[6]={ 9,1, 4, 8,5, 4}; // 4 spear bits added to aabits[5]
728  int aamax [6]={511,1,15,255,1,16};
729  int j=0;
730  int aa;
731  int aashift=0;
732  for(int i=0; i<6; i++) {
733  j=i+6;
734  if(i==3) {
735  float phase=atof (items [j].c_str());
736  float xphase=(phase+32.0)*4.0; // range of phase [-30.0,30.0]
737  aa=xphase;
738  } else {
739  aa=atoi (items [j].c_str());
740  }
741  if(aa>aamax[i] || aa<0) {
742  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for a"<<i<<" should be less than"<<aamax[i]<< std::endl;
743  }
744 
745  param1=param1|aa<<aashift;
746  aashift=aashift+aabits[i];
747  }
748  }
749 
750  HcalMCParam* fCondObject = new HcalMCParam(id, param1 );
751  fObject->addValues(*fCondObject);
752  delete fCondObject;
753  }
754  return true;
755 }
756 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalMCParams& fObject)
757 {
758  char buffer [1024];
759  // sprintf (buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
760  // fOutput << buffer;
761  std::vector<DetId> channels = fObject.getAllChannels ();
762  std::sort (channels.begin(), channels.end(), DetIdLess ());
763  int myCounter=0;
764  for (std::vector<DetId>::iterator channel = channels.begin ();
765  channel != channels.end ();
766  ++channel) {
767  myCounter++;;
768  int packingScheme=fObject.getValues (*channel)->packingScheme();
769  if(packingScheme==0) {
770  if(myCounter==1) {
771  sprintf (buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
772  fOutput << buffer;
773  }
774  const int value = fObject.getValues (*channel)->signalShape();
775  HcalDbASCIIIO::dumpId (fOutput, *channel);
776  sprintf (buffer, " %10d %17X\n", value, channel->rawId ());
777  fOutput << buffer;
778  } // packingScheme 0
779  if(packingScheme==1) {
780  if(myCounter==1) {
781  char lineT[100],lineA[200];
782  //
783  sprintf (lineT, "#%40s"," "); fOutput << lineT;
784  sprintf (lineA, " %31s","a0: signalShape\n"); fOutput << lineA;
785  sprintf (lineT, "#%40s"," "); fOutput << lineT;
786  sprintf (lineA, " %31s","a1: syncPhase\n"); fOutput << lineA;
787  sprintf (lineT, "#%40s"," "); fOutput << lineT;
788  sprintf (lineA, " %31s","a2: binOfMaximum\n"); fOutput << lineA;
789  sprintf (lineT, "#%40s"," "); fOutput << lineT;
790  sprintf (lineA, " %31s","a3: timePhase\n"); fOutput << lineA;
791  sprintf (lineT, "#%40s"," "); fOutput << lineT;
792  sprintf (lineA, " %31s","a4: timeSmearing\n"); fOutput << lineA;
793  sprintf (lineT, "#%40s"," "); fOutput << lineT;
794  sprintf (lineA, " %31s","a5: packingScheme\n"); fOutput << lineA;
795  sprintf (lineT, "# %5s %4s %4s %10s %11s %10s", "eta", "phi", "dep", "det", "param1", "DetId");
796  fOutput << lineT;
797  sprintf (lineA, " %6s %4s %4s %6s %4s %4s\n", "a0", "a1", "a2", "a3", "a4", "a5");
798  fOutput << lineA;
799  }
800  int param1 = fObject.getValues (*channel)->param1();
801  HcalDbASCIIIO::dumpIdShort (fOutput, *channel);
802  sprintf (buffer, " %11d %10X", param1, channel->rawId ());
803  fOutput << buffer;
804  int aa0 = fObject.getValues (*channel)->signalShape();
805  bool aa1 = fObject.getValues (*channel)->syncPhase();
806  int aa2 = fObject.getValues (*channel)->binOfMaximum();
807  float aa3 = fObject.getValues (*channel)->timePhase();
808  bool aa4 = fObject.getValues (*channel)->timeSmearing() ;
809  int aa5 = fObject.getValues (*channel)->packingScheme();
810  sprintf (buffer, "%6d %4d %4d %6.1f %4d %4d\n",aa0,aa1,aa2,aa3,aa4,aa5);
811  fOutput << buffer;
812  }
813  }
814  return true;
815 }
816 
817 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestals* fObject) {
818  char buffer [1024];
819 
820  while (fInput.getline(buffer, 1024)) {
821  std::vector <std::string> items = splitString (std::string (buffer));
822  if (items.size()==0) continue; // blank line
823  else {
824  if (items[0] == "#U")
825  {
826  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
827  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
828  else
829  {
830  edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
831  fObject->setUnitADC(false);
832  }
833  break;
834  }
835  else
836  {
837  edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
838  return false;
839  }
840  }
841  }
842  while (fInput.getline(buffer, 1024)) {
843  if (buffer [0] == '#') continue;
844  std::vector <std::string> items = splitString (std::string (buffer));
845  if (items.size()==0) continue; // blank line
846  if (items.size () < 8) {
847  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
848  << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
849  << std::endl;
850  continue;
851  }
852  DetId id = getId (items);
853 
854 // if (fObject->exists(id) )
855 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
856 // else
857 // {
858 
859  if (items.size() < 12) // old format without widths
860  {
861  HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
862  atof (items [6].c_str()), atof (items [7].c_str()),
863  0., 0., 0., 0. );
864  fObject->addValues(*fCondObject);
865  delete fCondObject;
866  }
867  else // new format with widths
868  {
869  HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
870  atof (items [6].c_str()), atof (items [7].c_str()),
871  atof (items [8].c_str()), atof (items [9].c_str()),
872  atof (items [10].c_str()), atof (items [11].c_str()) );
873  fObject->addValues(*fCondObject);
874  delete fCondObject;
875  }
876 
877  // }
878  }
879  return true;
880 }
881 
882 
883 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestals& fObject) {
884  char buffer [1024];
885  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
886  else sprintf (buffer, "#U fC << this is the unit \n");
887  fOutput << buffer;
888 
889  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");
890  fOutput << buffer;
891 
892  std::vector<DetId> channels = fObject.getAllChannels ();
893  std::sort (channels.begin(), channels.end(), DetIdLess ());
894  for (std::vector<DetId>::iterator channel = channels.begin ();
895  channel != channels.end ();
896  ++channel) {
897  const float* values = fObject.getValues (*channel)->getValues ();
898  if (values) {
899  dumpId (fOutput, *channel);
900  sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
901  values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
902  fOutput << buffer;
903  }
904  }
905  return true;
906 }
907 
908 
909 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
910 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalChannelQuality* fObject)
911 {
912  if (!fObject) return false; //fObject = new HcalChannelQuality;
913  char buffer [1024];
914  while (fInput.getline(buffer, 1024)) {
915  if (buffer [0] == '#') continue; //ignore comment
916  std::vector <std::string> items = splitString (std::string (buffer));
917  if (items.size()==0) continue; // blank line
918  if (items.size () < 6) {
919  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;
920  continue;
921  }
922  DetId id = getId (items);
923 
924 // if (fObject->exists(id) )
925 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
926 // else
927 // {
928  uint32_t mystatus;
929  if (items[4] == "(hex)")
930  sscanf(items[5].c_str(),"%X", &mystatus);
931  else if (items[4] == "(dec)")
932  sscanf(items[5].c_str(),"%u", &mystatus);
933  else
934  {
935  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
936  continue;
937  }
938 
939  HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus); //atoi (items [4].c_str()) );
940  fObject->addValues(*fCondObject);
941  delete fCondObject;
942  // }
943  }
944  return true;
945 }
946 
947 
948 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalChannelQuality& fObject) {
949  char buffer [1024];
950  sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
951  fOutput << buffer;
952  std::vector<DetId> channels = fObject.getAllChannels ();
953  std::sort (channels.begin(), channels.end(), DetIdLess ());
954  for (std::vector<DetId>::iterator channel = channels.begin ();
955  channel != channels.end ();
956  ++channel) {
957  const int value = fObject.getValues (*channel)->getValue ();
958  dumpId (fOutput, *channel);
959  sprintf (buffer, "%6s %15X %10X\n", "(hex)",
960  value, channel->rawId ());
961  fOutput << buffer;
962  }
963  return true;
964 }
965 
966 
967 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
968 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalL1TriggerObjects* fObject)
969 {
970  char buffer [1024];
971 
972  while (fInput.getline(buffer, 1024)) {
973  if (buffer [0] == '#')
974  {
975  if (buffer [1] == 'T') // contains tag name
976  {
977  std::vector <std::string> items = splitString (std::string (buffer) );
978  fObject->setTagString(items[1]);
979  continue;
980  }
981  if (buffer [1] == 'A') // contains algo name
982  {
983  std::vector <std::string> items = splitString (std::string (buffer) );
984  fObject->setAlgoString(items[1]);
985  continue;
986  }
987  else continue; //ignore comment
988  }
989  std::vector <std::string> items = splitString (std::string (buffer));
990  if (items.size()==0) continue; // blank line
991  if (items.size () < 7) {
992  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
993  continue;
994  }
995  DetId id = getId (items);
996 
997  HcalL1TriggerObject* fCondObject = new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()) );
998 
999  fObject->addValues(*fCondObject);
1000  delete fCondObject;
1001  }
1002  return true;
1003 }
1004 
1005 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalL1TriggerObjects& fObject)
1006 {
1007  char buffer [1024];
1008  //first print tag and algo
1009  sprintf (buffer, "#T %s << this is the tag name \n", fObject.getTagString().c_str() );
1010  fOutput << buffer;
1011  sprintf (buffer, "#A %s << this is the algorithm name \n", fObject.getAlgoString().c_str() );
1012  fOutput << buffer;
1013 
1014  //then the values
1015  sprintf (buffer, "# %15s %15s %15s %15s %8s %13s %8s %10s\n",
1016  "eta", "phi", "dep", "det", "ped", "respcorrgain", "flag",
1017  "DetId");
1018  fOutput << buffer;
1019  std::vector<DetId> channels = fObject.getAllChannels ();
1020  // std::sort (channels.begin(), channels.end(), DetIdLess ());
1021  for (std::vector<DetId>::iterator channel = channels.begin ();
1022  channel != channels.end ();
1023  ++channel) {
1024  const HcalL1TriggerObject* item = fObject.getValues (*channel);
1025  if (item) {
1026  dumpId (fOutput, *channel);
1027  sprintf (buffer, " %10.7f %10.7f %12d %10X\n",
1028  item->getPedestal(), item->getRespGain(), item->getFlag(), channel->rawId ());
1029  fOutput << buffer;
1030  }
1031  }
1032  return true;
1033 
1034 }
1035 
1036 
1037 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1038 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestalWidths* fObject) {
1039  char buffer [1024];
1040  int linecounter = 0;
1041 
1042  while (fInput.getline(buffer, 1024)) {
1043  linecounter++;
1044  std::vector <std::string> items = splitString (std::string (buffer));
1045  if (items.size()==0) continue; // blank line
1046  else {
1047  if (items[0] == (std::string)"#U")
1048  {
1049  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
1050  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
1051  else
1052  {
1053  edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
1054  fObject->setUnitADC(false);
1055  }
1056  break;
1057  }
1058  else
1059  {
1060  edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
1061  return false;
1062  }
1063  }
1064  }
1065 
1066  while (fInput.getline(buffer, 1024)) {
1067  linecounter++;
1068  if (buffer [0] == '#') continue; //ignore comment
1069  std::vector <std::string> items = splitString (std::string (buffer));
1070  if (items.size()==0) continue; // blank line
1071  if (items.size () < 14) {
1072  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
1073  << " or 20 items: eta, phi, depth, subdet, 16x correlations"
1074  << std::endl;
1075  continue;
1076  }
1077  DetId id = getId (items);
1078 
1079 // if (fObject->exists(id) )
1080 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1081 // else
1082 // {
1083 
1084  if (items.size() < 20) //old format
1085  {
1087  values.setSigma (0, 0, atof (items [4].c_str()));
1088  values.setSigma (1, 0, atof (items [5].c_str()));
1089  values.setSigma (1, 1, atof (items [6].c_str()));
1090  values.setSigma (2, 0, atof (items [7].c_str()));
1091  values.setSigma (2, 1, atof (items [8].c_str()));
1092  values.setSigma (2, 2, atof (items [9].c_str()));
1093  values.setSigma (3, 0, atof (items [10].c_str()));
1094  values.setSigma (3, 1, atof (items [11].c_str()));
1095  values.setSigma (3, 2, atof (items [12].c_str()));
1096  values.setSigma (3, 3, atof (items [13].c_str()));
1097  values.setSigma (0, 1, 0.);
1098  values.setSigma (0, 2, 0.);
1099  values.setSigma (0, 3, 0.);
1100  values.setSigma (1, 2, 0.);
1101  values.setSigma (1, 3, 0.);
1102  values.setSigma (2, 3, 0.);
1103  fObject->addValues(values);
1104  }
1105  else // new format
1106  {
1108  values.setSigma (0, 0, atof (items [4].c_str()) );
1109  values.setSigma (0, 1, atof (items [5].c_str()) );
1110  values.setSigma (0, 2, atof (items [6].c_str()) );
1111  values.setSigma (0, 3, atof (items [7].c_str()) );
1112  values.setSigma (1, 0, atof (items [8].c_str()) );
1113  values.setSigma (1, 1, atof (items [9].c_str()) );
1114  values.setSigma (1, 2, atof (items [10].c_str()) );
1115  values.setSigma (1, 3, atof (items [11].c_str()) );
1116  values.setSigma (2, 0, atof (items [12].c_str()) );
1117  values.setSigma (2, 1, atof (items [13].c_str()) );
1118  values.setSigma (2, 2, atof (items [14].c_str()) );
1119  values.setSigma (2, 3, atof (items [15].c_str()) );
1120  values.setSigma (3, 0, atof (items [16].c_str()) );
1121  values.setSigma (3, 1, atof (items [17].c_str()) );
1122  values.setSigma (3, 2, atof (items [18].c_str()) );
1123  values.setSigma (3, 3, atof (items [19].c_str()) );
1124  fObject->addValues(values);
1125  }
1126 
1127  // }
1128  }
1129  return true;
1130 }
1131 
1132 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestalWidths& fObject) {
1133  char buffer [1024];
1134  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
1135  else sprintf (buffer, "#U fC << this is the unit \n");
1136  fOutput << buffer;
1137 
1138  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
1139  "eta", "phi", "dep", "det",
1140  "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",
1141  "DetId");
1142  fOutput << buffer;
1143  std::vector<DetId> channels = fObject.getAllChannels ();
1144  std::sort (channels.begin(), channels.end(), DetIdLess ());
1145  for (std::vector<DetId>::iterator channel = channels.begin ();
1146  channel != channels.end ();
1147  ++channel) {
1148  const HcalPedestalWidth* item = fObject.getValues (*channel);
1149  if (item) {
1150  dumpId (fOutput, *channel);
1151  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",
1152  item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3),
1153  item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
1154  item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
1155  item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
1156  fOutput << buffer;
1157  }
1158  }
1159  return true;
1160 }
1161 
1162 
1163 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1164 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalQIEData* fObject) {
1165  char buffer [1024];
1166  while (fInput.getline(buffer, 1024)) {
1167  if (buffer [0] == '#') continue; //ignore comment
1168  std::vector <std::string> items = splitString (std::string (buffer));
1169  if (items.size()<1) continue;
1170  if (items [0] == "SHAPE") { // basic shape
1171  //this shape keyword is obsolete
1172  }
1173  else { // QIE parameters
1174  if (items.size () < 36) {
1175  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;
1176  continue;
1177  }
1178  DetId id = getId (items);
1179  fObject->sort ();
1180  // try {
1181  // fObject->getCoder (id);
1182  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1183  // }
1184 // catch (cms::Exception& e) {
1185  HcalQIECoder coder (id.rawId ());
1186  int index = 4;
1187  for (unsigned capid = 0; capid < 4; capid++) {
1188  for (unsigned range = 0; range < 4; range++) {
1189  coder.setOffset (capid, range, atof (items [index++].c_str ()));
1190  }
1191  }
1192  for (unsigned capid = 0; capid < 4; capid++) {
1193  for (unsigned range = 0; range < 4; range++) {
1194  coder.setSlope (capid, range, atof (items [index++].c_str ()));
1195  }
1196  }
1197 
1198  fObject->addCoder (coder);
1199 // }
1200  }
1201  }
1202  fObject->sort ();
1203  return true;
1204 }
1205 
1206 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalQIEData& fObject) {
1207  std::cout <<"dumping object\n";
1208  char buffer [1024];
1209 
1210  fOutput << "# QIE data" << std::endl;
1211  sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
1212  "eta", "phi", "dep", "det",
1213  "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
1214  "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
1215  fOutput << buffer;
1216  std::vector<DetId> channels = fObject.getAllChannels ();
1217  std::sort (channels.begin(), channels.end(), DetIdLess ());
1218  for (std::vector<DetId>::iterator channel = channels.begin ();
1219  channel != channels.end ();
1220  ++channel) {
1221  const HcalQIECoder* coder = fObject.getCoder (*channel);
1222  dumpId (fOutput, *channel);
1223  for (unsigned capid = 0; capid < 4; capid++) {
1224  for (unsigned range = 0; range < 4; range++) {
1225  sprintf (buffer, " %8.5f", coder->offset (capid, range));
1226  fOutput << buffer;
1227  }
1228  }
1229  for (unsigned capid = 0; capid < 4; capid++) {
1230  for (unsigned range = 0; range < 4; range++) {
1231  sprintf (buffer, " %8.5f", coder->slope (capid, range));
1232  fOutput << buffer;
1233  }
1234  }
1235  fOutput << std::endl;
1236  }
1237  return true;
1238 }
1239 
1240 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1241 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCalibrationQIEData* fObject) {
1242  char buffer [1024];
1243  while (fInput.getline(buffer, 1024)) {
1244  if (buffer [0] == '#') continue; //ignore comment
1245  std::vector <std::string> items = splitString (std::string (buffer));
1246  if (items.size () < 36) {
1247  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
1248  continue;
1249  }
1250  DetId id = getId (items);
1251  fObject->sort ();
1252  // try {
1253  // fObject->getCoder (id);
1254  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1255  // }
1256 // catch (cms::Exception& e) {
1257  HcalCalibrationQIECoder coder (id.rawId ());
1258  int index = 4;
1259  float values [32];
1260  for (unsigned bin = 0; bin < 32; bin++) {
1261  values[bin] = atof (items [index++].c_str ());
1262  }
1263  coder.setMinCharges (values);
1264  fObject->addCoder (coder);
1265 // }
1266  }
1267  fObject->sort ();
1268  return true;
1269 }
1270 
1271 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
1272  char buffer [1024];
1273  fOutput << "# QIE data in calibration mode" << std::endl;
1274  sprintf (buffer, "# %15s %15s %15s %15s %288s\n",
1275  "eta", "phi", "dep", "det", "32 x charges");
1276  fOutput << buffer;
1277  std::vector<DetId> channels = fObject.getAllChannels ();
1278  std::sort (channels.begin(), channels.end(), DetIdLess ());
1279  for (std::vector<DetId>::iterator channel = channels.begin ();
1280  channel != channels.end ();
1281  ++channel) {
1282  const HcalCalibrationQIECoder* coder = fObject.getCoder (*channel);
1283  if (coder) {
1284  dumpId (fOutput, *channel);
1285  const float* lowEdge = coder->minCharges ();
1286  for (unsigned bin = 0; bin < 32; bin++) {
1287  sprintf (buffer, " %8.5f", lowEdge [bin]);
1288  fOutput << buffer;
1289  }
1290  fOutput << std::endl;
1291  }
1292  }
1293  return true;
1294 }
1295 
1296 
1297 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1298 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalElectronicsMap* fObject) {
1299  char buffer [1024];
1300  while (fInput.getline(buffer, 1024)) {
1301  if (buffer [0] == '#') continue; //ignore comment
1302  std::vector <std::string> items = splitString (std::string (buffer));
1303  if (items.size () < 12) {
1304  if (items.size()==0) continue; // no warning here
1305  if (items.size()<9) {
1306  edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
1307  continue;
1308  }
1309  if (items[8]=="NA" || items[8]=="NT") {
1310  while (items.size()<12) items.push_back(""); // don't worry here
1311  } else if (items[8]=="HT") {
1312  if (items.size()==11) items.push_back("");
1313  else {
1314  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
1315  << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
1316  continue;
1317  }
1318  } else {
1319  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
1320  << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
1321  continue;
1322  }
1323  }
1324  // std::cout << "HcalElectronicsMap-> processing line: " << buffer << std::endl;
1325  int crate = atoi (items [1].c_str());
1326  int slot = atoi (items [2].c_str());
1327  int top = 1;
1328  if (items [3] == "b") top = 0;
1329  int dcc = atoi (items [4].c_str());
1330  int spigot = atoi (items [5].c_str());
1331  HcalElectronicsId elId;
1332  if (items[3][0] == 'u') { // uTCA!
1333  int fiber = atoi (items [6].c_str());
1334  int fiberCh = atoi (items [7].c_str());
1335  bool isTrig=(items[8] == "HT" || items[8] == "NT");
1336  elId=HcalElectronicsId(crate, slot, fiber, fiberCh,isTrig);
1337  } else if (items[8] == "HT" || items[8] == "NT") {
1338  int slb = atoi (items [6].c_str());
1339  int slbCh = atoi (items [7].c_str());
1340  elId=HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
1341  } else {
1342  int fiber = atoi (items [6].c_str());
1343  int fiberCh = atoi (items [7].c_str());
1344 
1345  elId=HcalElectronicsId(fiberCh, fiber, spigot, dcc);
1346  elId.setHTR (crate, slot, top);
1347  }
1348 
1349  // first, handle undefined cases
1350  if (items [8] == "NA") { // undefined channel
1351  fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
1352  } else if (items [8] == "NT") { // undefined trigger channel
1353  fObject->mapEId2tId (elId, DetId (HcalTrigTowerDetId::Undefined));
1354  } else {
1355  HcalText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
1356  if (converter.isHcalDetId ()) {
1357  fObject->mapEId2chId (elId, converter.getId ());
1358  }
1359  else if (converter.isHcalTrigTowerDetId ()) {
1360  fObject->mapEId2tId (elId, converter.getId ());
1361  }
1362  else if (converter.isHcalCalibDetId ()) {
1363  fObject->mapEId2chId (elId, converter.getId ());
1364  }
1365  else if (converter.isHcalZDCDetId ()) {
1366  fObject->mapEId2chId (elId, converter.getId ());
1367  }
1368  else {
1369  edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: "
1370  << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
1371  }
1372  }
1373  }
1374  fObject->sort ();
1375  return true;
1376 }
1377 
1378 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalElectronicsMap& fObject) {
1379  std::vector<HcalElectronicsId> eids = fObject.allElectronicsId ();
1380  char buf [1024];
1381  // changes by Jared, 6.03.09/(included 25.03.09)
1382  // sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
1383  sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
1384  "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
1385  fOutput << buf << std::endl;
1386 
1387  for (unsigned i = 0; i < eids.size (); i++) {
1388  HcalElectronicsId eid = eids[i];
1389  if (eid.isTriggerChainId()) {
1390  DetId trigger = fObject.lookupTrigger (eid);
1391  if (trigger.rawId ()) {
1392  HcalText2DetIdConverter converter (trigger);
1393  if( eid.isVMEid() ){
1394  // changes by Jared, 6.03.09/(included 25.03.09)
1395  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1396  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1397  // i,
1398  converter.getId().rawId(),
1399  // changes by Jared, 6.03.09/(included 25.03.09)
1400  // eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1401  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
1402  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1403  );
1404  fOutput << buf << std::endl;
1405  }else if( eid.isUTCAid() ){
1406  sprintf (buf, " %7X %3d %3d u %4d %7d %10d %14d %7s %5s %5s %6s",
1407  converter.getId().rawId(),
1408 // eid.crateId(), eid.slot(), 0, eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1409  eid.crateId(), eid.slot(), 0, 0, eid.fiberIndex(), eid.fiberChanId(),
1410  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1411  );
1412  fOutput << buf << std::endl;
1413  }else{
1414  sprintf (buf, "NOT SUPPORTED!");
1415  fOutput << buf << std::endl;
1416  }
1417  }
1418  } else {
1419  DetId channel = fObject.lookup (eid);
1420  if (channel.rawId()) {
1421  HcalText2DetIdConverter converter (channel);
1422  if (eid.isVMEid()) {
1423  // changes by Jared, 6.03.09/(included 25.03.09)
1424  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1425  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1426  // i,
1427  converter.getId().rawId(),
1428  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1429  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1430  );
1431  } else {
1432  sprintf (buf, " %7X %3d %3d u %4d %7d %10d %14d %7s %5s %5s %6s",
1433  // i,
1434  converter.getId().rawId(),
1435 // eid.crateId(), eid.slot(), 0, eid.slot(), eid.fiberIndex(), eid.fiberChanId(),
1436  eid.crateId(), eid.slot(), 0, 0, eid.fiberIndex(), eid.fiberChanId(),
1437  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1438  );
1439  }
1440  fOutput << buf << std::endl;
1441  }
1442  }
1443  }
1444  return true;
1445 }
1446 
1447 
1448 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLutMetadata* fObject){
1449  if (!fObject) return false; //fObject = new HcalLutMetadata;
1450  char buffer [1024];
1451  while (fInput.getline(buffer, 1024)) {
1452  if (buffer [0] == '#') continue; //ignore comment
1453  std::vector <std::string> items = splitString (std::string (buffer));
1454  if (items.size()==0) continue; // blank line
1455  // now get non-channel data
1456  if (items.size() > 1 &&
1457  items[0].find("RctLsb")!=std::string::npos){
1458  fObject->setRctLsb( atof( items[1].c_str() ) );
1459  continue;
1460  }
1461  if (items.size() > 1 &&
1462  items[0].find("Gain")!=std::string::npos){
1463  fObject->setNominalGain( atof( items[1].c_str() ) );
1464  continue;
1465  }
1466  // now proceeed to per-channel data
1467  if (items.size () < 7) {
1468  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold" << std::endl;
1469  continue;
1470  }
1471  DetId id = getId (items);
1472 
1473  HcalLutMetadatum * fCondObject = new HcalLutMetadatum(id,
1474  atof (items [4].c_str()),
1475  atoi (items [5].c_str()),
1476  atoi (items [6].c_str()));
1477  fObject->addValues(*fCondObject);
1478  delete fCondObject;
1479  }
1480  return true;
1481 }
1482 
1483 
1484 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLutMetadata& fObject){
1485  char buffer [1024];
1486  const float _rctLsb = fObject.getRctLsb();
1487  const float _gain = fObject.getNominalGain();
1488  sprintf (buffer, "# %20s\n", "Non-channel data");
1489  fOutput << buffer;
1490  sprintf (buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
1491  fOutput << buffer;
1492  sprintf (buffer, "%8s %8.5f\n", "Gain", _gain);
1493  fOutput << buffer;
1494  sprintf (buffer, "# %15s %15s %15s %15s %8s %15s %19s %10s\n", "eta", "phi", "dep", "det", "Rcalib", "LutGranularity", "OutputLutThreshold", "DetId");
1495  fOutput << buffer;
1496  std::vector<DetId> channels = fObject.getAllChannels ();
1497  std::sort (channels.begin(), channels.end(), DetIdLess ());
1498  for (std::vector<DetId>::iterator channel = channels.begin ();
1499  channel != channels.end ();
1500  ++channel) {
1501  const float _rCalib = fObject.getValues (*channel)->getRCalib();
1502  const uint8_t _lutGranularity = fObject.getValues (*channel)->getLutGranularity();
1503  const uint8_t _outputLutThreshold = fObject.getValues (*channel)->getOutputLutThreshold();
1504  dumpId (fOutput, *channel);
1505  sprintf (buffer, " %8.5f %15d %19d %10X\n",
1506  _rCalib,
1507  _lutGranularity,
1508  _outputLutThreshold,
1509  channel->rawId ());
1510  fOutput << buffer;
1511  }
1512  return true;
1513 }
1514 
1515 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1516 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues * fObject) {
1517  if (!fObject) return false; //fObject = new HcalDcsValues;
1518  std::string buffer;
1519  while (getline(fInput, buffer)) {
1520  if (buffer.at(0) == '#') continue; //ignore comment
1521  std::vector <std::string> items = splitString (buffer);
1522  if (items.size()==0) continue; // blank line
1523 
1524  if (items.size() < 9) {
1525  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;
1526  continue;
1527  }
1528 
1529  HcalOtherSubdetector subd;
1530  int sidering;
1531  unsigned int slice, subchan;
1532  switch (items[0].at(1)) {
1533  case 'B':
1534  subd = HcalDcsBarrel;
1535  break;
1536  case 'E':
1537  subd = HcalDcsEndcap;
1538  break;
1539  case 'F':
1540  subd = HcalDcsForward;
1541  break;
1542  case 'O':
1543  subd = HcalDcsOuter;
1544  break;
1545  default:
1546  continue;
1547  }
1548  //from_string<int>(subd, items[0], std::dec);
1549  from_string<int>(sidering, items[1], std::dec);
1550  from_string<unsigned int>(slice, items[2], std::dec);
1551  //from_string<int>(ty, items[3], std::dec);
1552  from_string<unsigned int>(subchan, items[4], std::dec);
1553 
1554  HcalDcsDetId newId(subd, sidering, slice,
1555  HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
1556 
1557  int LS;
1558  float val,upper,lower;
1559  from_string<int>(LS, items[5], std::dec);
1560  from_string<float>(val, items[6], std::dec);
1561  from_string<float>(upper, items[7], std::dec);
1562  from_string<float>(lower, items[8], std::dec);
1563 
1564  HcalDcsValue newVal(newId.rawId(),LS,val,upper,lower);
1565 // std::cout << buffer << '\n';
1566 // std::cout << subd << ' ' << sidering << ' ' << slice << ' '
1567 // << ty << ' ' << subchan << ' ' << LS << ' '
1568 // << val << ' ' << upper << ' ' << lower << '\n';
1569 // std::cout << newId ;
1570  if (!(fObject->addValue(newVal))) {
1571  edm::LogWarning("Data Error") << "Data from line " << buffer
1572  << "\nwas not added to the HcalDcsValues object." << std::endl;
1573  }
1574 // std::cout << std::endl;
1575  }
1576  fObject->sortAll();
1577  return true;
1578 }
1579 
1580 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput,
1581  HcalDcsValues const& fObject) {
1582  fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
1583  for(int subd = HcalDcsValues::HcalHB;
1584  subd <= HcalDcsValues::HcalHF; ++subd) {
1585 // std::cout << "subd: " << subd << '\n';
1586  HcalDcsValues::DcsSet const & vals=
1588  for (HcalDcsValues::DcsSet::const_iterator val = vals.begin();
1589  val != vals.end(); ++val) {
1590  HcalDcsDetId valId(val->DcsId());
1591 
1592  switch (valId.subdet()) {
1593  case HcalDcsBarrel:
1594  fOutput << "HB ";
1595  break;
1596  case HcalDcsEndcap:
1597  fOutput << "HE ";
1598  break;
1599  case HcalDcsOuter:
1600  fOutput << "HO ";
1601  break;
1602  case HcalDcsForward:
1603  fOutput << "HF ";
1604  break;
1605  default :
1606  fOutput << valId.subdet() << ' ';
1607  }
1608 
1609  if (valId.subdet() == HcalDcsOuter)
1610  fOutput << valId.ring() << ' ';
1611  else
1612  fOutput << valId.zside() << ' ';
1613 
1614  fOutput << valId.slice() << ' '
1615  << valId.typeString(valId.type()) << ' '
1616  << valId.subchannel() << ' ';
1617  fOutput << val->LS() << ' '
1618  << val->getValue() << ' '
1619  << val->getUpperLimit() << ' '
1620  << val->getLowerLimit() << ' ';
1621  fOutput << std::hex << val->DcsId() << std::dec << '\n';
1622 
1623 // std::cout << valId << ' '
1624 // << valId.subdet() << ' '
1625 // << val->LS() << ' ' << val->getValue() << ' '
1626 // << val->getUpperLimit() << ' ' << val->getLowerLimit()
1627 // << std::endl;
1628  }
1629  }
1630 
1631  return true;
1632 }
1633 
1634 
1635 // Format of the ASCII file:
1636 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1637 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1638 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalDcsMap* fObject) {
1639  char buffer [1024];
1640  while (fInput.getline(buffer, 1024)) {
1641  if (buffer [0] == '#') continue; //ignore comment
1642  std::vector <std::string> items = splitString (std::string (buffer));
1643  if (items.size () < 8) {
1644  if (items.size()==0) continue; // no warning here
1645  else {
1646  edm::LogError("MapFormat") << "HcalDcsMap-> Bad line: " << buffer
1647  << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
1648  continue;
1649  }
1650  }
1651  // std::cout << "HcalDcsMap-> processing line: " << buffer << std::endl;
1652  //int ring = atoi (items [1].c_str());
1653  int ring = atoi(items[1].c_str());
1654  unsigned int slice = atoi (items [2].c_str());
1655  unsigned int subchannel = atoi (items [3].c_str());
1657 // if(items[4].find("HV")!=std::string::npos){
1658 // type = HcalDcsDetId::HV;
1659 // }
1660 // else if (items[4].find("BV")!=std::string::npos){
1661 // type = HcalDcsDetId::BV;
1662 // }
1663 // else if (items[4].find("CATH")!=std::string::npos){
1664 // type = HcalDcsDetId::CATH;
1665 // }
1666 // else if (items[4].find("DYN7")!=std::string::npos){
1667 // type = HcalDcsDetId::DYN7;
1668 // }
1669 // else if (items[4].find("DYN8")!=std::string::npos){
1670 // type = HcalDcsDetId::DYN8;
1671 // }
1672 // else if (items[4].find("RM_TEMP")!=std::string::npos){
1673 // type = HcalDcsDetId::RM_TEMP;
1674 // }
1675 // else if (items[4].find("CCM_TEMP")!=std::string::npos){
1676 // type = HcalDcsDetId::CCM_TEMP;
1677 // }
1678 // else if (items[4].find("CALIB_TEMP")!=std::string::npos){
1679 // type = HcalDcsDetId::CALIB_TEMP;
1680 // }
1681 // else if (items[4].find("LVTTM_TEMP")!=std::string::npos){
1682 // type = HcalDcsDetId::LVTTM_TEMP;
1683 // }
1684 // else if (items[4].find("TEMP")!=std::string::npos){
1685 // type = HcalDcsDetId::TEMP;
1686 // }
1687 // else if (items[4].find("QPLL_LOCK")!=std::string::npos){
1688 // type = HcalDcsDetId::QPLL_LOCK;
1689 // }
1690 // else if (items[4].find("STATUS")!=std::string::npos){
1691 // type = HcalDcsDetId::STATUS;
1692 // }
1693 // else if (items[4].find("DCS_MAX")!=std::string::npos){
1694 // type = HcalDcsDetId::DCS_MAX;
1695 // }
1696 // else{
1697 // edm::LogError("MapFormat") << "HcalDcsMap-> Unknown DCS Type, line is not accepted: " << items[4];
1698 // continue;
1699 // }
1701  if (items[4].find("CALIB")!=std::string::npos){
1702  subdet = HcalCalibration;
1703  }
1704  else if (items[4].find("HB")!=std::string::npos){
1705  subdet = HcalDcsBarrel;
1706  }
1707  else if (items[4].find("HE")!=std::string::npos){
1708  subdet = HcalDcsEndcap;
1709  }
1710  else if (items[4].find("HO")!=std::string::npos){
1711  subdet = HcalDcsOuter;
1712  }
1713  else if (items[4].find("HF")!=std::string::npos){
1714  subdet = HcalDcsForward;
1715  }
1716  else{
1717  edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
1718  continue;
1719  }
1720  HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
1721  HcalText2DetIdConverter converter (items [4], items [5], items [6], items [7]);
1722  HcalDetId id(0);
1723  if (converter.isHcalDetId()){
1724  id = converter.getId();
1725  }
1726  else{
1727  edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: "
1728  << items [4] << '/'
1729  << items [5] << '/'
1730  << items [6] << '/'
1731  << items [7] << std::endl;
1732  continue;
1733  }
1734  fObject->mapGeomId2DcsId(id, dcsId);
1735  }
1736  fObject->sort ();
1737  return true;
1738 }
1739 
1740 // Format of the ASCII file:
1741 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1742 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1743 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalDcsMap& fObject) {
1744  char buf [1024];
1745  sprintf (buf, "# %7s %10s %6s %8s %7s %5s %5s %6s",
1746  "i", "side_ring", "slice", "subchan", "subdet", "ieta", "iphi", "depth");
1747  fOutput << buf << std::endl;
1749  unsigned int line_counter = 0;
1750  for (_line = fObject.beginById();
1751  _line != fObject.endById();
1752  ++_line) {
1753  HcalDcsDetId dcsId = _line.getHcalDcsDetId();
1754  //std::string _dcs_type = "DCSUNKNOWN";
1755  HcalText2DetIdConverter _converter(_line.getHcalDetId());
1756  sprintf (buf, " %8X %10d %6d %8d %7s %5s %5s %6s",
1757  line_counter,
1758  dcsId.ring(), // contains zside() already
1759  dcsId.slice(),
1760  dcsId.subchannel(),
1761  _converter.getFlavor().c_str(),
1762  _converter.getField1().c_str(),
1763  _converter.getField2().c_str(),
1764  _converter.getField3().c_str()
1765  );
1766  fOutput << buf << std::endl;
1767  ++line_counter;
1768  }
1769  return true;
1770 }
1771 
1772 
1773 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalFlagHFDigiTimeParams* fObject)
1774 {
1775 
1776  if (!fObject) return false; //fObject = new HcalFlagHFDigiTimeParams();
1777  char buffer [1024];
1778  while (fInput.getline(buffer, 1024)) {
1779  if (buffer [0] == '#') continue; //ignore comment
1780  std::vector <std::string> items = splitString (std::string (buffer));
1781  if (items.size()==0) continue; // blank line
1782  if (items.size () != 9) {
1783  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain at 9 least items: eta, phi, depth, subdet, firstSample, samplesToAdd, ExpectedPeak, MinEnergy, and a set of comma-separated coefficients" << std::endl;
1784  continue;
1785  }
1786  // expects (ieta, iphi, depth, subdet) as first four arguments
1787  DetId id = HcalDbASCIIIO::getId (items);
1788  std::vector<double> coef= splitStringToDoubleByComma(items[8].c_str());
1789 
1790  HcalFlagHFDigiTimeParam* fCondObject = new HcalFlagHFDigiTimeParam(id,
1791  atoi (items [4].c_str()), //firstSample
1792  atoi (items [5].c_str()), //samplesToAdd
1793  atoi (items [6].c_str()), //expectedPeak
1794  atof (items [7].c_str()), // minEThreshold
1795  coef // coefficients
1796  );
1797  fObject->addValues(*fCondObject);
1798  delete fCondObject;
1799  }
1800  return true;
1801 } // getObject (HcalFlagHFDigiTime)
1802 
1803 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalFlagHFDigiTimeParams& fObject)
1804 {
1805  char buffer [1024];
1806  sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s %30s\n", "eta", "phi", "dep", "det", "FirstSample", "SamplesToAdd", "ExpectedPeak","MinEnergy","Coefficients");
1807  fOutput << buffer;
1808  std::vector<DetId> channels = fObject.getAllChannels ();
1809  std::sort (channels.begin(), channels.end(), DetIdLess ());
1810  for (std::vector<DetId>::iterator channel = channels.begin ();
1811  channel != channels.end ();
1812  ++channel) {
1813  // Dump out channel (ieta,iphi,depth,subdet) info
1814  HcalDbASCIIIO::dumpId (fOutput, *channel);
1815  // Dump out values for channel
1816  sprintf (buffer, " %15u %15u %15u %15f",
1817  fObject.getValues (*channel)->HFdigiflagFirstSample(),
1818  fObject.getValues (*channel)->HFdigiflagSamplesToAdd(),
1819  fObject.getValues (*channel)->HFdigiflagExpectedPeak(),
1820  fObject.getValues (*channel)->HFdigiflagMinEThreshold()
1821  );
1822 
1823  fOutput<<buffer; // dump flag reco values to buffer
1824  fOutput<<" "; // simple spacer
1825 
1826  std::vector<double> coef=fObject.getValues(*channel)->HFdigiflagCoefficients();
1827  for (std::vector<double>::size_type x=0;x<coef.size();++x)
1828  {
1829  // dump comma-separated list of coefficients
1830  fOutput<<coef[x];
1831  if (x<coef.size()-1) // add commas where necessary
1832  fOutput<<",";
1833  }
1834  sprintf(buffer,"\n");
1835  fOutput << buffer;
1836  }
1837  return true;
1838 }
1839 
1840 
void dumpIdShort(std::ostream &fOutput, DetId id)
uint32_t getFlag() const
type
Definition: HCALResponse.h:21
float getPedestal() const
unsigned int firstSample() const
Definition: HcalRecoParam.h:32
static const HcalDetId Undefined
Definition: HcalDetId.h:80
void setAlgoString(std::string fAlgo)
int i
Definition: DBlmapReader.cc:9
float timePhase() const
Definition: HcalMCParam.h:43
int fiberIndex() const
get the fiber index. For VME 1-8 (which of eight fibers carried by a spigot), for uTCA fibers are zer...
void setUnitADC(bool isADC)
Definition: HcalPedestals.h:30
float slope(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:54
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
unsigned int param2() const
Definition: HcalRecoParam.h:27
bool getHcalSingleIntObject(std::istream &fInput, T *fObject, S *fCondObject)
std::vector< unsigned int > signalTS() const
bool isADC() const
Definition: HcalPedestals.h:28
int subchannel() const
Definition: HcalDcsDetId.h:49
bool getHcalSingleFloatObject(std::istream &fInput, T *fObject, S *fCondObject)
static int slb(const HcalTriggerPrimitiveSample &theSample)
unsigned int pileupCleaningID() const
Definition: HcalRecoParam.h:44
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:39
bool timeSmearing() const
Definition: HcalMCParam.h:44
uint8_t getOutputLutThreshold() const
unsigned int packingScheme() const
Definition: HcalMCParam.h:45
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:235
uint32_t HFdigiflagSamplesToAdd() const
bool getHcalMatrixObject(std::istream &fInput, T *fObject, S *fCondObject)
std::vector< float > splitStringToFloatByComma(const std::string &fLine)
DcsSet const & getAllSubdetValues(DcsSubDet subd) const
bool correctForPhaseContainment() const
Definition: HcalRecoParam.h:29
int htrSlot() const
get the htr slot
std::vector< unsigned int > splitStringToIntByComma(const std::string &fLine)
const Item * getValues(DetId fId, bool throwOnFail=true) const
bool dumpHcalSingleFloatObject(std::ostream &fOutput, const T &fObject)
unsigned int noiseFlaggingID() const
Definition: HcalRecoParam.h:43
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
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)
uint16_t size_type
unsigned int leakCorrectionID() const
Definition: HcalRecoParam.h:37
bool addCoder(const HcalQIECoder &fCoder)
Definition: HcalQIEData.h:43
int crateId() const
get the readout VME crate number
bool setRctLsb(float rctlsb)
int readoutVMECrateId() const
get the readout VME crate number
void dumpId(std::ostream &fOutput, DetId id)
unsigned int param1() const
Definition: HcalMCParam.h:39
tuple result
Definition: mps_fire.py:95
float phase() const
unsigned int specialCaseID() const
Definition: HcalRecoParam.h:42
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
const_iterator endById(void) const
Definition: HcalDcsMap.cc:87
bool syncPhase() const
Definition: HcalMCParam.h:41
T x() const
Cartesian x coordinate.
std::vector< HcalDcsValue > DcsSet
Definition: HcalDcsValues.h:27
void setUnitADC(bool isADC)
float getRespGain() const
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
float offset(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:50
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:73
std::vector< DetId > getAllChannels() const
unsigned int param1() const
Definition: HcalRecoParam.h:26
unsigned int nhits() const
float getNominalGain() const
HcalDetId getHcalDetId(void)
Definition: HcalDcsMap.cc:126
HcalOtherSubdetector
Definition: HcalAssistant.h:32
float getRCalib() const
bool correctForTimeslew() const
Definition: HcalRecoParam.h:38
bool correctTiming() const
Definition: HcalRecoParam.h:40
int dccid() const
get the (Hcal local) DCC id for VME, crate number for uTCA
HcalDcsDetId getHcalDcsDetId(void)
Definition: HcalDcsMap.cc:122
int j
Definition: DBlmapReader.cc:9
bool dumpHcalMatrixObject(std::ostream &fOutput, const T &fObject)
double f[11][100]
uint32_t HFdigiflagExpectedPeak() const
int fiberChanId() const
get the fiber channel id (which of channels on a fiber)
std::string getTagString() const
unsigned int samplesToAdd() const
Definition: HcalRecoParam.h:33
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
float correctionPhaseNS() const
Definition: HcalRecoParam.h:31
int spigot() const
get the spigot (input number on DCC, AMC card number for uTCA)
unsigned int pulseShapeID() const
Definition: HcalRecoParam.h:34
static DcsType DcsTypeFromString(const std::string &str)
Definition: HcalDcsDetId.cc:31
int slbChannelIndex() const
get the SLB channel index (valid only for VME trigger-chain ids)
std::vector< double > HFdigiflagCoefficients() const
Definition: DetId.h:18
void setHTR(int crate, int slot, int tb)
bool isVMEid() const
std::string getAlgoString() const
std::vector< HcalElectronicsId > allElectronicsId() const
void sort()
Definition: HcalQIEData.h:45
uint32_t HFdigiflagFirstSample() const
int slot() const
get the htr or uHTR slot
void sort()
Definition: HcalDcsMap.h:78
int slice() const
Definition: HcalDcsDetId.h:47
float getRctLsb() const
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
bool isTriggerChainId() const
unsigned int signalShape() const
Definition: HcalMCParam.h:40
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)
unsigned int binOfMaximum() const
Definition: HcalMCParam.h:42
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
int slbSiteNumber() const
get the SLB site number (valid only for VME trigger-chain ids)
unsigned int packingScheme() const
Definition: HcalRecoParam.h:45
const float * getValues() const
get value for all capId = 0..3
Definition: HcalPedestal.h:19
bool dumpHcalObject(std::ostream &fOutput, const T &fObject)
std::vector< unsigned int > noiseTS() const
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
tuple cout
Definition: gather_cfg.py:145
unsigned int firstAuxTS() const
Definition: HcalRecoParam.h:41
const float * minCharges() const
void setTagString(std::string fTag)
uint32_t getValue() const
bool correctForLeadingEdge() const
Definition: HcalRecoParam.h:30
float rms() const
bool addCoder(const HcalCalibrationQIECoder &fCoder)
bool addValues(const Item &myItem)
long double T
int ring() const
Definition: HcalDcsDetId.h:46
Readout chain identification for Hcal.
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
bool setNominalGain(float gain)
bool isUTCAid() const
bool dumpHcalSingleIntObject(std::ostream &fOutput, const T &fObject)
unsigned int timeslewCorrectionID() const
Definition: HcalRecoParam.h:39
std::vector< double > splitStringToDoubleByComma(const std::string &fLine)
bool from_string(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &))
double HFdigiflagMinEThreshold() const
bool useLeakCorrection() const
Definition: HcalRecoParam.h:36