uproot_custom.detree package¶
Subpackages¶
- uproot_custom.detree.compiler package
- Submodules
- uproot_custom.detree.compiler.frontend module
- uproot_custom.detree.compiler.ir_builder module
IRFunctionBuilderIRFunctionBuilder.assert_str_eq()IRFunctionBuilder.block()IRFunctionBuilder.buf_append()IRFunctionBuilder.buf_append_const()IRFunctionBuilder.buf_append_len()IRFunctionBuilder.buf_append_offset()IRFunctionBuilder.buf_last()IRFunctionBuilder.buf_len()IRFunctionBuilder.call()IRFunctionBuilder.const()IRFunctionBuilder.const_into()IRFunctionBuilder.cursor()IRFunctionBuilder.data_size()IRFunctionBuilder.emit()IRFunctionBuilder.emit_op()IRFunctionBuilder.entries()IRFunctionBuilder.finish()IRFunctionBuilder.for_range()IRFunctionBuilder.if_()IRFunctionBuilder.init_offset()IRFunctionBuilder.local()IRFunctionBuilder.mov()IRFunctionBuilder.offset_seek()IRFunctionBuilder.read_append()IRFunctionBuilder.read_bulk()IRFunctionBuilder.read_cstr()IRFunctionBuilder.read_fields()IRFunctionBuilder.read_fnb()IRFunctionBuilder.read_scalar()IRFunctionBuilder.read_strided()IRFunctionBuilder.read_version()IRFunctionBuilder.ref_count()IRFunctionBuilder.ref_get_class()IRFunctionBuilder.ref_get_obj()IRFunctionBuilder.ref_has()IRFunctionBuilder.ref_set_class()IRFunctionBuilder.ref_set_obj()IRFunctionBuilder.reg()IRFunctionBuilder.ret()IRFunctionBuilder.set_cursor()IRFunctionBuilder.skip()IRFunctionBuilder.skip_cstr()IRFunctionBuilder.skip_fnb()IRFunctionBuilder.skip_objhdr()IRFunctionBuilder.skip_reg()IRFunctionBuilder.skip_tobject()IRFunctionBuilder.skip_version()IRFunctionBuilder.state_get()IRFunctionBuilder.state_iadd()IRFunctionBuilder.state_set()IRFunctionBuilder.str_const()IRFunctionBuilder.str_load()IRFunctionBuilder.str_store()IRFunctionBuilder.temp()IRFunctionBuilder.throw()IRFunctionBuilder.while_()
- Module contents
Submodules¶
uproot_custom.detree.bufferproxy module¶
uproot_custom.detree.builtin module¶
The built-in readers, written in the detree reader API.
These are the same twelve reads as uproot_custom.python, kept separate on purpose: that module stays an independent implementation of the same format, so a disagreement between the two is a finding rather than a shared assumption. What differs is that a reader here declares its buffers, constants and sub-readers as fields and leaves read free of allocation and of raise, which is what lets the compiler lower it.
Buffers are declared with a struct typecode (“i”, “q”, “d”, …), a NumPy dtype or a dtype string; Buffer normalises all three to one fixed-width typecode and Buf maps it to the array dtype.
Nothing is interpreted at run time: read / read_many / read_until / read_many_memberwise exist only as source for the frontend, and data runs in Python over the buffers the virtual machine filled.
- class uproot_custom.detree.builtin.AnyClassReader(name: str, **values)[source]¶
Bases:
ReaderAny object framed by its byte count, which the read must consume exactly.
- class uproot_custom.detree.builtin.AnyPointerReader(name: str, **values)[source]¶
Bases:
ReaderA pointer written by TBuffer::WriteObjectAny.
The tag decides what follows: nothing (a null pointer), a back reference, a new class name, or a new object of a class already named. Class names and object indexes survive across events, so they are declared as state.
- class uproot_custom.detree.builtin.CStyleArrayReader(name: str, **values)[source]¶
Bases:
ReaderA C-style array, sized by the streamer info or by the entry boundary.
- class uproot_custom.detree.builtin.EmptyReader(name: str, **values)[source]¶
Bases:
ReaderReads nothing; used where a member’s value is not wanted.
- class uproot_custom.detree.builtin.GroupReader(name: str, **values)[source]¶
Bases:
ReaderSeveral readers over one object, in declaration order.
- class uproot_custom.detree.builtin.PrimitiveReader(name: str, **values)[source]¶
Bases:
ReaderA leaf of a built-in type; the value is read into a buffer of its own.
- class uproot_custom.detree.builtin.STLMapReader(name: str, **values)[source]¶
Bases:
ReaderA mapping-like STL container; keys and values are separate buffers.
- with_header: bool¶
- class uproot_custom.detree.builtin.STLSeqReader(name: str, **values)[source]¶
Bases:
ReaderA sequence-like STL container (vector, list, set, …).
- with_header: bool¶
- class uproot_custom.detree.builtin.STLStringReader(name: str, **values)[source]¶
Bases:
ReaderA std::string, which keeps its size before the characters.
- with_header: bool¶
- class uproot_custom.detree.builtin.TArrayReader(name: str, **values)[source]¶
Bases:
ReaderA TArray/std::array: a uint32 size then a bulk read.
uproot_custom.detree.cache module¶
uproot_custom.detree.decl module¶
- class uproot_custom.detree.decl.Buffer(type: Literal['b', 'B', 'h', 'H', 'i', 'I', 'q', 'Q', 'f', 'd'] | dtype | type | str | None = None, *, init=(), from_const: str | None = None, kind: Literal['data', 'offsets'] = 'data')[source]¶
Bases:
_FieldA typed buffer that a read path appends to.
The element type is a
structtypecode ("i"), a NumPy dtype (np.int32,np.dtype("i4")) or a dtype string ("int32"); all forms normalise to the fixed-width typecode the machine stores.- resolve_typecode(reader) Literal['b', 'B', 'h', 'H', 'i', 'I', 'q', 'Q', 'f', 'd'][source]¶
The normalised typecode of this buffer in reader, after its constants are set.
A reader whose element type is a constructor argument (a primitive, a TArray) names that Const field in from_const, so one class serves every dtype. The constant has to be declared before the buffer, which is also the order the fields are initialised in.
- class uproot_custom.detree.decl.ChildDict[source]¶
Bases:
_FieldDictionary of child fields, not enabled yet.
- class uproot_custom.detree.decl.Const(default=<object object>, *, type=None, choices=None, ge=None, le=None)[source]¶
Bases:
_Field
- class uproot_custom.detree.decl.Reader(name: str, **values)[source]¶
Bases:
object- property buffers¶
- property children¶
uproot_custom.detree.interp module¶
Run a detree reader tree in Python, without the virtual machine.
The reader’s read / read_many / read_until / read_many_memberwise are ordinary Python methods; uproot_custom.detree.compiler.frontend only compiles them so the machine can execute them faster. This module runs them directly, through uproot_custom.detree.stream.Stream, which implements the same operations as the machine’s opcodes.
Two uses:
debugging a reader – print, pdb and a Python traceback all work;
a second opinion on the machine and on the compiler – the three executors (uproot_custom.python, this one, and the VM) must agree on every basket.
State needs no write-back here: the reader’s own attributes are the state.
- uproot_custom.detree.interp.read_basket(reader: Reader, data: bytes, offsets: ndarray | None, cursor_offset=0, nbyte=None)[source]¶
Run reader’s methods over one basket; return the reader.
The reader is uproot_custom.detree.decl.Reader.reset first, so one tree reads one basket after another and the arrays an earlier call returned keep their values.
The cursor runs on across events, exactly as it does in the machine and in uproot_custom.python.read_data, and each event must end on its own entry offset.
- Parameters:
reader – the detree reader tree to run.
data – the basket bytes.
offsets – the entry offsets, or None to derive them from nbyte.
cursor_offset – the basket’s fKeylen, which is what uproot passes to a backend. An object reference is keyed by its position within the file (pos + fKeylen + kMapOffset), so a pointer member reads the wrong bytes when this is 0 – silently, without an error.
nbyte – the fixed entry size, used when offsets is None.
- Returns:
The reader, holding the buffers and states of the basket just read.
- uproot_custom.detree.interp.read_data(reader: Reader, data: bytes, offsets: ndarray | None, cursor_offset=0, nbyte=None)[source]¶
Read one basket in Python and return whatever reader.data() returns.
- Parameters:
reader – the detree reader tree to run.
data – the basket bytes.
offsets – the entry offsets, or None to derive them from nbyte.
cursor_offset – the basket’s fKeylen.
nbyte – the fixed entry size, used when offsets is None.
- Returns:
Whatever reader.data() returns.
uproot_custom.detree.run module¶
What compiling produces, and the one seam that runs it.
The frontend compiles a reader tree to detree-vm IR and detree.compile turns it into canonical module bytes. Those bytes are the artefact this module caches; a detree.Machine is built for every run, because a machine holds the mutable per-basket state and is not thread-safe.
detree.Machine.run resets the machine it is called on, so a caller that keeps a machine can serve basket after basket; the read path here builds a fresh one instead, which keeps concurrent readers independent without a thread-local cache.
- uproot_custom.detree.run.apply_outputs(reader: Reader, outputs: dict, states=None, path='root')[source]¶
Write the buffers the machine filled back into the reader and its children.
A native buffer adopts the array without copying. states is the {name: value} mapping the machine returns; when given, the Python side of a reader ends up with the values the run ended with.
- uproot_custom.detree.run.backend_name()[source]¶
Which detree-vm machine run selects.
Detree-VM’s official release ships the Rust machine only. The value comes from uproot_custom.detree.get_impl, an internal test helper; the environment variable it reads is only for development.
- uproot_custom.detree.run.compiled_for_reader(reader: Reader) bytes[source]¶
Return the cached compiled bytes of a reader tree, compiling it on first use.
- uproot_custom.detree.run.core()[source]¶
detree-vm when it has a compiled backend, or None.
The Python reference machine is always available; this probe is only used to decide whether a compiled machine can be exercised in tests and benchmarks.
- uproot_custom.detree.run.entry_offsets(data, offsets, nbyte=None)[source]¶
The entry offsets of a basket, derived from nbyte when absent.
A fixed-width branch has no byte_offsets; every entry is then the same size and the offsets are just i * nbyte. Every basket of a branch but the last has the same length, so the array is built once per length.
- uproot_custom.detree.run.read_data(reader: Reader, data: bytes | ndarray, offsets: ndarray | None, cursor_offset: int = 0, nbyte: int | None = None)[source]¶
Read one basket: compile reader, run it, hand the buffers back.
cursor_offset is the basket’s fKeylen, as uproot passes it; an object reference is keyed by its position within the file, so a pointer member reads the wrong bytes when this is 0.
The reader is reset first, exactly as uproot_custom.detree.interp does, so one tree reads basket after basket on either executor and the arrays a previous call returned stay valid.
- Parameters:
reader – the detree reader tree to compile and run.
data – the basket bytes.
offsets – the entry offsets, or None to derive them from nbyte.
cursor_offset – the basket’s fKeylen.
nbyte – the fixed entry size, used when offsets is None.
- Returns:
Whatever reader.data() returns; the caller turns it into an awkward array, usually through the factory that built the reader.
- uproot_custom.detree.run.run(code: bytes, data: bytes | ndarray, offsets: ndarray | None, cursor_offset: int = 0, nbyte: int | None = None)[source]¶
Run code over one basket; return (buffers, states).
buffers is {declared name: 1-D array} and states is {declared name: int | str | None} (a name slot comes back decoded from the string arena, None when it is empty).
A fresh detree.Machine is built for every call, so two threads may run the same module at the same time without sharing registers or buffers.
- Parameters:
code – the compiled reader bytes to run.
data – the basket bytes.
offsets – the entry offsets, or None to derive them from nbyte.
cursor_offset – the basket’s fKeylen.
nbyte – the fixed entry size, used when offsets is None; a fixed-width branch is then i * nbyte per event.
- Returns:
(buffers, states) as described above.
uproot_custom.detree.stream module¶
- class uproot_custom.detree.stream.Stream(data: bytes, offsets: list[int], initial_cursor_position: int = 0)[source]¶
Bases:
objectA byte buffer with a cursor, the entry offsets and the object references.
- property entries¶
- read_bulk(buffer: BufferProxy, count: int)[source]¶
Read count values of buffer’s typecode, in one extend.
- read_into(buffer: BufferProxy)[source]¶
Read one value of buffer’s own dtype and append it.
- refs¶
tag ->
("object", index)or("class", name)
Module contents¶
Detree: the reader DSL, its compiler, and the detree-vm execution seam.
uproot_custom.detree.decl + uproot_custom.detree.builtin – the declarative readers the frontend compiles, and the built-in implementations of the ROOT types;
uproot_custom.detree.compiler.frontend – compile_reader builds detree-vm IR and hands it to detree.compile for optimization and lowering;
uproot_custom.detree.run – caches the compiled module bytes per reader structure, builds a machine for one basket, and writes its buffers back into the reader.
uproot_custom.detree.interp is the Python executor of the same reader methods, used for debugging and as an oracle in the differential tests.
get_impl, set_impl and use_impl exist for internal tests only and are not part of the public API; Detree-VM’s official release ships the Rust machine only.
- class uproot_custom.detree.Buffer(type: Literal['b', 'B', 'h', 'H', 'i', 'I', 'q', 'Q', 'f', 'd'] | dtype | type | str | None = None, *, init=(), from_const: str | None = None, kind: Literal['data', 'offsets'] = 'data')[source]¶
Bases:
_FieldA typed buffer that a read path appends to.
The element type is a
structtypecode ("i"), a NumPy dtype (np.int32,np.dtype("i4")) or a dtype string ("int32"); all forms normalise to the fixed-width typecode the machine stores.- resolve_typecode(reader) Literal['b', 'B', 'h', 'H', 'i', 'I', 'q', 'Q', 'f', 'd'][source]¶
The normalised typecode of this buffer in reader, after its constants are set.
A reader whose element type is a constructor argument (a primitive, a TArray) names that Const field in from_const, so one class serves every dtype. The constant has to be declared before the buffer, which is also the order the fields are initialised in.
- class uproot_custom.detree.BufferProxy(typecode: Literal['b', 'B', 'h', 'H', 'i', 'I', 'q', 'Q', 'f', 'd'], init=(), *, kind: str = 'data')[source]¶
Bases:
object- property dtype¶
- init¶
- kind¶
- typecode¶
- class uproot_custom.detree.Const(default=<object object>, *, type=None, choices=None, ge=None, le=None)[source]¶
Bases:
_Field
- class uproot_custom.detree.Reader(name: str, **values)[source]¶
Bases:
object- property buffers¶
- property children¶
- class uproot_custom.detree.Stream(data: bytes, offsets: list[int], initial_cursor_position: int = 0)[source]¶
Bases:
objectA byte buffer with a cursor, the entry offsets and the object references.
- property entries¶
- read_bulk(buffer: BufferProxy, count: int)[source]¶
Read count values of buffer’s typecode, in one extend.
- read_into(buffer: BufferProxy)[source]¶
Read one value of buffer’s own dtype and append it.
- refs¶
tag ->
("object", index)or("class", name)