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>
19 std::set<std::string> uselessParallelModules({
"HistoManager",
"Gearbox",
"Geometry"});
26 for (
const ModulePtr& module : path->getModules()) {
32 if (hasParallelFlag and module->hasCondition()) {
33 for (
const auto& conditionPath : module->getAllConditionPaths()) {
35 hasParallelFlag =
false;
40 if ((stage == 0 and hasParallelFlag) or (stage == 1 and !hasParallelFlag)) {
44 bool path_is_useful =
false;
45 for (
const auto& parallelModule : mainPath->getModules()) {
46 if (uselessParallelModules.count(parallelModule->getType()) == 0) {
47 path_is_useful =
true;
51 if (not path_is_useful) {
53 inputPath->addPath(mainPath);
54 mainPath.reset(
new Path);
62 inputPath->addModule(module);
67 mainPath->addModule(module);
68 outputPath->addModule(module);
70 }
else if (stage == 1) {
71 mainPath->addModule(module);
72 }
else if (stage == 2) {
73 outputPath->addModule(module);
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};
103 for (
const ModulePtr& module : inputPath->getModules()) {
106 histoManagerModule = module;
111 return histoManagerModule;
115 B2ASSERT(
"The main part is empty. This is a bug in the framework.",
116 mainPath and not mainPath->isEmpty());
122 const auto& socketAddress = environment.getZMQSocketAddress();
128 unsigned int maximalWaitingTime = environment.getZMQMaximalWaitingTime();
129 unsigned int eventBufferSize = environment.getZMQEventBufferSize();
130 unsigned int workerTimeout = environment.getZMQWorkerTimeout();
131 bool useEventBackup = environment.getZMQUseEventBackup();
136 zmqTxInputModule->getParam<std::string>(
"socketName").setValue(inputSocketAddress);
137 zmqTxInputModule->getParam<std::string>(
"xpubProxySocketName").setValue(pubSocketAddress);
138 zmqTxInputModule->getParam<std::string>(
"xsubProxySocketName").setValue(subSocketAddress);
139 zmqTxInputModule->getParam<
unsigned int>(
"workerProcessTimeout").setValue(workerTimeout);
140 zmqTxInputModule->getParam<
bool>(
"useEventBackup").setValue(useEventBackup);
141 zmqTxInputModule->getParam<
unsigned int>(
"maximalWaitingTime").setValue(maximalWaitingTime);
146 zmqRxWorkerModule->getParam<std::string>(
"socketName").setValue(inputSocketAddress);
147 zmqRxWorkerModule->getParam<std::string>(
"xpubProxySocketName").setValue(pubSocketAddress);
148 zmqRxWorkerModule->getParam<std::string>(
"xsubProxySocketName").setValue(subSocketAddress);
149 zmqRxWorkerModule->getParam<
unsigned int>(
"maximalWaitingTime").setValue(maximalWaitingTime);
150 zmqRxWorkerModule->getParam<
unsigned int>(
"eventBufferSize").setValue(eventBufferSize);
158 zmqTxWorkerModule->getParam<std::string>(
"socketName").setValue(outputSocketAddress);
159 zmqTxWorkerModule->getParam<std::string>(
"xpubProxySocketName").setValue(pubSocketAddress);
160 zmqTxWorkerModule->getParam<std::string>(
"xsubProxySocketName").setValue(pubSocketAddress);
165 zmqRxOutputModule->getParam<std::string>(
"socketName").setValue(outputSocketAddress);
166 zmqRxOutputModule->getParam<std::string>(
"xpubProxySocketName").setValue(pubSocketAddress);
167 zmqRxOutputModule->getParam<std::string>(
"xsubProxySocketName").setValue(subSocketAddress);
168 zmqRxOutputModule->getParam<
unsigned int>(
"maximalWaitingTime").setValue(maximalWaitingTime);
174 B2INFO(
"Input Path " << inputPath->getPathString());
177 B2INFO(
"Main Path " << mainPath->getPathString());
180 B2INFO(
"Output Path " << outputPath->getPathString());
189 mergedPath.
addPath(outputPath);
202 tmpModuleList.push_back(m);
204 return tmpModuleList;
209 for (
const ModulePtr& m : prependModules) {
210 if (std::find(modules->begin(), modules->end(), m) == modules->end()) {
211 modules->push_front(m);
218 path->addModule(module);
224 newPath->addModule(module);
225 newPath->addPath(path);
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_Input
This module is an input module (reads data).
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
@ c_Output
This module is an output module (writes data).
@ 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 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 void prependModule(PathPtr &path, const ModulePtr &module)
Append given modules to the path.
static void appendModule(PathPtr &path, const ModulePtr &module)
Prepend given modules 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'.
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.
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.