Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<void(const char*)>;

} // namespace framework
} // namespace o2

#endif
15 changes: 15 additions & 0 deletions Framework/Core/include/Framework/runDataProcessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Framework/WorkflowSpec.h"
#include "Framework/ConfigContext.h"
#include "Framework/BoostOptionsRetriever.h"
#include "Framework/CustomWorkflowTerminationHook.h"

#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
Expand Down Expand Up @@ -67,6 +68,10 @@ o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext co
void defaultConfiguration(std::vector<o2::framework::ChannelConfigurationPolicy>& channelPolicies) {}
void defaultConfiguration(std::vector<o2::framework::ConfigParamSpec> &globalWorkflowOptions) {}
void defaultConfiguration(std::vector<o2::framework::CompletionPolicy> &completionPolicies) {}
void defaultConfiguration(o2::framework::OnWorkflowTerminationHook& hook)
{
hook = [](const char*) {};
}

struct UserCustomizationsHelper {
template <typename T>
Expand Down Expand Up @@ -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++) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is --id a new option needed for this hook? I think not?
In that case, perhaps the id parameter is already available from somewhere else, and does not need to be parsed from the cmdline again?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --id parameter is added by the main driver so that every child process knows it's role in the workflow. So it is there already. The parsing of all the options is done in doMain in the cxx file. The customization happens in the header file because of some template trick, so one would need to pass the function as another parameter to do main.

Using this id parameter allows to customize the hook depending on the position of a process in the workflow.

I decided not to do this and implement some simple parsing. But well, that can be changed.

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;
}
Expand Down