Belle II Software development
IfModule Class Reference
Inheritance diagram for IfModule:
WrapperModule IfStoreArrayPresentModule IfMCParticlesPresentModule IfStoreArrayNotPresentModule

Public Member Functions

def __init__ (self, module, condition=None)
 
def condition (self)
 
def event (self)
 

Public Attributes

 condition
 Condition function called at each event to determine if wrapped module should be executed.
 

Detailed Description

Wrapper module to conditionally execute module and continue with the normal path afterwards.

There are two ways to specify the condition.
One way is to override the condtion(self) method in a subclass.
The second way is to give a function as the second argument to the module constructor,
which is called each event.

Attributes:
  module (basf2.Module): The module executed, if the condition is met.

  condition (function() -> bool, optional): Function executed at each event to determine,
    if the given module shall be executed.
    If None call the condition method instead, which can be overridden by subclasses.

Definition at line 165 of file metamodules.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  module,
  condition = None 
)
Initialisation method taking the module instance to be wrapped.

Args:
  module (basf2.Module): The module executed, if the condition is met.
  condition  (function() -> bool, optional): Function executed at each event to determine,
    if the given module shall be executed.
    If None call the condition method instead, which can be overridden by subclasses.

Reimplemented from WrapperModule.

Reimplemented in IfMCParticlesPresentModule, and IfStoreArrayPresentModule.

Definition at line 183 of file metamodules.py.

183 def __init__(self, module, condition=None):
184 """Initialisation method taking the module instance to be wrapped.
185
186 Args:
187 module (basf2.Module): The module executed, if the condition is met.
188 condition (function() -> bool, optional): Function executed at each event to determine,
189 if the given module shall be executed.
190 If None call the condition method instead, which can be overridden by subclasses.
191 """
192
193 super().__init__(module)
194 if condition is not None:
195
197 self.condition = condition
198

Member Function Documentation

◆ condition()

def condition (   self)
Condition method called if not given a condition function during construction.

Can be overridden by a concrete subclass to specify
under which condition the wrapped module should be executed.
It can also be shadowed by a condition function given to the constructor of this module.

Returns:
  bool: The indication if the wrapped module should be executed.
    Always True in the base implementation

Reimplemented in IfStoreArrayPresentModule, and IfStoreArrayNotPresentModule.

Definition at line 199 of file metamodules.py.

199 def condition(self):
200 """Condition method called if not given a condition function during construction.
201
202 Can be overridden by a concrete subclass to specify
203 under which condition the wrapped module should be executed.
204 It can also be shadowed by a condition function given to the constructor of this module.
205
206 Returns:
207 bool: The indication if the wrapped module should be executed.
208 Always True in the base implementation
209 """
210 return True
211

◆ event()

def event (   self)
Event method of the module

Evaluates the condition and sets the return value of this module
to trigger the execution of the wrapped module.

Reimplemented from WrapperModule.

Definition at line 212 of file metamodules.py.

212 def event(self):
213 """Event method of the module
214
215 Evaluates the condition and sets the return value of this module
216 to trigger the execution of the wrapped module.
217 """
218
219 if self.condition():
220 super().event()
221
222

Member Data Documentation

◆ condition

condition

Condition function called at each event to determine if wrapped module should be executed.

Reimplemented in IfStoreArrayPresentModule, and IfStoreArrayNotPresentModule.

Definition at line 197 of file metamodules.py.


The documentation for this class was generated from the following file: