Skip to content

Commit f80a9a8

Browse files
knopers8Barthelemy
authored andcommitted
[QC-156] Access to conditions in CCDB inside Tasks (#224)
1 parent 86a002d commit f80a9a8

15 files changed

Lines changed: 110 additions & 2 deletions

File tree

Framework/advanced.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
"consul": {
1919
"url": "http://consul-test.cern.ch:8500"
20+
},
21+
"conditionDB": {
22+
"url": "ccdb-test.cern.ch:8080"
2023
}
2124
},
2225
"tasks": {

Framework/basic-no-sampling.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
"consul": {
1919
"url": "http://consul-test.cern.ch:8500"
20+
},
21+
"conditionDB": {
22+
"url": "ccdb-test.cern.ch:8080"
2023
}
2124
},
2225
"tasks": {

Framework/basic.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
"consul": {
1919
"url": "http://consul-test.cern.ch:8500"
20+
},
21+
"conditionDB": {
22+
"url": "ccdb-test.cern.ch:8080"
2023
}
2124
},
2225
"tasks": {
@@ -43,7 +46,7 @@
4346
"id": "tst-raw",
4447
"active": "true",
4548
"machines": [],
46-
"query" : "random:TST/RAWDATA/0",
49+
"query": "random:TST/RAWDATA/0",
4750
"samplingConditions": [
4851
{
4952
"condition": "random",

Framework/example-default.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
"consul": {
1919
"url": "http://consul-test.cern.ch:8500"
20+
},
21+
"conditionDB": {
22+
"url": "ccdb-test.cern.ch:8080"
2023
}
2124
},
2225
"tasks": {

Framework/include/QualityControl/TaskConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct TaskConfig {
3030
int cycleDurationSeconds;
3131
int maxNumberCycles;
3232
std::string consulUrl;
33+
std::string conditionUrl = "";
3334
std::unordered_map<std::string, std::string> customParameters = {};
3435
};
3536

Framework/include/QualityControl/TaskInterface.h

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

20+
#include <map>
2021
#include <memory>
2122
#include <string>
2223
#include <unordered_map>
@@ -27,6 +28,13 @@
2728
#include "QualityControl/Activity.h"
2829
#include "QualityControl/ObjectsManager.h"
2930

31+
namespace o2::ccdb
32+
{
33+
class CcdbApi;
34+
}
35+
36+
class TObject;
37+
3038
namespace o2::quality_control::core
3139
{
3240

@@ -62,6 +70,8 @@ class TaskInterface
6270
/// Move assignment operator
6371
TaskInterface& operator=(TaskInterface&& other) /* noexcept */ = default; // error with gcc if noexcept
6472

73+
virtual void loadCcdb(std::string url) final;
74+
6575
// Definition of the methods for the template method pattern
6676
virtual void initialize(o2::framework::InitContext& ctx) = 0;
6777
virtual void startOfActivity(Activity& activity) = 0;
@@ -79,12 +89,15 @@ class TaskInterface
7989

8090
protected:
8191
std::shared_ptr<ObjectsManager> getObjectsManager();
92+
TObject* retrieveCondition(std::string path, std::map<std::string, std::string> metadata = {}, long timestamp = -1);
93+
8294
std::unordered_map<std::string, std::string> mCustomParameters;
8395

8496
private:
8597
// TODO should we rather have a global/singleton for the objectsManager ?
8698
std::shared_ptr<ObjectsManager> mObjectsManager;
8799
std::string mName;
100+
std::shared_ptr<o2::ccdb::CcdbApi> mCcdbApi;
88101
};
89102

90103
} // namespace o2::quality_control::core

Framework/readout-no-sampling.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
"consul": {
1919
"url": "http://consul-test.cern.ch:8500"
20+
},
21+
"conditionDB": {
22+
"url": "ccdb-test.cern.ch:8080"
2023
}
2124
},
2225
"tasks": {

Framework/readout.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
"consul": {
1919
"url": "http://consul-test.cern.ch:8500"
20+
},
21+
"conditionDB": {
22+
"url": "ccdb-test.cern.ch:8080"
2023
}
2124
},
2225
"tasks": {

Framework/src/TaskInterface.cxx

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

1717
#include "QualityControl/TaskInterface.h"
18+
#include <CCDB/CcdbApi.h>
19+
20+
using namespace o2::ccdb;
1821

1922
namespace o2::quality_control::core
2023
{
2124

22-
TaskInterface::TaskInterface(ObjectsManager* objectsManager) : mObjectsManager(objectsManager) {}
25+
TaskInterface::TaskInterface(ObjectsManager* objectsManager) : mObjectsManager(objectsManager)
26+
{
27+
}
2328

2429
const std::string& TaskInterface::getName() const { return mName; }
2530

@@ -30,11 +35,33 @@ void TaskInterface::setObjectsManager(std::shared_ptr<ObjectsManager> objectsMan
3035
mObjectsManager = objectsManager;
3136
}
3237

38+
void TaskInterface::loadCcdb(std::string url)
39+
{
40+
if (!mCcdbApi) {
41+
mCcdbApi = std::make_shared<CcdbApi>();
42+
}
43+
44+
mCcdbApi->init(url);
45+
if (!mCcdbApi->isHostReachable()) {
46+
LOG(WARN) << "CCDB at URL '" << url << "' is not reachable.";
47+
}
48+
}
49+
3350
void TaskInterface::setCustomParameters(const std::unordered_map<std::string, std::string>& parameters)
3451
{
3552
mCustomParameters = parameters;
3653
}
3754

55+
TObject* TaskInterface::retrieveCondition(std::string path, std::map<std::string, std::string> metadata, long timestamp)
56+
{
57+
if (mCcdbApi) {
58+
return mCcdbApi->retrieve(path, metadata, timestamp);
59+
} else {
60+
LOG(ERROR) << "Trying to retrieve a condition, but CCDB API is not constructed.";
61+
return nullptr;
62+
}
63+
}
64+
3865
std::shared_ptr<ObjectsManager> TaskInterface::getObjectsManager() { return mObjectsManager; }
3966

4067
} // namespace o2::quality_control::core

Framework/src/TaskRunner.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void TaskRunner::init(InitContext& iCtx)
7979
mTask.reset(f.create(mTaskConfig, mObjectsManager));
8080

8181
// init user's task
82+
mTask->loadCcdb(mTaskConfig.conditionUrl);
8283
mTask->initialize(iCtx);
8384
}
8485

@@ -253,6 +254,7 @@ void TaskRunner::populateConfig(std::string taskName)
253254
mTaskConfig.cycleDurationSeconds = taskConfigTree->second.get<int>("cycleDurationSeconds", 10);
254255
mTaskConfig.maxNumberCycles = taskConfigTree->second.get<int>("maxNumberCycles", -1);
255256
mTaskConfig.consulUrl = mConfigFile->get<std::string>("qc.config.consul.url", "http://consul-test.cern.ch:8500");
257+
mTaskConfig.conditionUrl = mConfigFile->get<std::string>("qc.config.conditionDB.url", "http://ccdb-test.cern.ch:8080");
256258
try {
257259
mTaskConfig.customParameters = mConfigFile->getRecursiveMap("qc.tasks." + taskName + ".taskParameters");
258260
} catch (...) {

0 commit comments

Comments
 (0)