uproot_custom package

Contents

uproot_custom package#

Submodules#

uproot_custom.AsCustom module#

class uproot_custom.AsCustom.AsCustom(branch: TBranch, context: dict, simplify: bool)[source]#

Bases: CustomInterpretation

awkward_form(file, context=None, index_format='i64', header=False, tobject_header=False, breadcrumbs=())[source]#
Parameters:
  • file (uproot.reading.ReadOnlyFile) – File to use to generate uproot.model.Model classes from its uproot.reading.ReadOnlyFile.streamers and file_path for error messages.

  • context (dict) – Context for the Form-generation; defaults are the remaining arguments below.

  • index_format (str) – Format to use for indexes of the awkward.forms.Form; may be "i32", "u32", or "i64".

  • header (bool) – If True, include header fields of each C++ class.

  • tobject_header (bool) – If True, include header fields of each TObject base class.

  • breadcrumbs (tuple of class objects) – Used to check for recursion. Types that contain themselves cannot be Awkward Arrays because the depth of instances is unknown.

The awkward.forms.Form to use to put objects of type type in an Awkward Array.

basket_array(data, byte_offsets, basket, branch, context, cursor_offset, library, interp_options)[source]#
Parameters:
  • data (array of numpy.uint8) – Raw but uncompressed data from the TBasket. If the TBasket has offsets and navigational metadata, it is not included in this array.

  • byte_offsets (array of numpy.int32) – Index where each entry of the TBasket starts and stops. The header is not included (i.e. the first offset is 0), and the length of this array is one greater than the number of entries in the TBasket.

  • basket (uproot.models.TBasket.Model_TBasket) – The TBasket object.

  • context (dict) – Auxiliary data used in deserialization.

  • cursor_offset (int) – Correction to the integer keys used in uproot.source.cursor.Cursor.refs for objects deserialized by reference (uproot.deserialization.read_object_any).

  • library (uproot.interpretation.library.Library) – The requested library for output.

  • interp_options (dict) – Flags and other options passed through the interpretation process.

Performs the first step of interpretation, from uncompressed TBasket data to a temporary array.

property cache_key: str#

The cache key of the interpretation.

final_array(basket_arrays, entry_start, entry_stop, entry_offsets, library, branch, options)[source]#

Concatenate the arrays from the baskets and return the final array.

classmethod match_branch(branch: TBranch, context: dict, simplify: bool) bool[source]#
Parameters:
  • branch (uproot.behaviors.TBranch.TBranch) – The TBranch to interpret as an array.

  • context (dict) – Auxiliary data used in deserialization.

  • simplify (bool) – If True, call uproot.interpretation.objects.AsObjects.simplify on any uproot.interpretation.objects.AsObjects to try to get a more efficient interpretation.

Accept arguments from uproot.interpretation.identify.interpretation_of, determine whether this interpretation can be applied to the given branch.

target_branches: set[str] = {}#
property typename: str#

The name of the type of the interpretation.

uproot_custom.factories module#

class uproot_custom.factories.AnyClassFactory(name: str, sub_factories: list[Factory])[source]#

Bases: GroupFactory

This class tries to read any class object that is not handled by other factories.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Never match items. If one needs to use this factory, instatiate it directly.

classmethod priority()[source]#

Return the call priority of this factory. Factories with higher priority will be called first.

class uproot_custom.factories.BaseObjectFactory(name: str, sub_factories: list[Factory])[source]#

Bases: GroupFactory

This class reads base-object of an object. The base object has fNBytes(uint32), fVersion(uint16) at the beginning.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cls_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Never match items. If one needs to use this factory, instatiate it directly.

class uproot_custom.factories.CStyleArrayFactory(name: str, element_factory: Factory, flat_size: int, fMaxIndex: int, fArrayDim: ndarray)[source]#

Bases: Factory

This class reads a C-style array from a binary parser.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Return an instance of this factory when current item matches this factory, otherwise return None.

Parameters:
  • top_type_name (str) – Name of the top-level class of current item. For example, vector<int> -> vector.

  • cur_streamer_info (dict) – Streamer information of current item.

  • all_streamer_info (dict) – Dictionary storing streamer information of all types. The key is the classname, pair is a dictionary like cur_streamer_info.

  • item_path (str) – Indicating which item is being matched. One can use this variable to apply specific behavior.

Returns:

A dictionary containing all necessary information of building C++ reader and reconstruct raw data to awkward array for current item.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

classmethod priority()[source]#

Return the call priority of this factory. Factories with higher priority will be called first.

class uproot_custom.factories.EmptyFactory(name: str)[source]#

Bases: Factory

This factory does nothing. It’s just a place holder.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

This factory will never match items. If one needs to use this factory, instatiate it directly.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

class uproot_custom.factories.Factory(name: str)[source]#

Bases: object

