Skip to content

Commit f03ffeb

Browse files
committed
Switch reading booleans to state
1 parent 9bad534 commit f03ffeb

1 file changed

Lines changed: 40 additions & 29 deletions

File tree

Framework/AnalysisSupport/src/AODJAlienReaderHelpers.cxx

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,18 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
262262
auto dh = header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
263263
bool wasAOD = std::ranges::any_of(route.matcher.metadata, [](ConfigParamSpec const& p) { return p.name.starts_with("aod-origin-replaced"); });
264264

265-
bool treeRead = false;
265+
enum class ReadState {
266+
READ,
267+
NOT_READ_AND_FIRST,
268+
NOT_READ_AND_MIDDLE,
269+
};
270+
ReadState readState;
266271
try {
267-
treeRead = didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD);
272+
if (didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD)) {
273+
readState = ReadState::READ;
274+
} else {
275+
readState = first ? ReadState::NOT_READ_AND_FIRST : ReadState::NOT_READ_AND_MIDDLE;
276+
}
268277
} catch (InvalidAODReadError const& e) {
269278
if (!skipInvalidReads) {
270279
throw;
@@ -273,36 +282,38 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
273282
return;
274283
}
275284

276-
if (!treeRead) {
277-
if (!first) {
285+
switch (readState) {
286+
case ReadState::READ:
287+
break;
288+
case ReadState::NOT_READ_AND_MIDDLE:
278289
LOGP(fatal, "Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
279290
throw std::runtime_error("Processing is stopped!");
280-
}
281-
// check if there is a next file to read
282-
fcnt += device.maxInputTimeslices;
283-
if (didir->atEnd(fcnt)) {
284-
LOGP(info, "No input files left to read for reader {}!", device.inputTimesliceId);
285-
didir->closeInputFiles();
286-
monitoring.flushBuffer();
287-
control.endOfStream();
288-
control.readyToQuit(QuitRequest::Me);
289-
return;
290-
}
291-
// get first folder of next file
292-
ntf = 0;
293-
try {
294-
treeRead = didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD);
295-
} catch (InvalidAODReadError const& e) {
296-
if (!skipInvalidReads) {
297-
throw;
291+
case ReadState::NOT_READ_AND_FIRST:
292+
// check if there is a next file to read
293+
fcnt += device.maxInputTimeslices;
294+
if (didir->atEnd(fcnt)) {
295+
LOGP(info, "No input files left to read for reader {}!", device.inputTimesliceId);
296+
didir->closeInputFiles();
297+
monitoring.flushBuffer();
298+
control.endOfStream();
299+
control.readyToQuit(QuitRequest::Me);
300+
return;
298301
}
299-
skipInvalidRead(concrete.origin, e);
300-
return;
301-
}
302-
if (!treeRead) {
303-
LOGP(fatal, "Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
304-
throw std::runtime_error("Processing is stopped!");
305-
}
302+
// get first folder of next file
303+
ntf = 0;
304+
try {
305+
if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD)) {
306+
LOGP(fatal, "Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
307+
throw std::runtime_error("Processing is stopped!");
308+
}
309+
} catch (InvalidAODReadError const& e) {
310+
if (!skipInvalidReads) {
311+
throw;
312+
}
313+
skipInvalidRead(concrete.origin, e);
314+
return;
315+
}
316+
break;
306317
}
307318

308319
if (first) {

0 commit comments

Comments
 (0)