basf2_helper package#
- class b2luigi.basf2_helper.targets.ROOTLocalTarget(*args, **kwargs)[source]#
Bases:
LocalTarget- class ROOTLocalTarget[source]#
Bases:
objectA custom target class that extends
b2luigi.LocalTargetto handle ROOT files.This class overrides the
existsmethod to not only check for the existence of the file but also verify that the ROOT file contains at least one key.
- exists()[source]#
Checks if the target file exists and contains at least one key.
This method first verifies the existence of the file using the parent class’s
existsmethod. If the file exists, it opens the file using ROOT’s TFile, retrieves the list of keys, and checks if the list contains any entries.- Returns:
True if the file exists and contains at least one key, False otherwise.
- Return type:
bool
- class b2luigi.basf2_helper.tasks.Basf2Task(*args, **kwargs)[source]#
Bases:
DispatchableTaskA custom task class for handling
basf2-related tasks in theb2luigiframework. This class extendsb2luigi.DispatchableTaskand provides additional functionality for managing output file targets and serialized parameters.- git_hash = <luigi.parameter.Parameter object>#
A parameter representing the
basf2git hash. It is set to the currentbasf2git hash (see:get_basf2_git_hash) by default and marked as non-significant to avoid affecting the task’s unique ID.
- get_output_file_target(*args, **kwargs)[source]#
Determines the appropriate output file target based on the file extension.
If the output file has a “.root” extension, it returns a
b2luigi.basf2_helper.ROOTLocalTargetfor the specified file. Otherwise, it delegates to the superclass implementation ofb2luigi.Task.get_output_file_target().- Parameters:
*args – Positional arguments passed to
get_output_file_nameand the superclass method.**kwargs – Keyword arguments passed to
get_output_file_nameand the superclass method.
- Returns:
- A
b2luigi.basf2_helper.ROOTLocalTargetif the file extension is “.root”, otherwise the result of the superclass’s
get_output_file_targetmethod.
- A
- Return type:
Target
- get_serialized_parameters()[source]#
Retrieve the serialized parameters of the current task. (see
get_serialized_parameters)- Returns:
A dictionary containing the serialized parameters of the task.
- Return type:
dict
- class b2luigi.basf2_helper.tasks.Basf2PathTask(*args, **kwargs)[source]#
Bases:
Basf2TaskA task for running a
basf2processing path within theb2luigiframework.In contrast to the normal
(b2)luigitasks, the execution logic of aBasf2PathTaskis not defined in arunmethod but increate_path. Thecreate_pathmethod needs to return thebasf2path that is created in the steering file. Furthermore, theProgressmodule is automatically added andprint(b2.statistics)is called after the path is processed.Warning
Due to technical reasons, the path needs to be created within the
create_pathmethod. The path can be used in further objects, however, it is not possible for it to originate from an outer scope.- num_processes = <luigi.parameter.IntParameter object>#
- max_event = <luigi.parameter.IntParameter object>#
- process()[source]#
Executes the processing task using the
basf2framework.It sets the number of processes for basf2 if
self.num_processesis specified. Then, it creates a processing path, adds thebasf2.Progressmodule to the path, and prints the path configuration.Finally, it processes the path with the specified maximum number of events (
self.max_event). Ifself.max_eventis not set, it defaults to0(process all events). After processing, it prints thebasf2statistics.- Raises:
ImportError – If the basf2 module cannot be found.
- class b2luigi.basf2_helper.tasks.SimplifiedOutputBasf2Task(*args, **kwargs)[source]#
Bases:
Basf2PathTaskA task that simplifies the handling of output files in a
basf2processing path.This class is intended to be subclassed (see
Basf2PathTask), and thecreate_pathmethod must be implemented to define thebasf2processing path. Theoutputmethod identifies and collects output file targets from the modules in the path.
- class b2luigi.basf2_helper.tasks.MergerTask(*args, **kwargs)[source]#
Bases:
Basf2TaskA task class for merging input files using a specified command.
- cmd = []#
- output()[source]#
Generates the output for the task by iterating over input file names and applying filters based on the
keysattribute.- Yields:
The result of
b2luigi.Task.add_to_output()for each key that passes the filtering conditions.
- Filtering Conditions:
If the task has a
keysattribute, only keys present inself.keysare processed.
- process()[source]#
Processes input files and generates output files by executing a command.
Creates necessary output directories using
create_output_dirs.Iterates over the input file names grouped by keys.
Skips processing for keys not specified in
self.keys(ifself.keysexists).Constructs a command by appending the output file name and input file list to
self.cmd.Executes the constructed command using
subprocess.check_call.
- class b2luigi.basf2_helper.tasks.HaddTask(*args, **kwargs)[source]#
Bases:
MergerTaskHaddTaskis a subclass ofMergerTaskthat represents a task for merging ROOT files using thehaddcommand-line tool.- cmd = ['hadd', '-f']#
- class b2luigi.basf2_helper.tasks.Basf2FileMergeTask(*args, **kwargs)[source]#
Bases:
MergerTaskBasf2FileMergeTaskis a subclass ofMergerTaskthat represents a task for mergingbasf2ROOT files using theb2file-mergecommand-line tool.- cmd = ['b2file-merge', '-f']#
- class b2luigi.basf2_helper.tasks.Basf2nTupleMergeTask(*args, **kwargs)[source]#
Bases:
MergerTask- property cmd#
Command to use to merge basf2 tuple files.
- b2luigi.basf2_helper.utils.get_basf2_git_hash()[source]#
Retrieve the version or git hash of the
basf2release being used.This function determines the version of the
basf2framework in use. If the environment variableBELLE2_RELEASEis set to"head"or is not defined, it attempts to import thebasf2.versionmodule to retrieve the version information. If the import fails, a warning is issued, and the version is set to"not_set".- Returns:
The basf2 release name, its version hash, or “not_set” if basf2 cannot be imported or no release is configured.
- Return type:
str
Warning
ImportWarning: Raised if the basf2.version module cannot be imported.