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 1129 of file framework.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 1151 of file framework.py.

1151 def __init__(self, algorithm, data_input=None, pre_algorithm=None):
1152 """
1153 """
1154
1155 self.algorithm = algorithm
1156
1157 cppname = type(algorithm).__cpp_name__
1158
1159 self.name = cppname[cppname.rfind('::') + 2:]
1160
1163 self.data_input = data_input
1164 if not self.data_input:
1165 self.data_input = self.default_inputdata_setup
1166
1169 self.pre_algorithm = pre_algorithm
1170
1172 self.strategy = strategies.SingleIOV
1173
1178 self.params = {}
1179

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 1180 of file framework.py.

1180 def default_inputdata_setup(self, input_file_paths):
1181 """
1182 Simple setup to set the input file names to the algorithm. Applied to the data_input attribute
1183 by default. This simply takes all files returned from the `Calibration.output_patterns` and filters
1184 for only the CollectorOutput.root files. Then it sets them as input files to the CalibrationAlgorithm class.
1185 """
1186 collector_output_files = list(filter(lambda file_path: "CollectorOutput.root" == Path(file_path).name,
1187 input_file_paths))
1188 info_lines = [f"Input files used in {self.name}:"]
1189 info_lines.extend(collector_output_files)
1190 B2INFO_MULTILINE(info_lines)
1191 self.algorithm.setInputFileNames(collector_output_files)
1192
1193

Member Data Documentation

◆ algorithm

algorithm = algorithm

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

Definition at line 1155 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 1163 of file framework.py.

◆ name

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

reduced name

Definition at line 1159 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 1178 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 1169 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 1172 of file framework.py.


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