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