Skip to content

Commit 650bc5d

Browse files
Barthelemyknopers8
andauthored
[QC-1020] Custom Parameters for Post-Processing (#2041)
* [QC-1020] CP for PP * format * remove cout * Update Framework/src/PostProcessingConfig.cxx Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch> * Update PostProcessingConfig.cxx * Extract the parsing of the config for the Custom Parameters * fix test * rename --------- Co-authored-by: Piotr Konopka <piotr.jan.konopka@cern.ch>
1 parent aac649a commit 650bc5d

14 files changed

+92
-27
lines changed

Framework/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ endforeach()
323323

324324
foreach(t testWorkflow testTaskRunner testCheckWorkflow
325325
testPostProcessingConfig testPostProcessingInterface
326-
testCheck testTrendingTask)
326+
testCheck testTrendingTask testCustomParameters)
327327
target_sources(${t} PRIVATE
328328
${CMAKE_BINARY_DIR}/getTestDataDirectory.cxx)
329329
target_include_directories(${t} PRIVATE ${CMAKE_SOURCE_DIR})

Framework/include/QualityControl/CustomParameters.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string>
2323
#include <unordered_map>
2424
#include <optional>
25+
#include <boost/property_tree/ptree_fwd.hpp>
2526

2627
namespace o2::quality_control::core
2728
{
@@ -167,6 +168,12 @@ class CustomParameters
167168
*/
168169
friend std::ostream& operator<<(std::ostream& out, const CustomParameters& customParameters);
169170

171+
/**
172+
* \brief Provided the config subtree of the custom parameters, load its content and populate this CustomParameters.
173+
* \param paramsTree The subtree corresponding to extendedTaskParameters, extendedCheckParameters, etc...
174+
*/
175+
void populateCustomParameters(const boost::property_tree::ptree& paramsTree);
176+
170177
private:
171178
CustomParametersType mCustomParameters;
172179
};

Framework/include/QualityControl/PostProcessingConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef QUALITYCONTROL_POSTPROCESSINGCONFIG_H
1818
#define QUALITYCONTROL_POSTPROCESSINGCONFIG_H
1919

20+
#include "QualityControl/CustomParameters.h"
21+
2022
#include <vector>
2123
#include <string>
2224
#include <boost/property_tree/ptree_fwd.hpp>
@@ -45,6 +47,7 @@ struct PostProcessingConfig {
4547
std::string consulUrl;
4648
core::Activity activity;
4749
bool matchAnyRunNumber = false;
50+
core::CustomParameters customParameters;
4851
};
4952

5053
} // namespace o2::quality_control::postprocessing

Framework/include/QualityControl/PostProcessingInterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef QUALITYCONTROL_POSTPROCESSINTERFACE_H
1818
#define QUALITYCONTROL_POSTPROCESSINTERFACE_H
1919

20+
#include "QualityControl/CustomParameters.h"
21+
2022
#include <string>
2123
#include <boost/property_tree/ptree_fwd.hpp>
2224
#include "QualityControl/Triggers.h"
@@ -65,6 +67,7 @@ class PostProcessingInterface
6567
/// \param services Interface containing optional interfaces, for example DatabaseInterface
6668
virtual void finalize(Trigger trigger, framework::ServiceRegistryRef services) = 0;
6769

70+
void setCustomParameters(const core::CustomParameters& parameters);
6871
void setObjectsManager(std::shared_ptr<core::ObjectsManager> objectsManager);
6972
void setID(const std::string& id);
7073
[[nodiscard]] const std::string& getID() const;
@@ -73,6 +76,7 @@ class PostProcessingInterface
7376

7477
protected:
7578
std::shared_ptr<core::ObjectsManager> getObjectsManager();
79+
core::CustomParameters mCustomParameters;
7680

7781
private:
7882
std::string mID;

Framework/include/QualityControl/PostProcessingTaskSpec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct PostProcessingTaskSpec {
4343
bool active = true;
4444
std::string detectorName = "Invalid";
4545
boost::property_tree::ptree tree = {};
46+
core::CustomParameters customParameters;
4647
};
4748

4849
} // namespace o2::quality_control::core

Framework/src/CustomParameters.cxx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "QualityControl/CustomParameters.h"
1313
#include <DataFormatsParameters/ECSDataAdapters.h>
1414
#include <iostream>
15+
#include <boost/property_tree/ptree.hpp>
1516
#include <string_view>
1617
#include <vector>
1718

@@ -33,7 +34,7 @@ std::ostream& operator<<(std::ostream& out, const CustomParameters& customParame
3334

3435
CustomParameters::CustomParameters()
3536
{
36-
mCustomParameters["default"]["default"] = {};
37+
mCustomParameters["null"]["null"] = {};
3738
}
3839

3940
void CustomParameters::set(const std::string& key, const std::string& value, const std::string& runType, const std::string& beamType)
@@ -154,7 +155,7 @@ std::unordered_map<std::string, std::string>::const_iterator CustomParameters::f
154155

155156
std::unordered_map<std::string, std::string>::const_iterator CustomParameters::end() const
156157
{
157-
return mCustomParameters.at("default").at("default").end();
158+
return mCustomParameters.at("null").at("null").end();
158159
}
159160

160161
std::string CustomParameters::operator[](const std::string& key) const
@@ -170,4 +171,15 @@ std::string& CustomParameters::operator[](const std::string& key)
170171
return mCustomParameters.at("default").at("default").at(key);
171172
}
172173

