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