CMS 3D CMS Logo

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