Input

ROOT readers:

ReadROOTFile([types, keys, selector])

Read ROOT files from flow.

ReadROOTTree([leaves, get_entries])

Read ROOT trees from flow.

ROOT readers

To use these classes, ROOT must be installed.

class ReadROOTFile(types=None, keys=None, selector=None)[исходный код]

Read ROOT files from flow.

Keyword arguments specify which objects should be read from ROOT files.

types sets the list of possible objects types.

keys specifies a list of allowed objects“ names. Only simple keys are currently allowed (no regular expressions).

If both types and keys are provided, then objects that satisfy any of types or keys are read.

selector is a general function that accepts an object from a ROOT file and returns a boolean. If selector is given, both types and keys must be omitted, or LenaTypeError is raised.

run(flow)[исходный код]

Read ROOT files from flow and yield objects they contain.

For file to be read, data part of the value must be a string (file’s path) and context.input.read_root_file must not be False. Other values pass unchanged. After all entries from the file are yielded, it is closed.

context.input.root_file_path is updated with the path to the ROOT file.

Предупреждение

After a ROOT file is closed, all its contained objects are destroyed. Make all processing within one flow: don’t save yielded values to a list, or save copies of them.

class ReadROOTTree(leaves=None, get_entries=None)[исходный код]

Read ROOT trees from flow.

Trees can be read in two ways.

In the first variant, leaves is a list of strings that enables to read the specified tree leaves. Only branches containing the leaves are read. To get a leaf from a specific branch, add it to the leaf’s name with a slash, e.g. «my_branch/my_leaf». Tree entries are yielded as named tuples with fields named after leaves.

A leaf can contain a branch name prepended

In the second variant, get_entries is a function that accepts a ROOT tree and yields its entries.

Exactly one of leaves or get_entries (not both) must be provided, otherwise LenaTypeError is raised.

Примечание

To collect the resulting values (not use them on the fly), make copies of them in get_entries (e.g. use copy.deepcopy). Otherwise all items will be the last value read.

run(flow)[исходный код]

Read ROOT trees from flow and yield their contents.

context.input.root_tree_name is updated with the name of the current tree.

The tree must have one and only one branch corresponding to each leaf, otherwise LenaRuntimeError is raised. To read leaves with the same name in several branches, specify branch names for them.