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