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
9 changes: 8 additions & 1 deletion Framework/include/QualityControl/Reductor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
#ifndef QUALITYCONTROL_REDUCTOR_H
#define QUALITYCONTROL_REDUCTOR_H

#include "CustomParameters.h"

namespace o2::quality_control::postprocessing
{

/// \brief An interface for storing columnar data into a TTree
class Reductor
{
protected:
core::CustomParameters mCustomParameters;

public:
/// \brief Constructor
Reductor() = default;
Expand All @@ -34,8 +39,10 @@ class Reductor
/// \brief Branch leaf list getter
/// \return A C string with a description of a branch format, formatted accordingly to the TTree interface
virtual const char* getBranchLeafList() = 0;
/// \brief setter for mCustomParameters
void setCustomConfig(const core::CustomParameters& parameters) { mCustomParameters = parameters; };
};

} // namespace o2::quality_control::postprocessing

#endif //QUALITYCONTROL_REDUCTOR_H
#endif // QUALITYCONTROL_REDUCTOR_H
2 changes: 2 additions & 0 deletions Framework/include/QualityControl/TrendingTaskConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <vector>
#include <string>
#include "CustomParameters.h"
#include "QualityControl/PostProcessingConfig.h"

namespace o2::quality_control::postprocessing
Expand Down Expand Up @@ -56,6 +57,7 @@ struct TrendingTaskConfig : PostProcessingConfig {
std::string path;
std::string name;
std::string reductorName;
core::CustomParameters reductorParameters;
std::string moduleName;
};

Expand Down
3 changes: 2 additions & 1 deletion Framework/src/TrendingTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void TrendingTask::configure(const boost::property_tree::ptree& config)
// configuration
mConfig = TrendingTaskConfig(getID(), config);
for (const auto& source : mConfig.dataSources) {
mReductors.emplace(source.name, root_class_factory::create<Reductor>(source.moduleName, source.reductorName));
auto&& [emplaced, _] = mReductors.emplace(source.name, root_class_factory::create<Reductor>(source.moduleName, source.reductorName));
emplaced->second->setCustomConfig(source.reductorParameters);
}
}

Expand Down
11 changes: 11 additions & 0 deletions Framework/src/TrendingTaskConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,23 @@ TrendingTaskConfig::TrendingTaskConfig(std::string id, const boost::property_tre
plotConfig.get<int>("colorPalette", 0),
graphs });
}

const auto extractReductorParams = [](const boost::property_tree::ptree& dataSourceConfig) -> core::CustomParameters {
core::CustomParameters result;
if (const auto reductorParams = dataSourceConfig.get_child_optional("reductorParameters"); reductorParams.has_value()) {
result.populateCustomParameters(reductorParams.value());
}
return result;
};

for (const auto& dataSourceConfig : config.get_child("qc.postprocessing." + id + ".dataSources")) {
if (const auto& sourceNames = dataSourceConfig.second.get_child_optional("names"); sourceNames.has_value()) {
for (const auto& sourceName : sourceNames.value()) {
dataSources.push_back({ dataSourceConfig.second.get<std::string>("type", "repository"),
dataSourceConfig.second.get<std::string>("path"),
sourceName.second.data(),
dataSourceConfig.second.get<std::string>("reductorName"),
extractReductorParams(dataSourceConfig.second),
dataSourceConfig.second.get<std::string>("moduleName") });
}
} else if (!dataSourceConfig.second.get<std::string>("name").empty()) {
Expand All @@ -73,6 +83,7 @@ TrendingTaskConfig::TrendingTaskConfig(std::string id, const boost::property_tre
dataSourceConfig.second.get<std::string>("path"),
dataSourceConfig.second.get<std::string>("name"),
dataSourceConfig.second.get<std::string>("reductorName"),
extractReductorParams(dataSourceConfig.second),
dataSourceConfig.second.get<std::string>("moduleName") });
} else {
throw std::runtime_error("No 'name' value or a 'names' vector in the path 'qc.postprocessing." + id + ".dataSources'");
Expand Down
30 changes: 29 additions & 1 deletion Framework/test/testReductor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/// \author Piotr Konopka
///

#include "QualityControl/CustomParameters.h"
#include "QualityControl/Reductor.h"
#include "QualityControl/ReductorTObject.h"
#include "QualityControl/ReductorConditionAny.h"
Expand All @@ -23,6 +24,7 @@
#include "QualityControl/ConditionAccess.h"
#include <TH1I.h>
#include <TTree.h>
#include <boost/test/tools/old/interface.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

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

unwanted header added automatically?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@justonedev1 please fix it when you are back.


#define BOOST_TEST_MODULE Reductor test
#define BOOST_TEST_MAIN
Expand Down Expand Up @@ -172,4 +174,30 @@ BOOST_AUTO_TEST_CASE(test_ReductorAnyInterface)
Double_t* integrals = tree->GetVal(0);

BOOST_CHECK_EQUAL(integrals[0], secret.Length());
}
}

