Skip to content
Open
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
26 changes: 22 additions & 4 deletions Framework/include/QualityControl/CcdbDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <boost/property_tree/ptree_fwd.hpp>
#include <memory>
#include <string>
#include <utility>

namespace o2::ccdb
{
Expand Down Expand Up @@ -75,13 +76,14 @@ class CcdbDatabase : public DatabaseInterface
std::map<std::string, std::string>* headers = nullptr,
const std::string& createdNotAfter = "", const std::string& createdNotBefore = "") override;

// retrieval - MO - deprecated
std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath, std::string objectName,
// retrieval - MO
std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath,
long timestamp = Timestamp::Current,
const core::Activity& activity = {},
const std::map<std::string, std::string>& metadata = {}) override;
// retrieval - QO - deprecated
std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string qoPath, long timestamp = Timestamp::Current,
// retrieval - QO
std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string qoPath,
long timestamp = Timestamp::Current,
const core::Activity& activity = {},
const std::map<std::string, std::string>& metadata = {}) override;

Expand Down Expand Up @@ -163,6 +165,22 @@ class CcdbDatabase : public DatabaseInterface
*/
static void addFrameworkMetadata(std::map<std::string, std::string>& fullMetadata, std::string detectorName, std::string className);

/**
* Retrieve a QC object (MO or QO payload) given its path without the provenance prefix.
* The provenance prefix is taken from the activity, and the activity is converted into metadata filters
* and merged with the additional metadata.
* @param pathWithoutProvenance the path of the object, without the provenance prefix
* @param timestamp the timestamp to query the object
* @param activity activity used to build the full path and the metadata filters
* @param extraMetadata additional metadata to filter objects during retrieval
* @param headers populated with the headers received from the database
* @return the full path of the object (with provenance) and the retrieved object, or nullptr if not found
*/
std::pair<std::string, TObject*> retrieveQcObject(const std::string& pathWithoutProvenance, long timestamp,
const core::Activity& activity,
const std::map<std::string, std::string>& extraMetadata,
std::map<std::string, std::string>& headers);

