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;
134 for (; rob != robEnd; ++rob, ++robCounter) {
136 if (!
sc.isSuccess()) {
140 return StatusCode::SUCCESS;
151 ttCollection->setStore(
aux);
154 StatusCode
sc =
convert(robFrags,ttCollection);
158 if (
sc != StatusCode::SUCCESS) {
168 (*zdcCollection) = (*zc);
173 return StatusCode::SUCCESS;
179 return convert(
"ZdcTriggerTowerContainer", ttCollection);
191 m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags,
"ZdcByteStreamxAODReadTool");
192 ATH_MSG_DEBUG(
"Number of ROB fragments:" << robFrags.size());
195 return StatusCode::SUCCESS;
203 auto rob = **robIter;
206 "Treating ROB fragment source id #" << MSG::hex << rob.rob_source_id());
216 if (rob.nstatus() > 0) {
222 return StatusCode::FAILURE;
230 rob.rod_data(payloadBeg);
231 payloadEnd = payloadBeg + rob.rod_ndata();
232 payload = payloadBeg;
234 if (payload == payloadEnd) {
236 return StatusCode::FAILURE;
241 uint16_t rodVer = rob.rod_version() & 0xffff;
242 state.
m_verCode = ((rodVer & 0xfff) << 4) | 1;
243 uint32_t rodRunNumber = rob.rod_run_no() & 0xffffff;
248 return StatusCode::FAILURE;
251 ATH_MSG_DEBUG(
"Treating crate " << rodCrate <<
" slink " << rodSlink);
256 return StatusCode::FAILURE;
260 "Run number: " << MSG::dec << rodRunNumber <<
endmsg
261 <<
"Version code: 0x" << MSG::hex <<
int(state.
m_verCode) << MSG::dec
262 <<
endmsg <<
"LUT triggered slice offset: "
265 <<
endmsg <<
"FADC baseline lower bound: "
269 uint8_t blockType = 0;
272 for (; payload != payloadEnd; ++payload) {
283 blockType = (*payload >> 28) & 0xf;
285 if ((blockType & 0xd) == 0xc) {
294 subBlock = blockType & 0xe;
295 }
else if (blockType == (subBlock | 1)) {
301 case eformat::TDAQ_CALO_PREPROC:
304 case eformat::FORWARD_ZDC:
314 return StatusCode::SUCCESS;
330 return StatusCode::FAILURE;
332 return StatusCode::SUCCESS;
370 <<
"' for rob version '"
372 << MSG::dec <<
"'" );
373 return StatusCode::FAILURE;
375 return StatusCode::SUCCESS;
381 uint8_t totSlice = 3 * numLut + numFadc;
384 for (
int asic = 0 ; asic < 4 ; ++asic ) {
385 for (
int mcm = 0 ; mcm < 16 ; ++mcm ) {
387 std::vector<uint32_t> rotated(totSlice);
389 for ( uint8_t slice = 0 ; slice < totSlice ; ++slice ) {
390 for ( uint8_t bit = 0 ; bit < 11 ; ++bit ) {
391 if ( state.
m_ppBlock[slice * 11 + asic * (11 * totSlice) + bit + 1] & (1 << mcm))
392 rotated[slice] |= (1 << bit);
396 bool nonZeroData =
false;
397 for (uint8_t slice = 0; slice < numLut; ++slice) {
399 || rotated[slice + numLut]
400 || rotated[slice + 2 * numLut + numFadc]) {
406 std::vector<uint8_t> lcpVal;
407 std::vector<uint8_t> lcpBcidVec;
408 std::vector<uint8_t> ljeVal;
409 std::vector<uint8_t> ljeSat80Vec;
410 std::vector<int16_t> pedCor;
411 std::vector<uint8_t> pedEn;
413 std::vector<uint16_t> adcVal;
414 std::vector<uint8_t> adcExt;
417 for (uint8_t slice = 0; slice < numLut; ++slice) {
418 lcpVal.push_back(rotated[slice] & 0xff);
419 ljeVal.push_back(rotated[slice + numLut] & 0xff);
420 pedCor.push_back(::pedCorrection(rotated[slice + 2 * numLut + numFadc] & 0x3ff));
422 lcpBcidVec.push_back((rotated[slice] >> 8) & 0x7);
423 ljeSat80Vec.push_back((rotated[slice + numLut] >> 8) & 0x7);
424 pedEn.push_back((rotated[slice + 2 * numLut + numFadc] >> 10) & 0x1);
428 for (uint8_t slice = 0; slice < numFadc; ++slice) {
429 if (rotated[slice + numLut]) {
436 for (uint8_t slice = 0; slice < numFadc; ++ slice) {
437 adcVal.push_back(rotated[slice + 2 * numLut] & 0x3ff);
438 adcExt.push_back((rotated[slice + 2 * numLut] >> 10 & 0x1) & 0x3ff);
458 return StatusCode::SUCCESS;
468 present = br.getField (1);
478 std::vector<uint16_t> adcVal = {0 , 0, 0, 0, 0};
479 std::vector<uint8_t> adcExt = {0 , 0, 0, 0, 0};
481 uint8_t minHeader = br.getField (4);
482 uint8_t minIndex = minHeader % 5;
483 if (minHeader < 15) {
484 if (minHeader < 10) {
487 fmt = 2 + br.getField (2);
488 uint8_t haveLut = br.getField (1);
491 lutVal = br.getField (3);
495 uint8_t haveExt = br.getField (1);
497 lutVal = br.getField (8);
498 lutExt = br.getField (1);
499 lutSat = br.getField (1);
500 lutPeak = br.getField (1);
504 for(uint8_t i = 0; i < 5; ++i) {
505 adcExt[i] = br.getField (1);
514 uint8_t haveAdc = br.getField (1);
516 uint16_t val = br.getField (10);
517 for(uint8_t i = 0; i < 5; ++i) {
529 std::vector<uint8_t> {lutVal},
530 std::vector<uint8_t> {uint8_t(lutExt | (lutSat << 1) | (lutPeak << 2))},
537 }
catch (
const std::out_of_range& ex) {
541 return StatusCode::SUCCESS;
546 BitReader& br, uint8_t format, uint8_t minIndex)
const {
548 std::vector<uint16_t> adc = {0, 0, 0, 0, 0};
551 for(uint8_t i = 0; i <5; ++i) {
552 uint8_t longField = 0;
555 longField = br.getField (1);
556 numBits = longField == 0? 4: (format * 2);
558 numBits = i == 0? 4: (format + 2);
562 minAdc = br.getField (numBits);
563 if (longField == 0) {
567 adc[i] = minAdc + br.getField (numBits);
574 adc[0] = adc[minIndex];
575 adc[minIndex] = minAdc;
592 const uint8_t nTotal = numAdc + numLut;
593 const uint8_t wordsPerBlock = 8;
594 const uint8_t iBlk = inData / wordsPerBlock;
598 for(uint8_t i = 0; i < 2; ++i) {
599 uint16_t subword = (word >> 16 * i) & 0x7ff;
600 state.
m_ppLuts[iChan].push_back(subword);
603 }
else if (iBlk < nTotal) {
604 for(uint8_t i = 0; i < 2; ++i) {
605 uint16_t subword = (word >> (16 * i)) & 0x7ff;
606 state.
m_ppFadcs[iChan].push_back(subword);
612 sc = StatusCode::FAILURE;
622 return StatusCode::SUCCESS;
626 return StatusCode::SUCCESS;
628 return StatusCode::FAILURE;
636 int16_t pedCorBase = -20;
645 for(uint8_t chan = 0; chan < 64; ++chan) {
648 std::vector<uint8_t> haveLut(numLut, 0);
649 std::vector<uint8_t> lcpVal(numLut, 0);
651 std::vector<uint8_t> lcpExt(numLut, 0);
652 std::vector<uint8_t> lcpSat(numLut, 0);
653 std::vector<uint8_t> lcpPeak(numLut, 0);
654 std::vector<uint8_t> lcpBcidVec(numLut, 0);
656 std::vector<uint8_t> ljeVal(numLut, 0);
658 std::vector<uint8_t> ljeLow(numLut, 0);
659 std::vector<uint8_t> ljeHigh(numLut, 0);
660 std::vector<uint8_t> ljeRes(numLut, 0);
661 std::vector<uint8_t> ljeSat80Vec(numLut, 0);
663 std::vector<uint16_t> adcVal(numAdc, 0);
664 std::vector<uint8_t> adcExt(numAdc, 0);
665 std::vector<int16_t> pedCor(numLut, 0);
666 std::vector<uint8_t> pedEn(numLut, 0);
668 int8_t encoding = -1;
669 int8_t minIndex = -1;
672 present = br.getField (1);
676 CHECK((encoding != -1) && (minIndex != -1));
680 for(
uint i=0; i < numLut; ++i) {
681 lcpPeak[i] = br.getField (1);
685 for (uint8_t i = 0; i < numLut; ++i) {
686 ljeLow[i] = br.getField (1);
692 for (uint8_t i = 0; i < numLut; ++i) {
693 if (lcpPeak[i] == 1) {
694 lcpVal[i] = br.getField (4);
697 for(uint8_t i = 0; i < numLut; ++i) {
698 if (lcpPeak[i] == 1){
699 ljeVal[i] = br.getField (3);
703 }
else if (encoding < 6) {
705 for(uint8_t i = 0; i < numLut; ++i){
706 haveLut[i] = br.getField (1);
710 uint8_t haveExt = br.getField (1);
713 for (uint8_t i = 0; i < numAdc; ++i) {
714 adcExt[i] = br.getField (1);
718 for(uint8_t i = 0; i < numLut; ++i){
719 if (haveLut[i] == 1) {
720 lcpVal[i] = br.getField (8);
721 lcpExt[i] = br.getField (1);
722 lcpSat[i] = br.getField (1);
723 lcpPeak[i] = br.getField (1);
727 for(uint8_t i = 0; i < numLut; ++i){
728 if (haveLut[i] == 1) {
729 ljeVal[i] = br.getField (8);
730 ljeLow[i] = br.getField (1);
731 ljeHigh[i] = br.getField (1);
732 ljeRes[i] = br.getField (1);
741 return StatusCode::FAILURE;
746 if ((encoding < 3) || (encoding == 6)) {
747 for (uint8_t i = 0; i < numLut; ++i)
749 pedCor[i] = br.getField (6) + pedCorBase;
758 for (uint8_t i = 0; i < numLut; ++i)
760 uint16_t val = br.getField (10);
761 pedCor[i] = ::pedCorrection(val);
762 pedEn[i] = br.getField (1);
766 for(uint8_t i=0; i < numLut; ++i){
767 lcpBcidVec[i] = uint8_t((lcpPeak[i] << 2) | (lcpSat[i] << 1) | lcpExt[i]);
768 ljeSat80Vec[i] = uint8_t((ljeRes[i] << 2) | (ljeHigh[i] << 1) | ljeLow[i]);
771 chan, lcpVal, lcpBcidVec, ljeVal, ljeSat80Vec, adcVal, adcExt, pedCor,
774 }
catch (
const std::out_of_range& ex) {
778 return StatusCode::SUCCESS;
784 int8_t& encoding, int8_t& minIndex)
const {
785 uint8_t minHeader = 0;
788 minHeader = br.getField (4);
790 minIndex = minHeader % 5;
792 if (minHeader < 10) {
793 encoding = minHeader / 5;
795 encoding = 2 + br.getField (2);
804 }
else if (numAdc == 7) {
806 }
else if (numAdc < 16) {
811 uint8_t fieldSize = 1 << numBits;
812 minHeader = br.getField (numBits);
813 uint8_t encValue = fieldSize - 1;
814 if (minHeader == encValue) {
818 minHeader += br.getField (2) << numBits;
819 minIndex = minHeader % fieldSize;
820 encValue = 3 * fieldSize;
822 if (minHeader < encValue) {
823 encoding = minHeader / fieldSize;
825 encoding = 3 + br.getField (2);
834 BitReader& br, uint8_t encoding, uint8_t minIndex)
const {
838 uint16_t val = br.getField (6);
839 return std::vector<uint16_t>(numAdc, val);
840 }
else if ( encoding < 3) {
841 std::vector<uint16_t> adc(numAdc, 0);
843 adc[minIndex] = minAdc;
844 for(uint8_t i = 1; i < numAdc; ++i) {
845 adc[i == minIndex? 0: i] = br.getField (encoding + 2) + minAdc;
849 std::vector<uint16_t> adc(numAdc, 0);
850 uint16_t minAdc = br.getField (1)
851 ? br.getField (encoding * 2)
855 adc[minIndex] = minAdc;
856 for (uint8_t i = 1; i < numAdc; ++i) {
857 adc[minIndex == i? 0: i] = br.getField (
858 br.getField (1)? encoding * 2: 4
868 return StatusCode::SUCCESS;
871 return StatusCode::FAILURE;
873 return StatusCode::FAILURE;
887 for (uint8_t chan = 0; chan < 64; ++chan) {
889 std::vector<uint8_t> lcpVal;
890 std::vector<uint8_t> lcpBcidVec;
892 std::vector<uint8_t> ljeVal;
893 std::vector<uint8_t> ljeSat80Vec;
897 std::vector<uint16_t> adcVal;
898 std::vector<uint8_t> adcExt;
899 std::vector<int16_t> pedCor;
900 std::vector<uint8_t> pedEn;
902 for (
int i = 0; i < numLut; ++i) {
903 lcpVal.push_back(br.getField (8));
904 lcpBcidVec.push_back(br.getField (3));
907 for (
int i = 0; i < numLut; ++i) {
908 ljeVal.push_back(br.getField (8));
909 ljeSat80Vec.push_back(br.getField (3));
912 for (
int i = 0; i < numAdc; ++i) {
913 adcVal.push_back(br.getField (10));
914 adcExt.push_back(br.getField (1));
917 for (
int i = 0; i < numLut; ++i) {
918 uint16_t pc = br.getField (10);
919 pedCor.push_back(pedCorrection(pc));
920 pedEn.push_back(br.getField (1));
922 }
catch (
const std::out_of_range& ex) {
928 ljeVal, ljeSat80Vec, adcVal, adcExt, pedCor, pedEn));
931 return StatusCode::SUCCESS;
935 for(
const auto& lut : state.
m_ppLuts) {
944 return StatusCode::SUCCESS;
952 const std::vector<uint8_t>& lcpVal,
953 const std::vector<uint8_t>& lcpBcidVec,
954 const std::vector<uint8_t>& ljeVal,
955 const std::vector<uint8_t>& ljeSat80Vec,
956 const std::vector<uint16_t>& adcVal,
957 const std::vector<uint8_t>& adcExt,
958 const std::vector<int16_t>& pedCor,
959 const std::vector<uint8_t>& pedEn)
const {
966 bool isNotSpare =
false;
976 const int pin = channel % 16;
977 const int asic = channel / 16;
978 eta = 16 * crate + module;
979 phi = 4 * pin + asic;
982 uint32_t coolId = ::coolId(crate, module, channel);
1007 tt->initialize(coolId,
eta,
phi, lcpVal, ljeVal, pedCor, pedEn,
1010 return StatusCode::SUCCESS;
1018 const std::vector<uint8_t>& luts,
1019 const std::vector<uint8_t>& lcpBcidVec,
1020 const std::vector<uint16_t>& fadc,
1021 const std::vector<uint8_t>& bcidExt
1024 std::vector<uint8_t> ljeSat80Vec;
1026 std::vector<int16_t> pedCor;
1027 std::vector<uint8_t> pedEn;
1030 luts , ljeSat80Vec, fadc, bcidExt, pedCor, pedEn)
1033 return StatusCode::SUCCESS;
1041 const std::vector<uint16_t>& luts,
1042 const std::vector<uint16_t>& fadc
1045 std::vector<uint8_t> lcpVal;
1046 std::vector<uint8_t> lcpBcidVec;
1048 std::vector<uint16_t> adcVal;
1049 std::vector<uint8_t> adcExt;
1051 for(
auto lut: luts) {
1064 return StatusCode::SUCCESS;
1069 const int crates = 8;
1074 for (
int crate = 0; crate < crates; ++crate) {
1075 for (
int slink = 0; slink <
m_srcIdMap->maxSlinks(); ++slink) {
1078 const uint32_t rodId =
m_srcIdMap->getRodID(crate, slink, 0,
1079 eformat::FORWARD_ZDC);
1080 const uint32_t robId =
m_srcIdMap->getRobID(rodId);
1083 if (crate > 1 && crate < 6) {
1085 if (crate < 4 && slink == 0) {
1096 const std::string& sgKey)
const
1098 if (sgKey.find(
"Muon") != std::string::npos) {
1101 else if (sgKey.find(
"Spare") != std::string::npos) {
1111 (
const uint8_t numBits)
1119 if ((iBit + numBits) <= 31) {
1122 uint8_t nb1 = 31 - iBit;
1123 uint8_t nb2 = numBits - nb1;
1124 uint32_t field1 = ::bitFieldSize(
m_ppBlock[iWord], iBit, nb1);
1125 uint32_t field2 = ::bitFieldSize(
m_ppBlock[iWord + 1], 0, nb2);
1126 result = field1 | (field2 << nb1);
1132 throw std::out_of_range(
"Requested too much bits from ppm block");
1137 typedef std::map<uint32_t,ZdcDigits*> hashmapType;
1138 hashmapType digits_map;
1143 uint32_t coolId = tt->coolId();
1144 uint32_t pin = (coolId>>8) & 0xf;
1145 uint32_t asic = coolId & 0xf;
1146 uint32_t slinkChannel = asic*16 + pin;
1149 uint32_t module = (coolId>>16) & 0xf;
1158 ATH_MSG_DEBUG(
"Trying to find chan_hash " << chan_hash <<
" g" << gain <<
"d" <<
delay);
1160 hashmapType::iterator iter = digits_map.find(chan_hash);
1161 if (iter == digits_map.end())
1164 digits_map.insert(std::pair<uint32_t,ZdcDigits*>(chan_hash,
new ZdcDigits(chan_id)));
1165 iter = digits_map.find(chan_hash);
1167 if (iter != digits_map.end())
1170 if (gain==0&&
delay==0) (*iter).second->set_digits_gain0_delay0( tt->adc() );
1171 if (gain==1&&
delay==0) (*iter).second->set_digits_gain1_delay0( tt->adc() );
1172 if (gain==0&&
delay==1) (*iter).second->set_digits_gain0_delay1( tt->adc() );
1173 if (gain==1&&
delay==1) (*iter).second->set_digits_gain1_delay1( tt->adc() );
1180 hashmapType::iterator iter = digits_map.begin();
1181 hashmapType::iterator iter_end = digits_map.end();
1183 while (iter != iter_end)
1195 zdcCollection->
push_back((*iter).second);
1199 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.