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