Skip to content

Commit ae8f4f3

Browse files
committed
tfbuilder: fix handling of 1-message readout updates
1 parent d53e9b6 commit ae8f4f3

1 file changed

Lines changed: 51 additions & 49 deletions

File tree

src/StfBuilder/StfBuilderInput.cxx

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -293,63 +293,65 @@ void StfInputInterface::StfBuilderThread(const std::size_t pIdx)
293293
lCurrentStfId = lReadoutHdr.mTimeFrameId;
294294
}
295295

296-
// check subspecifications of all messages
297-
header::DataHeader::SubSpecificationType lSubSpecification = ~header::DataHeader::SubSpecificationType(0);
298-
header::DataOrigin lDataOrigin;
299-
try {
300-
const auto R1 = RDHReader(lReadoutMsgs[1]);
301-
lDataOrigin = ReadoutDataUtils::getDataOrigin(R1);
302-
lSubSpecification = ReadoutDataUtils::getSubSpecification(R1);
303-
} catch (RDHReaderException &e) {
304-
EDDLOG("READOUT_INTERFACE: Cannot parse RDH of received HBFs. what={}", e.what());
305-
// TODO: the whole ReadoutMsg is discarded. Account and report the data size.
306-
continue;
307-
}
308-
309-
assert (lReadoutMsgs.size() > 1);
310-
auto lStartHbf = lReadoutMsgs.begin() + 1; // skip the meta message
311-
auto lEndHbf = lStartHbf + 1;
312-
313-
std::size_t lAdded = 0;
314-
bool lErrorWhileAdding = false;
315296
const bool lFinishStf = lReadoutHdr.mFlags.mLastTFMessage;
316-
317-
while (true) {
318-
if (lEndHbf == lReadoutMsgs.end()) {
319-
//insert the remaining span
320-
std::size_t lInsertCnt = (lEndHbf - lStartHbf);
321-
lStfBuilder.addHbFrames(lDataOrigin, lSubSpecification, lReadoutHdr, lStartHbf, lInsertCnt);
322-
lAdded += lInsertCnt;
323-
break;
324-
}
325-
326-
header::DataHeader::SubSpecificationType lNewSubSpec = ~header::DataHeader::SubSpecificationType(0);
297+
if (lReadoutMsgs.size() > 1) {
298+
// check subspecifications of all messages
299+
header::DataHeader::SubSpecificationType lSubSpecification = ~header::DataHeader::SubSpecificationType(0);
300+
header::DataOrigin lDataOrigin;
327301
try {
328-
const auto Rend = RDHReader(*lEndHbf);
329-
lNewSubSpec = ReadoutDataUtils::getSubSpecification(Rend);
302+
const auto R1 = RDHReader(lReadoutMsgs[1]);
303+
lDataOrigin = ReadoutDataUtils::getDataOrigin(R1);
304+
lSubSpecification = ReadoutDataUtils::getSubSpecification(R1);
330305
} catch (RDHReaderException &e) {
331-
EDDLOG(e.what());
332-
// TODO: portion of the ReadoutMsg is discarded. Account and report the data size.
333-
lErrorWhileAdding = true;
334-
break;
306+
EDDLOG("READOUT_INTERFACE: Cannot parse RDH of received HBFs. what={}", e.what());
307+
// TODO: the whole ReadoutMsg is discarded. Account and report the data size.
308+
continue;
335309
}
336310

337-
if (lNewSubSpec != lSubSpecification) {
338-
EDDLOG("READOUT INTERFACE: update with mismatched subspecification."
339-
" block[0]: {:#06x}, block[{}]: {:#06x}",
340-
lSubSpecification, (lEndHbf - (lReadoutMsgs.begin() + 1)), lNewSubSpec);
341-
// insert
342-
lStfBuilder.addHbFrames(lDataOrigin, lSubSpecification, lReadoutHdr, lStartHbf, lEndHbf - lStartHbf);
343-
lAdded += (lEndHbf - lStartHbf);
344-
lStartHbf = lEndHbf;
311+
assert (lReadoutMsgs.size() > 1);
312+
auto lStartHbf = lReadoutMsgs.begin() + 1; // skip the meta message
313+
auto lEndHbf = lStartHbf + 1;
345314

346-
lSubSpecification = lNewSubSpec;
315+
std::size_t lAdded = 0;
316+
bool lErrorWhileAdding = false;
317+
318+
while (true) {
319+
if (lEndHbf == lReadoutMsgs.end()) {
320+
//insert the remaining span
321+
std::size_t lInsertCnt = (lEndHbf - lStartHbf);
322+
lStfBuilder.addHbFrames(lDataOrigin, lSubSpecification, lReadoutHdr, lStartHbf, lInsertCnt);
323+
lAdded += lInsertCnt;
324+
break;
325+
}
326+
327+
header::DataHeader::SubSpecificationType lNewSubSpec = ~header::DataHeader::SubSpecificationType(0);
328+
try {
329+
const auto Rend = RDHReader(*lEndHbf);
330+
lNewSubSpec = ReadoutDataUtils::getSubSpecification(Rend);
331+
} catch (RDHReaderException &e) {
332+
EDDLOG(e.what());
333+
// TODO: portion of the ReadoutMsg is discarded. Account and report the data size.
334+
lErrorWhileAdding = true;
335+
break;
336+
}
337+
338+
if (lNewSubSpec != lSubSpecification) {
339+
EDDLOG("READOUT INTERFACE: update with mismatched subspecification."
340+
" block[0]: {:#06x}, block[{}]: {:#06x}",
341+
lSubSpecification, (lEndHbf - (lReadoutMsgs.begin() + 1)), lNewSubSpec);
342+
// insert
343+
lStfBuilder.addHbFrames(lDataOrigin, lSubSpecification, lReadoutHdr, lStartHbf, lEndHbf - lStartHbf);
344+
lAdded += (lEndHbf - lStartHbf);
345+
lStartHbf = lEndHbf;
346+
347+
lSubSpecification = lNewSubSpec;
348+
}
349+
lEndHbf = lEndHbf + 1;
347350
}
348-
lEndHbf = lEndHbf + 1;
349-
}
350351

351-
if (!lErrorWhileAdding && (lAdded != lReadoutMsgs.size() - 1) ) {
352-
EDDLOG("BUG: Not all received HBFrames added to the STF.");
352+
if (!lErrorWhileAdding && (lAdded != lReadoutMsgs.size() - 1) ) {
353+
EDDLOG("BUG: Not all received HBFrames added to the STF.");
354+
}
353355
}
354356

355357
// check if this was the last message of an STF

0 commit comments

Comments
 (0)