std::unique_ptr<o2::ccdb::CcdbApi> ccdbApi;
std::string mUrl;
size_t mMaxObjectSize = 2097152; // 2MB by default
Expand Down
7 changes: 2 additions & 5 deletions Framework/include/QualityControl/DatabaseInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,12 @@ class DatabaseInterface
/**
* \brief Look up a monitor object and return it.
* Look up a monitor object and return it if found or nullptr if not.
* @param objectPath Path to the object without the provenance prefix
* @param objectName Name of the object
* @param objectPath Full path to the object (including the object name) without the provenance prefix
* @param timestamp Timestamp of the object in ms since epoch
* @param activity Activity of the object
* @param metadata additional metadata to filter objects during retrieval
* @deprecated
*/
virtual std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath, std::string objectName,
virtual std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath,
long timestamp = Timestamp::Current, const core::Activity& activity = {},
const std::map<std::string, std::string>& metadata = {}) = 0;
/**
Expand All @@ -146,7 +144,6 @@ class DatabaseInterface
* @param timestamp Timestamp of the object in ms since epoch
* @param activity Activity of the object
* @param metadata additional metadata to filter objects during retrieval
* @deprecated
*/
virtual std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string qoPath, long timestamp = Timestamp::Current,
const core::Activity& activity = {},
Expand Down
2 changes: 1 addition & 1 deletion Framework/include/QualityControl/DummyDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DummyDatabase : public DatabaseInterface
std::string const& detectorName, std::string const& taskName, long from = -1, long to = -1) override;
// MonitorObject
void storeMO(std::shared_ptr<const o2::quality_control::core::MonitorObject> q) override;
std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string taskName, std::string objectName, long timestamp = -1, const core::Activity& activity = {}, const std::map<std::string, std::string>& metadata = {}) override;
std::shared_ptr<o2::quality_control::core::MonitorObject> retrieveMO(std::string objectPath, long timestamp = -1, const core::Activity& activity = {}, const std::map<std::string, std::string>& metadata = {}) override;
// QualityObject
void storeQO(std::shared_ptr<const o2::quality_control::core::QualityObject> q) override;
std::shared_ptr<o2::quality_control::core::QualityObject> retrieveQO(std::string checkerName, long timestamp = -1, const core::Activity& activity = {}, const std::map<std::string, std::string>& metadata = {}) override;
Expand Down
5 changes: 2 additions & 3 deletions Framework/include/QualityControl/ReferenceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ namespace o2::quality_control::checker
static std::shared_ptr<quality_control::core::MonitorObject> getReferencePlot(quality_control::repository::DatabaseInterface* qcdb, std::string& fullPath,
core::Activity referenceActivity)
{
auto [success, path, name] = o2::quality_control::core::RepoPathUtils::splitObjectPath(fullPath);
if (!success) {
if (fullPath.find('/') == std::string::npos) {
return nullptr;
}
return qcdb->retrieveMO(path, name, repository::DatabaseInterface::Timestamp::Latest, referenceActivity);
return qcdb->retrieveMO(fullPath, repository::DatabaseInterface::Timestamp::Latest, referenceActivity);
}

//_________________________________________________________________________________________
Expand Down
32 changes: 18 additions & 14 deletions Framework/src/CcdbDatabase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,28 @@ void* CcdbDatabase::retrieveAny(const type_info& tinfo, const string& path, cons
return object;
}

std::shared_ptr<o2::quality_control::core::MonitorObject> CcdbDatabase::retrieveMO(std::string objectPath, std::string objectName,
long timestamp, const core::Activity& activity,
const std::map<std::string, std::string>& metadataToRetrieve)
std::pair<std::string, TObject*> CcdbDatabase::retrieveQcObject(const std::string& pathWithoutProvenance, long timestamp,
const core::Activity& activity,
const std::map<std::string, std::string>& extraMetadata,
std::map<std::string, std::string>& headers)
{
string fullPath = activity.mProvenance + "/" + objectPath + "/" + objectName;
map<string, string> headers;
string fullPath = activity.mProvenance + "/" + pathWithoutProvenance;
map<string, string> metadata = activity_helpers::asDatabaseMetadata(activity, false);
metadata.insert(metadataToRetrieve.begin(), metadataToRetrieve.end());
metadata.insert(extraMetadata.begin(), extraMetadata.end());
TObject* obj = retrieveTObject(fullPath, metadata, timestamp, &headers);
if (obj == nullptr && headers.count("Error") > 0) {
ILOG(Error, Support) << headers["Error"] << ENDM;
}
return { fullPath, obj };
}

// no object found
std::shared_ptr<o2::quality_control::core::MonitorObject> CcdbDatabase::retrieveMO(std::string objectPath,
long timestamp, const core::Activity& activity,
const std::map<std::string, std::string>& metadataToRetrieve)
{
map<string, string> headers;
auto [fullPath, obj] = retrieveQcObject(objectPath, timestamp, activity, metadataToRetrieve, headers);
if (obj == nullptr) {
if (headers.count("Error") > 0) {
ILOG(Error, Support) << headers["Error"] << ENDM;
}
return nullptr;
}

Expand Down Expand Up @@ -360,10 +367,7 @@ std::shared_ptr<o2::quality_control::core::QualityObject> CcdbDatabase::retrieve
const std::map<std::string, std::string>& metadataToRetrieve)
{
map<string, string> headers;
map<string, string> metadata = activity_helpers::asDatabaseMetadata(activity, false);
metadata.insert(metadataToRetrieve.begin(), metadataToRetrieve.end());
auto fullPath = activity.mProvenance + "/" + qoPath;
TObject* obj = retrieveTObject(fullPath, metadata, timestamp, &headers);
auto [fullPath, obj] = retrieveQcObject(qoPath, timestamp, activity, metadataToRetrieve, headers);
if (obj == nullptr) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion Framework/src/DummyDatabase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void DummyDatabase::storeMO(std::shared_ptr<const o2::quality_control::core::Mon
{
}

std::shared_ptr<o2::quality_control::core::MonitorObject> DummyDatabase::retrieveMO(std::string, std::string, long, const core::Activity& activity, const std::map<std::string, std::string>&)
std::shared_ptr<o2::quality_control::core::MonitorObject> DummyDatabase::retrieveMO(std::string, long, const core::Activity& activity, const std::map<std::string, std::string>&)
{
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion Framework/src/ReductorHelpers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool updateReductorImpl(Reductor* r, const Trigger& t, const std::string& path,
}

if (type == "repository") {
auto mo = qcdb.retrieveMO(path, name, t.timestamp, t.activity, t.metadata);
auto mo = qcdb.retrieveMO(path + "/" + name, t.timestamp, t.activity, t.metadata);
TObject* obj = mo ? mo->getObject() : nullptr;
auto reductorTObject = dynamic_cast<ReductorTObject*>(r);
if (obj && reductorTObject) {
Expand Down
4 changes: 2 additions & 2 deletions Framework/src/SliceTrendingTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void SliceTrendingTask::initialize(Trigger t, framework::ServiceRegistryRef serv
ILOG(Info, Support) << "Trying to retrieve an existing TTree for this task to continue the trend." << ENDM;
auto& qcdb = services.get<repository::DatabaseInterface>();
auto path = RepoPathUtils::getMoPath(mConfig.detectorName, PostProcessingInterface::getName(), "", "", false);
auto mo = qcdb.retrieveMO(path, PostProcessingInterface::getName(), repository::DatabaseInterface::Timestamp::Latest);
auto mo = qcdb.retrieveMO(path + "/" + PostProcessingInterface::getName(), repository::DatabaseInterface::Timestamp::Latest);
if (mo && mo->getObject()) {
auto tree = dynamic_cast<TTree*>(mo->getObject());
if (tree) {
Expand Down Expand Up @@ -225,7 +225,7 @@ void SliceTrendingTask::trendValues(const Trigger& t,
mNumberPads[dataSource.name] = 0;
mSources[dataSource.name]->clear();
if (dataSource.type == "repository") {
auto mo = qcdb.retrieveMO(dataSource.path, dataSource.name, t.timestamp, t.activity, t.metadata);
auto mo = qcdb.retrieveMO(dataSource.path + "/" + dataSource.name, t.timestamp, t.activity, t.metadata);
TObject* obj = mo ? mo->getObject() : nullptr;

mAxisDivision[dataSource.name] = dataSource.axisDivision;
Expand Down
2 changes: 1 addition & 1 deletion Framework/src/TrendingTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void TrendingTask::initializeTrend(o2::quality_control::repository::DatabaseInte
if (mConfig.resumeTrend) {
ILOG(Info, Support) << "Trying to retrieve an existing TTree for this task to continue the trend." << ENDM;
auto path = RepoPathUtils::getMoPath(mConfig.detectorName, PostProcessingInterface::getName(), "", "", false);
auto mo = qcdb.retrieveMO(path, PostProcessingInterface::getName(), repository::DatabaseInterface::Timestamp::Latest);
auto mo = qcdb.retrieveMO(path + "/" + PostProcessingInterface::getName(), repository::DatabaseInterface::Timestamp::Latest);
if (mo && mo->getObject()) {
auto tree = dynamic_cast<TTree*>(mo->getObject());
if (tree) {
Expand Down
19 changes: 9 additions & 10 deletions Framework/test/testCcdbDatabase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ TEST_CASE("ccdb_store_for_future_tests", "[ccdb]")
TEST_CASE("ccdb_retrieve_mo", "[ccdb]")
{
test_fixture f;
std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO(f.getMoFolder("quarantine"), "quarantine");
std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO(f.getMoPath("quarantine", "", false));
REQUIRE(mo != nullptr);
CHECK(mo->getName() == "quarantine");
CHECK(mo->getActivity().mId == 1234);
Expand All @@ -229,7 +229,7 @@ TEST_CASE("ccdb_retrieve_timestamps", "[ccdb]")
{
test_fixture f;

std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO(f.getMoFolder("short"), "short", 15000);
std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO(f.getMoPath("short", "", false), 15000);
REQUIRE(mo != nullptr);
CHECK(mo->getName() == "short");

Expand All @@ -246,21 +246,21 @@ TEST_CASE("ccdb_retrieve_inexisting_mo", "[ccdb]")
{
test_fixture f;

std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO("non/existing", "object");
std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO("non/existing/object");
CHECK(mo == nullptr);
}

TEST_CASE("ccdb_retrieve_mo_with_cycle", "[ccdb]")
{
test_fixture f;
std::shared_ptr<MonitorObject> mo{};
mo = f.backend->retrieveMO(f.getMoFolder("cycle"), "cycle",
mo = f.backend->retrieveMO(f.getMoPath("cycle", "", false),
15000, Activity{}, { { metadata_keys::cycleNumber, "1" } });
REQUIRE(mo.get() != nullptr);
REQUIRE_NOTHROW(mo->getMetadata(metadata_keys::cycleNumber));
REQUIRE(mo->getMetadata(metadata_keys::cycleNumber) == "1");

mo = f.backend->retrieveMO(f.getMoFolder("cycle"), "cycle",
mo = f.backend->retrieveMO(f.getMoPath("cycle", "", false),
15000, Activity{}, { { metadata_keys::cycleNumber, "2" } });
REQUIRE(mo.get() != nullptr);
REQUIRE_NOTHROW(mo->getMetadata(metadata_keys::cycleNumber));
Expand Down Expand Up @@ -295,7 +295,7 @@ TEST_CASE("ccdb_provenance", "[ccdb]")
REQUIRE(qo != nullptr);
CHECK(qo->getActivity().mProvenance == "qc_hello");

std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO(f.getMoFolder("provenance"), "provenance", -1, { 0, "NONE", "", "", "qc_hello" });
std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO(f.getMoPath("provenance", "", false), -1, { 0, "NONE", "", "", "qc_hello" });
REQUIRE(mo != nullptr);
CHECK(mo->getActivity().mProvenance == "qc_hello");
}
Expand Down Expand Up @@ -423,9 +423,8 @@ TEST_CASE("ccdb_metadata", "[ccdb]")
CHECK(headers2.count("my_meta") == 1);
CHECK(headers2.at("my_meta") == "is_good");

// get the path without the objectName because of the interface retrieveMO
auto obj1a = f.backend->retrieveMO(f.getMoFolder("quarantine"), "quarantine");
auto obj2a = f.backend->retrieveMO(f.getQoFolder(""), "metadata");
auto obj1a = f.backend->retrieveMO(f.getMoPath("quarantine", "", false));
auto obj2a = f.backend->retrieveMO(f.getQoFolder("") + "/metadata");
REQUIRE(obj1a != nullptr);
REQUIRE(obj2a != nullptr);
CHECK(obj1a->getMetadataMap().size() > 0);
Expand Down Expand Up @@ -485,7 +484,7 @@ TEST_CASE("ccdb_store_retrieve_latest", "[ccdb]")
mo1->setValidity({ 10, 30 });
f.backend->storeMO(mo1);

std::shared_ptr<MonitorObject> moBack = f.backend->retrieveMO(f.getMoFolder("latest_test"), "latest_test", DatabaseInterface::Timestamp::Latest, { 1234, "NONE", "LHC66", "passName1", "qc" });
std::shared_ptr<MonitorObject> moBack = f.backend->retrieveMO(f.getMoPath("latest_test", "", false), DatabaseInterface::Timestamp::Latest, { 1234, "NONE", "LHC66", "passName1", "qc" });
REQUIRE(moBack != nullptr);
auto h1Back = dynamic_cast<TH1F*>(moBack->getObject());
REQUIRE(h1Back != nullptr);
Expand Down
8 changes: 4 additions & 4 deletions Framework/test/testCcdbDatabaseExtra.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TEST_CASE("ccdb_retrieve_all", "[ccdb][.manual]")
test_fixture f;
for (auto const& [task, object] : Objects) {
ILOG(Info, Support) << "[RETRIEVE]: " << task << object << ENDM;
auto mo = f.backend->retrieveMO(task, object);
auto mo = f.backend->retrieveMO(task + "/" + object);
if (mo == nullptr) {
ILOG(Info, Support) << "No object found (" << task << object << ")" << ENDM;
continue;
Expand Down Expand Up @@ -106,21 +106,21 @@ TEST_CASE("ccdb_retrieve_former_versions", "[ccdb][.manual]")
f.backend->storeMO(mo1);

// Retrieve old object stored at timestampStorage
std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO("TST/MO/my/task", "asdf/asdf", oldTimestamp);
std::shared_ptr<MonitorObject> mo = f.backend->retrieveMO("TST/MO/my/task/asdf/asdf", oldTimestamp);
CHECK(mo);
TH1F* old = dynamic_cast<TH1F*>(mo->getObject());
CHECK(old != nullptr);
CHECK(old->GetEntries() == 10000);

// Retrieve latest object with timestamp
std::shared_ptr<MonitorObject> mo2 = f.backend->retrieveMO("TST/MO/my/task", "asdf/asdf", CcdbDatabase::getCurrentTimestamp());
std::shared_ptr<MonitorObject> mo2 = f.backend->retrieveMO("TST/MO/my/task/asdf/asdf", CcdbDatabase::getCurrentTimestamp());
CHECK(mo2);
TH1F* latest = dynamic_cast<TH1F*>(mo2->getObject());
CHECK(latest != nullptr);
CHECK(latest->GetEntries() == 10001);

// Retrieve latest object without timetsamp
std::shared_ptr<MonitorObject> mo3 = f.backend->retrieveMO("TST/MO/my/task", "asdf/asdf");
std::shared_ptr<MonitorObject> mo3 = f.backend->retrieveMO("TST/MO/my/task/asdf/asdf");
CHECK(mo3);
TH1F* latest2 = dynamic_cast<TH1F*>(mo3->getObject());
CHECK(latest2 != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion Modules/CTP/src/CTPTrendingTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void CTPTrendingTask::trendValues(const Trigger& t, repository::DatabaseInterfac
bool inputMissing = false;

for (auto& dataSource : mConfig.dataSources) {
auto mo = qcdb.retrieveMO(dataSource.path, dataSource.name, t.timestamp, t.activity);
auto mo = qcdb.retrieveMO(dataSource.path + "/" + dataSource.name, t.timestamp, t.activity);
if (!mo) {
ILOG(Info, Support) << "no MO object" << ENDM;
continue;
Expand Down
5 changes: 2 additions & 3 deletions Modules/Common/src/ReferenceComparatorTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ static std::pair<std::shared_ptr<MonitorObject>, bool> getMO(repository::Databas
return { nullptr, false };
}

auto [success, path, name] = o2::quality_control::core::RepoPathUtils::splitObjectPath(fullPath);
if (!success) {
if (fullPath.find('/') == std::string::npos) {
return { nullptr, false };
}
// retrieve QO from CCDB - do not associate to trigger activity if ignoreActivity is true
auto qo = qcdb.retrieveMO(path, name, objectTimestamp, trigger.activity);
auto qo = qcdb.retrieveMO(fullPath, objectTimestamp, trigger.activity);
if (!qo) {
return { nullptr, false };
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/EMCAL/src/BCVisualization.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void BCVisualization::update(Trigger t, framework::ServiceRegistryRef services)
{
constexpr unsigned int LHC_MAX_BC = o2::constants::lhc::LHCMaxBunches;
auto& qcdb = services.get<quality_control::repository::DatabaseInterface>();
auto moBCEMC = qcdb.retrieveMO(mDataPath, "BCEMCALReadout", t.timestamp, t.activity),
moBCCTP = qcdb.retrieveMO(mDataPath, "BCCTPEMCALAny", t.timestamp, t.activity);
auto moBCEMC = qcdb.retrieveMO(mDataPath + "/BCEMCALReadout", t.timestamp, t.activity),
moBCCTP = qcdb.retrieveMO(mDataPath + "/BCCTPEMCALAny", t.timestamp, t.activity);

if (moBCCTP == nullptr || moBCEMC == nullptr) {
ILOG(Error, Support) << "at least one of the expected objects (BCEMCALReadout and BCCTPEMCALAny) could not be "
Expand Down
Loading
Loading