Base class of reader factories. Reader factory is in charge of generating reader configuration tree, build an combine C++ reader and reconstruct raw array from C++ reader into structured awkward array.

build_cpp_reader() IReader[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name: str, cur_streamer_info: dict, all_streamer_info: dict, item_path: str, **kwargs) None | Factory[source]#

Return an instance of this factory when current item matches this factory, otherwise return None.

Parameters:
  • top_type_name (str) – Name of the top-level class of current item. For example, vector<int> -> vector.

  • cur_streamer_info (dict) – Streamer information of current item.

  • all_streamer_info (dict) – Dictionary storing streamer information of all types. The key is the classname, pair is a dictionary like cur_streamer_info.

  • item_path (str) – Indicating which item is being matched. One can use this variable to apply specific behavior.

Returns:

A dictionary containing all necessary information of building C++ reader and reconstruct raw data to awkward array for current item.

make_awkward_content(raw_data: Any) Content[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form() Form[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

classmethod priority() int[source]#

Return the call priority of this factory. Factories with higher priority will be called first.

class uproot_custom.factories.GroupFactory(name: str, sub_factories: list[Factory])[source]#

Bases: Factory

This factory groups differernt factory together. You can use this factory to read specific format of data as you like.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Never match items. If one needs to use this factory, instatiate it directly.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

class uproot_custom.factories.ObjectHeaderFactory(name: str, element_factory: Factory)[source]#

Bases: Factory

This class reads object header: 1. fNBytes 2. fTag 3. if (fTag == -1) null-terminated-string

If will be called automatically if no other factory matches. Also, it can be manually used to read object header.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

This factory will always match items. If one needs to use this factory, instatiate it directly.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

class uproot_custom.factories.PrimitiveFactory(name: str, ctype: str)[source]#

Bases: Factory

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Return when top_type_name is primitive type.

cpp_reader_map = {'bool': <class 'uproot_custom.cpp.BoolReader'>, 'd': <class 'uproot_custom.cpp.DoubleReader'>, 'f': <class 'uproot_custom.cpp.FloatReader'>, 'i1': <class 'uproot_custom.cpp.Int8Reader'>, 'i2': <class 'uproot_custom.cpp.Int16Reader'>, 'i4': <class 'uproot_custom.cpp.Int32Reader'>, 'i8': <class 'uproot_custom.cpp.Int64Reader'>, 'u1': <class 'uproot_custom.cpp.UInt8Reader'>, 'u2': <class 'uproot_custom.cpp.UInt16Reader'>, 'u4': <class 'uproot_custom.cpp.UInt32Reader'>, 'u8': <class 'uproot_custom.cpp.UInt64Reader'>}#
ctype_primitive_map = {'bool': 'bool', 'd': 'float64', 'f': 'float32', 'i1': 'int8', 'i2': 'int16', 'i4': 'int32', 'i8': 'int64', 'u1': 'uint8', 'u2': 'uint16', 'u4': 'uint32', 'u8': 'uint64'}#
ftypes = {1: 'i1', 2: 'i2', 3: 'i4', 4: 'i8', 5: 'f', 8: 'd', 11: 'u1', 12: 'u2', 13: 'u4', 14: 'u8', 18: 'bool'}#
make_awkward_content(raw_data: ndarray)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

typenames = {'Bool_t': 'bool', 'Char_t': 'i1', 'Double_t': 'd', 'Float_t': 'f', 'Int_t': 'i4', 'Long_t': 'i8', 'Short_t': 'i2', 'UChar_t': 'u1', 'UInt_t': 'u4', 'ULong_t': 'u8', 'UShort_t': 'u2', 'bool': 'bool', 'char': 'i1', 'double': 'd', 'float': 'f', 'int': 'i4', 'int16_t': 'i2', 'int32_t': 'i4', 'int64_t': 'i8', 'int8_t': 'i1', 'long': 'i8', 'long long': 'i8', 'short': 'i2', 'signed char': 'i1', 'signed int': 'i4', 'signed long': 'i8', 'signed long long': 'i8', 'signed short': 'i2', 'uint16_t': 'u2', 'uint32_t': 'u4', 'uint64_t': 'u8', 'uint8_t': 'u1', 'unsigned char': 'u1', 'unsigned int': 'u4', 'unsigned long': 'u8', 'unsigned long long': 'u8', 'unsigned short': 'u2'}#
class uproot_custom.factories.STLMapFactory(name: str, with_header: bool, objwise_or_memberwise: Literal[-1, 0, 1], key_factory: Factory, val_factory: Factory)[source]#

Bases: Factory

This class reads mapping-like STL containers.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Return when top_type_name is in cls.target_types.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

target_types = ['map', 'unordered_map', 'multimap', 'unordered_multimap']#
class uproot_custom.factories.STLSeqFactory(name: str, with_header: bool, objwise_or_memberwise: Literal[-1, 0, 1], element_factory: Factory)[source]#

Bases: Factory

This factory reads sequence-like STL containers.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Return when top_type_name is in cls.target_types.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

target_types = ['vector', 'array', 'list', 'set', 'multiset', 'unordered_set', 'unordered_multiset']#
class uproot_custom.factories.STLStringFactory(name: str, with_header: bool)[source]#

Bases: Factory

This class reads std::string.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Return an instance of this factory when current item matches this factory, otherwise return None.

Parameters:
  • top_type_name (str) – Name of the top-level class of current item. For example, vector<int> -> vector.

  • cur_streamer_info (dict) – Streamer information of current item.

  • all_streamer_info (dict) – Dictionary storing streamer information of all types. The key is the classname, pair is a dictionary like cur_streamer_info.

  • item_path (str) – Indicating which item is being matched. One can use this variable to apply specific behavior.

Returns:

A dictionary containing all necessary information of building C++ reader and reconstruct raw data to awkward array for current item.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

class uproot_custom.factories.TArrayFactory(name: str, ctype: str)[source]#

Bases: Factory

This class reads TArray from a binary paerser.

TArray includes TArrayC, TArrayS, TArrayI, TArrayL, TArrayL64, TArrayF, and TArrayD. Corresponding ctype is u1, u2, i4, i8, i8, f, and d.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Return when top_type_name is in cls.typenames.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

typenames = {'TArrayC': 'i1', 'TArrayD': 'd', 'TArrayF': 'f', 'TArrayI': 'i4', 'TArrayL': 'i8', 'TArrayL64': 'i8', 'TArrayS': 'i2'}#
class uproot_custom.factories.TObjectFactory(name: str, keep_data: bool)[source]#

Bases: Factory

This class reads base TObject from a binary parser. You should skip reconstructing array when this factory keeps no data, since the method reconstruct_array will always return None.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

The configuration contains: - factory: cls - name: fName, - `keep_data: Whether keep data from TObject.

keep_data_itempaths: set[str] = {}#
make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

class uproot_custom.factories.TStringFactory(name: str, with_header: bool)[source]#

Bases: Factory

This class reads TString from a binary parser.

build_cpp_reader()[source]#

Build concrete C++ reader.

Returns:

An instance of uproot_custom.cpp.IReader.

classmethod build_factory(top_type_name, cur_streamer_info, all_streamer_info, item_path, **kwargs)[source]#

Return an instance of this factory when current item matches this factory, otherwise return None.

Parameters:
  • top_type_name (str) – Name of the top-level class of current item. For example, vector<int> -> vector.

  • cur_streamer_info (dict) – Streamer information of current item.

  • all_streamer_info (dict) – Dictionary storing streamer information of all types. The key is the classname, pair is a dictionary like cur_streamer_info.

  • item_path (str) – Indicating which item is being matched. One can use this variable to apply specific behavior.

Returns:

A dictionary containing all necessary information of building C++ reader and reconstruct raw data to awkward array for current item.

make_awkward_content(raw_data)[source]#

Reconstruct awkward contents with raw data returned from the C++ reader.

Parameters:

raw_data – Data returned from C++ reader.

Returns:

Awkward content to build corresponding array.

Return type:

awkward.contents.Content

make_awkward_form()[source]#

Generate awkward form with tree configuration.

Returns:

Awkward form of current item.

Return type:

awkward.forms.Form

uproot_custom.factories.build_factory(cur_streamer_info: dict, all_streamer_info: dict, item_path: str = '', **kwargs) Factory[source]#

Generate factory with a given streamer information.

Parameters:
  • cur_streamer_info (dict) – Streamer information of current item.

  • all_streamer_info (dict) – All streamer information.

  • item_path (str) – Path to the item.

Returns:

An instance of Factory.

uproot_custom.factories.read_branch(branch: TBranch, data: ndarray[uint8], offsets: ndarray, cur_streamer_info: dict, all_streamer_info: dict[str, list[dict]], item_path: str = '')[source]#
uproot_custom.factories.read_branch_awkward_form(branch: TBranch, cur_streamer_info: dict, all_streamer_info: dict[str, list[dict]], item_path: str = '')[source]#

uproot_custom.utils module#

uproot_custom.utils.get_dims_from_branch(branch: TBranch) tuple[tuple[int, ...], bool][source]#
uproot_custom.utils.get_map_key_val_typenames(type_name: str) tuple[str, str][source]#

Get the key and value type names of a map type.

e.g. map<int, vector<int>> -> (int, vector<int>)

uproot_custom.utils.get_sequence_element_typename(type_name: str) str[source]#

Get the element type name of a vector type.

e.g. vector<vector<int>> -> vector<int>

uproot_custom.utils.get_top_type_name(type_name: str) str[source]#
uproot_custom.utils.regularize_object_path(object_path: str) str[source]#

Module contents#