diff --git a/Framework/src/CustomParameters.cxx b/Framework/src/CustomParameters.cxx index d4cb044770..7534379dec 100644 --- a/Framework/src/CustomParameters.cxx +++ b/Framework/src/CustomParameters.cxx @@ -202,7 +202,20 @@ void CustomParameters::populateCustomParameters(const boost::property_tree::ptre for (const auto& [runtype, subTreeRunType] : tree) { for (const auto& [beamtype, subTreeBeamType] : subTreeRunType) { for (const auto& [key, value] : subTreeBeamType) { - set(key, value.get_value(), runtype, beamtype); + // Check if value has children (thus it is json) + if (value.empty()) { // just a simple value + set(key, value.get_value(), runtype, beamtype); + } else { + // It's some json, serialize it to string + std::stringstream ss; + boost::property_tree::write_json(ss, value, false); + std::string jsonString = ss.str(); + // Remove trailing newline if present + if (!jsonString.empty() && jsonString.back() == '\n') { + jsonString.pop_back(); + } + set(key, jsonString, runtype, beamtype); + } } } } diff --git a/Framework/test/testCustomParameters.cxx b/Framework/test/testCustomParameters.cxx index 5d7eccfec7..8389047d9d 100644 --- a/Framework/test/testCustomParameters.cxx +++ b/Framework/test/testCustomParameters.cxx @@ -18,8 +18,12 @@ #include #include #include "getTestDataDirectory.h" +#include "QualityControl/InfrastructureGenerator.h" + #include #include +#include +#include using namespace o2::quality_control::core; using namespace std; @@ -201,6 +205,35 @@ TEST_CASE("test_load_from_ptree") CHECK(cp.at("myOwnKey") == "myOwnValue"); CHECK(cp.at("myOwnKey1", "PHYSICS") == "myOwnValue1b"); CHECK(cp.atOptional("asdf").has_value() == false); + + auto value = cp.getOptionalPtree("myOwnKey3"); + CHECK(value.has_value() == true); + + // Check that it's an array with 1 element + std::size_t arraySize = std::distance(value->begin(), value->end()); + CHECK(arraySize == 1); + + // Get the first (and only) element of the array + auto firstElement = value->begin()->second; + + // Check the top-level properties + CHECK(firstElement.get("name") == "mean_of_histogram"); + CHECK(firstElement.get("title") == "Mean trend of the example histogram"); + CHECK(firstElement.get("graphAxisLabel") == "Mean X:time"); + CHECK(firstElement.get("graphYRange") == "0:10000"); + + // Check the graphs array + auto graphs = firstElement.get_child("graphs"); + std::size_t graphsSize = std::distance(graphs.begin(), graphs.end()); + CHECK(graphsSize == 1); + + // Check the first graph properties + auto firstGraph = graphs.begin()->second; + CHECK(firstGraph.get("name") == "mean_trend"); + CHECK(firstGraph.get("title") == "mean trend"); + CHECK(firstGraph.get("varexp") == "example.mean:time"); + CHECK(firstGraph.get("selection") == ""); + CHECK(firstGraph.get("option") == "*L PLC PMC"); } TEST_CASE("test_default_if_not_found_at_optional") diff --git a/Framework/test/testWorkflow.json b/Framework/test/testWorkflow.json index e7376eb33f..f02db53386 100644 --- a/Framework/test/testWorkflow.json +++ b/Framework/test/testWorkflow.json @@ -28,7 +28,24 @@ "default": { "default": { "myOwnKey": "myOwnValue", - "myOwnKey2": "myOwnValue2" + "myOwnKey2": "myOwnValue2", + "myOwnKey3": [ + { + "name": "mean_of_histogram", + "title": "Mean trend of the example histogram", + "graphAxisLabel": "Mean X:time", + "graphYRange": "0:10000", + "graphs" : [ + { + "name": "mean_trend", + "title": "mean trend", + "varexp": "example.mean:time", + "selection": "", + "option": "*L PLC PMC" + } + ] + } + ] } }, "PHYSICS": {