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.66 2011/11/23 13:48:27 abdullin 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) 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) 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) 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) 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) fObject = new HcalRecoParams();
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) 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) 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) 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  if (!fObject) fObject = new HcalPedestals(false);
814  char buffer [1024];
815 
816  while (fInput.getline(buffer, 1024)) {
817  std::vector <std::string> items = splitString (std::string (buffer));
818  if (items.size()==0) continue; // blank line
819  else {
820  if (items[0] == "#U")
821  {
822  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
823  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
824  else
825  {
826  edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
827  fObject->setUnitADC(false);
828  }
829  break;
830  }
831  else
832  {
833  edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
834  return false;
835  }
836  }
837  }
838  while (fInput.getline(buffer, 1024)) {
839  if (buffer [0] == '#') continue;
840  std::vector <std::string> items = splitString (std::string (buffer));
841  if (items.size()==0) continue; // blank line
842  if (items.size () < 8) {
843  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
844  << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
845  << std::endl;
846  continue;
847  }
848  DetId id = getId (items);
849 
850 // if (fObject->exists(id) )
851 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
852 // else
853 // {
854 
855  if (items.size() < 12) // old format without widths
856  {
857  HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
858  atof (items [6].c_str()), atof (items [7].c_str()),
859  0., 0., 0., 0. );
860  fObject->addValues(*fCondObject);
861  delete fCondObject;
862  }
863  else // new format with widths
864  {
865  HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
866  atof (items [6].c_str()), atof (items [7].c_str()),
867  atof (items [8].c_str()), atof (items [9].c_str()),
868  atof (items [10].c_str()), atof (items [11].c_str()) );
869  fObject->addValues(*fCondObject);
870  delete fCondObject;
871  }
872 
873  // }
874  }
875  return true;
876 }
877 
878 
879 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestals& fObject) {
880  char buffer [1024];
881  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
882  else sprintf (buffer, "#U fC << this is the unit \n");
883  fOutput << buffer;
884 
885  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");
886  fOutput << buffer;
887 
888  std::vector<DetId> channels = fObject.getAllChannels ();
889  std::sort (channels.begin(), channels.end(), DetIdLess ());
890  for (std::vector<DetId>::iterator channel = channels.begin ();
891  channel != channels.end ();
892  channel++) {
893  const float* values = fObject.getValues (*channel)->getValues ();
894  if (values) {
895  dumpId (fOutput, *channel);
896  sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
897  values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
898  fOutput << buffer;
899  }
900  }
901  return true;
902 }
903 
904 
905 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
906 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalChannelQuality* fObject)
907 {
908  if (!fObject) fObject = new HcalChannelQuality;
909  char buffer [1024];
910  while (fInput.getline(buffer, 1024)) {
911  if (buffer [0] == '#') continue; //ignore comment
912  std::vector <std::string> items = splitString (std::string (buffer));
913  if (items.size()==0) continue; // blank line
914  if (items.size () < 6) {
915  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;
916  continue;
917  }
918  DetId id = getId (items);
919 
920 // if (fObject->exists(id) )
921 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
922 // else
923 // {
924  uint32_t mystatus;
925  if (items[4] == "(hex)")
926  sscanf(items[5].c_str(),"%X", &mystatus);
927  else if (items[4] == "(dec)")
928  sscanf(items[5].c_str(),"%u", &mystatus);
929  else
930  {
931  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
932  continue;
933  }
934 
935  HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus); //atoi (items [4].c_str()) );
936  fObject->addValues(*fCondObject);
937  delete fCondObject;
938  // }
939  }
940  return true;
941 }
942 
943 
944 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalChannelQuality& fObject) {
945  char buffer [1024];
946  sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
947  fOutput << buffer;
948  std::vector<DetId> channels = fObject.getAllChannels ();
949  std::sort (channels.begin(), channels.end(), DetIdLess ());
950  for (std::vector<DetId>::iterator channel = channels.begin ();
951  channel != channels.end ();
952  channel++) {
953  const int value = fObject.getValues (*channel)->getValue ();
954  dumpId (fOutput, *channel);
955  sprintf (buffer, "%6s %15X %10X\n", "(hex)",
956  value, channel->rawId ());
957  fOutput << buffer;
958  }
959  return true;
960 }
961 
962 
963 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
964 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalL1TriggerObjects* fObject)
965 {
966  if (!fObject) fObject = new HcalL1TriggerObjects;
967  char buffer [1024];
968 
969  while (fInput.getline(buffer, 1024)) {
970  if (buffer [0] == '#')
971  {
972  if (buffer [1] == 'T') // contains tag name
973  {
974  std::vector <std::string> items = splitString (std::string (buffer) );
975  fObject->setTagString(items[1]);
976  continue;
977  }
978  if (buffer [1] == 'A') // contains algo name
979  {
980  std::vector <std::string> items = splitString (std::string (buffer) );
981  fObject->setAlgoString(items[1]);
982  continue;
983  }
984  else continue; //ignore comment
985  }
986  std::vector <std::string> items = splitString (std::string (buffer));
987  if (items.size()==0) continue; // blank line
988  if (items.size () < 7) {
989  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
990  continue;
991  }
992  DetId id = getId (items);
993 
994  HcalL1TriggerObject* fCondObject = new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()) );
995 
996  fObject->addValues(*fCondObject);
997  delete fCondObject;
998  }
999  return true;
1000 }
1001 
1002 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalL1TriggerObjects& fObject)
1003 {
1004  char buffer [1024];
1005  //first print tag and algo
1006  sprintf (buffer, "#T %s << this is the tag name \n", fObject.getTagString().c_str() );
1007  fOutput << buffer;
1008  sprintf (buffer, "#A %s << this is the algorithm name \n", fObject.getAlgoString().c_str() );
1009  fOutput << buffer;
1010 
1011  //then the values
1012  sprintf (buffer, "# %15s %15s %15s %15s %8s %13s %8s %10s\n",
1013  "eta", "phi", "dep", "det", "ped", "respcorrgain", "flag",
1014  "DetId");
1015  fOutput << buffer;
1016  std::vector<DetId> channels = fObject.getAllChannels ();
1017  // std::sort (channels.begin(), channels.end(), DetIdLess ());
1018  for (std::vector<DetId>::iterator channel = channels.begin ();
1019  channel != channels.end ();
1020  channel++) {
1021  const HcalL1TriggerObject* item = fObject.getValues (*channel);
1022  if (item) {
1023  dumpId (fOutput, *channel);
1024  sprintf (buffer, " %10.7f %10.7f %12d %10X\n",
1025  item->getPedestal(), item->getRespGain(), item->getFlag(), channel->rawId ());
1026  fOutput << buffer;
1027  }
1028  }
1029  return true;
1030 
1031 }
1032 
1033 
1034 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1035 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestalWidths* fObject) {
1036  if (!fObject) fObject = new HcalPedestalWidths(false);
1037  char buffer [1024];
1038  int linecounter = 0;
1039 
1040  while (fInput.getline(buffer, 1024)) {
1041  linecounter++;
1042  std::vector <std::string> items = splitString (std::string (buffer));
1043  if (items.size()==0) continue; // blank line
1044  else {
1045  if (items[0] == (std::string)"#U")
1046  {
1047  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
1048  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
1049  else
1050  {
1051  edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
1052  fObject->setUnitADC(false);
1053  }
1054  break;
1055  }
1056  else
1057  {
1058  edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
1059  return false;
1060  }
1061  }
1062  }
1063 
1064  while (fInput.getline(buffer, 1024)) {
1065  linecounter++;
1066  if (buffer [0] == '#') continue; //ignore comment
1067  std::vector <std::string> items = splitString (std::string (buffer));
1068  if (items.size()==0) continue; // blank line
1069  if (items.size () < 14) {
1070  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
1071  << " or 20 items: eta, phi, depth, subdet, 16x correlations"
1072  << std::endl;
1073  continue;
1074  }
1075  DetId id = getId (items);
1076 
1077 // if (fObject->exists(id) )
1078 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1079 // else
1080 // {
1081 
1082  if (items.size() < 20) //old format
1083  {
1085  values.setSigma (0, 0, atof (items [4].c_str()));
1086  values.setSigma (1, 0, atof (items [5].c_str()));
1087  values.setSigma (1, 1, atof (items [6].c_str()));
1088  values.setSigma (2, 0, atof (items [7].c_str()));
1089  values.setSigma (2, 1, atof (items [8].c_str()));
1090  values.setSigma (2, 2, atof (items [9].c_str()));
1091  values.setSigma (3, 0, atof (items [10].c_str()));
1092  values.setSigma (3, 1, atof (items [11].c_str()));
1093  values.setSigma (3, 2, atof (items [12].c_str()));
1094  values.setSigma (3, 3, atof (items [13].c_str()));
1095  values.setSigma (0, 1, 0.);
1096  values.setSigma (0, 2, 0.);
1097  values.setSigma (0, 3, 0.);
1098  values.setSigma (1, 2, 0.);
1099  values.setSigma (1, 3, 0.);
1100  values.setSigma (2, 3, 0.);
1101  fObject->addValues(values);
1102  }
1103  else // new format
1104  {
1106  values.setSigma (0, 0, atof (items [4].c_str()) );
1107  values.setSigma (0, 1, atof (items [5].c_str()) );
1108  values.setSigma (0, 2, atof (items [6].c_str()) );
1109  values.setSigma (0, 3, atof (items [7].c_str()) );
1110  values.setSigma (1, 0, atof (items [8].c_str()) );
1111  values.setSigma (1, 1, atof (items [9].c_str()) );
1112  values.setSigma (1, 2, atof (items [10].c_str()) );
1113  values.setSigma (1, 3, atof (items [11].c_str()) );
1114  values.setSigma (2, 0, atof (items [12].c_str()) );
1115  values.setSigma (2, 1, atof (items [13].c_str()) );
1116  values.setSigma (2, 2, atof (items [14].c_str()) );
1117  values.setSigma (2, 3, atof (items [15].c_str()) );
1118  values.setSigma (3, 0, atof (items [16].c_str()) );
1119  values.setSigma (3, 1, atof (items [17].c_str()) );
1120  values.setSigma (3, 2, atof (items [18].c_str()) );
1121  values.setSigma (3, 3, atof (items [19].c_str()) );
1122  fObject->addValues(values);
1123  }
1124 
1125  // }
1126  }
1127  return true;
1128 }
1129 
1130 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestalWidths& fObject) {
1131  char buffer [1024];
1132  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
1133  else sprintf (buffer, "#U fC << this is the unit \n");
1134  fOutput << buffer;
1135 
1136  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
1137  "eta", "phi", "dep", "det",
1138  "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",
1139  "DetId");
1140  fOutput << buffer;
1141  std::vector<DetId> channels = fObject.getAllChannels ();
1142  std::sort (channels.begin(), channels.end(), DetIdLess ());
1143  for (std::vector<DetId>::iterator channel = channels.begin ();
1144  channel != channels.end ();
1145  channel++) {
1146  const HcalPedestalWidth* item = fObject.getValues (*channel);
1147  if (item) {
1148  dumpId (fOutput, *channel);
1149  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",
1150  item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3),
1151  item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
1152  item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
1153  item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
1154  fOutput << buffer;
1155  }
1156  }
1157  return true;
1158 }
1159 
1160 
1161 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1162 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalQIEData* fObject) {
1163  char buffer [1024];
1164  while (fInput.getline(buffer, 1024)) {
1165  if (buffer [0] == '#') continue; //ignore comment
1166  std::vector <std::string> items = splitString (std::string (buffer));
1167  if (items.size()<1) continue;
1168  if (items [0] == "SHAPE") { // basic shape
1169  if (items.size () < 33) {
1170  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 33 items: SHAPE 32 x low QIE edges for first 32 bins" << std::endl;
1171  continue;
1172  }
1173  // comment, as normally not used -----------------------
1174  /*
1175  float lowEdges [32];
1176  int i = 32;
1177  while (--i >= 0) lowEdges [i] = atof (items [i+1].c_str ());
1178  */
1179  // fObject->setShape (lowEdges);
1180  }
1181  else { // QIE parameters
1182  if (items.size () < 36) {
1183  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;
1184  continue;
1185  }
1186  DetId id = getId (items);
1187  fObject->sort ();
1188  // try {
1189  // fObject->getCoder (id);
1190  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1191  // }
1192 // catch (cms::Exception& e) {
1193  HcalQIECoder coder (id.rawId ());
1194  int index = 4;
1195  for (unsigned capid = 0; capid < 4; capid++) {
1196  for (unsigned range = 0; range < 4; range++) {
1197  coder.setOffset (capid, range, atof (items [index++].c_str ()));
1198  }
1199  }
1200  for (unsigned capid = 0; capid < 4; capid++) {
1201  for (unsigned range = 0; range < 4; range++) {
1202  coder.setSlope (capid, range, atof (items [index++].c_str ()));
1203  }
1204  }
1205  fObject->addCoder (coder);
1206 // }
1207  }
1208  }
1209  fObject->sort ();
1210  return true;
1211 }
1212 
1213 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalQIEData& fObject) {
1214  char buffer [1024];
1215  fOutput << "# QIE basic shape: SHAPE 32 x low edge values for first 32 channels" << std::endl;
1216  sprintf (buffer, "SHAPE ");
1217  fOutput << buffer;
1218  for (unsigned bin = 0; bin < 32; bin++) {
1219  sprintf (buffer, " %8.5f", fObject.getShape ().lowEdge (bin));
1220  fOutput << buffer;
1221  }
1222  fOutput << std::endl;
1223 
1224  fOutput << "# QIE data" << std::endl;
1225  sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
1226  "eta", "phi", "dep", "det",
1227  "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
1228  "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
1229  fOutput << buffer;
1230  std::vector<DetId> channels = fObject.getAllChannels ();
1231  std::sort (channels.begin(), channels.end(), DetIdLess ());
1232  for (std::vector<DetId>::iterator channel = channels.begin ();
1233  channel != channels.end ();
1234  channel++) {
1235  const HcalQIECoder* coder = fObject.getCoder (*channel);
1236  dumpId (fOutput, *channel);
1237  for (unsigned capid = 0; capid < 4; capid++) {
1238  for (unsigned range = 0; range < 4; range++) {
1239  sprintf (buffer, " %8.5f", coder->offset (capid, range));
1240  fOutput << buffer;
1241  }
1242  }
1243  for (unsigned capid = 0; capid < 4; capid++) {
1244  for (unsigned range = 0; range < 4; range++) {
1245  sprintf (buffer, " %8.5f", coder->slope (capid, range));
1246  fOutput << buffer;
1247  }
1248  }
1249  fOutput << std::endl;
1250  }
1251  return true;
1252 }
1253 
1254 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1255 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCalibrationQIEData* fObject) {
1256  char buffer [1024];
1257  while (fInput.getline(buffer, 1024)) {
1258  if (buffer [0] == '#') continue; //ignore comment
1259  std::vector <std::string> items = splitString (std::string (buffer));
1260  if (items.size () < 36) {
1261  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
1262  continue;
1263  }
1264  DetId id = getId (items);
1265  fObject->sort ();
1266  // try {
1267  // fObject->getCoder (id);
1268  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1269  // }
1270 // catch (cms::Exception& e) {
1271  HcalCalibrationQIECoder coder (id.rawId ());
1272  int index = 4;
1273  float values [32];
1274  for (unsigned bin = 0; bin < 32; bin++) {
1275  values[bin] = atof (items [index++].c_str ());
1276  }
1277  coder.setMinCharges (values);
1278  fObject->addCoder (coder);
1279 // }
1280  }
1281  fObject->sort ();
1282  return true;
1283 }
1284 
1285 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
1286  char buffer [1024];
1287  fOutput << "# QIE data in calibration mode" << std::endl;
1288  sprintf (buffer, "# %15s %15s %15s %15s %288s\n",
1289  "eta", "phi", "dep", "det", "32 x charges");
1290  fOutput << buffer;
1291  std::vector<DetId> channels = fObject.getAllChannels ();
1292  std::sort (channels.begin(), channels.end(), DetIdLess ());
1293  for (std::vector<DetId>::iterator channel = channels.begin ();
1294  channel != channels.end ();
1295  channel++) {
1296  const HcalCalibrationQIECoder* coder = fObject.getCoder (*channel);
1297  if (coder) {
1298  dumpId (fOutput, *channel);
1299  const float* lowEdge = coder->minCharges ();
1300  for (unsigned bin = 0; bin < 32; bin++) {
1301  sprintf (buffer, " %8.5f", lowEdge [bin]);
1302  fOutput << buffer;
1303  }
1304  fOutput << std::endl;
1305  }
1306  }
1307  return true;
1308 }
1309 
1310 
1311 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1312 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalElectronicsMap* fObject) {
1313  char buffer [1024];
1314  while (fInput.getline(buffer, 1024)) {
1315  if (buffer [0] == '#') continue; //ignore comment
1316  std::vector <std::string> items = splitString (std::string (buffer));
1317  if (items.size () < 12) {
1318  if (items.size()==0) continue; // no warning here
1319  if (items.size()<9) {
1320  edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
1321  continue;
1322  }
1323  if (items[8]=="NA" || items[8]=="NT") {
1324  while (items.size()<12) items.push_back(""); // don't worry here
1325  } else if (items[8]=="HT") {
1326  if (items.size()==11) items.push_back("");
1327  else {
1328  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
1329  << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
1330  continue;
1331  }
1332  } else {
1333  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
1334  << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
1335  continue;
1336  }
1337  }
1338  // std::cout << "HcalElectronicsMap-> processing line: " << buffer << std::endl;
1339  int crate = atoi (items [1].c_str());
1340  int slot = atoi (items [2].c_str());
1341  int top = 1;
1342  if (items [3] == "b") top = 0;
1343  int dcc = atoi (items [4].c_str());
1344  int spigot = atoi (items [5].c_str());
1345  HcalElectronicsId elId;
1346  if (items[8] == "HT" || items[8] == "NT") {
1347  int slb = atoi (items [6].c_str());
1348  int slbCh = atoi (items [7].c_str());
1349  elId=HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
1350  } else {
1351  int fiber = atoi (items [6].c_str());
1352  int fiberCh = atoi (items [7].c_str());
1353 
1354  elId=HcalElectronicsId(fiberCh, fiber, spigot, dcc);
1355  elId.setHTR (crate, slot, top);
1356  }
1357 
1358  // first, handle undefined cases
1359  if (items [8] == "NA") { // undefined channel
1360  fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
1361  } else if (items [8] == "NT") { // undefined trigger channel
1362  fObject->mapEId2tId (elId, DetId (HcalTrigTowerDetId::Undefined));
1363  } else {
1364  HcalText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
1365  if (converter.isHcalDetId ()) {
1366  fObject->mapEId2chId (elId, converter.getId ());
1367  }
1368  else if (converter.isHcalTrigTowerDetId ()) {
1369  fObject->mapEId2tId (elId, converter.getId ());
1370  }
1371  else if (converter.isHcalCalibDetId ()) {
1372  fObject->mapEId2chId (elId, converter.getId ());
1373  }
1374  else if (converter.isHcalZDCDetId ()) {
1375  fObject->mapEId2chId (elId, converter.getId ());
1376  }
1377  else {
1378  edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: "
1379  << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
1380  }
1381  }
1382  }
1383  fObject->sort ();
1384  return true;
1385 }
1386 
1387 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalElectronicsMap& fObject) {
1388  std::vector<HcalElectronicsId> eids = fObject.allElectronicsId ();
1389  char buf [1024];
1390  // changes by Jared, 6.03.09/(included 25.03.09)
1391  // sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
1392  sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
1393  "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
1394  fOutput << buf << std::endl;
1395 
1396  for (unsigned i = 0; i < eids.size (); i++) {
1397  HcalElectronicsId eid = eids[i];
1398  if (eid.isTriggerChainId()) {
1399  DetId trigger = fObject.lookupTrigger (eid);
1400  if (trigger.rawId ()) {
1401  HcalText2DetIdConverter converter (trigger);
1402  // changes by Jared, 6.03.09/(included 25.03.09)
1403  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1404  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1405  // i,
1406  converter.getId().rawId(),
1407  // changes by Jared, 6.03.09/(included 25.03.09)
1408  // eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1409  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
1410  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1411  );
1412  fOutput << buf << std::endl;
1413  }
1414  } else {
1415  DetId channel = fObject.lookup (eid);
1416  if (channel.rawId()) {
1417  HcalText2DetIdConverter converter (channel);
1418  // changes by Jared, 6.03.09/(included 25.03.09)
1419  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1420  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1421  // i,
1422  converter.getId().rawId(),
1423  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1424  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1425  );
1426  fOutput << buf << std::endl;
1427  }
1428  }
1429  }
1430  return true;
1431 }
1432 
1433 
1434 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLutMetadata* fObject){
1435  if (!fObject) fObject = new HcalLutMetadata;
1436  char buffer [1024];
1437  while (fInput.getline(buffer, 1024)) {
1438  if (buffer [0] == '#') continue; //ignore comment
1439  std::vector <std::string> items = splitString (std::string (buffer));
1440  if (items.size()==0) continue; // blank line
1441  // now get non-channel data
1442  if (items.size() > 1 &&
1443  items[0].find("RctLsb")!=std::string::npos){
1444  fObject->setRctLsb( atof( items[1].c_str() ) );
1445  continue;
1446  }
1447  if (items.size() > 1 &&
1448  items[0].find("Gain")!=std::string::npos){
1449  fObject->setNominalGain( atof( items[1].c_str() ) );
1450  continue;
1451  }
1452  // now proceeed to per-channel data
1453  if (items.size () < 7) {
1454  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold" << std::endl;
1455  continue;
1456  }
1457  DetId id = getId (items);
1458 
1459  HcalLutMetadatum * fCondObject = new HcalLutMetadatum(id,
1460  atof (items [4].c_str()),
1461  atoi (items [5].c_str()),
1462  atoi (items [6].c_str()));
1463  fObject->addValues(*fCondObject);
1464  delete fCondObject;
1465  }
1466  return true;
1467 }
1468 
1469 
1470 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLutMetadata& fObject){
1471  char buffer [1024];
1472  const float _rctLsb = fObject.getRctLsb();
1473  const float _gain = fObject.getNominalGain();
1474  sprintf (buffer, "# %20s\n", "Non-channel data");
1475  fOutput << buffer;
1476  sprintf (buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
1477  fOutput << buffer;
1478  sprintf (buffer, "%8s %8.5f\n", "Gain", _gain);
1479  fOutput << buffer;
1480  sprintf (buffer, "# %15s %15s %15s %15s %8s %15s %19s %10s\n", "eta", "phi", "dep", "det", "Rcalib", "LutGranularity", "OutputLutThreshold", "DetId");
1481  fOutput << buffer;
1482  std::vector<DetId> channels = fObject.getAllChannels ();
1483  std::sort (channels.begin(), channels.end(), DetIdLess ());
1484  for (std::vector<DetId>::iterator channel = channels.begin ();
1485  channel != channels.end ();
1486  channel++) {
1487  const float _rCalib = fObject.getValues (*channel)->getRCalib();
1488  const uint8_t _lutGranularity = fObject.getValues (*channel)->getLutGranularity();
1489  const uint8_t _outputLutThreshold = fObject.getValues (*channel)->getOutputLutThreshold();
1490  dumpId (fOutput, *channel);
1491  sprintf (buffer, " %8.5f %15d %19d %10X\n",
1492  _rCalib,
1493  _lutGranularity,
1494  _outputLutThreshold,
1495  channel->rawId ());
1496  fOutput << buffer;
1497  }
1498  return true;
1499 }
1500 
1501 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1502 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues * fObject) {
1503  if (!fObject) fObject = new HcalDcsValues;
1504  std::string buffer;
1505  while (getline(fInput, buffer)) {
1506  if (buffer.at(0) == '#') continue; //ignore comment
1507  std::vector <std::string> items = splitString (buffer);
1508  if (items.size()==0) continue; // blank line
1509 
1510  if (items.size() < 9) {
1511  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;
1512  continue;
1513  }
1514 
1515  HcalOtherSubdetector subd;
1516  int sidering;
1517  unsigned int slice, subchan;
1518  switch (items[0].at(1)) {
1519  case 'B':
1520  subd = HcalDcsBarrel;
1521  break;
1522  case 'E':
1523  subd = HcalDcsEndcap;
1524  break;
1525  case 'F':
1526  subd = HcalDcsForward;
1527  break;
1528  case 'O':
1529  subd = HcalDcsOuter;
1530  break;
1531  default:
1532  continue;
1533  }
1534  //from_string<int>(subd, items[0], std::dec);
1535  from_string<int>(sidering, items[1], std::dec);
1536  from_string<unsigned int>(slice, items[2], std::dec);
1537  //from_string<int>(ty, items[3], std::dec);
1538  from_string<unsigned int>(subchan, items[4], std::dec);
1539 
1540  HcalDcsDetId newId(subd, sidering, slice,
1541  HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
1542 
1543  int LS;
1544  float val,upper,lower;
1545  from_string<int>(LS, items[5], std::dec);
1546  from_string<float>(val, items[6], std::dec);
1547  from_string<float>(upper, items[7], std::dec);
1548  from_string<float>(lower, items[8], std::dec);
1549 
1550  HcalDcsValue newVal(newId.rawId(),LS,val,upper,lower);
1551 // std::cout << buffer << '\n';
1552 // std::cout << subd << ' ' << sidering << ' ' << slice << ' '
1553 // << ty << ' ' << subchan << ' ' << LS << ' '
1554 // << val << ' ' << upper << ' ' << lower << '\n';
1555 // std::cout << newId ;
1556  if (!(fObject->addValue(newVal))) {
1557  edm::LogWarning("Data Error") << "Data from line " << buffer
1558  << "\nwas not added to the HcalDcsValues object." << std::endl;
1559  }
1560 // std::cout << std::endl;
1561  }
1562  fObject->sortAll();
1563  return true;
1564 }
1565 
1566 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput,
1567  HcalDcsValues const& fObject) {
1568  fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
1569  for(int subd = HcalDcsValues::HcalHB;
1570  subd <= HcalDcsValues::HcalHF; ++subd) {
1571 // std::cout << "subd: " << subd << '\n';
1572  HcalDcsValues::DcsSet const & vals=
1574  for (HcalDcsValues::DcsSet::const_iterator val = vals.begin();
1575  val != vals.end(); ++val) {
1576  HcalDcsDetId valId(val->DcsId());
1577 
1578  switch (valId.subdet()) {
1579  case HcalDcsBarrel:
1580  fOutput << "HB ";
1581  break;
1582  case HcalDcsEndcap:
1583  fOutput << "HE ";
1584  break;
1585  case HcalDcsOuter:
1586  fOutput << "HO ";
1587  break;
1588  case HcalDcsForward:
1589  fOutput << "HF ";
1590  break;
1591  default :
1592  fOutput << valId.subdet() << ' ';
1593  }
1594 
1595  if (valId.subdet() == HcalDcsOuter)
1596  fOutput << valId.ring() << ' ';
1597  else
1598  fOutput << valId.zside() << ' ';
1599 
1600  fOutput << valId.slice() << ' '
1601  << valId.typeString(valId.type()) << ' '
1602  << valId.subchannel() << ' ';
1603  fOutput << val->LS() << ' '
1604  << val->getValue() << ' '
1605  << val->getUpperLimit() << ' '
1606  << val->getLowerLimit() << ' ';
1607  fOutput << std::hex << val->DcsId() << std::dec << '\n';
1608 
1609 // std::cout << valId << ' '
1610 // << valId.subdet() << ' '
1611 // << val->LS() << ' ' << val->getValue() << ' '
1612 // << val->getUpperLimit() << ' ' << val->getLowerLimit()
1613 // << std::endl;
1614  }
1615  }
1616 
1617  return true;
1618 }
1619 
1620 
1621 // Format of the ASCII file:
1622 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1623 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1624 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalDcsMap* fObject) {
1625  char buffer [1024];
1626  while (fInput.getline(buffer, 1024)) {
1627  if (buffer [0] == '#') continue; //ignore comment
1628  std::vector <std::string> items = splitString (std::string (buffer));
1629  if (items.size () < 8) {
1630  if (items.size()==0) continue; // no warning here
1631  else {
1632  edm::LogError("MapFormat") << "HcalDcsMap-> Bad line: " << buffer
1633  << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
1634  continue;
1635  }
1636  }
1637  // std::cout << "HcalDcsMap-> processing line: " << buffer << std::endl;
1638  //int ring = atoi (items [1].c_str());
1639  int ring = atoi(items[1].c_str());
1640  unsigned int slice = atoi (items [2].c_str());
1641  unsigned int subchannel = atoi (items [3].c_str());
1643 // if(items[4].find("HV")!=std::string::npos){
1644 // type = HcalDcsDetId::HV;
1645 // }
1646 // else if (items[4].find("BV")!=std::string::npos){
1647 // type = HcalDcsDetId::BV;
1648 // }
1649 // else if (items[4].find("CATH")!=std::string::npos){
1650 // type = HcalDcsDetId::CATH;
1651 // }
1652 // else if (items[4].find("DYN7")!=std::string::npos){
1653 // type = HcalDcsDetId::DYN7;
1654 // }
1655 // else if (items[4].find("DYN8")!=std::string::npos){
1656 // type = HcalDcsDetId::DYN8;
1657 // }
1658 // else if (items[4].find("RM_TEMP")!=std::string::npos){
1659 // type = HcalDcsDetId::RM_TEMP;
1660 // }
1661 // else if (items[4].find("CCM_TEMP")!=std::string::npos){
1662 // type = HcalDcsDetId::CCM_TEMP;
1663 // }
1664 // else if (items[4].find("CALIB_TEMP")!=std::string::npos){
1665 // type = HcalDcsDetId::CALIB_TEMP;
1666 // }
1667 // else if (items[4].find("LVTTM_TEMP")!=std::string::npos){
1668 // type = HcalDcsDetId::LVTTM_TEMP;
1669 // }
1670 // else if (items[4].find("TEMP")!=std::string::npos){
1671 // type = HcalDcsDetId::TEMP;
1672 // }
1673 // else if (items[4].find("QPLL_LOCK")!=std::string::npos){
1674 // type = HcalDcsDetId::QPLL_LOCK;
1675 // }
1676 // else if (items[4].find("STATUS")!=std::string::npos){
1677 // type = HcalDcsDetId::STATUS;
1678 // }
1679 // else if (items[4].find("DCS_MAX")!=std::string::npos){
1680 // type = HcalDcsDetId::DCS_MAX;
1681 // }
1682 // else{
1683 // edm::LogError("MapFormat") << "HcalDcsMap-> Unknown DCS Type, line is not accepted: " << items[4];
1684 // continue;
1685 // }
1687  if (items[4].find("CALIB")!=std::string::npos){
1688  subdet = HcalCalibration;
1689  }
1690  else if (items[4].find("HB")!=std::string::npos){
1691  subdet = HcalDcsBarrel;
1692  }
1693  else if (items[4].find("HE")!=std::string::npos){
1694  subdet = HcalDcsEndcap;
1695  }
1696  else if (items[4].find("HO")!=std::string::npos){
1697  subdet = HcalDcsOuter;
1698  }
1699  else if (items[4].find("HF")!=std::string::npos){
1700  subdet = HcalDcsForward;
1701  }
1702  else{
1703  edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
1704  continue;
1705  }
1706  HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
1707  HcalText2DetIdConverter converter (items [4], items [5], items [6], items [7]);
1708  HcalDetId id(0);
1709  if (converter.isHcalDetId()){
1710  id = converter.getId();
1711  }
1712  else{
1713  edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: "
1714  << items [4] << '/'
1715  << items [5] << '/'
1716  << items [6] << '/'
1717  << items [7] << std::endl;
1718  continue;
1719  }
1720  fObject->mapGeomId2DcsId(id, dcsId);
1721  }
1722  fObject->sort ();
1723  return true;
1724 }
1725 
1726 // Format of the ASCII file:
1727 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1728 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1729 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalDcsMap& fObject) {
1730  char buf [1024];
1731  sprintf (buf, "# %7s %10s %6s %8s %7s %5s %5s %6s",
1732  "i", "side_ring", "slice", "subchan", "subdet", "ieta", "iphi", "depth");
1733  fOutput << buf << std::endl;
1735  unsigned int line_counter = 0;
1736  for (_line = fObject.beginById();
1737  _line != fObject.endById();
1738  ++_line) {
1739  HcalDcsDetId dcsId = _line.getHcalDcsDetId();
1740  //std::string _dcs_type = "DCSUNKNOWN";
1741  HcalText2DetIdConverter _converter(_line.getHcalDetId());
1742  sprintf (buf, " %8X %10d %6d %8d %7s %5s %5s %6s",
1743  line_counter,
1744  dcsId.ring(), // contains zside() already
1745  dcsId.slice(),
1746  dcsId.subchannel(),
1747  _converter.getFlavor().c_str(),
1748  _converter.getField1().c_str(),
1749  _converter.getField2().c_str(),
1750  _converter.getField3().c_str()
1751  );
1752  fOutput << buf << std::endl;
1753  ++line_counter;
1754  }
1755  return true;
1756 }
1757 
1758 
1759 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalFlagHFDigiTimeParams* fObject)
1760 {
1761 
1762  if (!fObject) fObject = new HcalFlagHFDigiTimeParams();
1763  char buffer [1024];
1764  while (fInput.getline(buffer, 1024)) {
1765  if (buffer [0] == '#') continue; //ignore comment
1766  std::vector <std::string> items = splitString (std::string (buffer));
1767  if (items.size()==0) continue; // blank line
1768  if (items.size () != 9) {
1769  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;
1770  continue;
1771  }
1772  // expects (ieta, iphi, depth, subdet) as first four arguments
1773  DetId id = HcalDbASCIIIO::getId (items);
1774  std::vector<double> coef= splitStringToDoubleByComma(items[8].c_str());
1775 
1776  HcalFlagHFDigiTimeParam* fCondObject = new HcalFlagHFDigiTimeParam(id,
1777  atoi (items [4].c_str()), //firstSample
1778  atoi (items [5].c_str()), //samplesToAdd
1779  atoi (items [6].c_str()), //expectedPeak
1780  atof (items [7].c_str()), // minEThreshold
1781  coef // coefficients
1782  );
1783  fObject->addValues(*fCondObject);
1784  delete fCondObject;
1785  }
1786  return true;
1787 } // getObject (HcalFlagHFDigiTime)
1788 
1789 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalFlagHFDigiTimeParams& fObject)
1790 {
1791  char buffer [1024];
1792  sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s %30s\n", "eta", "phi", "dep", "det", "FirstSample", "SamplesToAdd", "ExpectedPeak","MinEnergy","Coefficients");
1793  fOutput << buffer;
1794  std::vector<DetId> channels = fObject.getAllChannels ();
1795  std::sort (channels.begin(), channels.end(), DetIdLess ());
1796  for (std::vector<DetId>::iterator channel = channels.begin ();
1797  channel != channels.end ();
1798  channel++) {
1799  // Dump out channel (ieta,iphi,depth,subdet) info
1800  HcalDbASCIIIO::dumpId (fOutput, *channel);
1801  // Dump out values for channel
1802  sprintf (buffer, " %15u %15u %15u %15f",
1803  fObject.getValues (*channel)->HFdigiflagFirstSample(),
1804  fObject.getValues (*channel)->HFdigiflagSamplesToAdd(),
1805  fObject.getValues (*channel)->HFdigiflagExpectedPeak(),
1806  fObject.getValues (*channel)->HFdigiflagMinEThreshold()
1807  );
1808 
1809  fOutput<<buffer; // dump flag reco values to buffer
1810  fOutput<<" "; // simple spacer
1811 
1812  std::vector<double> coef=fObject.getValues(*channel)->HFdigiflagCoefficients();
1813  for (std::vector<double>::size_type x=0;x<coef.size();++x)
1814  {
1815  // dump comma-separated list of coefficients
1816  fOutput<<coef[x];
1817  if (x<coef.size()-1) // add commas where necessary
1818  fOutput<<",";
1819  }
1820  sprintf(buffer,"\n");
1821  fOutput << buffer;
1822  }
1823  return true;
1824 }
1825 
1826 
void dumpIdShort(std::ostream &fOutput, DetId id)
uint32_t getFlag() const
type
Definition: HCALResponse.h:22
float getPedestal() const
unsigned int firstSample() const
Definition: HcalRecoParam.h:30
static const HcalDetId Undefined
Definition: HcalDetId.h:66
void setAlgoString(std::string fAlgo)
int i
Definition: DBlmapReader.cc:9
bool addValues(const Item &myItem, bool h2mode_=false)
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:25
float slope(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:52
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:23
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)
bool dumpHcalSingleFloatObject(std::ostream &fOutput, const T &fObject)
unsigned int noiseFlaggingID() const
Definition: HcalRecoParam.h:41
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
const HcalQIEShape & getShape() const
get basic shape
Definition: HcalQIEData.h:36
uint8_t getLutGranularity() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
const HcalCalibrationQIECoder * getCoder(DetId fId) const
get QIE parameters
std::vector< std::string > splitString(const std::string &fLine)
uint16_t size_type
unsigned int leakCorrectionID() const
Definition: HcalRecoParam.h:35
float lowEdge(unsigned fAdc) const
Definition: HcalQIEShape.cc:39
bool setRctLsb(float rctlsb)
int readoutVMECrateId() const
get the readout VME crate number
void dumpId(std::ostream &fOutput, DetId id)
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
bool addCoder(const HcalQIECoder &fCoder, bool h2mode_=false)
Definition: HcalQIEData.h:42
std::vector< HcalDcsValue > DcsSet
Definition: HcalDcsValues.h:25
void setUnitADC(bool isADC)
float getRespGain() const
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom)
float offset(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:48
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:45
std::vector< DetId > getAllChannels() const
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
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)
const Item * getValues(DetId fId) const
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