174+
void CustomParameters::populateCustomParameters(const boost::property_tree::ptree& tree)
175+
{
176+
for (const auto& [runtype, subTreeRunType] : tree) {
177+
for (const auto& [beamtype, subTreeBeamType] : subTreeRunType) {
178+
for (const auto& [key, value] : subTreeBeamType) {
179+
set(key, value.get_value<std::string>(), runtype, beamtype);
180+
}
181+
}
182+
}
183+
}
184+
173185
} // namespace o2::quality_control::core

Framework/src/InfrastructureSpecReader.cxx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,7 @@ TaskSpec InfrastructureSpecReader::readSpecEntry<TaskSpec>(const std::string& ta
117117
ILOG(Warning, Devel) << "Both taskParameters and extendedTaskParameters are defined in the QC config file. We will use only extendedTaskParameters. " << ENDM;
118118
}
119119
if (taskTree.count("extendedTaskParameters") > 0) {
120-
for (const auto& [runtype, subTreeRunType] : taskTree.get_child("extendedTaskParameters")) {
121-
for (const auto& [beamtype, subTreeBeamType] : subTreeRunType) {
122-
for (const auto& [key, value] : subTreeBeamType) {
123-
ts.customParameters.set(key, value.get_value<std::string>(), runtype, beamtype);
124-
}
125-
}
126-
}
120+
ts.customParameters.populateCustomParameters(taskTree.get_child("extendedTaskParameters"));
127121
} else if (taskTree.count("taskParameters") > 0) {
128122
for (const auto& [key, value] : taskTree.get_child("taskParameters")) {
129123
ts.customParameters.set(key, value.get_value<std::string>());
@@ -316,13 +310,7 @@ CheckSpec InfrastructureSpecReader::readSpecEntry<CheckSpec>(const std::string&
316310

317311
cs.active = checkTree.get<bool>("active", cs.active);
318312
if (checkTree.count("extendedCheckParameters") > 0) {
319-
for (const auto& [runtype, subTreeRunType] : checkTree.get_child("extendedCheckParameters")) {
320-
for (const auto& [beamtype, subTreeBeamType] : subTreeRunType) {
321-
for (const auto& [key, value] : subTreeBeamType) {
322-
cs.customParameters.set(key, value.get_value<std::string>(), runtype, beamtype);
323-
}
324-
}
325-
}
313+
cs.customParameters.populateCustomParameters(checkTree.get_child("extendedCheckParameters"));
326314
}
327315
if (checkTree.count("checkParameters") > 0) {
328316
for (const auto& [key, value] : checkTree.get_child("checkParameters")) {
@@ -356,13 +344,7 @@ AggregatorSpec InfrastructureSpecReader::readSpecEntry<AggregatorSpec>(const std
356344

357345
as.active = aggregatorTree.get<bool>("active", as.active);
358346
if (aggregatorTree.count("extendedAggregatorParameters") > 0) {
359-
for (const auto& [runtype, subTreeRunType] : aggregatorTree.get_child("extendedAggregatorParameters")) {
360-
for (const auto& [beamtype, subTreeBeamType] : subTreeRunType) {
361-
for (const auto& [key, value] : subTreeBeamType) {
362-
as.customParameters.set(key, value.get_value<std::string>(), runtype, beamtype);
363-
}
364-
}
365-
}
347+
as.customParameters.populateCustomParameters(aggregatorTree.get_child("extendedAggregatorParameters"));
366348
}
367349
if (aggregatorTree.count("aggregatorParameters") > 0) {
368350
for (const auto& [key, value] : aggregatorTree.get_child("aggregatorParameters")) {

Framework/src/PostProcessingConfig.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
///
1616

1717
#include "QualityControl/PostProcessingConfig.h"
18+
1819
#include <boost/property_tree/ptree.hpp>
1920

2021
namespace o2::quality_control::postprocessing
@@ -47,6 +48,10 @@ PostProcessingConfig::PostProcessingConfig(const std::string& id, const boost::p
4748
for (const auto& stopTrigger : config.get_child("qc.postprocessing." + id + ".stopTrigger")) {
4849
stopTriggers.push_back(stopTrigger.second.get_value<std::string>());
4950
}
51+
auto ppTree = config.get_child("qc.postprocessing." + id);
52+
if (ppTree.count("extendedTaskParameters")) {
53+
customParameters.populateCustomParameters(ppTree.get_child("extendedTaskParameters"));
54+
}
5055
}
5156

52-
} // namespace o2::quality_control::postprocessing
57+
} // namespace o2::quality_control::postprocessing

Framework/src/PostProcessingFactory.cxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ namespace o2::quality_control::postprocessing
2727
// todo: consider having a common helper for each class which loads tasks like below (QC tasks, checks, pp)
2828
PostProcessingInterface* PostProcessingFactory::create(const PostProcessingConfig& config)
2929
{
30-
return root_class_factory::create<PostProcessingInterface>(config.moduleName, config.className);
30+
auto* result = root_class_factory::create<PostProcessingInterface>(config.moduleName, config.className);
31+
result->setCustomParameters(config.customParameters);
32+
return result;
3133
}
3234

3335
} // namespace o2::quality_control::postprocessing

Framework/src/PostProcessingInterface.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ std::shared_ptr<core::ObjectsManager> PostProcessingInterface::getObjectsManager
5050
return mObjectsManager;
5151
}
5252

53+
void PostProcessingInterface::setCustomParameters(const core::CustomParameters& parameters)
54+
{
55+
mCustomParameters = parameters;
56+
}
57+
5358
} // namespace o2::quality_control::postprocessing

0 commit comments

Comments
 (0)