diff --git a/Framework/include/QualityControl/Actor.h b/Framework/include/QualityControl/Actor.h index 55fb1f9a17..84d1e3ed0c 100644 --- a/Framework/include/QualityControl/Actor.h +++ b/Framework/include/QualityControl/Actor.h @@ -138,13 +138,14 @@ class Actor void init(framework::InitContext& ictx) { impl::handleExceptions("process", [&] { - // we set the fallback activity. fields might get overwritten once runtime values become available - mActivity = mServicesConfig.activity; + // we set the fallback activity and overwrite its fields with the runtime values which are already available. + // some fields (e.g. the run number) might get overwritten again at start. + mActivity = computeActivity(ictx.services(), mServicesConfig.activity); initServices(ictx); initDplCallbacks(ictx); - concreteActor().onInit(ictx); + concreteActor().onInit(ictx, mActivity); }); } @@ -157,7 +158,7 @@ class Actor protected: // mandatory methods to be implemented by concrete actor - void onInit(framework::InitContext&) = delete; + void onInit(framework::InitContext&, const Activity&) = delete; void onProcess(framework::ProcessingContext&) = delete; // mandatory methods to be implemented by concrete actor if specific features are enabled @@ -210,7 +211,7 @@ class Actor static_assert(std::derived_from>); // mandatory methods static_assert(requires(ConcreteActor& actor, framework::ProcessingContext& pCtx) { { actor.onProcess(pCtx) } -> std::convertible_to; }); - static_assert(requires(ConcreteActor& actor, framework::InitContext& iCtx) { { actor.onInit(iCtx) } -> std::convertible_to; }); + static_assert(requires(ConcreteActor& actor, framework::InitContext& iCtx, const Activity& activity) { { actor.onInit(iCtx, activity) } -> std::convertible_to; }); // mandatory if specific features are enabled if constexpr (traits::sDetectorSpecific) { diff --git a/Framework/include/QualityControl/Aggregator.h b/Framework/include/QualityControl/Aggregator.h index 34c5f6dcd6..052a252380 100644 --- a/Framework/include/QualityControl/Aggregator.h +++ b/Framework/include/QualityControl/Aggregator.h @@ -64,7 +64,7 @@ class Aggregator /** * \brief Initialize the aggregator */ - void init(); + void init(const core::Activity& activity); o2::quality_control::core::QualityObjectsType aggregate(core::QualityObjectsMapType& qoMap, const core::Activity& defaultActivity = {}); diff --git a/Framework/include/QualityControl/AggregatorInterface.h b/Framework/include/QualityControl/AggregatorInterface.h index c91fc1da1b..5b5e5a6d42 100644 --- a/Framework/include/QualityControl/AggregatorInterface.h +++ b/Framework/include/QualityControl/AggregatorInterface.h @@ -51,6 +51,16 @@ class AggregatorInterface : public o2::quality_control::core::UserCodeInterface /// @return The new qualities, associated with a name. virtual std::map aggregate(const core::QCInputs& data); + /// \brief Configure the object, called each time mCustomParameters is updated (including the first time). + /// + /// This is the recommended method to override. The activity (e.g. run type and beam type) is provided so that + /// the custom parameters for the right run and beam type can be selected, e.g. with mCustomParameters.at("key", activity). + virtual void configure(const core::Activity& activity) override; + + /// \brief Legacy variant of configure(const Activity&), which does not receive the activity. + /// It is still called by the default implementation of configure(const Activity&), so existing code keeps working. + virtual void configure() override; + virtual void startOfActivity(const core::Activity& activity); virtual void endOfActivity(const core::Activity& activity); diff --git a/Framework/include/QualityControl/AggregatorRunner.h b/Framework/include/QualityControl/AggregatorRunner.h index 4066100325..5fe0128cf0 100644 --- a/Framework/include/QualityControl/AggregatorRunner.h +++ b/Framework/include/QualityControl/AggregatorRunner.h @@ -142,7 +142,7 @@ class AggregatorRunner : public framework::Task void initDatabase(); void initMonitoring(); void initLibraries(); - void initAggregators(); + void initAggregators(const core::Activity& activity); /** * Reorder the aggregators stored in mAggregators. diff --git a/Framework/include/QualityControl/Check.h b/Framework/include/QualityControl/Check.h index c53eede8ba..270b5751ed 100644 --- a/Framework/include/QualityControl/Check.h +++ b/Framework/include/QualityControl/Check.h @@ -61,7 +61,7 @@ class Check * \brief Initialize the check state * Expected to run in the init phase of the FairDevice */ - void init(); + void init(const core::Activity& activity); void reset(); core::QualityObjectsType check(std::map>& moMap); diff --git a/Framework/include/QualityControl/CheckInterface.h b/Framework/include/QualityControl/CheckInterface.h index 16d8ac05ab..aa84dddb08 100644 --- a/Framework/include/QualityControl/CheckInterface.h +++ b/Framework/include/QualityControl/CheckInterface.h @@ -84,7 +84,14 @@ class CheckInterface : public core::UserCodeInterface virtual void endOfActivity(const core::Activity& activity); // not fully abstract because we don't want to change all the existing subclasses protected: - /// \brief Called each time mCustomParameters is updated. + /// \brief Configure the object, called each time mCustomParameters is updated (including the first time). + /// + /// This is the recommended method to override. The activity (e.g. run type and beam type) is provided so that + /// the custom parameters for the right run and beam type can be selected, e.g. with mCustomParameters.at("key", activity). + virtual void configure(const core::Activity& activity) override; + + /// \brief Legacy variant of configure(const Activity&), which does not receive the activity. + /// It is still called by the default implementation of configure(const Activity&), so existing code keeps working. virtual void configure() override; /// \brief Retrieve a reference plot at the provided path, matching the give activity and for the provided run. diff --git a/Framework/include/QualityControl/LateTaskFactory.h b/Framework/include/QualityControl/LateTaskFactory.h index 9d6f81600d..5f36de89a6 100644 --- a/Framework/include/QualityControl/LateTaskFactory.h +++ b/Framework/include/QualityControl/LateTaskFactory.h @@ -45,8 +45,7 @@ class LateTaskFactory { auto* result = root_class_factory::create(taskConfig.moduleName, taskConfig.className); result->setName(taskConfig.name); - result->setObjectsManager(objectsManager); - result->setCustomParameters(taskConfig.customParameters); + result->setObjectsManager(objectsManager); // fixme: we do it twice, here and in LateTaskRunner. pick one result->setCcdbUrl(taskConfig.ccdbUrl); return result; diff --git a/Framework/include/QualityControl/LateTaskInterface.h b/Framework/include/QualityControl/LateTaskInterface.h index 5fa4f8523c..0a4436038e 100644 --- a/Framework/include/QualityControl/LateTaskInterface.h +++ b/Framework/include/QualityControl/LateTaskInterface.h @@ -96,7 +96,14 @@ class LateTaskInterface : public UserCodeInterface /// Invoked at the reset() transition in synchronous mode and during workflow cleanup in asynchronous mode virtual void reset() = 0; - /// \brief Called each time mCustomParameters is updated. + /// \brief Configure the object, called each time mCustomParameters is updated (including the first time). + /// + /// This is the recommended method to override. The activity (e.g. run type and beam type) is provided so that + /// the custom parameters for the right run and beam type can be selected, e.g. with mCustomParameters.at("key", activity). + virtual void configure(const Activity& activity) override; + + /// \brief Legacy variant of configure(const Activity&), which does not receive the activity. + /// It is still called by the default implementation of configure(const Activity&), so existing code keeps working. virtual void configure() override; // Setters and getters diff --git a/Framework/include/QualityControl/LateTaskRunner.h b/Framework/include/QualityControl/LateTaskRunner.h index f649d3f602..c9c652c78a 100644 --- a/Framework/include/QualityControl/LateTaskRunner.h +++ b/Framework/include/QualityControl/LateTaskRunner.h @@ -41,7 +41,7 @@ class LateTaskRunner : public Actor void onStart(framework::ServiceRegistryRef services, const Activity& activity); void onStop(framework::ServiceRegistryRef services, const Activity& activity); - void onInit(framework::InitContext& iCtx); + void onInit(framework::InitContext& iCtx, const Activity& activity); void onProcess(framework::ProcessingContext& pCtx); void onEndOfStream(framework::EndOfStreamContext& eosContext, const Activity& activity); diff --git a/Framework/include/QualityControl/PostProcessingInterface.h b/Framework/include/QualityControl/PostProcessingInterface.h index e253f9422c..72ddfe1d53 100644 --- a/Framework/include/QualityControl/PostProcessingInterface.h +++ b/Framework/include/QualityControl/PostProcessingInterface.h @@ -42,8 +42,14 @@ class PostProcessingInterface : public core::UserCodeInterface /// \brief Configure the task with custom parameters, optional for PostProcessingInterface /// - /// Users can use this method to configure their task with custom parameters + /// This is the recommended method to override. The activity (e.g. run type and beam type) is provided so that + /// the custom parameters for the right run and beam type can be selected, e.g. with mCustomParameters.at("key", activity). + /// For tasks running outside of DPL, the activity comes from the configuration file. /// It is called each time mCustomParameters is updated, including the first time it is read. + virtual void configure(const core::Activity& activity) override; + + /// \brief Legacy variant of configure(const Activity&), which does not receive the activity. + /// It is still called by the default implementation of configure(const Activity&), so existing code keeps working. virtual void configure() override; /// \brief Configuration of a post-processing task. diff --git a/Framework/include/QualityControl/TaskInterface.h b/Framework/include/QualityControl/TaskInterface.h index 2a0caaf7f3..3cbc9e91a1 100644 --- a/Framework/include/QualityControl/TaskInterface.h +++ b/Framework/include/QualityControl/TaskInterface.h @@ -88,7 +88,14 @@ class TaskInterface : public UserCodeInterface virtual void finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj); - /// \brief Called each time mCustomParameters is updated. + /// \brief Configure the object, called each time mCustomParameters is updated (including the first time). + /// + /// This is the recommended method to override. The activity (e.g. run type and beam type) is provided so that + /// the custom parameters for the right run and beam type can be selected, e.g. with mCustomParameters.at("key", activity). + virtual void configure(const Activity& activity) override; + + /// \brief Legacy variant of configure(const Activity&), which does not receive the activity. + /// It is still called by the default implementation of configure(const Activity&), so existing code keeps working. virtual void configure() override; // Setters and getters diff --git a/Framework/include/QualityControl/UserCodeInterface.h b/Framework/include/QualityControl/UserCodeInterface.h index 8cd26dd310..60b1ced5a4 100644 --- a/Framework/include/QualityControl/UserCodeInterface.h +++ b/Framework/include/QualityControl/UserCodeInterface.h @@ -21,6 +21,7 @@ #include #include +#include "QualityControl/Activity.h" #include "QualityControl/ConditionAccess.h" #include "QualityControl/CustomParameters.h" #include "QualityControl/DatabaseInterface.h" @@ -39,14 +40,30 @@ class UserCodeInterface : public ConditionAccess /// Destructor virtual ~UserCodeInterface() = default; - void setCustomParameters(const CustomParameters& parameters); + /// \brief Set the custom parameters and configure the object. + /// + /// Stores the parameters and calls configure(const Activity&). + /// \param parameters the custom parameters, which may differ depending on the run type and beam type + /// \param activity the activity known at a given time (e.g. providing run type and beam type for CustomParameters) + void setCustomParameters(const CustomParameters& parameters, const Activity& activity); /// \brief Configure the object. /// /// Users can use this method to configure their object. /// It is called each time mCustomParameters is updated, including the first time it is read. + /// If the user needs the run type, the beam type or other activity fields to choose the right custom parameters, + /// they should override configure(const Activity&) instead. virtual void configure() = 0; + /// \brief Configure the object, knowing the Activity. + /// + /// Users can override this method to configure their object using the Activity which is known at initialization, + /// e.g. to retrieve values from mCustomParameters for the actual run type and beam type with + /// mCustomParameters.at("key", activity). + /// It is called each time mCustomParameters is updated, including the first time it is read. + /// The default implementation calls configure(), so overriding configure() alone remains valid. + virtual void configure(const Activity& activity); + const std::string& getName() const; void setName(const std::string& name); void setDatabase(std::unordered_map dbConfig); diff --git a/Framework/src/Aggregator.cxx b/Framework/src/Aggregator.cxx index f5d5e30f62..d810b875d2 100644 --- a/Framework/src/Aggregator.cxx +++ b/Framework/src/Aggregator.cxx @@ -45,7 +45,7 @@ Aggregator::Aggregator(AggregatorConfig configuration) : mAggregatorConfig(std:: { } -void Aggregator::init() +void Aggregator::init(const core::Activity& activity) { try { ILOG(Info, Devel) << "Instantiating the user code for aggregator " << mAggregatorConfig.name @@ -53,7 +53,7 @@ void Aggregator::init() mAggregatorInterface = root_class_factory::create(mAggregatorConfig.moduleName, mAggregatorConfig.className); mAggregatorInterface->setName(mAggregatorConfig.name); - mAggregatorInterface->setCustomParameters(mAggregatorConfig.customParameters); + mAggregatorInterface->setCustomParameters(mAggregatorConfig.customParameters, activity); mAggregatorInterface->setCcdbUrl(mAggregatorConfig.ccdbUrl); mAggregatorInterface->setDatabase(mAggregatorConfig.repository); mAggregatorInterface->configure(); diff --git a/Framework/src/AggregatorInterface.cxx b/Framework/src/AggregatorInterface.cxx index 26140fb4ef..46247c69a9 100644 --- a/Framework/src/AggregatorInterface.cxx +++ b/Framework/src/AggregatorInterface.cxx @@ -34,6 +34,17 @@ std::map AggregatorInterface::aggregate(const core:: return {}; } +void AggregatorInterface::configure(const Activity& activity) +{ + // calls the legacy variant, so that user code overriding only that one keeps working + configure(); +} + +void AggregatorInterface::configure() +{ + // noop, override it if you want. +} + void AggregatorInterface::startOfActivity(const Activity& activity) { // noop, override it if you want. diff --git a/Framework/src/AggregatorRunner.cxx b/Framework/src/AggregatorRunner.cxx index 1e27cfea01..5f566c0f49 100644 --- a/Framework/src/AggregatorRunner.cxx +++ b/Framework/src/AggregatorRunner.cxx @@ -108,6 +108,7 @@ void AggregatorRunner::init(framework::InitContext& iCtx) Bookkeeping::getInstance().init(mRunnerConfig.bookkeepingUrl); try { + const auto activity = computeActivity(iCtx.services(), mRunnerConfig.fallbackActivity); initLibraries(); // we have to load libraries before we load ConfigurableParams, otherwise the corresponding ROOT dictionaries won't be found // load config params if (!ConfigParamGlo::keyValues.empty()) { @@ -115,7 +116,7 @@ void AggregatorRunner::init(framework::InitContext& iCtx) } initDatabase(); initMonitoring(); - initAggregators(); + initAggregators(activity); } catch (...) { ILOG(Fatal) << "Unexpected exception during initialization: " << current_diagnostic(true) << ENDM; @@ -240,7 +241,7 @@ void AggregatorRunner::initMonitoring() mTimer.reset(1000000); // 10 s. } -void AggregatorRunner::initAggregators() +void AggregatorRunner::initAggregators(const core::Activity& activity) { ILOG(Info, Devel) << "Initialization of the aggregators" << ENDM; @@ -249,7 +250,7 @@ void AggregatorRunner::initAggregators() ILOG(Info, Devel) << ">> Aggregator name : " << aggregatorConfig.name << ENDM; try { auto aggregator = make_shared(aggregatorConfig); - aggregator->init(); + aggregator->init(activity); mUpdatePolicyManager.addPolicy(aggregator->getName(), aggregator->getUpdatePolicyType(), aggregator->getObjectsNames(), diff --git a/Framework/src/Check.cxx b/Framework/src/Check.cxx index 5620e27605..07fc250313 100644 --- a/Framework/src/Check.cxx +++ b/Framework/src/Check.cxx @@ -50,13 +50,13 @@ Check::Check(CheckConfig config) { } -void Check::init() +void Check::init(const core::Activity& activity) { try { mCheckInterface = root_class_factory::create(mCheckConfig.moduleName, mCheckConfig.className); mCheckInterface->setName(mCheckConfig.name); mCheckInterface->setDatabase(mCheckConfig.repository); - mCheckInterface->setCustomParameters(mCheckConfig.customParameters); + mCheckInterface->setCustomParameters(mCheckConfig.customParameters, activity); mCheckInterface->setCcdbUrl(mCheckConfig.ccdbUrl); } catch (...) { std::string diagnostic = boost::current_exception_diagnostic_information(); diff --git a/Framework/src/CheckInterface.cxx b/Framework/src/CheckInterface.cxx index 3a35edf8cb..10a6e58556 100644 --- a/Framework/src/CheckInterface.cxx +++ b/Framework/src/CheckInterface.cxx @@ -37,6 +37,12 @@ core::Quality CheckInterface::check(const core::QCInputs& data) return core::Quality{}; }; +void CheckInterface::configure(const core::Activity& activity) +{ + // calls the legacy variant, so that user code overriding only that one keeps working + configure(); +} + void CheckInterface::configure() { // noop, override it if you want. diff --git a/Framework/src/CheckRunner.cxx b/Framework/src/CheckRunner.cxx index 35e34f8de6..b8f421413f 100644 --- a/Framework/src/CheckRunner.cxx +++ b/Framework/src/CheckRunner.cxx @@ -182,9 +182,11 @@ void CheckRunner::init(framework::InitContext& iCtx) iCtx.services().get().set([this]() { reset(); }); iCtx.services().get().set([this]() { stop(); }); + const auto activity = computeActivity(iCtx.services(), mConfig.fallbackActivity); + updatePolicyManager.reset(); for (auto& [checkName, check] : mChecks) { - check.init(); + check.init(activity); updatePolicyManager.addPolicy(check.getName(), check.getUpdatePolicyType(), check.getObjectsNames(), check.getAllObjectsOption(), false); } } catch (...) { diff --git a/Framework/src/LateTaskInterface.cxx b/Framework/src/LateTaskInterface.cxx index 684a49a7ff..104bddebca 100644 --- a/Framework/src/LateTaskInterface.cxx +++ b/Framework/src/LateTaskInterface.cxx @@ -51,6 +51,12 @@ void LateTaskInterface::finaliseCCDB(framework::ConcreteDataMatcher& matcher, vo { } */ +void LateTaskInterface::configure(const Activity& activity) +{ + // calls the legacy variant, so that user code overriding only that one keeps working + configure(); +} + void LateTaskInterface::configure() { // noop, override it if you want. diff --git a/Framework/src/LateTaskRunner.cxx b/Framework/src/LateTaskRunner.cxx index 1f2c74f0e8..bd0fdf8277 100644 --- a/Framework/src/LateTaskRunner.cxx +++ b/Framework/src/LateTaskRunner.cxx @@ -46,7 +46,7 @@ LateTaskRunner::LateTaskRunner(const ServicesConfig& servicesConfig, const LateT { } -void LateTaskRunner::onInit(InitContext& iCtx) +void LateTaskRunner::onInit(InitContext& iCtx, const Activity& activity) { // setup publisher mObjectsManager = std::make_shared(mTaskConfig.name, mTaskConfig.className, mTaskConfig.detectorName, 0); @@ -56,6 +56,7 @@ void LateTaskRunner::onInit(InitContext& iCtx) // init user's task mTask->setObjectsManager(mObjectsManager); + mTask->setCustomParameters(mTaskConfig.customParameters, activity); mTask->initialize(iCtx); } diff --git a/Framework/src/PostProcessingFactory.cxx b/Framework/src/PostProcessingFactory.cxx index 7b7e2e9348..16e43310c1 100644 --- a/Framework/src/PostProcessingFactory.cxx +++ b/Framework/src/PostProcessingFactory.cxx @@ -28,7 +28,6 @@ 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); return result; } diff --git a/Framework/src/PostProcessingInterface.cxx b/Framework/src/PostProcessingInterface.cxx index 5072980ffc..65bddb9ed5 100644 --- a/Framework/src/PostProcessingInterface.cxx +++ b/Framework/src/PostProcessingInterface.cxx @@ -33,6 +33,12 @@ void PostProcessingInterface::configure(const boost::property_tree::ptree& confi { } +void PostProcessingInterface::configure(const core::Activity& activity) +{ + // calls the legacy variant, so that user code overriding only that one keeps working + configure(); +} + void PostProcessingInterface::configure() { } diff --git a/Framework/src/PostProcessingRunner.cxx b/Framework/src/PostProcessingRunner.cxx index 294ef12075..a68e456475 100644 --- a/Framework/src/PostProcessingRunner.cxx +++ b/Framework/src/PostProcessingRunner.cxx @@ -113,7 +113,7 @@ void PostProcessingRunner::init(const PostProcessingRunnerConfig& runnerConfig, mTask->setObjectsManager(mObjectManager); mTask->setID(mTaskConfig.id); mTask->setName(mTaskConfig.taskName); - mTask->setCustomParameters(mTaskConfig.customParameters); + mTask->setCustomParameters(mTaskConfig.customParameters, mTaskConfig.activity); mTask->setCcdbUrl(mTaskConfig.ccdbUrl); mTask->configure(mRunnerConfig.configTree); } else { diff --git a/Framework/src/TaskFactory.cxx b/Framework/src/TaskFactory.cxx index cf62fd1ea4..efcf10334c 100644 --- a/Framework/src/TaskFactory.cxx +++ b/Framework/src/TaskFactory.cxx @@ -26,7 +26,6 @@ TaskInterface* TaskFactory::create(const TaskRunnerConfig& taskConfig, std::shar auto* result = root_class_factory::create(taskConfig.moduleName, taskConfig.className); result->setName(taskConfig.name); result->setObjectsManager(objectsManager); - result->setCustomParameters(taskConfig.customParameters); result->setCcdbUrl(taskConfig.ccdbUrl); return result; diff --git a/Framework/src/TaskInterface.cxx b/Framework/src/TaskInterface.cxx index 398ca070b1..7d4874911b 100644 --- a/Framework/src/TaskInterface.cxx +++ b/Framework/src/TaskInterface.cxx @@ -50,6 +50,12 @@ void TaskInterface::finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* { } +void TaskInterface::configure(const Activity& activity) +{ + // calls the legacy variant, so that user code overriding only that one keeps working + configure(); +} + void TaskInterface::configure() { // noop, override it if you want. diff --git a/Framework/src/TaskRunner.cxx b/Framework/src/TaskRunner.cxx index 4c54bc1fa3..b304ed025e 100644 --- a/Framework/src/TaskRunner.cxx +++ b/Framework/src/TaskRunner.cxx @@ -88,6 +88,8 @@ void TaskRunner::init(InitContext& iCtx) ILOG(Info, Devel) << "Initializing TaskRunner" << ENDM; printTaskConfig(); + const auto activity = computeActivity(iCtx.services(), mTaskConfig.fallbackActivity); + Bookkeeping::getInstance().init(mTaskConfig.bookkeepingUrl); // registering state machine callbacks @@ -124,6 +126,7 @@ void TaskRunner::init(InitContext& iCtx) mTask->setMonitoring(mCollector); mTask->setGlobalTrackingDataRequest(mTaskConfig.globalTrackingDataRequest); mTask->setDatabase(mTaskConfig.repository); + mTask->setCustomParameters(mTaskConfig.customParameters, activity); // load config params if (!ConfigParamGlo::keyValues.empty()) { diff --git a/Framework/src/UserCodeInterface.cxx b/Framework/src/UserCodeInterface.cxx index 96ee5bcdb3..895b727549 100644 --- a/Framework/src/UserCodeInterface.cxx +++ b/Framework/src/UserCodeInterface.cxx @@ -25,9 +25,14 @@ using namespace std; namespace o2::quality_control::core { -void UserCodeInterface::setCustomParameters(const CustomParameters& parameters) +void UserCodeInterface::setCustomParameters(const CustomParameters& parameters, const Activity& activity) { mCustomParameters = parameters; + configure(activity); +} + +void UserCodeInterface::configure(const Activity& activity) +{ configure(); } diff --git a/Framework/src/runnerUtils.cxx b/Framework/src/runnerUtils.cxx index e5627aa9a1..3e085bedac 100644 --- a/Framework/src/runnerUtils.cxx +++ b/Framework/src/runnerUtils.cxx @@ -96,6 +96,11 @@ std::string computeStringActivityField(framework::ServiceRegistryRef services, c Activity computeActivity(framework::ServiceRegistryRef services, const Activity& fallbackActivity) { + // without the device service (e.g. in unit tests or outside of a full DPL device) there is nothing to read from + if (!services.active()) { + ILOG(Info, Devel) << "RawDeviceService is not available, using the fallback activity" << ENDM; + return fallbackActivity; + } // for a complete list of the properties provided by ECS, see here: https://github.com/AliceO2Group/Control/blob/master/docs/handbook/configuration.md#variables-pushed-to-controlled-tasks auto runNumber = computeNumericalActivityField(services, "runNumber", fallbackActivity.mId); std::string runType = computeStringActivityField(services, "run_type", fallbackActivity.mType); diff --git a/Framework/test/testActor.cxx b/Framework/test/testActor.cxx index afe33b8f5d..db45532ffa 100644 --- a/Framework/test/testActor.cxx +++ b/Framework/test/testActor.cxx @@ -48,7 +48,7 @@ class DummyActor : public Actor public: explicit DummyActor(const ServicesConfig& cfg) : Actor(cfg) {} - void onInit(framework::InitContext&) {} + void onInit(framework::InitContext&, const Activity&) {} void onProcess(framework::ProcessingContext&) {} }; @@ -92,7 +92,7 @@ class UnrequestedAccessActor : public Actor static_assert(!(requires(T& t) { t.getCCDB(); })); } - void onInit(framework::InitContext&) + void onInit(framework::InitContext&, const Activity&) { assertNoAccessToServices(); } diff --git a/Framework/test/testActorCallbacks.cxx b/Framework/test/testActorCallbacks.cxx index cebd25977e..37390a7eb1 100644 --- a/Framework/test/testActorCallbacks.cxx +++ b/Framework/test/testActorCallbacks.cxx @@ -56,7 +56,7 @@ class DummyActor : public Actor explicit DummyActor(const ServicesConfig& cfg) : Actor(cfg) {} ~DummyActor() = default; - void onInit(InitContext&) + void onInit(InitContext&, const Activity&) { LOG(info) << "onInit called"; if (mLastEvent != sEventCreated) { diff --git a/Framework/test/testAggregatorRunner.cxx b/Framework/test/testAggregatorRunner.cxx index 91a5a62948..ad18d52a81 100644 --- a/Framework/test/testAggregatorRunner.cxx +++ b/Framework/test/testAggregatorRunner.cxx @@ -94,7 +94,7 @@ TEST_CASE("test_aggregator_onAnyNonZero") auto MyAggregatorBConfig = std::find_if(aggregatorConfigs.begin(), aggregatorConfigs.end(), [](const auto& cfg) { return cfg.name == "MyAggregatorB"; }); REQUIRE(MyAggregatorBConfig != aggregatorConfigs.end()); auto aggregator = make_shared(*MyAggregatorBConfig); - aggregator->init(); + aggregator->init(Activity()); QualityObjectsMapType qoMap; qoMap["checkAll"] = make_shared(Quality::Good, "checkAll"); @@ -113,7 +113,7 @@ TEST_CASE("test_aggregator_quality_filter") auto myAggregatorBConfig = std::find_if(aggregatorConfigs.begin(), aggregatorConfigs.end(), [](const auto& cfg) { return cfg.name == "MyAggregatorB"; }); REQUIRE(myAggregatorBConfig != aggregatorConfigs.end()); auto aggregator = make_shared(*myAggregatorBConfig); - aggregator->init(); + aggregator->init(Activity()); // empty list -> Good QualityObjectsMapType qoMap; @@ -173,7 +173,7 @@ TEST_CASE("test_aggregator_activity_propagation") auto myAggregatorCConfig = std::find_if(aggregatorConfigs.begin(), aggregatorConfigs.end(), [](const auto& cfg) { return cfg.name == "MyAggregatorC"; }); REQUIRE(myAggregatorCConfig != aggregatorConfigs.end()); auto aggregator = make_shared(*myAggregatorCConfig); - aggregator->init(); + aggregator->init(Activity()); Activity defaultActivity{ 123, "PHYSICS", "LHC34b", "apass4", "qc", { 34, 54 }, "proton - mouton" }; // empty list -> Good @@ -204,7 +204,7 @@ TEST_CASE("test_aggregator_cycle") auto MyAggregatorBConfig = std::find_if(aggregatorConfigs.begin(), aggregatorConfigs.end(), [](const auto& cfg) { return cfg.name == "MyAggregatorB"; }); REQUIRE(MyAggregatorBConfig != aggregatorConfigs.end()); auto aggregator = make_shared(*MyAggregatorBConfig); - aggregator->init(); + aggregator->init(Activity()); QualityObjectsMapType qoMap; auto qo1 = make_shared(Quality::Good, "checkAll"); diff --git a/Framework/test/testCheck.cxx b/Framework/test/testCheck.cxx index fc68d5236c..76c1d93bf0 100644 --- a/Framework/test/testCheck.cxx +++ b/Framework/test/testCheck.cxx @@ -88,7 +88,7 @@ TEST_CASE("test_check_empty_mo") std::string configFilePath = std::string("json://") + getTestDataDirectory() + "testSharedConfig.json"; Check check(getCheckConfig(configFilePath, "singleCheck")); - check.init(); + check.init(Activity()); check.startOfActivity(Activity()); { @@ -115,7 +115,7 @@ TEST_CASE("test_check_invoke_check") std::string configFilePath = std::string("json://") + getTestDataDirectory() + "testSharedConfig.json"; Check check(getCheckConfig(configFilePath, "singleCheck")); - check.init(); + check.init(Activity()); check.startOfActivity(Activity()); std::map> moMap{ @@ -131,7 +131,7 @@ TEST_CASE("test_check_postprocessing") std::string configFilePath = std::string("json://") + getTestDataDirectory() + "testSharedConfig.json"; Check check(getCheckConfig(configFilePath, "checkAnyPP")); - check.init(); + check.init(Activity()); check.startOfActivity(Activity()); std::map> moMap{ @@ -165,7 +165,7 @@ TEST_CASE("test_check_activity") moMap["abcTask/test1"]->setActivity({ 300000, "PHYSICS", "LHC22a", "spass", "qc", { 1, 10 }, "pp" }); moMap["abcTask/test2"]->setActivity({ 300000, "PHYSICS", "LHC22a", "spass", "qc", { 5, 15 }, "pp" }); - check.init(); + check.init(Activity()); check.startOfActivity(Activity()); auto qos = check.check(moMap); diff --git a/Framework/test/testUserCodeInterface.cxx b/Framework/test/testUserCodeInterface.cxx index adb3a9f966..e74e5963a6 100644 --- a/Framework/test/testUserCodeInterface.cxx +++ b/Framework/test/testUserCodeInterface.cxx @@ -111,7 +111,7 @@ TEST_CASE("UserCodeInterface_test_invoke_all_methods", "[ccdb]") // setting custom parameters should configure CustomParameters customParameters; customParameters["test"] = "asdf"; - testInterface.setCustomParameters(customParameters); + testInterface.setCustomParameters(customParameters, Activity()); CHECK(testInterface.configured == true); CHECK(testInterface.get("test") == "asdf"); diff --git a/Modules/Common/test/testMeanIsAbove.cxx b/Modules/Common/test/testMeanIsAbove.cxx index eb66b9f68d..21c05ef619 100644 --- a/Modules/Common/test/testMeanIsAbove.cxx +++ b/Modules/Common/test/testMeanIsAbove.cxx @@ -37,7 +37,7 @@ TEST_CASE("test_checks") MeanIsAbove check; CustomParameters customParameters; customParameters["meanThreshold"] = "1.0"; - check.setCustomParameters(customParameters); + check.setCustomParameters(customParameters, Activity()); Quality quality = check.check(&moMap); CHECK(quality == Quality::Bad); diff --git a/Modules/Skeleton/include/Skeleton/SkeletonAggregator.h b/Modules/Skeleton/include/Skeleton/SkeletonAggregator.h index 7575e55b73..3e30901cef 100644 --- a/Modules/Skeleton/include/Skeleton/SkeletonAggregator.h +++ b/Modules/Skeleton/include/Skeleton/SkeletonAggregator.h @@ -32,7 +32,7 @@ class SkeletonAggregator : public o2::quality_control::checker::AggregatorInterf { public: // Override interface - void configure() override; + void configure(const o2::quality_control::core::Activity& activity) override; std::map aggregate(const o2::quality_control::core::QCInputs& data) override; ClassDefOverride(SkeletonAggregator, 1); diff --git a/Modules/Skeleton/include/Skeleton/SkeletonCheck.h b/Modules/Skeleton/include/Skeleton/SkeletonCheck.h index a15ba7713f..eac5d15e59 100644 --- a/Modules/Skeleton/include/Skeleton/SkeletonCheck.h +++ b/Modules/Skeleton/include/Skeleton/SkeletonCheck.h @@ -33,7 +33,7 @@ class SkeletonCheck : public o2::quality_control::checker::CheckInterface ~SkeletonCheck() override = default; // Override interface - void configure() override; + void configure(const Activity& activity) override; Quality check(const quality_control::core::QCInputs& data) override; void beautify(std::shared_ptr mo, Quality checkResult = Quality::Null) override; void reset() override; diff --git a/Modules/Skeleton/include/Skeleton/SkeletonTask.h b/Modules/Skeleton/include/Skeleton/SkeletonTask.h index 8d315d994c..7da3c382bd 100644 --- a/Modules/Skeleton/include/Skeleton/SkeletonTask.h +++ b/Modules/Skeleton/include/Skeleton/SkeletonTask.h @@ -38,6 +38,7 @@ class SkeletonTask final : public TaskInterface ~SkeletonTask() override; // Definition of the methods for the template method pattern + void configure(const Activity& activity) override; void initialize(o2::framework::InitContext& ctx) override; void startOfActivity(const Activity& activity) override; void startOfCycle() override; diff --git a/Modules/Skeleton/src/SkeletonAggregator.cxx b/Modules/Skeleton/src/SkeletonAggregator.cxx index a8e587aaee..5a5b207999 100644 --- a/Modules/Skeleton/src/SkeletonAggregator.cxx +++ b/Modules/Skeleton/src/SkeletonAggregator.cxx @@ -24,13 +24,14 @@ using namespace o2::quality_control::core; namespace o2::quality_control_modules::skeleton { -void SkeletonAggregator::configure() +void SkeletonAggregator::configure(const Activity& activity) { // THIS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED. // This method is called whenever CustomParameters are set. + // The activity provides, among others, the run type and the beam type, which allows to pick the right custom parameters. - // Example of retrieving a custom parameter - std::string parameter = mCustomParameters.atOrDefaultValue("myOwnKey", "fallback value"); + // Example of retrieving a custom parameter for the current activity (run type and beam type) + std::string parameter = mCustomParameters.atOrDefaultValue("myOwnKey", "fallback value", activity); } std::map SkeletonAggregator::aggregate(const o2::quality_control::core::QCInputs& data) diff --git a/Modules/Skeleton/src/SkeletonCheck.cxx b/Modules/Skeleton/src/SkeletonCheck.cxx index 34e1a997b2..b6f0130ada 100644 --- a/Modules/Skeleton/src/SkeletonCheck.cxx +++ b/Modules/Skeleton/src/SkeletonCheck.cxx @@ -33,13 +33,14 @@ using namespace o2::quality_control; namespace o2::quality_control_modules::skeleton { -void SkeletonCheck::configure() +void SkeletonCheck::configure(const Activity& activity) { // THIS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED. // This method is called whenever CustomParameters are set. + // The activity provides, among others, the run type and the beam type, which allows to pick the right custom parameters. - // Example of retrieving a custom parameter - std::string parameter = mCustomParameters.atOrDefaultValue("myOwnKey1", "default"); + // Example of retrieving a custom parameter for the current activity (run type and beam type) + std::string parameter = mCustomParameters.atOrDefaultValue("myOwnKey1", "default", activity); } Quality SkeletonCheck::check(const quality_control::core::QCInputs& data) diff --git a/Modules/Skeleton/src/SkeletonTask.cxx b/Modules/Skeleton/src/SkeletonTask.cxx index eb67f98821..60ec8a7366 100644 --- a/Modules/Skeleton/src/SkeletonTask.cxx +++ b/Modules/Skeleton/src/SkeletonTask.cxx @@ -29,6 +29,17 @@ SkeletonTask::~SkeletonTask() { } +void SkeletonTask::configure(const Activity& activity) +{ + // THIS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED. + // This method is called whenever CustomParameters are set, before initialize(). + // The activity provides, among others, the run type and the beam type, which allows to pick the right custom parameters. + + // Example of retrieving a custom parameter for the current activity (run type and beam type) + std::string parameter = mCustomParameters.atOrDefaultValue("myOwnKey", "default", activity); + ILOG(Debug, Devel) << "SkeletonTask configured, myOwnKey: " << parameter << ENDM; +} + void SkeletonTask::initialize(o2::framework::InitContext& /*ctx*/) { // THIS FUNCTION BODY IS AN EXAMPLE. PLEASE REMOVE EVERYTHING YOU DO NOT NEED. diff --git a/doc/Configuration.md b/doc/Configuration.md index 783ed35644..3b38e186d5 100644 --- a/doc/Configuration.md +++ b/doc/Configuration.md @@ -745,13 +745,15 @@ Finally the way to search for a value and only act if it is there is the followi ### Retrieve the activity in the modules -In a task, the `activity` is provided in `startOfActivity`. +In a task and a late task, the `activity` is provided in `startOfActivity` and `endOfActivity`. In a Check, it is returned by `getActivity()`. In an Aggregator, it is returned by `getActivity()`. -In a postprocessing task, it is available in the objects manager: `getObjectsManager()->getActivity()` +In a postprocessing task, it is available in the objects manager: `getObjectsManager()->getActivity()`. + +For all of the above, the latest known activity is provided to `configure(const Activity& activity)` each time after `mCustomParameters` are updated. TODO we miss the definition of the datasampling policies