CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalLutManager.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <sstream>
3 #include <sys/time.h>
4 #include <stdlib.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <unistd.h>
8 
9 #include <cstdlib> // For srand() and rand()
10 
11 #ifdef HAVE_XDAQ
12 #include <toolbox/string.h>
13 #else
14 #include "CaloOnlineTools/HcalOnlineDb/interface/xdaq_compat.h" // Replaces toolbox::toString
15 #endif
16 
18 
28 
30 
31 using namespace std;
32 using namespace oracle::occi;
33 using namespace hcal;
34 
44 {
45  init();
46 }
47 
48 
49 HcalLutManager::HcalLutManager(std::vector<HcalGenericDetId> & map)
50 {
51  init();
52  _iter . init(map);
53 }
54 
55 
57  const HcalChannelQuality * _cq,
58  uint32_t _status_word_to_mask)
59 {
60  init();
61  emap = _emap;
62  cq = _cq;
63  status_word_to_mask = _status_word_to_mask;
64 }
65 
66 
68 {
69  lut_xml = 0;
70  lut_checksums_xml = 0;
71  db = 0;
72  lmap = 0;
73  emap = 0;
74  cq = 0;
75  status_word_to_mask = 0x0000;
76 }
77 
78 
79 
81 {
82  delete lut_xml;
83  delete lut_checksums_xml;
84  delete db;
85  delete lmap;
86 }
87 
88 
89 int HcalLutManager::initChannelIterator(std::vector<HcalGenericDetId> & map)
90 {
91  _iter . init(map);
92  return _iter.size();
93 }
94 
95 
96 std::string & HcalLutManager::getLutXml( std::vector<unsigned int> & _lut )
97 {
98 
99  if (lut_xml) delete lut_xml;
100 
101  lut_xml = new LutXml();
102 
103  LutXml::Config _config;
104  _config.lut = _lut;
105  lut_xml -> addLut( _config );
106  lut_xml -> addLut( _config );
107  lut_xml -> addLut( _config );
108 
109  //return lut_xml->getString();
110  return lut_xml->getCurrentBrick();
111 
112 }
113 
114 
116 {
117  int result;
118  sscanf(number.c_str(), "%d", &result);
119  return result;
120 }
121 
123 {
125  if ( _det.find("HB") != std::string::npos ) result = HcalBarrel;
126  else if ( _det.find("HE") != std::string::npos ) result = HcalEndcap;
127  else if ( _det.find("HF") != std::string::npos ) result = HcalForward;
128  else if ( _det.find("HO") != std::string::npos ) result = HcalOuter;
129  else result = HcalOther;
130 
131  return result;
132 }
133 
134 
136 {
137  HcalLutManager _manager;
138  HcalLutSet _set = _manager . getLutSetFromFile( _filename );
139  std::cout << "===> Test of HcalLutSet HcalLutManager::getLutSetFromFile( std::string _filename )" << std::endl << std::endl;
140  std::cout << _set . label << std::endl;
141  for (unsigned int i = 0; i != _set.subdet.size(); i++) std::cout << _set.subdet[i] << " ";
142  std::cout << std::endl;
143  for (unsigned int i = 0; i != _set.eta_min.size(); i++) std::cout << _set.eta_min[i] << " ";
144  std::cout << std::endl;
145  for (unsigned int i = 0; i != _set.eta_max.size(); i++) std::cout << _set.eta_max[i] << " ";
146  std::cout << std::endl;
147  for (unsigned int i = 0; i != _set.phi_min.size(); i++) std::cout << _set.phi_min[i] << " ";
148  std::cout << std::endl;
149  for (unsigned int i = 0; i != _set.phi_max.size(); i++) std::cout << _set.phi_max[i] << " ";
150  std::cout << std::endl;
151  for (unsigned int i = 0; i != _set.depth_min.size(); i++) std::cout << _set.depth_min[i] << " ";
152  std::cout << std::endl;
153  for (unsigned int i = 0; i != _set.depth_max.size(); i++) std::cout << _set.depth_max[i] << " ";
154  std::cout << std::endl;
155  for (unsigned int j = 0; j != _set.lut[0].size(); j++){
156  for (unsigned int i = 0; i != _set.lut.size(); i++){
157  std::cout << _set.lut[i][j] << " ";
158  }
159  std::cout << "---> " << j << std::endl;
160  }
161  return 0;
162 }
163 
164 
166 {
167  HcalLutSet _lutset;
168 
169  ifstream infile( _filename . c_str() );
170  std::string buf;
171 
172  if ( infile . is_open() ){
173  std::cout << "File " << _filename << " is open..." << std::endl;
174  std::cout << "Reading LUTs and their eta/phi/depth/subdet ranges...";
175 
176  // get label
177  getline( infile, _lutset . label );
178 
179  if ( _type == 1 ){ // for linearization LUTs get subdetectors (default)
180  //get subdetectors
181  getline( infile, buf );
182  _lutset . subdet = HcalQIEManager::splitString( buf );
183  }
184 
185  //get min etas
186  std::vector<std::string> buf_vec;
187  getline( infile, buf );
188  buf_vec = HcalQIEManager::splitString( buf );
189  for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
190  _lutset.eta_min.push_back(HcalLutManager::getInt(*iter));
191  }
192 
193  //get max etas
194  getline( infile, buf );
195  buf_vec = HcalQIEManager::splitString( buf );
196  for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
197  _lutset.eta_max.push_back(HcalLutManager::getInt(*iter));
198  }
199 
200  //get min phis
201  getline( infile, buf );
202  buf_vec = HcalQIEManager::splitString( buf );
203  for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
204  _lutset.phi_min.push_back(HcalLutManager::getInt(*iter));
205  }
206 
207  //get max phis
208  getline( infile, buf );
209  buf_vec = HcalQIEManager::splitString( buf );
210  for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
211  _lutset.phi_max.push_back(HcalLutManager::getInt(*iter));
212  }
213 
214  if ( _type == 1 ){ // for linearization LUTs get depth range (default)
215  //get min depths
216  getline( infile, buf );
217  buf_vec = HcalQIEManager::splitString( buf );
218  for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
219  _lutset.depth_min.push_back(HcalLutManager::getInt(*iter));
220  }
221 
222  //get max depths
223  getline( infile, buf );
224  buf_vec = HcalQIEManager::splitString( buf );
225  for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
226  _lutset.depth_max.push_back(HcalLutManager::getInt(*iter));
227  }
228  }
229 
230  bool first_lut_entry = true;
231  while ( getline( infile, buf ) > 0 ){
232  buf_vec = HcalQIEManager::splitString( buf );
233  for (unsigned int i = 0; i < buf_vec.size(); i++){
234  if (first_lut_entry){
235  std::vector<unsigned int> _l;
236  _lutset.lut.push_back(_l);
237  }
238  _lutset . lut[i] . push_back(HcalLutManager::getInt(buf_vec[i]));
239  }
240  first_lut_entry = false;
241  }
242  }
243 
244  std::cout << "done." << std::endl;
245 
246  return _lutset;
247 }
248 
249 
250 
251 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getLutXmlFromAsciiMaster( std::string _filename, std::string _tag, int _crate, bool split_by_crate )
252 {
253  std::cout << "Generating linearization (input) LUTs from ascii master file..." << std::endl;
254  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
255 
256  LMap _lmap;
257  _lmap . read( "./backup/HCALmapHBEF.txt", "HBEF" );
258  _lmap . read( "./backup/HCALmapHO.txt", "HO" );
259  std::map<int,LMapRow> & _map = _lmap.get_map();
260  std::cout << "LMap contains " << _map . size() << " channels" << std::endl;
261 
262  // read LUTs and their eta/phi/depth/subdet ranges
263  HcalLutSet _set = getLutSetFromFile( _filename );
264  int lut_set_size = _set.lut.size(); // number of different luts
265 
266  RooGKCounter _counter;
267  //loop over all HCAL channels
268  for( std::map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
269  LutXml::Config _cfg;
270 
271  // search for the correct LUT for a given channel,
272  // higher LUT numbers have priority in case of overlapping
273  int lut_index=-1;
274  for ( int i=0; i<lut_set_size; i++ ){
275  if ( (row->second.crate == _crate || _crate == -1) && // -1 stands for all crates
276  _set.eta_min[i] <= row->second.side*row->second.eta &&
277  _set.eta_max[i] >= row->second.side*row->second.eta &&
278  _set.phi_min[i] <= row->second.phi &&
279  _set.phi_max[i] >= row->second.phi &&
280  _set.depth_min[i] <= row->second.depth &&
281  _set.depth_max[i] >= row->second.depth &&
282  get_subdetector(_set.subdet[i]) == row->second.det ){
283  lut_index=i;
284  }
285  }
286  if ( lut_index >= 0 ){
287  if ( _xml.count(row->second.crate) == 0 && split_by_crate ){
288  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(row->second.crate,boost::shared_ptr<LutXml>(new LutXml())) );
289  }
290  else if ( _xml.count(0) == 0 && !split_by_crate ){
291  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
292  }
293  _cfg.ieta = row->second.side*row->second.eta;
294  _cfg.iphi = row->second.phi;
295  _cfg.depth = row->second.depth;
296  _cfg.crate = row->second.crate;
297  _cfg.slot = row->second.htr;
298  if (row->second.fpga . find("top") != std::string::npos) _cfg.topbottom = 1;
299  else if (row->second.fpga . find("bot") != std::string::npos) _cfg.topbottom = 0;
300  else std::cout << "Warning! fpga out of range..." << std::endl;
301  // FIXME: probably fixed. fiber==htr_fi, not rm_fi in LMAP notation.
302  //_cfg.fiber = row->second.rm_fi;
303  _cfg.fiber = row->second.htr_fi;
304  _cfg.fiberchan = row->second.fi_ch;
305  if (_set.lut[lut_index].size() == 128) _cfg.lut_type = 1;
306  else _cfg.lut_type = 2;
307  _cfg.creationtag = _tag;
308  _cfg.creationstamp = get_time_stamp( time(0) );
309  _cfg.targetfirmware = "1.0.0";
310  _cfg.formatrevision = "1"; //???
311  // "original" definition of GENERALIZEDINDEX from Mike Weinberger
312  // int generalizedIndex=id.ietaAbs()+1000*id.depth()+10000*id.iphi()+
313  // ((id.ieta()<0)?(0):(100))+((id.subdet()==HcalForward && id.ietaAbs()==29)?(4*10000):(0));
314  _cfg.generalizedindex =
315  _cfg.iphi*10000 + _cfg.depth*1000 +
316  (row->second.side>0)*100 + row->second.eta +
317  ((row->second.det==HcalForward && row->second.eta==29)?(4*10000):(0));
318  _cfg.lut = _set.lut[lut_index];
319  if (split_by_crate ){
320  _xml[row->second.crate]->addLut( _cfg, lut_checksums_xml );
321  _counter.count();
322  }
323  else{
324  _xml[0]->addLut( _cfg, lut_checksums_xml );
325  _counter.count();
326  }
327  }
328  }
329  std::cout << "LUTs generated: " << _counter.getCount() << std::endl;
330  std::cout << "Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
331  return _xml;
332 }
333 
334 //
335 //_____ get HO from ASCII master here ___________________________________
336 //
337 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getLinearizationLutXmlFromAsciiMasterEmap( std::string _filename, std::string _tag, int _crate, bool split_by_crate )
338 {
339  std::cout << "Generating linearization (input) LUTs from ascii master file..." << std::endl;
340  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
341 
342  EMap _emap(emap);
343  std::vector<EMap::EMapRow> & _map = _emap.get_map();
344  std::cout << "EMap contains " << _map . size() << " entries" << std::endl;
345 
346  // read LUTs and their eta/phi/depth/subdet ranges
347  HcalLutSet _set = getLutSetFromFile( _filename );
348  int lut_set_size = _set.lut.size(); // number of different luts
349  std::cout << " ==> " << lut_set_size << " sets of different LUTs read from the master file" << std::endl;
350 
351  // setup "zero" LUT for channel masking
352  std::vector<unsigned int> zeroLut;
353  for (size_t adc = 0; adc < 128; adc++) zeroLut.push_back(0);
354 
355  RooGKCounter _counter;
356  //loop over all EMap channels
357  for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
358  if( (row->subdet.find("HB")!=string::npos ||
359  row->subdet.find("HE")!=string::npos ||
360  row->subdet.find("HO")!=string::npos ||
361  row->subdet.find("HF")!=string::npos ) &&
362  row->subdet.size()==2
363  ){
364  LutXml::Config _cfg;
365 
366  // search for the correct LUT for a given channel,
367  // higher LUT numbers have priority in case of overlapping
368  int lut_index=-1;
369  for ( int i=0; i<lut_set_size; i++ ){
370  if ( (row->crate == _crate || _crate == -1) && // -1 stands for all crates
371  _set.eta_min[i] <= row->ieta &&
372  _set.eta_max[i] >= row->ieta &&
373  _set.phi_min[i] <= row->iphi &&
374  _set.phi_max[i] >= row->iphi &&
375  _set.depth_min[i] <= row->idepth &&
376  _set.depth_max[i] >= row->idepth &&
377  _set.subdet[i].find(row->subdet)!=string::npos ){
378  lut_index=i;
379  }
380  }
381  if ( lut_index >= 0 ){
382  if ( _xml.count(row->crate) == 0 && split_by_crate ){
383  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(new LutXml())) );
384  }
385  else if ( _xml.count(0) == 0 && !split_by_crate ){
386  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
387  }
388  _cfg.ieta = row->ieta;
389  _cfg.iphi = row->iphi;
390  _cfg.depth = row->idepth;
391  _cfg.crate = row->crate;
392  _cfg.slot = row->slot;
393  if (row->topbottom . find("t") != std::string::npos) _cfg.topbottom = 1;
394  else if (row->topbottom . find("b") != std::string::npos) _cfg.topbottom = 0;
395  else std::cout << "Warning! fpga out of range..." << std::endl;
396  _cfg.fiber = row->fiber;
397  _cfg.fiberchan = row->fiberchan;
398  _cfg.lut_type = 1;
399  _cfg.creationtag = _tag;
400  _cfg.creationstamp = get_time_stamp( time(0) );
401  _cfg.targetfirmware = "1.0.0";
402  _cfg.formatrevision = "1"; //???
403  // "original" definition of GENERALIZEDINDEX from Mike Weinberger
404  // int generalizedIndex=id.ietaAbs()+1000*id.depth()+10000*id.iphi()+
405  // ((id.ieta()<0)?(0):(100))+((id.subdet()==HcalForward && id.ietaAbs()==29)?(4*10000):(0));
406  _cfg.generalizedindex =
407  _cfg.iphi*10000 + _cfg.depth*1000 +
408  (row->ieta>0)*100 + abs(row->ieta) +
409  (((row->subdet.find("HF")!=string::npos) && abs(row->ieta)==29)?(4*10000):(0));
410  //
411  // consider channel status here
412  DetId _detId(row->rawId);
413  uint32_t status_word = cq->getValues(_detId)->getValue();
414  if ((status_word & status_word_to_mask) > 0){
415  _cfg.lut = zeroLut;
416  }
417  else{
418  _cfg.lut = _set.lut[lut_index];
419  }
420  if (split_by_crate ){
421  _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
422  _counter.count();
423  }
424  else{
425  _xml[0]->addLut( _cfg, lut_checksums_xml );
426  _counter.count();
427  }
428  }
429  }
430  }
431  std::cout << "LUTs generated: " << _counter.getCount() << std::endl;
432  std::cout << "Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
433  return _xml;
434 }
435 
436 
437 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getLinearizationLutXmlFromAsciiMasterEmap_new( std::string _filename, std::string _tag, int _crate, bool split_by_crate )
438 {
439  std::cout << "Generating linearization (input) LUTs from ascii master file..." << std::endl;
440  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
441 
442  // read LUTs and their eta/phi/depth/subdet ranges
443  HcalLutSet _set = getLutSetFromFile( _filename );
444  int lut_set_size = _set.lut.size(); // number of different luts
445  std::cout << " ==> " << lut_set_size << " sets of different LUTs read from the master file" << std::endl;
446 
447  RooGKCounter _counter;
448  //loop over all EMap channels
449  for( _iter.begin(); !_iter.end(); _iter.next() ){
450  HcalSubdetector _subdet = _iter.getHcalSubdetector();
451  if( (_subdet == HcalBarrel ||
452  _subdet == HcalEndcap ||
453  _subdet == HcalForward ||
454  _subdet == HcalOuter )
455  ){
456  int _ieta = _iter.getIeta();
457  int _iphi = _iter.getIphi();
458  int _depth = _iter.getDepth();
459 
460  // FIXME: this is probably wrong, raw ids are different
461  HcalElectronicsId _eId(_iter.getHcalGenericDetId().rawId());
462  int aCrate = _eId . readoutVMECrateId();
463  int aSlot = _eId . htrSlot();
464  int aTopBottom = _eId . htrTopBottom();
465  int aFiber = _eId . fiberIndex();
466  int aFiberChan = _eId . fiberChanId();
467 
468  LutXml::Config _cfg;
469 
470  // search for the correct LUT for a given channel,
471  // higher LUT numbers have priority in case of overlapping
472  int lut_index=-1;
473  for ( int i=0; i<lut_set_size; i++ ){
474  if ( (aCrate == _crate || _crate == -1) && // -1 stands for all crates
475  _set.eta_min[i] <= _ieta &&
476  _set.eta_max[i] >= _ieta &&
477  _set.phi_min[i] <= _iphi &&
478  _set.phi_max[i] >= _iphi &&
479  _set.depth_min[i] <= _depth &&
480  _set.depth_max[i] >= _depth &&
481  _set.subdet[i].find(_ass.getSubdetectorString(_subdet))!=string::npos ){
482  lut_index=i;
483  }
484  }
485  if ( lut_index >= 0 ){
486  if ( _xml.count(aCrate) == 0 && split_by_crate ){
487  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(aCrate,boost::shared_ptr<LutXml>(new LutXml())) );
488  }
489  else if ( _xml.count(0) == 0 && !split_by_crate ){
490  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
491  }
492  _cfg.ieta = _ieta;
493  _cfg.iphi = _iphi;
494  _cfg.depth = _depth;
495  _cfg.crate = aCrate;
496  _cfg.slot = aSlot;
497  _cfg.topbottom = aTopBottom;
498  _cfg.fiber = aFiber;
499  _cfg.fiberchan = aFiberChan;
500  _cfg.lut_type = 1;
501  _cfg.creationtag = _tag;
502  _cfg.creationstamp = get_time_stamp( time(0) );
503  _cfg.targetfirmware = "1.0.0";
504  _cfg.formatrevision = "1"; //???
505  // "original" definition of GENERALIZEDINDEX from Mike Weinberger
506  // int generalizedIndex=id.ietaAbs()+1000*id.depth()+10000*id.iphi()+
507  // ((id.ieta()<0)?(0):(100))+((id.subdet()==HcalForward && id.ietaAbs()==29)?(4*10000):(0));
508  _cfg.generalizedindex =
509  _cfg.iphi*10000 + _cfg.depth*1000 +
510  (_ieta>0)*100 + abs(_ieta) +
511  (((_subdet==HcalForward) && abs(_ieta)==29)?(4*10000):(0));
512  _cfg.lut = _set.lut[lut_index];
513  if (split_by_crate ){
514  _xml[aCrate]->addLut( _cfg, lut_checksums_xml );
515  _counter.count();
516  }
517  else{
518  _xml[0]->addLut( _cfg, lut_checksums_xml );
519  _counter.count();
520  }
521  }
522  }
523  }
524  std::cout << "LUTs generated: " << _counter.getCount() << std::endl;
525  std::cout << "Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
526  return _xml;
527 }
528 
529 
530 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getCompressionLutXmlFromAsciiMaster( std::string _filename, std::string _tag, int _crate, bool split_by_crate )
531 {
532  std::cout << "Generating compression (output) LUTs from ascii master file..." << std::endl;
533  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
534 
535  std::cout << "instantiating CaloTPGTranscoderULUT in order to check the validity of (ieta,iphi)..." << std::endl;
536  CaloTPGTranscoderULUT _coder;
537 
538  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.03_080817.txt");
539  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.04_080905.txt");
540  EMap _emap(emap);
541  std::vector<EMap::EMapRow> & _map = _emap.get_map();
542  std::cout << "EMap contains " << _map . size() << " channels" << std::endl;
543 
544  // read LUTs and their eta/phi/depth/subdet ranges
545  HcalLutSet _set = getLutSetFromFile( _filename, 2 );
546  int lut_set_size = _set.lut.size(); // number of different luts
547  std::cout << " ==> " << lut_set_size << " sets of different LUTs read from the master file" << std::endl;
548 
549  //loop over all EMap channels
550  RooGKCounter _counter;
551  for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
552  LutXml::Config _cfg;
553 
554  // search for the correct LUT for a given channel,
555  // higher LUT numbers have priority in case of overlapping
556  int lut_index=-1;
557  for ( int i=0; i<lut_set_size; i++ ){
558  if ( row->subdet . find("HT") != std::string::npos &&
559  (row->crate == _crate || _crate == -1) && // -1 stands for all crates
560  _set.eta_min[i] <= row->ieta &&
561  _set.eta_max[i] >= row->ieta &&
562  _set.phi_min[i] <= row->iphi &&
563  _set.phi_max[i] >= row->iphi &&
564  _coder.HTvalid(row->ieta, row->iphi) ){
565  lut_index=i;
566  }
567  }
568  if ( lut_index >= 0 ){
569  if ( _xml.count(row->crate) == 0 && split_by_crate ){
570  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(new LutXml())) );
571  }
572  else if ( _xml.count(0) == 0 && !split_by_crate ){
573  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
574  }
575  _cfg.ieta = row->ieta;
576  _cfg.iphi = row->iphi;
577  _cfg.depth = row->idepth;
578  _cfg.crate = row->crate;
579  _cfg.slot = row->slot;
580  if (row->topbottom . find("t") != std::string::npos) _cfg.topbottom = 1;
581  else if (row->topbottom . find("b") != std::string::npos) _cfg.topbottom = 0;
582  else std::cout << "Warning! fpga out of range..." << std::endl;
583  _cfg.fiber = row->fiber;
584  _cfg.fiberchan = row->fiberchan;
585  if (_set.lut[lut_index].size() == 128) _cfg.lut_type = 1;
586  else _cfg.lut_type = 2;
587  _cfg.creationtag = _tag;
588  _cfg.creationstamp = get_time_stamp( time(0) );
589  _cfg.targetfirmware = "1.0.0";
590  _cfg.formatrevision = "1"; //???
591  // "original" definition of GENERALIZEDINDEX from Mike Weinberger
592  // int generalizedIndex=id.ietaAbs()+10000*id.iphi()+
593  // ((id.ieta()<0)?(0):(100));
594  _cfg.generalizedindex =
595  _cfg.iphi*10000+
596  (row->ieta>0)*100+abs(row->ieta);
597  _cfg.lut = _set.lut[lut_index];
598  if (split_by_crate ){
599  _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
600  _counter.count();
601  }
602  else{
603  _xml[0]->addLut( _cfg, lut_checksums_xml );
604  _counter.count();
605  }
606  }
607  }
608  std::cout << "LUTs generated: " << _counter.getCount() << std::endl;
609  std::cout << "Generating compression (output) LUTs from ascii master file...DONE" << std::endl;
610  return _xml;
611 }
612 
613 
614 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getLinearizationLutXmlFromCoder( const HcalTPGCoder & _coder, std::string _tag, bool split_by_crate )
615 {
616  std::cout << "Generating linearization (input) LUTs from HcaluLUTTPGCoder..." << std::endl;
617  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
618 
619  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.03_080817.txt");
620  //std::vector<EMap::EMapRow> & _map = _emap.get_map();
621  //std::cout << "EMap contains " << _map . size() << " entries" << std::endl;
622 
623  LMap _lmap;
624  _lmap . read( "backup/HCALmapHBEF.txt", "HBEF" );
625  // HO is not part of trigger, so TPGCoder cannot generate LUTs for it
626  //_lmap . read( "backup/HCALmapHO.txt", "HO" );
627  std::map<int,LMapRow> & _map = _lmap.get_map();
628  std::cout << "LMap contains " << _map . size() << " channels" << std::endl;
629 
630  // read LUTs and their eta/phi/depth/subdet ranges
631  //HcalLutSet _set = getLinearizationLutSetFromCoder();
632  //int lut_set_size = _set.lut.size(); // number of different luts
633 
634  //loop over all HCAL channels
635  RooGKCounter _counter;
636  for( std::map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
637  LutXml::Config _cfg;
638 
639  if ( _xml.count(row->second.crate) == 0 && split_by_crate ){
640  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(row->second.crate,boost::shared_ptr<LutXml>(new LutXml())) );
641  }
642  else if ( _xml.count(0) == 0 && !split_by_crate ){
643  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
644  }
645  _cfg.ieta = row->second.side*row->second.eta;
646  _cfg.iphi = row->second.phi;
647  _cfg.depth = row->second.depth;
648  _cfg.crate = row->second.crate;
649  _cfg.slot = row->second.htr;
650  if (row->second.fpga . find("top") != std::string::npos) _cfg.topbottom = 1;
651  else if (row->second.fpga . find("bot") != std::string::npos) _cfg.topbottom = 0;
652  else std::cout << "Warning! fpga out of range..." << std::endl;
653  // FIXME: probably fixed. fiber==htr_fi, not rm_fi in LMAP notation.
654  //_cfg.fiber = row->second.rm_fi;
655  _cfg.fiber = row->second.htr_fi;
656  _cfg.fiberchan = row->second.fi_ch;
657  _cfg.lut_type = 1;
658  _cfg.creationtag = _tag;
659  _cfg.creationstamp = get_time_stamp( time(0) );
660  _cfg.targetfirmware = "1.0.0";
661  _cfg.formatrevision = "1"; //???
662  // "original" definition of GENERALIZEDINDEX from Mike Weinberger
663  // int generalizedIndex=id.ietaAbs()+1000*id.depth()+10000*id.iphi()+
664  // ((id.ieta()<0)?(0):(100))+((id.subdet()==HcalForward && id.ietaAbs()==29)?(4*10000):(0));
665  _cfg.generalizedindex =
666  _cfg.iphi*10000 + _cfg.depth*1000 +
667  (row->second.side>0)*100 + row->second.eta +
668  ((row->second.det==HcalForward && row->second.eta==29)?(4*10000):(0));
669 
670  //HcalDetId _detid(row->first);
671  HcalDetId _detid(row->second.det, row->second.side*row->second.eta, row->second.phi, row->second.depth);
672  //std::cout << "### DEBUG: rawid = " << _detid.rawId() << std::endl;
673 
674  //std::cout << "### DEBUG: subdetector = " << row->second.det << std::endl;
675  std::vector<unsigned short> coder_lut = _coder . getLinearizationLUT(_detid);
676  for (std::vector<unsigned short>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
677  unsigned int _temp = (unsigned int)(*_i);
678  //if (_temp!=0) std::cout << "DEBUG non-zero LUT!!!!!!!!!!!!!!!" << (*_i) << " " << _temp << std::endl;
679  //unsigned int _temp = 0;
680  _cfg.lut.push_back(_temp);
681  }
682  if (split_by_crate ){
683  _xml[row->second.crate]->addLut( _cfg, lut_checksums_xml );
684  _counter.count();
685  }
686  else{
687  _xml[0]->addLut( _cfg, lut_checksums_xml );
688  _counter.count();
689  }
690  }
691  std::cout << "Generated LUTs: " << _counter.getCount() << std::endl;
692  std::cout << "Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
693  return _xml;
694 }
695 
696 
697 
698 
699 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getLinearizationLutXmlFromCoderEmap( const HcalTPGCoder & _coder, std::string _tag, bool split_by_crate )
700 {
701  std::cout << "Generating linearization (input) LUTs from HcaluLUTTPGCoder..." << std::endl;
702  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
703 
704  EMap _emap(emap);
705  std::vector<EMap::EMapRow> & _map = _emap.get_map();
706  std::cout << "EMap contains " << _map . size() << " entries" << std::endl;
707 
708  std::vector<unsigned int> zeroLut;
709  for (size_t adc = 0; adc < 128; adc++) zeroLut.push_back(0);
710 
711  RooGKCounter _counter;
712  //loop over all EMap channels
713  for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
714  if( (row->subdet.find("HB")!=string::npos ||
715  row->subdet.find("HE")!=string::npos ||
716  row->subdet.find("HF")!=string::npos ) &&
717  row->subdet.size()==2
718  ){
719  LutXml::Config _cfg;
720 
721  if ( _xml.count(row->crate) == 0 && split_by_crate ){
722  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(new LutXml())) );
723  }
724  else if ( _xml.count(0) == 0 && !split_by_crate ){
725  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
726  }
727  _cfg.ieta = row->ieta;
728  _cfg.iphi = row->iphi;
729  _cfg.depth = row->idepth;
730  _cfg.crate = row->crate;
731  _cfg.slot = row->slot;
732  if (row->topbottom . find("t") != std::string::npos) _cfg.topbottom = 1;
733  else if (row->topbottom . find("b") != std::string::npos) _cfg.topbottom = 0;
734  else std::cout << "Warning! fpga out of range..." << std::endl;
735  _cfg.fiber = row->fiber;
736  _cfg.fiberchan = row->fiberchan;
737  _cfg.lut_type = 1;
738  _cfg.creationtag = _tag;
739  _cfg.creationstamp = get_time_stamp( time(0) );
740  _cfg.targetfirmware = "1.0.0";
741  _cfg.formatrevision = "1"; //???
742  // "original" definition of GENERALIZEDINDEX from Mike Weinberger
743  // int generalizedIndex=id.ietaAbs()+1000*id.depth()+10000*id.iphi()+
744  // ((id.ieta()<0)?(0):(100))+((id.subdet()==HcalForward && id.ietaAbs()==29)?(4*10000):(0));
745  _cfg.generalizedindex =
746  _cfg.iphi*10000 + _cfg.depth*1000 +
747  (row->ieta>0)*100 + abs(row->ieta) +
748  (((row->subdet.find("HF")!=string::npos) && abs(row->ieta)==29)?(4*10000):(0));
749  HcalSubdetector _subdet;
750  if ( row->subdet.find("HB")!=string::npos ) _subdet = HcalBarrel;
751  else if ( row->subdet.find("HE")!=string::npos ) _subdet = HcalEndcap;
752  else if ( row->subdet.find("HO")!=string::npos ) _subdet = HcalOuter;
753  else if ( row->subdet.find("HF")!=string::npos ) _subdet = HcalForward;
754  else _subdet = HcalOther;
755  HcalDetId _detid(_subdet, row->ieta, row->iphi, row->idepth);
756  //
757  // consider channel status here
758  uint32_t status_word = cq->getValues(_detid)->getValue();
759  if ((status_word & status_word_to_mask) > 0){
760  _cfg.lut = zeroLut;
761  }
762  else{
763  std::vector<unsigned short> coder_lut = _coder . getLinearizationLUT(_detid);
764  for (std::vector<unsigned short>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
765  unsigned int _temp = (unsigned int)(*_i);
766  _cfg.lut.push_back(_temp);
767  }
768  }
769  if (split_by_crate ){
770  _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
771  _counter.count();
772  }
773  else{
774  _xml[0]->addLut( _cfg, lut_checksums_xml );
775  _counter.count();
776  }
777  }
778  }
779  std::cout << "Generated LUTs: " << _counter.getCount() << std::endl;
780  std::cout << "Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
781  return _xml;
782 }
783 
784 
785 
786 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getCompressionLutXmlFromCoder( const CaloTPGTranscoderULUT & _coder, std::string _tag, bool split_by_crate )
787 {
788  std::cout << "Generating compression (output) LUTs from CaloTPGTranscoderULUT," << std::endl;
789  std::cout << "initialized from Event Setup" << std::endl;
790  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
791 
792  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.04_080905.txt");
793  EMap _emap(emap);
794 
795  std::vector<EMap::EMapRow> & _map = _emap.get_map();
796  std::cout << "EMap contains " << _map . size() << " channels" << std::endl;
797 
798  // read LUTs and their eta/phi/depth/subdet ranges
799  //HcalLutSet _set = getLutSetFromFile( _filename, 2 );
800  //int lut_set_size = _set.lut.size(); // number of different luts
801 
802  //loop over all EMap channels
803  RooGKCounter _counter;
804  for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
805  LutXml::Config _cfg;
806 
807  // only trigger tower channels
808  // and valid (ieta,iphi)
809  if ( row->subdet . find("HT") != std::string::npos && _coder.HTvalid(row->ieta, row->iphi) ){
810  if ( _xml.count(row->crate) == 0 && split_by_crate ){
811  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(new LutXml())) );
812  }
813  else if ( _xml.count(0) == 0 && !split_by_crate ){
814  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
815  }
816  _cfg.ieta = row->ieta;
817  _cfg.iphi = row->iphi;
818  _cfg.depth = row->idepth;
819  _cfg.crate = row->crate;
820  _cfg.slot = row->slot;
821  if (row->topbottom . find("t") != std::string::npos) _cfg.topbottom = 1;
822  else if (row->topbottom . find("b") != std::string::npos) _cfg.topbottom = 0;
823  else std::cout << "Warning! fpga out of range..." << std::endl;
824  _cfg.fiber = row->fiber;
825  _cfg.fiberchan = row->fiberchan;
826  _cfg.lut_type = 2;
827  _cfg.creationtag = _tag;
828  _cfg.creationstamp = get_time_stamp( time(0) );
829  _cfg.targetfirmware = "1.0.0";
830  _cfg.formatrevision = "1"; //???
831  // "original" definition of GENERALIZEDINDEX from Mike Weinberger
832  // int generalizedIndex=id.ietaAbs()+10000*id.iphi()+
833  // ((id.ieta()<0)?(0):(100));
834  _cfg.generalizedindex =
835  _cfg.iphi*10000+
836  (row->ieta>0)*100+abs(row->ieta);
837 
838  // FIXME: work around bug in emap v6: rawId wasn't filled
839  //HcalTrigTowerDetId _detid(row->rawId);
840  HcalTrigTowerDetId _detid(row->ieta, row->iphi);
841 
842  std::vector<unsigned char> coder_lut = _coder.getCompressionLUT(_detid);
843  for (std::vector<unsigned char>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
844  unsigned int _temp = (unsigned int)(*_i);
845  //if (_temp!=0) std::cout << "DEBUG non-zero LUT!!!!!!!!!!!!!!!" << (*_i) << " " << _temp << std::endl;
846  //unsigned int _temp = 0;
847  _cfg.lut.push_back(_temp);
848  }
849  //_cfg.lut = _set.lut[lut_index];
850 
851  if (split_by_crate ){
852  _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
853  _counter.count();
854  }
855  else{
856  _xml[0]->addLut( _cfg, lut_checksums_xml );
857  _counter.count();
858  }
859  }
860  }
861  std::cout << "LUTs generated: " << _counter.getCount() << std::endl;
862  std::cout << "Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE" << std::endl;
863  return _xml;
864 }
865 
866 
867 
868 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getCompressionLutXmlFromCoder( std::string _tag, bool split_by_crate )
869 {
870  std::cout << "Generating compression (output) LUTs from CaloTPGTranscoderULUT" << std::endl;
871  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
872 
873  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v5_080208.txt");
874  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.03_080817.txt");
875  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.04_080905.txt");
876  EMap _emap(emap);
877 
878  std::vector<EMap::EMapRow> & _map = _emap.get_map();
879  std::cout << "EMap contains " << _map . size() << " channels" << std::endl;
880 
881  // read LUTs and their eta/phi/depth/subdet ranges
882  //HcalLutSet _set = getLutSetFromFile( _filename, 2 );
883  //int lut_set_size = _set.lut.size(); // number of different luts
884 
885  CaloTPGTranscoderULUT _coder;
886 
887  //loop over all EMap channels
888  RooGKCounter _counter;
889  for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
890  LutXml::Config _cfg;
891 
892  // only trigger tower channels
893  // and valid (ieta,iphi)
894  if ( row->subdet . find("HT") != std::string::npos && _coder.HTvalid(row->ieta, row->iphi) ){
895  if ( _xml.count(row->crate) == 0 && split_by_crate ){
896  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(new LutXml())) );
897  }
898  else if ( _xml.count(0) == 0 && !split_by_crate ){
899  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
900  }
901  _cfg.ieta = row->ieta;
902  _cfg.iphi = row->iphi;
903  _cfg.depth = row->idepth;
904  _cfg.crate = row->crate;
905  _cfg.slot = row->slot;
906  if (row->topbottom . find("t") != std::string::npos) _cfg.topbottom = 1;
907  else if (row->topbottom . find("b") != std::string::npos) _cfg.topbottom = 0;
908  else std::cout << "Warning! fpga out of range..." << std::endl;
909  _cfg.fiber = row->fiber;
910  _cfg.fiberchan = row->fiberchan;
911  _cfg.lut_type = 2;
912  _cfg.creationtag = _tag;
913  _cfg.creationstamp = get_time_stamp( time(0) );
914  _cfg.targetfirmware = "1.0.0";
915  _cfg.formatrevision = "1"; //???
916  // "original" definition of GENERALIZEDINDEX from Mike Weinberger
917  // int generalizedIndex=id.ietaAbs()+10000*id.iphi()+
918  // ((id.ieta()<0)?(0):(100));
919  _cfg.generalizedindex =
920  _cfg.iphi*10000+
921  (row->ieta>0)*100+abs(row->ieta);
922 
923  // FIXME: work around bug in emap v6: rawId wasn't filled
924  //HcalTrigTowerDetId _detid(row->rawId);
925  HcalTrigTowerDetId _detid(row->ieta, row->iphi);
926 
927  std::vector<unsigned char> coder_lut = _coder.getCompressionLUT(_detid);
928  for (std::vector<unsigned char>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
929  unsigned int _temp = (unsigned int)(*_i);
930  //if (_temp!=0) std::cout << "DEBUG non-zero LUT!!!!!!!!!!!!!!!" << (*_i) << " " << _temp << std::endl;
931  //unsigned int _temp = 0;
932  _cfg.lut.push_back(_temp);
933  }
934  //_cfg.lut = _set.lut[lut_index];
935 
936  if (split_by_crate ){
937  _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
938  _counter.count();
939  }
940  else{
941  _xml[0]->addLut( _cfg, lut_checksums_xml );
942  _counter.count();
943  }
944  }
945  }
946  std::cout << "LUTs generated: " << _counter.getCount() << std::endl;
947  std::cout << "Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE" << std::endl;
948  return _xml;
949 }
950 
951 
952 
953 int HcalLutManager::writeLutXmlFiles( std::map<int, boost::shared_ptr<LutXml> > & _xml, std::string _tag, bool split_by_crate )
954 {
955  for (std::map<int,boost::shared_ptr<LutXml> >::const_iterator cr = _xml.begin(); cr != _xml.end(); cr++){
956  std::stringstream output_file_name;
957  if ( split_by_crate ){
958  output_file_name << _tag << "_" << cr->first << ".xml";
959  }
960  else{
961  output_file_name << _tag << ".xml";
962  }
963  cr->second->write( output_file_name.str().c_str() );
964  }
965  return 0;
966 }
967 
968 int HcalLutManager::createLinLutXmlFiles( std::string _tag, std::string _lin_file, bool split_by_crate )
969 {
970  //std::cout << "DEBUG1: split_by_crate = " << split_by_crate << std::endl;
971  std::map<int, boost::shared_ptr<LutXml> > xml;
972  if ( !lut_checksums_xml ){
973  lut_checksums_xml = new XMLDOMBlock( "CFGBrick", 1 );
974  }
975 
976  if ( _lin_file.size() != 0 ){
977  addLutMap( xml, getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate ) );
978  }
979  writeLutXmlFiles( xml, _tag, split_by_crate );
980 
981  std::string checksums_file = _tag + "_checksums.xml";
982  lut_checksums_xml -> write( checksums_file . c_str() );
983 
984  return 0;
985 }
986 
987 int HcalLutManager::createAllLutXmlFiles( std::string _tag, std::string _lin_file, std::string _comp_file, bool split_by_crate )
988 {
989  //std::cout << "DEBUG1: split_by_crate = " << split_by_crate << std::endl;
990  std::map<int, boost::shared_ptr<LutXml> > xml;
991  if ( !lut_checksums_xml ){
992  lut_checksums_xml = new XMLDOMBlock( "CFGBrick", 1 );
993  }
994 
995  if ( _lin_file.size() != 0 ){
996  //addLutMap( xml, getLutXmlFromAsciiMaster( _lin_file, _tag, -1, split_by_crate ) );
997  addLutMap( xml, getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate ) );
998  }
999  if ( _comp_file.size() != 0 ){
1000  //std::cout << "DEBUG1!!!!" << std::endl;
1001  addLutMap( xml, getCompressionLutXmlFromAsciiMaster( _comp_file, _tag, -1, split_by_crate ) );
1002  //std::cout << "DEBUG2!!!!" << std::endl;
1003  }
1004  writeLutXmlFiles( xml, _tag, split_by_crate );
1005 
1006  std::string checksums_file = _tag + "_checksums.xml";
1007  lut_checksums_xml -> write( checksums_file . c_str() );
1008 
1009  return 0;
1010 }
1011 
1013 {
1014  //std::cout << "DEBUG1: split_by_crate = " << split_by_crate << std::endl;
1015  std::map<int, boost::shared_ptr<LutXml> > xml;
1016  if ( !lut_checksums_xml ){
1017  lut_checksums_xml = new XMLDOMBlock( "CFGBrick", 1 );
1018  }
1019 
1020  addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1021 
1022  writeLutXmlFiles( xml, _tag, split_by_crate );
1023 
1024  std::string checksums_file = _tag + "_checksums.xml";
1025  lut_checksums_xml -> write( checksums_file . c_str() );
1026 
1027  return 0;
1028 }
1029 
1030 int HcalLutManager::createAllLutXmlFilesFromCoder( const HcalTPGCoder & _coder, std::string _tag, bool split_by_crate )
1031 {
1032  //std::cout << "DEBUG1: split_by_crate = " << split_by_crate << std::endl;
1033  std::map<int, boost::shared_ptr<LutXml> > xml;
1034  if ( !lut_checksums_xml ){
1035  lut_checksums_xml = new XMLDOMBlock( "CFGBrick", 1 );
1036  }
1037 
1038  //addLutMap( xml, getLinearizationLutXmlFromCoder( _coder, _tag, split_by_crate ) );
1039  addLutMap( xml, getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate ) );
1040  addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1041 
1042  writeLutXmlFiles( xml, _tag, split_by_crate );
1043 
1044  std::string checksums_file = _tag + "_checksums.xml";
1045  lut_checksums_xml -> write( checksums_file . c_str() );
1046 
1047  return 0;
1048 }
1049 
1050 //
1051 //_____ use this for creating a full set of LUTs ________________________
1052 //
1053 int HcalLutManager::createLutXmlFiles_HBEFFromCoder_HOFromAscii( std::string _tag, const HcalTPGCoder & _coder, const CaloTPGTranscoderULUT & _transcoder, std::string _lin_file, bool split_by_crate )
1054 {
1055  std::map<int, boost::shared_ptr<LutXml> > xml;
1056  if ( !lut_checksums_xml ){
1057  lut_checksums_xml = new XMLDOMBlock( "CFGBrick", 1 );
1058  }
1059 
1060  if ( _lin_file.size() != 0 ){
1061  const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1062  addLutMap( xml, _lin_lut_ascii_xml );
1063  }
1064  const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1065  addLutMap( xml, _lin_lut_xml );
1066  //
1067  const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _transcoder, _tag, split_by_crate );
1068  addLutMap( xml, _comp_lut_xml );
1069 
1070  writeLutXmlFiles( xml, _tag, split_by_crate );
1071 
1072  std::string checksums_file = _tag + "_checksums.xml";
1073  lut_checksums_xml -> write( checksums_file . c_str() );
1074 
1075  return 0;
1076 }
1077 
1078 
1080 {
1081  std::map<int, boost::shared_ptr<LutXml> > xml;
1082  if ( !lut_checksums_xml ){
1083  lut_checksums_xml = new XMLDOMBlock( "CFGBrick", 1 );
1084  }
1085 
1086  if ( _lin_file.size() != 0 ){
1087  const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1088  addLutMap( xml, _lin_lut_ascii_xml );
1089  }
1090  const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1091  addLutMap( xml, _lin_lut_xml );
1092  //
1093  const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _tag, split_by_crate );
1094  addLutMap( xml, _comp_lut_xml );
1095 
1096  writeLutXmlFiles( xml, _tag, split_by_crate );
1097 
1098  std::string checksums_file = _tag + "_checksums.xml";
1099  lut_checksums_xml -> write( checksums_file . c_str() );
1100 
1101  return 0;
1102 }
1103 
1104 
1105 // use this to create HBEF only from coders (physics LUTs)
1107 {
1108  //std::cout << "DEBUG1: split_by_crate = " << split_by_crate << std::endl;
1109  std::map<int, boost::shared_ptr<LutXml> > xml;
1110  if ( !lut_checksums_xml ){
1111  lut_checksums_xml = new XMLDOMBlock( "CFGBrick", 1 );
1112  }
1113 
1114  if ( _lin_file.size() != 0 ){
1115  addLutMap( xml, getLutXmlFromAsciiMaster( _lin_file, _tag, -1, split_by_crate ) );
1116  }
1117  addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1118  writeLutXmlFiles( xml, _tag, split_by_crate );
1119 
1120  std::string checksums_file = _tag + "_checksums.xml";
1121  lut_checksums_xml -> write( checksums_file . c_str() );
1122 
1123  return 0;
1124 }
1125 
1126 
1127 
1128 void HcalLutManager::addLutMap(std::map<int, boost::shared_ptr<LutXml> > & result, const std::map<int, boost::shared_ptr<LutXml> > & other)
1129 {
1130  for ( std::map<int, boost::shared_ptr<LutXml> >::const_iterator lut=other.begin(); lut!=other.end(); lut++ ){
1131  std::cout << "Added LUTs for crate " << lut->first << std::endl;
1132  if ( result.count(lut->first)==0 ){
1133  result . insert( *lut );
1134  }
1135  else{
1136  *(result[lut->first]) += *(lut->second);
1137  }
1138  }
1139 }
1140 
1141 
1142 
1143 
1144 string HcalLutManager::get_time_stamp( time_t _time )
1145 {
1146  char timebuf[50];
1147  //strftime( timebuf, 50, "%c", gmtime( &_time ) );
1148  strftime( timebuf, 50, "%Y-%m-%d %H:%M:%S", gmtime( &_time ) );
1149  std::string creationstamp = timebuf;
1150 
1151  return creationstamp;
1152 }
1153 
1154 
1155 
1156 
1158 {
1159  local_connect( _filename, "backup/HCALmapHBEF.txt", "backup/HCALmapHO.txt" );
1160 
1161  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.04_080905.txt");
1162  EMap _emap(emap);
1163  std::vector<EMap::EMapRow> & _map = _emap.get_map();
1164  int map_size = _map . size();
1165  std::cout << "EMap contains " << map_size << " channels" << std::endl;
1166 
1167  // make sure that all init is done
1168  std::vector<unsigned int> _lut;
1169  _lut = getLutFromXml( _tag, 1107313727, hcal::ConfigurationDatabase::LinearizerLUT );
1170 
1171 
1172  std::cout << std::endl << "Testing direct parsing of the LUT XML" << std::endl;
1173  struct timeval _t;
1174  gettimeofday( &_t, NULL );
1175  double _time =(double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0;
1176  test_direct_xml_parsing(_filename);
1177  gettimeofday( &_t, NULL );
1178  std::cout << "parsing took that much time: " << (double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0 - _time << std::endl;
1179 
1180 
1181  gettimeofday( &_t, NULL );
1182  _time =(double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0;
1183  std::cout << "before loop over random LUTs: " << _time << std::endl;
1184  int _raw_id;
1185 
1186  // loop over random LUTs
1187  for (int _iter=0; _iter<100; _iter++){
1188  gettimeofday( &_t, NULL );
1189  //std::cout << "before getting a LUT: " << _t . tv_sec << "." << _t . tv_usec << std::endl;
1190 
1191  // select valid random emap channel
1192  while(1){
1193  int _key = (rand() % map_size);
1194  //_key = 3356;
1195  if( (_map[_key].subdet.find("HB")!=string::npos ||
1196  _map[_key].subdet.find("HE")!=string::npos ||
1197  _map[_key].subdet.find("HO")!=string::npos ||
1198  _map[_key].subdet.find("HF")!=string::npos ) &&
1199  _map[_key].subdet.size()==2
1200  ){
1201  HcalSubdetector _subdet;
1202  if ( _map[_key].subdet.find("HB")!=string::npos ) _subdet = HcalBarrel;
1203  else if ( _map[_key].subdet.find("HE")!=string::npos ) _subdet = HcalEndcap;
1204  else if ( _map[_key].subdet.find("HO")!=string::npos ) _subdet = HcalOuter;
1205  else if ( _map[_key].subdet.find("HF")!=string::npos ) _subdet = HcalForward;
1206  else _subdet = HcalOther;
1207  HcalDetId _detid(_subdet, _map[_key].ieta, _map[_key].iphi, _map[_key].idepth);
1208  _raw_id = _detid.rawId();
1209  break;
1210  }
1211  }
1212  _lut = getLutFromXml( _tag, _raw_id, hcal::ConfigurationDatabase::LinearizerLUT );
1213 
1214  gettimeofday( &_t, NULL );
1215  }
1216  double d_time = _t.tv_sec+_t.tv_usec/1000000.0 - _time;
1217  std::cout << "after the loop over random LUTs: " << _time+d_time << std::endl;
1218  std::cout << "total time: " << d_time << std::endl;
1219 
1220  std::cout << "LUT length = " << _lut . size() << std::endl;
1221  for ( std::vector<unsigned int>::const_iterator i = _lut . end() - 1; i != _lut . begin()-1; i-- )
1222  {
1223  std::cout << (i-_lut.begin()) << " " << _lut[(i-_lut.begin())] << std::endl;
1224  break;
1225  }
1226 
1227  db -> disconnect();
1228 
1229  delete db;
1230  db = 0;
1231 
1232  return 0;
1233 }
1234 
1235 
1236 
1237 int HcalLutManager::read_lmap( std::string lmap_hbef_file, std::string lmap_ho_file )
1238 {
1239  delete lmap;
1240  lmap = new LMap();
1241  lmap -> read( lmap_hbef_file, "HBEF" );
1242  lmap -> read( lmap_ho_file, "HO" );
1243  std::cout << "LMap contains " << lmap -> get_map() . size() << " channels (compare to 9072 of all HCAL channels)" << std::endl;
1244  return 0;
1245 }
1246 
1247 
1248 
1250 {
1251  delete db;
1252  db = new HCALConfigDB();
1253  db -> connect( lut_xml_file );
1254  return 0;
1255 }
1256 
1257 
1258 
1259 
1260 
1261 int HcalLutManager::local_connect( std::string lut_xml_file, std::string lmap_hbef_file, std::string lmap_ho_file )
1262 {
1263  read_lmap( lmap_hbef_file, lmap_ho_file );
1264  read_luts( lut_xml_file );
1265  return 0;
1266 }
1267 
1268 
1269 
1270 
1271 std::vector<unsigned int> HcalLutManager::getLutFromXml( std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt )
1272 {
1273  std::cout << "getLutFromXml (new version) is not implemented. Use getLutFromXml_old() for now" << std::endl;
1274 
1275  std::vector<unsigned int> result;
1276 
1277 
1278 
1279  return result;
1280 }
1281 
1282 
1283 // obsolete, use getLutFromXml() instead
1284 std::vector<unsigned int> HcalLutManager::getLutFromXml_old( std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt )
1285 {
1286  if ( !lmap ){
1287  std::cout << "HcalLutManager: cannot find LUT without LMAP, exiting..." << std::endl;
1288  exit(-1);
1289  }
1290  if ( !db ){
1291  std::cout << "HcalLutManager: cannot find LUT, no source (local XML file), exiting..." << std::endl;
1292  exit(-1);
1293  }
1294 
1295  std::vector<unsigned int> result;
1296 
1297  std::map<int,LMapRow> & _map = lmap -> get_map();
1298  //std::cout << "HcalLutManager: LMap contains " << _map . size() << " channels (out of 9072 total)" << std::endl;
1299 
1300  HcalDetId _id( _rawid );
1301 
1302  unsigned int _crate, _slot, _fiber, _channel;
1303  std::string _fpga;
1304  int topbottom, luttype;
1305 
1306  // FIXME: check validity of _rawid
1307  if ( _map . find(_rawid) != _map.end() ){
1308  _crate = _map[_rawid] . crate;
1309  _slot = _map[_rawid] . htr;
1310  _fiber = _map[_rawid] . htr_fi;
1311  _channel = _map[_rawid] . fi_ch;
1312  _fpga = _map[_rawid] . fpga;
1313 
1314  if ( _fpga . find("top") != std::string::npos ) topbottom = 1;
1315  else if ( _fpga . find("bot") != std::string::npos ) topbottom = 0;
1316  else{
1317  std::cout << "HcalLutManager: irregular LMAP fpga value... do not know what to do - exiting" << std::endl;
1318  exit(-1);
1319  }
1320  if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
1321  else luttype = 2;
1322 
1323  result = db -> getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
1324  }
1325 
1326  return result;
1327 }
1328 
1329 
1330 
1331 int HcalLutManager::get_xml_files_from_db( std::string tag, const std::string db_accessor, bool split_by_crate )
1332 {
1333  std::map<int, boost::shared_ptr<LutXml> > lut_map = get_brickSet_from_oracle( tag, db_accessor );
1334  if (split_by_crate){
1335  writeLutXmlFiles( lut_map, tag, split_by_crate );
1336  }
1337  else{
1338  LutXml result;
1339  for( std::map<int, boost::shared_ptr<LutXml> >::const_iterator xml = lut_map.begin(); xml != lut_map.end(); xml++ ){
1340  result += *(xml->second);
1341  }
1342  std::stringstream out_file;
1343  out_file << tag << ".xml";
1344  result . write(out_file.str());
1345  }
1346 
1347  return 0;
1348 }
1349 
1350 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::get_brickSet_from_oracle( std::string tag, const std::string _accessor )
1351 {
1352  HCALConfigDB * db = new HCALConfigDB();
1353  XMLProcessor::getInstance(); // initialize xerces-c engine
1354  //const std::string _accessor = "occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22";
1355  db -> connect( _accessor );
1356  oracle::occi::Connection * _connection = db -> getConnection();
1357 
1358  std::cout << "Preparing to request the LUT CLOBs from the database..." << std::endl;
1359 
1360  //int crate = 0;
1361 
1362  //
1363  // _____ query is different for the old validation DB _________________
1364  //
1365  //std::string query = ("SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB, CRATE FROM CMS_HCL_HCAL_CONDITION_OWNER.V_HCAL_TRIG_LOOKUP_TABLES");
1366  std::string query = ("SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB, CRATE FROM CMS_HCL_HCAL_COND.V_HCAL_TRIG_LOOKUP_TABLES");
1367  //query+=toolbox::toString(" WHERE TAG_NAME='%s' AND CRATE=%d", tag.c_str(), crate);
1368  query+=toolbox::toString(" WHERE TAG_NAME='%s'", tag.c_str() );
1369 
1370  std::string brick_set;
1371 
1372  std::map<int, boost::shared_ptr<LutXml> > lut_map;
1373 
1374  try {
1375  //SELECT
1376  std::cout << "Executing the query..." << std::endl;
1377  Statement* stmt = _connection -> createStatement();
1378  ResultSet *rs = stmt->executeQuery(query.c_str());
1379  std::cout << "Executing the query... done" << std::endl;
1380 
1381  std::cout << "Processing the query results..." << std::endl;
1382  //RooGKCounter _lines;
1383  while (rs->next()) {
1384  //_lines.count();
1385  oracle::occi::Clob clob = rs->getClob (1);
1386  int crate = rs->getInt(2);
1387  if ( crate != -1 ){ // not a brick with checksums
1388  cout << "Getting LUTs for crate #" << crate << " out of the database...";
1389  brick_set = db -> clobToString(clob);
1390  /*
1391  // FIXME: DEBUG lut xml files from simple strings
1392  stringstream file_name;
1393  ofstream out_file;
1394  file_name << tag << "_" << crate << "_debug" << ".xml";
1395  out_file . open( file_name.str().c_str() );
1396  out_file << brick_set;
1397  out_file . close();
1398  */
1399  const char * bs = brick_set . c_str();
1400  MemBufInputSource * lut_clob = new MemBufInputSource( (const XMLByte *)bs, strlen( bs ), "lut_clob", false );
1401  boost::shared_ptr<LutXml> lut_xml = boost::shared_ptr<LutXml>( new LutXml( *lut_clob ) );
1402  lut_map[crate] = lut_xml;
1403  std::cout << " done" << std::endl;
1404  }
1405  }
1406  //Always terminate statement
1407  _connection -> terminateStatement(stmt);
1408  //std::cout << "Query line count: " << _lines.getCount() << std::endl;
1409  } catch (SQLException& e) {
1410  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()));
1411  }
1412 
1413  //std::cout << lut_map.size() << std::endl;
1414 
1415  db -> disconnect();
1416  //delete db;
1417  return lut_map;
1418 }
1419 
1420 
1422 {
1423  std::cout << "Generating XML loader for LUTs..." << std::endl;
1424  //std::cout << _prefix << "..." << tag_name << std::endl;
1425 
1429 
1430  baseConf . tag_name = tag_name;
1431  //baseConf . comment_description = tag_name;
1432  baseConf . comment_description = comment;
1433  baseConf . iov_begin = "1";
1434  baseConf . iov_end = "-1";
1435 
1436  conf . version = version;
1437 
1438  std::stringstream _subversion;
1439  _subversion << subversion;
1440  conf . subversion = _subversion.str();
1441 
1442  CSconf . version = conf . version;
1443  CSconf . subversion = conf . subversion;
1444  CSconf . trig_prim_lookuptbl_data_file = _prefix + "_checksums.xml.dat";
1445  CSconf . comment_description = tag_name;
1446 
1447  XMLLUTLoader doc( &baseConf );
1448 
1449  std::vector<int> crate_number;
1450  std::vector<std::string> file_name = HcalQIEManager::splitString(file_list);
1451  for (std::vector<std::string>::const_iterator _f = file_name.begin(); _f != file_name.end(); _f++){
1452  int crate_begin = _f->rfind("_");
1453  int crate_end = _f->rfind(".xml.dat");
1454  crate_number . push_back(getInt(_f->substr(crate_begin+1,crate_end-crate_begin-1)));
1455  }
1456  //
1457  //_____ fix due to the new convention: version/subversion combo must be unique for every payload
1458  //
1459  char _buf[128];
1460  time_t _offset = time(NULL);
1461  sprintf( _buf, "%d", (uint32_t)_offset );
1462  conf.version.append(".");
1463  conf.version.append(_buf);
1464  CSconf.version = conf.version;
1465  //
1466  for ( std::vector<std::string>::const_iterator _file = file_name . begin(); _file != file_name . end(); _file++ )
1467  {
1468  conf . trig_prim_lookuptbl_data_file = *_file;
1469  //conf . trig_prim_lookuptbl_data_file += ".dat";
1470  conf . crate = crate_number[ _file - file_name . begin() ];
1471  //
1472  //_____ fix due to the new convention: version/subversion combo must be unique for every payload
1473  //
1474  sprintf( _buf, "%.2d", conf.crate );
1475  conf.subversion.clear();
1476  conf.subversion.append(_buf);
1477  sprintf( _buf, "CRATE%.2d", conf . crate );
1478  std::string _namelabel;
1479  _namelabel . append( _buf );
1480  conf . name_label = _namelabel;
1481  doc . addLUT( &conf );
1482  }
1483 
1484  doc . addChecksums( &CSconf );
1485  //doc . write( _prefix + "_Loader.xml" );
1486  doc . write( tag_name + "_Loader.xml" );
1487 
1488  std::cout << "Generating XML loader for LUTs... done." << std::endl;
1489 
1490  return 0;
1491 }
1492 
1494  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v5_080208.txt");
1495  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.03_080817.txt");
1496  //EMap _emap("../../../CondFormats/HcalObjects/data/official_emap_v6.04_080905.txt");
1497  EMap _emap(emap);
1498  std::vector<EMap::EMapRow> & _map = _emap.get_map();
1499  std::cout << "EMap contains " << _map . size() << " channels" << std::endl;
1500 
1501  //loop over all EMap channels
1502  //RooGKCounter _c;
1503  for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
1504 
1505  // only trigger tower channels
1506  if ( row->subdet . find("HT") != std::string::npos ){
1507  std::cout << " -----> Subdet = " << row->subdet << std::endl;
1508 
1509  if (abs(row->ieta)>28){
1510  //if (row->iphi == 71){
1511  cout << " ==> (ieta,iphi) = " << row->ieta << ", " << row->iphi << std::endl;
1512  }
1513  }
1514  }
1515 }
1516 
1517 
1518 
1519 
1520 
1522  /*
1523  XMLDOMBlock _xml(_filename);
1524  //DOMElement * data_set_elem = (DOMElement *)(document -> getElementsByTagName( XMLProcessor::_toXMLCh( "DATA_SET" ) ) -> item(0));
1525  DOMNodeList * brick_list = _xml . getDocument() -> getElementsByTagName( XMLProcessor::_toXMLCh( "CFGBrick" ));
1526 
1527  double n_bricks = brick_list->getLength();
1528  std::cout << "amount of LUT bricks: " << n_bricks << std::endl;
1529 
1530  for (int iter=0; iter!=n_bricks; iter++){
1531  DOMElement * _brick = (DOMElement *)(brick_list->item(iter));
1532 
1533  DOMElement * _param = 0;
1534  // loop over brick parameters
1535  int par_iter = 0;
1536  while(1){
1537  _param = (DOMElement *)(_brick->getElementsByTagName(XMLProcessor::_toXMLCh("Parameter")));
1538  std::string _name = _param->getAttribute( XMLProcessor::_toXMLCh( "name" ) );
1539  if (_name.find("IETA")==string::npos) break;
1540 
1541  std::string _tag = "Parameter";
1542  std::cout << "### Parameter IETA = " << _xml.getTagValue( _tag, 0, _brick);
1543  par_iter++;
1544  }
1545  }
1546  */
1547  return 0;
1548 }
1549 
1550 
1551 //
1552 //_____ attempt to include ZDC LUTs _____________________________________
1553 //
1554 int HcalLutManager::createLutXmlFiles_HBEFFromCoder_HOFromAscii_ZDC( std::string _tag, const HcalTPGCoder & _coder, const CaloTPGTranscoderULUT & _transcoder, std::string _lin_file, bool split_by_crate )
1555 {
1556  std::map<int, boost::shared_ptr<LutXml> > xml;
1557  if ( !lut_checksums_xml ){
1558  lut_checksums_xml = new XMLDOMBlock( "CFGBrick", 1 );
1559  }
1560 
1561  if ( _lin_file.size() != 0 ){
1562  const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1563  addLutMap( xml, _lin_lut_ascii_xml );
1564  }
1565  const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1566  addLutMap( xml, _lin_lut_xml );
1567  //
1568  const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _transcoder, _tag, split_by_crate );
1569  addLutMap( xml, _comp_lut_xml );
1570  //
1571  const std::map<int, boost::shared_ptr<LutXml> > _zdc_lut_xml = getZdcLutXml( _tag, split_by_crate );
1572  addLutMap( xml, _zdc_lut_xml );
1573 
1574  writeLutXmlFiles( xml, _tag, split_by_crate );
1575 
1576  std::string checksums_file = _tag + "_checksums.xml";
1577  lut_checksums_xml -> write( checksums_file . c_str() );
1578 
1579  return 0;
1580 }
1581 
1582 
1583 std::map<int, boost::shared_ptr<LutXml> > HcalLutManager::getZdcLutXml( std::string _tag,
1584  bool split_by_crate )
1585 {
1586  std::cout << "Generating ZDC LUTs ...may the Force be with us..." << std::endl;
1587  std::map<int, boost::shared_ptr<LutXml> > _xml; // index - crate number
1588 
1589  EMap _emap(emap);
1590 
1591  ZdcLut zdc;
1592 
1593  std::vector<EMap::EMapRow> & _map = _emap.get_map();
1594  std::cout << "EMap contains " << _map . size() << " channels" << std::endl;
1595 
1596  //loop over all EMap channels
1597  RooGKCounter _counter;
1598  for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
1599  LutXml::Config _cfg;
1600 
1601  // only ZDC channels
1602  if ( row->zdc_section . find("ZDC") != std::string::npos ){
1603  if ( _xml.count(row->crate) == 0 && split_by_crate ){
1604  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(new LutXml())) );
1605  }
1606  else if ( _xml.count(0) == 0 && !split_by_crate ){
1607  _xml.insert( std::pair<int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(new LutXml())) );
1608  }
1609  // FIXME: introduce proper tag names in ZDC bricks for logical channel info
1610  _cfg.ieta = row->zdc_channel; // int
1611  //_cfg.ieta = row->zdc_zside; // int
1612  //_cfg.iphi = row->zdc_section; // string
1613  _cfg.depth = row->idepth; // int
1614  _cfg.crate = row->crate;
1615  _cfg.slot = row->slot;
1616  if (row->topbottom . find("t") != std::string::npos) _cfg.topbottom = 1;
1617  else if (row->topbottom . find("b") != std::string::npos) _cfg.topbottom = 0;
1618  else std::cout << "Warning! fpga out of range..." << std::endl;
1619  _cfg.fiber = row->fiber;
1620  _cfg.fiberchan = row->fiberchan;
1621  _cfg.lut_type = 1;
1622  _cfg.creationtag = _tag;
1623  _cfg.creationstamp = get_time_stamp( time(0) );
1624  _cfg.targetfirmware = "1.0.0";
1625  _cfg.formatrevision = "1"; //???
1626  _cfg.generalizedindex = 0;
1627 
1628  //HcalZDCDetId _detid(row->zdc_section, (row->zdc_zside>0), row->zdc_channel);
1629 
1630  std::vector<int> coder_lut = zdc.get_lut(row->zdc_section,
1631  row->zdc_zside,
1632  row->zdc_channel);
1633  std::cout << "***DEBUG: ZDC lut size: " << coder_lut.size() << std::endl;
1634  if (coder_lut.size()!=0){
1635  for (std::vector<int>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
1636  unsigned int _temp = (unsigned int)(*_i);
1637  //if (_temp!=0) std::cout << "DEBUG non-zero LUT!!!!!!!!!!!!!!!" << (*_i) << " " << _temp << std::endl;
1638  //unsigned int _temp = 0;
1639  _cfg.lut.push_back(_temp);
1640  }
1641  //_cfg.lut = _set.lut[lut_index];
1642 
1643  if (split_by_crate ){
1644  _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
1645  _counter.count();
1646  }
1647  else{
1648  _xml[0]->addLut( _cfg, lut_checksums_xml );
1649  _counter.count();
1650  }
1651  } //size of lut
1652  }
1653  }
1654  std::cout << "LUTs generated: " << _counter.getCount() << std::endl;
1655  std::cout << "Generating ZDC LUTs...DONE" << std::endl;
1656 
1657  return _xml;
1658 }
1659 
1660 
int adc(sample_type sample)
get the ADC sample (12 bits)
int i
Definition: DBlmapReader.cc:9
int initChannelIterator(std::vector< HcalGenericDetId > &map)
std::map< int, boost::shared_ptr< LutXml > > getLutXmlFromAsciiMaster(std::string _filename, std::string _tag, int _crate=-1, bool split_by_crate=true)
std::vector< std::vector< unsigned int > > lut
std::vector< int > get_lut(int emap_side, int emap_htr_fiber, int emap_fi_ch)
Definition: ZdcLut.cc:212
std::string targetfirmware
Definition: LutXml.h:39
Definition: LutXml.h:27
static int getLutSetFromFile_test(std::string _filename)
std::vector< int > phi_max
int generalizedindex
Definition: LutXml.h:40
int createLutXmlFiles_HBEFFromCoder_HOFromAscii_ZDC(std::string _tag, const HcalTPGCoder &_coder, const CaloTPGTranscoderULUT &_transcoder, std::string _lin_file, bool split_by_crate=true)
std::map< int, boost::shared_ptr< LutXml > > get_brickSet_from_oracle(std::string tag, const std::string _accessor="occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22")
std::vector< std::string > subdet
Various manipulations with trigger Lookup Tables.
int init
Definition: HydjetWrapper.h:62
std::string & getLutXml(std::vector< unsigned int > &_lut)
std::map< int, boost::shared_ptr< LutXml > > getCompressionLutXmlFromAsciiMaster(std::string _filename, std::string _tag, int _crate=-1, bool split_by_crate=true)
Generation of ZDC Lookup tables and associate helper methods.
Definition: ZdcLut.h:25
tuple db
Definition: EcalCondDB.py:151
std::vector< int > phi_min
std::vector< int > depth_max
#define NULL
Definition: scimark2.h:8
int get_xml_files_from_db(std::string tag, const std::string db_accessor="occi://CMS_HCL_PRTTYPE_HCAL_READER@anyhost/int2r?PASSWORD=HCAL_Reader_88,LHWM_VERSION=22", bool split_by_crate=true)
unsigned long int getCount(void)
virtual std::vector< unsigned char > getCompressionLUT(HcalTrigTowerDetId id) const
#define _depth
Definition: Pythia6jets.h:5
int getInt(ResultSet *rset, int ipar)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
static HcalSubdetector get_subdetector(std::string _subdet)
std::map< int, boost::shared_ptr< LutXml > > getCompressionLutXmlFromCoder(std::string _tag, bool split_by_crate=true)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
int createCompLutXmlFilesFromCoder(std::string _tag, bool split_by_crate=true)
int createLinLutXmlFiles(std::string _tag, std::string _lin_file, bool split_by_crate=true)
std::map< int, boost::shared_ptr< LutXml > > getLinearizationLutXmlFromCoder(const HcalTPGCoder &_coder, std::string _tag, bool split_by_crate=true)
HcalSubdetector get_subdetector(std::string _det)
std::map< int, LMapRow > & get_map(void)
Definition: LMap.cc:59
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int test_direct_xml_parsing(std::string _filename)
int topbottom
Definition: LutXml.h:35
std::vector< unsigned int > lut
Definition: LutXml.h:41
std::string creationtag
Definition: LutXml.h:36
void addLutMap(std::map< int, boost::shared_ptr< LutXml > > &result, const std::map< int, boost::shared_ptr< LutXml > > &other)
static std::vector< std::string > splitString(const std::string &fLine)
std::map< int, boost::shared_ptr< LutXml > > getZdcLutXml(std::string _tag, bool split_by_crate=true)
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
tuple result
Definition: query.py:137
int read_luts(std::string lut_xml_file)
std::vector< int > depth_min
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
std::map< int, boost::shared_ptr< LutXml > > getLinearizationLutXmlFromAsciiMasterEmap_new(std::string _filename, std::string _tag, int _crate, bool split_by_crate=true)
int writeLutXmlFiles(std::map< int, boost::shared_ptr< LutXml > > &_xml, std::string _tag="default_tag", bool split_by_crate=true)
HcalLutSet getLutSetFromFile(std::string _filename, int _type=1)
tuple doc
Definition: asciidump.py:381
tuple lut
Definition: lumiPlot.py:244
#define end
Definition: vmac.h:37
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
void init(void)
std::string formatrevision
Definition: LutXml.h:38
tuple conf
Definition: dbtoconf.py:185
virtual bool HTvalid(const int ieta, const int iphi) const
Gather config data from online DB.
Definition: HCALConfigDB.h:21
Definition: DetId.h:18
int test_xml_access(std::string _tag, std::string _filename)
int create_lut_loader(std::string file_list, std::string _prefix, std::string tag_name, std::string comment="default comment", std::string version="V00-01-01", int subversion=1)
for(const auto &pset:thresholds)
int createAllLutXmlFiles(std::string _tag, std::string _lin_file, std::string _comp_file, bool split_by_crate=true)
std::map< int, boost::shared_ptr< LutXml > > getLinearizationLutXmlFromCoderEmap(const HcalTPGCoder &_coder, std::string _tag, bool split_by_crate=true)
void count(void)
Definition: RooGKCounter.cc:66
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
#define begin
Definition: vmac.h:30
static int getInt(std::string number)
static std::string get_time_stamp(time_t _time)
Signal rand(Signal arg)
Definition: vlib.cc:442
int local_connect(std::string lut_xml_file, std::string lmap_hbef_file, std::string lmap_ho_file)
std::vector< unsigned int > getLutFromXml(std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt)
tuple query
Definition: o2o.py:269
std::map< int, boost::shared_ptr< LutXml > > getLinearizationLutXmlFromAsciiMasterEmap(std::string _filename, std::string _tag, int _crate, bool split_by_crate=true)
int createAllLutXmlFilesLinAsciiCompCoder(std::string _tag, std::string _lin_file, bool split_by_crate=true)
std::vector< int > eta_max
std::vector< EMap::EMapRow > & get_map(void)
Definition: LMap.cc:303
tuple cout
Definition: gather_cfg.py:121
Definition: LMap.h:94
int read_lmap(std::string lmap_hbef_file, std::string lmap_ho_file)
int lut_type
Definition: LutXml.h:35
std::string creationstamp
Definition: LutXml.h:37
Definition: LMap.h:75
Readout chain identification for Hcal [31:26] Unused (so far) [25] Trigger-chain id flag [24:20] Read...
int createLutXmlFiles_HBEFFromCoder_HOFromAscii(std::string _tag, const HcalTPGCoder &_coder, std::string _lin_file, bool split_by_crate=true)
int fiberchan
Definition: LutXml.h:35
tuple size
Write out results.
std::vector< int > eta_min
static XMLProcessor * getInstance()
Definition: XMLProcessor.h:146
int createAllLutXmlFilesFromCoder(const HcalTPGCoder &_coder, std::string _tag, bool split_by_crate=true)
void test_emap(void)
std::vector< unsigned int > getLutFromXml_old(std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt)
#define comment(par)
Definition: vmac.h:161