CMS 3D CMS Logo

HcalDbASCIIIO.cc
Go to the documentation of this file.
1 //
2 // F.Ratnikov (UMd), Oct 28, 2005
3 //
4 #include <vector>
5 #include <string>
6 #include <cstdio>
7 #include <sstream>
8 #include <memory>
9 #include <iostream>
10 
15 
19 
20 namespace {
21  class DetIdLess {
22  public:
23  bool operator () (DetId fFirst, DetId fSecond) const {
24  HcalGenericDetId first (fFirst);
25  HcalGenericDetId second (fSecond);
26  if (first.genericSubdet () != second.genericSubdet ()) return first.genericSubdet () < second.genericSubdet ();
27  if (first.isHcalDetId ()) {
28  HcalDetId f1 (first);
29  HcalDetId s1 (second);
30  return f1.zside () != s1.zside () ? f1.zside () < s1.zside () :
31  f1.iphi () != s1.iphi () ? f1.iphi () < s1.iphi () :
32  f1.ietaAbs () != s1.ietaAbs () ? f1.ietaAbs () < s1.ietaAbs () :
33  f1.depth () < s1.depth ();
34  }
35  else {
36  return first.rawId() < second.rawId();
37  }
38  }
39  };
40  class HcalElectronicsIdLess {
41  public:
42  bool operator () (HcalElectronicsId first, HcalElectronicsId second) const {
43  return
44  first.readoutVMECrateId () != second.readoutVMECrateId () ? first.readoutVMECrateId () < second.readoutVMECrateId () :
45  first.htrSlot () != second.htrSlot () ? first.htrSlot () < second.htrSlot () :
46  first.htrTopBottom () != second.htrTopBottom () ? first.htrTopBottom () < second.htrTopBottom () :
47  first.fiberIndex () != second.fiberIndex () ? first.fiberIndex () < second.fiberIndex () :
48  first.fiberChanId () < second.fiberChanId ();
49  }
50  };
51 }
52 
53 // ------------------------------ some little helpers ------------------------------
54 
55 std::vector <std::string> splitString (const std::string& fLine) {
56  std::vector <std::string> result;
57  int start = 0;
58  bool empty = true;
59  for (unsigned i = 0; i <= fLine.size (); i++) {
60  if (fLine [i] == ' ' || i == fLine.size ()) {
61  if (!empty) {
62  std::string item (fLine, start, i-start);
63  result.push_back (item);
64  empty = true;
65  }
66  start = i+1;
67  }
68  else {
69  if (empty) empty = false;
70  }
71  }
72  return result;
73 }
74 
75 std::vector <unsigned int> splitStringToIntByComma (const std::string& fLine) {
76  std::vector <unsigned int> result;
77  int start = 0;
78  bool empty = true;
79  for (unsigned i = 0; i <= fLine.size (); i++) {
80  if (fLine [i] == ',' || i == fLine.size ()) {
81  if (!empty) {
82  std::string itemString (fLine, start, i-start);
83  result.push_back (atoi (itemString.c_str()) );
84  empty = true;
85  }
86  start = i+1;
87  }
88  else {
89  if (empty) empty = false;
90  }
91  }
92  return result;
93 }
94 
95 std::vector <float> splitStringToFloatByComma (const std::string& fLine) {
96  std::vector <float> result;
97  int start = 0;
98  bool empty = true;
99  for (unsigned i = 0; i <= fLine.size (); i++) {
100  if (fLine [i] == ',' || i == fLine.size ()) {
101  if (!empty) {
102  std::string itemString (fLine, start, i-start);
103  result.push_back (atof (itemString.c_str()) );
104  empty = true;
105  }
106  start = i+1;
107  }
108  else {
109  if (empty) empty = false;
110  }
111  }
112  return result;
113 }
114 
115 std::vector <double> splitStringToDoubleByComma (const std::string& fLine) {
116  std::vector <double> result;
117  int start = 0;
118  bool empty = true;
119  for (unsigned i = 0; i <= fLine.size (); i++) {
120  if (fLine [i] == ',' || i == fLine.size ()) {
121  if (!empty) {
122  std::string itemString (fLine, start, i-start);
123  result.push_back (atof (itemString.c_str()) );
124  empty = true;
125  }
126  start = i+1;
127  }
128  else {
129  if (empty) empty = false;
130  }
131  }
132  return result;
133 }
134 
135 DetId HcalDbASCIIIO::getId (const std::vector <std::string> & items) {
136  HcalText2DetIdConverter converter (items [3], items [0], items [1], items [2]);
137  return converter.getId ();
138 }
139 
140 void HcalDbASCIIIO::dumpId (std::ostream& fOutput, DetId id) {
142  char buffer [1024];
143  sprintf (buffer, " %15s %15s %15s %15s",
144  converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
145  fOutput << buffer;
146 }
147 
148 void HcalDbASCIIIO::dumpIdShort (std::ostream& fOutput, DetId id) {
150  char buffer [1024];
151  sprintf (buffer, " %5s %4s %4s %10s",
152  converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str (),converter.getFlavor ().c_str ());
153  fOutput << buffer;
154 }
155 
156 
157 // ------------------------------ start templates ------------------------------
158 
159 template<class T>
160 bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) {
161  std::istringstream iss(s);
162  return !(iss >> f >> t).fail();
163 }
164 
165 template <class S,class T>
166 bool getHcalObject (std::istream& fInput, T* fObject) {
167  if (!fObject) return false; //fObject = new T;
168  char buffer [1024];
169  while (fInput.getline(buffer, 1024)) {
170  if (buffer [0] == '#') continue; //ignore comment
171  std::vector <std::string> items = splitString (std::string (buffer));
172  if (items.empty()) continue; // blank line
173  if (items.size () < 8) {
174  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values" << std::endl;
175  continue;
176  }
177  DetId id = HcalDbASCIIIO::getId (items);
178 
179 // if (fObject->exists(id) )
180 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
181 // else
182 // {
183  S fCondObject(id, atof (items [4].c_str()), atof (items [5].c_str()), atof (items [6].c_str()), atof (items [7].c_str()));
184  fObject->addValues(fCondObject);
185  // }
186  }
187 
188  return true;
189 }
190 
191 template <class T>
192 bool dumpHcalObject (std::ostream& fOutput, const T& fObject) {
193  char buffer [1024];
194  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %10s\n", "eta", "phi", "dep", "det", "cap0", "cap1", "cap2", "cap3", "DetId");
195  fOutput << buffer;
196  std::vector<DetId> channels = fObject.getAllChannels ();
197  std::sort (channels.begin(), channels.end(), DetIdLess ());
198  for (std::vector<DetId>::iterator channel = channels.begin ();
199  channel != channels.end ();
200  ++channel) {
201  const float* values = fObject.getValues (*channel)->getValues ();
202  if (values) {
203  HcalDbASCIIIO::dumpId (fOutput, *channel);
204  sprintf (buffer, " %10.7f %10.7f %10.7f %10.7f %10X\n",
205  values[0], values[1], values[2], values[3], channel->rawId ());
206  fOutput << buffer;
207  }
208  }
209  return true;
210 }
211 
212 template <class ObjectPrimitiveType, class S,class T>
213 bool getHcalSingleObject (std::istream& fInput, T* fObject) {
214  if (!fObject) return false; //fObject = new T;
215  char buffer [1024];
216  while (fInput.getline(buffer, 1024)) {
217  if (buffer [0] == '#') continue; //ignore comment
218  std::vector <std::string> items = splitString (std::string (buffer));
219  if (items.empty()) continue; // blank line
220  if (items.size () < 5) {
221  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, value" << std::endl;
222  continue;
223  }
224  DetId id = HcalDbASCIIIO::getId (items);
225 
226 // if (fObject->exists(id) )
227 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
228 // else
229 // {
230  std::stringstream ss(items[4]);
231  ObjectPrimitiveType x = 0; // usually int or float
232  ss >> x;
233  S fCondObject(id, x );
234  fObject->addValues(fCondObject);
235  // }
236  }
237  return true;
238 }
239 
240 template <class T>
241 bool dumpHcalSingleFloatObject (std::ostream& fOutput, const T& fObject) {
242  char buffer [1024];
243  sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
244  fOutput << buffer;
245  std::vector<DetId> channels = fObject.getAllChannels ();
246  std::sort (channels.begin(), channels.end(), DetIdLess ());
247  for (std::vector<DetId>::iterator channel = channels.begin ();
248  channel != channels.end ();
249  ++channel) {
250  const float value = fObject.getValues (*channel)->getValue ();
251  HcalDbASCIIIO::dumpId (fOutput, *channel);
252  sprintf (buffer, " %8.5f %10X\n",
253  value, channel->rawId ());
254  fOutput << buffer;
255  }
256  return true;
257 }
258 
259 template <class T>
260 bool dumpHcalSingleIntObject (std::ostream& fOutput, const T& fObject) {
261  char buffer [1024];
262  sprintf (buffer, "# %15s %15s %15s %15s %8s %10s\n", "eta", "phi", "dep", "det", "value", "DetId");
263  fOutput << buffer;
264  std::vector<DetId> channels = fObject.getAllChannels ();
265  std::sort (channels.begin(), channels.end(), DetIdLess ());
266  for (std::vector<DetId>::iterator channel = channels.begin ();
267  channel != channels.end ();
268  ++channel) {
269  const int value = fObject.getValues (*channel)->getValue ();
270  HcalDbASCIIIO::dumpId (fOutput, *channel);
271  sprintf (buffer, " %15d %10X\n",
272  value, channel->rawId ());
273  fOutput << buffer;
274  }
275  return true;
276 }
277 
278 template <class S,class T>
279 bool getHcalMatrixObject (std::istream& fInput, T* fObject, S* fCondObject) {
280  if (!fObject) return false; //fObject = new T;
281  char buffer [1024];
282  while (fInput.getline(buffer, 1024)) {
283  if (buffer [0] == '#') continue; //ignore comment
284  std::vector <std::string> items = splitString (std::string (buffer));
285  if (items.empty()) continue; // blank line
286  DetId firstid = HcalDbASCIIIO::getId (items);
287  fCondObject = new S(firstid.rawId());
288  for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), 0, j, atof(items[j+5].c_str()));
289  for(int i = 1; i != 40; i++){
290  fInput.getline(buffer, 1024);
291  items = splitString (std::string (buffer));
292  DetId id = HcalDbASCIIIO::getId (items);
293  if(id.rawId() != firstid.rawId()) break;//throw cms::Exception("Wrong number of elements");
294  for(int j = 0; j != 10; j++) fCondObject->setValue(atoi(items[4].c_str()), i%10, j, atof(items[j+5].c_str()));
295  }
296  fObject->addValues(*fCondObject);
297  delete fCondObject;
298  }
299  return true;
300 }
301 
302 template <class T>
303 bool dumpHcalMatrixObject (std::ostream& fOutput, const T& fObject) {
304  char buffer [1024];
305  sprintf (buffer, "# %5s %5s %5s %5s %5s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
306  "eta", "phi", "dep", "det", "capid","c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "DetId");
307  fOutput << buffer;
308  std::vector<DetId> channels = fObject.getAllChannels ();
309  std::sort (channels.begin(), channels.end(), DetIdLess ());
310  for (std::vector<DetId>::iterator channel = channels.begin ();
311  channel != channels.end ();
312  ++channel) {
313  float thisline[10];
314  for(int m = 0; m != 4; m++){
315  for(int i = 0; i != 10; i++){
316  for(int j = 0; j != 10; j++){
317 // std::cout <<"test "<<(fObject.getValues(*channel))->getValue(0,0,0);
318  thisline[j] = fObject.getValues(*channel)->getValue(m,i,j);
319 // thisline[j] = fObject.getValues(*channel)->getValue(1,1,1);
320  }
321  HcalDbASCIIIO::dumpId (fOutput, *channel);
322  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",
323  m, thisline[0], thisline[1], thisline[2], thisline[3], thisline[4], thisline[5], thisline[6], thisline[7],
324  thisline[8], thisline[9], channel->rawId());
325  fOutput << buffer;
326  }
327  }
328  }
329 
330  return true;
331 }
332 
333 // ------------------------------ end templates ------------------------------
334 
335 namespace HcalDbASCIIIO {
336  bool getObject (std::istream& fInput, HcalGains* fObject) {return getHcalObject<HcalGain> (fInput, fObject);}
337  bool dumpObject (std::ostream& fOutput, const HcalGains& fObject) {return dumpHcalObject (fOutput, fObject);}
338  bool getObject (std::istream& fInput, HcalGainWidths* fObject) {return getHcalObject<HcalGainWidth> (fInput, fObject);}
339  bool dumpObject (std::ostream& fOutput, const HcalGainWidths& fObject) {return dumpHcalObject (fOutput, fObject);}
340 
341  bool getObject (std::istream& fInput, HcalRespCorrs* fObject) {return getHcalSingleObject<float,HcalRespCorr> (fInput, fObject); }
342  bool dumpObject (std::ostream& fOutput, const HcalRespCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
343 
344  bool getObject (std::istream& fInput, HcalLUTCorrs* fObject) {return getHcalSingleObject<float,HcalLUTCorr> (fInput, fObject); }
345  bool dumpObject (std::ostream& fOutput, const HcalLUTCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
346 
347  bool getObject (std::istream& fInput, HcalPFCorrs* fObject) {return getHcalSingleObject<float,HcalPFCorr> (fInput, fObject); }
348  bool dumpObject (std::ostream& fOutput, const HcalPFCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
349 
350  bool getObject (std::istream& fInput, HcalTimeCorrs* fObject) {return getHcalSingleObject<float,HcalTimeCorr> (fInput, fObject); }
351  bool dumpObject (std::ostream& fOutput, const HcalTimeCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
352 
353  bool getObject (std::istream& fInput, HcalZSThresholds* fObject) {return getHcalSingleObject<int,HcalZSThreshold> (fInput, fObject); }
354  bool dumpObject (std::ostream& fOutput, const HcalZSThresholds& fObject) {return dumpHcalSingleIntObject (fOutput, fObject); }
355 
356  bool getObject (std::istream& fInput, HcalZDCLowGainFractions* fObject) {return getHcalSingleObject<float,HcalZDCLowGainFraction> (fInput, fObject); }
357  bool dumpObject (std::ostream& fOutput, const HcalZDCLowGainFractions& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
358 
359  bool getObject (std::istream& fInput, HcalValidationCorrs* fObject) {return getHcalSingleObject<float,HcalValidationCorr> (fInput, fObject); }
360  bool dumpObject (std::ostream& fOutput, const HcalValidationCorrs& fObject) {return dumpHcalSingleFloatObject (fOutput, fObject); }
361 
362  bool getObject (std::istream& fInput, HcalQIETypes* fObject) {return getHcalSingleObject<int,HcalQIEType> (fInput, fObject); }
363  bool dumpObject (std::ostream& fOutput, const HcalQIETypes& fObject) {return dumpHcalSingleIntObject (fOutput, fObject); }
364 }
365 
366 // ------------------------------ start specific implementations ------------------------------
367 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalRecoParams* fObject)
368 {
369  if (!fObject) return false; // fObject = new HcalRecoParams(); This was always useless...
370  char buffer [1024];
371  while (fInput.getline(buffer, 1024)) {
372  if (buffer [0] == '#') continue; //ignore comment
373  std::vector <std::string> items = splitString (std::string (buffer));
374  if (items.empty()) continue; // blank line
375  if (items.size () < 6) {
376  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, param1, param2" << std::endl;
377  continue;
378  }
379  DetId id = HcalDbASCIIIO::getId (items);
380 
381  int packingScheme =0;
382  if(items.size ()>22) {
383  packingScheme = atoi (items [22].c_str());
384  }
385 
386  int param1=0;
387  int param2=0;
388  if(packingScheme==0) {
389  param1=atoi (items [4].c_str());
390  param2=atoi (items [5].c_str());
391  } // packing scheme 0 (old format).
392 
393  if(packingScheme==1) {
394  // 0 1 2 3 4 5 6 7 8 9
395  int aabits[6]= {1,1, 8, 4, 4, 9};
396  int aamax[ 6]= {1,1,255,15,15,511};
397 
398  int bbbits[10]={1, 4,1, 4,1, 4, 4, 4, 4, 4};
399  int bbmax [10]={1,15,1,15,1,15,15,15,15,15};
400 
401  // param 1
402  int j=0;
403  int aa;
404  int aashift=0;
405  for(int i=0; i<6; i++) {
406  j=i+7;
407  if(i==2) {
408  float phase=atof (items [j].c_str());
409  float xphase=(phase+32.0)*4.0; // range of phase [-30.0,30.0]
410  aa=xphase;
411  } else {
412  aa=atoi (items [j].c_str());
413  }
414  if(aa>aamax[i] || aa<0) {
415  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for a"<<i<<" should be less than"<<aamax[i]<< std::endl;
416  }
417  param1=param1|aa<<aashift;
418  aashift=aashift+aabits[i];
419  }
420 
421  // param 2
422  int bb;
423  int bbshift=0;
424  for(int i=0; i<10; i++) {
425  j=i+13;
426  bb=atoi (items [j].c_str());
427  if(bb>bbmax[i]) {
428  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for b"<<i<<" should be less than"<<bbmax[i]<< std::endl;
429  }
430  param2=param2|bb<<bbshift;
431  bbshift=bbshift+bbbits[i];
432  }
433  } // packing sheme 1.
434 
435  // HcalRecoParam* fCondObject = new HcalRecoParam(id, atoi (items [4].c_str()), atoi (items [5].c_str()) );
436 
437  // std::cout<<" buffer "<<buffer<<std::endl;
438  // std::cout<<" param1, param2 "<<param1<<" "<<param2<<std::endl;
439 
440  HcalRecoParam* fCondObject = new HcalRecoParam(id, param1, param2 );
441  fObject->addValues(*fCondObject);
442  delete fCondObject;
443  }
444  return true;
445 }
446 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalRecoParams& fObject)
447 {
448  char buffer [1024];
449  // sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
450  // fOutput << buffer;
451  std::vector<DetId> channels = fObject.getAllChannels ();
452  std::sort (channels.begin(), channels.end(), DetIdLess ());
453  int myCounter=0;
454  for (std::vector<DetId>::iterator channel = channels.begin ();
455  channel != channels.end ();
456  ++channel) {
457  myCounter++;
458  int param1=fObject.getValues (*channel)->param1();
459  int param2=fObject.getValues (*channel)->param2();
460  int packingScheme=fObject.getValues (*channel)->packingScheme();
461 
462  // std::cout<<" Param1 "<<Param1<<" Param2 "<<Param2<<" packing "<<packingScheme<<std::endl;
463 
464  if(packingScheme==0) {
465  // old format
466  if(myCounter==1) {
467  sprintf (buffer, "# %15s %15s %15s %15s %18s %15s %10s\n", "eta", "phi", "dep", "det", "firstSample", "samplesToAdd", "DetId");
468  }
469  HcalDbASCIIIO::dumpId(fOutput, *channel);
470  sprintf (buffer, " %15d %15d %16X\n",
471  fObject.getValues (*channel)->firstSample(), fObject.getValues (*channel)->samplesToAdd(), channel->rawId ());
472  fOutput << buffer;
473  }
474 
475  if(packingScheme==1) {
476 
477  if(myCounter==1) {
478  char lineT[100],lineA[200],lineB[200];
479  //
480  sprintf (lineT, "#%50s"," "); fOutput << lineT;
481  sprintf (lineA, " %31s","a0: correctForPhaseContainment"); fOutput << lineA;
482  sprintf (lineB, " %36s","b0: useLeakCorrection\n"); fOutput << lineB;
483  //
484  sprintf (lineT, "#%50s"," "); fOutput << lineT;
485  sprintf (lineA, " %31s","a1: correctForLeadingEdge"); fOutput << lineA;
486  sprintf (lineB, " %36s","b1: leakCorrectionID\n"); fOutput << lineB;
487  //
488  sprintf (lineT, "#%50s"," "); fOutput << lineT;
489  sprintf (lineA, " %31s","a2: correctionPhaseNS"); fOutput << lineA;
490  sprintf (lineB, " %36s","b2: correctForTimeslew\n"); fOutput << lineB;
491  //
492  sprintf (lineT, "#%50s"," "); fOutput << lineT;
493  sprintf (lineA, " %31s","a3: firstSample"); fOutput << lineA;
494  sprintf (lineB, " %36s","b3: timeslewCorrectionID\n"); fOutput << lineB;
495  //
496  sprintf (lineT, "#%50s"," "); fOutput << lineT;
497  sprintf (lineA, " %31s","a4: samplesToAdd"); fOutput << lineA;
498  sprintf (lineB, " %36s","b4: correctTiming\n"); fOutput << lineB;
499  //
500  sprintf (lineT, "#%50s"," "); fOutput << lineT;
501  sprintf (lineA, " %31s","a5: pulseShapeID"); fOutput << lineA;
502  sprintf (lineB, " %36s","b5: firstAuxTS\n"); fOutput << lineB;
503  //
504  sprintf (lineT, "#%50s"," "); fOutput << lineT;
505  sprintf (lineA, " %31s"," "); fOutput << lineA;
506  sprintf (lineB, " %36s","b6: specialCaseID\n"); fOutput << lineB;
507  //
508  sprintf (lineT, "#%50s"," "); fOutput << lineT;
509  sprintf (lineA, " %31s"," "); fOutput << lineA;
510  sprintf (lineB, " %36s","b7: noiseFlaggingID\n"); fOutput << lineB;
511  //
512  sprintf (lineT, "#%50s"," "); fOutput << lineT;
513  sprintf (lineA, " %31s"," "); fOutput << lineA;
514  sprintf (lineB, " %36s","b8: pileupCleaningID\n"); fOutput << lineB;
515 
516  sprintf (lineT, "#%50s"," "); fOutput << lineT;
517  sprintf (lineA, " %31s"," "); fOutput << lineA;
518  sprintf (lineB, " %36s","b9: packingScheme\n"); fOutput << lineB;
519 
520  //
521  sprintf (lineT, "# %5s %4s %4s %10s %11s %10s %10s", "eta", "phi", "dep", "det", "param1", "param2", "DetId");
522  fOutput << lineT;
523 
524  sprintf (lineA, " %6s %4s %6s %4s %4s %4s", "a0", "a1", "a2", "a3", "a4", "a5");
525  fOutput << lineA;
526 
527  sprintf (lineB, " %6s %3s %3s %3s %3s %3s %3s %3s %3s\n", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8");
528  fOutput << lineB;
529  }
530 
531  HcalDbASCIIIO::dumpIdShort(fOutput, *channel);
532  sprintf (buffer, " %11d %10d %10X", param1, param2, channel->rawId ());
533  fOutput << buffer;
534 
535  bool aa0=fObject.getValues (*channel)->correctForPhaseContainment();
536  bool aa1=fObject.getValues (*channel)->correctForLeadingEdge();
537  float aa2=fObject.getValues (*channel)->correctionPhaseNS();
538  int aa3=fObject.getValues (*channel)->firstSample();
539  int aa4=fObject.getValues (*channel)->samplesToAdd();
540  int aa5=fObject.getValues (*channel)->pulseShapeID();
541  sprintf (buffer, " %6d %4d %6.1f %4d %4d %4d",aa0,aa1,aa2,aa3,aa4,aa5);
542  fOutput << buffer;
543 
544  bool bb0=fObject.getValues (*channel)->useLeakCorrection();
545  int bb1=fObject.getValues (*channel)->leakCorrectionID();
546  bool bb2=fObject.getValues (*channel)->correctForTimeslew();
547  int bb3=fObject.getValues (*channel)->timeslewCorrectionID();
548  bool bb4=fObject.getValues (*channel)->correctTiming();
549  int bb5=fObject.getValues (*channel)->firstAuxTS();
550  int bb6=fObject.getValues (*channel)->specialCaseID();
551  int bb7=fObject.getValues (*channel)->noiseFlaggingID();
552  int bb8=fObject.getValues (*channel)->pileupCleaningID();
553  int bb9=fObject.getValues (*channel)->packingScheme();
554  sprintf(buffer," %6d %3d %3d %3d %3d %3d %3d %3d %3d %3d\n",bb0,bb1,bb2,bb3,bb4,bb5,bb6,bb7,bb8,bb9);
555  fOutput << buffer;
556  } // packingScheme 1.
557 
558  } // loop ever channels
559  return true;
560 }
561 
562 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLongRecoParams* fObject)
563 {
564  if (!fObject) return false; // fObject = new HcalLongRecoParams();
565  char buffer [1024];
566  while (fInput.getline(buffer, 1024)) {
567  if (buffer [0] == '#') continue; //ignore comment
568  std::vector <std::string> items = splitString (std::string (buffer));
569  if (items.empty()) continue; // blank line
570  if (items.size() < 5) {
571  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs" << std::endl;
572  continue;
573  }
574  if (items.size() > 7) {
575  edm::LogWarning("Format Error") << "Check line: " << buffer << "\n line must contain 6 items: eta, phi, depth, subdet, signalTSs, noiseTSs. "
576  << "\n ! signalTS and noiseTS must be of format <ts1,ts2,ts3,...> withOUT spaces. Ignoring line for safety" << std::endl;
577  continue;
578  }
579  DetId id = HcalDbASCIIIO::getId (items);
580 
581  std::vector<unsigned int> mySignalTS = splitStringToIntByComma(items[4]);
582  std::vector<unsigned int> myNoiseTS = splitStringToIntByComma(items[5]);
583 
584  HcalLongRecoParam* fCondObject = new HcalLongRecoParam(id, mySignalTS, myNoiseTS );
585  fObject->addValues(*fCondObject);
586  delete fCondObject;
587  }
588  return true;
589 }
590 
591 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTimingParams* fObject)
592 {
593  if (!fObject) return false; // fObject = new HcalTimingParams();
594  char buffer [1024];
595  while (fInput.getline(buffer, 1024)) {
596  if (buffer [0] == '#') continue; //ignore comment
597  std::vector <std::string> items = splitString (std::string (buffer));
598  if (items.empty()) continue; // blank line
599  if (items.size () < 7) {
600  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, nhit, phase, rms,detid" << std::endl;
601  continue;
602  }
603  //std::cout<<"items[3] "<<items [3]<<std::endl;
604  //std::cout<<"items[0] "<<items [0]<<std::endl;
605  //std::cout<<"items[1] "<<items [1]<<std::endl;
606  //std::cout<<"items[2] "<<items [2]<<std::endl;
607 
608  //std::cout<<"items[4] "<<items [4]<<std::endl;
609  //std::cout<<"items[5] "<<items [5]<<std::endl;
610  //std::cout<<"items[6] "<<items [6]<<std::endl;
611  DetId id = HcalDbASCIIIO::getId (items);
612  //std::cout<<"calculated id "<<id.rawId()<<std::endl;
613  HcalTimingParam* fCondObject = new HcalTimingParam(id, atoi (items [4].c_str()), atof (items [5].c_str()), atof (items [6].c_str()));
614  fObject->addValues(*fCondObject);
615  delete fCondObject;
616  }
617  return true;
618 }
619 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTimingParams& fObject)
620 {
621  char buffer [1024];
622  sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s\n", "eta", "phi", "dep", "det", "nhit", "mean","rms" ,"DetId");
623  fOutput << buffer;
624  std::vector<DetId> channels = fObject.getAllChannels ();
625  std::sort (channels.begin(), channels.end(), DetIdLess ());
626  for (std::vector<DetId>::iterator channel = channels.begin ();
627  channel != channels.end ();
628  ++channel) {
629  HcalDbASCIIIO::dumpId (fOutput, *channel);
630  sprintf (buffer, " %15d %8.5f %8.5f %16X\n",
631  fObject.getValues (*channel)->nhits(), fObject.getValues (*channel)->phase(),fObject.getValues(*channel)->rms(),channel->rawId ());
632  fOutput << buffer;
633  }
634  return true;
635 }
636 
637 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLongRecoParams& fObject)
638 {
639  char buffer [1024];
640  sprintf (buffer, "# %15s %15s %15s %15s %10s %10s %10s\n", "eta", "phi", "dep", "det", "signalTSs", "noiseTSs", "DetId");
641  fOutput << buffer;
642  std::vector<DetId> channels = fObject.getAllChannels ();
643  std::sort (channels.begin(), channels.end(), DetIdLess ());
644  for (std::vector<DetId>::iterator channel = channels.begin ();
645  channel != channels.end ();
646  ++channel) {
647  HcalGenericDetId fId(*channel);
648  if (fId.isHcalZDCDetId())
649  {
650  std::vector<unsigned int> vSignalTS = fObject.getValues (*channel)->signalTS();
651  std::vector<unsigned int> vNoiseTS = fObject.getValues (*channel)->noiseTS();
652  HcalDbASCIIIO::dumpId (fOutput, *channel);
653  sprintf (buffer, " ");
654  fOutput << buffer;
655  for (unsigned int i=0; i<vSignalTS.size(); i++)
656  {
657  if (i>0) {sprintf (buffer, ","); fOutput << buffer;}
658  sprintf (buffer, "%u", vSignalTS.at(i));
659  fOutput << buffer;
660  }
661  sprintf (buffer, " ");
662  fOutput << buffer;
663  for (unsigned int i=0; i<vNoiseTS.size(); i++)
664  {
665  if (i>0) { sprintf (buffer, ","); fOutput << buffer;}
666  sprintf (buffer, "%u", vNoiseTS.at(i));
667  fOutput << buffer;
668  }
669  sprintf (buffer, " %10X\n", channel->rawId ());
670  fOutput << buffer;
671  }
672  }
673  return true;
674 }
675 
676 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalMCParams* fObject)
677 {
678  if (!fObject) return false; // fObject = new HcalMCParams();
679  char buffer [1024];
680  while (fInput.getline(buffer, 1024)) {
681  if (buffer [0] == '#') continue; //ignore comment
682  std::vector <std::string> items = splitString (std::string (buffer));
683  if (items.empty()) continue; // blank line
684  if (items.size () < 5) {
685  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 5 items: eta, phi, depth, subdet, signalShape" << std::endl;
686  continue;
687  }
688  DetId id = HcalDbASCIIIO::getId (items);
689 
690  int packingScheme=0;
691  if(items.size ()>11) {
692  packingScheme = atoi (items [11].c_str());
693  }
694 
695  int param1=0;
696  if(packingScheme==0) {
697  param1=atoi (items [4].c_str());
698  }
699 
700  if(packingScheme==1) {
701  int aabits[6]={ 9,1, 4, 8,5, 4}; // 4 spear bits added to aabits[5]
702  int aamax [6]={511,1,15,255,1,16};
703  int j=0;
704  int aa;
705  int aashift=0;
706  for(int i=0; i<6; i++) {
707  j=i+6;
708  if(i==3) {
709  float phase=atof (items [j].c_str());
710  float xphase=(phase+32.0)*4.0; // range of phase [-30.0,30.0]
711  aa=xphase;
712  } else {
713  aa=atoi (items [j].c_str());
714  }
715  if(aa>aamax[i] || aa<0) {
716  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value for a"<<i<<" should be less than"<<aamax[i]<< std::endl;
717  }
718 
719  param1=param1|aa<<aashift;
720  aashift=aashift+aabits[i];
721  }
722  }
723 
724  HcalMCParam* fCondObject = new HcalMCParam(id, param1 );
725  fObject->addValues(*fCondObject);
726  delete fCondObject;
727  }
728  return true;
729 }
730 
731 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalMCParams& fObject)
732 {
733  char buffer [1024];
734  // sprintf (buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
735  // fOutput << buffer;
736  std::vector<DetId> channels = fObject.getAllChannels ();
737  std::sort (channels.begin(), channels.end(), DetIdLess ());
738  int myCounter=0;
739  for (std::vector<DetId>::iterator channel = channels.begin ();
740  channel != channels.end ();
741  ++channel) {
742  myCounter++;;
743  int packingScheme=fObject.getValues (*channel)->packingScheme();
744  if(packingScheme==0) {
745  if(myCounter==1) {
746  sprintf (buffer, "# %15s %15s %15s %15s %14s %10s\n", "eta", "phi", "dep", "det", "signalShape", "DetId");
747  fOutput << buffer;
748  }
749  const int value = fObject.getValues (*channel)->signalShape();
750  HcalDbASCIIIO::dumpId (fOutput, *channel);
751  sprintf (buffer, " %10d %17X\n", value, channel->rawId ());
752  fOutput << buffer;
753  } // packingScheme 0
754  if(packingScheme==1) {
755  if(myCounter==1) {
756  char lineT[100],lineA[200];
757  //
758  sprintf (lineT, "#%40s"," "); fOutput << lineT;
759  sprintf (lineA, " %31s","a0: signalShape\n"); fOutput << lineA;
760  sprintf (lineT, "#%40s"," "); fOutput << lineT;
761  sprintf (lineA, " %31s","a1: syncPhase\n"); fOutput << lineA;
762  sprintf (lineT, "#%40s"," "); fOutput << lineT;
763  sprintf (lineA, " %31s","a2: binOfMaximum\n"); fOutput << lineA;
764  sprintf (lineT, "#%40s"," "); fOutput << lineT;
765  sprintf (lineA, " %31s","a3: timePhase\n"); fOutput << lineA;
766  sprintf (lineT, "#%40s"," "); fOutput << lineT;
767  sprintf (lineA, " %31s","a4: timeSmearing\n"); fOutput << lineA;
768  sprintf (lineT, "#%40s"," "); fOutput << lineT;
769  sprintf (lineA, " %31s","a5: packingScheme\n"); fOutput << lineA;
770  sprintf (lineT, "# %5s %4s %4s %10s %11s %10s", "eta", "phi", "dep", "det", "param1", "DetId");
771  fOutput << lineT;
772  sprintf (lineA, " %6s %4s %4s %6s %4s %4s\n", "a0", "a1", "a2", "a3", "a4", "a5");
773  fOutput << lineA;
774  }
775  int param1 = fObject.getValues (*channel)->param1();
776  HcalDbASCIIIO::dumpIdShort (fOutput, *channel);
777  sprintf (buffer, " %11d %10X", param1, channel->rawId ());
778  fOutput << buffer;
779  int aa0 = fObject.getValues (*channel)->signalShape();
780  bool aa1 = fObject.getValues (*channel)->syncPhase();
781  int aa2 = fObject.getValues (*channel)->binOfMaximum();
782  float aa3 = fObject.getValues (*channel)->timePhase();
783  bool aa4 = fObject.getValues (*channel)->timeSmearing() ;
784  int aa5 = fObject.getValues (*channel)->packingScheme();
785  sprintf (buffer, "%6d %4d %4d %6.1f %4d %4d\n",aa0,aa1,aa2,aa3,aa4,aa5);
786  fOutput << buffer;
787  }
788  }
789  return true;
790 }
791 
792 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestals* fObject) {
793  char buffer [1024];
794 
795  while (fInput.getline(buffer, 1024)) {
796  std::vector <std::string> items = splitString (std::string (buffer));
797  if (items.empty()) continue; // blank line
798  else {
799  if (items[0] == "#U")
800  {
801  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
802  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
803  else
804  {
805  edm::LogWarning("Pedestal Unit Error") << "Unrecognized unit for pedestals. Assuming fC." << std::endl;
806  fObject->setUnitADC(false);
807  }
808  break;
809  }
810  else
811  {
812  edm::LogWarning("Pedestal Unit Missing") << "The unit for the pedestals is missing in the txt file." << std::endl;
813  return false;
814  }
815  }
816  }
817  while (fInput.getline(buffer, 1024)) {
818  if (buffer [0] == '#') continue;
819  std::vector <std::string> items = splitString (std::string (buffer));
820  if (items.empty()) continue; // blank line
821  if (items.size () < 8) {
822  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values"
823  << " or 12 items: eta, phi, depth, subdet, 4x values for mean, 4x values for width"
824  << std::endl;
825  continue;
826  }
827  DetId id = getId (items);
828 
829 // if (fObject->exists(id) )
830 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
831 // else
832 // {
833 
834  if (items.size() < 12) // old format without widths
835  {
836  HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
837  atof (items [6].c_str()), atof (items [7].c_str()),
838  0., 0., 0., 0. );
839  fObject->addValues(*fCondObject);
840  delete fCondObject;
841  }
842  else // new format with widths
843  {
844  HcalPedestal* fCondObject = new HcalPedestal(id, atof (items [4].c_str()), atof (items [5].c_str()),
845  atof (items [6].c_str()), atof (items [7].c_str()),
846  atof (items [8].c_str()), atof (items [9].c_str()),
847  atof (items [10].c_str()), atof (items [11].c_str()) );
848  fObject->addValues(*fCondObject);
849  delete fCondObject;
850  }
851 
852  // }
853  }
854  return true;
855 }
856 
857 
858 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestals& fObject) {
859  char buffer [1024];
860  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
861  else sprintf (buffer, "#U fC << this is the unit \n");
862  fOutput << buffer;
863 
864  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");
865  fOutput << buffer;
866 
867  std::vector<DetId> channels = fObject.getAllChannels ();
868  std::sort (channels.begin(), channels.end(), DetIdLess ());
869  for (std::vector<DetId>::iterator channel = channels.begin ();
870  channel != channels.end ();
871  ++channel) {
872  const float* values = fObject.getValues (*channel)->getValues ();
873  if (values) {
874  dumpId (fOutput, *channel);
875  sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %8.5f %10X\n",
876  values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7], channel->rawId ());
877  fOutput << buffer;
878  }
879  }
880  return true;
881 }
882 
883 
884 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
885 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalChannelQuality* fObject)
886 {
887  if (!fObject) return false; //fObject = new HcalChannelQuality;
888  char buffer [1024];
889  while (fInput.getline(buffer, 1024)) {
890  if (buffer [0] == '#') continue; //ignore comment
891  std::vector <std::string> items = splitString (std::string (buffer));
892  if (items.empty()) continue; // blank line
893  if (items.size () < 6) {
894  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;
895  continue;
896  }
897  DetId id = getId (items);
898 
899 // if (fObject->exists(id) )
900 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
901 // else
902 // {
903  uint32_t mystatus;
904  if (items[4] == "(hex)")
905  sscanf(items[5].c_str(),"%X", &mystatus);
906  else if (items[4] == "(dec)")
907  sscanf(items[5].c_str(),"%u", &mystatus);
908  else
909  {
910  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n value field must contain the base: one of (hex), (dec)" << std::endl;
911  continue;
912  }
913 
914  HcalChannelStatus* fCondObject = new HcalChannelStatus(id, mystatus); //atoi (items [4].c_str()) );
915  fObject->addValues(*fCondObject);
916  delete fCondObject;
917  // }
918  }
919  return true;
920 }
921 
922 
923 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalChannelQuality& fObject) {
924  char buffer [1024];
925  sprintf (buffer, "# %15s %15s %15s %15s %15s %10s\n", "eta", "phi", "dep", "det", "(base) value", "DetId");
926  fOutput << buffer;
927  std::vector<DetId> channels = fObject.getAllChannels ();
928  std::sort (channels.begin(), channels.end(), DetIdLess ());
929  for (std::vector<DetId>::iterator channel = channels.begin ();
930  channel != channels.end ();
931  ++channel) {
932  const int value = fObject.getValues (*channel)->getValue ();
933  dumpId (fOutput, *channel);
934  sprintf (buffer, "%6s %15X %10X\n", "(hex)",
935  value, channel->rawId ());
936  fOutput << buffer;
937  }
938  return true;
939 }
940 
941 
942 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
943 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalL1TriggerObjects* fObject)
944 {
945  char buffer [1024];
946 
947  while (fInput.getline(buffer, 1024)) {
948  if (buffer [0] == '#')
949  {
950  if (buffer [1] == 'T') // contains tag name
951  {
952  std::vector <std::string> items = splitString (std::string (buffer) );
953  fObject->setTagString(items[1]);
954  continue;
955  }
956  if (buffer [1] == 'A') // contains algo name
957  {
958  std::vector <std::string> items = splitString (std::string (buffer) );
959  fObject->setAlgoString(items[1]);
960  continue;
961  }
962  else continue; //ignore comment
963  }
964  std::vector <std::string> items = splitString (std::string (buffer));
965  if (items.empty()) continue; // blank line
966  if (items.size () < 7) {
967  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, pedestal, resp.corr.gain, flag" << std::endl;
968  continue;
969  }
970  DetId id = getId (items);
971 
972  HcalL1TriggerObject* fCondObject = new HcalL1TriggerObject(id, atof(items[4].c_str()), atof(items[5].c_str()), atoi(items[6].c_str()) );
973 
974  fObject->addValues(*fCondObject);
975  delete fCondObject;
976  }
977  return true;
978 }
979 
980 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalL1TriggerObjects& fObject)
981 {
982  char buffer [1024];
983  //first print tag and algo
984  sprintf (buffer, "#T %s << this is the tag name \n", fObject.getTagString().c_str() );
985  fOutput << buffer;
986  sprintf (buffer, "#A %s << this is the algorithm name \n", fObject.getAlgoString().c_str() );
987  fOutput << buffer;
988 
989  //then the values
990  sprintf (buffer, "# %15s %15s %15s %15s %8s %13s %8s %10s\n",
991  "eta", "phi", "dep", "det", "ped", "respcorrgain", "flag",
992  "DetId");
993  fOutput << buffer;
994  std::vector<DetId> channels = fObject.getAllChannels ();
995  // std::sort (channels.begin(), channels.end(), DetIdLess ());
996  for (std::vector<DetId>::iterator channel = channels.begin ();
997  channel != channels.end ();
998  ++channel) {
999  const HcalL1TriggerObject* item = fObject.getValues (*channel);
1000  if (item) {
1001  dumpId (fOutput, *channel);
1002  sprintf (buffer, " %12.7f %13.10f %12d %10X\n",
1003  item->getPedestal(), item->getRespGain(), item->getFlag(), channel->rawId ());
1004  fOutput << buffer;
1005  }
1006  }
1007  return true;
1008 
1009 }
1010 
1011 
1012 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1013 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalPedestalWidths* fObject) {
1014  char buffer [1024];
1015  int linecounter = 0;
1016 
1017  while (fInput.getline(buffer, 1024)) {
1018  linecounter++;
1019  std::vector <std::string> items = splitString (std::string (buffer));
1020  if (items.empty()) continue; // blank line
1021  else {
1022  if (items[0] == (std::string)"#U")
1023  {
1024  if (items[1] == (std::string)"ADC") fObject->setUnitADC(true);
1025  else if (items[1] == (std::string)"fC") fObject->setUnitADC(false);
1026  else
1027  {
1028  edm::LogWarning("Pedestal Width Unit Error") << "Unrecognized unit for pedestal widths. Assuming fC." << std::endl;
1029  fObject->setUnitADC(false);
1030  }
1031  break;
1032  }
1033  else
1034  {
1035  edm::LogWarning("Pedestal Width Unit Missing") << "The unit for the pedestal widths is missing in the txt file." << std::endl;
1036  return false;
1037  }
1038  }
1039  }
1040 
1041  while (fInput.getline(buffer, 1024)) {
1042  linecounter++;
1043  if (buffer [0] == '#') continue; //ignore comment
1044  std::vector <std::string> items = splitString (std::string (buffer));
1045  if (items.empty()) continue; // blank line
1046  if (items.size () < 14) {
1047  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line number: " << linecounter << "\n line must contain 14 items: eta, phi, depth, subdet, 10x correlations"
1048  << " or 20 items: eta, phi, depth, subdet, 16x correlations"
1049  << std::endl;
1050  continue;
1051  }
1052  DetId id = getId (items);
1053 
1054 // if (fObject->exists(id) )
1055 // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1056 // else
1057 // {
1058 
1059  if (items.size() < 20) //old format
1060  {
1062  values.setSigma (0, 0, atof (items [4].c_str()));
1063  values.setSigma (1, 0, atof (items [5].c_str()));
1064  values.setSigma (1, 1, atof (items [6].c_str()));
1065  values.setSigma (2, 0, atof (items [7].c_str()));
1066  values.setSigma (2, 1, atof (items [8].c_str()));
1067  values.setSigma (2, 2, atof (items [9].c_str()));
1068  values.setSigma (3, 0, atof (items [10].c_str()));
1069  values.setSigma (3, 1, atof (items [11].c_str()));
1070  values.setSigma (3, 2, atof (items [12].c_str()));
1071  values.setSigma (3, 3, atof (items [13].c_str()));
1072  values.setSigma (0, 1, 0.);
1073  values.setSigma (0, 2, 0.);
1074  values.setSigma (0, 3, 0.);
1075  values.setSigma (1, 2, 0.);
1076  values.setSigma (1, 3, 0.);
1077  values.setSigma (2, 3, 0.);
1078  fObject->addValues(values);
1079  }
1080  else // new format
1081  {
1083  values.setSigma (0, 0, atof (items [4].c_str()) );
1084  values.setSigma (0, 1, atof (items [5].c_str()) );
1085  values.setSigma (0, 2, atof (items [6].c_str()) );
1086  values.setSigma (0, 3, atof (items [7].c_str()) );
1087  values.setSigma (1, 0, atof (items [8].c_str()) );
1088  values.setSigma (1, 1, atof (items [9].c_str()) );
1089  values.setSigma (1, 2, atof (items [10].c_str()) );
1090  values.setSigma (1, 3, atof (items [11].c_str()) );
1091  values.setSigma (2, 0, atof (items [12].c_str()) );
1092  values.setSigma (2, 1, atof (items [13].c_str()) );
1093  values.setSigma (2, 2, atof (items [14].c_str()) );
1094  values.setSigma (2, 3, atof (items [15].c_str()) );
1095  values.setSigma (3, 0, atof (items [16].c_str()) );
1096  values.setSigma (3, 1, atof (items [17].c_str()) );
1097  values.setSigma (3, 2, atof (items [18].c_str()) );
1098  values.setSigma (3, 3, atof (items [19].c_str()) );
1099  fObject->addValues(values);
1100  }
1101 
1102  // }
1103  }
1104  return true;
1105 }
1106 
1107 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalPedestalWidths& fObject) {
1108  char buffer [1024];
1109  if (fObject.isADC() ) sprintf (buffer, "#U ADC << this is the unit \n");
1110  else sprintf (buffer, "#U fC << this is the unit \n");
1111  fOutput << buffer;
1112 
1113  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s %10s\n",
1114  "eta", "phi", "dep", "det",
1115  "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",
1116  "DetId");
1117  fOutput << buffer;
1118  std::vector<DetId> channels = fObject.getAllChannels ();
1119  std::sort (channels.begin(), channels.end(), DetIdLess ());
1120  for (std::vector<DetId>::iterator channel = channels.begin ();
1121  channel != channels.end ();
1122  ++channel) {
1123  const HcalPedestalWidth* item = fObject.getValues (*channel);
1124  if (item) {
1125  dumpId (fOutput, *channel);
1126  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",
1127  item->getSigma (0,0), item->getSigma (0,1), item->getSigma (0,2), item->getSigma (0,3),
1128  item->getSigma (1,0), item->getSigma (1,1), item->getSigma (1,2), item->getSigma (1,3),
1129  item->getSigma (2,0), item->getSigma (2,1), item->getSigma (2,2), item->getSigma (2,3),
1130  item->getSigma (3,0), item->getSigma (3,1), item->getSigma (3,2), item->getSigma (3,3), channel->rawId ());
1131  fOutput << buffer;
1132  }
1133  }
1134  return true;
1135 }
1136 
1137 
1138 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1139 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalQIEData* fObject) {
1140  char buffer [1024];
1141  while (fInput.getline(buffer, 1024)) {
1142  if (buffer [0] == '#') continue; //ignore comment
1143  std::vector <std::string> items = splitString (std::string (buffer));
1144  if (items.empty()) continue;
1145  if (items [0] == "SHAPE") { // basic shape
1146  //this shape keyword is obsolete
1147  }
1148  else { // QIE parameters
1149  if (items.size () < 36) {
1150  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;
1151  continue;
1152  }
1153  DetId id = getId (items);
1154  fObject->sort ();
1155  // try {
1156  // fObject->getCoder (id);
1157  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1158  // }
1159 // catch (cms::Exception& e) {
1160  HcalQIECoder coder (id.rawId ());
1161  int index = 4;
1162  for (unsigned capid = 0; capid < 4; capid++) {
1163  for (unsigned range = 0; range < 4; range++) {
1164  coder.setOffset (capid, range, atof (items [index++].c_str ()));
1165  }
1166  }
1167  for (unsigned capid = 0; capid < 4; capid++) {
1168  for (unsigned range = 0; range < 4; range++) {
1169  coder.setSlope (capid, range, atof (items [index++].c_str ()));
1170  }
1171  }
1172 
1173  fObject->addCoder (coder);
1174 // }
1175  }
1176  }
1177  fObject->sort ();
1178  return true;
1179 }
1180 
1181 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalQIEData& fObject) {
1182 
1183  char buffer [1024];
1184 
1185  fOutput << "# QIE data" << std::endl;
1186  sprintf (buffer, "# %15s %15s %15s %15s %36s %36s %36s %36s %36s %36s %36s %36s\n",
1187  "eta", "phi", "dep", "det",
1188  "4 x offsets cap0", "4 x offsets cap1", "4 x offsets cap2", "4 x offsets cap3",
1189  "4 x slopes cap0", "4 x slopes cap1", "4 x slopes cap2", "4 x slopes cap3");
1190  fOutput << buffer;
1191  std::vector<DetId> channels = fObject.getAllChannels ();
1192  std::sort (channels.begin(), channels.end(), DetIdLess ());
1193  for (std::vector<DetId>::iterator channel = channels.begin ();
1194  channel != channels.end ();
1195  ++channel) {
1196  const HcalQIECoder* coder = fObject.getCoder (*channel);
1197  dumpId (fOutput, *channel);
1198  for (unsigned capid = 0; capid < 4; capid++) {
1199  for (unsigned range = 0; range < 4; range++) {
1200  sprintf (buffer, " %8.5f", coder->offset (capid, range));
1201  fOutput << buffer;
1202  }
1203  }
1204  for (unsigned capid = 0; capid < 4; capid++) {
1205  for (unsigned range = 0; range < 4; range++) {
1206  sprintf (buffer, " %8.5f", coder->slope (capid, range));
1207  fOutput << buffer;
1208  }
1209  }
1210  fOutput << std::endl;
1211  }
1212  return true;
1213 }
1214 
1215 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1216 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalCalibrationQIEData* fObject) {
1217  char buffer [1024];
1218  while (fInput.getline(buffer, 1024)) {
1219  if (buffer [0] == '#') continue; //ignore comment
1220  std::vector <std::string> items = splitString (std::string (buffer));
1221  if (items.size () < 36) {
1222  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 36 items: eta, phi, depth, subdet, 32 bin values" << std::endl;
1223  continue;
1224  }
1225  DetId id = getId (items);
1226  fObject->sort ();
1227  // try {
1228  // fObject->getCoder (id);
1229  // edm::LogWarning("Redefining Channel") << "line: " << buffer << "\n attempts to redefine data. Ignored" << std::endl;
1230  // }
1231 // catch (cms::Exception& e) {
1232  HcalCalibrationQIECoder coder (id.rawId ());
1233  int index = 4;
1234  float values [32];
1235  for (unsigned bin = 0; bin < 32; bin++) {
1236  values[bin] = atof (items [index++].c_str ());
1237  }
1238  coder.setMinCharges (values);
1239  fObject->addCoder (coder);
1240 // }
1241  }
1242  fObject->sort ();
1243  return true;
1244 }
1245 
1246 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationQIEData& fObject) {
1247  char buffer [1024];
1248  fOutput << "# QIE data in calibration mode" << std::endl;
1249  sprintf (buffer, "# %15s %15s %15s %15s %288s\n",
1250  "eta", "phi", "dep", "det", "32 x charges");
1251  fOutput << buffer;
1252  std::vector<DetId> channels = fObject.getAllChannels ();
1253  std::sort (channels.begin(), channels.end(), DetIdLess ());
1254  for (std::vector<DetId>::iterator channel = channels.begin ();
1255  channel != channels.end ();
1256  ++channel) {
1257  const HcalCalibrationQIECoder* coder = fObject.getCoder (*channel);
1258  if (coder) {
1259  dumpId (fOutput, *channel);
1260  const float* lowEdge = coder->minCharges ();
1261  for (unsigned bin = 0; bin < 32; bin++) {
1262  sprintf (buffer, " %8.5f", lowEdge [bin]);
1263  fOutput << buffer;
1264  }
1265  fOutput << std::endl;
1266  }
1267  }
1268  return true;
1269 }
1270 
1271 
1272 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1273 namespace HcalDbASCIIIO {
1274 template<> std::unique_ptr<HcalElectronicsMap> createObject<HcalElectronicsMap>(std::istream& fInput) {
1275  HcalElectronicsMapAddons::Helper fObjectHelper;
1276  char buffer [1024];
1277  while (fInput.getline(buffer, 1024)) {
1278  if (buffer [0] == '#') continue; //ignore comment
1279  std::vector <std::string> items = splitString (std::string (buffer));
1280  if (items.size () < 12) {
1281  if (items.empty()) continue; // no warning here
1282  if (items.size()<9) {
1283  edm::LogError("MapFormat") << "HcalElectronicsMap-> line too short: " << buffer;
1284  continue;
1285  }
1286  if (items[8]=="NA" || items[8]=="NT") {
1287  while (items.size()<12) items.push_back(""); // don't worry here
1288  } else if (items[8]=="HT") {
1289  if (items.size()==11) items.push_back("");
1290  else {
1291  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
1292  << "\n HT line must contain at least 11 items: i cr sl tb dcc spigot fiber fiberchan subdet=HT ieta iphi";
1293  continue;
1294  }
1295  } else {
1296  edm::LogError("MapFormat") << "HcalElectronicsMap-> Bad line: " << buffer
1297  << "\n line must contain 12 items: i cr sl tb dcc spigot fiber fiberchan subdet ieta iphi depth";
1298  continue;
1299  }
1300  }
1301  int crate = atoi (items [1].c_str());
1302  int slot = atoi (items [2].c_str());
1303  int top = 1;
1304  if (items [3] == "b") top = 0;
1305  int dcc = atoi (items [4].c_str());
1306  int spigot = atoi (items [5].c_str());
1307  HcalElectronicsId elId;
1308  if (items[3][0] == 'u') { // uTCA!
1309  int fiber = atoi (items [6].c_str());
1310  int fiberCh = atoi (items [7].c_str());
1311  bool isTrig=(items[8] == "HT" || items[8] == "NT");
1312  elId=HcalElectronicsId(crate, slot, fiber, fiberCh,isTrig);
1313  } else if (items[8] == "HT" || items[8] == "NT") {
1314  int slb = atoi (items [6].c_str());
1315  int slbCh = atoi (items [7].c_str());
1316  elId=HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
1317  } else {
1318  int fiber = atoi (items [6].c_str());
1319  int fiberCh = atoi (items [7].c_str());
1320 
1321  elId=HcalElectronicsId(fiberCh, fiber, spigot, dcc);
1322  elId.setHTR (crate, slot, top);
1323  }
1324 
1325  // first, handle undefined cases
1326  if (items [8] == "NA") { // undefined channel
1327  fObjectHelper.mapEId2chId (elId, DetId (HcalDetId::Undefined));
1328  } else if (items [8] == "NT") { // undefined trigger channel
1329  fObjectHelper.mapEId2tId (elId, DetId (HcalTrigTowerDetId::Undefined));
1330  } else {
1331  HcalText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
1332  if (converter.isHcalDetId() or converter.isHcalCalibDetId() or converter.isHcalZDCDetId()) {
1333  fObjectHelper.mapEId2chId (elId, converter.getId ());
1334  }
1335  else if (converter.isHcalTrigTowerDetId ()) {
1336  fObjectHelper.mapEId2tId (elId, converter.getId ());
1337  }
1338  else {
1339  edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: "
1340  << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
1341  }
1342  }
1343  }
1344  auto fObject = std::make_unique<HcalElectronicsMap>(fObjectHelper);
1345  return fObject;
1346 }
1347 }
1348 
1349 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalElectronicsMap& fObject) {
1350  std::vector<HcalElectronicsId> eids = fObject.allElectronicsId ();
1351  char buf [1024];
1352  // changes by Jared, 6.03.09/(included 25.03.09)
1353  // sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
1354  sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
1355  "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
1356  fOutput << buf << std::endl;
1357 
1358  for (unsigned i = 0; i < eids.size (); i++) {
1359  HcalElectronicsId eid = eids[i];
1360  if (eid.isTriggerChainId()) {
1361  DetId trigger = fObject.lookupTrigger (eid);
1362  if (trigger.rawId ()) {
1364  if( eid.isVMEid() ){
1365  // changes by Jared, 6.03.09/(included 25.03.09)
1366  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1367  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1368  // i,
1369  converter.getId().rawId(),
1370  // changes by Jared, 6.03.09/(included 25.03.09)
1371  // eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1372  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
1373  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1374  );
1375  fOutput << buf << std::endl;
1376  }else if( eid.isUTCAid() ){
1377  sprintf (buf, " %7X %3d %3d u %4d %7d %10d %14d %7s %5s %5s %6s",
1378  converter.getId().rawId(),
1379 // eid.crateId(), eid.slot(), 0, eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1380  eid.crateId(), eid.slot(), 0, 0, eid.fiberIndex(), eid.fiberChanId(),
1381  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1382  );
1383  fOutput << buf << std::endl;
1384  }else{
1385  sprintf (buf, "NOT SUPPORTED!");
1386  fOutput << buf << std::endl;
1387  }
1388  }
1389  } else {
1390  DetId channel = fObject.lookup (eid);
1391  if (channel.rawId()) {
1393  if (eid.isVMEid()) {
1394  // changes by Jared, 6.03.09/(included 25.03.09)
1395  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1396  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1397  // i,
1398  converter.getId().rawId(),
1399  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1400  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1401  );
1402  } else {
1403  sprintf (buf, " %7X %3d %3d u %4d %7d %10d %14d %7s %5s %5s %6s",
1404  // i,
1405  converter.getId().rawId(),
1406 // eid.crateId(), eid.slot(), 0, eid.slot(), eid.fiberIndex(), eid.fiberChanId(),
1407  eid.crateId(), eid.slot(), 0, 0, eid.fiberIndex(), eid.fiberChanId(),
1408  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1409  );
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.empty()) 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;
1490  while (getline(fInput, buffer)) {
1491  if (buffer.at(0) == '#') continue; //ignore comment
1492  std::vector <std::string> items = splitString (buffer);
1493  if (items.empty()) 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 namespace HcalDbASCIIIO {
1610 template <> std::unique_ptr<HcalDcsMap> createObject<HcalDcsMap>(std::istream& fInput) {
1611  char buffer [1024];
1612  HcalDcsMapAddons::Helper fObjectHelper;
1613  while (fInput.getline(buffer, 1024)) {
1614  if (buffer [0] == '#') continue; //ignore comment
1615  std::vector <std::string> items = splitString (std::string (buffer));
1616  if (items.size () < 8) {
1617  if (items.empty()) continue; // no warning here
1618  else {
1619  edm::LogError("MapFormat") << "HcalDcsMap-> Bad line: " << buffer
1620  << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
1621  continue;
1622  }
1623  }
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());
1629  if (items[4].find("CALIB")!=std::string::npos){
1630  subdet = HcalCalibration;
1631  }
1632  else if (items[4].find("HB")!=std::string::npos){
1633  subdet = HcalDcsBarrel;
1634  }
1635  else if (items[4].find("HE")!=std::string::npos){
1636  subdet = HcalDcsEndcap;
1637  }
1638  else if (items[4].find("HO")!=std::string::npos){
1639  subdet = HcalDcsOuter;
1640  }
1641  else if (items[4].find("HF")!=std::string::npos){
1642  subdet = HcalDcsForward;
1643  }
1644  else{
1645  edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
1646  continue;
1647  }
1648  HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
1649  HcalText2DetIdConverter converter (items [4], items [5], items [6], items [7]);
1650  HcalDetId id(0);
1651  if (converter.isHcalDetId()){
1652  id = converter.getId();
1653  }
1654  else{
1655  edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: "
1656  << items [4] << '/'
1657  << items [5] << '/'
1658  << items [6] << '/'
1659  << items [7] << std::endl;
1660  continue;
1661  }
1662  fObjectHelper.mapGeomId2DcsId(id, dcsId);
1663  }
1664  auto fObject = std::make_unique<HcalDcsMap>(fObjectHelper);
1665  return fObject;
1666 }
1667 }
1668 
1669 // Format of the ASCII file:
1670 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1671 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1672 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalDcsMap& fObject) {
1673  char buf [1024];
1674  sprintf (buf, "# %7s %10s %6s %8s %7s %5s %5s %6s",
1675  "i", "side_ring", "slice", "subchan", "subdet", "ieta", "iphi", "depth");
1676  fOutput << buf << std::endl;
1678  unsigned int line_counter = 0;
1679  for (_line = fObject.beginById();
1680  _line != fObject.endById();
1681  ++_line) {
1682  HcalDcsDetId dcsId = _line.getHcalDcsDetId();
1683  //std::string _dcs_type = "DCSUNKNOWN";
1684  HcalText2DetIdConverter _converter(_line.getHcalDetId());
1685  sprintf (buf, " %8X %10d %6d %8d %7s %5s %5s %6s",
1686  line_counter,
1687  dcsId.ring(), // contains zside() already
1688  dcsId.slice(),
1689  dcsId.subchannel(),
1690  _converter.getFlavor().c_str(),
1691  _converter.getField1().c_str(),
1692  _converter.getField2().c_str(),
1693  _converter.getField3().c_str()
1694  );
1695  fOutput << buf << std::endl;
1696  ++line_counter;
1697  }
1698  return true;
1699 }
1700 
1701 
1702 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalFlagHFDigiTimeParams* fObject)
1703 {
1704 
1705  if (!fObject) return false; //fObject = new HcalFlagHFDigiTimeParams();
1706  char buffer [1024];
1707  while (fInput.getline(buffer, 1024)) {
1708  if (buffer [0] == '#') continue; //ignore comment
1709  std::vector <std::string> items = splitString (std::string (buffer));
1710  if (items.empty()) continue; // blank line
1711  if (items.size () != 9) {
1712  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;
1713  continue;
1714  }
1715  // expects (ieta, iphi, depth, subdet) as first four arguments
1716  DetId id = HcalDbASCIIIO::getId (items);
1717  std::vector<double> coef= splitStringToDoubleByComma(items[8]);
1718 
1719  HcalFlagHFDigiTimeParam* fCondObject = new HcalFlagHFDigiTimeParam(id,
1720  atoi (items [4].c_str()), //firstSample
1721  atoi (items [5].c_str()), //samplesToAdd
1722  atoi (items [6].c_str()), //expectedPeak
1723  atof (items [7].c_str()), // minEThreshold
1724  coef // coefficients
1725  );
1726  fObject->addValues(*fCondObject);
1727  delete fCondObject;
1728  }
1729  return true;
1730 } // getObject (HcalFlagHFDigiTime)
1731 
1732 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalFlagHFDigiTimeParams& fObject)
1733 {
1734  char buffer [1024];
1735  sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s %30s\n", "eta", "phi", "dep", "det", "FirstSample", "SamplesToAdd", "ExpectedPeak","MinEnergy","Coefficients");
1736  fOutput << buffer;
1737  std::vector<DetId> channels = fObject.getAllChannels ();
1738  std::sort (channels.begin(), channels.end(), DetIdLess ());
1739  for (std::vector<DetId>::iterator channel = channels.begin ();
1740  channel != channels.end ();
1741  ++channel) {
1742  // Dump out channel (ieta,iphi,depth,subdet) info
1743  HcalDbASCIIIO::dumpId (fOutput, *channel);
1744  // Dump out values for channel
1745  sprintf (buffer, " %15u %15u %15u %15f",
1746  fObject.getValues (*channel)->HFdigiflagFirstSample(),
1747  fObject.getValues (*channel)->HFdigiflagSamplesToAdd(),
1748  fObject.getValues (*channel)->HFdigiflagExpectedPeak(),
1749  fObject.getValues (*channel)->HFdigiflagMinEThreshold()
1750  );
1751 
1752  fOutput<<buffer; // dump flag reco values to buffer
1753  fOutput<<" "; // simple spacer
1754 
1755  std::vector<double> coef=fObject.getValues(*channel)->HFdigiflagCoefficients();
1756  for (std::vector<double>::size_type x=0;x<coef.size();++x)
1757  {
1758  // dump comma-separated list of coefficients
1759  fOutput<<coef[x];
1760  if (x<coef.size()-1) // add commas where necessary
1761  fOutput<<",";
1762  }
1763  sprintf(buffer,"\n");
1764  fOutput << buffer;
1765  }
1766  return true;
1767 }
1768 
1769 
1770 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1771 namespace HcalDbASCIIIO {
1772 template<> std::unique_ptr<HcalFrontEndMap> createObject<HcalFrontEndMap>(std::istream& fInput) {
1773  char buffer [1024];
1774  HcalFrontEndMapAddons::Helper fObjectHelper;
1775  unsigned int all(0), good(0);
1776  while (fInput.getline(buffer, 1024)) {
1777  ++all;
1778  if (buffer [0] == '#') continue; //ignore comment
1779  std::vector <std::string> items = splitString (std::string (buffer));
1780  if (items.size () != 6) {
1781  edm::LogError("Format Error") << "HcalFrontEndMap-> line ignored: " << buffer;
1782  continue;
1783  }
1784  ++good;
1785  DetId id = HcalDbASCIIIO::getId (items);
1786  int rm = atoi (items [5].c_str());
1787  fObjectHelper.loadObject (id, rm, items[4]);
1788  }
1789  edm::LogInfo("MapFormat") << "HcalFrontEndMap:: processed " << good << " records in " << all << " record" << std::endl;
1790  auto fObject = std::make_unique<HcalFrontEndMap>(fObjectHelper);
1791  return fObject;
1792 }
1793 }
1794 
1795 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalFrontEndMap& fObject) {
1796 
1797  char buffer [1024];
1798  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s\n", "eta", "phi", "dep", "det", "rbx", "rm");
1799  fOutput << buffer;
1800 
1801  std::vector<DetId> channels = fObject.allDetIds();
1802  std::sort (channels.begin(), channels.end(), DetIdLess ());
1803  for (std::vector<DetId>::iterator channel = channels.begin ();
1804  channel != channels.end (); ++channel) {
1805  const std::string rbx = fObject.lookupRBX(*channel);
1806  const int rm = fObject.lookupRM(*channel);
1807  dumpId (fOutput, *channel);
1808  sprintf (buffer, " %8s %8d \n", rbx.c_str(), rm);
1809  fOutput << buffer;
1810  }
1811  return true;
1812 }
1813 
1814 
1815 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1816 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalSiPMParameters* fObject) {
1817  if (!fObject) return false;
1818  char buffer [1024];
1819  while (fInput.getline(buffer, 1024)) {
1820  if (buffer [0] == '#') continue; //ignore comment
1821  std::vector <std::string> items = splitString (std::string (buffer));
1822  if (items.empty()) continue; // blank line
1823  if (items.size () < 9) {
1824  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 9 items: eta, phi, depth, subdet, 5x values" << std::endl;
1825  continue;
1826  }
1827  DetId id = HcalDbASCIIIO::getId (items);
1828 
1829  HcalSiPMParameter* obj = new HcalSiPMParameter(id, atoi(items[4].c_str()),
1830  atof(items[5].c_str()),
1831  atof(items[6].c_str()),
1832  atoi(items[7].c_str()),
1833  atof(items[8].c_str()));
1834  fObject->addValues(*obj);
1835  delete obj;
1836  }
1837  return true;
1838 }
1839 
1840 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalSiPMParameters& fObject) {
1841 
1842  char buffer [1024];
1843  sprintf (buffer, "# %15s %15s %15s %15s %8s %15s %15s %8s %15s\n",
1844  "eta", "phi", "dep", "det", "type", "fcByPE", "darkCurrent",
1845  "auxi1", "auxi2");
1846  fOutput << buffer;
1847  std::vector<DetId> channels = fObject.getAllChannels ();
1848  std::sort (channels.begin(), channels.end(), DetIdLess ());
1849  for (std::vector<DetId>::iterator channel = channels.begin ();
1850  channel != channels.end ();
1851  ++channel) {
1852  const int type = fObject.getValues(*channel)->getType();
1853  const float fcByPE = fObject.getValues(*channel)->getFCByPE();
1854  const float darkC = fObject.getValues(*channel)->getDarkCurrent();
1855  const int auxi1 = fObject.getValues(*channel)->getauxi1();
1856  const float auxi2 = fObject.getValues(*channel)->getauxi2();
1857  HcalDbASCIIIO::dumpId (fOutput, *channel);
1858  sprintf (buffer, " %8d %15.6f %15.6f %8d %15.6f\n", type, fcByPE,
1859  darkC, auxi1, auxi2);
1860  fOutput << buffer;
1861  }
1862  return true;
1863 }
1864 
1865 
1866 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1867 namespace HcalDbASCIIIO {
1868 template<> std::unique_ptr<HcalSiPMCharacteristics> createObject<HcalSiPMCharacteristics>(std::istream& fInput) {
1869  char buffer [1024];
1871  unsigned int all(0), good(0);
1872  while (fInput.getline(buffer, 1024)) {
1873  ++all;
1874  if (buffer [0] == '#') continue; //ignore comment
1875  std::vector <std::string> items = splitString (std::string (buffer));
1876  if (items.size () != 8) {
1877  edm::LogError("MapFormat") << "HcalSiPMCharacteristics-> line ignored: " << buffer;
1878  continue;
1879  }
1880  ++good;
1881  // std::cout << "HcalSiPMCharacteristics-> processing line: " << buffer << std::endl;
1882  int type = atoi (items [0].c_str());
1883  int pixels = atoi (items [1].c_str());
1884  float parL0 = atof (items [2].c_str());
1885  float parL1 = atof (items [3].c_str());
1886  float parL2 = atof (items [4].c_str());
1887  float cTalk = atof (items [5].c_str());
1888  int auxi1 = atoi (items [6].c_str());
1889  float auxi2 = atof (items [7].c_str());
1890  fObjectHelper.loadObject (type, pixels, parL0, parL1, parL2, cTalk, auxi1, auxi2);
1891  }
1892  edm::LogInfo("MapFormat") << "HcalSiPMCharacteristics:: processed " << good << " records in " << all << " record" << std::endl;
1893  auto fObject = std::make_unique<HcalSiPMCharacteristics>(fObjectHelper);
1894  return fObject;
1895 }
1896 }
1897 
1898 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalSiPMCharacteristics& fObject) {
1899 
1900  char buffer [1024];
1901  sprintf (buffer, "# %8s %8s %15s %15s %15s %15s %8s %15s\n", "type",
1902  "pixels", "parLin1", "parLin2", "parLin3", "crossTalk", "auxi1",
1903  "auxi2");
1904  fOutput << buffer;
1905 
1906  unsigned int size = fObject.getTypes();
1907  for (unsigned int k=0; k<size; ++k) {
1908  const int type = fObject.getType(k);
1909  const int pixels = fObject.getPixels(type);
1910  const std::vector<float> pars = fObject.getNonLinearities(type);
1911  const float cTalk = fObject.getCrossTalk(type);
1912  const int auxi1 = fObject.getAuxi1(type);
1913  const float auxi2 = fObject.getAuxi2(type);
1914  const float par0 = (!pars.empty()) ? pars[0] : 0;
1915  const float par1 = (pars.size() > 1) ? pars[1] : 0;
1916  const float par2 = (pars.size() > 2) ? pars[2] : 0;
1917  sprintf (buffer, " %8d %8d %15.6e %15.6e %15.6e %15.6f %8d %15.6f\n",
1918  type, pixels, par0, par1, par2, cTalk, auxi1, auxi2);
1919  fOutput << buffer;
1920  }
1921  return true;
1922 }
1923 
1924 
1925 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1926 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTPChannelParameters* fObject) {
1927  if (!fObject) return false;
1928  char buffer [1024];
1929  while (fInput.getline(buffer, 1024)) {
1930  if (buffer [0] == '#') continue; //ignore comment
1931  std::vector <std::string> items = splitString (std::string (buffer));
1932  if (items.empty()) continue; // blank line
1933  if (items.size () < 8) {
1934  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 8 items: eta, phi, depth, subdet, 4x values" << std::endl;
1935  continue;
1936  }
1937  DetId id = HcalDbASCIIIO::getId (items);
1938 
1940  atoi(items[4].c_str()),
1941  atoi(items[5].c_str()),
1942  atoi(items[6].c_str()),
1943  atoi(items[7].c_str()));
1944  fObject->addValues(*obj);
1945  delete obj;
1946  }
1947  return true;
1948 }
1949 
1950 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTPChannelParameters& fObject) {
1951 
1952  char buffer [1024];
1953  sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s\n",
1954  "eta", "phi", "dep", "det", "Mask", "FGBitInfo", "auxi1", "auxi2");
1955  fOutput << buffer;
1956  std::vector<DetId> channels = fObject.getAllChannels ();
1957  std::sort (channels.begin(), channels.end(), DetIdLess ());
1958  for (std::vector<DetId>::iterator channel = channels.begin ();
1959  channel != channels.end ();
1960  ++channel) {
1961  const uint32_t mask = fObject.getValues(*channel)->getMask();
1962  const uint32_t fgBitInfo = fObject.getValues(*channel)->getFGBitInfo();
1963  const int auxi1 = fObject.getValues(*channel)->getauxi1();
1964  const int auxi2 = fObject.getValues(*channel)->getauxi2();
1965  HcalDbASCIIIO::dumpId (fOutput, *channel);
1966  sprintf (buffer, " %15d %15d %15d %15d \n", mask, fgBitInfo, auxi1, auxi2);
1967  fOutput << buffer;
1968  }
1969  return true;
1970 }
1971 
1972 
1973 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1974 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalTPParameters* fObject) {
1975  char buffer [1024];
1976  unsigned int all(0), good(0);
1977  while (fInput.getline(buffer, 1024)) {
1978  ++all;
1979  if (buffer [0] == '#') continue; //ignore comment
1980  std::vector <std::string> items = splitString (std::string (buffer));
1981  if (items.size () != 6) {
1982  edm::LogError("Format Error") << "HcalTPParameters-> line ignored: " << buffer;
1983  continue;
1984  }
1985  ++good;
1986  // std::cout << "HcalTPParameters-> processing line: " << buffer << std::endl;
1987  int version = atoi (items [0].c_str());
1988  int adcCut = atoi (items [1].c_str());
1989  uint64_t tdcMask = strtoull(items [2].c_str(),nullptr,16);
1990  uint32_t tbits = atoi (items [3].c_str());
1991  int auxi1 = atoi (items [4].c_str());
1992  int auxi2 = atoi (items [5].c_str());
1993  fObject->loadObject (version, adcCut, tdcMask, tbits, auxi1, auxi2);
1994  break;
1995  }
1996  edm::LogInfo("MapFormat") << "HcalTPParameters:: processed " << good << " records in " << all << " record" << std::endl;
1997  return true;
1998 }
1999 
2000 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalTPParameters& fObject) {
2001 
2002  char buffer [1024];
2003  sprintf (buffer, "# %15s %15s %16s %15s %15s %15s\n", "FGAlgo_HBHE",
2004  "ADCThrHF", "TDCMaskHF", "STBitsHF", "auxi1", "auxi2");
2005  fOutput << buffer;
2006 
2007  const int version = fObject.getFGVersionHBHE();
2008  const int adcCut = fObject.getADCThresholdHF();
2009  const uint64_t tdcMask = fObject.getTDCMaskHF();
2010  const uint32_t tbits = fObject.getHFTriggerInfo();
2011  const int auxi1 = fObject.getAuxi1();
2012  const int auxi2 = fObject.getAuxi2();
2013 
2014  sprintf (buffer, " %15d %15d %16jx %15x %15d %15d\n", version, adcCut, tdcMask, tbits, auxi1, auxi2);
2015  fOutput << buffer;
2016 
2017  return true;
2018 }
2019 
2020 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2021 
2022 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationsSet& fObject) {
2023  char buffer [1024];
2024  sprintf (buffer, "# %15s %15s %15s %15s %8s %8s %8s %8s %11s %11s %11s %11s %9s %9s %9s %9s %10s\n",
2025  "eta", "phi", "dep", "det",
2026  "pedcap0", "pedcap1", "pedcap2", "pedcap3",
2027  "effpedcap0", "effpedcap1", "effpedcap2", "effpedcap3",
2028  "gaincap0", "gaincap1", "gaincap2", "gaincap3", "DetId");
2029  fOutput << buffer;
2030 
2031  std::vector<DetId> channels = fObject.getAllChannels ();
2032  std::sort (channels.begin(), channels.end(), DetIdLess ());
2033  for (std::vector<DetId>::iterator channel = channels.begin (); channel != channels.end (); ++channel) {
2034  dumpId (fOutput, *channel);
2035  const HcalCalibrations& values = fObject.getCalibrations(*channel);
2036  sprintf (buffer, " %8.5f %8.5f %8.5f %8.5f %11.5f %11.5f %11.5f %11.5f %9.5f %9.5f %9.5f %9.5f %10X\n",
2037  values.pedestal(0), values.pedestal(1), values.pedestal(2), values.pedestal(3),
2038  values.effpedestal(0), values.effpedestal(1), values.effpedestal(2), values.effpedestal(3),
2039  values.respcorrgain(0), values.respcorrgain(1), values.respcorrgain(2), values.respcorrgain(3), channel->rawId ());
2040  fOutput << buffer;
2041  }
2042  return true;
2043 }
2044 
2045 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalCalibrationWidthsSet& fObject) {
2046  char buffer [1024];
2047  sprintf (buffer, "# %15s %15s %15s %15s %9s %9s %9s %9s %12s %12s %12s %12s %10s %10s %10s %10s %10s\n",
2048  "eta", "phi", "dep", "det",
2049  "pedwcap0", "pedwcap1", "pedwcap2", "pedwcap3",
2050  "effpedwcap0", "effpedwcap1", "effpedwcap2", "effpedwcap3",
2051  "gainwcap0", "gainwcap1", "gainwcap2", "gainwcap3", "DetId");
2052  fOutput << buffer;
2053 
2054  std::vector<DetId> channels = fObject.getAllChannels ();
2055  std::sort (channels.begin(), channels.end(), DetIdLess ());
2056  for (std::vector<DetId>::iterator channel = channels.begin (); channel != channels.end (); ++channel) {
2057  dumpId (fOutput, *channel);
2058  const HcalCalibrationWidths& values = fObject.getCalibrationWidths(*channel);
2059  sprintf (buffer, " %9.5f %9.5f %9.5f %9.5f %12.5f %12.5f %12.5f %12.5f %10.5f %10.5f %10.5f %10.5f %10X\n",
2060  values.pedestal(0), values.pedestal(1), values.pedestal(2), values.pedestal(3),
2061  values.effpedestal(0), values.effpedestal(1), values.effpedestal(2), values.effpedestal(3),
2062  values.gain(0), values.gain(1), values.gain(2), values.gain(3), channel->rawId ());
2063  fOutput << buffer;
2064  }
2065  return true;
2066 }
2067 
const std::string & getField1() const
void dumpIdShort(std::ostream &fOutput, DetId id)
size
Write out results.
std::unique_ptr< HcalFrontEndMap > createObject< HcalFrontEndMap >(std::istream &fInput)
uint32_t getFlag() const
Definition: start.py:1
constexpr void setHTR(int crate, int slot, int tb)
type
Definition: HCALResponse.h:21
float getPedestal() const
constexpr unsigned int pulseShapeID() const
Definition: HcalRecoParam.h:34
static const HcalDetId Undefined
Definition: HcalDetId.h:272
constexpr unsigned int param2() const
Definition: HcalRecoParam.h:27
static unsigned int getId()
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
float timePhase() const
Definition: HcalMCParam.h:43
constexpr unsigned int samplesToAdd() const
Definition: HcalRecoParam.h:33
void setUnitADC(bool isADC)
Definition: HcalPedestals.h:30
double gain(int fCapId) const
get gain width for capid=0..3
float slope(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:54
int getAuxi1() const
get Axiliary words
std::vector< DetId > getAllChannels() const
uint64_t getTDCMaskHF() const
get TDC mask for HF
std::vector< unsigned int > signalTS() const
bool from_string(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &))
bool isADC() const
Definition: HcalPedestals.h:28
bool isHcalZDCDetId() const
constexpr unsigned int pileupCleaningID() const
Definition: HcalRecoParam.h:44
int subchannel() const
Definition: HcalDcsDetId.h:49
bool loadObject(DetId fId, int rm, std::string rbx)
load a new entry
static int slb(const HcalTriggerPrimitiveSample &theSample)
const HcalQIECoder * getCoder(DetId fId) const
get QIE parameters
Definition: HcalQIEData.h:39
bool timeSmearing() const
Definition: HcalMCParam.h:44
TObject * getObject(TDirectory *fDir, const std::vector< std::string > &fObjectName)
Definition: compareHists.cc:44
uint8_t getOutputLutThreshold() const
float getauxi2() const
unsigned int packingScheme() const
Definition: HcalMCParam.h:45
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
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
int getType() const
get SiPM type
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
double effpedestal(int fCapId) const
get effective pedestal width for capid=0..3
std::vector< unsigned int > splitStringToIntByComma(const std::string &fLine)
const Item * getValues(DetId fId, bool throwOnFail=true) const
void setOffset(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:58
constexpr int slbChannelIndex() const
get the SLB channel index (valid only for VME trigger-chain ids)
bool dumpHcalSingleFloatObject(std::ostream &fOutput, const T &fObject)
void dumpId(std::ostream &fOutput, DetId id)
constexpr int dccid() const
get the (Hcal local) DCC id for VME, crate number for uTCA
uint8_t getLutGranularity() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const HcalCalibrationQIECoder * getCoder(DetId fId) const
get QIE parameters
std::vector< std::string > splitString(const std::string &fLine)
std::vector< DetId > getAllChannels() const
uint16_t size_type
bool addCoder(const HcalQIECoder &fCoder)
Definition: HcalQIEData.h:43
bool setRctLsb(float rctlsb)
void dumpId(std::ostream &fOutput, DetId id)
float getCrossTalk(int type) const
get cross talk
constexpr unsigned int timeslewCorrectionID() const
Definition: HcalRecoParam.h:39
unsigned int param1() const
Definition: HcalMCParam.h:39
float phase() const
U second(std::pair< T, U > const &p)
const_iterator endById(void) const
Definition: HcalDcsMap.cc:61
constexpr bool isUTCAid() const
bool syncPhase() const
Definition: HcalMCParam.h:41
const std::string & getField3() const
constexpr int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
std::unique_ptr< HcalSiPMCharacteristics > createObject< HcalSiPMCharacteristics >(std::istream &fInput)
std::vector< HcalDcsValue > DcsSet
Definition: HcalDcsValues.h:27
constexpr unsigned int noiseFlaggingID() const
Definition: HcalRecoParam.h:43
void setUnitADC(bool isADC)
float getRespGain() const
double pedestal(int fCapId) const
get pedestal width for capid=0..3
float offset(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:50
constexpr bool isVMEid() const
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:49
std::vector< DetId > getAllChannels() const
constexpr float correctionPhaseNS() const
Definition: HcalRecoParam.h:31
unsigned int nhits() const
float getNominalGain() const
std::vector< DetId > allDetIds() const
constexpr int htrSlot() const
get the htr slot
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
HcalDetId getHcalDetId(void)
Definition: HcalDcsMap.cc:98
HcalOtherSubdetector
Definition: HcalAssistant.h:32
float getRCalib() const
int getFGVersionHBHE() const
get FineGrain Algorithm Version for HBHE
constexpr double effpedestal(int fCapId) const
get effective pedestal for capid=0..3
HcalDcsDetId getHcalDcsDetId(void)
Definition: HcalDcsMap.cc:94
bool dumpHcalMatrixObject(std::ostream &fOutput, const T &fObject)
constexpr int readoutVMECrateId() const
get the readout VME crate number
constexpr unsigned int firstAuxTS() const
Definition: HcalRecoParam.h:41
double f[11][100]
uint32_t HFdigiflagExpectedPeak() const
constexpr int spigot() const
get the spigot (input number on DCC, AMC card number for uTCA)
constexpr int crateId() const
get the readout VME crate number
constexpr bool correctTiming() const
Definition: HcalRecoParam.h:40
unsigned int getTypes() const
get # of types
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:160
Definition: value.py:1
constexpr bool useLeakCorrection() const
Definition: HcalRecoParam.h:36
float getDarkCurrent() const
get dark current
std::string getTagString() const
void setMinCharges(const float fValue[32])
uint32_t getHFTriggerInfo() const
get Self Trigger bits
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
bool getHcalSingleObject(std::istream &fInput, T *fObject)
static DcsType DcsTypeFromString(const std::string &str)
Definition: HcalDcsDetId.cc:31
int k[5][pyjets_maxn]
bin
set the eta bin as selection string.
const HcalCalibrationWidths & getCalibrationWidths(const DetId id) const
std::vector< double > HFdigiflagCoefficients() const
int getauxi1() const
Definition: DetId.h:18
constexpr int fiberIndex() const
get the fiber index. For VME 1-8 (which of eight fibers carried by a spigot), for uTCA fibers are zer...
constexpr bool correctForPhaseContainment() const
Definition: HcalRecoParam.h:29
constexpr double pedestal(int fCapId) const
get pedestal for capid=0..3
constexpr bool correctForTimeslew() const
Definition: HcalRecoParam.h:38
const std::string & getField2() const
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
int getAuxi2() const
int getAuxi1(int type) const
get auxiliary words
std::string getAlgoString() const
std::vector< HcalElectronicsId > allElectronicsId() const
unsigned long long uint64_t
Definition: Time.h:15
bool getHcalObject(std::istream &fInput, T *fObject)
int getType(unsigned int k) const
void sort()
Definition: HcalQIEData.h:45
constexpr bool correctForLeadingEdge() const
Definition: HcalRecoParam.h:30
uint32_t HFdigiflagFirstSample() const
const int lookupRM(DetId fId) const
brief lookup the RM associated with the given logical id
const HcalCalibrations & getCalibrations(const DetId id) const
int slice() const
Definition: HcalDcsDetId.h:47
bool loadObject(int type, int pixels, float parLin1, float parLin2, float parLin3, float crossTalk, int auxi1=0, float auxi2=0)
std::vector< float > getNonLinearities(int type) const
get nonlinearity constants
float getRctLsb() const
double S(const TLorentzVector &, const TLorentzVector &)
Definition: Particle.cc:99
void loadObject(int version, int adcCut, uint64_t tdcMask, uint32_t tbits, int auxi1, int auxi2)
unsigned int signalShape() const
Definition: HcalMCParam.h:40
static const HcalTrigTowerDetId Undefined
bool addValue(HcalDcsValue const &newVal)
constexpr unsigned int param1() const
Definition: HcalRecoParam.h:26
bool getObject(std::istream &fInput, HcalPedestals *fObject)
void setTagString(std::string const &fTag)
constexpr int slot() const
get the htr or uHTR slot
DetId getId(const std::vector< std::string > &items)
unsigned int binOfMaximum() const
Definition: HcalMCParam.h:42
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
constexpr unsigned int leakCorrectionID() const
Definition: HcalRecoParam.h:37
constexpr int slbSiteNumber() const
get the SLB site number (valid only for VME trigger-chain ids)
uint32_t getFGBitInfo() const
get FG bit information
const float * getValues() const
get value for all capId = 0..3
Definition: HcalPedestal.h:19
bool dumpHcalObject(std::ostream &fOutput, const T &fObject)
constexpr unsigned int packingScheme() const
Definition: HcalRecoParam.h:45
std::vector< unsigned int > noiseTS() const
constexpr bool isTriggerChainId() const
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
float getAuxi2(int type) const
const std::string & getFlavor() const
const float * minCharges() const
constexpr int fiberChanId() const
get the fiber channel id (which of channels on a fiber)
constexpr unsigned int specialCaseID() const
Definition: HcalRecoParam.h:42
std::unique_ptr< HcalDcsMap > createObject< HcalDcsMap >(std::istream &fInput)
uint32_t getValue() const
float rms() const
bool addCoder(const HcalCalibrationQIECoder &fCoder)
def fail(errstr="")
bool addValues(const Item &myItem)
rm
Definition: submit.py:77
long double T
int getPixels(int type) const
get # of pixels
int ring() const
Definition: HcalDcsDetId.h:46
void setAlgoString(std::string const &fAlgo)
std::unique_ptr< HcalElectronicsMap > createObject< HcalElectronicsMap >(std::istream &fInput)
Readout chain identification for Hcal.
constexpr double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
void setSigma(int fCapId1, int fCapId2, float fSigma)
void setSlope(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:67
const std::string lookupRBX(DetId fId) const
brief lookup the RBX associated with the given logical id
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
int getADCThresholdHF() const
get ADC threshold fof TDC mask of HF
float getFCByPE() const
get fcByPE
bool setNominalGain(float gain)
constexpr unsigned int firstSample() const
Definition: HcalRecoParam.h:32
bool dumpHcalSingleIntObject(std::ostream &fOutput, const T &fObject)
uint32_t getMask() const
get mask for channel validity and self trigger information
std::vector< double > splitStringToDoubleByComma(const std::string &fLine)
double HFdigiflagMinEThreshold() const