11 #include "xgi/Utils.h"
12 #include "toolbox/string.h"
28 using namespace oracle::occi;
54 uint32_t _status_word_to_mask)
59 status_word_to_mask = _status_word_to_mask;
66 lut_checksums_xml = 0;
71 status_word_to_mask = 0x0000;
79 delete lut_checksums_xml;
95 if (lut_xml)
delete lut_xml;
101 lut_xml -> addLut( _config );
102 lut_xml -> addLut( _config );
103 lut_xml -> addLut( _config );
106 return lut_xml->getCurrentBrick();
114 sscanf(number.c_str(),
"%d", &
result);
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;
135 std::cout <<
"===> Test of HcalLutSet HcalLutManager::getLutSetFromFile( std::string _filename )" << std::endl << 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++){
165 ifstream
infile( _filename . c_str() );
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...";
173 getline( infile, _lutset .
label );
177 getline( infile, buf );
182 std::vector<std::string> buf_vec;
183 getline( infile, buf );
185 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
190 getline( infile, buf );
192 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
197 getline( infile, buf );
199 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
204 getline( infile, buf );
206 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
212 getline( infile, buf );
214 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
219 getline( infile, buf );
221 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
226 bool first_lut_entry =
true;
227 while ( getline( infile, buf ) > 0 ){
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);
236 first_lut_entry =
false;
249 std::cout <<
"Generating linearization (input) LUTs from ascii master file..." << std::endl;
250 std::map<int, boost::shared_ptr<LutXml> > _xml;
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;
260 int lut_set_size = _set.
lut.size();
264 for( std::map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
270 for (
int i=0;
i<lut_set_size;
i++ ){
271 if ( (row->second.crate == _crate || _crate == -1) &&
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 &&
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())) );
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())) );
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;
299 _cfg.
fiber = row->second.htr_fi;
301 if (_set.
lut[lut_index].size() == 128) _cfg.
lut_type = 1;
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 );
320 _xml[0]->addLut( _cfg, lut_checksums_xml );
326 std::cout <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
335 std::cout <<
"Generating linearization (input) LUTs from ascii master file..." << std::endl;
336 std::map<int, boost::shared_ptr<LutXml> > _xml;
339 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
340 std::cout <<
"EMap contains " << _map .
size() <<
" entries" << std::endl;
344 int lut_set_size = _set.
lut.size();
345 std::cout <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file" << std::endl;
348 std::vector<unsigned int> zeroLut;
349 for (
size_t adc = 0;
adc < 128;
adc++) zeroLut.push_back(0);
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
365 for (
int i=0;
i<lut_set_size;
i++ ){
366 if ( (row->crate == _crate || _crate == -1) &&
373 _set.
subdet[
i].find(row->subdet)!=string::npos ){
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())) );
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())) );
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;
404 (row->ieta>0)*100 +
abs(row->ieta) +
405 (((row->subdet.find(
"HF")!=string::npos) &&
abs(row->ieta)==29)?(4*10000):(0));
408 DetId _detId(row->rawId);
409 uint32_t status_word = cq->getValues(_detId)->getValue();
410 if ((status_word & status_word_to_mask) > 0){
414 _cfg.
lut = _set.
lut[lut_index];
416 if (split_by_crate ){
417 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
421 _xml[0]->addLut( _cfg, lut_checksums_xml );
428 std::cout <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
435 std::cout <<
"Generating linearization (input) LUTs from ascii master file..." << std::endl;
436 std::map<int, boost::shared_ptr<LutXml> > _xml;
440 int lut_set_size = _set.
lut.size();
441 std::cout <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file" << std::endl;
445 for( _iter.begin(); !_iter.end(); _iter.next() ){
452 int _ieta = _iter.getIeta();
453 int _iphi = _iter.getIphi();
454 int _depth = _iter.getDepth();
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();
469 for (
int i=0;
i<lut_set_size;
i++ ){
470 if ( (aCrate == _crate || _crate == -1) &&
477 _set.
subdet[
i].find(_ass.getSubdetectorString(_subdet))!=string::npos ){
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())) );
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())) );
506 (_ieta>0)*100 +
abs(_ieta) +
508 _cfg.
lut = _set.
lut[lut_index];
509 if (split_by_crate ){
510 _xml[aCrate]->addLut( _cfg, lut_checksums_xml );
514 _xml[0]->addLut( _cfg, lut_checksums_xml );
521 std::cout <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
528 std::cout <<
"Generating compression (output) LUTs from ascii master file..." << std::endl;
529 std::map<int, boost::shared_ptr<LutXml> > _xml;
531 std::cout <<
"instantiating CaloTPGTranscoderULUT in order to check the validity of (ieta,iphi)..." << std::endl;
537 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
538 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
542 int lut_set_size = _set.
lut.size();
543 std::cout <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file" << std::endl;
547 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
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) &&
560 _coder.
HTvalid(row->ieta, row->iphi) ){
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())) );
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())) );
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;
581 if (_set.
lut[lut_index].size() == 128) _cfg.
lut_type = 1;
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 );
599 _xml[0]->addLut( _cfg, lut_checksums_xml );
605 std::cout <<
"Generating compression (output) LUTs from ascii master file...DONE" << std::endl;
612 std::cout <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder..." << std::endl;
613 std::map<int, boost::shared_ptr<LutXml> > _xml;
620 _lmap .
read(
"backup/HCALmapHBEF.txt",
"HBEF" );
623 std::map<int,LMapRow> & _map = _lmap.
get_map();
624 std::cout <<
"LMap contains " << _map .
size() <<
" channels" << std::endl;
632 for( std::map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
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())) );
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())) );
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;
651 _cfg.
fiber = row->second.htr_fi;
663 (row->second.side>0)*100 + row->second.eta +
664 ((row->second.det==
HcalForward && row->second.eta==29)?(4*10000):(0));
667 HcalDetId _detid(row->second.det, row->second.side*row->second.eta, row->second.phi, row->second.depth);
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);
676 _cfg.
lut.push_back(_temp);
678 if (split_by_crate ){
679 _xml[row->second.crate]->addLut( _cfg, lut_checksums_xml );
683 _xml[0]->addLut( _cfg, lut_checksums_xml );
688 std::cout <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
697 std::cout <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder..." << std::endl;
698 std::map<int, boost::shared_ptr<LutXml> > _xml;
701 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
702 std::cout <<
"EMap contains " << _map .
size() <<
" entries" << std::endl;
704 std::vector<unsigned int> zeroLut;
705 for (
size_t adc = 0;
adc < 128;
adc++) zeroLut.push_back(0);
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
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())) );
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())) );
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;
743 (row->ieta>0)*100 +
abs(row->ieta) +
744 (((row->subdet.find(
"HF")!=string::npos) &&
abs(row->ieta)==29)?(4*10000):(0));
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;
751 HcalDetId _detid(_subdet, row->ieta, row->iphi, row->idepth);
754 uint32_t status_word = cq->getValues(_detid)->getValue();
755 if ((status_word & status_word_to_mask) > 0){
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);
765 if (split_by_crate ){
766 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
770 _xml[0]->addLut( _cfg, lut_checksums_xml );
776 std::cout <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
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;
791 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
792 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
800 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
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())) );
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())) );
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;
832 (row->ieta>0)*100+
abs(row->ieta);
839 for (std::vector<unsigned char>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
840 unsigned int _temp = (
unsigned int)(*_i);
843 _cfg.
lut.push_back(_temp);
847 if (split_by_crate ){
848 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
852 _xml[0]->addLut( _cfg, lut_checksums_xml );
858 std::cout <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE" << std::endl;
866 std::cout <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT" << std::endl;
867 std::map<int, boost::shared_ptr<LutXml> > _xml;
874 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
875 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
885 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
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())) );
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())) );
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;
917 (row->ieta>0)*100+
abs(row->ieta);
924 for (std::vector<unsigned char>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
925 unsigned int _temp = (
unsigned int)(*_i);
928 _cfg.
lut.push_back(_temp);
932 if (split_by_crate ){
933 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
937 _xml[0]->addLut( _cfg, lut_checksums_xml );
943 std::cout <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE" << std::endl;
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";
957 output_file_name << _tag <<
".xml";
959 cr->second->write( output_file_name.str().c_str() );
967 std::map<int, boost::shared_ptr<LutXml> > xml;
968 if ( !lut_checksums_xml ){
969 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
972 if ( _lin_file.size() != 0 ){
973 addLutMap( xml, getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate ) );
975 writeLutXmlFiles( xml, _tag, split_by_crate );
977 std::string checksums_file = _tag +
"_checksums.xml";
978 lut_checksums_xml ->
write( checksums_file . c_str() );
986 std::map<int, boost::shared_ptr<LutXml> > xml;
987 if ( !lut_checksums_xml ){
988 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
991 if ( _lin_file.size() != 0 ){
993 addLutMap( xml, getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate ) );
995 if ( _comp_file.size() != 0 ){
997 addLutMap( xml, getCompressionLutXmlFromAsciiMaster( _comp_file, _tag, -1, split_by_crate ) );
1000 writeLutXmlFiles( xml, _tag, split_by_crate );
1002 std::string checksums_file = _tag +
"_checksums.xml";
1003 lut_checksums_xml ->
write( checksums_file . c_str() );
1011 std::map<int, boost::shared_ptr<LutXml> > xml;
1012 if ( !lut_checksums_xml ){
1013 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1016 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1018 writeLutXmlFiles( xml, _tag, split_by_crate );
1020 std::string checksums_file = _tag +
"_checksums.xml";
1021 lut_checksums_xml ->
write( checksums_file . c_str() );
1029 std::map<int, boost::shared_ptr<LutXml> > xml;
1030 if ( !lut_checksums_xml ){
1031 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1035 addLutMap( xml, getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate ) );
1036 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1038 writeLutXmlFiles( xml, _tag, split_by_crate );
1040 std::string checksums_file = _tag +
"_checksums.xml";
1041 lut_checksums_xml ->
write( checksums_file . c_str() );
1051 std::map<int, boost::shared_ptr<LutXml> > xml;
1052 if ( !lut_checksums_xml ){
1053 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
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 );
1060 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1061 addLutMap( xml, _lin_lut_xml );
1063 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _transcoder, _tag, split_by_crate );
1064 addLutMap( xml, _comp_lut_xml );
1066 writeLutXmlFiles( xml, _tag, split_by_crate );
1068 std::string checksums_file = _tag +
"_checksums.xml";
1069 lut_checksums_xml ->
write( checksums_file . c_str() );
1077 std::map<int, boost::shared_ptr<LutXml> > xml;
1078 if ( !lut_checksums_xml ){
1079 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
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 );
1086 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1087 addLutMap( xml, _lin_lut_xml );
1089 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _tag, split_by_crate );
1090 addLutMap( xml, _comp_lut_xml );
1092 writeLutXmlFiles( xml, _tag, split_by_crate );
1094 std::string checksums_file = _tag +
"_checksums.xml";
1095 lut_checksums_xml ->
write( checksums_file . c_str() );
1105 std::map<int, boost::shared_ptr<LutXml> > xml;
1106 if ( !lut_checksums_xml ){
1107 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1110 if ( _lin_file.size() != 0 ){
1111 addLutMap( xml, getLutXmlFromAsciiMaster( _lin_file, _tag, -1, split_by_crate ) );
1113 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1114 writeLutXmlFiles( xml, _tag, split_by_crate );
1116 std::string checksums_file = _tag +
"_checksums.xml";
1117 lut_checksums_xml ->
write( checksums_file . c_str() );
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;
1144 strftime( timebuf, 50,
"%Y-%m-%d %H:%M:%S", gmtime( &_time ) );
1145 std::string creationstamp = timebuf;
1147 return creationstamp;
1155 local_connect( _filename,
"backup/HCALmapHBEF.txt",
"backup/HCALmapHO.txt" );
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;
1164 std::vector<unsigned int> _lut;
1165 _lut = getLutFromXml( _tag, 1107313727, hcal::ConfigurationDatabase::LinearizerLUT );
1168 std::cout << std::endl <<
"Testing direct parsing of the LUT XML" << std::endl;
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;
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;
1183 for (
int _iter=0; _iter<100; _iter++){
1184 gettimeofday( &_t,
NULL );
1189 int _key = (
rand() % map_size);
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
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;
1203 HcalDetId _detid(_subdet, _map[_key].ieta, _map[_key].iphi, _map[_key].idepth);
1204 _raw_id = _detid.
rawId();
1208 _lut = getLutFromXml( _tag, _raw_id, hcal::ConfigurationDatabase::LinearizerLUT );
1210 gettimeofday( &_t,
NULL );
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;
1217 for ( std::vector<unsigned int>::const_iterator
i = _lut .
end() - 1;
i != _lut .
begin()-1;
i-- )
1219 std::cout << (
i-_lut.begin()) <<
" " << _lut[(
i-_lut.begin())] << std::endl;
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;
1259 read_lmap( lmap_hbef_file, lmap_ho_file );
1260 read_luts( lut_xml_file );
1269 std::cout <<
"getLutFromXml (new version) is not implemented. Use getLutFromXml_old() for now" << std::endl;
1271 std::vector<unsigned int>
result;
1283 std::cout <<
"HcalLutManager: cannot find LUT without LMAP, exiting..." << std::endl;
1287 std::cout <<
"HcalLutManager: cannot find LUT, no source (local XML file), exiting..." << std::endl;
1291 std::vector<unsigned int>
result;
1293 std::map<int,LMapRow> & _map = lmap -> get_map();
1298 unsigned int _crate, _slot, _fiber, _channel;
1300 int topbottom, luttype;
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;
1310 if ( _fpga .
find(
"top") != std::string::npos ) topbottom = 1;
1311 else if ( _fpga .
find(
"bot") != std::string::npos ) topbottom = 0;
1313 std::cout <<
"HcalLutManager: irregular LMAP fpga value... do not know what to do - exiting" << std::endl;
1316 if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
1319 result =
db -> getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
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 );
1335 for(
std::map<
int, boost::shared_ptr<LutXml> >::const_iterator xml = lut_map.begin(); xml != lut_map.end(); xml++ ){
1336 result += *(xml->second);
1338 std::stringstream out_file;
1339 out_file << tag <<
".xml";
1340 result .
write(out_file.str());
1352 oracle::occi::Connection * _connection = db -> getConnection();
1354 std::cout <<
"Preparing to request the LUT CLOBs from the database..." << std::endl;
1362 std::string
query = (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB, CRATE FROM CMS_HCL_HCAL_COND.V_HCAL_TRIG_LOOKUP_TABLES");
1366 std::string brick_set;
1368 std::map<int, boost::shared_ptr<LutXml> > lut_map;
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;
1377 std::cout <<
"Processing the query results..." << std::endl;
1379 while (rs->next()) {
1381 oracle::occi::Clob clob = rs->getClob (1);
1382 int crate = rs->getInt(2);
1384 cout <<
"Getting LUTs for crate #" << crate <<
" out of the database...";
1385 brick_set = db -> clobToString(clob);
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;
1403 _connection -> terminateStatement(stmt);
1406 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
1419 std::cout <<
"Generating XML loader for LUTs..." << std::endl;
1426 baseConf . tag_name = tag_name;
1428 baseConf . comment_description =
comment;
1429 baseConf . iov_begin =
"1";
1430 baseConf . iov_end =
"-1";
1434 std::stringstream _subversion;
1435 _subversion << subversion;
1436 conf . subversion = _subversion.str();
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;
1445 std::vector<int> crate_number;
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)));
1457 sprintf( _buf,
"%d", (uint32_t)_offset );
1462 for ( std::vector<std::string>::const_iterator _file = file_name .
begin(); _file != file_name .
end(); _file++ )
1464 conf . trig_prim_lookuptbl_data_file = *_file;
1466 conf . crate = crate_number[ _file - file_name .
begin() ];
1470 sprintf( _buf,
"%.2d", conf.
crate );
1473 sprintf( _buf,
"CRATE%.2d", conf . crate );
1474 std::string _namelabel;
1475 _namelabel .
append( _buf );
1476 conf . name_label = _namelabel;
1477 doc . addLUT( &conf );
1480 doc . addChecksums( &CSconf );
1482 doc .
write( tag_name +
"_Loader.xml" );
1484 std::cout <<
"Generating XML loader for LUTs... done." << std::endl;
1494 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
1495 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
1499 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
1502 if ( row->subdet .
find(
"HT") != std::string::npos ){
1503 std::cout <<
" -----> Subdet = " << row->subdet << std::endl;
1505 if (
abs(row->ieta)>28){
1507 cout <<
" ==> (ieta,iphi) = " << row->ieta <<
", " << row->iphi << std::endl;
1552 std::map<int, boost::shared_ptr<LutXml> > xml;
1553 if ( !lut_checksums_xml ){
1554 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
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 );
1561 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1562 addLutMap( xml, _lin_lut_xml );
1564 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _transcoder, _tag, split_by_crate );
1565 addLutMap( xml, _comp_lut_xml );
1567 const std::map<int, boost::shared_ptr<LutXml> > _zdc_lut_xml = getZdcLutXml( _tag, split_by_crate );
1568 addLutMap( xml, _zdc_lut_xml );
1570 writeLutXmlFiles( xml, _tag, split_by_crate );
1572 std::string checksums_file = _tag +
"_checksums.xml";
1573 lut_checksums_xml ->
write( checksums_file . c_str() );
1580 bool split_by_crate )
1582 std::cout <<
"Generating ZDC LUTs ...may the Force be with us..." << std::endl;
1583 std::map<int, boost::shared_ptr<LutXml> > _xml;
1589 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
1590 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
1594 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
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())) );
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())) );
1606 _cfg.
ieta = row->zdc_channel;
1609 _cfg.
depth = row->idepth;
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;
1626 std::vector<int> coder_lut = zdc.
get_lut(row->zdc_section,
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);
1635 _cfg.
lut.push_back(_temp);
1639 if (split_by_crate ){
1640 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
1644 _xml[0]->addLut( _cfg, lut_checksums_xml );
1651 std::cout <<
"Generating ZDC LUTs...DONE" << std::endl;
int adc(sample_type sample)
get the ADC sample (12 bits)
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)
std::string targetfirmware
static int getLutSetFromFile_test(std::string _filename)
std::vector< int > phi_max
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.
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.
std::vector< int > phi_min
std::vector< int > depth_max
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
int getInt(ResultSet *rset, int ipar)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
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
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)
uint32_t rawId() const
get the raw id
int test_direct_xml_parsing(std::string _filename)
std::vector< unsigned int > lut
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)
int read_luts(std::string lut_xml_file)
std::vector< int > depth_min
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)
std::string formatrevision
virtual bool HTvalid(const int ieta, const int iphi) const
std::string toString(const std::pair< T, T > &aT)
Gather config data from online DB.
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)
oracle::occi::ResultSet ResultSet
static int getInt(std::string number)
static std::string get_time_stamp(time_t _time)
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)
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)
int read_lmap(std::string lmap_hbef_file, std::string lmap_ho_file)
bool insert(Storage &, ItemType *, const IdTag &)
std::string creationstamp
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)
tuple size
Write out results.
std::vector< int > eta_min
static XMLProcessor * getInstance()
int createAllLutXmlFilesFromCoder(const HcalTPGCoder &_coder, std::string _tag, bool split_by_crate=true)
std::vector< unsigned int > getLutFromXml_old(std::string tag, uint32_t _rawid, hcal::ConfigurationDatabase::LUTType _lt)