Belle II Software development
Algorithm Class Reference

Public Member Functions

 __init__ (self, algorithm, data_input=None, pre_algorithm=None)
 
 default_inputdata_setup (self, input_file_paths)
 

Public Attributes

 algorithm = algorithm
 CalibrationAlgorithm instance (assumed to be true since the Calibration class checks)
 
 name = cppname[cppname.rfind('::') + 2:]
 reduced name
 
 data_input = data_input
 Function called before the pre_algorithm method to setup the input data that the CalibrationAlgorithm uses.
 
 pre_algorithm = pre_algorithm
 Function called after data_input but before algorithm.execute to do any remaining setup.
 
 strategy = strategies.SingleIOV
 The algorithm stratgey that will be used when running over the collected data.
 
dict params = {}
 Parameters that could be used in the execution of the algorithm strategy/runner to modify behaviour.
 

Detailed Description

Parameters:
    algorithm: The CalibrationAlgorithm instance that we want to execute.
Keyword Arguments:
    data_input : An optional function that sets the input files of the algorithm.
    pre_algorithm : An optional function that runs just prior to execution of the algorithm.
        Useful for set up e.g. module initialisation

This is a simple wrapper class around the C++ CalibrationAlgorithm class.
It helps to add functionality to algorithms for use by the Calibration and CAF classes rather
than separating the logic into those classes directly.

This is **not** currently a class that a user should interact with much during `CAF`
setup (unless you're doing something advanced).
The `Calibration` class should be doing the most of the creation of the defaults for these objects.

Setting the `data_input` function might be necessary if you have set the `Calibration.output_patterns`.
Also, setting the `pre_algorithm` to a function that should execute prior to each `strategies.AlgorithmStrategy`
is often useful i.e. by calling for the Geometry module to initialise.

Definition at line 1118 of file framework.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
algorithm,
data_input = None,
pre_algorithm = None )
 

Definition at line 1140 of file framework.py.

1140 def __init__(self, algorithm, data_input=None, pre_algorithm=None):
1141 """
1142 """
1143
1144 self.algorithm = algorithm
1145
1146 cppname = type(algorithm).__cpp_name__
1147
1148 self.name = cppname[cppname.rfind('::') + 2:]
1149
1152 self.data_input = data_input
1153 if not self.data_input:
1154 self.data_input = self.default_inputdata_setup
1155
1158 self.pre_algorithm = pre_algorithm
1159
1161 self.strategy = strategies.SingleIOV
1162
1167 self.params = {}
1168

Member Function Documentation

◆ default_inputdata_setup()

default_inputdata_setup ( self,
input_file_paths )
Simple setup to set the input file names to the algorithm. Applied to the data_input attribute
by default. This simply takes all files returned from the `Calibration.output_patterns` and filters
for only the CollectorOutput.root files. Then it sets them as input files to the CalibrationAlgorithm class.

Definition at line 1169 of file framework.py.

1169 def default_inputdata_setup(self, input_file_paths):
1170 """
1171 Simple setup to set the input file names to the algorithm. Applied to the data_input attribute
1172 by default. This simply takes all files returned from the `Calibration.output_patterns` and filters
1173 for only the CollectorOutput.root files. Then it sets them as input files to the CalibrationAlgorithm class.
1174 """
1175 collector_output_files = list(filter(lambda file_path: "CollectorOutput.root" == Path(file_path).name,
1176 input_file_paths))
1177 info_lines = [f"Input files used in {self.name}:"]
1178 info_lines.extend(collector_output_files)
1179 B2INFO_MULTILINE(info_lines)
1180 self.algorithm.setInputFileNames(collector_output_files)
1181
1182

Member Data Documentation

◆ algorithm

algorithm = algorithm

CalibrationAlgorithm instance (assumed to be true since the Calibration class checks)

Definition at line 1144 of file framework.py.

◆ data_input

data_input = data_input

Function called before the pre_algorithm method to setup the input data that the CalibrationAlgorithm uses.

The list of files matching the Calibration.output_patterns from the collector output directories will be passed to it

Definition at line 1152 of file framework.py.

◆ name

name = cppname[cppname.rfind('::') + 2:]

reduced name

Definition at line 1148 of file framework.py.

◆ params

dict params = {}

Parameters that could be used in the execution of the algorithm strategy/runner to modify behaviour.

By default this is empty and not used by the default :py:class:caf.strategies.SingleIOV class. But more complex strategies, or your own custom ones, could use it to configure behaviour. Note that if you modify this inside a subprocess the modification won't persist outside, you would have to change it in the parent process (or dump values to a file and read it in next time).

Definition at line 1167 of file framework.py.

◆ pre_algorithm

pre_algorithm = pre_algorithm

Function called after data_input but before algorithm.execute to do any remaining setup.

It must have the form pre_algorithm(algorithm, iteration) where algorithm can be assumed to be the CalibrationAlgorithm instance about to be executed, and iteration is an int e.g. 0, 1, 2...

Definition at line 1158 of file framework.py.

◆ strategy

The algorithm stratgey that will be used when running over the collected data.

you can set this here, or from the Calibration.strategies attribute.

Definition at line 1161 of file framework.py.


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