Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QC-1206] Make database available to user code + refactor *Config to extract common part #2459

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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: 2 additions & 7 deletions Framework/include/QualityControl/AggregatorConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,20 @@
#include <Framework/DataProcessorSpec.h>
#include "QualityControl/UpdatePolicyType.h"
#include "QualityControl/AggregatorSource.h"
#include "QualityControl/CustomParameters.h"
#include "QualityControl/UserCodeConfig.h"

namespace o2::quality_control::checker
{

/// \brief Container for the configuration of an Aggregator.
struct AggregatorConfig {
struct AggregatorConfig : public o2::quality_control::core::UserCodeConfig {
std::string name;
std::string moduleName;
std::string className;
std::string detectorName = "MISC"; // intended to be the 3 letters code;
core::CustomParameters customParameters;
UpdatePolicyType policyType = UpdatePolicyType::OnAny;
std::vector<std::string> objectNames{}; // fixme: if object names are empty, allObjects are true, consider reducing to one var // fixme: duplicates "sources"
bool allObjects = false;
framework::Inputs inputSpecs{};
framework::OutputSpec qoSpec{ "XXX", "INVALID" };
std::vector<AggregatorSource> sources;
std::string conditionUrl{};
};

} // namespace o2::quality_control::checker
Expand Down
5 changes: 0 additions & 5 deletions Framework/include/QualityControl/Check.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ class Check
static CheckConfig extractConfig(const core::CommonSpec&, const CheckSpec&);
static framework::OutputSpec createOutputSpec(const std::string& detector, const std::string& checkName);

void setDatabase(std::shared_ptr<o2::quality_control::repository::DatabaseInterface> database)
{
mCheckInterface->setDatabase(database);
}

private:
void beautify(std::map<std::string, std::shared_ptr<core::MonitorObject>>& moMap, const core::Quality& quality);

Expand Down
9 changes: 2 additions & 7 deletions Framework/include/QualityControl/CheckConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@

#include <Framework/DataProcessorSpec.h>
#include "QualityControl/UpdatePolicyType.h"
#include "QualityControl/CustomParameters.h"
#include "QualityControl/UserCodeConfig.h"

namespace o2::quality_control::checker
{

/// \brief Container for the configuration of a Check.
struct CheckConfig {
struct CheckConfig : public o2::quality_control::core::UserCodeConfig {
std::string name;
std::string moduleName;
std::string className;
std::string detectorName = "MISC"; // intended to be the 3 letters code;
core::CustomParameters customParameters;
UpdatePolicyType policyType = UpdatePolicyType::OnAny;
std::vector<std::string> objectNames{}; // fixme: if object names are empty, allObjects are true, consider reducing to one var
bool allObjects = false;
bool allowBeautify = false;
framework::Inputs inputSpecs{};
framework::OutputSpec qoSpec{ "XXX", "INVALID" };
std::string conditionUrl{};
};

} // namespace o2::quality_control::checker
Expand Down
8 changes: 0 additions & 8 deletions Framework/include/QualityControl/CheckInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ class CheckInterface : public core::UserCodeInterface
virtual void startOfActivity(const core::Activity& activity); // not fully abstract because we don't want to change all the existing subclasses
virtual void endOfActivity(const core::Activity& activity); // not fully abstract because we don't want to change all the existing subclasses

void setDatabase(std::shared_ptr<o2::quality_control::repository::DatabaseInterface> database)
{
mDatabase = database;
}

protected:
/// \brief Called each time mCustomParameters is updated.
virtual void configure() override;
Expand All @@ -100,9 +95,6 @@ class CheckInterface : public core::UserCodeInterface
/// \return
std::shared_ptr<MonitorObject> retrieveReference(std::string path, Activity referenceActivity);

private:
std::shared_ptr<o2::quality_control::repository::DatabaseInterface> mDatabase;

ClassDef(CheckInterface, 6)
};

Expand Down
12 changes: 2 additions & 10 deletions Framework/include/QualityControl/PostProcessingConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,32 @@
#ifndef QUALITYCONTROL_POSTPROCESSINGCONFIG_H
#define QUALITYCONTROL_POSTPROCESSINGCONFIG_H

#include "QualityControl/CustomParameters.h"

#include <vector>
#include <string>
#include <boost/property_tree/ptree_fwd.hpp>
#include "QualityControl/Activity.h"
#include "QualityControl/UserCodeConfig.h"

namespace o2::quality_control::postprocessing
{

// todo pretty print

/// \brief Post-processing configuration structure
struct PostProcessingConfig {
struct PostProcessingConfig : public o2::quality_control::core::UserCodeConfig {
PostProcessingConfig() = default;
PostProcessingConfig(const std::string& id, const boost::property_tree::ptree& config);
~PostProcessingConfig() = default;
std::string id;
std::string taskName;
std::string moduleName;
std::string className;
std::string detectorName = "MISC";
std::vector<std::string> initTriggers = {};
std::vector<std::string> updateTriggers = {};
std::vector<std::string> stopTriggers = {};
std::string qcdbUrl;
std::string ccdbUrl;
std::string consulUrl;
std::string kafkaBrokersUrl;
std::string kafkaTopic;
core::Activity activity;
bool matchAnyRunNumber = false;
bool critical;
core::CustomParameters customParameters;
};

} // namespace o2::quality_control::postprocessing
Expand Down
10 changes: 2 additions & 8 deletions Framework/include/QualityControl/TaskRunnerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <Framework/DataProcessorSpec.h>
#include "QualityControl/Activity.h"
#include "QualityControl/LogDiscardParameters.h"
#include "QualityControl/CustomParameters.h"
#include "QualityControl/UserCodeConfig.h"

namespace o2::base
{
Expand All @@ -40,23 +40,17 @@ namespace o2::quality_control::core
{

/// \brief Container for the configuration of a Task
struct TaskRunnerConfig {
struct TaskRunnerConfig : public UserCodeConfig {
std::string deviceName;
std::string taskName;
std::string moduleName;
std::string className;
std::vector<std::pair<size_t, size_t>> cycleDurations = {};
int maxNumberCycles;
bool critical;
std::string consulUrl{};
std::string conditionUrl{};
std::string monitoringUrl{};
std::string bookkeepingUrl{};
framework::Inputs inputSpecs{};
framework::OutputSpec moSpec{ "XXX", "INVALID" };
framework::Options options{};
CustomParameters customParameters;
std::string detectorName = "MISC"; // intended to be the 3 letters code
int parallelTaskID = 0; // ID to differentiate parallel local Tasks from one another. 0 means this is the only one.
std::string saveToFile{};
int resetAfterCycles = 0;
Expand Down
39 changes: 39 additions & 0 deletions Framework/include/QualityControl/UserCodeConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

///
/// \file UserCodeConfig.h
/// \author Barthelemy von Haller
///

#ifndef QUALITYCONTROL_USERCODECONFIG_H
#define QUALITYCONTROL_USERCODECONFIG_H

#include "QualityControl/CustomParameters.h"
#include "QualityControl/stringUtils.h"

namespace o2::quality_control::core
{

/// \brief Container for the configuration of a Task
struct UserCodeConfig {
std::string moduleName;
std::string className;
std::string detectorName = "MISC"; // intended to be the 3 letters code;
std::string consulUrl;
CustomParameters customParameters;
std::string conditionUrl{};
std::unordered_map<std::string, std::string> database;
};

} // namespace o2::quality_control::core

#endif // QUALITYCONTROL_USERCODECONFIG_H
5 changes: 4 additions & 1 deletion Framework/include/QualityControl/UserCodeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "QualityControl/ConditionAccess.h"
#include "QualityControl/CustomParameters.h"
#include "QualityControl/DatabaseInterface.h"

namespace o2::quality_control::core
{
Expand All @@ -48,12 +49,14 @@ class UserCodeInterface : public ConditionAccess

const std::string& getName() const;
void setName(const std::string& name);
void setDatabase(std::unordered_map<std::string, std::string> dbConfig);

protected:
CustomParameters mCustomParameters;
std::string mName;
std::shared_ptr<o2::quality_control::repository::DatabaseInterface> mDatabase;

ClassDef(UserCodeInterface, 3)
ClassDef(UserCodeInterface, 4)
};

} // namespace o2::quality_control::core
Expand Down
9 changes: 6 additions & 3 deletions Framework/src/Aggregator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void Aggregator::init()
mAggregatorInterface->setName(mAggregatorConfig.name);
mAggregatorInterface->setCustomParameters(mAggregatorConfig.customParameters);
mAggregatorInterface->setCcdbUrl(mAggregatorConfig.conditionUrl);
mAggregatorInterface->setDatabase(mAggregatorConfig.database);
mAggregatorInterface->configure();
} catch (...) {
std::string diagnostic = boost::current_exception_diagnostic_information();
Expand Down Expand Up @@ -217,18 +218,20 @@ AggregatorConfig Aggregator::extractConfig(const core::CommonSpec& commonSpec, c
}

return {
aggregatorSpec.aggregatorName,
aggregatorSpec.moduleName,
aggregatorSpec.className,
aggregatorSpec.detectorName,
commonSpec.consulUrl,
aggregatorSpec.customParameters,
commonSpec.conditionDBUrl,
commonSpec.database,
aggregatorSpec.aggregatorName,
updatePolicy,
std::move(objectNames),
checkAllObjects,
std::move(inputs),
createOutputSpec(aggregatorSpec.detectorName, aggregatorSpec.aggregatorName),
sources,
commonSpec.conditionDBUrl
sources
};
}

Expand Down
8 changes: 6 additions & 2 deletions Framework/src/Check.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "QualityControl/QcInfoLogger.h"
#include "QualityControl/Quality.h"
#include "QualityControl/HashDataDescription.h"
#include "QualityControl/runnerUtils.h"

#include <QualityControl/AggregatorRunner.h>

Expand Down Expand Up @@ -70,6 +71,7 @@ void Check::init()
try {
mCheckInterface = root_class_factory::create<CheckInterface>(mCheckConfig.moduleName, mCheckConfig.className);
mCheckInterface->setName(mCheckConfig.name);
mCheckInterface->setDatabase(mCheckConfig.database);
mCheckInterface->setCustomParameters(mCheckConfig.customParameters);
mCheckInterface->setCcdbUrl(mCheckConfig.conditionUrl);
} catch (...) {
Expand Down Expand Up @@ -250,18 +252,20 @@ CheckConfig Check::extractConfig(const CommonSpec& commonSpec, const CheckSpec&
}

return {
checkSpec.checkName,
checkSpec.moduleName,
checkSpec.className,
checkSpec.detectorName,
commonSpec.consulUrl,
checkSpec.customParameters,
commonSpec.conditionDBUrl,
commonSpec.database,
checkSpec.checkName,
updatePolicy,
std::move(objectNames),
checkAllObjects,
allowBeautify,
std::move(inputs),
createOutputSpec(checkSpec.detectorName, checkSpec.checkName),
commonSpec.conditionDBUrl
};
}

Expand Down
1 change: 0 additions & 1 deletion Framework/src/CheckRunner.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ void CheckRunner::init(framework::InitContext& iCtx)
updatePolicyManager.reset();
for (auto& [checkName, check] : mChecks) {
check.init();
check.setDatabase(mDatabase);
updatePolicyManager.addPolicy(check.getName(), check.getUpdatePolicyType(), check.getObjectsNames(), check.getAllObjectsOption(), false);
}
} catch (...) {
Expand Down
17 changes: 11 additions & 6 deletions Framework/src/PostProcessingConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ namespace o2::quality_control::postprocessing
PostProcessingConfig::PostProcessingConfig(const std::string& id, const boost::property_tree::ptree& config) //
: id(id),
taskName(config.get<std::string>("qc.postprocessing." + id + ".taskName", id)),
moduleName(config.get<std::string>("qc.postprocessing." + id + ".moduleName")),
className(config.get<std::string>("qc.postprocessing." + id + ".className")),
detectorName(config.get<std::string>("qc.postprocessing." + id + ".detectorName", "MISC")),
qcdbUrl(config.get<std::string>("qc.config.database.implementation") == "CCDB" ? config.get<std::string>("qc.config.database.host") : ""),
ccdbUrl(config.get<std::string>("qc.config.conditionDB.url", "")),
consulUrl(config.get<std::string>("qc.config.consul.url", "")),
activity(config.get<int>("qc.config.Activity.number", 0),
config.get<std::string>("qc.config.Activity.type", "NONE"),
config.get<std::string>("qc.config.Activity.periodName", ""),
Expand All @@ -40,6 +34,17 @@ PostProcessingConfig::PostProcessingConfig(const std::string& id, const boost::p
matchAnyRunNumber(config.get<bool>("qc.config.postprocessing.matchAnyRunNumber", false)),
critical(true)
{
moduleName = config.get<std::string>("qc.postprocessing." + id + ".moduleName");
className = config.get<std::string>("qc.postprocessing." + id + ".className");
detectorName = config.get<std::string>("qc.postprocessing." + id + ".detectorName", "MISC");
consulUrl = config.get<std::string>("qc.config.consul.url", "");
conditionUrl = config.get<std::string>("qc.config.conditionDB.url", "");
std::unordered_map<std::string, std::string> dbConfig{
{ "implementation", config.get<std::string>("qc.config.database.implementation") },
{ "host", config.get<std::string>("qc.config.database.host") }
};
database = dbConfig;

for (const auto& initTrigger : config.get_child("qc.postprocessing." + id + ".initTrigger")) {
initTriggers.push_back(initTrigger.second.get_value<std::string>());
}
Expand Down
1 change: 1 addition & 0 deletions Framework/src/PostProcessingFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PostProcessingInterface* PostProcessingFactory::create(const PostProcessingConfi
{
auto* result = root_class_factory::create<PostProcessingInterface>(config.moduleName, config.className);
result->setCustomParameters(config.customParameters);
result->setDatabase(config.database);
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion Framework/src/PostProcessingRunner.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void PostProcessingRunner::init(const PostProcessingRunnerConfig& runnerConfig,
mTask->setID(mTaskConfig.id);
mTask->setName(mTaskConfig.taskName);
mTask->setCustomParameters(mTaskConfig.customParameters);
mTask->setCcdbUrl(mTaskConfig.ccdbUrl);
mTask->setCcdbUrl(mTaskConfig.conditionUrl);
mTask->configure(mRunnerConfig.configTree);
} else {
throw std::runtime_error("Failed to create the task '" + mTaskConfig.taskName + "' (det " + mTaskConfig.detectorName + ")");
Expand Down
2 changes: 2 additions & 0 deletions Framework/src/TaskRunner.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "QualityControl/ActivityHelpers.h"
#include "QualityControl/WorkflowType.h"
#include "QualityControl/HashDataDescription.h"
#include "QualityControl/runnerUtils.h"

#include <string>
#include <TFile.h>
Expand Down Expand Up @@ -122,6 +123,7 @@ void TaskRunner::init(InitContext& iCtx)
mTask.reset(TaskFactory::create(mTaskConfig, mObjectsManager));
mTask->setMonitoring(mCollector);
mTask->setGlobalTrackingDataRequest(mTaskConfig.globalTrackingDataRequest);
mTask->setDatabase(mTaskConfig.database);

// load config params
if (!ConfigParamGlo::keyValues.empty()) {
Expand Down
Loading
Loading