diff --git a/Framework/Core/include/Framework/CustomWorkflowTerminationHook.h b/Framework/Core/include/Framework/CustomWorkflowTerminationHook.h new file mode 100644 index 0000000000000..33f8cda30543e --- /dev/null +++ b/Framework/Core/include/Framework/CustomWorkflowTerminationHook.h @@ -0,0 +1,46 @@ +// Copyright CERN and copyright holders of ALICE O2. This software is +// distributed under the terms of the GNU General Public License v3 (GPL +// Version 3), copied verbatim in the file "COPYING". +// +// See http://alice-o2.web.cern.ch/license for full licensing information. +// +// 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. +#ifndef CUSTOMWORKFLOWTERMINATIONHOOK_H +#define CUSTOMWORKFLOWTERMINATIONHOOK_H + +namespace o2 +{ +namespace framework +{ + +/// A callback definition for a hook to be invoked when processes terminate +/// +/// The parameter is the nullptr if the process is the main driver, for all +/// child processes, the id string is passed. This allows to customize the +/// hook depending on the process. +/// Note that the callback hook is invoked for every process, i.e. main driver +/// and all childs. +/// +/// \par Usage: +/// The customize the hook, add a function with the following signature before +/// including heder file runDataProcessing.h: +/// +/// void customize(o2::framework::OnWorkflowTerminationHook& hook) +/// { +/// hook = [](const char* idstring){ +/// if (idstring == nullptr) { +/// std::cout << "hook" << std::endl; +/// } else { +/// std::cout << "child process " << idstring << " terminating" << std::endl; +/// } +/// }; +/// } +/// #include "Framework/runDataProcessing.h" +using OnWorkflowTerminationHook = std::function; + +} // namespace framework +} // namespace o2 + +#endif diff --git a/Framework/Core/include/Framework/runDataProcessing.h b/Framework/Core/include/Framework/runDataProcessing.h index 4fefa24fc19aa..4eacf466ef719 100644 --- a/Framework/Core/include/Framework/runDataProcessing.h +++ b/Framework/Core/include/Framework/runDataProcessing.h @@ -17,6 +17,7 @@ #include "Framework/WorkflowSpec.h" #include "Framework/ConfigContext.h" #include "Framework/BoostOptionsRetriever.h" +#include "Framework/CustomWorkflowTerminationHook.h" #include #include @@ -67,6 +68,10 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co void defaultConfiguration(std::vector& channelPolicies) {} void defaultConfiguration(std::vector &globalWorkflowOptions) {} void defaultConfiguration(std::vector &completionPolicies) {} +void defaultConfiguration(o2::framework::OnWorkflowTerminationHook& hook) +{ + hook = [](const char*) {}; +} struct UserCustomizationsHelper { template @@ -124,6 +129,16 @@ int main(int argc, char** argv) LOG(ERROR) << "Unknown error while setting up workflow."; } + char* idstring = nullptr; + for (int argi = 0; argi < argc; argi++) { + if (strcmp(argv[argi], "--id") == 0 && argi + 1 < argc) { + idstring = argv[argi + 1]; + break; + } + } + o2::framework::OnWorkflowTerminationHook onWorkflowTerminationHook; + UserCustomizationsHelper::userDefinedCustomization(onWorkflowTerminationHook, 0); + onWorkflowTerminationHook(idstring); LOG(INFO) << "Process " << getpid() << " is exiting."; return result; }