Skip to content

Commit

Permalink
MRRTF-154: MCH raw data decoder now catches exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
aphecetche authored and davidrohr committed Apr 27, 2022
1 parent 63d806e commit 8cfc790
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ class DataDecoder
/// Must be called before processing the TmeFrame buffer
void setFirstOrbitInTF(uint32_t orbit);

/// Decode one TimeFrame buffer and fill the vector of digits
void decodeBuffer(gsl::span<const std::byte> buf);
/** Decode one TimeFrame buffer and fill the vector of digits.
* @return true if decoding went ok, or false otherwise.
* if false is returned, the decoding of the (rest of the) TF should be
* abandonned simply.
*/
bool decodeBuffer(gsl::span<const std::byte> buf);

/// Functions to set and get the calibration offset for the SAMPA time computation
void setSampaBcOffset(uint32_t offset) { mSampaTimeOffset = offset; }
Expand Down
28 changes: 14 additions & 14 deletions Detectors/MUON/MCH/Raw/Decoder/include/MCHRawDecoder/ErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ namespace raw
{

enum ErrorCodes {
ErrorParity = 1, // 1
ErrorHammingCorrectable = 1 << 1, // 2
ErrorHammingUncorrectable = 1 << 2, // 4
ErrorBadClusterSize = 1 << 3, // 8
ErrorBadPacketType = 1 << 4, // 16
ErrorBadHeartBeatPacket = 1 << 5, // 32
ErrorBadIncompleteWord = 1 << 6, // 64
ErrorTruncatedData = 1 << 7, // 128
ErrorBadELinkID = 1 << 8, // 256
ErrorBadLinkID = 1 << 9, // 512
ErrorUnknownLinkID = 1 << 10, // 1024
ErrorBadDigitTime = 1 << 11, // 2048
ErrorInvalidDigitTime = 1 << 12 // 4096

ErrorParity = 1, // 1
ErrorHammingCorrectable = 1 << 1, // 2
ErrorHammingUncorrectable = 1 << 2, // 4
ErrorBadClusterSize = 1 << 3, // 8
ErrorBadPacketType = 1 << 4, // 16
ErrorBadHeartBeatPacket = 1 << 5, // 32
ErrorBadIncompleteWord = 1 << 6, // 64
ErrorTruncatedData = 1 << 7, // 128
ErrorBadELinkID = 1 << 8, // 256
ErrorBadLinkID = 1 << 9, // 512
ErrorUnknownLinkID = 1 << 10, // 1024
ErrorBadDigitTime = 1 << 11, // 2048
ErrorInvalidDigitTime = 1 << 12, // 4096
ErrorNonRecoverableDecodingError = 1 << 13 // 8192
};

uint32_t getErrorCodesSize();
Expand Down
11 changes: 9 additions & 2 deletions Detectors/MUON/MCH/Raw/Decoder/src/DataDecoder.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "CommonConstants/LHCConstants.h"
#include "DetectorsRaw/RDHUtils.h"
#include "DetectorsRaw/HBFUtils.h"
#include "MCHBase/DecoderError.h"
#include "MCHMappingInterface/Segmentation.h"
#include "Framework/Logger.h"
#include "MCHRawDecoder/ErrorCodes.h"
Expand Down Expand Up @@ -264,7 +265,7 @@ void DataDecoder::setFirstOrbitInTF(uint32_t orbit)

//_________________________________________________________________________________________________

void DataDecoder::decodeBuffer(gsl::span<const std::byte> buf)
bool DataDecoder::decodeBuffer(gsl::span<const std::byte> buf)
{
if (mDebug) {
std::cout << "\n\n============================\nStart of new buffer\n";
Expand All @@ -289,7 +290,12 @@ void DataDecoder::decodeBuffer(gsl::span<const std::byte> buf)
auto pageSize = o2::raw::RDHUtils::getOffsetToNext(rdh);

gsl::span<const std::byte> page(reinterpret_cast<const std::byte*>(rdh), pageSize);
decodePage(page);
try {
decodePage(page);
} catch (const std::exception& e) {
mErrors.emplace_back(DecoderError(0, 0, 0, ErrorNonRecoverableDecodingError));
return false;
}

pageStart += pageSize;
}
Expand All @@ -300,6 +306,7 @@ void DataDecoder::decodeBuffer(gsl::span<const std::byte> buf)
std::cout << "[decodeBuffer] mDigits size: " << mDigits.size() << std::endl;
dumpDigits();
}
return true;
}

//_________________________________________________________________________________________________
Expand Down
5 changes: 4 additions & 1 deletion Detectors/MUON/MCH/Raw/Decoder/src/ErrorCodes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace raw

uint32_t getErrorCodesSize()
{
return 13;
return 14;
}

void append(const char* msg, std::string& to)
Expand Down Expand Up @@ -76,6 +76,9 @@ std::string errorCodeAsString(uint32_t ec)
if (ec & ErrorInvalidDigitTime) {
append("Invalid Digit Time", msg);
}
if (ec & ErrorNonRecoverableDecodingError) {
append("Non Recoverable", msg);
}
return msg;
}

Expand Down
9 changes: 7 additions & 2 deletions Detectors/MUON/MCH/Workflow/src/DataDecoderSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,20 @@ class DataDecoderTask
// get the input buffer
auto& inputs = pc.inputs();
DPLRawParser parser(inputs, o2::framework::select(mInputSpec.c_str()));
for (auto it = parser.begin(), end = parser.end(); it != end; ++it) {
bool abort{false};
for (auto it = parser.begin(), end = parser.end(); it != end && abort == false; ++it) {
auto const* raw = it.raw();
if (!raw) {
continue;
}
size_t payloadSize = it.size();

gsl::span<const std::byte> buffer(reinterpret_cast<const std::byte*>(raw), sizeof(RDH) + payloadSize);
mDecoder->decodeBuffer(buffer);
bool ok = mDecoder->decodeBuffer(buffer);
if (!ok) {
LOG(alarm) << "critical decoding error : aborting this TF decoding\n";
abort = true;
}
}
}

Expand Down

0 comments on commit 8cfc790

Please sign in to comment.