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;
982 int crot = 100 * row->crate + row->slot;
983 unsigned int size = _cfg.
lut.size();
985 edm::LogWarning(
"HcalLutManager") <<
" resizing LUT for " << _detid <<
", channel=[" << _cfg.
crate <<
":"
987 <<
"], using value=" << _cfg.
lut[
size - 1] << std::endl;
992 if (split_by_crate) {
993 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
996 _xml[0]->addLut(_cfg, lut_checksums_xml);
1001 <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE"
1008 bool split_by_crate) {
1009 edm::LogInfo(
"HcalLutManager") <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT";
1010 std::map<int, std::shared_ptr<LutXml>> _xml;
1017 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
1018 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" channels";
1028 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
1033 const int tp_version = row->idepth / 10;
1034 if (row->subdet.find(
"HT") != std::string::npos && _coder.
HTvalid(row->ieta, row->iphi, tp_version)) {
1035 if (_xml.count(row->crate) == 0 && split_by_crate) {
1036 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
1037 }
else if (_xml.count(0) == 0 && !split_by_crate) {
1038 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
1040 _cfg.
ieta = row->ieta;
1041 _cfg.
iphi = row->iphi;
1042 _cfg.
depth = row->idepth;
1043 _cfg.
crate = row->crate;
1044 _cfg.
slot = row->slot;
1045 if (row->topbottom.find(
't') != std::string::npos)
1047 else if (row->topbottom.find(
'b') != std::string::npos)
1049 else if (row->topbottom.find(
'u') != std::string::npos)
1053 _cfg.
fiber = row->fiber;
1071 if (split_by_crate) {
1072 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
1075 _xml[0]->addLut(_cfg, lut_checksums_xml);
1081 <<
"Generating compression (output) LUTs from CaloTPGTranscoderULUT...DONE"
1088 bool split_by_crate) {
1089 for (
std::map<
int, std::shared_ptr<LutXml>>::const_iterator cr = _xml.begin(); cr != _xml.end(); cr++) {
1090 std::stringstream output_file_name;
1091 if (split_by_crate) {
1092 output_file_name << _tag <<
"_" << cr->first <<
".xml";
1094 output_file_name << _tag <<
".xml";
1096 cr->second->write(output_file_name.str());
1103 std::map<int, std::shared_ptr<LutXml>> xml;
1104 if (!lut_checksums_xml) {
1105 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1108 if (!_lin_file.empty()) {
1109 addLutMap(xml, getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate));
1111 writeLutXmlFiles(xml, _tag, split_by_crate);
1113 std::string checksums_file = _tag +
"_checksums.xml";
1114 lut_checksums_xml->write(checksums_file);
1122 bool split_by_crate) {
1124 std::map<int, std::shared_ptr<LutXml>> xml;
1125 if (!lut_checksums_xml) {
1126 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1129 if (!_lin_file.empty()) {
1131 addLutMap(xml, getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate));
1133 if (!_comp_file.empty()) {
1135 addLutMap(xml, getCompressionLutXmlFromAsciiMaster(_comp_file, _tag, -1, split_by_crate));
1138 writeLutXmlFiles(xml, _tag, split_by_crate);
1140 std::string checksums_file = _tag +
"_checksums.xml";
1141 lut_checksums_xml->write(checksums_file);
1148 std::map<int, std::shared_ptr<LutXml>> xml;
1149 if (!lut_checksums_xml) {
1150 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1153 addLutMap(xml, getCompressionLutXmlFromCoder(_tag, split_by_crate));
1155 writeLutXmlFiles(xml, _tag, split_by_crate);
1157 std::string checksums_file = _tag +
"_checksums.xml";
1158 lut_checksums_xml->write(checksums_file);
1165 std::map<int, std::shared_ptr<LutXml>> xml;
1166 if (!lut_checksums_xml) {
1167 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1171 addLutMap(xml, getLinearizationLutXmlFromCoderEmap(_coder, _tag, split_by_crate));
1172 addLutMap(xml, getCompressionLutXmlFromCoder(_tag, split_by_crate));
1174 writeLutXmlFiles(xml, _tag, split_by_crate);
1176 std::string checksums_file = _tag +
"_checksums.xml";
1177 lut_checksums_xml->write(checksums_file);
1189 bool split_by_crate) {
1190 std::map<int, std::shared_ptr<LutXml>> xml;
1191 if (!lut_checksums_xml) {
1192 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1195 if (!_lin_file.empty()) {
1196 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_ascii_xml =
1197 getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate);
1198 addLutMap(xml, _lin_lut_ascii_xml);
1200 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_xml =
1201 getLinearizationLutXmlFromCoderEmap(_coder, _tag, split_by_crate);
1202 addLutMap(xml, _lin_lut_xml);
1204 const std::map<int, std::shared_ptr<LutXml>> _comp_lut_xml =
1205 getCompressionLutXmlFromCoder(_transcoder, _tag, split_by_crate);
1206 addLutMap(xml, _comp_lut_xml);
1208 const std::map<int, std::shared_ptr<LutXml>> _HE_FG_lut_xml = getHEFineGrainLUTs(_tag, split_by_crate);
1209 addLutMap(xml, _HE_FG_lut_xml);
1211 writeLutXmlFiles(xml, _tag, split_by_crate);
1213 std::string checksums_file = _tag +
"_checksums.xml";
1214 lut_checksums_xml->write(checksums_file);
1222 bool split_by_crate) {
1223 std::map<int, std::shared_ptr<LutXml>> xml;
1224 if (!lut_checksums_xml) {
1225 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1228 if (!_lin_file.empty()) {
1229 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_ascii_xml =
1230 getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate);
1231 addLutMap(xml, _lin_lut_ascii_xml);
1233 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_xml =
1234 getLinearizationLutXmlFromCoderEmap(_coder, _tag, split_by_crate);
1235 addLutMap(xml, _lin_lut_xml);
1237 const std::map<int, std::shared_ptr<LutXml>> _comp_lut_xml = getCompressionLutXmlFromCoder(_tag, split_by_crate);
1238 addLutMap(xml, _comp_lut_xml);
1240 writeLutXmlFiles(xml, _tag, split_by_crate);
1242 std::string checksums_file = _tag +
"_checksums.xml";
1243 lut_checksums_xml->write(checksums_file);
1251 bool split_by_crate) {
1253 std::map<int, std::shared_ptr<LutXml>> xml;
1254 if (!lut_checksums_xml) {
1255 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1258 if (!_lin_file.empty()) {
1259 addLutMap(xml, getLutXmlFromAsciiMaster(_lin_file, _tag, -1, split_by_crate));
1261 addLutMap(xml, getCompressionLutXmlFromCoder(_tag, split_by_crate));
1262 writeLutXmlFiles(xml, _tag, split_by_crate);
1264 std::string checksums_file = _tag +
"_checksums.xml";
1265 lut_checksums_xml->write(checksums_file);
1272 for (
std::map<
int, std::shared_ptr<LutXml>>::const_iterator lut =
other.begin(); lut !=
other.end(); lut++) {
1273 edm::LogInfo(
"HcalLutManager") <<
"Added LUTs for crate " << lut->first;
1274 if (
result.count(lut->first) == 0) {
1277 *(
result[lut->first]) += *(lut->second);
1285 strftime(timebuf, 50,
"%Y-%m-%d %H:%M:%S", gmtime(&_time));
1288 return creationstamp;
1292 local_connect(_filename,
"backup/HCALmapHBEF.txt",
"backup/HCALmapHO.txt");
1296 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
1297 int map_size = _map.size();
1298 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << map_size <<
" channels";
1301 std::vector<unsigned int> _lut;
1302 _lut = getLutFromXml(_tag, 1107313727, hcal::ConfigurationDatabase::LinearizerLUT);
1304 edm::LogInfo(
"HcalLutManager") <<
"Testing direct parsing of the LUT XML";
1306 gettimeofday(&_t,
nullptr);
1307 double _time = (double)(_t.tv_sec) + (double)(_t.tv_usec) / 1000000.0;
1308 test_direct_xml_parsing(_filename);
1309 gettimeofday(&_t,
nullptr);
1310 edm::LogInfo(
"HcalLutManager") <<
"parsing took that much time: "
1311 << (double)(_t.tv_sec) + (double)(_t.tv_usec) / 1000000.0 - _time;
1313 gettimeofday(&_t,
nullptr);
1314 _time = (double)(_t.tv_sec) + (double)(_t.tv_usec) / 1000000.0;
1315 edm::LogInfo(
"HcalLutManager") <<
"before loop over random LUTs: " << _time;
1319 for (
int _iter = 0; _iter < 100; _iter++) {
1320 gettimeofday(&_t,
nullptr);
1325 int _key = (rand() % map_size);
1327 if ((_map[_key].subdet.find(
"HB") != string::npos || _map[_key].subdet.find(
"HE") != string::npos ||
1328 _map[_key].subdet.find(
"HO") != string::npos || _map[_key].subdet.find(
"HF") != string::npos) &&
1329 _map[_key].subdet.size() == 2) {
1331 if (_map[_key].subdet.find(
"HB") != string::npos)
1333 else if (_map[_key].subdet.find(
"HE") != string::npos)
1335 else if (_map[_key].subdet.find(
"HO") != string::npos)
1337 else if (_map[_key].subdet.find(
"HF") != string::npos)
1342 _raw_id = _detid.
rawId();
1346 _lut = getLutFromXml(_tag, _raw_id, hcal::ConfigurationDatabase::LinearizerLUT);
1348 gettimeofday(&_t,
nullptr);
1350 double d_time = _t.tv_sec + _t.tv_usec / 1000000.0 - _time;
1351 edm::LogInfo(
"HcalLutManager") <<
"after the loop over random LUTs: " << _time + d_time << std::endl
1352 <<
"total time: " << d_time << std::endl;
1354 edm::LogInfo(
"HcalLutManager") <<
"LUT length = " << _lut.size();
1355 for (std::vector<unsigned int>::const_iterator
i = _lut.end() - 1;
i != _lut.begin() - 1;
i--) {
1356 edm::LogInfo(
"HcalLutManager") << (
i - _lut.begin()) <<
" " << _lut[(
i - _lut.begin())];
1371 lmap->read(lmap_hbef_file,
"HBEF");
1372 lmap->read(lmap_ho_file,
"HO");
1373 edm::LogInfo(
"HcalLutManager") <<
"LMap contains " << lmap->get_map().size()
1374 <<
" channels (compare to 9072 of all HCAL channels)";
1381 db->connect(lut_xml_file);
1386 read_lmap(lmap_hbef_file, lmap_ho_file);
1387 read_luts(lut_xml_file);
1393 hcal::ConfigurationDatabase::LUTType _lt) {
1394 edm::LogInfo(
"HcalLutManager") <<
"getLutFromXml (new version) is not implemented. Use getLutFromXml_old() for now";
1396 std::vector<unsigned int>
result;
1404 hcal::ConfigurationDatabase::LUTType _lt) {
1406 edm::LogError(
"HcalLutManager") <<
"Cannot find LUT without LMAP, exiting...";
1410 edm::LogError(
"HcalLutManager") <<
"Cannot find LUT, no source (local XML file), exiting...";
1414 std::vector<unsigned int>
result;
1416 std::map<int, LMapRow>& _map = lmap->get_map();
1421 unsigned int _crate, _slot, _fiber, _channel;
1423 int topbottom, luttype;
1426 if (_map.find(_rawid) != _map.end()) {
1427 _crate = _map[_rawid].crate;
1428 _slot = _map[_rawid].htr;
1429 _fiber = _map[_rawid].htr_fi;
1430 _channel = _map[_rawid].fi_ch;
1431 _fpga = _map[_rawid].fpga;
1433 if (_fpga.find(
"top") != std::string::npos)
1435 else if (_fpga.find(
"bot") != std::string::npos)
1438 edm::LogError(
"HcalLutManager") <<
"Irregular LMAP fpga value... do not know what to do - exiting";
1441 if (_lt == hcal::ConfigurationDatabase::LinearizerLUT)
1446 result =
db->getOnlineLUT(
tag, _crate, _slot, topbottom, _fiber, _channel, luttype);
1453 std::map<int, std::shared_ptr<LutXml>> lut_map = get_brickSet_from_oracle(
tag, db_accessor);
1454 if (split_by_crate) {
1455 writeLutXmlFiles(lut_map,
tag, split_by_crate);
1458 for (
std::map<
int, std::shared_ptr<LutXml>>::const_iterator xml = lut_map.begin(); xml != lut_map.end(); xml++) {
1459 result += *(xml->second);
1474 db->connect(_accessor);
1475 oracle::occi::Connection* _connection =
db->getConnection();
1477 edm::LogInfo(
"HcalLutManager") <<
"Preparing to request the LUT CLOBs from the database...";
1485 std::string query = (
"SELECT TRIG_PRIM_LOOKUPTBL_DATA_CLOB, CRATE FROM CMS_HCL_HCAL_COND.V_HCAL_TRIG_LOOKUP_TABLES");
1491 std::map<int, std::shared_ptr<LutXml>> lut_map;
1495 edm::LogInfo(
"HcalLutManager") <<
"Executing the query...";
1496 Statement* stmt = _connection->createStatement();
1497 ResultSet* rs = stmt->executeQuery(
query);
1498 edm::LogInfo(
"HcalLutManager") <<
"Executing the query... done";
1500 edm::LogInfo(
"HcalLutManager") <<
"Processing the query results...";
1502 while (rs->next()) {
1504 oracle::occi::Clob clob = rs->getClob(1);
1505 int crate = rs->getInt(2);
1507 edm::LogInfo(
"HcalLutManager") <<
"Getting LUTs for crate #" << crate <<
" out of the database...";
1508 brick_set =
db->clobToString(clob);
1518 const char*
bs = brick_set.c_str();
1519 MemBufInputSource* lut_clob =
new MemBufInputSource((
const XMLByte*)
bs, strlen(
bs),
"lut_clob",
false);
1520 std::shared_ptr<LutXml> lut_xml = std::make_shared<LutXml>(*lut_clob);
1521 lut_map[crate] = lut_xml;
1526 _connection->terminateStatement(stmt);
1528 }
catch (SQLException&
e) {
1529 XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
1546 edm::LogInfo(
"HcalLutManager") <<
"Generating XML loader for LUTs...";
1561 std::stringstream _subversion;
1562 _subversion << subversion;
1572 std::vector<int> crate_number;
1574 for (std::vector<std::string>::const_iterator _f =
file_name.begin(); _f !=
file_name.end(); _f++) {
1575 int crate_begin = _f->rfind(
"_");
1576 int crate_end = _f->rfind(
".xml.dat");
1577 crate_number.push_back(
getInt(_f->substr(crate_begin + 1, crate_end - crate_begin - 1)));
1583 time_t _offset =
time(
nullptr);
1584 sprintf(_buf,
"%d", (uint32_t)_offset);
1589 for (std::vector<std::string>::const_iterator _file =
file_name.begin(); _file !=
file_name.end(); _file++) {
1596 sprintf(_buf,
"%.2d", conf.
crate);
1599 sprintf(_buf,
"CRATE%.2d", conf.
crate);
1601 _namelabel.append(_buf);
1606 doc.addChecksums(&CSconf);
1608 doc.write(tag_name +
"_Loader.xml");
1610 edm::LogInfo(
"HcalLutManager") <<
"Generating XML loader for LUTs... done.";
1620 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
1621 std::stringstream
s;
1622 s <<
"EMap contains " << _map.size() <<
" channels" << std::endl;
1626 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
1628 if (row->subdet.find(
"HT") != std::string::npos) {
1629 s <<
" -----> Subdet = " << row->subdet << std::endl;
1631 if (
abs(row->ieta) > 28) {
1633 s <<
" ==> (ieta,iphi) = " << row->ieta <<
", " << row->iphi << std::endl;
1676 bool split_by_crate) {
1677 std::map<int, std::shared_ptr<LutXml>> xml;
1678 if (!lut_checksums_xml) {
1679 lut_checksums_xml =
new XMLDOMBlock(
"CFGBrick", 1);
1682 if (!_lin_file.empty()) {
1683 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_ascii_xml =
1684 getLinearizationLutXmlFromAsciiMasterEmap(_lin_file, _tag, -1, split_by_crate);
1685 addLutMap(xml, _lin_lut_ascii_xml);
1687 const std::map<int, std::shared_ptr<LutXml>> _lin_lut_xml =
1688 getLinearizationLutXmlFromCoderEmap(_coder, _tag, split_by_crate);
1689 addLutMap(xml, _lin_lut_xml);
1691 const std::map<int, std::shared_ptr<LutXml>> _comp_lut_xml =
1692 getCompressionLutXmlFromCoder(_transcoder, _tag, split_by_crate);
1693 addLutMap(xml, _comp_lut_xml);
1695 const std::map<int, std::shared_ptr<LutXml>> _HE_FG_lut_xml = getHEFineGrainLUTs(_tag, split_by_crate);
1696 addLutMap(xml, _HE_FG_lut_xml);
1698 for (
auto masktype : {0, 1, 2}) {
1699 const auto masks = getMasks(masktype, _tag, split_by_crate);
1700 addLutMap(xml, masks);
1703 const std::map<int, std::shared_ptr<LutXml>> _zdc_lut_xml = getZdcLutXml(_tag, split_by_crate);
1704 addLutMap(xml, _zdc_lut_xml);
1706 writeLutXmlFiles(xml, _tag, split_by_crate);
1708 std::string checksums_file = _tag +
"_checksums.xml";
1709 lut_checksums_xml->write(checksums_file);
1715 edm::LogInfo(
"HcalLutManager") <<
"Generating ZDC LUTs ...may the Force be with us...";
1716 std::map<int, std::shared_ptr<LutXml>> _xml;
1722 std::vector<EMap::EMapRow>& _map = _emap.
get_map();
1723 edm::LogInfo(
"HcalLutManager") <<
"EMap contains " << _map.size() <<
" channels";
1727 for (std::vector<EMap::EMapRow>::const_iterator row = _map.begin(); row != _map.end(); row++) {
1731 if (row->zdc_section.find(
"ZDC") != std::string::npos) {
1732 if (_xml.count(row->crate) == 0 && split_by_crate) {
1733 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(row->crate, std::make_shared<LutXml>()));
1734 }
else if (_xml.count(0) == 0 && !split_by_crate) {
1735 _xml.insert(std::pair<
int, std::shared_ptr<LutXml>>(0, std::make_shared<LutXml>()));
1738 _cfg.
ieta = row->zdc_channel;
1741 _cfg.
depth = row->idepth;
1742 _cfg.
crate = row->crate;
1743 _cfg.
slot = row->slot;
1744 if (row->topbottom.find(
't') != std::string::npos)
1746 else if (row->topbottom.find(
'b') != std::string::npos)
1750 _cfg.
fiber = row->fiber;
1761 std::vector<int> coder_lut =
zdc.get_lut(row->zdc_section, row->zdc_zside, row->zdc_channel);
1762 edm::LogInfo(
"HcalLutManager") <<
"***DEBUG: ZDC lut size: " << coder_lut.size();
1763 if (!coder_lut.empty()) {
1764 for (std::vector<int>::const_iterator _i = coder_lut.begin(); _i != coder_lut.end(); _i++) {
1765 unsigned int _temp = (
unsigned int)(*_i);
1768 _cfg.
lut.push_back(_temp);
1772 if (split_by_crate) {
1773 _xml[row->crate]->addLut(_cfg, lut_checksums_xml);
1776 _xml[0]->addLut(_cfg, lut_checksums_xml);
1783 <<
"Generating ZDC LUTs...DONE" << std::endl;