From 7434f9508b6ecdf70af53b62fd3917ad973e009f Mon Sep 17 00:00:00 2001 From: Pascal Raisig <praisig@ikf.uni-frankfurt.de> Date: Thu, 5 Aug 2021 14:48:30 +0200 Subject: [PATCH] Trd1DUnpackAlgo: Add 2 safeties against corrupted data This adds a safeties that protect from unwanted behavior, in case of corrupted EOM messages. --- reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx index cd218e250a..fe61f2ea46 100644 --- a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx +++ b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx @@ -404,7 +404,8 @@ bool CbmTrdUnpackAlgoR::unpack(const fles::Timeslice* ts, std::uint16_t icomp, U word = static_cast<size_t>(mscontent[iword]); frame = (word >> (32 * istream)) & 0xffffffff; - while (getMessageType(frame) == Spadic::MsMessageType::kRDA) { + // The maximum amount of samples (32) equals to 12 RDA messages + while (getMessageType(frame) == Spadic::MsMessageType::kRDA && irda < 12) { // We have to count the number of rda frames for sample reconstruction in eom irda++; @@ -449,10 +450,10 @@ bool CbmTrdUnpackAlgoR::unpack(const fles::Timeslice* ts, std::uint16_t icomp, U // Number of samples indicator = nsamples % 4 std::uint8_t nsamplesindicator = (frame >> 18) & 0x3; // Number of required samples as indicated - auto nreqsamples = (nadcbitstotal + 18) / 9; - std::uint8_t nn = nreqsamples % 4; + std::uint64_t nreqsamples = (nadcbitstotal + 18) / 9; + std::uint8_t nn = nreqsamples % 4; for (std::uint8_t itest = 0; itest < 3; itest++) { - if (nn == nsamplesindicator) break; + if (nn == nsamplesindicator || nreqsamples == 0) break; nreqsamples--; nn = nreqsamples % 4; } @@ -477,8 +478,9 @@ bool CbmTrdUnpackAlgoR::unpack(const fles::Timeslice* ts, std::uint16_t icomp, U ++fNrCorruptEom; } ++fNrCreatedRawMsgs; - // the message is done and the raw message container should contain everything we need. So now we can call makeDigi() - makeDigi(raw); + + // the message is done and the raw message container should contain everything we need. So now we can call makeDigi(). Nevertheless there is a chance for a corrupted message, which ends up with 0 samples so we have to check for it. + if (isample > 0) makeDigi(raw); } else { // We move the word counter backwards by one, such that the unexpected message can correctly be digested -- GitLab