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_pathfor 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
TObjectbase 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.Formto 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 theTBasket. If theTBaskethas offsets and navigational metadata, it is not included in this array.byte_offsets (array of
numpy.int32) – Index where each entry of theTBasketstarts and stops. The header is not included (i.e. the first offset is0), and the length of this array is one greater than the number of entries in theTBasket.basket (uproot.models.TBasket.Model_TBasket) – The
TBasketobject.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
TBasketdata 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
TBranchto 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:
GroupFactoryThis 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.
- class uproot_custom.factories.BaseObjectFactory(name: str, sub_factories: list[Factory])[source]#
Bases:
GroupFactoryThis class reads base-object of an object. The base object has fNBytes(uint32), fVersion(uint16) at the beginning.
- class uproot_custom.factories.CStyleArrayFactory(name: str, element_factory: Factory, flat_size: int, fMaxIndex: int, fArrayDim: ndarray)[source]#
Bases:
FactoryThis 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
- class uproot_custom.factories.EmptyFactory(name: str)[source]#
Bases:
FactoryThis 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.
- class uproot_custom.factories.Factory(name: str)[source]#
Bases:
objectBase 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
- class uproot_custom.factories.GroupFactory(name: str, sub_factories: list[Factory])[source]#
Bases:
FactoryThis 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.
- class uproot_custom.factories.ObjectHeaderFactory(name: str, element_factory: Factory)[source]#
Bases:
FactoryThis 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.
- 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:
FactoryThis 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:
FactoryThis 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:
FactoryThis 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.
- class uproot_custom.factories.TArrayFactory(name: str, ctype: str)[source]#
Bases:
FactoryThis 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:
FactoryThis 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] = {}#
- class uproot_custom.factories.TStringFactory(name: str, with_header: bool)[source]#
Bases:
FactoryThis 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.
- 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.utils module#
- 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>)