From 1adad3cef1b6652f46dd084d258afc1729aa0d3c Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Fri, 4 Dec 2026 15:13:58 +0100 Subject: [PATCH] DPL: discover AOD metadata with the reader's backend The driver opened the input AO2D (and its parents) with ROOT to read the metadata, the parent files and the list of tables, even with --aod-reader-backend native. For an alien:// file that starts ROOT's interpreter in the driver: in a grid run of Hyperloop test 821131 the driver of the last stage was the only driver with libCling, at 411 MB PSS. Discovery now opens the files with the backend the reader uses. native uses the native reader (without prefetching, since only keys and maps are read), auto tries it and falls back to ROOT as the reader does, root is unchanged. --aod-reader-backend is an option of the reader device, not of the workflow, so discovery takes it from the command line. On an alien:// AO2D with the native backend the discovering process no longer loads libCling (38 MB peak), and the discovered options, metadata and list of tables included, are identical to those found with ROOT. --- Framework/AnalysisSupport/src/Plugin.cxx | 45 ++++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/Framework/AnalysisSupport/src/Plugin.cxx b/Framework/AnalysisSupport/src/Plugin.cxx index b0a5b0b8001cf..ad1a6c4c32940 100644 --- a/Framework/AnalysisSupport/src/Plugin.cxx +++ b/Framework/AnalysisSupport/src/Plugin.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -174,11 +175,40 @@ auto metadataToSpecs(std::map const& metadata) -> std: return results; } -/// Opens an AO2D for metadata discovery. The factory is only needed to read -/// tables, which discovery does not do. -std::shared_ptr openForDiscovery(std::string const& filename) +/// The reader backend, from the command line: --aod-reader-backend is an option +/// of the reader device, not of the workflow, so it is not in the registry. +std::string readerBackend(int argc, char** argv) +{ + std::string backend = "root"; + for (int i = 1; i < argc; ++i) { + std::string_view arg = argv[i]; + if (arg == "--aod-reader-backend" && i + 1 < argc) { + backend = argv[++i]; + } else if (arg.starts_with("--aod-reader-backend=")) { + backend = arg.substr(std::string_view("--aod-reader-backend=").size()); + } + } + return backend; +} + +/// Opens an AO2D for metadata discovery with the backend the reader uses, so that +/// with the native one the driver does not start ROOT's interpreter either. The +/// factory is only needed to read tables, which discovery does not do. +std::shared_ptr openForDiscovery(std::string const& filename, std::string const& backend) { static RootObjectReadingFactory noTables; + if (backend == "native" || backend == "auto") { + o2::aod::native::Options options; + options.prefetchDepth = 0; // only keys and maps are read + try { + return openNativeAOD(filename, noTables, options); + } catch (std::exception const& e) { + if (backend == "native") { + throw std::runtime_error(fmt::format("Couldn't open file \"{}\" with the native reader: {}", filename, e.what())); + } + LOGP(info, "Reading the metadata of \"{}\" with ROOT, the native reader cannot: {}", filename, e.what()); + } + } return RootAODInputFile::open(filename, noTables); } @@ -188,7 +218,7 @@ struct FileAtLevel { }; // Open the first parent file of `child` -FileAtLevel openParent(FileAtLevel const& child, ConfigParamRegistry& registry) +FileAtLevel openParent(FileAtLevel const& child, ConfigParamRegistry& registry, std::string const& backend) { auto parentFiles = child.file->parentFiles(); if (parentFiles.empty()) { @@ -216,7 +246,7 @@ FileAtLevel openParent(FileAtLevel const& child, ConfigParamRegistry& registry) TGrid::Connect("alien://"); } - auto parentFile = openForDiscovery(parentFilename); + auto parentFile = openForDiscovery(parentFilename, backend); if (parentFile.get() == nullptr) { LOGP(fatal, "Couldn't open derived file \"{}\"!", parentFilename); } @@ -255,7 +285,8 @@ struct DiscoverMetadataInAOD : o2::framework::ConfigDiscoveryPlugin { TGrid::Connect("alien://"); } LOGP(info, "Loading metadata from file {} in PID {}", filename, getpid()); - auto currentFile = openForDiscovery(filename); + auto backend = readerBackend(argc, argv); + auto currentFile = openForDiscovery(filename, backend); if (currentFile.get() == nullptr) { throw std::runtime_error(fmt::format("Couldn't open file \"{}\"!", filename)); } @@ -269,7 +300,7 @@ struct DiscoverMetadataInAOD : o2::framework::ConfigDiscoveryPlugin { return it->second; } while (chain.back().file && chain.size() <= static_cast(level)) { - chain.push_back(openParent(chain.back(), registry)); + chain.push_back(openParent(chain.back(), registry, backend)); } LevelMetadata data; auto const& atLevel = chain[std::min(static_cast(level), chain.size() - 1)];