diff --git a/dam/source/cc/src/TpcTrimmedRange.hh b/dam/source/cc/src/TpcTrimmedRange.hh index 462f3f6..2cae2f7 100644 --- a/dam/source/cc/src/TpcTrimmedRange.hh +++ b/dam/source/cc/src/TpcTrimmedRange.hh @@ -50,6 +50,8 @@ #include "TpcStream-Impl.hh" #include "TpcCompressed-Impl.hh" +#include +#include namespace pdd { namespace access { @@ -299,6 +301,7 @@ inline uint32_t TpcTrimmedRange::Location:: int nTotFrames, bool begin) { + std::string myname = "TpcTrimmedRange::Location::locate: "; auto pktNum = pdd::access::TpcRangesIndices::getPacket (pktIdx); auto pktOff = pdd::access::TpcRangesIndices::getOffset (pktIdx); int wfOff = nframesPerPkt * pktNum + pktOff; @@ -311,20 +314,22 @@ inline uint32_t TpcTrimmedRange::Location:: // the calculation, which depends on the data not // having certain pathologies, on the RCE fails. // ------------------------------------------------ - if (wfOff > nTotFrames) + if (wfOff >= nTotFrames) { // ------------ // Try guessing // ------------ - wfOff = (timestamp - firstTimestamp) / 25; + // + int wfOffNew = (timestamp - firstTimestamp) / 25; // --------------------------------------------- // Hopeless if this occurs before the timestamp // of the first WIB frame in the untrimmed data. // This likely indicates a complete corruption. // --------------------------------------------- - if (wfOff < 0) - { + if ( wfOffNew < 0 || wfOffNew >= nTotFrames ) { + std::cout << myname << "WARNING: Skipping invalid frame index: " << wfOff << " --> " + << wfOffNew << " >= " << nTotFrames << std::endl; m_wibOff = 0; m_pktNum = 0; m_pktOff = 0; @@ -332,6 +337,10 @@ inline uint32_t TpcTrimmedRange::Location:: return -1; } + std::cout << myname << "WARNING: Guess fixed invalid frame index: " << wfOff << " --> " + << wfOffNew << " / " << nTotFrames << std::endl; + wfOff = wfOffNew; + pktNum = wfOff / nframesPerPkt; pktOff = wfOff % nframesPerPkt; } @@ -359,7 +368,6 @@ inline uint32_t TpcTrimmedRange::Location:: return 0; } - // ---------------------------------------- // Get the timestamp at the predicted point // ----------------------------------------