Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions Framework/AnalysisSupport/src/Plugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <unistd.h>

Expand Down Expand Up @@ -174,11 +175,40 @@ auto metadataToSpecs(std::map<std::string, std::string> 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<AODInputFile> 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<AODInputFile> 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);
}

Expand All @@ -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()) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -269,7 +300,7 @@ struct DiscoverMetadataInAOD : o2::framework::ConfigDiscoveryPlugin {
return it->second;
}
while (chain.back().file && chain.size() <= static_cast<size_t>(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<size_t>(level), chain.size() - 1)];
Expand Down