@@ -887,6 +887,7 @@ void zsEncoderDenseLinkBased::decodePage(std::vector<o2::tpc::Digit>& outputBuff
887887 std::vector<unsigned char > tmpBuffer;
888888 bool extendFailure = false ;
889889 unsigned int nOutput = 0 ;
890+ unsigned int minTimeBin = -1 , maxTimeBin = 0 ;
890891 for (unsigned int i = 0 ; i < decHDR->nTimebinHeaders ; i++) {
891892 int sizeLeftInPage = payloadEnd - decPagePtr;
892893 if (sizeLeftInPage <= 0 ) {
@@ -952,10 +953,16 @@ void zsEncoderDenseLinkBased::decodePage(std::vector<o2::tpc::Digit>& outputBuff
952953 int encodeBitsBlock = v2Flag ? v2nbits : encodeBits;
953954 decPagePtr += (nTotalSamples * encodeBitsBlock + 7 ) / 8 ;
954955
955- if (linkBC < triggerBC) {
956+ if (linkBC < triggerBC || nTotalSamples == 0 ) {
956957 continue ;
957958 }
958959 int timeBin = (linkBC - triggerBC + (unsigned long )(o2::raw::RDHUtils::getHeartBeatOrbit (*rdh) - firstOrbit) * o2::constants::lhc::LHCMaxBunches) / LHCBCPERTIMEBIN;
960+ if (timeBin > maxTimeBin) {
961+ maxTimeBin = timeBin;
962+ }
963+ if (timeBin < minTimeBin) {
964+ minTimeBin = timeBin;
965+ }
959966
960967 std::vector<unsigned short > samples (nTotalSamples);
961968 unsigned int mask = (1 << encodeBitsBlock) - 1 ;
@@ -988,13 +995,24 @@ void zsEncoderDenseLinkBased::decodePage(std::vector<o2::tpc::Digit>& outputBuff
988995 }
989996 }
990997 }
998+
999+ unsigned int hdrMinTimeBin = (decHDR->timeOffset + (o2::raw::RDHUtils::getHeartBeatOrbit (*rdh) - firstOrbit) * o2::constants::lhc::LHCMaxBunches) / LHCBCPERTIMEBIN;
1000+ unsigned int hdrMaxTimeBin = hdrMinTimeBin + decHDR->nTimeBinSpan ;
1001+
9911002 if (!extendFailure && nOutput != decHDR->nADCsamples ) {
9921003 std::ostringstream oss;
9931004 oss << " Number of decoded digits " << nOutput << " does not match value from MetaInfo " << decHDR->nADCsamples ;
9941005 amendPageErrorMessage (oss, rdh, decHDR, nullptr , nullptr , nOutput);
9951006 throw std::runtime_error (oss.str ());
9961007 }
9971008
1009+ if (decHDR->nADCsamples && (minTimeBin < hdrMinTimeBin || maxTimeBin > hdrMaxTimeBin)) {
1010+ std::ostringstream oss;
1011+ oss << " Incorrect time bin range in header, says " << hdrMinTimeBin << " - " << hdrMaxTimeBin << " , data is " << minTimeBin << " - " << maxTimeBin;
1012+ amendPageErrorMessage (oss, rdh, decHDR, payloadEnd, decPagePtr, nOutput);
1013+ throw std::runtime_error (oss.str ());
1014+ }
1015+
9981016 if (decHDR->nTimebinHeaders && payloadEnd - decPagePtr < 0 ) {
9991017 std::ostringstream oss;
10001018 oss << " Decoding ran over end of page" ;
0 commit comments