13 #include <toolbox/string.h>
55 uint32_t _status_word_to_mask) {
59 status_word_to_mask = _status_word_to_mask;
64 uint32_t _status_word_to_mask) {
69 status_word_to_mask = _status_word_to_mask;
74 lut_checksums_xml =
nullptr;
80 status_word_to_mask = 0x0000;
85 delete lut_checksums_xml;
103 lut_xml->addLut(_config);
104 lut_xml->addLut(_config);
105 lut_xml->addLut(_config);
108 return lut_xml->getCurrentBrick();
119 if (_det.find(
"HB") != std::string::npos)
121 else if (_det.find(
"HE") != std::string::npos)
123 else if (_det.find(
"HF") != std::string::npos)
125 else if (_det.find(
"HO") != std::string::npos)
137 s <<
"===> Test of HcalLutSet HcalLutManager::getLutSetFromFile( std::string _filename )" << std::endl << std::endl;
138 s << _set.
label << std::endl;
139 for (
unsigned int i = 0;
i != _set.
subdet.size();
i++)
160 for (
unsigned int j = 0;
j != _set.
lut[0].size();
j++) {
161 for (
unsigned int i = 0;
i != _set.
lut.size();
i++) {
162 s << _set.
lut[
i][
j] <<
" ";
164 s <<
"---> " <<
j << std::endl;
173 ifstream
infile(_filename.c_str());
177 edm::LogInfo(
"HcalLutManager") <<
"File " << _filename <<
" is open..." << std::endl
178 <<
"Reading LUTs and their eta/phi/depth/subdet ranges...";
190 std::vector<std::string> buf_vec;
193 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++) {
200 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++) {
207 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++) {
214 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++) {
222 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++) {
229 for (std::vector<std::string>::const_iterator iter = buf_vec.begin(); iter != buf_vec.end(); iter++) {
234 bool first_lut_entry =
true;
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;
256 bool split_by_crate) {
257 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from ascii master file...";
258 std::map<int, std::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";
267 HcalLutSet _set = getLutSetFromFile(_filename);
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 && _set.
phi_min[
i] <= row->second.phi &&
283 _set.
depth_max[
i] >= row->second.depth && get_subdetector(_set.
subdet[
i]) == row->second.det) {
287 if (lut_index >= 0) {
288 if (_xml.count(row->second.crate) == 0 && split_by_crate) {
289 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->second.crate, std::make_shared<LutXml>()));
290 }
else if (_xml.count(0) == 0 && !split_by_crate) {
291 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<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)
300 else if (row->second.fpga.find(
"bot") != std::string::npos)
306 _cfg.
fiber = row->second.htr_fi;
308 if (_set.
lut[lut_index].size() == 128)
320 ((row->second.det ==
HcalForward && row->second.eta == 29) ? (4 * 10000) : (0));
321 _cfg.
lut = _set.
lut[lut_index];
322 if (split_by_crate) {
323 _xml[row->second.crate]->addLut(_cfg, lut_checksums_xml);
326 _xml[0]->addLut(_cfg, lut_checksums_xml);
332 <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
342 bool split_by_crate) {
343 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from ascii master file...";
344 std::map<int, std::shared_ptr<LutXml>> _xml;
347 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
348 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" entries";
351 HcalLutSet _set = getLutSetFromFile(_filename);
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;
358 zeroLut.push_back(0);
362 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
363 if ((row->subdet.find(
"HB") != string::npos || row->subdet.find(
"HE") != string::npos ||
364 row->subdet.find(
"HO") != string::npos || row->subdet.find(
"HF") != string::npos) &&
365 row->subdet.size() == 2) {
371 for (
int i = 0;
i < lut_set_size;
i++) {
372 if ((row->crate == _crate || _crate == -1) &&
375 _set.
subdet[
i].find(row->subdet) != string::npos) {
379 if (lut_index >= 0) {
380 if (_xml.count(row->crate) == 0 && split_by_crate) {
381 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
382 }
else if (_xml.count(0) == 0 && !split_by_crate) {
383 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
385 _cfg.
ieta = row->ieta;
386 _cfg.
iphi = row->iphi;
387 _cfg.
depth = row->idepth;
388 _cfg.
crate = row->crate;
389 _cfg.
slot = row->slot;
390 if (row->topbottom.find(
't') != std::string::npos)
392 else if (row->topbottom.find(
'b') != std::string::npos)
394 else if (row->topbottom.find(
'u') != std::string::npos)
398 _cfg.
fiber = row->fiber;
409 _cfg.
iphi * 10000 + _cfg.
depth * 1000 + (row->ieta > 0) * 100 +
abs(row->ieta) +
410 (((row->subdet.find(
"HF") != string::npos) &&
abs(row->ieta) == 29) ? (4 * 10000) : (0));
413 DetId _detId(row->rawId);
414 uint32_t status_word = cq->getValues(_detId)->getValue();
415 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);
424 _xml[0]->addLut(_cfg, lut_checksums_xml);
431 <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
437 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from ascii master file...";
438 std::map<int, std::shared_ptr<LutXml>> _xml;
441 HcalLutSet _set = getLutSetFromFile(_filename);
442 int lut_set_size = _set.
lut.size();
443 edm::LogInfo(
"HcalLutManager") <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file";
447 for (_iter.begin(); !_iter.end(); _iter.next()) {
450 int _ieta = _iter.getIeta();
451 int _iphi = _iter.getIphi();
452 int _depth = _iter.getDepth();
457 int aSlot = _eId.htrSlot();
458 int aTopBottom = _eId.htrTopBottom();
459 int aFiber = _eId.fiberIndex();
460 int aFiberChan = _eId.fiberChanId();
467 for (
int i = 0;
i < lut_set_size;
i++) {
468 if ((aCrate == _crate || _crate == -1) &&
471 _set.
subdet[
i].find(_ass.getSubdetectorString(_subdet)) != string::npos) {
475 if (lut_index >= 0) {
476 if (_xml.count(aCrate) == 0 && split_by_crate) {
477 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(aCrate, std::make_shared<LutXml>()));
478 }
else if (_xml.count(0) == 0 && !split_by_crate) {
479 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
498 (((_subdet ==
HcalForward) &&
abs(_ieta) == 29) ? (4 * 10000) : (0));
499 _cfg.
lut = _set.
lut[lut_index];
500 if (split_by_crate) {
501 _xml[aCrate]->addLut(_cfg, lut_checksums_xml);
504 _xml[0]->addLut(_cfg, lut_checksums_xml);
511 <<
"Generating linearization (input) LUTs from ascii master file...DONE" << std::endl;
518 bool split_by_crate) {
519 edm::LogInfo(
"HcalLutManager") <<
"Generating compression (output) LUTs from ascii master file...";
520 std::map<int, std::shared_ptr<LutXml>> _xml;
523 <<
"instantiating CaloTPGTranscoderULUT in order to check the validity of (ieta,iphi)...";
529 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
530 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" channels";
533 HcalLutSet _set = getLutSetFromFile(_filename, 2);
534 int lut_set_size = _set.
lut.size();
535 edm::LogInfo(
"HcalLutManager") <<
" ==> " << lut_set_size <<
" sets of different LUTs read from the master file";
539 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
545 for (
int i = 0;
i < lut_set_size;
i++) {
546 if (row->subdet.find(
"HT") != std::string::npos &&
547 (row->crate == _crate || _crate == -1) &&
549 _set.
phi_max[
i] >= row->iphi && _coder.
HTvalid(row->ieta, row->iphi, row->idepth / 10)) {
553 if (lut_index >= 0) {
554 if (_xml.count(row->crate) == 0 && split_by_crate) {
555 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
556 }
else if (_xml.count(0) == 0 && !split_by_crate) {
557 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
559 _cfg.
ieta = row->ieta;
560 _cfg.
iphi = row->iphi;
561 _cfg.
depth = row->idepth;
562 _cfg.
crate = row->crate;
563 _cfg.
slot = row->slot;
564 if (row->topbottom.find(
't') != std::string::npos)
566 else if (row->topbottom.find(
'b') != std::string::npos)
568 else if (row->topbottom.find(
'u') != std::string::npos)
572 _cfg.
fiber = row->fiber;
574 if (_set.
lut[lut_index].size() == 128)
586 _cfg.
lut = _set.
lut[lut_index];
587 if (split_by_crate) {
588 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
591 _xml[0]->addLut(_cfg, lut_checksums_xml);
597 <<
"Generating compression (output) LUTs from ascii master file...DONE" << std::endl;
603 bool split_by_crate) {
604 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...";
605 std::map<int, std::shared_ptr<LutXml>> _xml;
612 _lmap.
read(
"backup/HCALmapHBEF.txt",
"HBEF");
615 std::map<int, LMapRow>& _map = _lmap.
get_map();
616 edm::LogInfo(
"HcalLutManager") <<
"LMap contains " << _map.size() <<
" channels";
624 for (std::map<int, LMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
627 if (_xml.count(row->second.crate) == 0 && split_by_crate) {
628 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->second.crate, std::make_shared<LutXml>()));
629 }
else if (_xml.count(0) == 0 && !split_by_crate) {
630 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
632 _cfg.
ieta = row->second.side * row->second.eta;
633 _cfg.
iphi = row->second.phi;
634 _cfg.
depth = row->second.depth;
635 _cfg.
crate = row->second.crate;
636 _cfg.
slot = row->second.htr;
637 if (row->second.fpga.find(
"top") != std::string::npos)
639 else if (row->second.fpga.find(
"bot") != std::string::npos)
645 _cfg.
fiber = row->second.htr_fi;
656 ((row->second.det ==
HcalForward && row->second.eta == 29) ? (4 * 10000) : (0));
659 HcalDetId _detid(row->second.det, row->second.side * row->second.eta, row->second.phi, row->second.depth);
664 for (std::vector<unsigned short>::const_iterator _i = coder_lut.begin(); _i != coder_lut.end(); _i++) {
665 unsigned int _temp = (
unsigned int)(*_i);
668 _cfg.
lut.push_back(_temp);
670 if (split_by_crate) {
671 _xml[row->second.crate]->addLut(_cfg, lut_checksums_xml);
674 _xml[0]->addLut(_cfg, lut_checksums_xml);
679 <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
684 edm::LogInfo(
"HcalLutManager") <<
"Generating TDC masks...";
687 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
688 edm::LogInfo(
"HcalLutManager") <<
"EMap contains new" << _map.size() <<
" entries";
690 std::map<int, std::vector<uint64_t>> masks;
692 for (
const auto& row : _map) {
696 int crate = row.crate;
698 int crot = 100 * crate + slot;
699 int fiber = row.fiber;
700 int channel = row.fiberchan;
701 unsigned int finel = 4 * fiber + channel;
702 if (masks.count(crot) == 0)
704 if (finel >= masks[crot].
size())
705 masks[crot].resize(finel + 1);
709 if (row.subdet.find(
"HB") != string::npos)
711 else if (row.subdet.find(
"HE") != string::npos)
713 else if (row.subdet.find(
"HO") != string::npos)
715 else if (row.subdet.find(
"HF") != string::npos)
719 HcalDetId _detid(_subdet, row.ieta, row.iphi, row.idepth);
720 masks[crot][finel] =
conditions->getHcalTPChannelParameter(_detid)->getMask();
723 masks[crot][finel] = masktype == 1 ?
parameters->getADCThresholdHF() :
parameters->getTDCMaskHF();
727 std::map<int, std::shared_ptr<LutXml>> _xml;
730 for (
const auto&
i : masks) {
732 int crate = crot / 100;
737 _cfg.
slot = crot % 100;
739 _cfg.
mask =
i.second;
744 int c = split_by_crate ? crate : 0;
745 if (_xml.count(
c) == 0)
746 _xml[
c] = std::make_shared<LutXml>();
748 _xml[
c]->addLut(_cfg);
753 <<
"Generating Masks...DONE" << std::endl;
759 bool split_by_crate) {
760 edm::LogInfo(
"HcalLutManager") <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...";
761 std::map<int, std::shared_ptr<LutXml>> _xml;
764 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
765 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" entries";
769 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
770 if ((row->subdet.find(
"HB") != string::npos || row->subdet.find(
"HE") != string::npos ||
771 row->subdet.find(
"HF") != string::npos) &&
772 row->subdet.size() == 2) {
775 if (_xml.count(row->crate) == 0 && split_by_crate) {
776 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
777 }
else if (_xml.count(0) == 0 && !split_by_crate) {
778 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
780 _cfg.
ieta = row->ieta;
781 _cfg.
iphi = row->iphi;
782 _cfg.
depth = row->idepth;
783 _cfg.
crate = row->crate;
784 _cfg.
slot = row->slot;
785 if (row->topbottom.find(
't') != std::string::npos)
787 else if (row->topbottom.find(
'b') != std::string::npos)
789 else if (row->topbottom.find(
'u') != std::string::npos)
793 _cfg.
fiber = row->fiber;
804 (((row->subdet.find(
"HF") != string::npos) &&
abs(row->ieta) == 29) ? (4 * 10000) : (0));
806 if (row->subdet.find(
"HB") != string::npos)
808 else if (row->subdet.find(
"HE") != string::npos)
810 else if (row->subdet.find(
"HO") != string::npos)
812 else if (row->subdet.find(
"HF") != string::npos)
816 HcalDetId _detid(_subdet, row->ieta, row->iphi, row->idepth);
819 _cfg.
lut.push_back(
i);
821 if (split_by_crate) {
822 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
825 _xml[0]->addLut(_cfg, lut_checksums_xml);
831 <<
"Generating linearization (input) LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
836 edm::LogInfo(
"HcalLutManager") <<
"Generating HE fine grain LUTs";
837 std::map<int, std::shared_ptr<LutXml>> _xml;
840 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
841 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" entries";
845 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
846 if (row->subdet.find(
"HT") != string::npos && row->subdet.size() == 2) {
847 int abseta =
abs(row->ieta);
849 if (abseta <= topo->lastHBRing()
or abseta > topo->
lastHERing())
855 if (_xml.count(row->crate) == 0 && split_by_crate) {
856 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
857 }
else if (_xml.count(0) == 0 && !split_by_crate) {
858 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
860 _cfg.
ieta = row->ieta;
861 _cfg.
iphi = row->iphi;
862 _cfg.
depth = row->idepth;
863 _cfg.
crate = row->crate;
864 _cfg.
slot = row->slot;
865 if (row->topbottom.find(
't') != std::string::npos)
867 else if (row->topbottom.find(
'b') != std::string::npos)
869 else if (row->topbottom.find(
'u') != std::string::npos)
873 _cfg.
fiber = row->fiber;
881 (((row->subdet.find(
"HF") != string::npos) &&
abs(row->ieta) == 29) ? (4 * 10000) : (0));
884 HcalDetId _detid(_subdet, row->ieta, row->iphi, row->idepth);
890 const int n_fgab_bits = 2048;
891 for (
int i = 0;
i < 2 * n_fgab_bits;
i++) {
893 for (
int k = 0;
k < 6;
k++) {
894 tow[0][
k] = (1 <<
k) &
i;
895 tow[1][
k] = (1 << (
k + 6)) &
i;
897 _cfg.
lut.push_back(fg_algo.compute(tow).to_ulong());
900 if (split_by_crate) {
901 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
904 _xml[0]->addLut(_cfg, lut_checksums_xml);
910 <<
"Generating HE fine grain LUTs from HcaluLUTTPGCoder...DONE" << std::endl;
916 edm::LogInfo(
"HcalLutManager") <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT," << std::endl
917 <<
"initialized from Event Setup" << std::endl;
918 std::map<int, std::shared_ptr<LutXml>> _xml;
922 std::map<int, unsigned int>
maxsize;
924 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
925 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" channels";
928 for (
const auto& row : _map) {
929 if (row.subdet.find(
"HT") == std::string::npos)
932 if (!cq->topo()->validHT(_detid))
934 int crot = 100 * row.crate + row.slot;
941 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
944 if (row->subdet.find(
"HT") == std::string::npos)
949 if (!cq->topo()->validHT(_detid))
952 if (_xml.count(row->crate) == 0 && split_by_crate) {
953 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
954 }
else if (_xml.count(0) == 0 && !split_by_crate) {
955 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
958 _cfg.
ieta = row->ieta;
959 _cfg.
iphi = row->iphi;
960 _cfg.
depth = row->idepth;
961 _cfg.
crate = row->crate;
962 _cfg.
slot = row->slot;
963 if (row->topbottom.find(
't') != std::string::npos)
965 else if (row->topbottom.find(
'b') != std::string::npos)
967 else if (row->topbottom.find(
'u') != std::string::npos)
971 _cfg.
fiber = row->fiber;
981 auto pWeight =
conditions->getHcalTPChannelParameter(_detid,
false);
983 _cfg.
weight = pWeight->getauxi1();
985 int crot = 100 * row->crate + row->slot;
986 unsigned int size = _cfg.
lut.size();
988 edm::LogWarning(
"HcalLutManager") <<
" resizing LUT for " << _detid <<
", channel=[" << _cfg.
crate <<
":"
990 <<
"], using value=" << _cfg.
lut[
size - 1] << std::endl;
995 if (split_by_crate) {
996 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
999 _xml[0]->addLut(_cfg, lut_checksums_xml);
1004 <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE"
1011 bool split_by_crate) {
1012 edm::LogInfo(
"HcalLutManager") <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT";
1013 std::map<int, std::shared_ptr<LutXml>> _xml;
1020 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
1021 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" channels";
1031 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
1036 const int tp_version = row->idepth / 10;
1037 if (row->subdet.find(
"HT") != std::string::npos && _coder.
HTvalid(row->ieta, row->iphi, tp_version)) {
1038 if (_xml.count(row->crate) == 0 && split_by_crate) {
1039 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
1040 }
else if (_xml.count(0) == 0 && !split_by_crate) {
1041 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
1043 _cfg.
ieta = row->ieta;
1044 _cfg.
iphi = row->iphi;
1045 _cfg.
depth = row->idepth;
1046 _cfg.
crate = row->crate;
1047 _cfg.
slot = row->slot;
1048 if (row->topbottom.find(
't') != std::string::npos)
1050 else if (row->topbottom.find(
'b') != std::string::npos)
1052 else if (row->topbottom.find(
'u') != std::string::npos)
1056 _cfg.
fiber = row->fiber;
1074 if (split_by_crate) {
1075 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
1078 _xml[0]->addLut(_cfg, lut_checksums_xml);
1084 <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE"
1091 bool split_by_crate) {
1092 for (
std::map<
int, std::shared_ptr<LutXml>>::const_iterator cr = _xml.begin(); cr != _xml.end(); cr++) {
1093 std::stringstream output_file_name;
1094 if (split_by_crate) {
1095 output_file_name << _tag <<
"_" << cr->first <<
".xml";
1097 output_file_name << _tag <<
".xml";
1099 cr->second->write(output_file_name.str());
1106 std::map<int, std::shared_ptr<LutXml>> xml;
1107 if (!lut_checksums_xml) {
1108 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1111 if (!_lin_file.empty()) {
1112 addLutMap(xml, getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, 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);
1125 bool split_by_crate) {
1127 std::map<int, std::shared_ptr<LutXml>> xml;
1128 if (!lut_checksums_xml) {
1129 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1132 if (!_lin_file.empty()) {
1134 addLutMap(xml, getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate));
1136 if (!_comp_file.empty()) {
1138 addLutMap(xml, getCompressionLutXmlFromAsciiMaster(_comp_file, _tag, -1, split_by_crate));
1141 writeLutXmlFiles(xml, _tag, split_by_crate);
1143 std::string checksums_file = _tag +
"_checksums.xml";
1144 lut_checksums_xml->write(checksums_file);
1151 std::map<int, std::shared_ptr<LutXml>> xml;
1152 if (!lut_checksums_xml) {
1153 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1156 addLutMap(xml, getCompressionLutXmlFromCoder(_tag, split_by_crate));
1158 writeLutXmlFiles(xml, _tag, split_by_crate);
1160 std::string checksums_file = _tag +
"_checksums.xml";
1161 lut_checksums_xml->write(checksums_file);
1168 std::map<int, std::shared_ptr<LutXml>> xml;
1169 if (!lut_checksums_xml) {
1170 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1174 addLutMap(xml, getLinearizationLutXmlFromCoderEmap(_coder, _tag, split_by_crate));
1175 addLutMap(xml, getCompressionLutXmlFromCoder(_tag, split_by_crate));
1177 writeLutXmlFiles(xml, _tag, split_by_crate);
1179 std::string checksums_file = _tag +
"_checksums.xml";
1180 lut_checksums_xml->write(checksums_file);
1192 bool split_by_crate) {
1193 std::map<int, std::shared_ptr<LutXml>> xml;
1194 if (!lut_checksums_xml) {
1195 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1198 if (!_lin_file.empty()) {
1199 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_ascii_xml =
1200 getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate);
1201 addLutMap(xml, _lin_lut_ascii_xml);
1203 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_xml =
1204 getLinearizationLutXmlFromCoderEmap(_coder, _tag, split_by_crate);
1205 addLutMap(xml, _lin_lut_xml);
1207 const std::map<int, std::shared_ptr<LutXml>> _comp_lut_xml =
1208 getCompressionLutXmlFromCoder(_transcoder, _tag, split_by_crate);
1209 addLutMap(xml, _comp_lut_xml);
1211 const std::map<int, std::shared_ptr<LutXml>> _HE_FG_lut_xml = getHEFineGrainLUTs(_tag, split_by_crate);
1212 addLutMap(xml, _HE_FG_lut_xml);
1214 writeLutXmlFiles(xml, _tag, split_by_crate);
1216 std::string checksums_file = _tag +
"_checksums.xml";
1217 lut_checksums_xml->write(checksums_file);
1225 bool split_by_crate) {
1226 std::map<int, std::shared_ptr<LutXml>> xml;
1227 if (!lut_checksums_xml) {
1228 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1231 if (!_lin_file.empty()) {
1232 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_ascii_xml =
1233 getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate);
1234 addLutMap(xml, _lin_lut_ascii_xml);
1236 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_xml =
1237 getLinearizationLutXmlFromCoderEmap(_coder, _tag, split_by_crate);
1238 addLutMap(xml, _lin_lut_xml);
1240 const std::map<int, std::shared_ptr<LutXml>> _comp_lut_xml = getCompressionLutXmlFromCoder(_tag, split_by_crate);
1241 addLutMap(xml, _comp_lut_xml);
1243 writeLutXmlFiles(xml, _tag, split_by_crate);
1245 std::string checksums_file = _tag +
"_checksums.xml";
1246 lut_checksums_xml->write(checksums_file);
1254 bool split_by_crate) {
1256 std::map<int, std::shared_ptr<LutXml>> xml;
1257 if (!lut_checksums_xml) {
1258 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1261 if (!_lin_file.empty()) {
1262 addLutMap(xml, getLutXmlFromAsciiMaster(_lin_file, _tag, -1, split_by_crate));
1264 addLutMap(xml, getCompressionLutXmlFromCoder(_tag, split_by_crate));
1265 writeLutXmlFiles(xml, _tag, split_by_crate);
1267 std::string checksums_file = _tag +
"_checksums.xml";
1268 lut_checksums_xml->write(checksums_file);
1275 for (
std::map<
int, std::shared_ptr<LutXml>>::const_iterator lut =
other.begin(); lut !=
other.end(); lut++) {
1276 edm::LogInfo(
"HcalLutManager") <<
"Added LUTs for crate " << lut->first;
1277 if (
result.count(lut->first) == 0) {
1280 *(
result[lut->first]) += *(lut->second);
1288 strftime(timebuf, 50,
"%Y-%m-%d %H:%M:%S", gmtime(&_time));
1291 return creationstamp;
1295 local_connect(_filename,
"backup/HCALmapHBEF.txt",
"backup/HCALmapHO.txt");
1299 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
1300 int map_size = _map.size();
1301 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << map_size <<
" channels";
1304 std::vector<unsigned int> _lut;
1305 _lut = getLutFromXml(_tag, 1107313727, hcal::ConfigurationDatabase::LinearizerLUT);
1307 edm::LogInfo(
"HcalLutManager") <<
"Testing direct parsing of the LUT XML";
1309 gettimeofday(&_t,
nullptr);
1310 double _time = (double)(_t.tv_sec) + (double)(_t.tv_usec) / 1000000.0;
1311 test_direct_xml_parsing(_filename);
1312 gettimeofday(&_t,
nullptr);
1313 edm::LogInfo(
"HcalLutManager") <<
"parsing took that much time: "
1314 << (double)(_t.tv_sec) + (double)(_t.tv_usec) / 1000000.0 - _time;
1316 gettimeofday(&_t,
nullptr);
1317 _time = (double)(_t.tv_sec) + (double)(_t.tv_usec) / 1000000.0;
1318 edm::LogInfo(
"HcalLutManager") <<
"before loop over random LUTs: " << _time;
1322 for (
int _iter = 0; _iter < 100; _iter++) {
1323 gettimeofday(&_t,
nullptr);
1328 int _key = (rand() % map_size);
1330 if ((_map[_key].subdet.find(
"HB") != string::npos || _map[_key].subdet.find(
"HE") != string::npos ||
1331 _map[_key].subdet.find(
"HO") != string::npos || _map[_key].subdet.find(
"HF") != string::npos) &&
1332 _map[_key].subdet.size() == 2) {
1334 if (_map[_key].subdet.find(
"HB") != string::npos)
1336 else if (_map[_key].subdet.find(
"HE") != string::npos)
1338 else if (_map[_key].subdet.find(
"HO") != string::npos)
1340 else if (_map[_key].subdet.find(
"HF") != string::npos)
1345 _raw_id = _detid.
rawId();
1349 _lut = getLutFromXml(_tag, _raw_id, hcal::ConfigurationDatabase::LinearizerLUT);
1351 gettimeofday(&_t,
nullptr);
1353 double d_time = _t.tv_sec + _t.tv_usec / 1000000.0 - _time;
1354 edm::LogInfo(
"HcalLutManager") <<
"after the loop over random LUTs: " << _time + d_time << std::endl
1355 <<
"total time: " << d_time << std::endl;
1357 edm::LogInfo(
"HcalLutManager") <<
"LUT length = " << _lut.size();
1358 for (std::vector<unsigned int>::const_iterator
i = _lut.end() - 1;
i != _lut.begin() - 1;
i--) {
1359 edm::LogInfo(
"HcalLutManager") << (
i - _lut.begin()) <<
" " << _lut[(
i - _lut.begin())];
1374 lmap->read(lmap_hbef_file,
"HBEF");
1375 lmap->read(lmap_ho_file,
"HO");
1376 edm::LogInfo(
"HcalLutManager") <<
"LMap contains " << lmap->get_map().size()
1377 <<
" channels (compare to 9072 of all HCAL channels)";
1384 db->connect(lut_xml_file);
1389 read_lmap(lmap_hbef_file, lmap_ho_file);
1390 read_luts(lut_xml_file);
1396 hcal::ConfigurationDatabase::LUTType _lt) {
1397 edm::LogInfo(
"HcalLutManager") <<
"getLutFromXml (new version) is not implemented. Use getLutFromXml_old() for now";
1399 std::vector<unsigned int>
result;
1407 hcal::ConfigurationDatabase::LUTType _lt) {
1409 edm::LogError(
"HcalLutManager") <<
"Cannot find LUT without LMAP, exiting...";
1413 edm::LogError(
"HcalLutManager") <<
"Cannot find LUT, no source (local XML file), exiting...";
1417 std::vector<unsigned int>
result;
1419 std::map<int, LMapRow>& _map = lmap->get_map();
1424 unsigned int _crate, _slot, _fiber, _channel;
1426 int topbottom, luttype;
1429 if (_map.find(_rawid) != _map.end()) {
1430 _crate = _map[_rawid].crate;
1431 _slot = _map[_rawid].htr;
1432 _fiber = _map[_rawid].htr_fi;
1433 _channel = _map[_rawid].fi_ch;
1434 _fpga = _map[_rawid].fpga;
1436 if (_fpga.find(
"top") != std::string::npos)
1438 else if (_fpga.find(
"bot") != std::string::npos)
1441 edm::LogError(
"HcalLutManager") <<
"Irregular LMAP fpga value... do not know what to do - exiting";
1444 if (_lt == hcal::ConfigurationDatabase::LinearizerLUT)
1449 result =
db->getOnlineLUT(
tag, _crate, _slot, topbottom, _fiber, _channel, luttype);
1456 std::map<int, std::shared_ptr<LutXml>> lut_map = get_brickSet_from_oracle(
tag, db_accessor);
1457 if (split_by_crate) {
1458 writeLutXmlFiles(lut_map,
tag, split_by_crate);
1461 for (
std::map<
int, std::shared_ptr<LutXml>>::const_iterator xml = lut_map.begin(); xml != lut_map.end(); xml++) {
1462 result += *(xml->second);
1477 db->connect(_accessor);
1478 oracle::occi::Connection* _connection =
db->getConnection();
1480 edm::LogInfo(
"HcalLutManager") <<
"Preparing to request the LUT CLOBs from the database...";
1488 std::string query = (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB, CRATE FROM CMS_HCL_HCAL_COND.V_HCAL_TRIG_LOOKUP_TABLES");
1494 std::map<int, std::shared_ptr<LutXml>> lut_map;
1498 edm::LogInfo(
"HcalLutManager") <<
"Executing the query...";
1499 Statement* stmt = _connection->createStatement();
1500 ResultSet* rs = stmt->executeQuery(
query);
1501 edm::LogInfo(
"HcalLutManager") <<
"Executing the query... done";
1503 edm::LogInfo(
"HcalLutManager") <<
"Processing the query results...";
1505 while (rs->next()) {
1507 oracle::occi::Clob clob = rs->getClob(1);
1508 int crate = rs->getInt(2);
1510 edm::LogInfo(
"HcalLutManager") <<
"Getting LUTs for crate #" << crate <<
" out of the database...";
1511 brick_set =
db->clobToString(clob);
1521 const char*
bs = brick_set.c_str();
1522 MemBufInputSource* lut_clob =
new MemBufInputSource((
const XMLByte*)
bs, strlen(
bs),
"lut_clob",
false);
1523 std::shared_ptr<LutXml> lut_xml = std::make_shared<LutXml>(*lut_clob);
1524 lut_map[crate] = lut_xml;
1529 _connection->terminateStatement(stmt);
1531 }
catch (SQLException&
e) {
1532 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
1549 edm::LogInfo(
"HcalLutManager") <<
"Generating XML loader for LUTs...";
1564 std::stringstream _subversion;
1565 _subversion << subversion;
1575 std::vector<int> crate_number;
1577 for (std::vector<std::string>::const_iterator _f =
file_name.begin(); _f !=
file_name.end(); _f++) {
1578 int crate_begin = _f->rfind(
"_");
1579 int crate_end = _f->rfind(
".xml.dat");
1580 crate_number.push_back(
getInt(_f->substr(crate_begin + 1, crate_end - crate_begin - 1)));
1586 time_t _offset =
time(
nullptr);
1587 sprintf(_buf,
"%d", (uint32_t)_offset);
1592 for (std::vector<std::string>::const_iterator _file =
file_name.begin(); _file !=
file_name.end(); _file++) {
1599 sprintf(_buf,
"%.2d", conf.
crate);
1602 sprintf(_buf,
"CRATE%.2d", conf.
crate);
1604 _namelabel.append(_buf);
1609 doc.addChecksums(&CSconf);
1611 doc.write(tag_name +
"_Loader.xml");
1613 edm::LogInfo(
"HcalLutManager") <<
"Generating XML loader for LUTs... done.";
1623 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
1624 std::stringstream
s;
1625 s <<
"EMap contains " << _map.size() <<
" channels" << std::endl;
1629 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
1631 if (row->subdet.find(
"HT") != std::string::npos) {
1632 s <<
" -----> Subdet = " << row->subdet << std::endl;
1634 if (
abs(row->ieta) > 28) {
1636 s <<
" ==> (ieta,iphi) = " << row->ieta <<
", " << row->iphi << std::endl;
1679 bool split_by_crate) {
1680 std::map<int, std::shared_ptr<LutXml>> xml;
1681 if (!lut_checksums_xml) {
1682 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1685 if (!_lin_file.empty()) {
1686 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_ascii_xml =
1687 getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate);
1688 addLutMap(xml, _lin_lut_ascii_xml);
1690 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_xml =
1691 getLinearizationLutXmlFromCoderEmap(_coder, _tag, split_by_crate);
1692 addLutMap(xml, _lin_lut_xml);
1694 const std::map<int, std::shared_ptr<LutXml>> _comp_lut_xml =
1695 getCompressionLutXmlFromCoder(_transcoder, _tag, split_by_crate);
1696 addLutMap(xml, _comp_lut_xml);
1698 const std::map<int, std::shared_ptr<LutXml>> _HE_FG_lut_xml = getHEFineGrainLUTs(_tag, split_by_crate);
1699 addLutMap(xml, _HE_FG_lut_xml);
1701 for (
auto masktype : {0, 1, 2}) {
1702 const auto masks = getMasks(masktype, _tag, split_by_crate);
1703 addLutMap(xml, masks);
1706 const std::map<int, std::shared_ptr<LutXml>> _zdc_lut_xml = getZdcLutXml(_tag, split_by_crate);
1707 addLutMap(xml, _zdc_lut_xml);
1709 writeLutXmlFiles(xml, _tag, split_by_crate);
1711 std::string checksums_file = _tag +
"_checksums.xml";
1712 lut_checksums_xml->write(checksums_file);
1718 edm::LogInfo(
"HcalLutManager") <<
"Generating ZDC LUTs ...may the Force be with us...";
1719 std::map<int, std::shared_ptr<LutXml>> _xml;
1725 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
1726 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" channels";
1730 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
1734 if (row->zdc_section.find(
"ZDC") != std::string::npos) {
1735 if (_xml.count(row->crate) == 0 && split_by_crate) {
1736 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
1737 }
else if (_xml.count(0) == 0 && !split_by_crate) {
1738 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
1741 _cfg.
ieta = row->zdc_channel;
1744 _cfg.
depth = row->idepth;
1745 _cfg.
crate = row->crate;
1746 _cfg.
slot = row->slot;
1747 if (row->topbottom.find(
't') != std::string::npos)
1749 else if (row->topbottom.find(
'b') != std::string::npos)
1753 _cfg.
fiber = row->fiber;
1764 std::vector<int> coder_lut =
zdc.get_lut(row->zdc_section, row->zdc_zside, row->zdc_channel);
1765 edm::LogInfo(
"HcalLutManager") <<
"***DEBUG: ZDC lut size: " << coder_lut.size();
1766 if (!coder_lut.empty()) {
1767 for (std::vector<int>::const_iterator _i = coder_lut.begin(); _i != coder_lut.end(); _i++) {
1768 unsigned int _temp = (
unsigned int)(*_i);
1771 _cfg.
lut.push_back(_temp);
1775 if (split_by_crate) {
1776 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
1779 _xml[0]->addLut(_cfg, lut_checksums_xml);
1786 <<
"Generating ZDC LUTs...DONE" << std::endl;