162 .discover = [](
ConfigParamRegistry& registry,
int argc,
char** argv) -> std::vector<ConfigParamSpec> {
163 auto filename = registry.
get<std::string>(
"aod-file");
171 if (!
file.is_open()) {
172 LOGP(fatal,
"Couldn't open file \"{}\"!",
filename);
177 if (
filename.rfind(
"alien://", 0) == 0) {
178 TGrid::Connect(
"alien://");
180 LOGP(info,
"Loading metadata from file {} in PID {}",
filename, getpid());
181 std::unique_ptr<TFile> currentFile{TFile::Open(
filename.c_str())};
182 if (currentFile.get() ==
nullptr) {
183 LOGP(fatal,
"Couldn't open file \"{}\"!",
filename);
185 std::vector<ConfigParamSpec> results =
readMetadata(currentFile);
186 const bool metaDataEmpty = results.empty();
188 if (tables.empty() ==
false) {
189 results.push_back(
ConfigParamSpec{
"aod-metadata-tables", VariantType::ArrayString, tables, {
"Tables in first AOD"}});
193 if (!metaDataEmpty) {
194 results.push_back(
ConfigParamSpec{
"aod-metadata-source", VariantType::String,
filename, {
"File from which the metadata was extracted."}});
198 if (!registry.
isSet(
"aod-parent-access-level") || registry.
get<
int>(
"aod-parent-access-level") == 0) {
199 LOGP(info,
"No metadata found in file \"{}\" and parent level 0 prevents further lookup.",
filename);
200 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});
205 auto parentFiles = (TMap*)currentFile->Get(
"parentFiles");
207 LOGP(info,
"No metadata found in file \"{}\"",
filename);
208 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});
211 LOGP(info,
"No metadata found in file \"{}\", checking in its parents.",
filename);
212 for (
auto* p : *parentFiles) {
213 std::string parentFilename = ((TPair*)p)->Value()->GetName();
216 if (registry.
isSet(
"aod-parent-base-path-replacement")) {
217 auto parentFileReplacement = registry.
get<std::string>(
"aod-parent-base-path-replacement");
218 auto pos = parentFileReplacement.find(
';');
219 if (
pos == std::string::npos) {
220 throw std::runtime_error(fmt::format(
"Invalid syntax in aod-parent-base-path-replacement: \"{}\"", parentFileReplacement.c_str()));
222 auto from = parentFileReplacement.substr(0,
pos);
223 auto to = parentFileReplacement.substr(
pos + 1);
224 pos = parentFilename.find(from);
225 if (
pos != std::string::npos) {
226 parentFilename.replace(
pos, from.length(), to);
230 if (parentFilename.starts_with(
"alien://")) {
231 TGrid::Connect(
"alien://");
234 std::unique_ptr<TFile> parentFile{TFile::Open(parentFilename.c_str())};
235 if (parentFile.get() ==
nullptr) {
236 LOGP(fatal,
"Couldn't open derived file \"{}\"!", parentFilename);
240 if (!results.empty()) {
242 if (tables.empty() ==
false) {
243 results.push_back(
ConfigParamSpec{
"aod-metadata-tables", VariantType::ArrayString, tables, {
"Tables in first AOD"}});
245 results.push_back(
ConfigParamSpec{
"aod-metadata-source", VariantType::String,
filename, {
"File from which the metadata was extracted."}});
248 LOGP(info,
"No metadata found in file \"{}\" nor in its parent file \"{}\"",
filename, parentFilename);
251 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});