CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTrigPrimESProducer.cc
Go to the documentation of this file.
1 // user include files
3 
4 #include <iostream>
5 #include <fstream>
6 #include <TMath.h>
7 #include <sstream>
8 
10 
11 //
12 // input stream from a gz file
13 //
14 
16  {
17  typedef voidp gzFile ;
19  char buffer[256] ;
20  std::istringstream iss ;
21  bool eof ;
22  GzInputStream( const char * file )
23  : eof(false)
24  {
25  gzf = gzopen(file,"rb") ;
26  if (gzf==Z_NULL)
27  {
28  eof = true ;
29  edm::LogWarning("EcalTPG") <<"Database file "<<file<<" not found!!!";
30  }
31  else readLine() ;
32  }
33  void readLine()
34  {
35  char * res = gzgets(gzf,buffer,256) ;
36  eof = (res==Z_NULL) ;
37  if (!eof)
38  {
39  iss.clear() ;
40  iss.str(buffer) ;
41  }
42  }
44  { gzclose(gzf) ; }
45  operator void*()
46  { return ((eof==true)?((void*)0):iss) ; }
47  } ;
48 
49 template <typename T>
51  {
52  while ((gis)&&(!(gis.iss>>var)))
53  { gis.readLine() ; }
54  return gis ;
55  }
56 
57 
58 //
59 // constructors and destructor
60 //
61 
63  dbFilename_(iConfig.getUntrackedParameter<std::string>("DatabaseFile",""))
64 {
65  //the following line is needed to tell the framework what
66  // data is being produced
81  //now do what ever other initialization is needed
82 }
83 
84 
86 {
87 }
88 
89 //
90 // member functions
91 //
92 
93 // ------------ method called to produce the data ------------
94 
95 
96 std::auto_ptr<EcalTPGPedestals> EcalTrigPrimESProducer::producePedestals(const EcalTPGPedestalsRcd & iRecord)
97 {
98  std::auto_ptr<EcalTPGPedestals> prod(new EcalTPGPedestals());
99  parseTextFile() ;
100  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
101  for (it = mapXtal_.begin() ; it != mapXtal_.end() ; it++) {
102  EcalTPGPedestal item ;
103  item.mean_x12 = (it->second)[0] ;
104  item.mean_x6 = (it->second)[3] ;
105  item.mean_x1 = (it->second)[6] ;
106  prod->setValue(it->first,item) ;
107  }
108  return prod;
109 }
110 
111 std::auto_ptr<EcalTPGLinearizationConst> EcalTrigPrimESProducer::produceLinearizationConst(const EcalTPGLinearizationConstRcd & iRecord)
112 {
113  std::auto_ptr<EcalTPGLinearizationConst> prod(new EcalTPGLinearizationConst());
114  parseTextFile() ;
115  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
116  for (it = mapXtal_.begin() ; it != mapXtal_.end() ; it++) {
118  item.mult_x12 = (it->second)[1] ;
119  item.mult_x6 = (it->second)[4] ;
120  item.mult_x1 = (it->second)[7] ;
121  item.shift_x12 = (it->second)[2] ;
122  item.shift_x6 = (it->second)[5] ;
123  item.shift_x1 = (it->second)[8] ;
124  prod->setValue(it->first,item) ;
125  }
126  return prod;
127 }
128 
129 std::auto_ptr<EcalTPGSlidingWindow> EcalTrigPrimESProducer::produceSlidingWindow(const EcalTPGSlidingWindowRcd & iRecord)
130 {
131  std::auto_ptr<EcalTPGSlidingWindow> prod(new EcalTPGSlidingWindow());
132  parseTextFile() ;
133  for (int subdet=0 ; subdet<2 ; subdet++) {
134  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
135  for (it = mapStrip_[subdet].begin() ; it != mapStrip_[subdet].end() ; it++) {
136  prod->setValue(it->first,(it->second)[0]) ;
137  }
138  }
139  return prod;
140 }
141 
142 std::auto_ptr<EcalTPGFineGrainEBIdMap> EcalTrigPrimESProducer::produceFineGrainEB(const EcalTPGFineGrainEBIdMapRcd & iRecord)
143 {
144  std::auto_ptr<EcalTPGFineGrainEBIdMap> prod(new EcalTPGFineGrainEBIdMap());
145  parseTextFile() ;
147  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
148  for (it = mapFg_.begin() ; it != mapFg_.end() ; it++) {
149  fg.setValues((it->second)[0], (it->second)[1], (it->second)[2], (it->second)[3], (it->second)[4]) ;
150  prod->setValue(it->first,fg) ;
151  }
152  return prod;
153 }
154 
155 std::auto_ptr<EcalTPGFineGrainStripEE> EcalTrigPrimESProducer::produceFineGrainEEstrip(const EcalTPGFineGrainStripEERcd & iRecord)
156 {
157  std::auto_ptr<EcalTPGFineGrainStripEE> prod(new EcalTPGFineGrainStripEE());
158  parseTextFile() ;
159  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
160  for (it = mapStrip_[1].begin() ; it != mapStrip_[1].end() ; it++) {
162  item.threshold = (it->second)[2] ;
163  item.lut = (it->second)[3] ;
164  prod->setValue(it->first,item) ;
165  }
166  return prod;
167 }
168 
169 std::auto_ptr<EcalTPGFineGrainTowerEE> EcalTrigPrimESProducer::produceFineGrainEEtower(const EcalTPGFineGrainTowerEERcd & iRecord)
170 {
171  std::auto_ptr<EcalTPGFineGrainTowerEE> prod(new EcalTPGFineGrainTowerEE());
172  parseTextFile() ;
173  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
174  for (it = mapTower_[1].begin() ; it != mapTower_[1].end() ; it++) {
175  prod->setValue(it->first,(it->second)[1]) ;
176  }
177  return prod;
178 }
179 
180 std::auto_ptr<EcalTPGLutIdMap> EcalTrigPrimESProducer::produceLUT(const EcalTPGLutIdMapRcd & iRecord)
181 {
182  std::auto_ptr<EcalTPGLutIdMap> prod(new EcalTPGLutIdMap());
183  parseTextFile() ;
184  EcalTPGLut lut ;
185  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
186  for (it = mapLut_.begin() ; it != mapLut_.end() ; it++) {
187  unsigned int lutArray[1024] ;
188  for (int i=0 ; i <1024 ; i++) lutArray[i] = (it->second)[i] ;
189  lut.setLut(lutArray) ;
190  prod->setValue(it->first,lut) ;
191  }
192  return prod;
193 }
194 
195 std::auto_ptr<EcalTPGWeightIdMap> EcalTrigPrimESProducer::produceWeight(const EcalTPGWeightIdMapRcd & iRecord)
196 {
197  std::auto_ptr<EcalTPGWeightIdMap> prod(new EcalTPGWeightIdMap());
198  parseTextFile() ;
200  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
201  for (it = mapWeight_.begin() ; it != mapWeight_.end() ; it++) {
202  weights.setValues((it->second)[0],
203  (it->second)[1],
204  (it->second)[2],
205  (it->second)[3],
206  (it->second)[4]) ;
207  prod->setValue(it->first,weights) ;
208  }
209  return prod;
210 }
211 
212 std::auto_ptr<EcalTPGWeightGroup> EcalTrigPrimESProducer::produceWeightGroup(const EcalTPGWeightGroupRcd & iRecord)
213 {
214  std::auto_ptr<EcalTPGWeightGroup> prod(new EcalTPGWeightGroup());
215  parseTextFile() ;
216  for (int subdet=0 ; subdet<2 ; subdet++) {
217  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
218  for (it = mapStrip_[subdet].begin() ; it != mapStrip_[subdet].end() ; it++) {
219  prod->setValue(it->first,(it->second)[1]) ;
220  }
221  }
222  return prod;
223 }
224 
225 std::auto_ptr<EcalTPGLutGroup> EcalTrigPrimESProducer::produceLutGroup(const EcalTPGLutGroupRcd & iRecord)
226 {
227  std::auto_ptr<EcalTPGLutGroup> prod(new EcalTPGLutGroup());
228  parseTextFile() ;
229  for (int subdet=0 ; subdet<2 ; subdet++) {
230  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
231  for (it = mapTower_[subdet].begin() ; it != mapTower_[subdet].end() ; it++) {
232  prod->setValue(it->first,(it->second)[0]) ;
233  }
234  }
235  return prod;
236 }
237 
238 std::auto_ptr<EcalTPGFineGrainEBGroup> EcalTrigPrimESProducer::produceFineGrainEBGroup(const EcalTPGFineGrainEBGroupRcd & iRecord)
239 {
240  std::auto_ptr<EcalTPGFineGrainEBGroup> prod(new EcalTPGFineGrainEBGroup());
241  parseTextFile() ;
242  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
243  for (it = mapTower_[0].begin() ; it != mapTower_[0].end() ; it++) {
244  prod->setValue(it->first,(it->second)[1]) ;
245  }
246  return prod;
247 }
248 
249 std::auto_ptr<EcalTPGPhysicsConst> EcalTrigPrimESProducer::producePhysicsConst(const EcalTPGPhysicsConstRcd & iRecord)
250 {
251  std::auto_ptr<EcalTPGPhysicsConst> prod(new EcalTPGPhysicsConst());
252  parseTextFile() ;
253  std::map<uint32_t, std::vector<float> >::const_iterator it ;
254  for (it = mapPhys_.begin() ; it != mapPhys_.end() ; it++) {
256  item.EtSat = (it->second)[0] ;
257  item.ttf_threshold_Low = (it->second)[1] ;
258  item.ttf_threshold_High = (it->second)[2] ;
259  item.FG_lowThreshold = (it->second)[3] ;
260  item.FG_highThreshold = (it->second)[4] ;
261  item.FG_lowRatio = (it->second)[5] ;
262  item.FG_highRatio = (it->second)[6] ;
263  prod->setValue(it->first,item) ;
264  }
265  return prod;
266 }
267 
268 std::auto_ptr<EcalTPGCrystalStatus> EcalTrigPrimESProducer::produceBadX(const EcalTPGCrystalStatusRcd & iRecord)
269 {
270  std::auto_ptr<EcalTPGCrystalStatus> prod(new EcalTPGCrystalStatus());
271  parseTextFile() ;
272  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
273  for (it = mapXtal_.begin() ; it != mapXtal_.end() ; it++) {
274 
275  EcalTPGCrystalStatusCode badXValue;
276  badXValue.setStatusCode(0);
277  prod->setValue(it->first,badXValue) ;
278  }
279  return prod;
280 
281 }
282 
283 std::auto_ptr<EcalTPGTowerStatus> EcalTrigPrimESProducer::produceBadTT(const EcalTPGTowerStatusRcd & iRecord)
284 {
285  std::auto_ptr<EcalTPGTowerStatus> prod(new EcalTPGTowerStatus());
286  parseTextFile() ;
287  std::map<uint32_t, std::vector<uint32_t> >::const_iterator it ;
288  //Barrel
289  for (it = mapTower_[0].begin() ; it != mapTower_[0].end() ; it++) {
290  //set the BadTT status to 0
291  prod->setValue(it->first,0) ;
292  }
293  //Endcap
294  for (it = mapTower_[1].begin() ; it != mapTower_[1].end() ; it++) {
295  //set the BadTT status to 0
296  prod->setValue(it->first,0) ;
297  }
298 
299  return prod;
300 }
301 
303 {
304  if (mapXtal_.size() != 0) return ; // just parse the file once!
305 
306  uint32_t id ;
307  std::string dataCard ;
308  std::string line;
309  std::ifstream infile ;
310  std::vector<unsigned int> param ;
311  std::vector<float> paramF ;
312  int NBstripparams[2] = {2, 4} ;
313  unsigned int data ;
314  float dataF ;
315 
316  std::string bufString;
317  std::string iString;
318  std::string fString;
319  std::string filename = "SimCalorimetry/EcalTrigPrimProducers/data/"+dbFilename_;
320  std::string finalFileName ;
321  size_t slash=dbFilename_.find("/");
322  if (slash!=0) {
323  edm::FileInPath fileInPath(filename);
324  finalFileName = fileInPath.fullPath() ;
325  }
326  else {
327  finalFileName = dbFilename_.c_str() ;
328  edm::LogWarning("EcalTPG") <<"Couldnt find database file via fileinpath, trying with pathname directly!!";
329  }
330 
331 
332  GzInputStream gis(finalFileName.c_str()) ;
333  while (gis>>dataCard) {
334 
335  if (dataCard == "PHYSICS_EB" || dataCard == "PHYSICS_EE") {
336  gis>>std::dec>>id ;
337  //std::cout<<dataCard<<" "<<std::dec<<id ;
338  paramF.clear() ;
339  for (int i=0 ; i <7 ; i++) {
340  gis>>std::dec>>dataF ;
341  paramF.push_back(dataF) ;
342  //std::cout<<", "<<std::dec<<dataF ;
343  }
344  //std::cout<<std::endl ;
345  mapPhys_[id] = paramF ;
346  }
347 
348  if (dataCard == "CRYSTAL") {
349  gis>>std::dec>>id ;
350  //std::cout<<dataCard<<" "<<std::dec<<id ;
351  param.clear() ;
352  for (int i=0 ; i <9 ; i++) {
353  gis>>std::hex>>data ;
354  //std::cout<<", "<<std::hex<<data ;
355  param.push_back(data) ;
356  }
357  //std::cout<<std::endl ;
358  mapXtal_[id] = param ;
359  }
360 
361  if (dataCard == "STRIP_EB") {
362  gis>>std::dec>>id ;
363  //std::cout<<dataCard<<" "<<std::dec<<id ;
364  param.clear() ;
365  for (int i=0 ; i <NBstripparams[0] ; i++) {
366  gis>>std::hex>>data ;
367  //std::cout<<", "<<std::hex<<data ;
368  param.push_back(data) ;
369  }
370  //std::cout<<std::endl ;
371  mapStrip_[0][id] = param ;
372  }
373 
374  if (dataCard == "STRIP_EE") {
375  gis>>std::dec>>id ;
376  //std::cout<<dataCard<<" "<<std::dec<<id ;
377  param.clear() ;
378  for (int i=0 ; i <NBstripparams[1] ; i++) {
379  gis>>std::hex>>data ;
380  //std::cout<<", "<<std::hex<<data ;
381  param.push_back(data) ;
382  }
383  //std::cout<<std::endl ;
384  mapStrip_[1][id] = param ;
385  }
386 
387  if (dataCard == "TOWER_EB" || dataCard == "TOWER_EE") {
388  gis>>std::dec>>id ;
389  //std::cout<<dataCard<<" "<<std::dec<<id ;
390  param.clear() ;
391  for (int i=0 ; i <2 ; i++) {
392  gis>>std::hex>>data ;
393  //std::cout<<", "<<std::hex<<data ;
394  param.push_back(data) ;
395  }
396  //std::cout<<std::endl ;
397  if (dataCard == "TOWER_EB") mapTower_[0][id] = param ;
398  if (dataCard == "TOWER_EE") mapTower_[1][id] = param ;
399  }
400 
401  if (dataCard == "WEIGHT") {
402  gis>>std::hex>>id ;
403  //std::cout<<dataCard<<" "<<std::dec<<id ;
404  param.clear() ;
405  for (int i=0 ; i <5 ; i++) {
406  gis>>std::hex>>data ;
407  //std::cout<<", "<<std::hex<<data ;
408  param.push_back(data) ;
409  }
410  //std::cout<<std::endl ;
411  mapWeight_[id] = param ;
412  }
413 
414  if (dataCard == "FG") {
415  gis>>std::hex>>id ;
416  //std::cout<<dataCard<<" "<<std::dec<<id ;
417  param.clear() ;
418  for (int i=0 ; i <5 ; i++) {
419  gis>>std::hex>>data ;
420  //std::cout<<", "<<std::hex<<data ;
421  param.push_back(data) ;
422  }
423  //std::cout<<std::endl ;
424  mapFg_[id] = param ;
425  }
426 
427  if (dataCard == "LUT") {
428  gis>>std::hex>>id ;
429  //std::cout<<dataCard<<" "<<std::dec<<id ;
430  param.clear() ;
431  for (int i=0 ; i <1024 ; i++) {
432  gis>>std::hex>>data ;
433  //std::cout<<", "<<std::hex<<data ;
434  param.push_back(data) ;
435  }
436  //std::cout<<std::endl ;
437  mapLut_[id] = param ;
438  }
439  }
440 }
441 
442 std::vector<int> EcalTrigPrimESProducer::getRange(int subdet, int tccNb, int towerNbInTcc, int stripNbInTower, int xtalNbInStrip)
443 {
444  std::vector<int> range ;
445  if (subdet == 0) {
446  // Barrel
447  range.push_back(37) ; // stccNbMin
448  range.push_back(73) ; // tccNbMax
449  range.push_back(1) ; // towerNbMin
450  range.push_back(69) ; // towerNbMax
451  range.push_back(1) ; // stripNbMin
452  range.push_back(6) ; // stripNbMax
453  range.push_back(1) ; // xtalNbMin
454  range.push_back(6) ; // xtalNbMax
455  } else {
456  // Endcap eta >0
457  if (subdet >0 ) {
458  range.push_back(73) ; // tccNbMin
459  range.push_back(109) ; // tccNbMax
460  } else { //endcap eta <0
461  range.push_back(1) ; // tccNbMin
462  range.push_back(37) ; // tccNbMax
463  }
464  range.push_back(1) ; // towerNbMin
465  range.push_back(29) ; // towerNbMax
466  range.push_back(1) ; // stripNbMin
467  range.push_back(6) ; // stripNbMax
468  range.push_back(1) ; // xtalNbMin
469  range.push_back(6) ; // xtalNbMax
470  }
471 
472  if (tccNb>0) {
473  range[0] = tccNb ;
474  range[1] = tccNb+1 ;
475  }
476  if (towerNbInTcc>0) {
477  range[2] = towerNbInTcc ;
478  range[3] = towerNbInTcc+1 ;
479  }
480  if (stripNbInTower>0) {
481  range[4] = stripNbInTower ;
482  range[5] = stripNbInTower+1 ;
483  }
484  if (xtalNbInStrip>0) {
485  range[6] = xtalNbInStrip ;
486  range[7] = xtalNbInStrip+1 ;
487  }
488 
489  return range ;
490 }
491 
492 // bool EcalTrigPrimESProducer::getNextString(gzFile &gzf){
493 // size_t blank;
494 // if (bufpos_==0) {
495 // gzgets(gzf,buf_,80);
496 // if (gzeof(gzf)) return true;
497 // bufString_=std::string(buf_);
498 // }
499 // int pos=0;
500 // pos =bufpos_;
501 // // look for next non-blank
502 // while (pos<bufString_.size()) {
503 // if (!bufString_.compare(pos,1," ")) pos++;
504 // else break;
505 // }
506 // blank=bufString_.find(" ",pos);
507 // size_t end = blank;
508 // if (blank==std::string::npos) end=bufString_.size();
509 // sub_=bufString_.substr(pos,end-pos);
510 // bufpos_= blank;
511 // if (blank==std::string::npos) bufpos_=0;
512 // return false;
513 // }
514 //
515 // int EcalTrigPrimESProducer::converthex() {
516 // // converts hex dec string sub to hexa
517 // //FIXME:: find something better (istrstream?)!!!!
518 //
519 // std::string chars("0123456789abcdef");
520 // int hex=0;
521 // for (size_t i=2;i<sub_.length();++i) {
522 // size_t f=chars.find(sub_[i]);
523 // if (f==std::string::npos) break; //FIXME: length is 4 for 0x3!!
524 // hex=hex*16+chars.find(sub_[i]);
525 // }
526 // return hex;
527 // }
int i
Definition: DBlmapReader.cc:9
std::vector< int > getRange(int subdet, int smNb, int towerNbInSm, int stripNbInTower=0, int xtalNbInStrip=0)
std::auto_ptr< EcalTPGLutGroup > produceLutGroup(const EcalTPGLutGroupRcd &)
list file
Definition: dbtoweb.py:253
void setValues(const uint32_t &ThresholdETLow, const uint32_t &ThresholdETHigh, const uint32_t &RatioLow, const uint32_t &RatioHigh, const uint32_t &LUT)
std::auto_ptr< EcalTPGTowerStatus > produceBadTT(const EcalTPGTowerStatusRcd &)
std::map< uint32_t, std::vector< uint32_t > > mapTower_[2]
void setLut(const unsigned int *lut)
Definition: EcalTPGLut.cc:20
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
void setStatusCode(const uint16_t &val)
std::map< uint32_t, std::vector< uint32_t > > mapXtal_
std::auto_ptr< EcalTPGFineGrainTowerEE > produceFineGrainEEtower(const EcalTPGFineGrainTowerEERcd &)
std::auto_ptr< EcalTPGCrystalStatus > produceBadX(const EcalTPGCrystalStatusRcd &)
EcalTPGCrystalStatusMap EcalTPGCrystalStatus
std::auto_ptr< EcalTPGFineGrainStripEE > produceFineGrainEEstrip(const EcalTPGFineGrainStripEERcd &)
tuple prod
Definition: CrabTask.py:87
std::map< uint32_t, std::vector< uint32_t > > mapWeight_
std::auto_ptr< EcalTPGFineGrainEBIdMap > produceFineGrainEB(const EcalTPGFineGrainEBIdMapRcd &)
std::auto_ptr< EcalTPGSlidingWindow > produceSlidingWindow(const EcalTPGSlidingWindowRcd &)
std::auto_ptr< EcalTPGPedestals > producePedestals(const EcalTPGPedestalsRcd &)
EcalTrigPrimESProducer(const edm::ParameterSet &)
std::auto_ptr< EcalTPGLinearizationConst > produceLinearizationConst(const EcalTPGLinearizationConstRcd &)
std::map< uint32_t, std::vector< uint32_t > > mapFg_
GzInputStream(const char *file)
std::auto_ptr< EcalTPGLutIdMap > produceLUT(const EcalTPGLutIdMapRcd &)
std::istream & operator>>(std::istream &input, CLHEP::HepGenMatrix &matrix)
Definition: matrixSaver.cc:111
std::map< uint32_t, std::vector< float > > mapPhys_
#define begin
Definition: vmac.h:31
std::auto_ptr< EcalTPGWeightGroup > produceWeightGroup(const EcalTPGWeightGroupRcd &)
list infile
Definition: EdgesToViz.py:90
tuple filename
Definition: lut2db_cfg.py:20
std::string fullPath() const
Definition: FileInPath.cc:170
void setValues(const uint32_t &w0, const uint32_t &w1, const uint32_t &w2, const uint32_t &w3, const uint32_t &w4)
std::map< uint32_t, std::vector< uint32_t > > mapLut_
EcalTPGPedestalsMap EcalTPGPedestals
std::auto_ptr< EcalTPGPhysicsConst > producePhysicsConst(const EcalTPGPhysicsConstRcd &)
std::auto_ptr< EcalTPGFineGrainEBGroup > produceFineGrainEBGroup(const EcalTPGFineGrainEBGroupRcd &)
std::auto_ptr< EcalTPGWeightIdMap > produceWeight(const EcalTPGWeightIdMapRcd &)
std::map< uint32_t, std::vector< uint32_t > > mapStrip_[2]
std::istringstream iss
EcalTPGLinearizationConstMap EcalTPGLinearizationConst