Skip to content

Commit e4e6659

Browse files
committed
DPL: Add optional incomplete HBF check to DPL RawParser
1 parent 536132a commit e4e6659

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

Framework/Utils/include/DPLUtils/RawParser.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ struct RDHFormatter<header::RAWDataHeaderV4> {
8080
};
8181

8282
struct RawParserParam {
83-
static int sErrorMode; // 0: no error checking, 1: print error message, 2: throw exception. To be set via O2_DPL_RAWPARSER_ERRORMODE.
84-
static unsigned int sErrors; // Obviously this would need to be atomic to be fully correct, but a race condition is unlikely and would only lead to one extra log message printed.
83+
static int sErrorMode; // 0: no error checking, 1: print error message, 2: throw exception. To be set via O2_DPL_RAWPARSER_ERRORMODE.
84+
static int sCheckIncompleteHBF; // Check if HBFs are incomplete, set to 2 to throw in case sErrorMode = 2.
85+
static unsigned int sErrors; // Obviously this would need to be atomic to be fully correct, but a race condition is unlikely and would only lead to one extra log message printed.
8586
};
8687

8788
/// @class ConcreteRawParser
@@ -231,6 +232,7 @@ class ConcreteRawParser
231232
/// Move to next page start
232233
bool next()
233234
{
235+
int lastPacketCounter = -1;
234236
if (mPosition == nullptr) {
235237
mPosition = mRawBuffer;
236238
if (mSize == 0) {
@@ -242,6 +244,9 @@ class ConcreteRawParser
242244
mPosition = mRawBuffer + mSize;
243245
return false;
244246
}
247+
if (RawParserParam::sCheckIncompleteHBF) {
248+
lastPacketCounter = header().packetCounter;
249+
}
245250
mPosition += offset;
246251
}
247252
if constexpr (BOUNDS_CHECKS) {
@@ -252,9 +257,32 @@ class ConcreteRawParser
252257
if (RawParserParam::sErrors++ < 20) {
253258
LOG(error) << "Corrupt RDH - RDH parsing ran out of raw data buffer";
254259
}
260+
mPosition = mRawBuffer + mSize;
261+
return false;
262+
}
263+
}
264+
if (RawParserParam::sErrorMode) {
265+
if (header().version != HeaderType().version) {
266+
if (RawParserParam::sErrorMode >= 2) {
267+
throw std::runtime_error("Corrupt RDH - Invalid RDH version");
268+
}
269+
if (RawParserParam::sErrors++ < 20) {
270+
LOG(error) << "Corrupt RDH - Invalid RDH Version " << header().version << " (expected " << HeaderType().version << ")";
271+
}
272+
mPosition = mRawBuffer + mSize;
273+
return false;
274+
}
275+
if (lastPacketCounter != -1 && (unsigned char)(lastPacketCounter + 1) != header().packetCounter) {
276+
if (RawParserParam::sErrorMode >= 2 && RawParserParam::sCheckIncompleteHBF >= 2) {
277+
throw std::runtime_error("Incomplete HBF - jump in packet counter");
278+
}
279+
if (RawParserParam::sErrors++ < 20) {
280+
LOG(error) << "Incomplete HBF - jump in packet counter " << lastPacketCounter << " to " << header().packetCounter;
281+
}
282+
mPosition = mRawBuffer + mSize;
283+
return false;
255284
}
256285
}
257-
// FIXME: check page header validity: version
258286
return true;
259287
}
260288

Framework/Utils/src/RawParser.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace o2::framework::raw_parser
2222
{
2323

2424
int RawParserParam::sErrorMode = getenv("O2_DPL_RAWPARSER_ERRORMODE") ? atoi(getenv("O2_DPL_RAWPARSER_ERRORMODE")) : 1;
25+
int RawParserParam::sCheckIncompleteHBF = getenv("O2_DPL_RAWPARSER_CHECKINCOMPLETEHBF") ? atoi(getenv("O2_DPL_RAWPARSER_CHECKINCOMPLETEHBF")) : 1;
2526
unsigned int RawParserParam::sErrors = 0;
2627

2728
const char* RDHFormatter<V7>::sFormatString = "{:>5} {:>4} {:>4} {:>4} {:>4} {:>3} {:>3} {:>3} {:>1} {:>2}";

0 commit comments

Comments
 (0)