From 2bdebc0e8ea555a139009d5be378f2a26b227845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 10 Sep 2025 12:40:01 +0200 Subject: [PATCH 1/6] Add label making utility to metadata --- Common/Core/MetadataHelper.cxx | 16 +++++ Common/Core/MetadataHelper.h | 3 + Common/Core/macros/testMetadataHelper.C | 79 +++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 Common/Core/macros/testMetadataHelper.C diff --git a/Common/Core/MetadataHelper.cxx b/Common/Core/MetadataHelper.cxx index 79aa051a64f..b025c5df7a1 100644 --- a/Common/Core/MetadataHelper.cxx +++ b/Common/Core/MetadataHelper.cxx @@ -124,3 +124,19 @@ bool MetadataHelper::isInitialized() const } return mIsInitialized; } + +std::string MetadataHelper::makeMetadataLabel() const +{ + if (!mIsInitialized) { + LOG(fatal) << "Metadata not initialized"; + } + std::string label = get("DataType"); + label += "_" + get("LPMProductionTag"); + if (isMC()) { + label += "_" + get("AnchorPassName"); + label += "_" + get("AnchorProduction"); + } else { + label += "_" + get("RecoPassName"); + } + return label; +} diff --git a/Common/Core/MetadataHelper.h b/Common/Core/MetadataHelper.h index bab7b1f7eb0..20737376c51 100644 --- a/Common/Core/MetadataHelper.h +++ b/Common/Core/MetadataHelper.h @@ -61,6 +61,9 @@ struct MetadataHelper { /// @return true if the key is defined, false otherwise. Throws an exception if the key is not found bool isKeyDefined(const std::string& key) const; + /// @brief Function to create a label with the metadata information, useful e.g. for histogram naming + std::string makeMetadataLabel() const; + private: std::map mMetadata; /// < The metadata map bool mIsInitialized = false; /// < Flag to check if the metadata has been initialized diff --git a/Common/Core/macros/testMetadataHelper.C b/Common/Core/macros/testMetadataHelper.C new file mode 100644 index 00000000000..abeb0314dd5 --- /dev/null +++ b/Common/Core/macros/testMetadataHelper.C @@ -0,0 +1,79 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file testMetadataHelper.C +/// \author Nicolò Jacazio nicolo.jacazio@cern.ch +/// \brief Test the MetadataHelper functionality + +#include "Common/Core/MetadataHelper.h" + +#include +#include +#include +#include +#include + +#include +#include +#include + +// Taken from O2/Framework/AnalysisSupport/src/Plugin.cxx +auto readMetadata(std::unique_ptr& currentFile) -> std::vector +{ + // Get the metadata, if any + auto m = (TMap*)currentFile->Get("metaData"); + if (!m) { + return {}; + } + std::vector results; + auto it = m->MakeIterator(); + + // Serialise metadata into a ; separated string with : separating key and value + bool first = true; + while (auto obj = it->Next()) { + if (first) { + LOGP(info, "Metadata for file \"{}\":", currentFile->GetName()); + first = false; + } + auto objString = (TObjString*)m->GetValue(obj); + std::string key = "aod-metadata-" + std::string(obj->GetName()); + LOGP(info, "- {}: {} goes into key {}", obj->GetName(), objString->String().Data(), key); + char const* value = strdup(objString->String()); + results.push_back(o2::framework::ConfigParamSpec{key, o2::framework::VariantType::String, value, {"Metadata in AOD"}}); + } + return results; +} + +void testMetadataHelper(std::string aod = "/tmp/AO2D.root") +{ + + TFile* file = TFile::Open(aod.c_str()); + if (!file || file->IsZombie()) { + LOG(fatal) << "Could not open file " << aod; + } + std::unique_ptr currentFile{file}; + std::vector specs = readMetadata(currentFile); + + std::vector> retrievers; + auto paramStore = std::make_unique(specs, std::move(retrievers)); + paramStore->preload(); + paramStore->activate(); + o2::framework::ConfigParamRegistry paramRegistry(std::move(paramStore)); + o2::framework::ServiceRegistry serviceRegistry; + o2::framework::ServiceRegistryRef services(serviceRegistry); + o2::framework::ConfigContext aodCfg(paramRegistry, services, 0, nullptr); + LOG(info) << "Loaded " << aodCfg.options().specs().size() << " configuration entries from file " << aod; + aodCfg.options().get("aod-metadata-DataType"); + o2::common::core::MetadataHelper metadataInfo; + metadataInfo.initMetadata(aodCfg); + metadataInfo.print(); + LOG(info) << "Metadata label: " << metadataInfo.makeMetadataLabel(); +} From 7ad384800d05c0332f267f479b24a5463e8ceea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 10 Sep 2025 12:42:43 +0200 Subject: [PATCH 2/6] Fix linter --- Common/Core/MetadataHelper.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Common/Core/MetadataHelper.h b/Common/Core/MetadataHelper.h index 20737376c51..3e60d56695b 100644 --- a/Common/Core/MetadataHelper.h +++ b/Common/Core/MetadataHelper.h @@ -8,7 +8,9 @@ // In applying this license CERN does not waive the privileges and immunities // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file TableHelper.h + +/// +/// \file MetaDataHelper.h /// \author Nicolò Jacazio nicolo.jacazio@cern.ch /// \brief Utility to handle the metadata from the AOD /// From d53f1d2d27c3ab210194475bdacf06cb2251fca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 10 Sep 2025 12:44:30 +0200 Subject: [PATCH 3/6] Attempt at fix O2Linter --- Common/Core/MetadataHelper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/Core/MetadataHelper.h b/Common/Core/MetadataHelper.h index 3e60d56695b..e82d5eae591 100644 --- a/Common/Core/MetadataHelper.h +++ b/Common/Core/MetadataHelper.h @@ -10,9 +10,9 @@ // or submit itself to any jurisdiction. /// -/// \file MetaDataHelper.h +/// \file MetaDataHelper.h /// \author Nicolò Jacazio nicolo.jacazio@cern.ch -/// \brief Utility to handle the metadata from the AOD +/// \brief Utility to handle the metadata from the AOD /// #ifndef COMMON_CORE_METADATAHELPER_H_ From 2a4fffe0bc3d1dbf9f2c01dc57c8592e14ab1190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 10 Sep 2025 12:46:27 +0200 Subject: [PATCH 4/6] Second try --- Common/Core/MetadataHelper.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Common/Core/MetadataHelper.h b/Common/Core/MetadataHelper.h index e82d5eae591..d5a5d6d8a39 100644 --- a/Common/Core/MetadataHelper.h +++ b/Common/Core/MetadataHelper.h @@ -9,11 +9,9 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// /// \file MetaDataHelper.h -/// \author Nicolò Jacazio nicolo.jacazio@cern.ch /// \brief Utility to handle the metadata from the AOD -/// +/// \author Nicolò Jacazio nicolo.jacazio@cern.ch #ifndef COMMON_CORE_METADATAHELPER_H_ #define COMMON_CORE_METADATAHELPER_H_ From 13aaf2c36d06e9d3d09541aa02ec44768374a24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 10 Sep 2025 12:46:48 +0200 Subject: [PATCH 5/6] Fix --- Common/Core/MetadataHelper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/Core/MetadataHelper.h b/Common/Core/MetadataHelper.h index d5a5d6d8a39..3854820bd84 100644 --- a/Common/Core/MetadataHelper.h +++ b/Common/Core/MetadataHelper.h @@ -9,7 +9,7 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file MetaDataHelper.h +/// \file MetadataHelper.h /// \brief Utility to handle the metadata from the AOD /// \author Nicolò Jacazio nicolo.jacazio@cern.ch From 4409e189ac4a7c4d3379cf8d8994c9c6a3242888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 10 Sep 2025 12:51:55 +0200 Subject: [PATCH 6/6] Update --- Common/Core/macros/testMetadataHelper.C | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Common/Core/macros/testMetadataHelper.C b/Common/Core/macros/testMetadataHelper.C index abeb0314dd5..30c109f7840 100644 --- a/Common/Core/macros/testMetadataHelper.C +++ b/Common/Core/macros/testMetadataHelper.C @@ -25,6 +25,11 @@ #include #include +#include +#include +#include +#include + // Taken from O2/Framework/AnalysisSupport/src/Plugin.cxx auto readMetadata(std::unique_ptr& currentFile) -> std::vector {