BOOST_AUTO_TEST_CASE(test_ReductorConfigurable)
{
class ReductorTest : public Reductor
{
public:
std::string value{};

virtual void* getBranchAddress()
{
return nullptr;
}
virtual const char* getBranchLeafList()
{
value = mCustomParameters.at("key");
return value.c_str();
}
};

ReductorTest reductor;
CustomParameters params;
params.set("key", "value");
Reductor& r = reductor;
r.setCustomConfig(params);
BOOST_REQUIRE_EQUAL(r.getBranchLeafList(), "value");
}
41 changes: 41 additions & 0 deletions Framework/test/testTrendingTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/// \author Piotr Konopka
///

#include "Framework/include/QualityControl/Reductor.h"
#include "QualityControl/TrendingTask.h"
#include "QualityControl/DatabaseFactory.h"
#include "QualityControl/MonitorObject.h"
Expand Down Expand Up @@ -51,6 +52,25 @@ struct CleanupAtDestruction {
std::function<void()> mCallback = nullptr;
};

// https://stackoverflow.com/questions/424104/can-i-access-private-members-from-outside-the-class-without-using-friends
template <typename Accessor, typename Accessor::type Member>
struct DeclareGlobalGet {
friend typename Accessor::type get(Accessor) { return Member; }
};

struct TrendingTaskReductorAccessor {
using type = std::unordered_map<std::string, std::unique_ptr<Reductor>> TrendingTask::*;
friend type get(TrendingTaskReductorAccessor);
};

struct ReductorConfigAccessor {
using type = CustomParameters Reductor::*;
friend type get(ReductorConfigAccessor);
};

template struct DeclareGlobalGet<TrendingTaskReductorAccessor, &TrendingTask::mReductors>;
template struct DeclareGlobalGet<ReductorConfigAccessor, &Reductor::mCustomParameters>;

Comment on lines +55 to +73
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have to admit, I spent 2 hours trying to understand it and I did not manage. Not saying that the solution is bad though, but I need some learning.

TEST_CASE("test_trending_task")
{
const std::string pid = std::to_string(getpid());
Expand Down Expand Up @@ -88,6 +108,13 @@ TEST_CASE("test_trending_task")
taskName + R"json(",
"name": "testHistoTrending",
"reductorName": "o2::quality_control_modules::common::TH1Reductor",
"reductorParameters": {
"default": {
"default": {
"key":"value"
}
}
},
"moduleName": "QcCommon"
},
{
Expand Down Expand Up @@ -146,6 +173,20 @@ TEST_CASE("test_trending_task")
task.setObjectsManager(objectManager);
REQUIRE_NOTHROW(task.configure(config));

{
auto& reductors = task.*get(TrendingTaskReductorAccessor());
size_t foundCount{};
for (const auto& reductor : reductors) {
auto& config = (*reductor.second.get()).*get(ReductorConfigAccessor());
if (auto found = config.find("key"); found != config.end()) {
if (found->second == "value") {
foundCount++;
}
}
}
REQUIRE(foundCount == 1);
}

// test initialize()
REQUIRE_NOTHROW(task.initialize({ TriggerType::UserOrControl, true, { 0, "NONE", "", "", "qc" }, 1 }, services));
REQUIRE(objectManager->getNumberPublishedObjects() == 1);
Expand Down
Loading
Loading