8#include <framework/pcore/PathUtils.h>
9#include <framework/pcore/zmq/utils/ZMQAddressUtils.h>
10#include <framework/core/ModuleManager.h>
11#include <framework/core/Environment.h>
18 for (
const ModulePtr& module : path.getModules()) {
35 for (
const ModulePtr& module : path->getModules()) {
36 bool hasParallelFlag =
module->hasProperties(Module::c_ParallelProcessingCertified) and
37 !module->hasProperties(Module::c_Input) and
38 !module->hasProperties(Module::c_Output) and
39 !module->hasProperties(Module::c_HistogramManager) ;
41 if (hasParallelFlag and module->hasCondition()) {
42 for (
const auto& conditionPath : module->getAllConditionPaths()) {
44 hasParallelFlag =
false;
49 if ((stage == 0 and hasParallelFlag) or (stage == 1 and !hasParallelFlag)) {
56 mainPath.reset(
new Path);
66 }
else if (stage == 1) {
67 mainPath->addModule(module);
68 }
else if (stage == 2) {
77 bool createAllPaths =
false;
78 for (
const ModulePtr& module : path->getModules()) {
80 createAllPaths =
true;
85 if (mainPath->isEmpty() and not createAllPaths) {
88 if (inputPath->
isEmpty() and not createAllPaths) {
91 if (outputPath->
isEmpty() and not createAllPaths) {
95 return {inputPath, mainPath, outputPath};
105 return histoManagerModule;
110 B2ASSERT(
"The main part is empty. This is a bug in the framework.",
111 mainPath and not mainPath->isEmpty());
117 const auto& socketAddress = environment.getZMQSocketAddress();
123 unsigned int maximalWaitingTime = environment.getZMQMaximalWaitingTime();
124 unsigned int eventBufferSize = environment.getZMQEventBufferSize();
125 unsigned int workerTimeout = environment.getZMQWorkerTimeout();
126 bool useEventBackup = environment.getZMQUseEventBackup();
131 zmqTxInputModule->
getParam<std::string>(
"socketName").setValue(inputSocketAddress);
132 zmqTxInputModule->
getParam<std::string>(
"xpubProxySocketName").setValue(pubSocketAddress);
133 zmqTxInputModule->
getParam<std::string>(
"xsubProxySocketName").setValue(subSocketAddress);
134 zmqTxInputModule->
getParam<
unsigned int>(
"workerProcessTimeout").setValue(workerTimeout);
135 zmqTxInputModule->
getParam<
bool>(
"useEventBackup").setValue(useEventBackup);
136 zmqTxInputModule->
getParam<
unsigned int>(
"maximalWaitingTime").setValue(maximalWaitingTime);
141 zmqRxWorkerModule->
getParam<std::string>(
"socketName").setValue(inputSocketAddress);
142 zmqRxWorkerModule->
getParam<std::string>(
"xpubProxySocketName").setValue(pubSocketAddress);
143 zmqRxWorkerModule->
getParam<std::string>(
"xsubProxySocketName").setValue(subSocketAddress);
144 zmqRxWorkerModule->
getParam<
unsigned int>(
"maximalWaitingTime").setValue(maximalWaitingTime);
145 zmqRxWorkerModule->
getParam<
unsigned int>(
"eventBufferSize").setValue(eventBufferSize);
153 zmqTxWorkerModule->
getParam<std::string>(
"socketName").setValue(outputSocketAddress);
154 zmqTxWorkerModule->
getParam<std::string>(
"xpubProxySocketName").setValue(pubSocketAddress);
155 zmqTxWorkerModule->
getParam<std::string>(
"xsubProxySocketName").setValue(pubSocketAddress);
160 zmqRxOutputModule->
getParam<std::string>(
"socketName").setValue(outputSocketAddress);
161 zmqRxOutputModule->
getParam<std::string>(
"xpubProxySocketName").setValue(pubSocketAddress);
162 zmqRxOutputModule->
getParam<std::string>(
"xsubProxySocketName").setValue(subSocketAddress);
163 zmqRxOutputModule->
getParam<
unsigned int>(
"maximalWaitingTime").setValue(maximalWaitingTime);
172 B2INFO(
"Main Path " << mainPath->getPathString());
184 mergedPath.
addPath(outputPath);
197 tmpModuleList.push_back(m);
199 return tmpModuleList;
205 if (std::find(modules->begin(), modules->end(), m) == modules->end()) {
206 modules->push_front(m);
213 path->addModule(module);
219 if (modules.empty())
return;
static Environment & Instance()
Static method to get a reference to the Environment instance.
std::shared_ptr< Module > registerModule(const std::string &moduleName, std::string sharedLibPath="") noexcept(false)
Creates an instance of a module and registers it to the ModuleManager.
static ModuleManager & Instance()
Exception is thrown if the requested module could not be created by the ModuleManager.
static bool allModulesHaveFlag(const std::list< std::shared_ptr< Module > > &list, unsigned int flag)
Returns true if and only if all modules in list have the given flag (or list is empty).
@ c_HistogramManager
This module is used to manage histograms accumulated by other modules.
@ c_NoParallelWork
This module does no per-event work that is worth running in parallel.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
@ c_TerminateInAllProcesses
When using parallel processing, call this module's terminate() function in all processes().
static ModulePtrList getTerminateGloballyModules(const ModulePtrList &modules)
Return only modules which have the TerminateGlobally Module flag set.
static ModulePtrList preparePaths(PathPtr &inputPath, PathPtr &mainPath, PathPtr &outputPath)
Adds internal zmq modules to the paths.
static std::tuple< PathPtr, PathPtr, PathPtr > splitPath(const PathPtr &path)
Split the given part into the input, main and output path (in this order) by looking onto the paralle...
static void prependModules(PathPtr &path, const ModulePtrList &modules)
Prepend the given modules to the path, keeping their order.
static ModulePtr getHistogramManager(PathPtr &inputPath)
Find the histogram manager in the paths and return it.
static void prependModulesIfNotPresent(ModulePtrList *modules, const ModulePtrList &prependModules)
Prepend given 'prependModules' to 'modules', if they're not already present.
static bool isWorthParallelising(const Path &path)
Is a parallel section made up of these modules worth creating processes for?
static void appendModule(PathPtr &path, const ModulePtr &module)
Append the given module to the path.
Implements a path consisting of Module and/or Path objects.
std::list< std::shared_ptr< Module > > buildModulePathList(bool unique=true) const
Builds a list of all modules which could be executed during the data processing.
void addPath(const PathPtr &path)
See 'pydoc3 basf2.Path'.
void addModule(const std::shared_ptr< Module > &module)
Adds a module to the path.
bool isEmpty() const
Returns true if this Path doesn't contain any elements.
std::list< std::shared_ptr< Module > > getModules() const override
Returns a list of the modules in this path.
std::string getPathString() const override
return a string of the form [module a -> module b -> [another path]]
static std::string getSocketAddress(const std::string &socketAddress, ZMQAddressType socketPart)
Create a full socket address for the given type from a random socket address, ba adding a suffix.
ModuleParam< T > & getParam(const std::string &name) const
Returns a reference to a parameter.
std::shared_ptr< Path > PathPtr
Defines a pointer to a path object as a boost shared pointer.
std::shared_ptr< Module > ModulePtr
Defines a pointer to a module object as a boost shared pointer.
std::list< ModulePtr > ModulePtrList
Defines a std::list of shared module pointers.
@ c_sub
Multicast publish socket.
Abstract base class for different kinds of events.