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)];