13 #include "eformat/SourceIdentifier.h"
23 #include "../L1CaloSubBlock.h"
24 #include "../L1CaloSrcIdMap.h"
37 return (crate << 8) | (1 << 4) |
module;
43 return (crateModuleMask(crate,
module) << 16) | (pin << 8) | asic;
47 return twoBytePedCor > 511? (twoBytePedCor - 1024): twoBytePedCor;
51 std::string noAuxSuffix(
const std::string&
name) {
52 if ((
name.size() > 4) && (
name.substr(
name.size()-4, 4) ==
"Aux.")) {
53 return name.substr(0,
name.size() - 4);
66 m_errorTool(
"LVL1BS::L1CaloErrorByteStreamTool/L1CaloErrorByteStreamTool"),
67 m_ppmMaps(
"LVL1::PpmMappingTool/PpmMappingTool"),
68 m_robDataProvider(
"ROBDataProviderSvc",
name),
72 declareInterface<PpmByteStreamReadV1V2Tool>(
this);
75 "Crate/Module/Channel to Eta/Phi/Layer mapping tool");
77 "Get ROB source IDs service");
95 return StatusCode::SUCCESS;
103 return StatusCode::SUCCESS;
121 for (; rob != robEnd; ++rob, ++robCounter) {
124 if (!
sc.isSuccess()) {
130 return StatusCode::SUCCESS;
145 const std::vector<uint32_t>& vID(
ppmSourceIDs(state, sgKey));
148 m_robDataProvider->getROBData(Gaudi::Hive::currentContext(), vID, robFrags,
"PpmByteStreamxAODReadTool");
149 ATH_MSG_DEBUG(
"Number of ROB fragments:" << robFrags.size());
152 return StatusCode::SUCCESS;
160 auto rob = **robIter;
163 "Treating ROB fragment source id #" << MSG::hex << rob.rob_source_id());
173 if (rob.nstatus() > 0) {
179 return StatusCode::FAILURE;
187 rob.rod_data(payloadBeg);
188 payloadEnd = payloadBeg + rob.rod_ndata();
193 return StatusCode::FAILURE;
198 uint16_t rodVer = rob.rod_version() & 0xffff;
199 uint32_t rodRunNumber = rob.rod_run_no() & 0xffffff;
200 state.
m_verCode = ((rodVer & 0xfff) << 4) | 1;
205 return StatusCode::FAILURE;
208 ATH_MSG_DEBUG(
"Treating crate " << rodCrate <<
" slink " << rodSlink);
212 return StatusCode::FAILURE;
216 "Run number: " << MSG::dec << rodRunNumber <<
endmsg
217 <<
"Version code: 0x" << MSG::hex <<
int(state.
m_verCode) << MSG::dec
218 <<
endmsg <<
"LUT triggered slice offset: "
221 <<
endmsg <<
"FADC baseline lower bound: "
251 }
else if (
blockType == (subBlock | 1)) {
257 case eformat::TDAQ_CALO_PREPROC:
270 return StatusCode::SUCCESS;
287 return StatusCode::FAILURE;
289 return StatusCode::SUCCESS;
323 <<
"' for rob version '"
325 << MSG::dec <<
"'" );
326 return StatusCode::FAILURE;
328 return StatusCode::SUCCESS;
335 uint8_t totSlice = 3 * numLut + numFadc;
338 for (
int asic = 0 ; asic < 4 ; ++asic ) {
339 for (
int mcm = 0 ; mcm < 16 ; ++mcm ) {
341 std::vector<uint32_t> rotated(totSlice);
344 for (
uint8_t bit = 0 ; bit < 11 ; ++bit ) {
345 if ( state.
m_ppBlock[
slice * 11 + asic * (11 * totSlice) + bit + 1] & (1 << mcm))
346 rotated[
slice] |= (1 << bit);
350 bool nonZeroData =
false;
353 || rotated[
slice + numLut]
354 || rotated[
slice + 2 * numLut + numFadc]) {
360 std::vector<uint8_t> lcpVal;
361 std::vector<uint8_t> lcpBcidVec;
362 std::vector<uint8_t> ljeVal;
363 std::vector<uint8_t> ljeSat80Vec;
364 std::vector<int16_t> pedCor;
365 std::vector<uint8_t> pedEn;
367 std::vector<uint16_t> adcVal;
368 std::vector<uint8_t> adcExt;
372 lcpVal.push_back(rotated[
slice] & 0xff);
373 ljeVal.push_back(rotated[
slice + numLut] & 0xff);
374 pedCor.push_back(::pedCorrection(rotated[
slice + 2 * numLut + numFadc] & 0x3ff));
376 lcpBcidVec.push_back((rotated[
slice] >> 8) & 0x7);
377 ljeSat80Vec.push_back((rotated[
slice + numLut] >> 8) & 0x7);
378 pedEn.push_back((rotated[
slice + 2 * numLut + numFadc] >> 10) & 0x1);
383 if (rotated[
slice + numLut]) {
391 adcVal.push_back(rotated[
slice + 2 * numLut] & 0x3ff);
392 adcExt.push_back((rotated[
slice + 2 * numLut] >> 10 & 0
x1) & 0x3ff);
402 std::move(lcpBcidVec),
404 std::move(ljeSat80Vec),
413 return StatusCode::SUCCESS;
424 present =
br.getField(1);
434 std::vector<uint16_t> adcVal = {0 , 0, 0, 0, 0};
435 std::vector<uint8_t> adcExt = {0 , 0, 0, 0, 0};
438 uint8_t minIndex = minHeader % 5;
439 if (minHeader < 15) {
440 if (minHeader < 10) {
443 fmt = 2 +
br.getField( 2);
447 lutVal =
br.getField(3);
453 lutVal =
br.getField(8);
454 lutExt =
br.getField(1);
455 lutSat =
br.getField(1);
456 lutPeak =
br.getField(1);
461 adcExt[
i] =
br.getField(1);
485 std::vector<uint8_t> {lutVal},
486 std::vector<uint8_t> {uint8_t(lutExt | (lutSat << 1) | (lutPeak << 2))},
493 }
catch (
const std::out_of_range& ex) {
497 return StatusCode::SUCCESS;
504 std::vector<uint16_t>
adc = {0, 0, 0, 0, 0};
511 longField =
br.getField(1);
512 numBits = longField == 0? 4: (
format * 2);
514 numBits =
i == 0? 4: (
format + 2);
518 minAdc =
br.getField(numBits);
519 if (longField == 0) {
523 adc[
i] = minAdc +
br.getField(numBits);
531 adc[minIndex] = minAdc;
550 const uint8_t nTotal = numAdc + numLut;
551 const uint8_t wordsPerBlock = 8;
552 const uint8_t iBlk = inData / wordsPerBlock;
557 uint16_t subword = (word >> 16 *
i) & 0x7ff;
558 state.
m_ppLuts[iChan].push_back(subword);
561 }
else if (iBlk < nTotal) {
563 uint16_t subword = (word >> (16 *
i)) & 0x7ff;
564 state.
m_ppFadcs[iChan].push_back(subword);
570 sc = StatusCode::FAILURE;
581 return StatusCode::SUCCESS;
584 return StatusCode::SUCCESS;
586 return StatusCode::FAILURE;
601 std::vector<uint8_t> haveLut(numLut, 0);
602 std::vector<uint8_t> lcpVal(numLut, 0);
604 std::vector<uint8_t> lcpExt(numLut, 0);
605 std::vector<uint8_t> lcpSat(numLut, 0);
606 std::vector<uint8_t> lcpPeak(numLut, 0);
607 std::vector<uint8_t> lcpBcidVec(numLut, 0);
609 std::vector<uint8_t> ljeVal(numLut, 0);
611 std::vector<uint8_t> ljeLow(numLut, 0);
612 std::vector<uint8_t> ljeHigh(numLut, 0);
613 std::vector<uint8_t> ljeRes(numLut, 0);
614 std::vector<uint8_t> ljeSat80Vec(numLut, 0);
616 std::vector<uint16_t> adcVal(numAdc, 0);
617 std::vector<uint8_t> adcExt(numAdc, 0);
618 std::vector<int16_t> pedCor(numLut, 0);
619 std::vector<uint8_t> pedEn(numLut, 0);
622 int8_t minIndex = -1;
625 present =
br.getField(1);
633 for(
uint i=0;
i < numLut; ++
i) {
634 lcpPeak[
i] =
br.getField(1);
639 ljeLow[
i] =
br.getField(1);
646 if (lcpPeak[
i] == 1) {
647 lcpVal[
i] =
br.getField(4);
651 if (lcpPeak[
i] == 1){
652 ljeVal[
i] =
br.getField(3);
659 haveLut[
i] =
br.getField(1);
667 adcExt[
i] =
br.getField(1);
672 if (haveLut[
i] == 1) {
673 lcpVal[
i] =
br.getField(8);
674 lcpExt[
i] =
br.getField(1);
675 lcpSat[
i] =
br.getField(1);
676 lcpPeak[
i] =
br.getField(1);
681 if (haveLut[
i] == 1) {
682 ljeVal[
i] =
br.getField(8);
683 ljeLow[
i] =
br.getField(1);
684 ljeHigh[
i] =
br.getField(1);
685 ljeRes[
i] =
br.getField(1);
698 pedCor[
i] =
br.getField(6) + pedCorBase;
710 pedCor[
i] = ::pedCorrection(
val);
711 pedEn[
i] =
br.getField(1);
716 lcpBcidVec[
i] =
uint8_t((lcpPeak[
i] << 2) | (lcpSat[
i] << 1) | lcpExt[
i]);
717 ljeSat80Vec[
i] =
uint8_t((ljeRes[
i] << 2) | (ljeHigh[
i] << 1) | ljeLow[
i]);
722 std::move(lcpVal), std::move(lcpBcidVec),
723 std::move(ljeVal), std::move(ljeSat80Vec),
724 std::move(adcVal), std::move(adcExt),
725 std::move(pedCor), std::move(pedEn)));
727 }
catch (
const std::out_of_range& ex) {
732 return StatusCode::SUCCESS;
738 int8_t&
encoding, int8_t& minIndex)
const
743 minHeader =
br.getField(4);
745 minIndex = minHeader % 5;
747 if (minHeader < 10) {
759 }
else if (numAdc == 7) {
761 }
else if (numAdc < 16) {
766 uint8_t fieldSize = 1 << numBits;
767 minHeader =
br.getField(numBits);
768 uint8_t encValue = fieldSize - 1;
769 if (minHeader == encValue) {
773 minHeader +=
br.getField(2) << numBits;
774 minIndex = minHeader % fieldSize;
775 encValue = 3 * fieldSize;
777 if (minHeader < encValue) {
796 return std::vector<uint16_t>(numAdc,
val);
798 std::vector<uint16_t>
adc(numAdc, 0);
800 adc[minIndex] = minAdc;
806 std::vector<uint16_t>
adc(numAdc, 0);
812 adc[minIndex] = minAdc;
814 adc[minIndex ==
i? 0:
i] =
br.getField(
826 return StatusCode::SUCCESS;
829 return StatusCode::FAILURE;
831 return StatusCode::FAILURE;
845 std::vector<uint8_t> lcpVal;
846 std::vector<uint8_t> lcpBcidVec;
848 std::vector<uint8_t> ljeVal;
849 std::vector<uint8_t> ljeSat80Vec;
853 std::vector<uint16_t> adcVal;
854 std::vector<uint8_t> adcExt;
855 std::vector<int16_t> pedCor;
856 std::vector<uint8_t> pedEn;
858 for (
int i = 0;
i < numLut; ++
i) {
859 lcpVal.push_back(
br.getField(8));
860 lcpBcidVec.push_back(
br.getField(3));
863 for (
int i = 0;
i < numLut; ++
i) {
864 ljeVal.push_back(
br.getField(8));
865 ljeSat80Vec.push_back(
br.getField(3));
868 for (
int i = 0;
i < numAdc; ++
i) {
869 adcVal.push_back(
br.getField(10));
870 adcExt.push_back(
br.getField(1));
873 for (
int i = 0;
i < numLut; ++
i) {
875 pedCor.push_back(pedCorrection(
pc));
876 pedEn.push_back(
br.getField(1));
878 }
catch (
const std::out_of_range& ex) {
885 std::move(lcpVal), std::move(lcpBcidVec),
886 std::move(ljeVal), std::move(ljeSat80Vec),
887 std::move(adcVal), std::move(adcExt),
888 std::move(pedCor), std::move(pedEn)));
891 return StatusCode::SUCCESS;
905 return StatusCode::SUCCESS;
921 if (
tt->coolId() >> 16 & crateModuleMask(crate,
module)){
935 std::vector<uint8_t>&& lcpVal,
936 std::vector<uint8_t>&& lcpBcidVec,
937 std::vector<uint8_t>&& ljeVal,
938 std::vector<uint8_t>&& ljeSat80Vec,
939 std::vector<uint16_t>&& adcVal,
940 std::vector<uint8_t>&& adcExt,
941 std::vector<int16_t>&& pedCor,
942 std::vector<uint8_t>&& pedEn)
const
953 return StatusCode::SUCCESS;
959 eta = 16 * crate +
module;
960 phi = 4 * pin + asic;
966 tt->initialize(coolId, eta, phi,
967 std::move(lcpVal), std::move(ljeVal),
968 std::move(pedCor), std::move(pedEn),
969 std::move(lcpBcidVec), std::move(adcVal),
970 std::move(adcExt), std::move(ljeSat80Vec),
973 return StatusCode::SUCCESS;
981 std::vector<uint8_t>&& luts,
982 std::vector<uint8_t>&& lcpBcidVec,
983 std::vector<uint16_t>&& fadc,
984 std::vector<uint8_t>&& bcidExt
987 std::vector<uint8_t> ljeSat80Vec;
989 std::vector<int16_t> pedCor;
990 std::vector<uint8_t> pedEn;
994 std::move(luts), std::move(lcpBcidVec),
995 std::move(luts) , std::move(ljeSat80Vec),
996 std::move(fadc), std::move(bcidExt),
997 std::move(pedCor), std::move(pedEn))
1000 return StatusCode::SUCCESS;
1008 const std::vector<uint16_t>& luts,
1009 const std::vector<uint16_t>& fadc
1012 std::vector<uint8_t> lcpVal;
1013 std::vector<uint8_t> lcpBcidVec;
1015 std::vector<uint16_t> adcVal;
1016 std::vector<uint8_t> adcExt;
1018 for(
auto lut: luts) {
1019 lcpVal.push_back(BitField::get<uint8_t>(
lut, 0, 8));
1020 lcpBcidVec.push_back(BitField::get<uint8_t>(
lut, 8, 3));
1024 adcExt.push_back(BitField::get<uint8_t>(
f, 0, 1));
1025 adcVal.push_back(BitField::get<uint16_t>(
f, 1, 10));
1030 std::move(lcpVal), std::move(lcpBcidVec),
1031 std::move(adcVal), std::move(adcExt)));
1033 return StatusCode::SUCCESS;
1041 const int crates = 8;
1047 for (
int crate = 0; crate < crates; ++crate) {
1050 eformat::TDAQ_CALO_PREPROC);
1053 if (crate > 1 && crate < 6) {
1055 if (crate < 4 && slink == 0) {
1067 const std::string& sgKey)
const
1072 if (sgKey.find(
"Muon") != std::string::npos) {
1074 }
else if (sgKey.find(
"Spare") != std::string::npos) {
1100 if ((iBit + numBits) <= 31) {
1107 result = field1 | (field2 << nb1);
1113 throw std::out_of_range(
"Requested too much bits from ppm block");