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[8] == "HT" || items[8] == "NT") {
1331  int slb = atoi (items [6].c_str());
1332  int slbCh = atoi (items [7].c_str());
1333  elId=HcalElectronicsId(slbCh, slb, spigot, dcc,crate,slot,top);
1334  } else {
1335  int fiber = atoi (items [6].c_str());
1336  int fiberCh = atoi (items [7].c_str());
1337 
1338  elId=HcalElectronicsId(fiberCh, fiber, spigot, dcc);
1339  elId.setHTR (crate, slot, top);
1340  }
1341 
1342  // first, handle undefined cases
1343  if (items [8] == "NA") { // undefined channel
1344  fObject->mapEId2chId (elId, DetId (HcalDetId::Undefined));
1345  } else if (items [8] == "NT") { // undefined trigger channel
1346  fObject->mapEId2tId (elId, DetId (HcalTrigTowerDetId::Undefined));
1347  } else {
1348  HcalText2DetIdConverter converter (items [8], items [9], items [10], items [11]);
1349  if (converter.isHcalDetId ()) {
1350  fObject->mapEId2chId (elId, converter.getId ());
1351  }
1352  else if (converter.isHcalTrigTowerDetId ()) {
1353  fObject->mapEId2tId (elId, converter.getId ());
1354  }
1355  else if (converter.isHcalCalibDetId ()) {
1356  fObject->mapEId2chId (elId, converter.getId ());
1357  }
1358  else if (converter.isHcalZDCDetId ()) {
1359  fObject->mapEId2chId (elId, converter.getId ());
1360  }
1361  else {
1362  edm::LogWarning("Format Error") << "HcalElectronicsMap-> Unknown subdetector: "
1363  << items [8] << '/' << items [9] << '/' << items [10] << '/' << items [11] << std::endl;
1364  }
1365  }
1366  }
1367  fObject->sort ();
1368  return true;
1369 }
1370 
1371 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalElectronicsMap& fObject) {
1372  std::vector<HcalElectronicsId> eids = fObject.allElectronicsId ();
1373  char buf [1024];
1374  // changes by Jared, 6.03.09/(included 25.03.09)
1375  // sprintf (buf, "#%10s %6s %6s %6s %6s %6s %6s %6s %15s %15s %15s %15s",
1376  sprintf (buf, "# %7s %3s %3s %3s %4s %7s %10s %14s %7s %5s %5s %6s",
1377  "i", "cr", "sl", "tb", "dcc", "spigot", "fiber/slb", "fibcha/slbcha", "subdet", "ieta", "iphi", "depth");
1378  fOutput << buf << std::endl;
1379 
1380  for (unsigned i = 0; i < eids.size (); i++) {
1381  HcalElectronicsId eid = eids[i];
1382  if (eid.isTriggerChainId()) {
1383  DetId trigger = fObject.lookupTrigger (eid);
1384  if (trigger.rawId ()) {
1385  HcalText2DetIdConverter converter (trigger);
1386  // changes by Jared, 6.03.09/(included 25.03.09)
1387  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1388  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1389  // i,
1390  converter.getId().rawId(),
1391  // changes by Jared, 6.03.09/(included 25.03.09)
1392  // eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1393  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.slbSiteNumber(), eid.slbChannelIndex(),
1394  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1395  );
1396  fOutput << buf << std::endl;
1397  }
1398  } else {
1399  DetId channel = fObject.lookup (eid);
1400  if (channel.rawId()) {
1401  HcalText2DetIdConverter converter (channel);
1402  // changes by Jared, 6.03.09/(included 25.03.09)
1403  // sprintf (buf, " %10X %6d %6d %6c %6d %6d %6d %6d %15s %15s %15s %15s",
1404  sprintf (buf, " %7X %3d %3d %3c %4d %7d %10d %14d %7s %5s %5s %6s",
1405  // i,
1406  converter.getId().rawId(),
1407  eid.readoutVMECrateId(), eid.htrSlot(), eid.htrTopBottom()>0?'t':'b', eid.dccid(), eid.spigot(), eid.fiberIndex(), eid.fiberChanId(),
1408  converter.getFlavor ().c_str (), converter.getField1 ().c_str (), converter.getField2 ().c_str (), converter.getField3 ().c_str ()
1409  );
1410  fOutput << buf << std::endl;
1411  }
1412  }
1413  }
1414  return true;
1415 }
1416 
1417 
1418 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalLutMetadata* fObject){
1419  if (!fObject) return false; //fObject = new HcalLutMetadata;
1420  char buffer [1024];
1421  while (fInput.getline(buffer, 1024)) {
1422  if (buffer [0] == '#') continue; //ignore comment
1423  std::vector <std::string> items = splitString (std::string (buffer));
1424  if (items.size()==0) continue; // blank line
1425  // now get non-channel data
1426  if (items.size() > 1 &&
1427  items[0].find("RctLsb")!=std::string::npos){
1428  fObject->setRctLsb( atof( items[1].c_str() ) );
1429  continue;
1430  }
1431  if (items.size() > 1 &&
1432  items[0].find("Gain")!=std::string::npos){
1433  fObject->setNominalGain( atof( items[1].c_str() ) );
1434  continue;
1435  }
1436  // now proceeed to per-channel data
1437  if (items.size () < 7) {
1438  edm::LogWarning("Format Error") << "Bad line: " << buffer << "\n line must contain 7 items: eta, phi, depth, subdet, Rcalib, LutGranularity, OutputLutThreshold" << std::endl;
1439  continue;
1440  }
1441  DetId id = getId (items);
1442 
1443  HcalLutMetadatum * fCondObject = new HcalLutMetadatum(id,
1444  atof (items [4].c_str()),
1445  atoi (items [5].c_str()),
1446  atoi (items [6].c_str()));
1447  fObject->addValues(*fCondObject);
1448  delete fCondObject;
1449  }
1450  return true;
1451 }
1452 
1453 
1454 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalLutMetadata& fObject){
1455  char buffer [1024];
1456  const float _rctLsb = fObject.getRctLsb();
1457  const float _gain = fObject.getNominalGain();
1458  sprintf (buffer, "# %20s\n", "Non-channel data");
1459  fOutput << buffer;
1460  sprintf (buffer, "%8s %8.5f\n", "RctLsb", _rctLsb);
1461  fOutput << buffer;
1462  sprintf (buffer, "%8s %8.5f\n", "Gain", _gain);
1463  fOutput << buffer;
1464  sprintf (buffer, "# %15s %15s %15s %15s %8s %15s %19s %10s\n", "eta", "phi", "dep", "det", "Rcalib", "LutGranularity", "OutputLutThreshold", "DetId");
1465  fOutput << buffer;
1466  std::vector<DetId> channels = fObject.getAllChannels ();
1467  std::sort (channels.begin(), channels.end(), DetIdLess ());
1468  for (std::vector<DetId>::iterator channel = channels.begin ();
1469  channel != channels.end ();
1470  channel++) {
1471  const float _rCalib = fObject.getValues (*channel)->getRCalib();
1472  const uint8_t _lutGranularity = fObject.getValues (*channel)->getLutGranularity();
1473  const uint8_t _outputLutThreshold = fObject.getValues (*channel)->getOutputLutThreshold();
1474  dumpId (fOutput, *channel);
1475  sprintf (buffer, " %8.5f %15d %19d %10X\n",
1476  _rCalib,
1477  _lutGranularity,
1478  _outputLutThreshold,
1479  channel->rawId ());
1480  fOutput << buffer;
1481  }
1482  return true;
1483 }
1484 
1485 //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1486 bool HcalDbASCIIIO::getObject(std::istream& fInput, HcalDcsValues * fObject) {
1487  if (!fObject) return false; //fObject = new HcalDcsValues;
1488  std::string buffer;
1489  while (getline(fInput, buffer)) {
1490  if (buffer.at(0) == '#') continue; //ignore comment
1491  std::vector <std::string> items = splitString (buffer);
1492  if (items.size()==0) continue; // blank line
1493 
1494  if (items.size() < 9) {
1495  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;
1496  continue;
1497  }
1498 
1499  HcalOtherSubdetector subd;
1500  int sidering;
1501  unsigned int slice, subchan;
1502  switch (items[0].at(1)) {
1503  case 'B':
1504  subd = HcalDcsBarrel;
1505  break;
1506  case 'E':
1507  subd = HcalDcsEndcap;
1508  break;
1509  case 'F':
1510  subd = HcalDcsForward;
1511  break;
1512  case 'O':
1513  subd = HcalDcsOuter;
1514  break;
1515  default:
1516  continue;
1517  }
1518  //from_string<int>(subd, items[0], std::dec);
1519  from_string<int>(sidering, items[1], std::dec);
1520  from_string<unsigned int>(slice, items[2], std::dec);
1521  //from_string<int>(ty, items[3], std::dec);
1522  from_string<unsigned int>(subchan, items[4], std::dec);
1523 
1524  HcalDcsDetId newId(subd, sidering, slice,
1525  HcalDcsDetId::DcsTypeFromString(items[3]), subchan);
1526 
1527  int LS;
1528  float val,upper,lower;
1529  from_string<int>(LS, items[5], std::dec);
1530  from_string<float>(val, items[6], std::dec);
1531  from_string<float>(upper, items[7], std::dec);
1532  from_string<float>(lower, items[8], std::dec);
1533 
1534  HcalDcsValue newVal(newId.rawId(),LS,val,upper,lower);
1535 // std::cout << buffer << '\n';
1536 // std::cout << subd << ' ' << sidering << ' ' << slice << ' '
1537 // << ty << ' ' << subchan << ' ' << LS << ' '
1538 // << val << ' ' << upper << ' ' << lower << '\n';
1539 // std::cout << newId ;
1540  if (!(fObject->addValue(newVal))) {
1541  edm::LogWarning("Data Error") << "Data from line " << buffer
1542  << "\nwas not added to the HcalDcsValues object." << std::endl;
1543  }
1544 // std::cout << std::endl;
1545  }
1546  fObject->sortAll();
1547  return true;
1548 }
1549 
1550 bool HcalDbASCIIIO::dumpObject(std::ostream& fOutput,
1551  HcalDcsValues const& fObject) {
1552  fOutput << "# subDet side_ring slice type subChan LS Value UpperLimit LowerLimit DcsId\n";
1553  for(int subd = HcalDcsValues::HcalHB;
1554  subd <= HcalDcsValues::HcalHF; ++subd) {
1555 // std::cout << "subd: " << subd << '\n';
1556  HcalDcsValues::DcsSet const & vals=
1558  for (HcalDcsValues::DcsSet::const_iterator val = vals.begin();
1559  val != vals.end(); ++val) {
1560  HcalDcsDetId valId(val->DcsId());
1561 
1562  switch (valId.subdet()) {
1563  case HcalDcsBarrel:
1564  fOutput << "HB ";
1565  break;
1566  case HcalDcsEndcap:
1567  fOutput << "HE ";
1568  break;
1569  case HcalDcsOuter:
1570  fOutput << "HO ";
1571  break;
1572  case HcalDcsForward:
1573  fOutput << "HF ";
1574  break;
1575  default :
1576  fOutput << valId.subdet() << ' ';
1577  }
1578 
1579  if (valId.subdet() == HcalDcsOuter)
1580  fOutput << valId.ring() << ' ';
1581  else
1582  fOutput << valId.zside() << ' ';
1583 
1584  fOutput << valId.slice() << ' '
1585  << valId.typeString(valId.type()) << ' '
1586  << valId.subchannel() << ' ';
1587  fOutput << val->LS() << ' '
1588  << val->getValue() << ' '
1589  << val->getUpperLimit() << ' '
1590  << val->getLowerLimit() << ' ';
1591  fOutput << std::hex << val->DcsId() << std::dec << '\n';
1592 
1593 // std::cout << valId << ' '
1594 // << valId.subdet() << ' '
1595 // << val->LS() << ' ' << val->getValue() << ' '
1596 // << val->getUpperLimit() << ' ' << val->getLowerLimit()
1597 // << std::endl;
1598  }
1599  }
1600 
1601  return true;
1602 }
1603 
1604 
1605 // Format of the ASCII file:
1606 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1607 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1608 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalDcsMap* fObject) {
1609  char buffer [1024];
1610  while (fInput.getline(buffer, 1024)) {
1611  if (buffer [0] == '#') continue; //ignore comment
1612  std::vector <std::string> items = splitString (std::string (buffer));
1613  if (items.size () < 8) {
1614  if (items.size()==0) continue; // no warning here
1615  else {
1616  edm::LogError("MapFormat") << "HcalDcsMap-> Bad line: " << buffer
1617  << "\n line must contain 8 items: line side_ring slice subchannel subdet ieta iphi depth";
1618  continue;
1619  }
1620  }
1621  // std::cout << "HcalDcsMap-> processing line: " << buffer << std::endl;
1622  //int ring = atoi (items [1].c_str());
1623  int ring = atoi(items[1].c_str());
1624  unsigned int slice = atoi (items [2].c_str());
1625  unsigned int subchannel = atoi (items [3].c_str());
1627 // if(items[4].find("HV")!=std::string::npos){
1628 // type = HcalDcsDetId::HV;
1629 // }
1630 // else if (items[4].find("BV")!=std::string::npos){
1631 // type = HcalDcsDetId::BV;
1632 // }
1633 // else if (items[4].find("CATH")!=std::string::npos){
1634 // type = HcalDcsDetId::CATH;
1635 // }
1636 // else if (items[4].find("DYN7")!=std::string::npos){
1637 // type = HcalDcsDetId::DYN7;
1638 // }
1639 // else if (items[4].find("DYN8")!=std::string::npos){
1640 // type = HcalDcsDetId::DYN8;
1641 // }
1642 // else if (items[4].find("RM_TEMP")!=std::string::npos){
1643 // type = HcalDcsDetId::RM_TEMP;
1644 // }
1645 // else if (items[4].find("CCM_TEMP")!=std::string::npos){
1646 // type = HcalDcsDetId::CCM_TEMP;
1647 // }
1648 // else if (items[4].find("CALIB_TEMP")!=std::string::npos){
1649 // type = HcalDcsDetId::CALIB_TEMP;
1650 // }
1651 // else if (items[4].find("LVTTM_TEMP")!=std::string::npos){
1652 // type = HcalDcsDetId::LVTTM_TEMP;
1653 // }
1654 // else if (items[4].find("TEMP")!=std::string::npos){
1655 // type = HcalDcsDetId::TEMP;
1656 // }
1657 // else if (items[4].find("QPLL_LOCK")!=std::string::npos){
1658 // type = HcalDcsDetId::QPLL_LOCK;
1659 // }
1660 // else if (items[4].find("STATUS")!=std::string::npos){
1661 // type = HcalDcsDetId::STATUS;
1662 // }
1663 // else if (items[4].find("DCS_MAX")!=std::string::npos){
1664 // type = HcalDcsDetId::DCS_MAX;
1665 // }
1666 // else{
1667 // edm::LogError("MapFormat") << "HcalDcsMap-> Unknown DCS Type, line is not accepted: " << items[4];
1668 // continue;
1669 // }
1671  if (items[4].find("CALIB")!=std::string::npos){
1672  subdet = HcalCalibration;
1673  }
1674  else if (items[4].find("HB")!=std::string::npos){
1675  subdet = HcalDcsBarrel;
1676  }
1677  else if (items[4].find("HE")!=std::string::npos){
1678  subdet = HcalDcsEndcap;
1679  }
1680  else if (items[4].find("HO")!=std::string::npos){
1681  subdet = HcalDcsOuter;
1682  }
1683  else if (items[4].find("HF")!=std::string::npos){
1684  subdet = HcalDcsForward;
1685  }
1686  else{
1687  edm::LogError("MapFormat") << "HcalDcsMap-> Unknown subdetector, line is not accepted: " << items[5];
1688  continue;
1689  }
1690  HcalDcsDetId dcsId(subdet, ring, slice, type, subchannel);
1691  HcalText2DetIdConverter converter (items [4], items [5], items [6], items [7]);
1692  HcalDetId id(0);
1693  if (converter.isHcalDetId()){
1694  id = converter.getId();
1695  }
1696  else{
1697  edm::LogWarning("Invalid HCAL channel") << "HcalDcsMap-> invalid channel: "
1698  << items [4] << '/'
1699  << items [5] << '/'
1700  << items [6] << '/'
1701  << items [7] << std::endl;
1702  continue;
1703  }
1704  fObject->mapGeomId2DcsId(id, dcsId);
1705  }
1706  fObject->sort ();
1707  return true;
1708 }
1709 
1710 // Format of the ASCII file:
1711 // line# Ring Slice Subchannel Subdetector Eta Phi Depth
1712 // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1713 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalDcsMap& fObject) {
1714  char buf [1024];
1715  sprintf (buf, "# %7s %10s %6s %8s %7s %5s %5s %6s",
1716  "i", "side_ring", "slice", "subchan", "subdet", "ieta", "iphi", "depth");
1717  fOutput << buf << std::endl;
1719  unsigned int line_counter = 0;
1720  for (_line = fObject.beginById();
1721  _line != fObject.endById();
1722  ++_line) {
1723  HcalDcsDetId dcsId = _line.getHcalDcsDetId();
1724  //std::string _dcs_type = "DCSUNKNOWN";
1725  HcalText2DetIdConverter _converter(_line.getHcalDetId());
1726  sprintf (buf, " %8X %10d %6d %8d %7s %5s %5s %6s",
1727  line_counter,
1728  dcsId.ring(), // contains zside() already
1729  dcsId.slice(),
1730  dcsId.subchannel(),
1731  _converter.getFlavor().c_str(),
1732  _converter.getField1().c_str(),
1733  _converter.getField2().c_str(),
1734  _converter.getField3().c_str()
1735  );
1736  fOutput << buf << std::endl;
1737  ++line_counter;
1738  }
1739  return true;
1740 }
1741 
1742 
1743 bool HcalDbASCIIIO::getObject (std::istream& fInput, HcalFlagHFDigiTimeParams* fObject)
1744 {
1745 
1746  if (!fObject) return false; //fObject = new HcalFlagHFDigiTimeParams();
1747  char buffer [1024];
1748  while (fInput.getline(buffer, 1024)) {
1749  if (buffer [0] == '#') continue; //ignore comment
1750  std::vector <std::string> items = splitString (std::string (buffer));
1751  if (items.size()==0) continue; // blank line
1752  if (items.size () != 9) {
1753  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;
1754  continue;
1755  }
1756  // expects (ieta, iphi, depth, subdet) as first four arguments
1757  DetId id = HcalDbASCIIIO::getId (items);
1758  std::vector<double> coef= splitStringToDoubleByComma(items[8].c_str());
1759 
1760  HcalFlagHFDigiTimeParam* fCondObject = new HcalFlagHFDigiTimeParam(id,
1761  atoi (items [4].c_str()), //firstSample
1762  atoi (items [5].c_str()), //samplesToAdd
1763  atoi (items [6].c_str()), //expectedPeak
1764  atof (items [7].c_str()), // minEThreshold
1765  coef // coefficients
1766  );
1767  fObject->addValues(*fCondObject);
1768  delete fCondObject;
1769  }
1770  return true;
1771 } // getObject (HcalFlagHFDigiTime)
1772 
1773 bool HcalDbASCIIIO::dumpObject (std::ostream& fOutput, const HcalFlagHFDigiTimeParams& fObject)
1774 {
1775  char buffer [1024];
1776  sprintf (buffer, "# %15s %15s %15s %15s %15s %15s %15s %15s %30s\n", "eta", "phi", "dep", "det", "FirstSample", "SamplesToAdd", "ExpectedPeak","MinEnergy","Coefficients");
1777  fOutput << buffer;
1778  std::vector<DetId> channels = fObject.getAllChannels ();
1779  std::sort (channels.begin(), channels.end(), DetIdLess ());
1780  for (std::vector<DetId>::iterator channel = channels.begin ();
1781  channel != channels.end ();
1782  channel++) {
1783  // Dump out channel (ieta,iphi,depth,subdet) info
1784  HcalDbASCIIIO::dumpId (fOutput, *channel);
1785  // Dump out values for channel
1786  sprintf (buffer, " %15u %15u %15u %15f",
1787  fObject.getValues (*channel)->HFdigiflagFirstSample(),
1788  fObject.getValues (*channel)->HFdigiflagSamplesToAdd(),
1789  fObject.getValues (*channel)->HFdigiflagExpectedPeak(),
1790  fObject.getValues (*channel)->HFdigiflagMinEThreshold()
1791  );
1792 
1793  fOutput<<buffer; // dump flag reco values to buffer
1794  fOutput<<" "; // simple spacer
1795 
1796  std::vector<double> coef=fObject.getValues(*channel)->HFdigiflagCoefficients();
1797  for (std::vector<double>::size_type x=0;x<coef.size();++x)
1798  {
1799  // dump comma-separated list of coefficients
1800  fOutput<<coef[x];
1801  if (x<coef.size()-1) // add commas where necessary
1802  fOutput<<",";
1803  }
1804  sprintf(buffer,"\n");
1805  fOutput << buffer;
1806  }
1807  return true;
1808 }
1809 
1810 
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 [1-8] (which of eight fibers carried by a spigot) (valid only for non-trigger-cha...
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)
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
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)
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
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 three channels on a readout fiber) (valid only for non-trigger-cha...
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)
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 trigger-chain ids)
std::vector< double > HFdigiflagCoefficients() const
Definition: DetId.h:18
void setHTR(int crate, int slot, int tb)
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
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 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 [31:26] Unused (so far) [25] Trigger-chain id flag [24:20] Read...
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
bool setNominalGain(float gain)
bool dumpHcalSingleIntObject(std::ostream &fOutput, const T &fObject)
unsigned int timeslewCorrectionID() const
Definition: HcalRecoParam.h: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