Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Framework/src/CustomParameters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(), runtype, beamtype);
// Check if value has children (thus it is json)
if (value.empty()) { // just a simple value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not believe that empty() checks if there are children, but indeed it does... https://github.com/boostorg/property_tree/blob/2669458cebee100bc1f9f4a9d2f0cd95d07740bc/include/boost/property_tree/ptree.hpp#L107

set(key, value.get_value<std::string>(), 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);
}
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions Framework/test/testCustomParameters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "getTestDataDirectory.h"
#include "QualityControl/InfrastructureGenerator.h"

#include <iostream>
#include <catch_amalgamated.hpp>
#include <Configuration/ConfigurationFactory.h>
#include <DataSampling/DataSampling.h>

using namespace o2::quality_control::core;
using namespace std;
Expand Down Expand Up @@ -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<string>("name") == "mean_of_histogram");
CHECK(firstElement.get<string>("title") == "Mean trend of the example histogram");
CHECK(firstElement.get<string>("graphAxisLabel") == "Mean X:time");
CHECK(firstElement.get<string>("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<string>("name") == "mean_trend");
CHECK(firstGraph.get<string>("title") == "mean trend");
CHECK(firstGraph.get<string>("varexp") == "example.mean:time");
CHECK(firstGraph.get<string>("selection") == "");
CHECK(firstGraph.get<string>("option") == "*L PLC PMC");
}

TEST_CASE("test_default_if_not_found_at_optional")
Expand Down
19 changes: 18 additions & 1 deletion Framework/test/testWorkflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down