From feb31eaff4bbed57c68b8789f7a502c91ed6383e Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:14:04 +0100 Subject: [PATCH] DPL Analysis: report an AO2D without DF folders as a file which cannot be opened The checks for "no TF left" in getTimeFrameNumber and getFileFolder only applied when the file had timeframes, so on an AO2D without any DF folder they indexed an empty list: the reader crashed with a segmentation fault in DataInputDescriptor::getFileFolder, with the ROOT and the native backend alike. Such files exist: merging a derived AO2D which was not closed gives an AO2D without DF folders (e.g. /alice/cern.ch/user/a/alihyperloop/jobs/0654/hy_6549405/AOD/001/AO2D.root). An AO2D without DF folders means data was lost upstream, so do not skip it silently: setFile() closes it and throws AODReadError FileOpen, as for a file which cannot be opened. With --skip-invalid-reads it is skipped and counted in AOD_FILE_OPEN_SKIPPED_FILES; otherwise the processing stops with the name of the file. The range checks no longer depend on the file having timeframes. --- .../AnalysisSupport/src/DataInputDirector.cxx | 19 +++++++-- .../test/test_NavigateToLevel.cxx | 40 +++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Framework/AnalysisSupport/src/DataInputDirector.cxx b/Framework/AnalysisSupport/src/DataInputDirector.cxx index 25eef8ecf1fe5..a2310139dc035 100644 --- a/Framework/AnalysisSupport/src/DataInputDirector.cxx +++ b/Framework/AnalysisSupport/src/DataInputDirector.cxx @@ -275,6 +275,17 @@ bool DataInputDescriptor::setFile(int counter, int wantedParentLevel, std::strin mfilenames[counter].alreadyRead.resize(mfilenames[counter].alreadyRead.size() + mfilenames[counter].listOfTimeFrameNumbers.size(), false); mfilenames[counter].numberOfTimeFrames = mfilenames[counter].listOfTimeFrameNumbers.size(); + + // An AO2D without any DF folder is what is left when the data was lost upstream (e.g. an + // AO2D merged from one which was not closed). Report it as a file which cannot be opened, + // so that it is either skipped and counted (--skip-invalid-reads) or stops the processing. + if (mfilenames[counter].numberOfTimeFrames == 0) { + mCurrentFileID = counter; // for the statistics reported on closing it + mCurrentFileStartedAt = uv_hrtime(); + mIOTime = 0; + closeInputFile(); + throw AODReadError(AODReadError::Kind::FileOpen, fmt::format("File \"{}\" has no DF folder!", filename)); + } } std::vector readOrder; for (auto number : mfilenames[counter].listOfTimeFrameNumbers) { @@ -297,8 +308,8 @@ uint64_t DataInputDescriptor::getTimeFrameNumber(int counter, int numTF, int wan return 0ul; } - // no TF left - if (mfilenames[counter].numberOfTimeFrames > 0 && numTF >= mfilenames[counter].numberOfTimeFrames) { + // no TF left, or none at all: setFile() has counted them, an empty AO2D has 0 + if (numTF < 0 || numTF >= mfilenames[counter].numberOfTimeFrames) { return 0ul; } @@ -338,8 +349,8 @@ arrow::dataset::FileSource DataInputDescriptor::getFileFolder(int counter, int n return {}; } - // no TF left - if ((mfilenames[counter].numberOfTimeFrames > 0) && (numTF >= mfilenames[counter].numberOfTimeFrames)) { + // no TF left, or none at all: setFile() has counted them, an empty AO2D has 0 + if (numTF < 0 || numTF >= mfilenames[counter].numberOfTimeFrames) { return {}; } diff --git a/Framework/AnalysisSupport/test/test_NavigateToLevel.cxx b/Framework/AnalysisSupport/test/test_NavigateToLevel.cxx index 0072ee3b67d37..c3961c49bab74 100644 --- a/Framework/AnalysisSupport/test/test_NavigateToLevel.cxx +++ b/Framework/AnalysisSupport/test/test_NavigateToLevel.cxx @@ -18,6 +18,8 @@ #include #include +#include + using namespace o2::framework; // Tests for DataInputDirectorContext::levelForOrigin @@ -133,3 +135,41 @@ TEST_CASE("navigateToLevel returns -1 for missing DF in parent") REQUIRE(parentDesc != nullptr); CHECK(parentNumTF == -1); } + +// An AO2D without any DF folder, as merging an AO2D which was not closed +// produces, is reported as a file which cannot be opened, every time it is +// asked for, instead of indexing its empty list of timeframes. +TEST_CASE("An AO2D without DFs is a file which cannot be opened") +{ + auto* emptyMF = new TMemFile("empty.root", "RECREATE"); + emptyMF->Write(); + + DataInputDirectorContext ctx; + ctx.openFiles = {{"empty.root", emptyMF}}; + + DataInputDescriptor desc(false, 0, ctx); + desc.addFileNameHolder(makeFileNameHolder("empty.root")); + + auto isFileOpen = [](AODReadError const& e) { return e.getKind() == AODReadError::Kind::FileOpen; }; + for (int attempt = 0; attempt < 2; ++attempt) { + CHECK_THROWS_MATCHES(desc.getFileFolder(0, 0, -1, "AOD"), AODReadError, Catch::Matchers::Predicate(isFileOpen)); + CHECK_THROWS_MATCHES(desc.getTimeFrameNumber(0, 0, -1, "AOD"), AODReadError, Catch::Matchers::Predicate(isFileOpen)); + } + CHECK(desc.getTimeFramesInFile(0) == 0); +} + +TEST_CASE("An AO2D without DFs is a file which cannot be opened, native reader") +{ + const char* name = "test_NavigateToLevel_empty_native.root"; + delete TFile::Open(name, "RECREATE"); + + DataInputDirectorContext ctx; + ctx.readerBackend = "native"; + + DataInputDescriptor desc(false, 0, ctx); + desc.addFileNameHolder(makeFileNameHolder(name)); + + auto isFileOpen = [](AODReadError const& e) { return e.getKind() == AODReadError::Kind::FileOpen; }; + CHECK_THROWS_MATCHES(desc.getFileFolder(0, 0, -1, "AOD"), AODReadError, Catch::Matchers::Predicate(isFileOpen)); + std::remove(name); +}