Skip to content

Commit 8cfc790

Browse files
aphecetchedavidrohr
authored andcommitted
MRRTF-154: MCH raw data decoder now catches exceptions
1 parent 63d806e commit 8cfc790

5 files changed

Lines changed: 40 additions & 21 deletions

File tree

Detectors/MUON/MCH/Raw/Decoder/include/MCHRawDecoder/DataDecoder.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,12 @@ class DataDecoder
158158
/// Must be called before processing the TmeFrame buffer
159159
void setFirstOrbitInTF(uint32_t orbit);
160160

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

164168
/// Functions to set and get the calibration offset for the SAMPA time computation
165169
void setSampaBcOffset(uint32_t offset) { mSampaTimeOffset = offset; }

Detectors/MUON/MCH/Raw/Decoder/include/MCHRawDecoder/ErrorCodes.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ namespace raw
2222
{
2323

2424
enum ErrorCodes {
25-
ErrorParity = 1, // 1
26-
ErrorHammingCorrectable = 1 << 1, // 2
27-
ErrorHammingUncorrectable = 1 << 2, // 4
28-
ErrorBadClusterSize = 1 << 3, // 8
29-
ErrorBadPacketType = 1 << 4, // 16
30-
ErrorBadHeartBeatPacket = 1 << 5, // 32
31-
ErrorBadIncompleteWord = 1 << 6, // 64
32-
ErrorTruncatedData = 1 << 7, // 128
33-
ErrorBadELinkID = 1 << 8, // 256
34-
ErrorBadLinkID = 1 << 9, // 512
35-
ErrorUnknownLinkID = 1 << 10, // 1024
36-
ErrorBadDigitTime = 1 << 11, // 2048
37-
ErrorInvalidDigitTime = 1 << 12 // 4096
38-
25+
ErrorParity = 1, // 1
26+
ErrorHammingCorrectable = 1 << 1, // 2
27+
ErrorHammingUncorrectable = 1 << 2, // 4
28+
ErrorBadClusterSize = 1 << 3, // 8
29+
ErrorBadPacketType = 1 << 4, // 16
30+
ErrorBadHeartBeatPacket = 1 << 5, // 32
31+
ErrorBadIncompleteWord = 1 << 6, // 64
32+
ErrorTruncatedData = 1 << 7, // 128
33+
ErrorBadELinkID = 1 << 8, // 256
34+
ErrorBadLinkID = 1 << 9, // 512
35+
ErrorUnknownLinkID = 1 << 10, // 1024
36+
ErrorBadDigitTime = 1 << 11, // 2048
37+
ErrorInvalidDigitTime = 1 << 12, // 4096
38+
ErrorNonRecoverableDecodingError = 1 << 13 // 8192
3939
};
4040

4141
uint32_t getErrorCodesSize();

Detectors/MUON/MCH/Raw/Decoder/src/DataDecoder.cxx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "CommonConstants/LHCConstants.h"
2525
#include "DetectorsRaw/RDHUtils.h"
2626
#include "DetectorsRaw/HBFUtils.h"
27+
#include "MCHBase/DecoderError.h"
2728
#include "MCHMappingInterface/Segmentation.h"
2829
#include "Framework/Logger.h"
2930
#include "MCHRawDecoder/ErrorCodes.h"
@@ -264,7 +265,7 @@ void DataDecoder::setFirstOrbitInTF(uint32_t orbit)
264265

265266
//_________________________________________________________________________________________________
266267

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

291292
gsl::span<const std::byte> page(reinterpret_cast<const std::byte*>(rdh), pageSize);
292-
decodePage(page);
293+
try {
294+
decodePage(page);
295+
} catch (const std::exception& e) {
296+
mErrors.emplace_back(DecoderError(0, 0, 0, ErrorNonRecoverableDecodingError));
297+
return false;
298+
}
293299

294300
pageStart += pageSize;
295301
}
@@ -300,6 +306,7 @@ void DataDecoder::decodeBuffer(gsl::span<const std::byte> buf)
300306
std::cout << "[decodeBuffer] mDigits size: " << mDigits.size() << std::endl;
301307
dumpDigits();
302308
}
309+
return true;
303310
}
304311

305312
//_________________________________________________________________________________________________

Detectors/MUON/MCH/Raw/Decoder/src/ErrorCodes.cxx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace raw
2020

2121
uint32_t getErrorCodesSize()
2222
{
23-
return 13;
23+
return 14;
2424
}
2525

2626
void append(const char* msg, std::string& to)
@@ -76,6 +76,9 @@ std::string errorCodeAsString(uint32_t ec)
7676
if (ec & ErrorInvalidDigitTime) {
7777
append("Invalid Digit Time", msg);
7878
}
79+
if (ec & ErrorNonRecoverableDecodingError) {
80+
append("Non Recoverable", msg);
81+
}
7982
return msg;
8083
}
8184

Detectors/MUON/MCH/Workflow/src/DataDecoderSpec.cxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,20 @@ class DataDecoderTask
122122
// get the input buffer
123123
auto& inputs = pc.inputs();
124124
DPLRawParser parser(inputs, o2::framework::select(mInputSpec.c_str()));
125-
for (auto it = parser.begin(), end = parser.end(); it != end; ++it) {
125+
bool abort{false};
126+
for (auto it = parser.begin(), end = parser.end(); it != end && abort == false; ++it) {
126127
auto const* raw = it.raw();
127128
if (!raw) {
128129
continue;
129130
}
130131
size_t payloadSize = it.size();
131132

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

0 commit comments

Comments
 (0)