basf2_helper package#
- class b2luigi.basf2_helper.targets.ROOTLocalTarget(*args, **kwargs)[source]#
Bases:
LocalTarget
- class ROOTLocalTarget[source]#
Bases:
object
A custom target class that extends
b2luigi.LocalTarget
to handle ROOT files.This class overrides the
exists
method 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
exists
method. 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:
DispatchableTask
- class Basf2Task[source]#
Bases:
object
A custom task class for handling
basf2
-related tasks in theb2luigi
framework. This class extendsb2luigi.DispatchableTask
and provides additional functionality for managing output file targets and serialized parameters.- git_hash#
A parameter representing the
basf2
git hash. It is set to the currentbasf2
git hash (see:get_basf2_git_hash
) by default and marked as non-significant to avoid affecting the task’s unique ID.- Type:
b2luigi.Parameter
- git_hash = <luigi.parameter.Parameter object>#
- 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.ROOTLocalTarget
for 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_name
and the superclass method.**kwargs – Keyword arguments passed to
get_output_file_name
and the superclass method.
- Returns:
- A
b2luigi.basf2_helper.ROOTLocalTarget
if the file extension is “.root”, otherwise the result of the superclass’s
get_output_file_target
method.
- 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:
Basf2Task
A task for running a
basf2
processing path within theb2luigi
framework.In contrast to the normal
(b2)luigi
tasks, the execution logic of aBasf2PathTask
is not defined in arun
method but increate_path
. Thecreate_path
method needs to return thebasf2
path that is created in the steering file. Furthermore, theProgress
module 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_path
method. 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
basf2
framework.It sets the number of processes for basf2 if
self.num_processes
is specified. Then, it creates a processing path, adds thebasf2.Progress
module 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_event
is not set, it defaults to0
(process all events). After processing, it prints thebasf2
statistics.- Raises:
ImportError – If the basf2 module cannot be found.
- class b2luigi.basf2_helper.tasks.SimplifiedOutputBasf2Task(*args, **kwargs)[source]#
Bases:
Basf2PathTask
A task that simplifies the handling of output files in a
basf2
processing path.This class is intended to be subclassed (see
Basf2PathTask
), and thecreate_path
method must be implemented to define thebasf2
processing path. Theoutput
method identifies and collects output file targets from the modules in the path.
- class b2luigi.basf2_helper.tasks.MergerTask(*args, **kwargs)[source]#
Bases:
Basf2Task
A 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
keys
attribute.- Yields:
The result of
b2luigi.Task.add_to_output()
for each key that passes the filtering conditions.
- Filtering Conditions:
If the task has a
keys
attribute, only keys present inself.keys
are 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.keys
exists).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:
MergerTask
HaddTask
is a subclass ofMergerTask
that represents a task for merging ROOT files using thehadd
command-line tool.- cmd = ['hadd', '-f']#
- class b2luigi.basf2_helper.tasks.Basf2FileMergeTask(*args, **kwargs)[source]#
Bases:
MergerTask
Basf2FileMergeTask
is a subclass ofMergerTask
that represents a task for mergingbasf2
ROOT files using theb2file-merge
command-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
basf2
release being used.This function determines the version of the
basf2
framework in use. If the environment variableBELLE2_RELEASE
is set to"head"
or is not defined, it attempts to import thebasf2.version
module 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.