Skip to content

Commit be76adc

Browse files
committed
AOD: Possibility to inject additional meta data
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. 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 108aeca commit be76adc

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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)