Skip to content

Commit 893836d

Browse files
authored
AOD: Possibility to inject additional meta data (#14362)
Commit provides possibility to inject additional (non-hard-coded) meta data into AOD. This could be used by MC to add information about timeframe length used or other specific configurations etc. The commit relates to https://its.cern.ch/jira/browse/O2-6027 By default this does not change any production behaviour. Existing meta data is not touched. This works by generating a simple key-value json (foo.json) like ``` { "ALIEN_JDL_MC_ORBITS_PER_TF": "4", "ALIEN_JDL_ANCHOR_SIM_OPTIONS": "-gen pythia8" } ``` and then exporting an environment variable pointing to this json. ``` export AOD_ADDITIONAL_METADATA_FILE=${PWD}/foo.json ```
1 parent ec14f04 commit 893836d

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

Detectors/AOD/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ o2_add_executable(
4242
COMPONENT_NAME aod-producer
4343
TARGETVARNAME targetName
4444
SOURCES src/aod-producer-workflow.cxx src/AODProducerWorkflowSpec.cxx src/AODMcProducerHelpers.cxx
45-
PUBLIC_LINK_LIBRARIES internal::AODProducerWorkflow O2::Version
45+
PUBLIC_LINK_LIBRARIES internal::AODProducerWorkflow O2::Version nlohmann_json::nlohmann_json
4646
)
4747

4848
o2_add_executable(
4949
workflow
5050
COMPONENT_NAME aod-mc-producer
5151
SOURCES src/aod-mc-producer-workflow.cxx src/AODMcProducerWorkflowSpec.cxx src/AODMcProducerHelpers.cxx
52-
PUBLIC_LINK_LIBRARIES internal::AODProducerWorkflow O2::Version
52+
PUBLIC_LINK_LIBRARIES internal::AODProducerWorkflow O2::Version nlohmann_json::nlohmann_json
5353
)
5454

5555
o2_add_executable(
@@ -75,7 +75,8 @@ o2_add_executable(
7575
O2::DataFormatsFT0
7676
O2::Steer
7777
O2::ZDCBase
78-
)
78+
nlohmann_json::nlohmann_json
79+
)
7980

8081
if (OpenMP_CXX_FOUND)
8182
target_compile_definitions(${targetName} PRIVATE WITH_OPENMP)

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
#ifdef WITH_OPENMP
103103
#include <omp.h>
104104
#endif
105+
#include <filesystem>
106+
#include <nlohmann/json.hpp>
105107

106108
using namespace o2::framework;
107109
using namespace o2::math_utils::detail;
@@ -1793,6 +1795,38 @@ void AODProducerWorkflowDPL::init(InitContext& ic)
17931795
}
17941796
}
17951797

1798+
namespace
1799+
{
1800+
void add_additional_meta_info(std::vector<TString>& keys, std::vector<TString>& values)
1801+
{
1802+
// see if we should put additional meta info (e.g. from MC)
1803+
auto aod_external_meta_info_file = getenv("AOD_ADDITIONAL_METADATA_FILE");
1804+
if (aod_external_meta_info_file != nullptr) {
1805+
LOG(info) << "Trying to inject additional AOD meta-data from " << aod_external_meta_info_file;
1806+
if (std::filesystem::exists(aod_external_meta_info_file)) {
1807+
std::ifstream input_file(aod_external_meta_info_file);
1808+
if (input_file) {
1809+
nlohmann::json json_data;
1810+
try {
1811+
input_file >> json_data;
1812+
} catch (nlohmann::json::parse_error& e) {
1813+
std::cerr << "JSON Parse Error: " << e.what() << "\n";
1814+
std::cerr << "Exception ID: " << e.id << "\n";
1815+
std::cerr << "Byte position: " << e.byte << "\n";
1816+
return;
1817+
}
1818+
// If parsing succeeds, iterate over key-value pairs
1819+
for (const auto& [key, value] : json_data.items()) {
1820+
LOG(info) << "Adding AOD MetaData" << key << " : " << value;
1821+
keys.push_back(key.c_str());
1822+
values.push_back(value.get<std::string>());
1823+
}
1824+
}
1825+
}
1826+
}
1827+
}
1828+
} // namespace
1829+
17961830
void AODProducerWorkflowDPL::run(ProcessingContext& pc)
17971831
{
17981832
mTimer.Start(false);
@@ -2401,6 +2435,8 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
24012435
TString ROOTVersion = ROOT_RELEASE;
24022436
mMetaDataKeys = {"DataType", "Run", "O2Version", "ROOTVersion", "RecoPassName", "AnchorProduction", "AnchorPassName", "LPMProductionTag", "CreatedBy"};
24032437
mMetaDataVals = {dataType, "3", O2Version, ROOTVersion, mRecoPass, mAnchorProd, mAnchorPass, mLPMProdTag, mUser};
2438+
add_additional_meta_info(mMetaDataKeys, mMetaDataVals);
2439+
24042440
pc.outputs().snapshot(Output{"AMD", "AODMetadataKeys", 0}, mMetaDataKeys);
24052441
pc.outputs().snapshot(Output{"AMD", "AODMetadataVals", 0}, mMetaDataVals);
24062442

0 commit comments

Comments
 (0)