134 .discover = [](
ConfigParamRegistry& registry,
int argc,
char** argv) -> std::vector<ConfigParamSpec> {
135 auto filename = registry.
get<std::string>(
"aod-file");
143 if (!
file.is_open()) {
144 LOGP(fatal,
"Couldn't open file \"{}\"!",
filename);
149 if (
filename.rfind(
"alien://", 0) == 0) {
150 TGrid::Connect(
"alien://");
152 LOGP(info,
"Loading metadata from file {} in PID {}",
filename, getpid());
153 std::unique_ptr<TFile> currentFile{TFile::Open(
filename.c_str())};
154 if (currentFile.get() ==
nullptr) {
155 LOGP(fatal,
"Couldn't open file \"{}\"!",
filename);
157 std::vector<ConfigParamSpec> results =
readMetadata(currentFile);
158 const bool metaDataEmpty = results.empty();
160 if (tables.empty() ==
false) {
161 results.push_back(
ConfigParamSpec{
"aod-metadata-tables", VariantType::ArrayString, tables, {
"Tables in first AOD"}});
165 if (!metaDataEmpty) {
166 results.push_back(
ConfigParamSpec{
"aod-metadata-source", VariantType::String,
filename, {
"File from which the metadata was extracted."}});
170 if (!registry.
isSet(
"aod-parent-access-level") || registry.
get<
int>(
"aod-parent-access-level") == 0) {
171 LOGP(info,
"No metadata found in file \"{}\" and parent level 0 prevents further lookup.",
filename);
172 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});
177 auto parentFiles = (TMap*)currentFile->Get(
"parentFiles");
179 LOGP(info,
"No metadata found in file \"{}\"",
filename);
180 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});
183 LOGP(info,
"No metadata found in file \"{}\", checking in its parents.",
filename);
184 for (
auto* p : *parentFiles) {
185 std::string parentFilename = ((TPair*)p)->Value()->GetName();
188 if (registry.
isSet(
"aod-parent-base-path-replacement")) {
189 auto parentFileReplacement = registry.
get<std::string>(
"aod-parent-base-path-replacement");
190 auto pos = parentFileReplacement.find(
';');
191 if (
pos == std::string::npos) {
192 throw std::runtime_error(fmt::format(
"Invalid syntax in aod-parent-base-path-replacement: \"{}\"", parentFileReplacement.c_str()));
194 auto from = parentFileReplacement.substr(0,
pos);
195 auto to = parentFileReplacement.substr(
pos + 1);
196 pos = parentFilename.find(from);
197 if (
pos != std::string::npos) {
198 parentFilename.replace(
pos, from.length(), to);
202 if (parentFilename.starts_with(
"alien://")) {
203 TGrid::Connect(
"alien://");
206 std::unique_ptr<TFile> parentFile{TFile::Open(parentFilename.c_str())};
207 if (parentFile.get() ==
nullptr) {
208 LOGP(fatal,
"Couldn't open derived file \"{}\"!", parentFilename);
212 if (!results.empty()) {
214 if (tables.empty() ==
false) {
215 results.push_back(
ConfigParamSpec{
"aod-metadata-tables", VariantType::ArrayString, tables, {
"Tables in first AOD"}});
217 results.push_back(
ConfigParamSpec{
"aod-metadata-source", VariantType::String,
filename, {
"File from which the metadata was extracted."}});
220 LOGP(info,
"No metadata found in file \"{}\" nor in its parent file \"{}\"",
filename, parentFilename);
223 results.push_back(
ConfigParamSpec{
"aod-metadata-disable", VariantType::String,
"1", {
"Metadata not found in AOD"}});