From 4a5244a0ed2f63f87ae27fbaeeab205ee70de6cb Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Wed, 23 Oct 2024 09:01:51 +0200 Subject: [PATCH 01/13] [QC-1206] Make CTP Scalers available to user code --- Framework/CMakeLists.txt | 1 + .../QualityControl/UserCodeInterface.h | 22 +++++- Framework/src/UserCodeInterface.cxx | 69 +++++++++++++++++-- Modules/Skeleton/src/SkeletonCheck.cxx | 4 ++ doc/Advanced.md | 3 + 5 files changed, 93 insertions(+), 6 deletions(-) diff --git a/Framework/CMakeLists.txt b/Framework/CMakeLists.txt index 5f48077f10..74416324d0 100644 --- a/Framework/CMakeLists.txt +++ b/Framework/CMakeLists.txt @@ -169,6 +169,7 @@ target_link_libraries(O2QualityControl O2::DataFormatsQualityControl O2::DetectorsBase O2::GlobalTracking + O2::DataFormatsCTP O2QualityControlKafkaProtos ${RDKAFKA_LIB} PRIVATE Boost::system diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index 8cd26dd310..cc58294b8d 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -25,6 +25,10 @@ #include "QualityControl/CustomParameters.h" #include "QualityControl/DatabaseInterface.h" +namespace o2::ctp { +class CTPRateFetcher; +} + namespace o2::quality_control::core { @@ -51,14 +55,28 @@ class UserCodeInterface : public ConditionAccess void setName(const std::string& name); void setDatabase(std::unordered_map dbConfig); + private: + /// \brief Just the callback for the thread for the scalers retrieval. + void regularCallback(int intervalMinutes); + /// \brief Retrieve fresh scalers from the QCDB (with cache) + void updateScalers(); + std::shared_ptr mCtpFetcher; + std::chrono::steady_clock::time_point mScalersLastUpdate; + bool mScalersEnabled = false; + protected: + /// \brief Call it to enable the retrieval of CTP scalers and use `getScalers` later + void enableCtpScalers(size_t runNumber, std::string ccdbUrl); + /// \brief Get the scalers's value for the given source + double getScalersValue(std::string sourceName, size_t runNumber); + CustomParameters mCustomParameters; std::string mName; std::shared_ptr mDatabase; - ClassDef(UserCodeInterface, 4) + ClassDef(UserCodeInterface, 5) }; } // namespace o2::quality_control::core -#endif // QUALITYCONTROL_USERCODEINTERFACE_H +#endif // QUALITYCONTROL_USERCODEINTERFACE_H \ No newline at end of file diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 96ee5bcdb3..ae83243d41 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -15,6 +15,7 @@ /// #include "QualityControl/UserCodeInterface.h" +#include #include #include "QualityControl/QcInfoLogger.h" #include "QualityControl/DatabaseFactory.h" @@ -31,16 +32,76 @@ void UserCodeInterface::setCustomParameters(const CustomParameters& parameters) configure(); } -const std::string& UserCodeInterface::getName() const -{ +const std::string& UserCodeInterface::getName() const { return mName; } -void UserCodeInterface::setName(const std::string& name) -{ +void UserCodeInterface::setName(const std::string& name) { mName = name; } +void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) +{ + // TODO bail if we are in async + ILOG(Debug, Devel) << "Enabling CTP scalers" << ENDM; + mCtpFetcher = make_shared(); + mScalersEnabled = true; + auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); + ccdbManager.setURL(ccdbUrl); + mCtpFetcher->setupRun(runNumber, &ccdbManager, /*1726300234140*/ getCurrentTimestamp(), false); + + mScalersLastUpdate = std::chrono::steady_clock::time_point::min(); + cout << "mScalersLastUpdate : " << std::chrono::duration_cast(mScalersLastUpdate.time_since_epoch()).count() << endl; + updateScalers(); // initial value + ILOG(Debug, Devel) << "Enabled CTP scalers" << ENDM; +} + +void UserCodeInterface::updateScalers() +{ + if(!mScalersEnabled) { + ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get them." << ENDM; + return; // TODO should we throw ? probably yes + } + ILOG(Debug, Devel) << "Updating scalers." << ENDM; + + if(! mDatabase) { + ILOG(Error, Devel) << "Database not set ! Cannot update scalers." << ENDM; + mScalersEnabled = false; + + return; + // todo handle the case when database is not set + } + + auto now = std::chrono::steady_clock::now(); + auto minutesSinceLast = std::chrono::duration_cast(now - mScalersLastUpdate); + + // TODO get the interval from config + if (minutesSinceLast.count() >= 0 /*first time it is neg*/ && minutesSinceLast.count() < 5) { + ILOG(Debug, Devel) << "getScalers was called less than 5 minutes ago, use the cached value" << ENDM; + return; + } + + std::map meta; + void* rawResult = mDatabase->retrieveAny(typeid(o2::ctp::CTPRunScalers), "qc/CTP/Scalers", meta); + o2::ctp::CTPRunScalers* ctpScalers = static_cast(rawResult); + mCtpFetcher->updateScalers(*ctpScalers); + mScalersLastUpdate = now; + ILOG(Debug, Devel) << "Scalers updated." << ENDM; +} + +double UserCodeInterface::getScalersValue(std::string sourceName, size_t runNumber) +{ + if(!mScalersEnabled) { + ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get the value." << ENDM; + return 0; + } + updateScalers(); // from QCDB + auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); + auto result = mCtpFetcher->fetchNoPuCorr(&ccdbManager, getCurrentTimestamp(), runNumber, sourceName); + ILOG(Debug, Devel) << "Returning scaler value : " << result << ENDM; + return result; +} + void UserCodeInterface::setDatabase(std::unordered_map dbConfig) { if (dbConfig.count("implementation") == 0 || dbConfig.count("host") == 0) { diff --git a/Modules/Skeleton/src/SkeletonCheck.cxx b/Modules/Skeleton/src/SkeletonCheck.cxx index 8f1f1cbf99..eef9552566 100644 --- a/Modules/Skeleton/src/SkeletonCheck.cxx +++ b/Modules/Skeleton/src/SkeletonCheck.cxx @@ -49,6 +49,9 @@ Quality SkeletonCheck::check(std::mapmId); + ILOG(Info, Devel) << "\"T0VTX\" : " << t0vtx << ENDM; + // This is an example of accessing the histogram 'example' created by SkeletonTask for (auto& [moName, mo] : *moMap) { if (mo->getName() == "example") { @@ -124,6 +127,7 @@ void SkeletonCheck::startOfActivity(const Activity& activity) // THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED. ILOG(Debug, Devel) << "SkeletonCheck::start : " << activity.mId << ENDM; mActivity = make_shared(activity); + enableCtpScalers(activity.mId, "alice-ccdb.cern.ch"); // TODO get it from the config } void SkeletonCheck::endOfActivity(const Activity& activity) diff --git a/doc/Advanced.md b/doc/Advanced.md index 38c67576e5..94fdc62b09 100644 --- a/doc/Advanced.md +++ b/doc/Advanced.md @@ -1996,7 +1996,10 @@ The values are relative to the canvas size, so in the example above the label wi In consul go to `o2/runtime/aliecs/defaults` and modify the file corresponding to the detector: [det]_qc_shm_segment_size +## CTP Scalers +Get a certificate for development : https://alice-doc.github.io/alice-analysis-tutorial/start/cert.html#test-your-certificate +JAliEn-ROOT --- From f020b141adaf9fe1c535bde496e747929bccd855 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Wed, 23 Oct 2024 09:03:10 +0200 Subject: [PATCH 02/13] format --- Framework/include/QualityControl/UserCodeInterface.h | 5 +++-- Framework/src/UserCodeInterface.cxx | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index cc58294b8d..f3b7fe99ff 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -25,7 +25,8 @@ #include "QualityControl/CustomParameters.h" #include "QualityControl/DatabaseInterface.h" -namespace o2::ctp { +namespace o2::ctp +{ class CTPRateFetcher; } @@ -61,7 +62,7 @@ class UserCodeInterface : public ConditionAccess /// \brief Retrieve fresh scalers from the QCDB (with cache) void updateScalers(); std::shared_ptr mCtpFetcher; - std::chrono::steady_clock::time_point mScalersLastUpdate; + std::chrono::steady_clock::time_point mScalersLastUpdate; bool mScalersEnabled = false; protected: diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index ae83243d41..954d166f52 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -58,13 +58,13 @@ void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) void UserCodeInterface::updateScalers() { - if(!mScalersEnabled) { + if (!mScalersEnabled) { ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get them." << ENDM; return; // TODO should we throw ? probably yes } ILOG(Debug, Devel) << "Updating scalers." << ENDM; - if(! mDatabase) { + if (!mDatabase) { ILOG(Error, Devel) << "Database not set ! Cannot update scalers." << ENDM; mScalersEnabled = false; @@ -91,7 +91,7 @@ void UserCodeInterface::updateScalers() double UserCodeInterface::getScalersValue(std::string sourceName, size_t runNumber) { - if(!mScalersEnabled) { + if (!mScalersEnabled) { ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get the value." << ENDM; return 0; } From 0f9b4d3b413511d07475e7c251ae7feb53a1f6c7 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Wed, 23 Oct 2024 16:58:36 +0200 Subject: [PATCH 03/13] disable CTP scalers in async --- Framework/src/UserCodeInterface.cxx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 954d166f52..8d59cbadcc 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -43,6 +43,13 @@ void UserCodeInterface::setName(const std::string& name) { void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) { // TODO bail if we are in async + + auto deploymentMode = framework::DefaultsHelpers::deploymentMode(); + if(deploymentMode == framework::DeploymentMode::Grid) { + ILOG(Info, Ops) << "Async mode detected, CTP scalers cannot be enabled." << ENDM; + return; + } + ILOG(Debug, Devel) << "Enabling CTP scalers" << ENDM; mCtpFetcher = make_shared(); mScalersEnabled = true; From 166bb8a21434b7f3ba89f3d4f1ce5277e461d6bf Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Thu, 31 Oct 2024 15:17:49 +0100 Subject: [PATCH 04/13] properly set the run number --- .../QualityControl/UserCodeInterface.h | 3 +- Framework/src/UserCodeInterface.cxx | 40 +++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index f3b7fe99ff..f575d5e9ce 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -60,7 +60,8 @@ class UserCodeInterface : public ConditionAccess /// \brief Just the callback for the thread for the scalers retrieval. void regularCallback(int intervalMinutes); /// \brief Retrieve fresh scalers from the QCDB (with cache) - void updateScalers(); + /// \return true if success, false if failure + bool updateScalers(size_t runNumber); std::shared_ptr mCtpFetcher; std::chrono::steady_clock::time_point mScalersLastUpdate; bool mScalersEnabled = false; diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 8d59cbadcc..bb5ab40351 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -58,25 +58,25 @@ void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) mCtpFetcher->setupRun(runNumber, &ccdbManager, /*1726300234140*/ getCurrentTimestamp(), false); mScalersLastUpdate = std::chrono::steady_clock::time_point::min(); - cout << "mScalersLastUpdate : " << std::chrono::duration_cast(mScalersLastUpdate.time_since_epoch()).count() << endl; - updateScalers(); // initial value - ILOG(Debug, Devel) << "Enabled CTP scalers" << ENDM; + if(updateScalers(runNumber)) { // initial value + ILOG(Debug, Devel) << "Enabled CTP scalers" << ENDM; + } else { + ILOG(Debug, Devel) << "CTP scalers not enabled, failure to get them." << ENDM; + } } -void UserCodeInterface::updateScalers() +bool UserCodeInterface::updateScalers(size_t runNumber) { if (!mScalersEnabled) { - ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get them." << ENDM; - return; // TODO should we throw ? probably yes + ILOG(Error, Ops) << "CTP scalers not enabled, impossible to update them." << ENDM; + return false; } ILOG(Debug, Devel) << "Updating scalers." << ENDM; if (!mDatabase) { ILOG(Error, Devel) << "Database not set ! Cannot update scalers." << ENDM; mScalersEnabled = false; - - return; - // todo handle the case when database is not set + return false; } auto now = std::chrono::steady_clock::now(); @@ -85,15 +85,26 @@ void UserCodeInterface::updateScalers() // TODO get the interval from config if (minutesSinceLast.count() >= 0 /*first time it is neg*/ && minutesSinceLast.count() < 5) { ILOG(Debug, Devel) << "getScalers was called less than 5 minutes ago, use the cached value" << ENDM; - return; + return true; } std::map meta; - void* rawResult = mDatabase->retrieveAny(typeid(o2::ctp::CTPRunScalers), "qc/CTP/Scalers", meta); + meta["runNumber"] = std::to_string(runNumber); + std::map headers; + auto validity = mDatabase->getLatestObjectValidity("qc/CTP/Scalers", meta); + void* rawResult = mDatabase->retrieveAny(typeid(o2::ctp::CTPRunScalers), "qc/CTP/Scalers", meta, validity.getMax() - 1, &headers); + if (!rawResult) { + ILOG(Error, Devel) << "Could not retrieve the CTP Scalers" << ENDM; + return false; + } else { + ILOG(Debug, Devel) << "object retrieved" << ENDM; + } + o2::ctp::CTPRunScalers* ctpScalers = static_cast(rawResult); mCtpFetcher->updateScalers(*ctpScalers); mScalersLastUpdate = now; ILOG(Debug, Devel) << "Scalers updated." << ENDM; + return true; } double UserCodeInterface::getScalersValue(std::string sourceName, size_t runNumber) @@ -102,9 +113,12 @@ double UserCodeInterface::getScalersValue(std::string sourceName, size_t runNumb ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get the value." << ENDM; return 0; } - updateScalers(); // from QCDB + if(!updateScalers(runNumber)) { // from QCDB + ILOG(Debug, Devel) << "Could not update the scalers, returning 0" << ENDM; + return 0; + } auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); - auto result = mCtpFetcher->fetchNoPuCorr(&ccdbManager, getCurrentTimestamp(), runNumber, sourceName); + auto result = mCtpFetcher->fetchNoPuCorr(&ccdbManager, getCurrentTimestamp()*1000, runNumber, sourceName); ILOG(Debug, Devel) << "Returning scaler value : " << result << ENDM; return result; } From 940a3be0192e07a3fccd8e1eb448c8dca350c463 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Fri, 1 Nov 2024 14:52:38 +0100 Subject: [PATCH 05/13] doc --- doc/Advanced.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/Advanced.md b/doc/Advanced.md index 94fdc62b09..437a6046b2 100644 --- a/doc/Advanced.md +++ b/doc/Advanced.md @@ -1999,7 +1999,11 @@ In consul go to `o2/runtime/aliecs/defaults` and modify the file corresponding t ## CTP Scalers Get a certificate for development : https://alice-doc.github.io/alice-analysis-tutorial/start/cert.html#test-your-certificate -JAliEn-ROOT + +Build JAlien-ROOT + +alienv enter QualityControl/latest JAliEn-ROOT/latest + --- From 9d1fe139744414ef6df80bfd7b18d21077c8cf6b Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Thu, 13 Mar 2025 14:15:35 +0100 Subject: [PATCH 06/13] format --- Framework/src/UserCodeInterface.cxx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index bb5ab40351..64fd241c20 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -32,11 +32,13 @@ void UserCodeInterface::setCustomParameters(const CustomParameters& parameters) configure(); } -const std::string& UserCodeInterface::getName() const { +const std::string& UserCodeInterface::getName() const +{ return mName; } -void UserCodeInterface::setName(const std::string& name) { +void UserCodeInterface::setName(const std::string& name) +{ mName = name; } @@ -45,7 +47,7 @@ void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) // TODO bail if we are in async auto deploymentMode = framework::DefaultsHelpers::deploymentMode(); - if(deploymentMode == framework::DeploymentMode::Grid) { + if (deploymentMode == framework::DeploymentMode::Grid) { ILOG(Info, Ops) << "Async mode detected, CTP scalers cannot be enabled." << ENDM; return; } @@ -58,7 +60,7 @@ void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) mCtpFetcher->setupRun(runNumber, &ccdbManager, /*1726300234140*/ getCurrentTimestamp(), false); mScalersLastUpdate = std::chrono::steady_clock::time_point::min(); - if(updateScalers(runNumber)) { // initial value + if (updateScalers(runNumber)) { // initial value ILOG(Debug, Devel) << "Enabled CTP scalers" << ENDM; } else { ILOG(Debug, Devel) << "CTP scalers not enabled, failure to get them." << ENDM; @@ -113,12 +115,12 @@ double UserCodeInterface::getScalersValue(std::string sourceName, size_t runNumb ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get the value." << ENDM; return 0; } - if(!updateScalers(runNumber)) { // from QCDB + if (!updateScalers(runNumber)) { // from QCDB ILOG(Debug, Devel) << "Could not update the scalers, returning 0" << ENDM; return 0; } auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); - auto result = mCtpFetcher->fetchNoPuCorr(&ccdbManager, getCurrentTimestamp()*1000, runNumber, sourceName); + auto result = mCtpFetcher->fetchNoPuCorr(&ccdbManager, getCurrentTimestamp() * 1000, runNumber, sourceName); ILOG(Debug, Devel) << "Returning scaler value : " << result << ENDM; return result; } From c23a052635e6847689404d149ad7d624d83e56bd Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Fri, 14 Mar 2025 08:37:11 +0100 Subject: [PATCH 07/13] doc and cleanup --- Framework/basic.json | 4 +- .../QualityControl/UserCodeInterface.h | 2 - Framework/src/UserCodeInterface.cxx | 4 +- doc/Advanced.md | 39 +++++++++++++++++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Framework/basic.json b/Framework/basic.json index d61ac6285d..1f71aa047e 100644 --- a/Framework/basic.json +++ b/Framework/basic.json @@ -10,7 +10,7 @@ "maxObjectSize": "2097152", "": "[Bytes, default=2MB] Maximum size allowed, larger objects are rejected." }, "Activity": { - "number": "42", + "number": "561253", "type": "NONE", "periodName": "", "": "Period name - e.g. LHC22c, LHC22c1b_test", "passName": "", "": "Pass type - e.g. spass, cpass1", @@ -27,7 +27,7 @@ }, "infologger": { "": "Configuration of the Infologger (optional).", "filterDiscardDebug": "false", "": "Set to true to discard debug and trace messages (default: false)", - "filterDiscardLevel": "12", "": "Message at this level or above are discarded (default: 21 - Trace)", + "filterDiscardLevel": "21", "": "Message at this level or above are discarded (default: 21 - Trace)", "filterDiscardFile": "/tmp/_ID_.txt", "": ["If set, the messages discarded because of filterDiscardLevel", "will go to this file (default: ); The keyword _ID_ is replaced by the device id. Discarded Debug ", "messages won't go there."] diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index f575d5e9ce..a2db8b4c63 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -57,8 +57,6 @@ class UserCodeInterface : public ConditionAccess void setDatabase(std::unordered_map dbConfig); private: - /// \brief Just the callback for the thread for the scalers retrieval. - void regularCallback(int intervalMinutes); /// \brief Retrieve fresh scalers from the QCDB (with cache) /// \return true if success, false if failure bool updateScalers(size_t runNumber); diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 64fd241c20..3015d4aa41 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -16,7 +16,6 @@ #include "QualityControl/UserCodeInterface.h" #include -#include #include "QualityControl/QcInfoLogger.h" #include "QualityControl/DatabaseFactory.h" @@ -44,8 +43,7 @@ void UserCodeInterface::setName(const std::string& name) void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) { - // TODO bail if we are in async - + // bail if we are in async auto deploymentMode = framework::DefaultsHelpers::deploymentMode(); if (deploymentMode == framework::DeploymentMode::Grid) { ILOG(Info, Ops) << "Async mode detected, CTP scalers cannot be enabled." << ENDM; diff --git a/doc/Advanced.md b/doc/Advanced.md index 437a6046b2..4b7b719ee4 100644 --- a/doc/Advanced.md +++ b/doc/Advanced.md @@ -1998,13 +1998,46 @@ In consul go to `o2/runtime/aliecs/defaults` and modify the file corresponding t ## CTP Scalers -Get a certificate for development : https://alice-doc.github.io/alice-analysis-tutorial/start/cert.html#test-your-certificate +### Usage -Build JAlien-ROOT +User code can access CTP scalers in the following way : +``` +// in start of activity + enableCtpScalers(activity.mId, "alice-ccdb.cern.ch"); // TODO get it from the config + +// in your e.g. check(...) + auto t0vtx = getScalersValue("T0VTX", mActivity->mId); + ILOG(Info, Devel) << "\"T0VTX\" : " << t0vtx << ENDM; +``` + +### Limitations + +It does not work in async. + +### Implementation -alienv enter QualityControl/latest JAliEn-ROOT/latest +`CTP proxy` publishes the scalers every 5 minutes into the QCDB at [`qc/CTP/Scalers`](http://ali-qcdb-gpn.cern.ch:8083/browse/qc/CTP/Scalers?report=true). They are cleaned up after 3 days. +Thus we query from the QCDB yet we also need access to CCDB to setup the `CTPRateFetcher`. +When enabling the scalers we instantiate `CTPRateFetcher` and call `setupRun()` __using the current timestamp__. +When asking for the scalers, they are retrieved from the QCDB or a cached version is used (cache of 5 minutes). + +### Development and test + +* Get a certificate : https://alice-doc.github.io/alice-analysis-tutorial/start/cert.html#test-your-certificate +* Build JAlien-ROOT : `aliBuild build JAliEn-ROOT [--defaults o2-dataflow]` +* Build AliEn-Runtime : `aliBuild build xjalienfs [--defaults o2-dataflow]` +* Use a combined environment : `alienv enter QualityControl/latest JAliEn-ROOT/latest xjalienfs/latest` + +Then change the run number in the config file (`basic.json` to match a recent run otherwise it won't work as the CTP scalers are deleted after 3 days). + +``` +alien-token-init + +``` +How do we do if there are no current runs ? we end up with some data in CCDB but the scalers in QCDB are missing. +Could we specify a file instead ? --- From 344146eb8ed029b19e7cebbf3fcfbf18c2dda1f4 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Fri, 14 Mar 2025 09:34:58 +0100 Subject: [PATCH 08/13] put the scalers in their own class --- Framework/CMakeLists.txt | 2 + Framework/include/QualityControl/CtpScalers.h | 63 ++++++++++ .../QualityControl/DatabaseInterface.h | 1 - Framework/include/QualityControl/LinkDef.h | 1 + .../QualityControl/UserCodeInterface.h | 19 +-- Framework/src/CtpScalers.cxx | 109 ++++++++++++++++++ Framework/src/UserCodeInterface.cxx | 78 +------------ 7 files changed, 183 insertions(+), 90 deletions(-) create mode 100644 Framework/include/QualityControl/CtpScalers.h create mode 100644 Framework/src/CtpScalers.cxx diff --git a/Framework/CMakeLists.txt b/Framework/CMakeLists.txt index 74416324d0..06214282f2 100644 --- a/Framework/CMakeLists.txt +++ b/Framework/CMakeLists.txt @@ -90,6 +90,7 @@ add_library(O2QualityControl src/TaskRunner.cxx src/TaskRunnerFactory.cxx src/TaskInterface.cxx + src/CtpScalers.cxx src/UserCodeInterface.cxx src/RepositoryBenchmark.cxx src/RepoPathUtils.cxx @@ -181,6 +182,7 @@ add_root_dictionary(O2QualityControl HEADERS include/QualityControl/CheckInterface.h include/QualityControl/TaskInterface.h + include/QualityControl/CtpScalers.h include/QualityControl/UserCodeInterface.h include/QualityControl/AggregatorInterface.h include/QualityControl/PostProcessingInterface.h diff --git a/Framework/include/QualityControl/CtpScalers.h b/Framework/include/QualityControl/CtpScalers.h new file mode 100644 index 0000000000..94e4a7ebe3 --- /dev/null +++ b/Framework/include/QualityControl/CtpScalers.h @@ -0,0 +1,63 @@ +// 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 CtpScalers.h +/// \author Barthelemy von Haller +/// + +#ifndef QUALITYCONTROL_CTPSCALERS_H +#define QUALITYCONTROL_CTPSCALERS_H + +#include +#include "QualityControl/DatabaseInterface.h" + +namespace o2::ctp +{ +class CTPRateFetcher; +} + +namespace o2::quality_control::core +{ + +class CtpScalers +{ + public: + CtpScalers() = default; + virtual ~CtpScalers() = default; + + /// \brief Call it to enable the retrieval of CTP scalers and use `getScalers` later + void enableCtpScalers(size_t runNumber, std::string ccdbUrl); + /// \brief Get the scalers's value for the given source + double getScalersValue(std::string sourceName, size_t runNumber); + + void setDatabase(std::shared_ptr database) + { + mDatabase = database; + } + + private: + /// \brief Retrieve fresh scalers from the QCDB (with cache) + /// \return true if success, false if failure + bool updateScalers(size_t runNumber); + + std::shared_ptr mCtpFetcher; + std::chrono::steady_clock::time_point mScalersLastUpdate; + bool mScalersEnabled = false; + std::shared_ptr mDatabase; //! the repository used by the Framework + + private: + ClassDef(CtpScalers, 1) +}; + +} // namespace o2::quality_control::core + +#endif // QUALITYCONTROL_USERCODEINTERFACE_H \ No newline at end of file diff --git a/Framework/include/QualityControl/DatabaseInterface.h b/Framework/include/QualityControl/DatabaseInterface.h index 066f459390..cc3d45a2d3 100644 --- a/Framework/include/QualityControl/DatabaseInterface.h +++ b/Framework/include/QualityControl/DatabaseInterface.h @@ -18,7 +18,6 @@ #define QC_REPOSITORY_DATABASEINTERFACE_H #include -#include #include #include diff --git a/Framework/include/QualityControl/LinkDef.h b/Framework/include/QualityControl/LinkDef.h index 08fde33986..0468378da0 100644 --- a/Framework/include/QualityControl/LinkDef.h +++ b/Framework/include/QualityControl/LinkDef.h @@ -7,6 +7,7 @@ #pragma link C++ namespace o2::quality_control::checker; #pragma link C++ namespace o2::quality_control::postprocessing; +#pragma link C++ class o2::quality_control::core::CtpScalers + ; #pragma link C++ class o2::quality_control::core::UserCodeInterface + ; #pragma link C++ class o2::quality_control::checker::CheckInterface + ; #pragma link C++ class o2::quality_control::core::TaskInterface + ; diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index a2db8b4c63..42991fe2e4 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -18,17 +18,13 @@ #define QUALITYCONTROL_USERCODEINTERFACE_H #include -#include #include #include "QualityControl/ConditionAccess.h" #include "QualityControl/CustomParameters.h" #include "QualityControl/DatabaseInterface.h" - -namespace o2::ctp -{ -class CTPRateFetcher; -} +#include "QualityControl/CcdbDatabase.h" +#include "QualityControl/CtpScalers.h" namespace o2::quality_control::core { @@ -56,14 +52,6 @@ class UserCodeInterface : public ConditionAccess void setName(const std::string& name); void setDatabase(std::unordered_map dbConfig); - private: - /// \brief Retrieve fresh scalers from the QCDB (with cache) - /// \return true if success, false if failure - bool updateScalers(size_t runNumber); - std::shared_ptr mCtpFetcher; - std::chrono::steady_clock::time_point mScalersLastUpdate; - bool mScalersEnabled = false; - protected: /// \brief Call it to enable the retrieval of CTP scalers and use `getScalers` later void enableCtpScalers(size_t runNumber, std::string ccdbUrl); @@ -72,7 +60,8 @@ class UserCodeInterface : public ConditionAccess CustomParameters mCustomParameters; std::string mName; - std::shared_ptr mDatabase; + std::shared_ptr mDatabase; //! the repository used by the Framework + CtpScalers mCtpScalers; ClassDef(UserCodeInterface, 5) }; diff --git a/Framework/src/CtpScalers.cxx b/Framework/src/CtpScalers.cxx new file mode 100644 index 0000000000..8c10006f72 --- /dev/null +++ b/Framework/src/CtpScalers.cxx @@ -0,0 +1,109 @@ +// 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 CtpScalers.cxx +/// \author Barthelemy von Haller +/// + +#include "QualityControl/CtpScalers.h" +#include +#include "QualityControl/QcInfoLogger.h" +#include "QualityControl/DatabaseFactory.h" + +using namespace o2::ccdb; +using namespace std; + +namespace o2::quality_control::core +{ +void CtpScalers::enableCtpScalers(size_t runNumber, std::string ccdbUrl) +{ + // bail if we are in async + auto deploymentMode = framework::DefaultsHelpers::deploymentMode(); + if (deploymentMode == framework::DeploymentMode::Grid) { + ILOG(Info, Ops) << "Async mode detected, CTP scalers cannot be enabled." << ENDM; + return; + } + + ILOG(Debug, Devel) << "Enabling CTP scalers" << ENDM; + mCtpFetcher = make_shared(); + mScalersEnabled = true; + auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); + ccdbManager.setURL(ccdbUrl); + mCtpFetcher->setupRun(runNumber, &ccdbManager, /*1726300234140*/ getCurrentTimestamp(), false); + + mScalersLastUpdate = std::chrono::steady_clock::time_point::min(); + if (updateScalers(runNumber)) { // initial value + ILOG(Debug, Devel) << "Enabled CTP scalers" << ENDM; + } else { + ILOG(Debug, Devel) << "CTP scalers not enabled, failure to get them." << ENDM; + } +} + +bool CtpScalers::updateScalers(size_t runNumber) +{ + if (!mScalersEnabled) { + ILOG(Error, Ops) << "CTP scalers not enabled, impossible to update them." << ENDM; + return false; + } + ILOG(Debug, Devel) << "Updating scalers." << ENDM; + + if (!mDatabase) { + ILOG(Error, Devel) << "Database not set ! Cannot update scalers." << ENDM; + mScalersEnabled = false; + return false; + } + + auto now = std::chrono::steady_clock::now(); + auto minutesSinceLast = std::chrono::duration_cast(now - mScalersLastUpdate); + + // TODO get the interval from config + if (minutesSinceLast.count() >= 0 /*first time it is neg*/ && minutesSinceLast.count() < 5) { + ILOG(Debug, Devel) << "getScalers was called less than 5 minutes ago, use the cached value" << ENDM; + return true; + } + + std::map meta; + meta["runNumber"] = std::to_string(runNumber); + std::map headers; + auto validity = mDatabase->getLatestObjectValidity("qc/CTP/Scalers", meta); + void* rawResult = mDatabase->retrieveAny(typeid(o2::ctp::CTPRunScalers), "qc/CTP/Scalers", meta, validity.getMax() - 1, &headers); + if (!rawResult) { + ILOG(Error, Devel) << "Could not retrieve the CTP Scalers" << ENDM; + return false; + } else { + ILOG(Debug, Devel) << "object retrieved" << ENDM; + } + + o2::ctp::CTPRunScalers* ctpScalers = static_cast(rawResult); + mCtpFetcher->updateScalers(*ctpScalers); + mScalersLastUpdate = now; + ILOG(Debug, Devel) << "Scalers updated." << ENDM; + return true; +} + +double CtpScalers::getScalersValue(std::string sourceName, size_t runNumber) +{ + if (!mScalersEnabled) { + ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get the value." << ENDM; + return 0; + } + if (!updateScalers(runNumber)) { // from QCDB + ILOG(Debug, Devel) << "Could not update the scalers, returning 0" << ENDM; + return 0; + } + auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); + auto result = mCtpFetcher->fetchNoPuCorr(&ccdbManager, getCurrentTimestamp() * 1000, runNumber, sourceName); + ILOG(Debug, Devel) << "Returning scaler value : " << result << ENDM; + return result; +} + +} // namespace o2::quality_control::core \ No newline at end of file diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 3015d4aa41..3ab097eb8e 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -43,84 +43,12 @@ void UserCodeInterface::setName(const std::string& name) void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) { - // bail if we are in async - auto deploymentMode = framework::DefaultsHelpers::deploymentMode(); - if (deploymentMode == framework::DeploymentMode::Grid) { - ILOG(Info, Ops) << "Async mode detected, CTP scalers cannot be enabled." << ENDM; - return; - } - - ILOG(Debug, Devel) << "Enabling CTP scalers" << ENDM; - mCtpFetcher = make_shared(); - mScalersEnabled = true; - auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); - ccdbManager.setURL(ccdbUrl); - mCtpFetcher->setupRun(runNumber, &ccdbManager, /*1726300234140*/ getCurrentTimestamp(), false); - - mScalersLastUpdate = std::chrono::steady_clock::time_point::min(); - if (updateScalers(runNumber)) { // initial value - ILOG(Debug, Devel) << "Enabled CTP scalers" << ENDM; - } else { - ILOG(Debug, Devel) << "CTP scalers not enabled, failure to get them." << ENDM; - } -} - -bool UserCodeInterface::updateScalers(size_t runNumber) -{ - if (!mScalersEnabled) { - ILOG(Error, Ops) << "CTP scalers not enabled, impossible to update them." << ENDM; - return false; - } - ILOG(Debug, Devel) << "Updating scalers." << ENDM; - - if (!mDatabase) { - ILOG(Error, Devel) << "Database not set ! Cannot update scalers." << ENDM; - mScalersEnabled = false; - return false; - } - - auto now = std::chrono::steady_clock::now(); - auto minutesSinceLast = std::chrono::duration_cast(now - mScalersLastUpdate); - - // TODO get the interval from config - if (minutesSinceLast.count() >= 0 /*first time it is neg*/ && minutesSinceLast.count() < 5) { - ILOG(Debug, Devel) << "getScalers was called less than 5 minutes ago, use the cached value" << ENDM; - return true; - } - - std::map meta; - meta["runNumber"] = std::to_string(runNumber); - std::map headers; - auto validity = mDatabase->getLatestObjectValidity("qc/CTP/Scalers", meta); - void* rawResult = mDatabase->retrieveAny(typeid(o2::ctp::CTPRunScalers), "qc/CTP/Scalers", meta, validity.getMax() - 1, &headers); - if (!rawResult) { - ILOG(Error, Devel) << "Could not retrieve the CTP Scalers" << ENDM; - return false; - } else { - ILOG(Debug, Devel) << "object retrieved" << ENDM; - } - - o2::ctp::CTPRunScalers* ctpScalers = static_cast(rawResult); - mCtpFetcher->updateScalers(*ctpScalers); - mScalersLastUpdate = now; - ILOG(Debug, Devel) << "Scalers updated." << ENDM; - return true; + mCtpScalers.enableCtpScalers(runNumber, ccdbUrl); } double UserCodeInterface::getScalersValue(std::string sourceName, size_t runNumber) { - if (!mScalersEnabled) { - ILOG(Error, Ops) << "CTP scalers not enabled, impossible to get the value." << ENDM; - return 0; - } - if (!updateScalers(runNumber)) { // from QCDB - ILOG(Debug, Devel) << "Could not update the scalers, returning 0" << ENDM; - return 0; - } - auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); - auto result = mCtpFetcher->fetchNoPuCorr(&ccdbManager, getCurrentTimestamp() * 1000, runNumber, sourceName); - ILOG(Debug, Devel) << "Returning scaler value : " << result << ENDM; - return result; + return mCtpScalers.getScalersValue( sourceName, runNumber); } void UserCodeInterface::setDatabase(std::unordered_map dbConfig) @@ -133,6 +61,8 @@ void UserCodeInterface::setDatabase(std::unordered_map mDatabase = repository::DatabaseFactory::create(dbConfig.at("implementation")); mDatabase->connect(dbConfig); ILOG(Debug, Devel) << "Database that is going to be used > Implementation : " << dbConfig.at("implementation") << " / Host : " << dbConfig.at("host") << ENDM; + + mCtpScalers.setDatabase(mDatabase); } } // namespace o2::quality_control::core \ No newline at end of file From 81fba101562875bc5f723f648716c1119eefc19d Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Fri, 14 Mar 2025 09:36:48 +0100 Subject: [PATCH 09/13] form at --- Framework/src/UserCodeInterface.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 3ab097eb8e..862718020b 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -48,7 +48,7 @@ void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) double UserCodeInterface::getScalersValue(std::string sourceName, size_t runNumber) { - return mCtpScalers.getScalersValue( sourceName, runNumber); + return mCtpScalers.getScalersValue(sourceName, runNumber); } void UserCodeInterface::setDatabase(std::unordered_map dbConfig) From 7b442b47230b9e4d5b037d4cb34d0e1a144f5e15 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Fri, 14 Mar 2025 14:09:59 +0100 Subject: [PATCH 10/13] change interface of UserCodeInterface to take the UserConfig (to ease future extension) --- Framework/include/QualityControl/ConditionAccess.h | 2 +- .../include/QualityControl/UserCodeInterface.h | 8 ++++---- Framework/src/Aggregator.cxx | 4 +--- Framework/src/Check.cxx | 4 +--- Framework/src/CtpScalers.cxx | 1 - Framework/src/PostProcessingFactory.cxx | 3 +-- Framework/src/PostProcessingRunner.cxx | 2 -- Framework/src/TaskFactory.cxx | 3 +-- Framework/src/TaskRunner.cxx | 2 -- Framework/src/UserCodeInterface.cxx | 8 ++++++-- Framework/test/testCheck.cxx | 4 ++-- Framework/test/testSharedConfig.json | 3 +++ Framework/test/testTaskInterface.cxx | 4 ++-- Framework/test/testUserCodeInterface.cxx | 13 ++++++++----- Modules/Common/test/testMeanIsAbove.cxx | 7 ++++++- Modules/Example/test/testFactory.cxx | 1 + 16 files changed, 37 insertions(+), 32 deletions(-) diff --git a/Framework/include/QualityControl/ConditionAccess.h b/Framework/include/QualityControl/ConditionAccess.h index e1ed6346f0..02bd8a2b5e 100644 --- a/Framework/include/QualityControl/ConditionAccess.h +++ b/Framework/include/QualityControl/ConditionAccess.h @@ -30,6 +30,7 @@ class ConditionAccess void setCcdbUrl(const std::string& url) { o2::ccdb::BasicCCDBManager::instance().setURL(url); + o2::ccdb::BasicCCDBManager::instance().setFatalWhenNull(false); } /** @@ -43,7 +44,6 @@ template T* ConditionAccess::retrieveConditionAny(std::string const& path, std::map const& metadata, long timestamp) { auto& mgr = o2::ccdb::BasicCCDBManager::instance(); - mgr.setFatalWhenNull(false); mgr.setTimestamp(timestamp); return mgr.getSpecific(path, mgr.getTimestamp(), metadata); } diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index 42991fe2e4..79a9b818e6 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -23,11 +23,11 @@ #include "QualityControl/ConditionAccess.h" #include "QualityControl/CustomParameters.h" #include "QualityControl/DatabaseInterface.h" -#include "QualityControl/CcdbDatabase.h" #include "QualityControl/CtpScalers.h" namespace o2::quality_control::core { +class UserCodeConfig; /// \brief Common interface for Check and Task Interfaces. /// @@ -40,8 +40,6 @@ class UserCodeInterface : public ConditionAccess /// Destructor virtual ~UserCodeInterface() = default; - void setCustomParameters(const CustomParameters& parameters); - /// \brief Configure the object. /// /// Users can use this method to configure their object. @@ -50,7 +48,7 @@ class UserCodeInterface : public ConditionAccess const std::string& getName() const; void setName(const std::string& name); - void setDatabase(std::unordered_map dbConfig); + void setConfig(UserCodeConfig config); protected: /// \brief Call it to enable the retrieval of CTP scalers and use `getScalers` later @@ -58,6 +56,8 @@ class UserCodeInterface : public ConditionAccess /// \brief Get the scalers's value for the given source double getScalersValue(std::string sourceName, size_t runNumber); + void setDatabase(std::unordered_map dbConfig); + CustomParameters mCustomParameters; std::string mName; std::shared_ptr mDatabase; //! the repository used by the Framework diff --git a/Framework/src/Aggregator.cxx b/Framework/src/Aggregator.cxx index ac76398dfd..361a85b2e4 100644 --- a/Framework/src/Aggregator.cxx +++ b/Framework/src/Aggregator.cxx @@ -50,9 +50,7 @@ void Aggregator::init() mAggregatorInterface = root_class_factory::create(mAggregatorConfig.moduleName, mAggregatorConfig.className); mAggregatorInterface->setName(mAggregatorConfig.name); - mAggregatorInterface->setCustomParameters(mAggregatorConfig.customParameters); - mAggregatorInterface->setCcdbUrl(mAggregatorConfig.ccdbUrl); - mAggregatorInterface->setDatabase(mAggregatorConfig.repository); + mAggregatorInterface->setConfig(mAggregatorConfig); mAggregatorInterface->configure(); } catch (...) { std::string diagnostic = boost::current_exception_diagnostic_information(); diff --git a/Framework/src/Check.cxx b/Framework/src/Check.cxx index 1e07661c0e..d962f54e10 100644 --- a/Framework/src/Check.cxx +++ b/Framework/src/Check.cxx @@ -71,9 +71,7 @@ void Check::init() try { mCheckInterface = root_class_factory::create(mCheckConfig.moduleName, mCheckConfig.className); mCheckInterface->setName(mCheckConfig.name); - mCheckInterface->setDatabase(mCheckConfig.repository); - mCheckInterface->setCustomParameters(mCheckConfig.customParameters); - mCheckInterface->setCcdbUrl(mCheckConfig.ccdbUrl); + mCheckInterface->setConfig(mCheckConfig); } catch (...) { std::string diagnostic = boost::current_exception_diagnostic_information(); ILOG(Fatal, Ops) << "Unexpected exception, diagnostic information follows: " diff --git a/Framework/src/CtpScalers.cxx b/Framework/src/CtpScalers.cxx index 8c10006f72..0b113229c0 100644 --- a/Framework/src/CtpScalers.cxx +++ b/Framework/src/CtpScalers.cxx @@ -37,7 +37,6 @@ void CtpScalers::enableCtpScalers(size_t runNumber, std::string ccdbUrl) mCtpFetcher = make_shared(); mScalersEnabled = true; auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); - ccdbManager.setURL(ccdbUrl); mCtpFetcher->setupRun(runNumber, &ccdbManager, /*1726300234140*/ getCurrentTimestamp(), false); mScalersLastUpdate = std::chrono::steady_clock::time_point::min(); diff --git a/Framework/src/PostProcessingFactory.cxx b/Framework/src/PostProcessingFactory.cxx index 7b7e2e9348..19a516ffe9 100644 --- a/Framework/src/PostProcessingFactory.cxx +++ b/Framework/src/PostProcessingFactory.cxx @@ -28,8 +28,7 @@ namespace o2::quality_control::postprocessing PostProcessingInterface* PostProcessingFactory::create(const PostProcessingConfig& config) { auto* result = root_class_factory::create(config.moduleName, config.className); - result->setCustomParameters(config.customParameters); - result->setDatabase(config.repository); + result->setConfig(config); return result; } diff --git a/Framework/src/PostProcessingRunner.cxx b/Framework/src/PostProcessingRunner.cxx index b2a7636c82..197683cd94 100644 --- a/Framework/src/PostProcessingRunner.cxx +++ b/Framework/src/PostProcessingRunner.cxx @@ -113,8 +113,6 @@ void PostProcessingRunner::init(const PostProcessingRunnerConfig& runnerConfig, mTask->setObjectsManager(mObjectManager); mTask->setID(mTaskConfig.id); mTask->setName(mTaskConfig.taskName); - mTask->setCustomParameters(mTaskConfig.customParameters); - mTask->setCcdbUrl(mTaskConfig.ccdbUrl); mTask->configure(mRunnerConfig.configTree); } else { throw std::runtime_error("Failed to create the task '" + mTaskConfig.taskName + "' (det " + mTaskConfig.detectorName + ")"); diff --git a/Framework/src/TaskFactory.cxx b/Framework/src/TaskFactory.cxx index ea77ca5356..8e6d939ce3 100644 --- a/Framework/src/TaskFactory.cxx +++ b/Framework/src/TaskFactory.cxx @@ -26,8 +26,7 @@ TaskInterface* TaskFactory::create(const TaskRunnerConfig& taskConfig, std::shar auto* result = root_class_factory::create(taskConfig.moduleName, taskConfig.className); result->setName(taskConfig.taskName); result->setObjectsManager(objectsManager); - result->setCustomParameters(taskConfig.customParameters); - result->setCcdbUrl(taskConfig.ccdbUrl); + result->setConfig(taskConfig); return result; } diff --git a/Framework/src/TaskRunner.cxx b/Framework/src/TaskRunner.cxx index 8450c7f580..835c007c19 100644 --- a/Framework/src/TaskRunner.cxx +++ b/Framework/src/TaskRunner.cxx @@ -74,7 +74,6 @@ using namespace AliceO2::Common; TaskRunner::TaskRunner(const TaskRunnerConfig& config) : mTaskConfig(config) { - o2::ccdb::BasicCCDBManager::instance().setFatalWhenNull(false); } TaskRunner::~TaskRunner() @@ -123,7 +122,6 @@ void TaskRunner::init(InitContext& iCtx) mTask.reset(TaskFactory::create(mTaskConfig, mObjectsManager)); mTask->setMonitoring(mCollector); mTask->setGlobalTrackingDataRequest(mTaskConfig.globalTrackingDataRequest); - mTask->setDatabase(mTaskConfig.repository); // load config params if (!ConfigParamGlo::keyValues.empty()) { diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 862718020b..26f294c2f6 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -18,6 +18,7 @@ #include #include "QualityControl/QcInfoLogger.h" #include "QualityControl/DatabaseFactory.h" +#include "QualityControl/UserCodeConfig.h" using namespace o2::ccdb; using namespace std; @@ -25,9 +26,12 @@ using namespace std; namespace o2::quality_control::core { -void UserCodeInterface::setCustomParameters(const CustomParameters& parameters) +void UserCodeInterface::setConfig(UserCodeConfig config) { - mCustomParameters = parameters; + setDatabase(config.repository); + setCcdbUrl(config.ccdbUrl); + + mCustomParameters = config.customParameters; configure(); } diff --git a/Framework/test/testCheck.cxx b/Framework/test/testCheck.cxx index 06a74f8bf8..3d159110f7 100644 --- a/Framework/test/testCheck.cxx +++ b/Framework/test/testCheck.cxx @@ -149,8 +149,8 @@ TEST_CASE("test_check_activity") "TST", "", {}, - "", - { { "implementation", "CCDB" }, { "host", "" } }, + "alice-ccdb.cern.ch", + { { "implementation", "CCDB" }, { "host", "ccdb-test.cern.ch:8080" } }, "test", UpdatePolicyType::OnAny, {}, diff --git a/Framework/test/testSharedConfig.json b/Framework/test/testSharedConfig.json index 2fba174e91..83684b393f 100644 --- a/Framework/test/testSharedConfig.json +++ b/Framework/test/testSharedConfig.json @@ -14,6 +14,9 @@ }, "monitoring": { "url": "infologger:///debug?qc" + }, + "conditionDB": { + "url": "alice-ccdb.cern.ch" } }, "tasks": { diff --git a/Framework/test/testTaskInterface.cxx b/Framework/test/testTaskInterface.cxx index 7b93b3ad21..60d5846d53 100644 --- a/Framework/test/testTaskInterface.cxx +++ b/Framework/test/testTaskInterface.cxx @@ -172,8 +172,8 @@ TEST_CASE("test_task_factory") "TST", "", {}, - "", - {}, + "alice-ccdb.cern.ch", + { { "implementation", "CCDB" }, { "host", "ccdb-test.cern.ch:8080" } }, "SkeletonTaskRunner", "skeletonTask", { { 10, 1 } }, diff --git a/Framework/test/testUserCodeInterface.cxx b/Framework/test/testUserCodeInterface.cxx index d7f287cefe..242b7b1ecf 100644 --- a/Framework/test/testUserCodeInterface.cxx +++ b/Framework/test/testUserCodeInterface.cxx @@ -20,6 +20,8 @@ #define BOOST_TEST_MAIN #define BOOST_TEST_DYN_LINK +#include "QualityControl/UserCodeConfig.h" + #include #include #include @@ -82,19 +84,20 @@ BOOST_AUTO_TEST_CASE(test_invoke_all_methods) auto taskName = "Test/pid" + pid; shared_ptr mo1 = make_shared(h1, taskName, "task", "TST"); auto backend = std::make_unique(); - backend->connect("ccdb-test.cern.ch:8080", "", "", ""); + backend->connect("ccdb-test.cern.ch:8080", "QCDB", "", ""); backend->storeMO(mo1); // setting custom parameters should configure CustomParameters customParameters; customParameters["test"] = "asdf"; - testInterface.setCustomParameters(customParameters); + UserCodeConfig config; + config.customParameters = customParameters; + config.repository = {{"host", "ccdb-test.cern.ch:8080"}, {"implementation", "CCDB"}}; + testInterface.setConfig(config); BOOST_CHECK_EQUAL(testInterface.configured, true); BOOST_CHECK_EQUAL(testInterface.get("test"), "asdf"); - testInterface.setCcdbUrl("ccdb-test.cern.ch:8080"); - auto obj = testInterface.retrieveConditionAny("qc/TST/MO/" + taskName + "/asdf"); - BOOST_CHECK_NE(obj, nullptr); + } } /* namespace test */ } /* namespace o2::quality_control */ \ No newline at end of file diff --git a/Modules/Common/test/testMeanIsAbove.cxx b/Modules/Common/test/testMeanIsAbove.cxx index fe4a5964e9..b19a272f70 100644 --- a/Modules/Common/test/testMeanIsAbove.cxx +++ b/Modules/Common/test/testMeanIsAbove.cxx @@ -22,6 +22,8 @@ #define BOOST_TEST_DYN_LINK #include "QualityControl/MonitorObject.h" +#include "QualityControl/UserCodeConfig.h" + #include #include #include @@ -41,7 +43,10 @@ BOOST_AUTO_TEST_CASE(test_checks) MeanIsAbove check; CustomParameters customParameters; customParameters["meanThreshold"] = "1.0"; - check.setCustomParameters(customParameters); + UserCodeConfig config; + config.customParameters = customParameters; + config.repository = {{"host", "ccdb-test.cern.ch:8080"}, {"implementation", "CCDB"}}; + check.setConfig(config); Quality quality = check.check(&moMap); BOOST_CHECK_EQUAL(quality, Quality::Bad); diff --git a/Modules/Example/test/testFactory.cxx b/Modules/Example/test/testFactory.cxx index fb4faea2a5..9025b454bc 100644 --- a/Modules/Example/test/testFactory.cxx +++ b/Modules/Example/test/testFactory.cxx @@ -30,6 +30,7 @@ BOOST_AUTO_TEST_CASE(Task_Factory) config.moduleName = "QcCommon"; config.className = "o2::quality_control_modules::example::ExampleTask"; config.detectorName = "DAQ"; + config.repository = {{"host", "ccdb-test.cern.ch:8080"}, {"implementation", "CCDB"}}; auto manager = make_shared(config.taskName, config.className, config.detectorName, config.consulUrl, 0, true); try { gSystem->AddDynamicPath("lib:../../lib:../../../lib:.:"); // add local paths for the test From 4bc18e9301d272ac0705fd8e262d1ab0341a431a Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Fri, 14 Mar 2025 14:10:48 +0100 Subject: [PATCH 11/13] format --- Framework/test/testUserCodeInterface.cxx | 4 +--- Modules/Common/test/testMeanIsAbove.cxx | 2 +- Modules/Example/test/testFactory.cxx | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Framework/test/testUserCodeInterface.cxx b/Framework/test/testUserCodeInterface.cxx index 242b7b1ecf..0a7d046ed0 100644 --- a/Framework/test/testUserCodeInterface.cxx +++ b/Framework/test/testUserCodeInterface.cxx @@ -92,12 +92,10 @@ BOOST_AUTO_TEST_CASE(test_invoke_all_methods) customParameters["test"] = "asdf"; UserCodeConfig config; config.customParameters = customParameters; - config.repository = {{"host", "ccdb-test.cern.ch:8080"}, {"implementation", "CCDB"}}; + config.repository = { { "host", "ccdb-test.cern.ch:8080" }, { "implementation", "CCDB" } }; testInterface.setConfig(config); BOOST_CHECK_EQUAL(testInterface.configured, true); BOOST_CHECK_EQUAL(testInterface.get("test"), "asdf"); - - } } /* namespace test */ } /* namespace o2::quality_control */ \ No newline at end of file diff --git a/Modules/Common/test/testMeanIsAbove.cxx b/Modules/Common/test/testMeanIsAbove.cxx index b19a272f70..6fb0f76103 100644 --- a/Modules/Common/test/testMeanIsAbove.cxx +++ b/Modules/Common/test/testMeanIsAbove.cxx @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(test_checks) customParameters["meanThreshold"] = "1.0"; UserCodeConfig config; config.customParameters = customParameters; - config.repository = {{"host", "ccdb-test.cern.ch:8080"}, {"implementation", "CCDB"}}; + config.repository = { { "host", "ccdb-test.cern.ch:8080" }, { "implementation", "CCDB" } }; check.setConfig(config); Quality quality = check.check(&moMap); BOOST_CHECK_EQUAL(quality, Quality::Bad); diff --git a/Modules/Example/test/testFactory.cxx b/Modules/Example/test/testFactory.cxx index 9025b454bc..a272630d8a 100644 --- a/Modules/Example/test/testFactory.cxx +++ b/Modules/Example/test/testFactory.cxx @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(Task_Factory) config.moduleName = "QcCommon"; config.className = "o2::quality_control_modules::example::ExampleTask"; config.detectorName = "DAQ"; - config.repository = {{"host", "ccdb-test.cern.ch:8080"}, {"implementation", "CCDB"}}; + config.repository = { { "host", "ccdb-test.cern.ch:8080" }, { "implementation", "CCDB" } }; auto manager = make_shared(config.taskName, config.className, config.detectorName, config.consulUrl, 0, true); try { gSystem->AddDynamicPath("lib:../../lib:../../../lib:.:"); // add local paths for the test From e5b58981f3b9e6ff09507171a9e8ea9ad70ea0a1 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Fri, 14 Mar 2025 15:44:04 +0100 Subject: [PATCH 12/13] Possibility to set a different source repo for the scalers. Useful to test. --- Framework/basic.json | 8 +++++++- Framework/include/QualityControl/CommonSpec.h | 1 + Framework/include/QualityControl/CtpScalers.h | 7 +++---- Framework/include/QualityControl/UserCodeConfig.h | 2 +- .../include/QualityControl/UserCodeInterface.h | 2 +- Framework/src/Aggregator.cxx | 1 + Framework/src/Check.cxx | 1 + Framework/src/CtpScalers.cxx | 6 +++--- Framework/src/InfrastructureSpecReader.cxx | 4 +++- Framework/src/TaskRunnerFactory.cxx | 1 + Framework/src/UserCodeInterface.cxx | 15 ++++++++++++--- Framework/test/testCheck.cxx | 1 + Framework/test/testTaskInterface.cxx | 1 + 13 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Framework/basic.json b/Framework/basic.json index 1f71aa047e..068d684b5e 100644 --- a/Framework/basic.json +++ b/Framework/basic.json @@ -23,7 +23,7 @@ "url": "" }, "conditionDB": { - "url": "ccdb-test.cern.ch:8080" + "url": "alice-ccdb.cern.ch" }, "infologger": { "": "Configuration of the Infologger (optional).", "filterDiscardDebug": "false", "": "Set to true to discard debug and trace messages (default: false)", @@ -34,6 +34,12 @@ }, "bookkeeping": { "url": "" + }, + "ctpscalers": { + "sourceRepo": { + "implementation": "CCDB", + "host": "ali-qcdb-gpn.cern.ch:8083" + } } }, "tasks": { diff --git a/Framework/include/QualityControl/CommonSpec.h b/Framework/include/QualityControl/CommonSpec.h index 7041c346fa..2d8d39cae4 100644 --- a/Framework/include/QualityControl/CommonSpec.h +++ b/Framework/include/QualityControl/CommonSpec.h @@ -44,6 +44,7 @@ struct CommonSpec { LogDiscardParameters infologgerDiscardParameters; double postprocessingPeriod = 30.0; std::string bookkeepingUrl; + std::unordered_map ctpScalersSourceRepo; }; } // namespace o2::quality_control::core diff --git a/Framework/include/QualityControl/CtpScalers.h b/Framework/include/QualityControl/CtpScalers.h index 94e4a7ebe3..7f0e2504f9 100644 --- a/Framework/include/QualityControl/CtpScalers.h +++ b/Framework/include/QualityControl/CtpScalers.h @@ -39,9 +39,9 @@ class CtpScalers /// \brief Get the scalers's value for the given source double getScalersValue(std::string sourceName, size_t runNumber); - void setDatabase(std::shared_ptr database) + void setScalersRepo(std::shared_ptr database) { - mDatabase = database; + mScalersRepo = database; } private: @@ -52,9 +52,8 @@ class CtpScalers std::shared_ptr mCtpFetcher; std::chrono::steady_clock::time_point mScalersLastUpdate; bool mScalersEnabled = false; - std::shared_ptr mDatabase; //! the repository used by the Framework + std::shared_ptr mScalersRepo; //! where to get the scalers from - private: ClassDef(CtpScalers, 1) }; diff --git a/Framework/include/QualityControl/UserCodeConfig.h b/Framework/include/QualityControl/UserCodeConfig.h index b57241fdad..ee5716246b 100644 --- a/Framework/include/QualityControl/UserCodeConfig.h +++ b/Framework/include/QualityControl/UserCodeConfig.h @@ -18,7 +18,6 @@ #define QUALITYCONTROL_USERCODECONFIG_H #include "QualityControl/CustomParameters.h" -#include "QualityControl/stringUtils.h" namespace o2::quality_control::core { @@ -32,6 +31,7 @@ struct UserCodeConfig { CustomParameters customParameters; std::string ccdbUrl; std::unordered_map repository; // we need the full config of the database to build the database in the subclasses + std::unordered_map ctpScalersSourceRepo; }; } // namespace o2::quality_control::core diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index 79a9b818e6..1ef4d6e4e1 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -48,7 +48,7 @@ class UserCodeInterface : public ConditionAccess const std::string& getName() const; void setName(const std::string& name); - void setConfig(UserCodeConfig config); + void setConfig(const UserCodeConfig& config); protected: /// \brief Call it to enable the retrieval of CTP scalers and use `getScalers` later diff --git a/Framework/src/Aggregator.cxx b/Framework/src/Aggregator.cxx index 361a85b2e4..c8b1891ebe 100644 --- a/Framework/src/Aggregator.cxx +++ b/Framework/src/Aggregator.cxx @@ -223,6 +223,7 @@ AggregatorConfig Aggregator::extractConfig(const core::CommonSpec& commonSpec, c aggregatorSpec.customParameters, commonSpec.conditionDBUrl, commonSpec.database, + commonSpec.ctpScalersSourceRepo, aggregatorSpec.aggregatorName, updatePolicy, std::move(objectNames), diff --git a/Framework/src/Check.cxx b/Framework/src/Check.cxx index d962f54e10..142c2b9662 100644 --- a/Framework/src/Check.cxx +++ b/Framework/src/Check.cxx @@ -257,6 +257,7 @@ CheckConfig Check::extractConfig(const CommonSpec& commonSpec, const CheckSpec& checkSpec.customParameters, commonSpec.conditionDBUrl, commonSpec.database, + commonSpec.ctpScalersSourceRepo, checkSpec.checkName, updatePolicy, std::move(objectNames), diff --git a/Framework/src/CtpScalers.cxx b/Framework/src/CtpScalers.cxx index 0b113229c0..445a2f0fcf 100644 --- a/Framework/src/CtpScalers.cxx +++ b/Framework/src/CtpScalers.cxx @@ -55,7 +55,7 @@ bool CtpScalers::updateScalers(size_t runNumber) } ILOG(Debug, Devel) << "Updating scalers." << ENDM; - if (!mDatabase) { + if (!mScalersRepo) { ILOG(Error, Devel) << "Database not set ! Cannot update scalers." << ENDM; mScalersEnabled = false; return false; @@ -73,8 +73,8 @@ bool CtpScalers::updateScalers(size_t runNumber) std::map meta; meta["runNumber"] = std::to_string(runNumber); std::map headers; - auto validity = mDatabase->getLatestObjectValidity("qc/CTP/Scalers", meta); - void* rawResult = mDatabase->retrieveAny(typeid(o2::ctp::CTPRunScalers), "qc/CTP/Scalers", meta, validity.getMax() - 1, &headers); + auto validity = mScalersRepo->getLatestObjectValidity("qc/CTP/Scalers", meta); + void* rawResult = mScalersRepo->retrieveAny(typeid(o2::ctp::CTPRunScalers), "qc/CTP/Scalers", meta, validity.getMax() - 1, &headers); if (!rawResult) { ILOG(Error, Devel) << "Could not retrieve the CTP Scalers" << ENDM; return false; diff --git a/Framework/src/InfrastructureSpecReader.cxx b/Framework/src/InfrastructureSpecReader.cxx index d22d140229..02c7842e88 100644 --- a/Framework/src/InfrastructureSpecReader.cxx +++ b/Framework/src/InfrastructureSpecReader.cxx @@ -81,7 +81,9 @@ CommonSpec InfrastructureSpecReader::readSpecEntry(const std::string }; spec.postprocessingPeriod = commonTree.get("postprocessing.periodSeconds", spec.postprocessingPeriod); spec.bookkeepingUrl = commonTree.get("bookkeeping.url", spec.bookkeepingUrl); - + for (const auto& [key, value] : commonTree.get_child("ctpscalers.sourceRepo")) { + spec.ctpScalersSourceRepo.emplace(key, value.get_value()); + } return spec; } diff --git a/Framework/src/TaskRunnerFactory.cxx b/Framework/src/TaskRunnerFactory.cxx index 654dcb1bae..533dcfc2ac 100644 --- a/Framework/src/TaskRunnerFactory.cxx +++ b/Framework/src/TaskRunnerFactory.cxx @@ -175,6 +175,7 @@ TaskRunnerConfig TaskRunnerFactory::extractConfig(const CommonSpec& globalConfig taskSpec.customParameters, globalConfig.conditionDBUrl, globalConfig.database, + globalConfig.ctpScalersSourceRepo, deviceName, taskSpec.taskName, multipleCycleDurations, diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 26f294c2f6..8fc9607a56 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -26,11 +26,22 @@ using namespace std; namespace o2::quality_control::core { -void UserCodeInterface::setConfig(UserCodeConfig config) +void UserCodeInterface::setConfig(const UserCodeConfig& config) { setDatabase(config.repository); setCcdbUrl(config.ccdbUrl); + // if a specific repository is provided as source for the scalers we use it otherwise we use the normal database + std::shared_ptr ctpSourceRepo; + if (auto ctpScalersSourceRepo = config.ctpScalersSourceRepo; + ctpScalersSourceRepo.size() > 0 && ctpScalersSourceRepo.contains("implementation") && config.ctpScalersSourceRepo.contains("host")) { + ctpSourceRepo = repository::DatabaseFactory::create(ctpScalersSourceRepo.at("implementation")); + ctpSourceRepo->connect(ctpScalersSourceRepo); + } else { + ctpSourceRepo = mDatabase; + } + mCtpScalers.setScalersRepo(ctpSourceRepo); + mCustomParameters = config.customParameters; configure(); } @@ -65,8 +76,6 @@ void UserCodeInterface::setDatabase(std::unordered_map mDatabase = repository::DatabaseFactory::create(dbConfig.at("implementation")); mDatabase->connect(dbConfig); ILOG(Debug, Devel) << "Database that is going to be used > Implementation : " << dbConfig.at("implementation") << " / Host : " << dbConfig.at("host") << ENDM; - - mCtpScalers.setDatabase(mDatabase); } } // namespace o2::quality_control::core \ No newline at end of file diff --git a/Framework/test/testCheck.cxx b/Framework/test/testCheck.cxx index 3d159110f7..ec4d43881d 100644 --- a/Framework/test/testCheck.cxx +++ b/Framework/test/testCheck.cxx @@ -151,6 +151,7 @@ TEST_CASE("test_check_activity") {}, "alice-ccdb.cern.ch", { { "implementation", "CCDB" }, { "host", "ccdb-test.cern.ch:8080" } }, + { { "implementation", "CCDB" }, { "host", "ccdb-test.cern.ch:8080" } }, "test", UpdatePolicyType::OnAny, {}, diff --git a/Framework/test/testTaskInterface.cxx b/Framework/test/testTaskInterface.cxx index 60d5846d53..f6fc612934 100644 --- a/Framework/test/testTaskInterface.cxx +++ b/Framework/test/testTaskInterface.cxx @@ -174,6 +174,7 @@ TEST_CASE("test_task_factory") {}, "alice-ccdb.cern.ch", { { "implementation", "CCDB" }, { "host", "ccdb-test.cern.ch:8080" } }, + { { "implementation", "CCDB" }, { "host", "ccdb-test.cern.ch:8080" } }, "SkeletonTaskRunner", "skeletonTask", { { 10, 1 } }, From 6f9c473fd3b6fac4f5ed9f3f256408476196f997 Mon Sep 17 00:00:00 2001 From: Barthelemy Date: Fri, 14 Mar 2025 16:21:12 +0100 Subject: [PATCH 13/13] clean up and doc --- Framework/include/QualityControl/CtpScalers.h | 2 +- .../QualityControl/UserCodeInterface.h | 2 +- Framework/src/CtpScalers.cxx | 5 ++--- Framework/src/UserCodeInterface.cxx | 4 ++-- Modules/Skeleton/src/SkeletonCheck.cxx | 3 +-- doc/Advanced.md | 22 +++++++++++++++++-- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Framework/include/QualityControl/CtpScalers.h b/Framework/include/QualityControl/CtpScalers.h index 7f0e2504f9..7303b3e251 100644 --- a/Framework/include/QualityControl/CtpScalers.h +++ b/Framework/include/QualityControl/CtpScalers.h @@ -35,7 +35,7 @@ class CtpScalers virtual ~CtpScalers() = default; /// \brief Call it to enable the retrieval of CTP scalers and use `getScalers` later - void enableCtpScalers(size_t runNumber, std::string ccdbUrl); + void enableCtpScalers(size_t runNumber); /// \brief Get the scalers's value for the given source double getScalersValue(std::string sourceName, size_t runNumber); diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index 1ef4d6e4e1..68dc8c1b12 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -52,7 +52,7 @@ class UserCodeInterface : public ConditionAccess protected: /// \brief Call it to enable the retrieval of CTP scalers and use `getScalers` later - void enableCtpScalers(size_t runNumber, std::string ccdbUrl); + void enableCtpScalers(size_t runNumber); /// \brief Get the scalers's value for the given source double getScalersValue(std::string sourceName, size_t runNumber); diff --git a/Framework/src/CtpScalers.cxx b/Framework/src/CtpScalers.cxx index 445a2f0fcf..8d40c9db7d 100644 --- a/Framework/src/CtpScalers.cxx +++ b/Framework/src/CtpScalers.cxx @@ -24,7 +24,7 @@ using namespace std; namespace o2::quality_control::core { -void CtpScalers::enableCtpScalers(size_t runNumber, std::string ccdbUrl) +void CtpScalers::enableCtpScalers(size_t runNumber) { // bail if we are in async auto deploymentMode = framework::DefaultsHelpers::deploymentMode(); @@ -99,8 +99,7 @@ double CtpScalers::getScalersValue(std::string sourceName, size_t runNumber) ILOG(Debug, Devel) << "Could not update the scalers, returning 0" << ENDM; return 0; } - auto& ccdbManager = o2::ccdb::BasicCCDBManager::instance(); - auto result = mCtpFetcher->fetchNoPuCorr(&ccdbManager, getCurrentTimestamp() * 1000, runNumber, sourceName); + auto result = mCtpFetcher->fetchNoPuCorr(&o2::ccdb::BasicCCDBManager::instance(), getCurrentTimestamp() * 1000, runNumber, sourceName); ILOG(Debug, Devel) << "Returning scaler value : " << result << ENDM; return result; } diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 8fc9607a56..a02da63219 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -56,9 +56,9 @@ void UserCodeInterface::setName(const std::string& name) mName = name; } -void UserCodeInterface::enableCtpScalers(size_t runNumber, std::string ccdbUrl) +void UserCodeInterface::enableCtpScalers(size_t runNumber) { - mCtpScalers.enableCtpScalers(runNumber, ccdbUrl); + mCtpScalers.enableCtpScalers(runNumber); } double UserCodeInterface::getScalersValue(std::string sourceName, size_t runNumber) diff --git a/Modules/Skeleton/src/SkeletonCheck.cxx b/Modules/Skeleton/src/SkeletonCheck.cxx index eef9552566..222d996a1e 100644 --- a/Modules/Skeleton/src/SkeletonCheck.cxx +++ b/Modules/Skeleton/src/SkeletonCheck.cxx @@ -21,7 +21,6 @@ // ROOT #include -#include #include using namespace std; @@ -127,7 +126,7 @@ void SkeletonCheck::startOfActivity(const Activity& activity) // THUS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED. ILOG(Debug, Devel) << "SkeletonCheck::start : " << activity.mId << ENDM; mActivity = make_shared(activity); - enableCtpScalers(activity.mId, "alice-ccdb.cern.ch"); // TODO get it from the config + enableCtpScalers(activity.mId); } void SkeletonCheck::endOfActivity(const Activity& activity) diff --git a/doc/Advanced.md b/doc/Advanced.md index 4b7b719ee4..1c249e2281 100644 --- a/doc/Advanced.md +++ b/doc/Advanced.md @@ -1679,6 +1679,12 @@ the "tasks" path. "canProcessClusters" : "TPC", "": "clusters that the QC task can process", "requestClusters" : "TPC", "": "clusters that the QC task should process", "mc" : "false", "": "mc boolean flag for the data request" + }, + "ctpscalers": { + "sourceRepo": { + "implementation": "CCDB", + "host": "ali-qcdb-gpn.cern.ch:8083" + } } } } @@ -2003,18 +2009,30 @@ In consul go to `o2/runtime/aliecs/defaults` and modify the file corresponding t User code can access CTP scalers in the following way : ``` // in start of activity - enableCtpScalers(activity.mId, "alice-ccdb.cern.ch"); // TODO get it from the config + enableCtpScalers(activity.mId); // in your e.g. check(...) auto t0vtx = getScalersValue("T0VTX", mActivity->mId); ILOG(Info, Devel) << "\"T0VTX\" : " << t0vtx << ENDM; ``` +By default the Scalers are pulled from the QCDB. However, for the purpose of testing, one can also set a different +repo for it : +``` + "ctpscalers": { + "sourceRepo": { + "implementation": "CCDB", + "host": "ali-qcdb-gpn.cern.ch:8083" + } + } +``` +This way, the data can be pulled from production but the storage is still in the test database. + ### Limitations It does not work in async. -### Implementation +### Implementation details `CTP proxy` publishes the scalers every 5 minutes into the QCDB at [`qc/CTP/Scalers`](http://ali-qcdb-gpn.cern.ch:8083/browse/qc/CTP/Scalers?report=true). They are cleaned up after 3 days. Thus we query from the QCDB yet we also need access to CCDB to setup the `CTPRateFetcher`.