From 3e37f60c2f8ac6840cf78bdd930cadefaedcf184 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:18:39 +0100 Subject: [PATCH] DPL: reduce bloat in runDataProcessing.h --- .../include/Framework/runDataProcessing.h | 70 +++++++------------ 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/Framework/Core/include/Framework/runDataProcessing.h b/Framework/Core/include/Framework/runDataProcessing.h index 8293bf0cf7039..6c1897bc8c1f3 100644 --- a/Framework/Core/include/Framework/runDataProcessing.h +++ b/Framework/Core/include/Framework/runDataProcessing.h @@ -11,6 +11,7 @@ #ifndef FRAMEWORK_RUN_DATA_PROCESSING_H #define FRAMEWORK_RUN_DATA_PROCESSING_H +#include #include "Framework/ChannelConfigurationPolicy.h" #include "Framework/CallbacksPolicy.h" #include "Framework/CompletionPolicy.h" @@ -30,6 +31,7 @@ #include "Framework/CheckTypes.h" #include "Framework/StructToTuple.h" #include "Framework/ConfigParamDiscovery.h" +#include "ResourcePolicy.h" #include "ServiceRegistryRef.h" #include @@ -66,9 +68,7 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co // By default we leave the channel policies unchanged. Notice that the default still include // a "match all" policy which uses pub / sub -// FIXME: add a debug statement saying that the default policy was used? -void defaultConfiguration(std::vector& channelPolicies) {} void defaultConfiguration(std::vector& globalWorkflowOptions) { o2::framework::call_if_defined([&](auto* ptr) { @@ -80,9 +80,6 @@ void defaultConfiguration(std::vector& globalWor }); } -void defaultConfiguration(std::vector& completionPolicies) {} -void defaultConfiguration(std::vector& dispatchPolicies) {} -void defaultConfiguration(std::vector& resourcePolicies) {} void defaultConfiguration(std::vector& services) { if (services.empty()) { @@ -90,9 +87,6 @@ void defaultConfiguration(std::vector& services) } } -void defaultConfiguration(std::vector& callbacksPolicies) {} -void defaultConfiguration(std::vector& callbacksPolicies) {} - /// Workflow options which are required by DPL in order to work. std::vector requiredWorkflowOptions(); @@ -101,19 +95,26 @@ void defaultConfiguration(o2::framework::OnWorkflowTerminationHook& hook) hook = [](const char*) {}; } +template +concept WithUserOverride = requires(T& something) { customize(something); }; + +template +concept WithNonTrivialDefault = !WithUserOverride && requires(T& something) { defaultConfiguration(something); }; + struct UserCustomizationsHelper { - template - static auto userDefinedCustomization(T& something, int preferUser) -> decltype(customize(something), void()) + static auto userDefinedCustomization(WithUserOverride auto& something) -> void { customize(something); } - template - static auto userDefinedCustomization(T& something, long preferUser) - -> decltype(defaultConfiguration(something), void()) + static auto userDefinedCustomization(WithNonTrivialDefault auto& something) -> void { defaultConfiguration(something); } + + static auto userDefinedCustomization(auto&) -> void + { + } }; namespace o2::framework @@ -144,12 +145,14 @@ int doMain(int argc, char** argv, o2::framework::WorkflowSpec const& specs, void doDefaultWorkflowTerminationHook(); template + requires requires(T& policy) { { T::createDefaultPolicies() } -> std::same_as>; } std::vector injectCustomizations() { std::vector policies; - UserCustomizationsHelper::userDefinedCustomization(policies, 0); + UserCustomizationsHelper::userDefinedCustomization(policies); auto defaultPolicies = T::createDefaultPolicies(); - policies.insert(std::end(policies), std::begin(policies), std::end(policies)); + policies.insert(std::end(policies), std::begin(defaultPolicies), std::end(defaultPolicies)); + return policies; } int mainNoCatch(int argc, char** argv) @@ -158,34 +161,15 @@ int mainNoCatch(int argc, char** argv) using namespace boost::program_options; std::vector workflowOptions; - UserCustomizationsHelper::userDefinedCustomization(workflowOptions, 0); + UserCustomizationsHelper::userDefinedCustomization(workflowOptions); auto requiredWorkflowOptions = WorkflowCustomizationHelpers::requiredWorkflowOptions(); workflowOptions.insert(std::end(workflowOptions), std::begin(requiredWorkflowOptions), std::end(requiredWorkflowOptions)); - std::vector completionPolicies; - UserCustomizationsHelper::userDefinedCustomization(completionPolicies, 0); - auto defaultCompletionPolicies = CompletionPolicy::createDefaultPolicies(); - completionPolicies.insert(std::end(completionPolicies), std::begin(defaultCompletionPolicies), std::end(defaultCompletionPolicies)); - - std::vector dispatchPolicies; - UserCustomizationsHelper::userDefinedCustomization(dispatchPolicies, 0); - auto defaultDispatchPolicies = DispatchPolicy::createDefaultPolicies(); - dispatchPolicies.insert(std::end(dispatchPolicies), std::begin(defaultDispatchPolicies), std::end(defaultDispatchPolicies)); - - std::vector resourcePolicies; - UserCustomizationsHelper::userDefinedCustomization(resourcePolicies, 0); - auto defaultResourcePolicies = ResourcePolicy::createDefaultPolicies(); - resourcePolicies.insert(std::end(resourcePolicies), std::begin(defaultResourcePolicies), std::end(defaultResourcePolicies)); - - std::vector callbacksPolicies; - UserCustomizationsHelper::userDefinedCustomization(callbacksPolicies, 0); - auto defaultCallbacksPolicies = CallbacksPolicy::createDefaultPolicies(); - callbacksPolicies.insert(std::end(callbacksPolicies), std::begin(defaultCallbacksPolicies), std::end(defaultCallbacksPolicies)); - - std::vector sendingPolicies; - UserCustomizationsHelper::userDefinedCustomization(sendingPolicies, 0); - auto defaultSendingPolicies = SendingPolicy::createDefaultPolicies(); - sendingPolicies.insert(std::end(sendingPolicies), std::begin(defaultSendingPolicies), std::end(defaultSendingPolicies)); + std::vector completionPolicies = injectCustomizations(); + std::vector dispatchPolicies = injectCustomizations(); + std::vector resourcePolicies = injectCustomizations(); + std::vector callbacksPolicies = injectCustomizations(); + std::vector sendingPolicies = injectCustomizations(); std::vector> retrievers; std::unique_ptr retriever{new BoostOptionsRetriever(true, argc, argv)}; @@ -206,10 +190,10 @@ int mainNoCatch(int argc, char** argv) overridePipeline(configContext, specs); overrideLabels(configContext, specs); for (auto& spec : specs) { - UserCustomizationsHelper::userDefinedCustomization(spec.requiredServices, 0); + UserCustomizationsHelper::userDefinedCustomization(spec.requiredServices); } std::vector channelPolicies; - UserCustomizationsHelper::userDefinedCustomization(channelPolicies, 0); + UserCustomizationsHelper::userDefinedCustomization(channelPolicies); auto defaultChannelPolicies = ChannelConfigurationPolicy::createDefaultPolicies(configContext); channelPolicies.insert(std::end(channelPolicies), std::begin(defaultChannelPolicies), std::end(defaultChannelPolicies)); return doMain(argc, argv, specs, @@ -229,7 +213,7 @@ int main(int argc, char** argv) char* idstring = getIdString(argc, argv); o2::framework::OnWorkflowTerminationHook onWorkflowTerminationHook; - UserCustomizationsHelper::userDefinedCustomization(onWorkflowTerminationHook, 0); + UserCustomizationsHelper::userDefinedCustomization(onWorkflowTerminationHook); onWorkflowTerminationHook(idstring); doDefaultWorkflowTerminationHook();