Belle II Software development
SubEventModule.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/Module.h>
12#include <framework/core/EventProcessor.h>
13#include <framework/datastore/StoreArray.h>
14
15#include <memory>
16#include <optional>
17
18namespace Belle2 {
23 class Path;
26 class SubEventModule : public Module, public EventProcessor {
27 public:
29 enum EModes {
30 c_ForEach = 0,
31 c_DoWhile = 1,
32 };
33
36
38 void initSubEvent(const std::string& objectName, const std::string& loopOver, std::shared_ptr<Path> path);
40 void initSubLoop(std::shared_ptr<Path> path, const std::string& condition, unsigned int maxIterations);
41
42 virtual void initialize() override;
43 virtual void beginRun() override;
44 virtual void endRun() override;
45 virtual void event() override;
46 virtual void terminate() override;
47
48 private:
50 void setProperties();
56 std::optional<std::string> m_objectName{std::nullopt};
58 std::optional<std::string> m_loopOverName{std::nullopt};
62 std::shared_ptr<Path> m_path;
65 int m_processID{ -1};
67 unsigned int m_maxIterations{10000};
69 std::optional<std::string> m_loopConditionString{std::nullopt};
71 std::unique_ptr<ModuleCondition> m_loopCondition;
75 int m_mode{c_ForEach};
76 };
78}
provides the core event processing loop.
Base class for Modules.
Definition: Module.h:72
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Framework-internal module that implements the functionality of Path::forEach() as well as Path::doWhi...
StoreArray< TObject > m_loopOver
array looped over in case of forEach
void initSubLoop(std::shared_ptr< Path > path, const std::string &condition, unsigned int maxIterations)
ised by Path::doWhile() to actually set parameters
std::optional< std::string > m_loopOverName
name for m_loopOver in case of forEach.
void initSubEvent(const std::string &objectName, const std::string &loopOver, std::shared_ptr< Path > path)
used by Path::forEach() to actually set parameters.
virtual void initialize() override
Initialize the Module.
virtual void event() override
This method is the core of the module.
int m_mode
Mode for this module.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
std::unique_ptr< ModuleCondition > m_loopCondition
Condition object to evaluate if the loop is finished in case of doWhile()
void setProperties()
Set properties for this module based on the modules found in m_path.
std::optional< std::string > m_objectName
name of our loop variable in case of forEach.
virtual void beginRun() override
Called when entering a new run.
EModes
Define the constants for the different modes.
void setDoWhileConditions()
Set the necessary pointers for do_while(): the pointer to the module whose return value we'll use as ...
int m_processID
when using multi-processing contains the ID of the process where event() is called (in that process o...
std::shared_ptr< Path > m_path
Path to execute.
std::optional< std::string > m_loopConditionString
String for the condition when looping.
Module * m_loopConditionModule
pointer to the module to provide the returnValue in case of doWhile()
unsigned int m_maxIterations
maximum number of iterations before giving up in case of doWhile()
Abstract base class for different kinds of events.