184 .discover = [](
ConfigParamRegistry& registry,
int argc,
char** argv) -> std::vector<ConfigParamSpec> {
185 auto filename = registry.
get<std::string>(
"aod-file");
193 if (!
file.is_open()) {
194 LOGP(fatal,
"Couldn't open file \"{}\"!",
filename);
199 if (
filename.rfind(
"alien://", 0) == 0 && !gGrid) {
200 TGrid::Connect(
"alien://");
202 LOGP(info,
"Loading metadata from file {} in PID {}",
filename, getpid());
203 std::unique_ptr<TFile> currentFile{TFile::Open(
filename.c_str())};
204 if (currentFile.get() ==
nullptr) {
205 LOGP(fatal,
"Couldn't open file \"{}\"!",
filename);
207 std::vector<ConfigParamSpec> results =
readMetadata(currentFile);
208 const bool metaDataEmpty = results.empty();
210 if (tables.empty() ==
false) {
211 results.push_back(
ConfigParamSpec{
"aod-metadata-tables", VariantType::ArrayString, tables, {
"Tables in first AOD"}});
215 if (!metaDataEmpty) {
216 results.push_back(
ConfigParamSpec{
"aod-metadata-source", VariantType::String,
filename, {
"File from which the metadata was extracted."}});
220 if (!registry.
isSet(
"aod-parent-access-level") || registry.
get<
int>(
"aod-parent-access-level") == 0) {
221 LOGP(info,
"No metadata found in file \"{}\" and parent level 0 prevents further lookup.",
filename);
222 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});
227 auto parentFiles = (TMap*)currentFile->Get(
"parentFiles");
229 LOGP(info,
"No metadata found in file \"{}\"",
filename);
230 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});
233 LOGP(info,
"No metadata found in file \"{}\", checking in its parents.",
filename);
234 for (
auto* p : *parentFiles) {
235 std::string parentFilename = ((TPair*)p)->Value()->GetName();
238 if (registry.
isSet(
"aod-parent-base-path-replacement")) {
239 auto parentFileReplacement = registry.
get<std::string>(
"aod-parent-base-path-replacement");
240 auto pos = parentFileReplacement.find(
';');
241 if (
pos == std::string::npos) {
242 throw std::runtime_error(fmt::format(
"Invalid syntax in aod-parent-base-path-replacement: \"{}\"", parentFileReplacement.c_str()));
244 auto from = parentFileReplacement.substr(0,
pos);
245 auto to = parentFileReplacement.substr(
pos + 1);
246 pos = parentFilename.find(from);
247 if (
pos != std::string::npos) {
248 parentFilename.replace(
pos, from.length(), to);
252 if (parentFilename.starts_with(
"alien://") && !gGrid) {
253 TGrid::Connect(
"alien://");
256 std::unique_ptr<TFile> parentFile{TFile::Open(parentFilename.c_str())};
257 if (parentFile.get() ==
nullptr) {
258 LOGP(fatal,
"Couldn't open derived file \"{}\"!", parentFilename);
262 if (!results.empty()) {
264 if (tables.empty() ==
false) {
265 results.push_back(
ConfigParamSpec{
"aod-metadata-tables", VariantType::ArrayString, tables, {
"Tables in first AOD"}});
267 results.push_back(
ConfigParamSpec{
"aod-metadata-source", VariantType::String,
filename, {
"File from which the metadata was extracted."}});
270 LOGP(info,
"No metadata found in file \"{}\" nor in its parent file \"{}\"",
filename, parentFilename);
273 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});