12 #include <toolbox/string.h>
30 XERCES_CPP_NAMESPACE_USE
32 using namespace oracle::occi;
58 uint32_t _status_word_to_mask)
63 status_word_to_mask = _status_word_to_mask;
70 lut_checksums_xml = 0;
75 status_word_to_mask = 0x0000;
83 delete lut_checksums_xml;
99 if (lut_xml)
delete lut_xml;
105 lut_xml -> addLut( _config );
106 lut_xml -> addLut( _config );
107 lut_xml -> addLut( _config );
110 return lut_xml->getCurrentBrick();
118 sscanf(number.c_str(),
"%d", &
result);
125 if ( _det.find(
"HB") != std::string::npos ) result =
HcalBarrel;
126 else if ( _det.find(
"HE") != std::string::npos ) result =
HcalEndcap;
127 else if ( _det.find(
"HF") != std::string::npos ) result =
HcalForward;
128 else if ( _det.find(
"HO") != std::string::npos ) result =
HcalOuter;
139 std::cout <<
"===> Test of HcalLutSet HcalLutManager::getLutSetFromFile( std::string _filename )" << std::endl << std::endl;
155 for (
unsigned int j = 0;
j != _set.
lut[0].size();
j++){
156 for (
unsigned int i = 0;
i != _set.
lut.size();
i++){
169 ifstream
infile( _filename . c_str() );
172 if ( infile . is_open() ){
173 std::cout <<
"File " << _filename <<
" is open..." << std::endl;
174 std::cout <<
"Reading LUTs and their eta/phi/depth/subdet ranges...";
177 getline( infile, _lutset .
label );
181 getline( infile, buf );
186 std::vector<std::string> buf_vec;
187 getline( infile, buf );
189 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
194 getline( infile, buf );
196 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
201 getline( infile, buf );
203 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
208 getline( infile, buf );
210 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
216 getline( infile, buf );
218 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
223 getline( infile, buf );
225 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
230 bool first_lut_entry =
true;
231 while (getline( infile, buf )) {
233 for (
unsigned int i = 0;
i < buf_vec.size();
i++){
234 if (first_lut_entry){
235 std::vector<unsigned int> _l;
236 _lutset.
lut.push_back(_l);
240 first_lut_entry =
false;
253 std::cout <<
"Generating linearization (input) LUTs from ascii master file..." << std::endl;
254 std::map<int, boost::shared_ptr<LutXml> > _xml;
257 _lmap .
read(
"./backup/HCALmapHBEF.txt",
"HBEF" );
258 _lmap .
read(
"./backup/HCALmapHO.txt",
"HO" );
259 std::map<int,LMapRow> & _map = _lmap.
get_map();
260 std::cout <<
"LMap contains " << _map .
size() <<
" channels" << std::endl;
264 int lut_set_size = _set.
lut.size();
268 for( std::map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
274 for (
int i=0;
i<lut_set_size;
i++ ){
275 if ( (row->second.crate == _crate || _crate == -1) &&
276 _set.
eta_min[
i] <= row->second.side*row->second.eta &&
277 _set.
eta_max[
i] >= row->second.side*row->second.eta &&
278 _set.
phi_min[
i] <= row->second.phi &&
279 _set.
phi_max[
i] >= row->second.phi &&
286 if ( lut_index >= 0 ){
287 if ( _xml.count(row->second.crate) == 0 && split_by_crate ){
288 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->second.crate,boost::shared_ptr<LutXml>(
new LutXml())) );
290 else if ( _xml.count(0) == 0 && !split_by_crate ){
291 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
293 _cfg.
ieta = row->second.side*row->second.eta;
294 _cfg.
iphi = row->second.phi;
295 _cfg.
depth = row->second.depth;
296 _cfg.
crate = row->second.crate;
297 _cfg.
slot = row->second.htr;
298 if (row->second.fpga .
find(
"top") != std::string::npos) _cfg.
topbottom = 1;
299 else if (row->second.fpga .
find(
"bot") != std::string::npos) _cfg.
topbottom = 0;
300 else std::cout <<
"Warning! fpga out of range..." << std::endl;
303 _cfg.
fiber = row->second.htr_fi;
305 if (_set.
lut[lut_index].size() == 128) _cfg.
lut_type = 1;
316 (row->second.side>0)*100 + row->second.eta +
317 ((row->second.det==
HcalForward && row->second.eta==29)?(4*10000):(0));
318 _cfg.
lut = _set.
lut[lut_index];
319 if (split_by_crate ){
320 _xml[row->second.crate]->addLut( _cfg, lut_checksums_xml );
324 _xml[0]->addLut( _cfg, lut_checksums_xml );
330 std::cout <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
339 std::cout <<
"Generating linearization (input) LUTs from ascii master file..." << std::endl;
340 std::map<int, boost::shared_ptr<LutXml> > _xml;
343 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
344 std::cout <<
"EMap contains " << _map .
size() <<
" entries" << std::endl;
348 int lut_set_size = _set.
lut.size();
349 std::cout <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file" << std::endl;
352 std::vector<unsigned int> zeroLut;
353 for (
size_t adc = 0;
adc < 128;
adc++) zeroLut.push_back(0);
357 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
358 if( (row->subdet.find(
"HB")!=string::npos ||
359 row->subdet.find(
"HE")!=string::npos ||
360 row->subdet.find(
"HO")!=string::npos ||
361 row->subdet.find(
"HF")!=string::npos ) &&
362 row->subdet.size()==2
369 for (
int i=0;
i<lut_set_size;
i++ ){
370 if ( (row->crate == _crate || _crate == -1) &&
377 _set.
subdet[
i].find(row->subdet)!=string::npos ){
381 if ( lut_index >= 0 ){
382 if ( _xml.count(row->crate) == 0 && split_by_crate ){
383 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
385 else if ( _xml.count(0) == 0 && !split_by_crate ){
386 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
388 _cfg.
ieta = row->ieta;
389 _cfg.
iphi = row->iphi;
390 _cfg.
depth = row->idepth;
391 _cfg.
crate = row->crate;
392 _cfg.
slot = row->slot;
393 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
394 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
395 else std::cout <<
"Warning! fpga out of range..." << std::endl;
396 _cfg.
fiber = row->fiber;
408 (row->ieta>0)*100 +
abs(row->ieta) +
409 (((row->subdet.find(
"HF")!=string::npos) &&
abs(row->ieta)==29)?(4*10000):(0));
412 DetId _detId(row->rawId);
413 uint32_t status_word = cq->getValues(_detId)->getValue();
414 if ((status_word & status_word_to_mask) > 0){
418 _cfg.
lut = _set.
lut[lut_index];
420 if (split_by_crate ){
421 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
425 _xml[0]->addLut( _cfg, lut_checksums_xml );
432 std::cout <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
439 std::cout <<
"Generating linearization (input) LUTs from ascii master file..." << std::endl;
440 std::map<int, boost::shared_ptr<LutXml> > _xml;
444 int lut_set_size = _set.
lut.size();
445 std::cout <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file" << std::endl;
449 for( _iter.begin(); !_iter.end(); _iter.next() ){
456 int _ieta = _iter.getIeta();
457 int _iphi = _iter.getIphi();
458 int _depth = _iter.getDepth();
462 int aCrate = _eId . readoutVMECrateId();
463 int aSlot = _eId . htrSlot();
464 int aTopBottom = _eId . htrTopBottom();
465 int aFiber = _eId . fiberIndex();
466 int aFiberChan = _eId . fiberChanId();
473 for (
int i=0;
i<lut_set_size;
i++ ){
474 if ( (aCrate == _crate || _crate == -1) &&
481 _set.
subdet[
i].find(_ass.getSubdetectorString(_subdet))!=string::npos ){
485 if ( lut_index >= 0 ){
486 if ( _xml.count(aCrate) == 0 && split_by_crate ){
487 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(aCrate,boost::shared_ptr<LutXml>(
new LutXml())) );
489 else if ( _xml.count(0) == 0 && !split_by_crate ){
490 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
510 (_ieta>0)*100 +
abs(_ieta) +
512 _cfg.
lut = _set.
lut[lut_index];
513 if (split_by_crate ){
514 _xml[aCrate]->addLut( _cfg, lut_checksums_xml );
518 _xml[0]->addLut( _cfg, lut_checksums_xml );
525 std::cout <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
532 std::cout <<
"Generating compression (output) LUTs from ascii master file..." << std::endl;
533 std::map<int, boost::shared_ptr<LutXml> > _xml;
535 std::cout <<
"instantiating CaloTPGTranscoderULUT in order to check the validity of (ieta,iphi)..." << std::endl;
541 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
542 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
546 int lut_set_size = _set.
lut.size();
547 std::cout <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file" << std::endl;
551 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
557 for (
int i=0;
i<lut_set_size;
i++ ){
558 if ( row->subdet .
find(
"HT") != std::string::npos &&
559 (row->crate == _crate || _crate == -1) &&
564 _coder.
HTvalid(row->ieta, row->iphi) ){
568 if ( lut_index >= 0 ){
569 if ( _xml.count(row->crate) == 0 && split_by_crate ){
570 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
572 else if ( _xml.count(0) == 0 && !split_by_crate ){
573 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
575 _cfg.
ieta = row->ieta;
576 _cfg.
iphi = row->iphi;
577 _cfg.
depth = row->idepth;
578 _cfg.
crate = row->crate;
579 _cfg.
slot = row->slot;
580 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
581 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
582 else std::cout <<
"Warning! fpga out of range..." << std::endl;
583 _cfg.
fiber = row->fiber;
585 if (_set.
lut[lut_index].size() == 128) _cfg.
lut_type = 1;
596 (row->ieta>0)*100+
abs(row->ieta);
597 _cfg.
lut = _set.
lut[lut_index];
598 if (split_by_crate ){
599 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
603 _xml[0]->addLut( _cfg, lut_checksums_xml );
609 std::cout <<
"Generating compression (output) LUTs from ascii master file...DONE" << std::endl;
616 std::cout <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder..." << std::endl;
617 std::map<int, boost::shared_ptr<LutXml> > _xml;
624 _lmap .
read(
"backup/HCALmapHBEF.txt",
"HBEF" );
627 std::map<int,LMapRow> & _map = _lmap.
get_map();
628 std::cout <<
"LMap contains " << _map .
size() <<
" channels" << std::endl;
636 for( std::map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
639 if ( _xml.count(row->second.crate) == 0 && split_by_crate ){
640 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->second.crate,boost::shared_ptr<LutXml>(
new LutXml())) );
642 else if ( _xml.count(0) == 0 && !split_by_crate ){
643 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
645 _cfg.
ieta = row->second.side*row->second.eta;
646 _cfg.
iphi = row->second.phi;
647 _cfg.
depth = row->second.depth;
648 _cfg.
crate = row->second.crate;
649 _cfg.
slot = row->second.htr;
650 if (row->second.fpga .
find(
"top") != std::string::npos) _cfg.
topbottom = 1;
651 else if (row->second.fpga .
find(
"bot") != std::string::npos) _cfg.
topbottom = 0;
652 else std::cout <<
"Warning! fpga out of range..." << std::endl;
655 _cfg.
fiber = row->second.htr_fi;
667 (row->second.side>0)*100 + row->second.eta +
668 ((row->second.det==
HcalForward && row->second.eta==29)?(4*10000):(0));
671 HcalDetId _detid(row->second.det, row->second.side*row->second.eta, row->second.phi, row->second.depth);
675 std::vector<unsigned short> coder_lut = _coder . getLinearizationLUT(_detid);
676 for (std::vector<unsigned short>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
677 unsigned int _temp = (
unsigned int)(*_i);
680 _cfg.
lut.push_back(_temp);
682 if (split_by_crate ){
683 _xml[row->second.crate]->addLut( _cfg, lut_checksums_xml );
687 _xml[0]->addLut( _cfg, lut_checksums_xml );
692 std::cout <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
701 std::cout <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder..." << std::endl;
702 std::map<int, boost::shared_ptr<LutXml> > _xml;
705 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
706 std::cout <<
"EMap contains " << _map .
size() <<
" entries" << std::endl;
708 std::vector<unsigned int> zeroLut;
709 for (
size_t adc = 0;
adc < 128;
adc++) zeroLut.push_back(0);
713 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
714 if( (row->subdet.find(
"HB")!=string::npos ||
715 row->subdet.find(
"HE")!=string::npos ||
716 row->subdet.find(
"HF")!=string::npos ) &&
717 row->subdet.size()==2
721 if ( _xml.count(row->crate) == 0 && split_by_crate ){
722 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
724 else if ( _xml.count(0) == 0 && !split_by_crate ){
725 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
727 _cfg.
ieta = row->ieta;
728 _cfg.
iphi = row->iphi;
729 _cfg.
depth = row->idepth;
730 _cfg.
crate = row->crate;
731 _cfg.
slot = row->slot;
732 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
733 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
734 else std::cout <<
"Warning! fpga out of range..." << std::endl;
735 _cfg.
fiber = row->fiber;
747 (row->ieta>0)*100 +
abs(row->ieta) +
748 (((row->subdet.find(
"HF")!=string::npos) &&
abs(row->ieta)==29)?(4*10000):(0));
750 if ( row->subdet.find(
"HB")!=string::npos ) _subdet =
HcalBarrel;
751 else if ( row->subdet.find(
"HE")!=string::npos ) _subdet =
HcalEndcap;
752 else if ( row->subdet.find(
"HO")!=string::npos ) _subdet =
HcalOuter;
753 else if ( row->subdet.find(
"HF")!=string::npos ) _subdet =
HcalForward;
755 HcalDetId _detid(_subdet, row->ieta, row->iphi, row->idepth);
758 uint32_t status_word = cq->getValues(_detid)->getValue();
759 if ((status_word & status_word_to_mask) > 0){
763 std::vector<unsigned short> coder_lut = _coder . getLinearizationLUT(_detid);
764 for (std::vector<unsigned short>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
765 unsigned int _temp = (
unsigned int)(*_i);
766 _cfg.
lut.push_back(_temp);
769 if (split_by_crate ){
770 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
774 _xml[0]->addLut( _cfg, lut_checksums_xml );
780 std::cout <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
788 std::cout <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT," << std::endl;
789 std::cout <<
"initialized from Event Setup" << std::endl;
790 std::map<int, boost::shared_ptr<LutXml> > _xml;
795 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
796 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
804 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
809 if ( row->subdet .
find(
"HT") != std::string::npos && _coder.
HTvalid(row->ieta, row->iphi) ){
810 if ( _xml.count(row->crate) == 0 && split_by_crate ){
811 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
813 else if ( _xml.count(0) == 0 && !split_by_crate ){
814 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
816 _cfg.
ieta = row->ieta;
817 _cfg.
iphi = row->iphi;
818 _cfg.
depth = row->idepth;
819 _cfg.
crate = row->crate;
820 _cfg.
slot = row->slot;
821 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
822 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
823 else std::cout <<
"Warning! fpga out of range..." << std::endl;
824 _cfg.
fiber = row->fiber;
836 (row->ieta>0)*100+
abs(row->ieta);
843 for (std::vector<unsigned char>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
844 unsigned int _temp = (
unsigned int)(*_i);
847 _cfg.
lut.push_back(_temp);
851 if (split_by_crate ){
852 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
856 _xml[0]->addLut( _cfg, lut_checksums_xml );
862 std::cout <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE" << std::endl;
870 std::cout <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT" << std::endl;
871 std::map<int, boost::shared_ptr<LutXml> > _xml;
878 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
879 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
889 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
894 if ( row->subdet .
find(
"HT") != std::string::npos && _coder.
HTvalid(row->ieta, row->iphi) ){
895 if ( _xml.count(row->crate) == 0 && split_by_crate ){
896 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
898 else if ( _xml.count(0) == 0 && !split_by_crate ){
899 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
901 _cfg.
ieta = row->ieta;
902 _cfg.
iphi = row->iphi;
903 _cfg.
depth = row->idepth;
904 _cfg.
crate = row->crate;
905 _cfg.
slot = row->slot;
906 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
907 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
908 else std::cout <<
"Warning! fpga out of range..." << std::endl;
909 _cfg.
fiber = row->fiber;
921 (row->ieta>0)*100+
abs(row->ieta);
928 for (std::vector<unsigned char>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
929 unsigned int _temp = (
unsigned int)(*_i);
932 _cfg.
lut.push_back(_temp);
936 if (split_by_crate ){
937 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
941 _xml[0]->addLut( _cfg, lut_checksums_xml );
947 std::cout <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE" << std::endl;
955 for (
std::map<
int,boost::shared_ptr<LutXml> >::const_iterator cr = _xml.begin(); cr != _xml.end(); cr++){
957 if ( split_by_crate ){
958 output_file_name << _tag <<
"_" << cr->first <<
".xml";
961 output_file_name << _tag <<
".xml";
963 cr->second->write( output_file_name.str().c_str() );
971 std::map<int, boost::shared_ptr<LutXml> > xml;
972 if ( !lut_checksums_xml ){
973 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
976 if ( _lin_file.size() != 0 ){
977 addLutMap( xml, getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate ) );
979 writeLutXmlFiles( xml, _tag, split_by_crate );
981 std::string checksums_file = _tag +
"_checksums.xml";
982 lut_checksums_xml ->
write( checksums_file . c_str() );
990 std::map<int, boost::shared_ptr<LutXml> > xml;
991 if ( !lut_checksums_xml ){
992 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
995 if ( _lin_file.size() != 0 ){
997 addLutMap( xml, getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate ) );
999 if ( _comp_file.size() != 0 ){
1001 addLutMap( xml, getCompressionLutXmlFromAsciiMaster( _comp_file, _tag, -1, split_by_crate ) );
1004 writeLutXmlFiles( xml, _tag, split_by_crate );
1006 std::string checksums_file = _tag +
"_checksums.xml";
1007 lut_checksums_xml ->
write( checksums_file . c_str() );
1015 std::map<int, boost::shared_ptr<LutXml> > xml;
1016 if ( !lut_checksums_xml ){
1017 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1020 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1022 writeLutXmlFiles( xml, _tag, split_by_crate );
1024 std::string checksums_file = _tag +
"_checksums.xml";
1025 lut_checksums_xml ->
write( checksums_file . c_str() );
1033 std::map<int, boost::shared_ptr<LutXml> > xml;
1034 if ( !lut_checksums_xml ){
1035 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1039 addLutMap( xml, getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate ) );
1040 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1042 writeLutXmlFiles( xml, _tag, split_by_crate );
1044 std::string checksums_file = _tag +
"_checksums.xml";
1045 lut_checksums_xml ->
write( checksums_file . c_str() );
1055 std::map<int, boost::shared_ptr<LutXml> > xml;
1056 if ( !lut_checksums_xml ){
1057 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1060 if ( _lin_file.size() != 0 ){
1061 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1062 addLutMap( xml, _lin_lut_ascii_xml );
1064 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1065 addLutMap( xml, _lin_lut_xml );
1067 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _transcoder, _tag, split_by_crate );
1068 addLutMap( xml, _comp_lut_xml );
1070 writeLutXmlFiles( xml, _tag, split_by_crate );
1072 std::string checksums_file = _tag +
"_checksums.xml";
1073 lut_checksums_xml ->
write( checksums_file . c_str() );
1081 std::map<int, boost::shared_ptr<LutXml> > xml;
1082 if ( !lut_checksums_xml ){
1083 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1086 if ( _lin_file.size() != 0 ){
1087 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1088 addLutMap( xml, _lin_lut_ascii_xml );
1090 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1091 addLutMap( xml, _lin_lut_xml );
1093 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _tag, split_by_crate );
1094 addLutMap( xml, _comp_lut_xml );
1096 writeLutXmlFiles( xml, _tag, split_by_crate );
1098 std::string checksums_file = _tag +
"_checksums.xml";
1099 lut_checksums_xml ->
write( checksums_file . c_str() );
1109 std::map<int, boost::shared_ptr<LutXml> > xml;
1110 if ( !lut_checksums_xml ){
1111 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1114 if ( _lin_file.size() != 0 ){
1115 addLutMap( xml, getLutXmlFromAsciiMaster( _lin_file, _tag, -1, split_by_crate ) );
1117 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1118 writeLutXmlFiles( xml, _tag, split_by_crate );
1120 std::string checksums_file = _tag +
"_checksums.xml";
1121 lut_checksums_xml ->
write( checksums_file . c_str() );
1130 for (
std::map<
int, boost::shared_ptr<LutXml> >::const_iterator
lut=other.begin();
lut!=other.end();
lut++ ){
1131 std::cout <<
"Added LUTs for crate " <<
lut->first << std::endl;
1148 strftime( timebuf, 50,
"%Y-%m-%d %H:%M:%S", gmtime( &_time ) );
1151 return creationstamp;
1159 local_connect( _filename,
"backup/HCALmapHBEF.txt",
"backup/HCALmapHO.txt" );
1163 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
1164 int map_size = _map .
size();
1165 std::cout <<
"EMap contains " << map_size <<
" channels" << std::endl;
1168 std::vector<unsigned int> _lut;
1169 _lut = getLutFromXml( _tag, 1107313727, hcal::ConfigurationDatabase::LinearizerLUT );
1172 std::cout << std::endl <<
"Testing direct parsing of the LUT XML" << std::endl;
1174 gettimeofday( &_t,
NULL );
1175 double _time =(double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0;
1176 test_direct_xml_parsing(_filename);
1177 gettimeofday( &_t,
NULL );
1178 std::cout <<
"parsing took that much time: " << (double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0 - _time << std::endl;
1181 gettimeofday( &_t,
NULL );
1182 _time =(double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0;
1183 std::cout <<
"before loop over random LUTs: " << _time << std::endl;
1187 for (
int _iter=0; _iter<100; _iter++){
1188 gettimeofday( &_t,
NULL );
1193 int _key = (
rand() % map_size);
1195 if( (_map[_key].subdet.find(
"HB")!=string::npos ||
1196 _map[_key].subdet.find(
"HE")!=string::npos ||
1197 _map[_key].subdet.find(
"HO")!=string::npos ||
1198 _map[_key].subdet.find(
"HF")!=string::npos ) &&
1199 _map[_key].subdet.size()==2
1202 if ( _map[_key].subdet.find(
"HB")!=string::npos ) _subdet =
HcalBarrel;
1203 else if ( _map[_key].subdet.find(
"HE")!=string::npos ) _subdet =
HcalEndcap;
1204 else if ( _map[_key].subdet.find(
"HO")!=string::npos ) _subdet =
HcalOuter;
1205 else if ( _map[_key].subdet.find(
"HF")!=string::npos ) _subdet =
HcalForward;
1207 HcalDetId _detid(_subdet, _map[_key].ieta, _map[_key].iphi, _map[_key].idepth);
1208 _raw_id = _detid.
rawId();
1212 _lut = getLutFromXml( _tag, _raw_id, hcal::ConfigurationDatabase::LinearizerLUT );
1214 gettimeofday( &_t,
NULL );
1216 double d_time = _t.tv_sec+_t.tv_usec/1000000.0 - _time;
1217 std::cout <<
"after the loop over random LUTs: " << _time+d_time << std::endl;
1218 std::cout <<
"total time: " << d_time << std::endl;
1221 for ( std::vector<unsigned int>::const_iterator
i = _lut .
end() - 1;
i != _lut .
begin()-1;
i-- )
1223 std::cout << (
i-_lut.begin()) <<
" " << _lut[(
i-_lut.begin())] << std::endl;
1241 lmap ->
read( lmap_hbef_file,
"HBEF" );
1242 lmap ->
read( lmap_ho_file,
"HO" );
1243 std::cout <<
"LMap contains " << lmap -> get_map() .
size() <<
" channels (compare to 9072 of all HCAL channels)" << std::endl;
1263 read_lmap( lmap_hbef_file, lmap_ho_file );
1264 read_luts( lut_xml_file );
1273 std::cout <<
"getLutFromXml (new version) is not implemented. Use getLutFromXml_old() for now" << std::endl;
1275 std::vector<unsigned int>
result;
1287 std::cout <<
"HcalLutManager: cannot find LUT without LMAP, exiting..." << std::endl;
1291 std::cout <<
"HcalLutManager: cannot find LUT, no source (local XML file), exiting..." << std::endl;
1295 std::vector<unsigned int>
result;
1297 std::map<int,LMapRow> & _map = lmap -> get_map();
1302 unsigned int _crate, _slot, _fiber, _channel;
1304 int topbottom, luttype;
1307 if ( _map .
find(_rawid) != _map.end() ){
1308 _crate = _map[_rawid] . crate;
1309 _slot = _map[_rawid] . htr;
1310 _fiber = _map[_rawid] . htr_fi;
1311 _channel = _map[_rawid] . fi_ch;
1312 _fpga = _map[_rawid] . fpga;
1314 if ( _fpga .
find(
"top") != std::string::npos ) topbottom = 1;
1315 else if ( _fpga .
find(
"bot") != std::string::npos ) topbottom = 0;
1317 std::cout <<
"HcalLutManager: irregular LMAP fpga value... do not know what to do - exiting" << std::endl;
1320 if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
1323 result =
db -> getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
1333 std::map<int, boost::shared_ptr<LutXml> > lut_map = get_brickSet_from_oracle( tag, db_accessor );
1334 if (split_by_crate){
1335 writeLutXmlFiles( lut_map, tag, split_by_crate );
1339 for(
std::map<
int, boost::shared_ptr<LutXml> >::const_iterator xml = lut_map.begin(); xml != lut_map.end(); xml++ ){
1340 result += *(xml->second);
1342 std::stringstream out_file;
1343 out_file << tag <<
".xml";
1344 result .
write(out_file.str());
1356 oracle::occi::Connection * _connection = db -> getConnection();
1358 std::cout <<
"Preparing to request the LUT CLOBs from the database..." << std::endl;
1366 std::string query = (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB, CRATE FROM CMS_HCL_HCAL_COND.V_HCAL_TRIG_LOOKUP_TABLES");
1372 std::map<int, boost::shared_ptr<LutXml> > lut_map;
1376 std::cout <<
"Executing the query..." << std::endl;
1377 Statement* stmt = _connection -> createStatement();
1378 ResultSet *rs = stmt->executeQuery(query.c_str());
1379 std::cout <<
"Executing the query... done" << std::endl;
1381 std::cout <<
"Processing the query results..." << std::endl;
1383 while (rs->next()) {
1385 oracle::occi::Clob clob = rs->getClob (1);
1386 int crate = rs->getInt(2);
1388 cout <<
"Getting LUTs for crate #" << crate <<
" out of the database...";
1389 brick_set = db -> clobToString(clob);
1399 const char * bs = brick_set . c_str();
1400 MemBufInputSource * lut_clob =
new MemBufInputSource( (
const XMLByte *)bs, strlen( bs ),
"lut_clob",
false );
1401 boost::shared_ptr<LutXml> lut_xml = boost::shared_ptr<LutXml>(
new LutXml( *lut_clob ) );
1402 lut_map[crate] = lut_xml;
1407 _connection -> terminateStatement(stmt);
1410 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
1423 std::cout <<
"Generating XML loader for LUTs..." << std::endl;
1430 baseConf . tag_name = tag_name;
1432 baseConf . comment_description =
comment;
1433 baseConf . iov_begin =
"1";
1434 baseConf . iov_end =
"-1";
1438 std::stringstream _subversion;
1439 _subversion << subversion;
1440 conf . subversion = _subversion.str();
1442 CSconf . version = conf .
version;
1443 CSconf . subversion = conf . subversion;
1444 CSconf . trig_prim_lookuptbl_data_file = _prefix +
"_checksums.xml.dat";
1445 CSconf . comment_description = tag_name;
1449 std::vector<int> crate_number;
1451 for (std::vector<std::string>::const_iterator _f = file_name.begin(); _f != file_name.end(); _f++){
1452 int crate_begin = _f->rfind(
"_");
1453 int crate_end = _f->rfind(
".xml.dat");
1454 crate_number . push_back(
getInt(_f->substr(crate_begin+1,crate_end-crate_begin-1)));
1461 sprintf( _buf,
"%d", (uint32_t)_offset );
1466 for ( std::vector<std::string>::const_iterator _file = file_name .
begin(); _file != file_name .
end(); _file++ )
1468 conf . trig_prim_lookuptbl_data_file = *_file;
1470 conf . crate = crate_number[ _file - file_name .
begin() ];
1474 sprintf( _buf,
"%.2d", conf.
crate );
1477 sprintf( _buf,
"CRATE%.2d", conf . crate );
1479 _namelabel .
append( _buf );
1480 conf . name_label = _namelabel;
1481 doc . addLUT( &conf );
1484 doc . addChecksums( &CSconf );
1486 doc .
write( tag_name +
"_Loader.xml" );
1488 std::cout <<
"Generating XML loader for LUTs... done." << std::endl;
1498 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
1499 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
1503 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
1506 if ( row->subdet .
find(
"HT") != std::string::npos ){
1507 std::cout <<
" -----> Subdet = " << row->subdet << std::endl;
1509 if (
abs(row->ieta)>28){
1511 cout <<
" ==> (ieta,iphi) = " << row->ieta <<
", " << row->iphi << std::endl;
1556 std::map<int, boost::shared_ptr<LutXml> > xml;
1557 if ( !lut_checksums_xml ){
1558 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1561 if ( _lin_file.size() != 0 ){
1562 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1563 addLutMap( xml, _lin_lut_ascii_xml );
1565 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1566 addLutMap( xml, _lin_lut_xml );
1568 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _transcoder, _tag, split_by_crate );
1569 addLutMap( xml, _comp_lut_xml );
1571 const std::map<int, boost::shared_ptr<LutXml> > _zdc_lut_xml = getZdcLutXml( _tag, split_by_crate );
1572 addLutMap( xml, _zdc_lut_xml );
1574 writeLutXmlFiles( xml, _tag, split_by_crate );
1576 std::string checksums_file = _tag +
"_checksums.xml";
1577 lut_checksums_xml ->
write( checksums_file . c_str() );
1584 bool split_by_crate )
1586 std::cout <<
"Generating ZDC LUTs ...may the Force be with us..." << std::endl;
1587 std::map<int, boost::shared_ptr<LutXml> > _xml;
1593 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
1594 std::cout <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
1598 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
1602 if ( row->zdc_section .
find(
"ZDC") != std::string::npos ){
1603 if ( _xml.count(row->crate) == 0 && split_by_crate ){
1604 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
1606 else if ( _xml.count(0) == 0 && !split_by_crate ){
1607 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
1610 _cfg.
ieta = row->zdc_channel;
1613 _cfg.
depth = row->idepth;
1614 _cfg.
crate = row->crate;
1615 _cfg.
slot = row->slot;
1616 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
1617 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
1618 else std::cout <<
"Warning! fpga out of range..." << std::endl;
1619 _cfg.
fiber = row->fiber;
1630 std::vector<int> coder_lut = zdc.
get_lut(row->zdc_section,
1633 std::cout <<
"***DEBUG: ZDC lut size: " << coder_lut.size() << std::endl;
1634 if (coder_lut.size()!=0){
1635 for (std::vector<int>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
1636 unsigned int _temp = (
unsigned int)(*_i);
1639 _cfg.
lut.push_back(_temp);
1643 if (split_by_crate ){
1644 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
1648 _xml[0]->addLut( _cfg, lut_checksums_xml );
1655 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
Abs< T >::type abs(const T &t)
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)
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
std::string formatrevision
virtual bool HTvalid(const int ieta, const int iphi) const
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)
for(const auto &isodef:isoDefs)
std::string creationstamp
Readout chain identification for Hcal.
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)