Skip to content

Commit 5db8c28

Browse files
authored
[QC-1206] Make database available to user code + refactor *Config to extract common part (#2459)
* [QC-1206] Make the database available to the UserCodeInterface + refactor *Config to extract common part - needed for the CTP Scalers - it required adding the database param to all the *Config.h I decided to extract the common part to a new interface `UserCodeConfig`. # Conflicts: # Framework/src/PostProcessingConfig.cxx * Format * merge * format * fix the test * format
1 parent 9a7fe2f commit 5db8c28

22 files changed

+130
-80
lines changed

Framework/include/QualityControl/AggregatorConfig.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,20 @@
2424
#include <Framework/DataProcessorSpec.h>
2525
#include "QualityControl/UpdatePolicyType.h"
2626
#include "QualityControl/AggregatorSource.h"
27-
#include "QualityControl/CustomParameters.h"
27+
#include "QualityControl/UserCodeConfig.h"
2828

2929
namespace o2::quality_control::checker
3030
{
3131

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

4843
} // namespace o2::quality_control::checker

Framework/include/QualityControl/Check.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ class Check
9494
static CheckConfig extractConfig(const core::CommonSpec&, const CheckSpec&);
9595
static framework::OutputSpec createOutputSpec(const std::string& detector, const std::string& checkName);
9696

97-
void setDatabase(std::shared_ptr<o2::quality_control::repository::DatabaseInterface> database)
98-
{
99-
mCheckInterface->setDatabase(database);
100-
}
101-
10297
private:
10398
void beautify(std::map<std::string, std::shared_ptr<core::MonitorObject>>& moMap, const core::Quality& quality);
10499

Framework/include/QualityControl/CheckConfig.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,20 @@
2222

2323
#include <Framework/DataProcessorSpec.h>
2424
#include "QualityControl/UpdatePolicyType.h"
25-
#include "QualityControl/CustomParameters.h"
25+
#include "QualityControl/UserCodeConfig.h"
2626

2727
namespace o2::quality_control::checker
2828
{
2929

3030
/// \brief Container for the configuration of a Check.
31-
struct CheckConfig {
31+
struct CheckConfig : public o2::quality_control::core::UserCodeConfig {
3232
std::string name;
33-
std::string moduleName;
34-
std::string className;
35-
std::string detectorName = "MISC"; // intended to be the 3 letters code;
36-
core::CustomParameters customParameters;
3733
UpdatePolicyType policyType = UpdatePolicyType::OnAny;
3834
std::vector<std::string> objectNames{}; // fixme: if object names are empty, allObjects are true, consider reducing to one var
3935
bool allObjects = false;
4036
bool allowBeautify = false;
4137
framework::Inputs inputSpecs{};
4238
framework::OutputSpec qoSpec{ "XXX", "INVALID" };
43-
std::string conditionUrl{};
4439
};
4540

4641
} // namespace o2::quality_control::checker

Framework/include/QualityControl/CheckInterface.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ class CheckInterface : public core::UserCodeInterface
8383
virtual void startOfActivity(const core::Activity& activity); // not fully abstract because we don't want to change all the existing subclasses
8484
virtual void endOfActivity(const core::Activity& activity); // not fully abstract because we don't want to change all the existing subclasses
8585

86-
void setDatabase(std::shared_ptr<o2::quality_control::repository::DatabaseInterface> database)
87-
{
88-
mDatabase = database;
89-
}
90-
9186
protected:
9287
/// \brief Called each time mCustomParameters is updated.
9388
virtual void configure() override;
@@ -100,9 +95,6 @@ class CheckInterface : public core::UserCodeInterface
10095
/// \return
10196
std::shared_ptr<MonitorObject> retrieveReference(std::string path, Activity referenceActivity);
10297

103-
private:
104-
std::shared_ptr<o2::quality_control::repository::DatabaseInterface> mDatabase;
105-
10698
ClassDef(CheckInterface, 6)
10799
};
108100

Framework/include/QualityControl/PostProcessingConfig.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,32 @@
1717
#ifndef QUALITYCONTROL_POSTPROCESSINGCONFIG_H
1818
#define QUALITYCONTROL_POSTPROCESSINGCONFIG_H
1919

20-
#include "QualityControl/CustomParameters.h"
21-
2220
#include <vector>
2321
#include <string>
2422
#include <boost/property_tree/ptree_fwd.hpp>
2523
#include "QualityControl/Activity.h"
24+
#include "QualityControl/UserCodeConfig.h"
2625

2726
namespace o2::quality_control::postprocessing
2827
{
2928

3029
// todo pretty print
3130

3231
/// \brief Post-processing configuration structure
33-
struct PostProcessingConfig {
32+
struct PostProcessingConfig : public o2::quality_control::core::UserCodeConfig {
3433
PostProcessingConfig() = default;
3534
PostProcessingConfig(const std::string& id, const boost::property_tree::ptree& config);
3635
~PostProcessingConfig() = default;
3736
std::string id;
3837
std::string taskName;
39-
std::string moduleName;
40-
std::string className;
41-
std::string detectorName = "MISC";
4238
std::vector<std::string> initTriggers = {};
4339
std::vector<std::string> updateTriggers = {};
4440
std::vector<std::string> stopTriggers = {};
45-
std::string qcdbUrl;
46-
std::string ccdbUrl;
47-
std::string consulUrl;
4841
std::string kafkaBrokersUrl;
4942
std::string kafkaTopic;
5043
core::Activity activity;
5144
bool matchAnyRunNumber = false;
5245
bool critical;
53-
core::CustomParameters customParameters;
5446
};
5547

5648
} // namespace o2::quality_control::postprocessing

Framework/include/QualityControl/TaskRunnerConfig.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <Framework/DataProcessorSpec.h>
2525
#include "QualityControl/Activity.h"
2626
#include "QualityControl/LogDiscardParameters.h"
27-
#include "QualityControl/CustomParameters.h"
27+
#include "QualityControl/UserCodeConfig.h"
2828

2929
namespace o2::base
3030
{
@@ -40,23 +40,17 @@ namespace o2::quality_control::core
4040
{
4141

4242
/// \brief Container for the configuration of a Task
43-
struct TaskRunnerConfig {
43+
struct TaskRunnerConfig : public UserCodeConfig {
4444
std::string deviceName;
4545
std::string taskName;
46-
std::string moduleName;
47-
std::string className;
4846
std::vector<std::pair<size_t, size_t>> cycleDurations = {};
4947
int maxNumberCycles;
5048
bool critical;
51-
std::string consulUrl{};
52-
std::string conditionUrl{};
5349
std::string monitoringUrl{};
5450
std::string bookkeepingUrl{};
5551
framework::Inputs inputSpecs{};
5652
framework::OutputSpec moSpec{ "XXX", "INVALID" };
5753
framework::Options options{};
58-
CustomParameters customParameters;
59-
std::string detectorName = "MISC"; // intended to be the 3 letters code
6054
int parallelTaskID = 0; // ID to differentiate parallel local Tasks from one another. 0 means this is the only one.
6155
std::string saveToFile{};
6256
int resetAfterCycles = 0;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
///
13+
/// \file UserCodeConfig.h
14+
/// \author Barthelemy von Haller
15+
///
16+
17+
#ifndef QUALITYCONTROL_USERCODECONFIG_H
18+
#define QUALITYCONTROL_USERCODECONFIG_H
19+
20+
#include "QualityControl/CustomParameters.h"
21+
#include "QualityControl/stringUtils.h"
22+
23+
namespace o2::quality_control::core
24+
{
25+
26+
/// \brief Container for the configuration of a Task
27+
struct UserCodeConfig {
28+
std::string moduleName;
29+
std::string className;
30+
std::string detectorName = "MISC"; // intended to be the 3 letters code;
31+
std::string consulUrl;
32+
CustomParameters customParameters;
33+
std::string ccdbUrl;
34+
std::unordered_map<std::string, std::string> repository; // we need the full config of the database to build the database in the subclasses
35+
};
36+
37+
} // namespace o2::quality_control::core
38+
39+
#endif // QUALITYCONTROL_USERCODECONFIG_H

Framework/include/QualityControl/UserCodeInterface.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "QualityControl/ConditionAccess.h"
2525
#include "QualityControl/CustomParameters.h"
26+
#include "QualityControl/DatabaseInterface.h"
2627

2728
namespace o2::quality_control::core
2829
{
@@ -48,12 +49,14 @@ class UserCodeInterface : public ConditionAccess
4849

4950
const std::string& getName() const;
5051
void setName(const std::string& name);
52+
void setDatabase(std::unordered_map<std::string, std::string> dbConfig);
5153

5254
protected:
5355
CustomParameters mCustomParameters;
5456
std::string mName;
57+
std::shared_ptr<o2::quality_control::repository::DatabaseInterface> mDatabase;
5558

56-
ClassDef(UserCodeInterface, 3)
59+
ClassDef(UserCodeInterface, 4)
5760
};
5861

5962
} // namespace o2::quality_control::core

Framework/src/Aggregator.cxx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ void Aggregator::init()
5151
root_class_factory::create<AggregatorInterface>(mAggregatorConfig.moduleName, mAggregatorConfig.className);
5252
mAggregatorInterface->setName(mAggregatorConfig.name);
5353
mAggregatorInterface->setCustomParameters(mAggregatorConfig.customParameters);
54-
mAggregatorInterface->setCcdbUrl(mAggregatorConfig.conditionUrl);
54+
mAggregatorInterface->setCcdbUrl(mAggregatorConfig.ccdbUrl);
55+
mAggregatorInterface->setDatabase(mAggregatorConfig.repository);
5556
mAggregatorInterface->configure();
5657
} catch (...) {
5758
std::string diagnostic = boost::current_exception_diagnostic_information();
@@ -217,18 +218,20 @@ AggregatorConfig Aggregator::extractConfig(const core::CommonSpec& commonSpec, c
217218
}
218219

219220
return {
220-
aggregatorSpec.aggregatorName,
221221
aggregatorSpec.moduleName,
222222
aggregatorSpec.className,
223223
aggregatorSpec.detectorName,
224+
commonSpec.consulUrl,
224225
aggregatorSpec.customParameters,
226+
commonSpec.conditionDBUrl,
227+
commonSpec.database,
228+
aggregatorSpec.aggregatorName,
225229
updatePolicy,
226230
std::move(objectNames),
227231
checkAllObjects,
228232
std::move(inputs),
229233
createOutputSpec(aggregatorSpec.detectorName, aggregatorSpec.aggregatorName),
230-
sources,
231-
commonSpec.conditionDBUrl
234+
sources
232235
};
233236
}
234237

Framework/src/Check.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "QualityControl/QcInfoLogger.h"
2929
#include "QualityControl/Quality.h"
3030
#include "QualityControl/HashDataDescription.h"
31+
#include "QualityControl/runnerUtils.h"
3132

3233
#include <QualityControl/AggregatorRunner.h>
3334

@@ -70,8 +71,9 @@ void Check::init()
7071
try {
7172
mCheckInterface = root_class_factory::create<CheckInterface>(mCheckConfig.moduleName, mCheckConfig.className);
7273
mCheckInterface->setName(mCheckConfig.name);
74+
mCheckInterface->setDatabase(mCheckConfig.repository);
7375
mCheckInterface->setCustomParameters(mCheckConfig.customParameters);
74-
mCheckInterface->setCcdbUrl(mCheckConfig.conditionUrl);
76+
mCheckInterface->setCcdbUrl(mCheckConfig.ccdbUrl);
7577
} catch (...) {
7678
std::string diagnostic = boost::current_exception_diagnostic_information();
7779
ILOG(Fatal, Ops) << "Unexpected exception, diagnostic information follows: "
@@ -250,18 +252,20 @@ CheckConfig Check::extractConfig(const CommonSpec& commonSpec, const CheckSpec&
250252
}
251253

252254
return {
253-
checkSpec.checkName,
254255
checkSpec.moduleName,
255256
checkSpec.className,
256257
checkSpec.detectorName,
258+
commonSpec.consulUrl,
257259
checkSpec.customParameters,
260+
commonSpec.conditionDBUrl,
261+
commonSpec.database,
262+
checkSpec.checkName,
258263
updatePolicy,
259264
std::move(objectNames),
260265
checkAllObjects,
261266
allowBeautify,
262267
std::move(inputs),
263268
createOutputSpec(checkSpec.detectorName, checkSpec.checkName),
264-
commonSpec.conditionDBUrl
265269
};
266270
}
267271

0 commit comments

Comments
 (0)