12 #include <toolbox/string.h>
32 XERCES_CPP_NAMESPACE_USE
34 using namespace oracle::occi;
60 uint32_t _status_word_to_mask)
65 status_word_to_mask = _status_word_to_mask;
72 lut_checksums_xml = 0;
77 status_word_to_mask = 0x0000;
85 delete lut_checksums_xml;
101 if (lut_xml)
delete lut_xml;
107 lut_xml -> addLut( _config );
108 lut_xml -> addLut( _config );
109 lut_xml -> addLut( _config );
112 return lut_xml->getCurrentBrick();
120 sscanf(number.c_str(),
"%d", &
result);
127 if ( _det.find(
"HB") != std::string::npos ) result =
HcalBarrel;
128 else if ( _det.find(
"HE") != std::string::npos ) result =
HcalEndcap;
129 else if ( _det.find(
"HF") != std::string::npos ) result =
HcalForward;
130 else if ( _det.find(
"HO") != std::string::npos ) result =
HcalOuter;
142 s <<
"===> Test of HcalLutSet HcalLutManager::getLutSetFromFile( std::string _filename )" << std::endl << std::endl;
143 s << _set .
label << std::endl;
144 for (
unsigned int i = 0;
i != _set.
subdet.size();
i++) s << _set.
subdet[
i] <<
" ";
158 for (
unsigned int j = 0;
j != _set.
lut[0].size();
j++){
159 for (
unsigned int i = 0;
i != _set.
lut.size();
i++){
160 s << _set.
lut[
i][
j] <<
" ";
162 s <<
"---> " <<
j << std::endl;
173 ifstream
infile( _filename . c_str() );
176 if ( infile . is_open() ){
177 edm::LogInfo(
"HcalLutManager") <<
"File " << _filename <<
" is open..." << std::endl
178 <<
"Reading LUTs and their eta/phi/depth/subdet ranges...";
181 getline( infile, _lutset .
label );
185 getline( infile, buf );
190 std::vector<std::string> buf_vec;
191 getline( infile, buf );
193 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
198 getline( infile, buf );
200 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
205 getline( infile, buf );
207 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++){
220 getline( infile, buf );
222 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
227 getline( infile, buf );
229 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++){
234 bool first_lut_entry =
true;
235 while (getline( infile, buf )) {
237 for (
unsigned int i = 0;
i < buf_vec.size();
i++){
238 if (first_lut_entry){
239 std::vector<unsigned int> _l;
240 _lutset.
lut.push_back(_l);
244 first_lut_entry =
false;
257 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from ascii master file...";
258 std::map<int, boost::shared_ptr<LutXml> > _xml;
261 _lmap .
read(
"./backup/HCALmapHBEF.txt",
"HBEF" );
262 _lmap .
read(
"./backup/HCALmapHO.txt",
"HO" );
263 std::map<int,LMapRow> & _map = _lmap.
get_map();
264 edm::LogInfo(
"HcalLutManager") <<
"LMap contains " << _map .
size() <<
" channels";
268 int lut_set_size = _set.
lut.size();
272 for( std::map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
278 for (
int i=0;
i<lut_set_size;
i++ ){
279 if ( (row->second.crate == _crate || _crate == -1) &&
280 _set.
eta_min[
i] <= row->second.side*row->second.eta &&
281 _set.
eta_max[
i] >= row->second.side*row->second.eta &&
282 _set.
phi_min[
i] <= row->second.phi &&
283 _set.
phi_max[
i] >= row->second.phi &&
290 if ( lut_index >= 0 ){
291 if ( _xml.count(row->second.crate) == 0 && split_by_crate ){
292 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->second.crate,boost::shared_ptr<LutXml>(
new LutXml())) );
294 else if ( _xml.count(0) == 0 && !split_by_crate ){
295 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
297 _cfg.
ieta = row->second.side*row->second.eta;
298 _cfg.
iphi = row->second.phi;
299 _cfg.
depth = row->second.depth;
300 _cfg.
crate = row->second.crate;
301 _cfg.
slot = row->second.htr;
302 if (row->second.fpga .
find(
"top") != std::string::npos) _cfg.
topbottom = 1;
303 else if (row->second.fpga .
find(
"bot") != std::string::npos) _cfg.
topbottom = 0;
307 _cfg.
fiber = row->second.htr_fi;
309 if (_set.
lut[lut_index].size() == 128) _cfg.
lut_type = 1;
320 (row->second.side>0)*100 + row->second.eta +
321 ((row->second.det==
HcalForward && row->second.eta==29)?(4*10000):(0));
322 _cfg.
lut = _set.
lut[lut_index];
323 if (split_by_crate ){
324 _xml[row->second.crate]->addLut( _cfg, lut_checksums_xml );
328 _xml[0]->addLut( _cfg, lut_checksums_xml );
334 <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
343 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from ascii master file...";
344 std::map<int, boost::shared_ptr<LutXml> > _xml;
347 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
348 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map .
size() <<
" entries";
352 int lut_set_size = _set.
lut.size();
353 edm::LogInfo(
"HcalLutManager") <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file";
356 std::vector<unsigned int> zeroLut;
357 for (
size_t adc = 0;
adc < 128;
adc++) zeroLut.push_back(0);
361 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
362 if( (row->subdet.find(
"HB")!=string::npos ||
363 row->subdet.find(
"HE")!=string::npos ||
364 row->subdet.find(
"HO")!=string::npos ||
365 row->subdet.find(
"HF")!=string::npos ) &&
366 row->subdet.size()==2
373 for (
int i=0;
i<lut_set_size;
i++ ){
374 if ( (row->crate == _crate || _crate == -1) &&
381 _set.
subdet[
i].find(row->subdet)!=string::npos ){
385 if ( lut_index >= 0 ){
386 if ( _xml.count(row->crate) == 0 && split_by_crate ){
387 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
389 else if ( _xml.count(0) == 0 && !split_by_crate ){
390 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
392 _cfg.
ieta = row->ieta;
393 _cfg.
iphi = row->iphi;
394 _cfg.
depth = row->idepth;
395 _cfg.
crate = row->crate;
396 _cfg.
slot = row->slot;
397 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
398 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
400 _cfg.
fiber = row->fiber;
412 (row->ieta>0)*100 +
abs(row->ieta) +
413 (((row->subdet.find(
"HF")!=string::npos) &&
abs(row->ieta)==29)?(4*10000):(0));
416 DetId _detId(row->rawId);
417 uint32_t status_word = cq->getValues(_detId)->getValue();
418 if ((status_word & status_word_to_mask) > 0){
422 _cfg.
lut = _set.
lut[lut_index];
424 if (split_by_crate ){
425 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
429 _xml[0]->addLut( _cfg, lut_checksums_xml );
436 <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
443 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from ascii master file...";
444 std::map<int, boost::shared_ptr<LutXml> > _xml;
448 int lut_set_size = _set.
lut.size();
449 edm::LogInfo(
"HcalLutManager") <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file";
453 for( _iter.begin(); !_iter.end(); _iter.next() ){
460 int _ieta = _iter.getIeta();
461 int _iphi = _iter.getIphi();
462 int _depth = _iter.getDepth();
466 int aCrate = _eId . readoutVMECrateId();
467 int aSlot = _eId . htrSlot();
468 int aTopBottom = _eId . htrTopBottom();
469 int aFiber = _eId . fiberIndex();
470 int aFiberChan = _eId . fiberChanId();
477 for (
int i=0;
i<lut_set_size;
i++ ){
478 if ( (aCrate == _crate || _crate == -1) &&
485 _set.
subdet[
i].find(_ass.getSubdetectorString(_subdet))!=string::npos ){
489 if ( lut_index >= 0 ){
490 if ( _xml.count(aCrate) == 0 && split_by_crate ){
491 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(aCrate,boost::shared_ptr<LutXml>(
new LutXml())) );
493 else if ( _xml.count(0) == 0 && !split_by_crate ){
494 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
514 (_ieta>0)*100 +
abs(_ieta) +
516 _cfg.
lut = _set.
lut[lut_index];
517 if (split_by_crate ){
518 _xml[aCrate]->addLut( _cfg, lut_checksums_xml );
522 _xml[0]->addLut( _cfg, lut_checksums_xml );
529 <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
536 edm::LogInfo(
"HcalLutManager") <<
"Generating compression (output) LUTs from ascii master file...";
537 std::map<int, boost::shared_ptr<LutXml> > _xml;
539 edm::LogInfo(
"HcalLutManager") <<
"instantiating CaloTPGTranscoderULUT in order to check the validity of (ieta,iphi)...";
545 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
546 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map .
size() <<
" channels";
550 int lut_set_size = _set.
lut.size();
551 edm::LogInfo(
"HcalLutManager") <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file";
555 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
561 for (
int i=0;
i<lut_set_size;
i++ ){
562 if ( row->subdet .
find(
"HT") != std::string::npos &&
563 (row->crate == _crate || _crate == -1) &&
568 _coder.
HTvalid(row->ieta, row->iphi, row->idepth / 10) ){
572 if ( lut_index >= 0 ){
573 if ( _xml.count(row->crate) == 0 && split_by_crate ){
574 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
576 else if ( _xml.count(0) == 0 && !split_by_crate ){
577 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
579 _cfg.
ieta = row->ieta;
580 _cfg.
iphi = row->iphi;
581 _cfg.
depth = row->idepth;
582 _cfg.
crate = row->crate;
583 _cfg.
slot = row->slot;
584 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
585 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
587 _cfg.
fiber = row->fiber;
589 if (_set.
lut[lut_index].size() == 128) _cfg.
lut_type = 1;
600 (row->ieta>0)*100+
abs(row->ieta);
601 _cfg.
lut = _set.
lut[lut_index];
602 if (split_by_crate ){
603 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
607 _xml[0]->addLut( _cfg, lut_checksums_xml );
613 <<
"Generating compression (output) LUTs from ascii master file...DONE" << std::endl;
620 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...";
621 std::map<int, boost::shared_ptr<LutXml> > _xml;
628 _lmap .
read(
"backup/HCALmapHBEF.txt",
"HBEF" );
631 std::map<int,LMapRow> & _map = _lmap.
get_map();
632 edm::LogInfo(
"HcalLutManager") <<
"LMap contains " << _map .
size() <<
" channels";
640 for( std::map<int,LMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
643 if ( _xml.count(row->second.crate) == 0 && split_by_crate ){
644 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->second.crate,boost::shared_ptr<LutXml>(
new LutXml())) );
646 else if ( _xml.count(0) == 0 && !split_by_crate ){
647 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
649 _cfg.
ieta = row->second.side*row->second.eta;
650 _cfg.
iphi = row->second.phi;
651 _cfg.
depth = row->second.depth;
652 _cfg.
crate = row->second.crate;
653 _cfg.
slot = row->second.htr;
654 if (row->second.fpga .
find(
"top") != std::string::npos) _cfg.
topbottom = 1;
655 else if (row->second.fpga .
find(
"bot") != std::string::npos) _cfg.
topbottom = 0;
659 _cfg.
fiber = row->second.htr_fi;
671 (row->second.side>0)*100 + row->second.eta +
672 ((row->second.det==
HcalForward && row->second.eta==29)?(4*10000):(0));
675 HcalDetId _detid(row->second.det, row->second.side*row->second.eta, row->second.phi, row->second.depth);
679 std::vector<unsigned short> coder_lut = _coder . getLinearizationLUT(_detid);
680 for (std::vector<unsigned short>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
681 unsigned int _temp = (
unsigned int)(*_i);
684 _cfg.
lut.push_back(_temp);
686 if (split_by_crate ){
687 _xml[row->second.crate]->addLut( _cfg, lut_checksums_xml );
691 _xml[0]->addLut( _cfg, lut_checksums_xml );
696 <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
705 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...";
706 std::map<int, boost::shared_ptr<LutXml> > _xml;
709 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
710 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map .
size() <<
" entries";
712 std::vector<unsigned int> zeroLut;
713 for (
size_t adc = 0;
adc < 128;
adc++) zeroLut.push_back(0);
717 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
718 if( (row->subdet.find(
"HB")!=string::npos ||
719 row->subdet.find(
"HE")!=string::npos ||
720 row->subdet.find(
"HF")!=string::npos ) &&
721 row->subdet.size()==2
725 if ( _xml.count(row->crate) == 0 && split_by_crate ){
726 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
728 else if ( _xml.count(0) == 0 && !split_by_crate ){
729 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
731 _cfg.
ieta = row->ieta;
732 _cfg.
iphi = row->iphi;
733 _cfg.
depth = row->idepth;
734 _cfg.
crate = row->crate;
735 _cfg.
slot = row->slot;
736 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
737 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
739 _cfg.
fiber = row->fiber;
751 (row->ieta>0)*100 +
abs(row->ieta) +
752 (((row->subdet.find(
"HF")!=string::npos) &&
abs(row->ieta)==29)?(4*10000):(0));
754 if ( row->subdet.find(
"HB")!=string::npos ) _subdet =
HcalBarrel;
755 else if ( row->subdet.find(
"HE")!=string::npos ) _subdet =
HcalEndcap;
756 else if ( row->subdet.find(
"HO")!=string::npos ) _subdet =
HcalOuter;
757 else if ( row->subdet.find(
"HF")!=string::npos ) _subdet =
HcalForward;
759 HcalDetId _detid(_subdet, row->ieta, row->iphi, row->idepth);
762 uint32_t status_word = cq->getValues(_detid)->getValue();
763 if ((status_word & status_word_to_mask) > 0){
767 std::vector<unsigned short> coder_lut = _coder . getLinearizationLUT(_detid);
768 for (std::vector<unsigned short>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
769 unsigned int _temp = (
unsigned int)(*_i);
770 _cfg.
lut.push_back(_temp);
773 if (split_by_crate ){
774 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
778 _xml[0]->addLut( _cfg, lut_checksums_xml );
784 <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
792 edm::LogInfo(
"HcalLutManager") <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT," << std::endl
793 <<
"initialized from Event Setup" << std::endl;
794 std::map<int, boost::shared_ptr<LutXml> > _xml;
798 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
799 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map .
size() <<
" channels";
802 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
805 if ( row->subdet.find(
"HT") == std::string::npos)
continue;
809 if(!cq->topo()->validHT(_detid))
continue;
812 if ( _xml.count(row->crate) == 0 && split_by_crate ){
813 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
815 else if ( _xml.count(0) == 0 && !split_by_crate ){
816 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
819 _cfg.
ieta = row->ieta;
820 _cfg.
iphi = row->iphi;
821 _cfg.
depth = row->idepth;
822 _cfg.
crate = row->crate;
823 _cfg.
slot = row->slot;
824 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
825 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
827 _cfg.
fiber = row->fiber;
839 if (split_by_crate ){
840 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
844 _xml[0]->addLut( _cfg, lut_checksums_xml );
849 <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE" << std::endl;
857 edm::LogInfo(
"HcalLutManager") <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT";
858 std::map<int, boost::shared_ptr<LutXml> > _xml;
865 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
866 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map .
size() <<
" channels";
876 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
881 const int tp_version = row->idepth / 10;
882 if ( row->subdet .
find(
"HT") != std::string::npos && _coder.
HTvalid(row->ieta, row->iphi, tp_version) ){
883 if ( _xml.count(row->crate) == 0 && split_by_crate ){
884 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
886 else if ( _xml.count(0) == 0 && !split_by_crate ){
887 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
889 _cfg.
ieta = row->ieta;
890 _cfg.
iphi = row->iphi;
891 _cfg.
depth = row->idepth;
892 _cfg.
crate = row->crate;
893 _cfg.
slot = row->slot;
894 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
895 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
897 _cfg.
fiber = row->fiber;
909 (row->ieta>0)*100+
abs(row->ieta);
917 if (split_by_crate ){
918 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
922 _xml[0]->addLut( _cfg, lut_checksums_xml );
928 <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE" << std::endl;
936 for (std::map<
int,boost::shared_ptr<LutXml> >::const_iterator cr = _xml.begin(); cr != _xml.end(); cr++){
938 if ( split_by_crate ){
939 output_file_name << _tag <<
"_" << cr->first <<
".xml";
942 output_file_name << _tag <<
".xml";
944 cr->second->write( output_file_name.str().c_str() );
952 std::map<int, boost::shared_ptr<LutXml> > xml;
953 if ( !lut_checksums_xml ){
954 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
957 if ( _lin_file.size() != 0 ){
958 addLutMap( xml, getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate ) );
960 writeLutXmlFiles( xml, _tag, split_by_crate );
962 std::string checksums_file = _tag +
"_checksums.xml";
963 lut_checksums_xml ->
write( checksums_file . 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 ){
978 addLutMap( xml, getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate ) );
980 if ( _comp_file.size() != 0 ){
982 addLutMap( xml, getCompressionLutXmlFromAsciiMaster( _comp_file, _tag, -1, split_by_crate ) );
985 writeLutXmlFiles( xml, _tag, split_by_crate );
987 std::string checksums_file = _tag +
"_checksums.xml";
988 lut_checksums_xml ->
write( checksums_file . c_str() );
996 std::map<int, boost::shared_ptr<LutXml> > xml;
997 if ( !lut_checksums_xml ){
998 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1001 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1003 writeLutXmlFiles( xml, _tag, split_by_crate );
1005 std::string checksums_file = _tag +
"_checksums.xml";
1006 lut_checksums_xml ->
write( checksums_file . c_str() );
1014 std::map<int, boost::shared_ptr<LutXml> > xml;
1015 if ( !lut_checksums_xml ){
1016 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1020 addLutMap( xml, getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate ) );
1021 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1023 writeLutXmlFiles( xml, _tag, split_by_crate );
1025 std::string checksums_file = _tag +
"_checksums.xml";
1026 lut_checksums_xml ->
write( checksums_file . c_str() );
1036 std::map<int, boost::shared_ptr<LutXml> > xml;
1037 if ( !lut_checksums_xml ){
1038 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1041 if ( _lin_file.size() != 0 ){
1042 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1043 addLutMap( xml, _lin_lut_ascii_xml );
1045 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1046 addLutMap( xml, _lin_lut_xml );
1048 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _transcoder, _tag, split_by_crate );
1049 addLutMap( xml, _comp_lut_xml );
1051 writeLutXmlFiles( xml, _tag, split_by_crate );
1053 std::string checksums_file = _tag +
"_checksums.xml";
1054 lut_checksums_xml ->
write( checksums_file . c_str() );
1062 std::map<int, boost::shared_ptr<LutXml> > xml;
1063 if ( !lut_checksums_xml ){
1064 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1067 if ( _lin_file.size() != 0 ){
1068 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1069 addLutMap( xml, _lin_lut_ascii_xml );
1071 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1072 addLutMap( xml, _lin_lut_xml );
1074 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _tag, split_by_crate );
1075 addLutMap( xml, _comp_lut_xml );
1077 writeLutXmlFiles( xml, _tag, split_by_crate );
1079 std::string checksums_file = _tag +
"_checksums.xml";
1080 lut_checksums_xml ->
write( checksums_file . c_str() );
1090 std::map<int, boost::shared_ptr<LutXml> > xml;
1091 if ( !lut_checksums_xml ){
1092 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1095 if ( _lin_file.size() != 0 ){
1096 addLutMap( xml, getLutXmlFromAsciiMaster( _lin_file, _tag, -1, split_by_crate ) );
1098 addLutMap( xml, getCompressionLutXmlFromCoder( _tag, split_by_crate ) );
1099 writeLutXmlFiles( xml, _tag, split_by_crate );
1101 std::string checksums_file = _tag +
"_checksums.xml";
1102 lut_checksums_xml ->
write( checksums_file . c_str() );
1111 for ( std::map<
int, boost::shared_ptr<LutXml> >::const_iterator
lut=other.begin();
lut!=other.end();
lut++ ){
1112 edm::LogInfo(
"HcalLutManager") <<
"Added LUTs for crate " <<
lut->first;
1129 strftime( timebuf, 50,
"%Y-%m-%d %H:%M:%S", gmtime( &_time ) );
1132 return creationstamp;
1140 local_connect( _filename,
"backup/HCALmapHBEF.txt",
"backup/HCALmapHO.txt" );
1144 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
1145 int map_size = _map .
size();
1146 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << map_size <<
" channels";
1149 std::vector<unsigned int> _lut;
1150 _lut = getLutFromXml( _tag, 1107313727, hcal::ConfigurationDatabase::LinearizerLUT );
1153 edm::LogInfo(
"HcalLutManager") <<
"Testing direct parsing of the LUT XML";
1155 gettimeofday( &_t,
NULL );
1156 double _time =(double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0;
1157 test_direct_xml_parsing(_filename);
1158 gettimeofday( &_t,
NULL );
1159 edm::LogInfo(
"HcalLutManager") <<
"parsing took that much time: " << (double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0 - _time;
1162 gettimeofday( &_t,
NULL );
1163 _time =(double)(_t . tv_sec) + (double)(_t . tv_usec)/1000000.0;
1164 edm::LogInfo(
"HcalLutManager") <<
"before loop over random LUTs: " << _time;
1168 for (
int _iter=0; _iter<100; _iter++){
1169 gettimeofday( &_t,
NULL );
1174 int _key = (
rand() % map_size);
1176 if( (_map[_key].subdet.find(
"HB")!=string::npos ||
1177 _map[_key].subdet.find(
"HE")!=string::npos ||
1178 _map[_key].subdet.find(
"HO")!=string::npos ||
1179 _map[_key].subdet.find(
"HF")!=string::npos ) &&
1180 _map[_key].subdet.size()==2
1183 if ( _map[_key].subdet.find(
"HB")!=string::npos ) _subdet =
HcalBarrel;
1184 else if ( _map[_key].subdet.find(
"HE")!=string::npos ) _subdet =
HcalEndcap;
1185 else if ( _map[_key].subdet.find(
"HO")!=string::npos ) _subdet =
HcalOuter;
1186 else if ( _map[_key].subdet.find(
"HF")!=string::npos ) _subdet =
HcalForward;
1188 HcalDetId _detid(_subdet, _map[_key].ieta, _map[_key].iphi, _map[_key].idepth);
1189 _raw_id = _detid.
rawId();
1193 _lut = getLutFromXml( _tag, _raw_id, hcal::ConfigurationDatabase::LinearizerLUT );
1195 gettimeofday( &_t,
NULL );
1197 double d_time = _t.tv_sec+_t.tv_usec/1000000.0 - _time;
1198 edm::LogInfo(
"HcalLutManager") <<
"after the loop over random LUTs: " << _time+d_time << std::endl
1199 <<
"total time: " << d_time << std::endl;
1202 for ( std::vector<unsigned int>::const_iterator
i = _lut .
end() - 1;
i != _lut .
begin()-1;
i-- )
1204 edm::LogInfo(
"HcalLutManager") << (
i-_lut.begin()) <<
" " << _lut[(
i-_lut.begin())];
1222 lmap ->
read( lmap_hbef_file,
"HBEF" );
1223 lmap ->
read( lmap_ho_file,
"HO" );
1224 edm::LogInfo(
"HcalLutManager") <<
"LMap contains " << lmap -> get_map() .
size() <<
" channels (compare to 9072 of all HCAL channels)";
1244 read_lmap( lmap_hbef_file, lmap_ho_file );
1245 read_luts( lut_xml_file );
1254 edm::LogInfo(
"HcalLutManager") <<
"getLutFromXml (new version) is not implemented. Use getLutFromXml_old() for now";
1256 std::vector<unsigned int>
result;
1268 edm::LogError(
"HcalLutManager") <<
"Cannot find LUT without LMAP, exiting...";
1272 edm::LogError(
"HcalLutManager") <<
"Cannot find LUT, no source (local XML file), exiting...";
1276 std::vector<unsigned int>
result;
1278 std::map<int,LMapRow> & _map = lmap -> get_map();
1283 unsigned int _crate, _slot, _fiber, _channel;
1285 int topbottom, luttype;
1288 if ( _map .
find(_rawid) != _map.end() ){
1289 _crate = _map[_rawid] . crate;
1290 _slot = _map[_rawid] . htr;
1291 _fiber = _map[_rawid] . htr_fi;
1292 _channel = _map[_rawid] . fi_ch;
1293 _fpga = _map[_rawid] . fpga;
1295 if ( _fpga .
find(
"top") != std::string::npos ) topbottom = 1;
1296 else if ( _fpga .
find(
"bot") != std::string::npos ) topbottom = 0;
1298 edm::LogError(
"HcalLutManager") <<
"Irregular LMAP fpga value... do not know what to do - exiting";
1301 if ( _lt == hcal::ConfigurationDatabase::LinearizerLUT ) luttype = 1;
1304 result =
db -> getOnlineLUT( tag, _crate, _slot, topbottom, _fiber, _channel, luttype );
1314 std::map<int, boost::shared_ptr<LutXml> > lut_map = get_brickSet_from_oracle( tag, db_accessor );
1315 if (split_by_crate){
1316 writeLutXmlFiles( lut_map, tag, split_by_crate );
1320 for( std::map<
int, boost::shared_ptr<LutXml> >::const_iterator xml = lut_map.begin(); xml != lut_map.end(); xml++ ){
1321 result += *(xml->second);
1324 out_file << tag <<
".xml";
1325 result .
write(out_file.str());
1337 oracle::occi::Connection * _connection = db -> getConnection();
1339 edm::LogInfo(
"HcalLutManager") <<
"Preparing to request the LUT CLOBs from the database...";
1347 std::string query = (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB, CRATE FROM CMS_HCL_HCAL_COND.V_HCAL_TRIG_LOOKUP_TABLES");
1353 std::map<int, boost::shared_ptr<LutXml> > lut_map;
1357 edm::LogInfo(
"HcalLutManager") <<
"Executing the query...";
1358 Statement* stmt = _connection -> createStatement();
1359 ResultSet *rs = stmt->executeQuery(query.c_str());
1360 edm::LogInfo(
"HcalLutManager") <<
"Executing the query... done";
1362 edm::LogInfo(
"HcalLutManager") <<
"Processing the query results...";
1364 while (rs->next()) {
1366 oracle::occi::Clob clob = rs->getClob (1);
1367 int crate = rs->getInt(2);
1369 edm::LogInfo(
"HcalLutManager") <<
"Getting LUTs for crate #" << crate <<
" out of the database...";
1370 brick_set = db -> clobToString(clob);
1380 const char * bs = brick_set . c_str();
1381 MemBufInputSource * lut_clob =
new MemBufInputSource( (
const XMLByte *)bs, strlen( bs ),
"lut_clob",
false );
1382 boost::shared_ptr<LutXml> lut_xml = boost::shared_ptr<LutXml>(
new LutXml( *lut_clob ) );
1383 lut_map[crate] = lut_xml;
1388 _connection -> terminateStatement(stmt);
1391 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::
toolbox::toString(
"Oracle exception : %s",e.getMessage().c_str()));
1404 edm::LogInfo(
"HcalLutManager") <<
"Generating XML loader for LUTs...";
1411 baseConf . tag_name = tag_name;
1413 baseConf . comment_description =
comment;
1414 baseConf . iov_begin =
"1";
1415 baseConf . iov_end =
"-1";
1419 std::stringstream _subversion;
1420 _subversion << subversion;
1421 conf . subversion = _subversion.str();
1423 CSconf . version = conf .
version;
1424 CSconf . subversion = conf . subversion;
1425 CSconf . trig_prim_lookuptbl_data_file = _prefix +
"_checksums.xml.dat";
1426 CSconf . comment_description = tag_name;
1430 std::vector<int> crate_number;
1432 for (std::vector<std::string>::const_iterator _f = file_name.begin(); _f != file_name.end(); _f++){
1433 int crate_begin = _f->rfind(
"_");
1434 int crate_end = _f->rfind(
".xml.dat");
1435 crate_number . push_back(
getInt(_f->substr(crate_begin+1,crate_end-crate_begin-1)));
1441 time_t _offset = time(
NULL);
1442 sprintf( _buf,
"%d", (uint32_t)_offset );
1447 for ( std::vector<std::string>::const_iterator _file = file_name .
begin(); _file != file_name .
end(); _file++ )
1449 conf . trig_prim_lookuptbl_data_file = *_file;
1451 conf . crate = crate_number[ _file - file_name .
begin() ];
1455 sprintf( _buf,
"%.2d", conf.
crate );
1458 sprintf( _buf,
"CRATE%.2d", conf . crate );
1460 _namelabel .
append( _buf );
1461 conf . name_label = _namelabel;
1462 doc . addLUT( &conf );
1465 doc . addChecksums( &CSconf );
1467 doc .
write( tag_name +
"_Loader.xml" );
1469 edm::LogInfo(
"HcalLutManager") <<
"Generating XML loader for LUTs... done.";
1479 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
1480 std::stringstream
s;
1481 s <<
"EMap contains " << _map .
size() <<
" channels" << std::endl;
1485 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
1488 if ( row->subdet .
find(
"HT") != std::string::npos ){
1489 s <<
" -----> Subdet = " << row->subdet << std::endl;
1491 if (
abs(row->ieta)>28){
1493 s <<
" ==> (ieta,iphi) = " << row->ieta <<
", " << row->iphi << std::endl;
1539 std::map<int, boost::shared_ptr<LutXml> > xml;
1540 if ( !lut_checksums_xml ){
1541 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1 );
1544 if ( _lin_file.size() != 0 ){
1545 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_ascii_xml = getLinearizationLutXmlFromAsciiMasterEmap( _lin_file, _tag, -1, split_by_crate );
1546 addLutMap( xml, _lin_lut_ascii_xml );
1548 const std::map<int, boost::shared_ptr<LutXml> > _lin_lut_xml = getLinearizationLutXmlFromCoderEmap( _coder, _tag, split_by_crate );
1549 addLutMap( xml, _lin_lut_xml );
1551 const std::map<int, boost::shared_ptr<LutXml> > _comp_lut_xml = getCompressionLutXmlFromCoder( _transcoder, _tag, split_by_crate );
1552 addLutMap( xml, _comp_lut_xml );
1554 const std::map<int, boost::shared_ptr<LutXml> > _zdc_lut_xml = getZdcLutXml( _tag, split_by_crate );
1555 addLutMap( xml, _zdc_lut_xml );
1557 writeLutXmlFiles( xml, _tag, split_by_crate );
1559 std::string checksums_file = _tag +
"_checksums.xml";
1560 lut_checksums_xml ->
write( checksums_file . c_str() );
1567 bool split_by_crate )
1569 edm::LogInfo(
"HcalLutManager") <<
"Generating ZDC LUTs ...may the Force be with us...";
1570 std::map<int, boost::shared_ptr<LutXml> > _xml;
1576 std::vector<EMap::EMapRow> & _map = _emap.
get_map();
1577 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map .
size() <<
" channels";
1581 for( std::vector<EMap::EMapRow>::const_iterator row=_map.begin(); row!=_map.end(); row++ ){
1585 if ( row->zdc_section .
find(
"ZDC") != std::string::npos ){
1586 if ( _xml.count(row->crate) == 0 && split_by_crate ){
1587 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(row->crate,boost::shared_ptr<LutXml>(
new LutXml())) );
1589 else if ( _xml.count(0) == 0 && !split_by_crate ){
1590 _xml.insert( std::pair<
int,boost::shared_ptr<LutXml> >(0,boost::shared_ptr<LutXml>(
new LutXml())) );
1593 _cfg.
ieta = row->zdc_channel;
1596 _cfg.
depth = row->idepth;
1597 _cfg.
crate = row->crate;
1598 _cfg.
slot = row->slot;
1599 if (row->topbottom .
find(
"t") != std::string::npos) _cfg.
topbottom = 1;
1600 else if (row->topbottom .
find(
"b") != std::string::npos) _cfg.
topbottom = 0;
1602 _cfg.
fiber = row->fiber;
1613 std::vector<int> coder_lut = zdc.
get_lut(row->zdc_section,
1616 edm::LogInfo(
"HcalLutManager") <<
"***DEBUG: ZDC lut size: " << coder_lut.size();
1617 if (coder_lut.size()!=0){
1618 for (std::vector<int>::const_iterator _i=coder_lut.begin(); _i!=coder_lut.end();_i++){
1619 unsigned int _temp = (
unsigned int)(*_i);
1622 _cfg.
lut.push_back(_temp);
1626 if (split_by_crate ){
1627 _xml[row->crate]->addLut( _cfg, lut_checksums_xml );
1631 _xml[0]->addLut( _cfg, lut_checksums_xml );
1638 <<
"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)
virtual bool HTvalid(const int ieta, const int iphi, const int version) const
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")
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
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 const std::vector< unsigned int > & getCompressionLUT(const 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
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)