15#include "eformat/SourceIdentifier.h"
41 {0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60,
42 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63,
43 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61,
44 2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62 };
46 uint32_t bitFieldSize(uint32_t word, uint8_t offset, uint8_t size) {
47 return (word >> offset) & ((1U << size) - 1);
50 uint32_t coolId(uint8_t crate, uint8_t module, uint8_t channel) {
53 return (crate << 24) | (1 << 20) | (module << 16) | (pin << 8) | asic;
56 int16_t pedCorrection(uint16_t twoBytePedCor) {
57 return twoBytePedCor > 511? (twoBytePedCor - 1024): twoBytePedCor;
61 std::string noAuxSuffix(
const std::string& name) {
62 if ((
name.size() > 4) && (
name.substr(
name.size()-4, 4) ==
"Aux.")) {
63 return name.substr(0,
name.size() - 4);
77 m_errorTool(
"ZdcL1CaloErrorByteStreamTool/ZdcL1CaloErrorByteStreamTool"),
80 declareInterface<ZdcByteStreamReadV1V2Tool>(
this);
84 "Get ROB source IDs service");
98 const ZdcID* zdcID =
nullptr;
99 if (
detStore()->retrieve( zdcID ).isFailure() ) {
100 msg(MSG::ERROR) <<
"execute: Could not retrieve ZdcID object from the detector store" <<
endmsg;
101 return StatusCode::FAILURE;
104 msg(MSG::DEBUG) <<
"execute: retrieved ZdcID" <<
endmsg;
110 return StatusCode::SUCCESS;
118 return StatusCode::SUCCESS;
133 for (; rob != robEnd; ++rob) {
135 if (!
sc.isSuccess()) {
139 return StatusCode::SUCCESS;
150 ttCollection->setStore(
aux);
153 StatusCode
sc =
convert(robFrags,ttCollection);
157 if (
sc != StatusCode::SUCCESS) {
167 (*zdcCollection) = (*zc);
172 return StatusCode::SUCCESS;
178 return convert(
"ZdcTriggerTowerContainer", ttCollection);
190 m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags,
"ZdcByteStreamxAODReadTool");
191 ATH_MSG_DEBUG(
"Number of ROB fragments:" << robFrags.size());
194 return StatusCode::SUCCESS;
202 auto rob = **robIter;
205 "Treating ROB fragment source id #" << MSG::hex << rob.rob_source_id());
215 if (rob.nstatus() > 0) {
221 return StatusCode::FAILURE;
229 rob.rod_data(payloadBeg);
230 payloadEnd = payloadBeg + rob.rod_ndata();
231 payload = payloadBeg;
233 if (payload == payloadEnd) {
235 return StatusCode::FAILURE;
240 uint16_t rodVer = rob.rod_version() & 0xffff;
241 state.
m_verCode = ((rodVer & 0xfff) << 4) | 1;
242 uint32_t rodRunNumber = rob.rod_run_no() & 0xffffff;
247 return StatusCode::FAILURE;
250 ATH_MSG_DEBUG(
"Treating crate " << rodCrate <<
" slink " << rodSlink);
255 return StatusCode::FAILURE;
259 "Run number: " << MSG::dec << rodRunNumber <<
endmsg
260 <<
"Version code: 0x" << MSG::hex <<
int(state.
m_verCode) << MSG::dec
261 <<
endmsg <<
"LUT triggered slice offset: "
264 <<
endmsg <<
"FADC baseline lower bound: "
268 uint8_t blockType = 0;
271 for (; payload != payloadEnd; ++payload) {
282 blockType = (*payload >> 28) & 0xf;
284 if ((blockType & 0xd) == 0xc) {
293 subBlock = blockType & 0xe;
294 }
else if (blockType == (subBlock | 1)) {
300 case eformat::TDAQ_CALO_PREPROC:
303 case eformat::FORWARD_ZDC:
313 return StatusCode::SUCCESS;
329 return StatusCode::FAILURE;
331 return StatusCode::SUCCESS;
369 <<
"' for rob version '"
371 << MSG::dec <<
"'" );
372 return StatusCode::FAILURE;
374 return StatusCode::SUCCESS;
380 uint8_t totSlice = 3 * numLut + numFadc;
383 for (
int asic = 0 ; asic < 4 ; ++asic ) {
384 for (
int mcm = 0 ; mcm < 16 ; ++mcm ) {
386 std::vector<uint32_t> rotated(totSlice);
388 for ( uint8_t slice = 0 ; slice < totSlice ; ++slice ) {
389 for ( uint8_t bit = 0 ; bit < 11 ; ++bit ) {
390 if ( state.
m_ppBlock[slice * 11 + asic * (11 * totSlice) + bit + 1] & (1 << mcm))
391 rotated[slice] |= (1 << bit);
395 bool nonZeroData =
false;
396 for (uint8_t slice = 0; slice < numLut; ++slice) {
398 || rotated[slice + numLut]
399 || rotated[slice + 2 * numLut + numFadc]) {
405 std::vector<uint8_t> lcpVal;
406 std::vector<uint8_t> lcpBcidVec;
407 std::vector<uint8_t> ljeVal;
408 std::vector<uint8_t> ljeSat80Vec;
409 std::vector<int16_t> pedCor;
410 std::vector<uint8_t> pedEn;
412 std::vector<uint16_t> adcVal;
413 std::vector<uint8_t> adcExt;
416 for (uint8_t slice = 0; slice < numLut; ++slice) {
417 lcpVal.push_back(rotated[slice] & 0xff);
418 ljeVal.push_back(rotated[slice + numLut] & 0xff);
419 pedCor.push_back(::pedCorrection(rotated[slice + 2 * numLut + numFadc] & 0x3ff));
421 lcpBcidVec.push_back((rotated[slice] >> 8) & 0x7);
422 ljeSat80Vec.push_back((rotated[slice + numLut] >> 8) & 0x7);
423 pedEn.push_back((rotated[slice + 2 * numLut + numFadc] >> 10) & 0x1);
427 for (uint8_t slice = 0; slice < numFadc; ++slice) {
428 if (rotated[slice + numLut]) {
435 for (uint8_t slice = 0; slice < numFadc; ++ slice) {
436 adcVal.push_back(rotated[slice + 2 * numLut] & 0x3ff);
437 adcExt.push_back((rotated[slice + 2 * numLut] >> 10 & 0x1) & 0x3ff);
457 return StatusCode::SUCCESS;
467 present = br.getField (1);
477 std::vector<uint16_t> adcVal = {0 , 0, 0, 0, 0};
478 std::vector<uint8_t> adcExt = {0 , 0, 0, 0, 0};
480 uint8_t minHeader = br.getField (4);
481 uint8_t minIndex = minHeader % 5;
482 if (minHeader < 15) {
483 if (minHeader < 10) {
486 fmt = 2 + br.getField (2);
487 uint8_t haveLut = br.getField (1);
490 lutVal = br.getField (3);
494 uint8_t haveExt = br.getField (1);
496 lutVal = br.getField (8);
497 lutExt = br.getField (1);
498 lutSat = br.getField (1);
499 lutPeak = br.getField (1);
503 for(uint8_t i = 0; i < 5; ++i) {
504 adcExt[i] = br.getField (1);
513 uint8_t haveAdc = br.getField (1);
515 uint16_t val = br.getField (10);
516 for(uint8_t i = 0; i < 5; ++i) {
528 std::vector<uint8_t> {lutVal},
529 std::vector<uint8_t> {uint8_t(lutExt | (lutSat << 1) | (lutPeak << 2))},
536 }
catch (
const std::out_of_range& ex) {
540 return StatusCode::SUCCESS;
545 BitReader& br, uint8_t format, uint8_t minIndex)
const {
547 std::vector<uint16_t> adc = {0, 0, 0, 0, 0};
550 for(uint8_t i = 0; i <5; ++i) {
551 uint8_t longField = 0;
554 longField = br.getField (1);
555 numBits = longField == 0? 4: (format * 2);
557 numBits = i == 0? 4: (format + 2);
561 minAdc = br.getField (numBits);
562 if (longField == 0) {
566 adc[i] = minAdc + br.getField (numBits);
573 adc[0] = adc[minIndex];
574 adc[minIndex] = minAdc;
591 const uint8_t nTotal = numAdc + numLut;
592 const uint8_t wordsPerBlock = 8;
593 const uint8_t iBlk = inData / wordsPerBlock;
597 for(uint8_t i = 0; i < 2; ++i) {
598 uint16_t subword = (word >> 16 * i) & 0x7ff;
599 state.
m_ppLuts[iChan].push_back(subword);
602 }
else if (iBlk < nTotal) {
603 for(uint8_t i = 0; i < 2; ++i) {
604 uint16_t subword = (word >> (16 * i)) & 0x7ff;
605 state.
m_ppFadcs[iChan].push_back(subword);
611 sc = StatusCode::FAILURE;
621 return StatusCode::SUCCESS;
625 return StatusCode::SUCCESS;
627 return StatusCode::FAILURE;
635 int16_t pedCorBase = -20;
644 for(uint8_t chan = 0; chan < 64; ++chan) {
647 std::vector<uint8_t> haveLut(numLut, 0);
648 std::vector<uint8_t> lcpVal(numLut, 0);
650 std::vector<uint8_t> lcpExt(numLut, 0);
651 std::vector<uint8_t> lcpSat(numLut, 0);
652 std::vector<uint8_t> lcpPeak(numLut, 0);
653 std::vector<uint8_t> lcpBcidVec(numLut, 0);
655 std::vector<uint8_t> ljeVal(numLut, 0);
657 std::vector<uint8_t> ljeLow(numLut, 0);
658 std::vector<uint8_t> ljeHigh(numLut, 0);
659 std::vector<uint8_t> ljeRes(numLut, 0);
660 std::vector<uint8_t> ljeSat80Vec(numLut, 0);
662 std::vector<uint16_t> adcVal(numAdc, 0);
663 std::vector<uint8_t> adcExt(numAdc, 0);
664 std::vector<int16_t> pedCor(numLut, 0);
665 std::vector<uint8_t> pedEn(numLut, 0);
667 int8_t encoding = -1;
668 int8_t minIndex = -1;
671 present = br.getField (1);
675 CHECK((encoding != -1) && (minIndex != -1));
679 for(
uint i=0; i < numLut; ++i) {
680 lcpPeak[i] = br.getField (1);
684 for (uint8_t i = 0; i < numLut; ++i) {
685 ljeLow[i] = br.getField (1);
691 for (uint8_t i = 0; i < numLut; ++i) {
692 if (lcpPeak[i] == 1) {
693 lcpVal[i] = br.getField (4);
696 for(uint8_t i = 0; i < numLut; ++i) {
697 if (lcpPeak[i] == 1){
698 ljeVal[i] = br.getField (3);
702 }
else if (encoding < 6) {
704 for(uint8_t i = 0; i < numLut; ++i){
705 haveLut[i] = br.getField (1);
709 uint8_t haveExt = br.getField (1);
712 for (uint8_t i = 0; i < numAdc; ++i) {
713 adcExt[i] = br.getField (1);
717 for(uint8_t i = 0; i < numLut; ++i){
718 if (haveLut[i] == 1) {
719 lcpVal[i] = br.getField (8);
720 lcpExt[i] = br.getField (1);
721 lcpSat[i] = br.getField (1);
722 lcpPeak[i] = br.getField (1);
726 for(uint8_t i = 0; i < numLut; ++i){
727 if (haveLut[i] == 1) {
728 ljeVal[i] = br.getField (8);
729 ljeLow[i] = br.getField (1);
730 ljeHigh[i] = br.getField (1);
731 ljeRes[i] = br.getField (1);
740 return StatusCode::FAILURE;
745 if ((encoding < 3) || (encoding == 6)) {
746 for (uint8_t i = 0; i < numLut; ++i)
748 pedCor[i] = br.getField (6) + pedCorBase;
757 for (uint8_t i = 0; i < numLut; ++i)
759 uint16_t val = br.getField (10);
760 pedCor[i] = ::pedCorrection(val);
761 pedEn[i] = br.getField (1);
765 for(uint8_t i=0; i < numLut; ++i){
766 lcpBcidVec[i] = uint8_t((lcpPeak[i] << 2) | (lcpSat[i] << 1) | lcpExt[i]);
767 ljeSat80Vec[i] = uint8_t((ljeRes[i] << 2) | (ljeHigh[i] << 1) | ljeLow[i]);
770 chan, lcpVal, lcpBcidVec, ljeVal, ljeSat80Vec, adcVal, adcExt, pedCor,
773 }
catch (
const std::out_of_range& ex) {
777 return StatusCode::SUCCESS;
783 int8_t& encoding, int8_t& minIndex)
const {
784 uint8_t minHeader = 0;
787 minHeader = br.getField (4);
789 minIndex = minHeader % 5;
791 if (minHeader < 10) {
792 encoding = minHeader / 5;
794 encoding = 2 + br.getField (2);
803 }
else if (numAdc == 7) {
805 }
else if (numAdc < 16) {
810 uint8_t fieldSize = 1 << numBits;
811 minHeader = br.getField (numBits);
812 uint8_t encValue = fieldSize - 1;
813 if (minHeader == encValue) {
817 minHeader += br.getField (2) << numBits;
818 minIndex = minHeader % fieldSize;
819 encValue = 3 * fieldSize;
821 if (minHeader < encValue) {
822 encoding = minHeader / fieldSize;
824 encoding = 3 + br.getField (2);
833 BitReader& br, uint8_t encoding, uint8_t minIndex)
const {
837 uint16_t val = br.getField (6);
838 return std::vector<uint16_t>(numAdc, val);
839 }
else if ( encoding < 3) {
840 std::vector<uint16_t> adc(numAdc, 0);
842 adc[minIndex] = minAdc;
843 for(uint8_t i = 1; i < numAdc; ++i) {
844 adc[i == minIndex? 0: i] = br.getField (encoding + 2) + minAdc;
848 std::vector<uint16_t> adc(numAdc, 0);
849 uint16_t minAdc = br.getField (1)
850 ? br.getField (encoding * 2)
854 adc[minIndex] = minAdc;
855 for (uint8_t i = 1; i < numAdc; ++i) {
856 adc[minIndex == i? 0: i] = br.getField (
857 br.getField (1)? encoding * 2: 4
867 return StatusCode::SUCCESS;
870 return StatusCode::FAILURE;
872 return StatusCode::FAILURE;
886 for (uint8_t chan = 0; chan < 64; ++chan) {
888 std::vector<uint8_t> lcpVal;
889 std::vector<uint8_t> lcpBcidVec;
891 std::vector<uint8_t> ljeVal;
892 std::vector<uint8_t> ljeSat80Vec;
896 std::vector<uint16_t> adcVal;
897 std::vector<uint8_t> adcExt;
898 std::vector<int16_t> pedCor;
899 std::vector<uint8_t> pedEn;
901 for (
int i = 0; i < numLut; ++i) {
902 lcpVal.push_back(br.getField (8));
903 lcpBcidVec.push_back(br.getField (3));
906 for (
int i = 0; i < numLut; ++i) {
907 ljeVal.push_back(br.getField (8));
908 ljeSat80Vec.push_back(br.getField (3));
911 for (
int i = 0; i < numAdc; ++i) {
912 adcVal.push_back(br.getField (10));
913 adcExt.push_back(br.getField (1));
916 for (
int i = 0; i < numLut; ++i) {
917 uint16_t pc = br.getField (10);
918 pedCor.push_back(pedCorrection(pc));
919 pedEn.push_back(br.getField (1));
921 }
catch (
const std::out_of_range& ex) {
927 ljeVal, ljeSat80Vec, adcVal, adcExt, pedCor, pedEn));
930 return StatusCode::SUCCESS;
934 for(
const auto& lut : state.
m_ppLuts) {
943 return StatusCode::SUCCESS;
951 const std::vector<uint8_t>& lcpVal,
952 const std::vector<uint8_t>& lcpBcidVec,
953 const std::vector<uint8_t>& ljeVal,
954 const std::vector<uint8_t>& ljeSat80Vec,
955 const std::vector<uint16_t>& adcVal,
956 const std::vector<uint8_t>& adcExt,
957 const std::vector<int16_t>& pedCor,
958 const std::vector<uint8_t>& pedEn)
const {
965 bool isNotSpare =
false;
975 const int pin = channel % 16;
976 const int asic = channel / 16;
977 eta = 16 * crate + module;
978 phi = 4 * pin + asic;
981 uint32_t coolId = ::coolId(crate, module, channel);
1006 tt->initialize(coolId,
eta,
phi, lcpVal, ljeVal, pedCor, pedEn,
1009 return StatusCode::SUCCESS;
1017 const std::vector<uint8_t>& luts,
1018 const std::vector<uint8_t>& lcpBcidVec,
1019 const std::vector<uint16_t>& fadc,
1020 const std::vector<uint8_t>& bcidExt
1023 std::vector<uint8_t> ljeSat80Vec;
1025 std::vector<int16_t> pedCor;
1026 std::vector<uint8_t> pedEn;
1029 luts , ljeSat80Vec, fadc, bcidExt, pedCor, pedEn)
1032 return StatusCode::SUCCESS;
1040 const std::vector<uint16_t>& luts,
1041 const std::vector<uint16_t>& fadc
1044 std::vector<uint8_t> lcpVal;
1045 std::vector<uint8_t> lcpBcidVec;
1047 std::vector<uint16_t> adcVal;
1048 std::vector<uint8_t> adcExt;
1050 for(
auto lut: luts) {
1063 return StatusCode::SUCCESS;
1068 const int crates = 8;
1073 for (
int crate = 0; crate < crates; ++crate) {
1074 for (
int slink = 0; slink <
m_srcIdMap->maxSlinks(); ++slink) {
1077 const uint32_t rodId =
m_srcIdMap->getRodID(crate, slink, 0,
1078 eformat::FORWARD_ZDC);
1079 const uint32_t robId =
m_srcIdMap->getRobID(rodId);
1082 if (crate > 1 && crate < 6) {
1084 if (crate < 4 && slink == 0) {
1095 const std::string& sgKey)
const
1097 if (sgKey.find(
"Muon") != std::string::npos) {
1100 else if (sgKey.find(
"Spare") != std::string::npos) {
1110 (
const uint8_t numBits)
1118 if ((iBit + numBits) <= 31) {
1121 uint8_t nb1 = 31 - iBit;
1122 uint8_t nb2 = numBits - nb1;
1123 uint32_t field1 = ::bitFieldSize(
m_ppBlock[iWord], iBit, nb1);
1124 uint32_t field2 = ::bitFieldSize(
m_ppBlock[iWord + 1], 0, nb2);
1125 result = field1 | (field2 << nb1);
1131 throw std::out_of_range(
"Requested too much bits from ppm block");
1136 typedef std::map<uint32_t,ZdcDigits*> hashmapType;
1137 hashmapType digits_map;
1142 uint32_t coolId = tt->coolId();
1143 uint32_t pin = (coolId>>8) & 0xf;
1144 uint32_t asic = coolId & 0xf;
1145 uint32_t slinkChannel = asic*16 + pin;
1148 uint32_t module = (coolId>>16) & 0xf;
1157 ATH_MSG_DEBUG(
"Trying to find chan_hash " << chan_hash <<
" g" << gain <<
"d" <<
delay);
1159 hashmapType::iterator iter = digits_map.find(chan_hash);
1160 if (iter == digits_map.end())
1163 digits_map.insert(std::pair<uint32_t,ZdcDigits*>(chan_hash,
new ZdcDigits(chan_id)));
1164 iter = digits_map.find(chan_hash);
1166 if (iter != digits_map.end())
1169 if (gain==0&&
delay==0) (*iter).second->set_digits_gain0_delay0( tt->adc() );
1170 if (gain==1&&
delay==0) (*iter).second->set_digits_gain1_delay0( tt->adc() );
1171 if (gain==0&&
delay==1) (*iter).second->set_digits_gain0_delay1( tt->adc() );
1172 if (gain==1&&
delay==1) (*iter).second->set_digits_gain1_delay1( tt->adc() );
1179 hashmapType::iterator iter = digits_map.begin();
1180 hashmapType::iterator iter_end = digits_map.end();
1182 while (iter != iter_end)
1194 zdcCollection->
push_back((*iter).second);
1198 return zdcCollection;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define CHECK(...)
Evaluate an expression and check for errors.
double delay(std::size_t d)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
T get(const uint32_t &word) const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
std::vector< const ROBF * > VROBFRAG
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
int hwid2gain(int crate, int channel) const
static const ZdcCablingService * getInstance()
get pointer to service instance
int hwid2delay(int crate, int channel) const
Identifier h2s_channel_id(int crate, int channel) const
This class provides conversion between Lower level Source ID to higher level source ID for L1Calo Byt...
static int crate(uint32_t code)
moduleID -> crate
static int slink(uint32_t code)
moduleID -> slink
TriggerTowerContainer_v2 TriggerTowerContainer
Define the latest version of the TriggerTower container.
setScaleOne setStatusOne setSaturated int16_t
TriggerTower_v2 TriggerTower
Define the latest version of the TriggerTower class.
TriggerTowerAuxContainer_v2 TriggerTowerAuxContainer
Define the latest version of the TriggerTower auxiliary container.