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