uproot_custom.cpp module#
-
namespace uproot
Typedefs
Functions
Read data from a binary buffer using the provided reader.
- Parameters:
data – Binary data as a numpy array of uint8_t
offsets – Offsets for each entry as a numpy array of uint32_t
reader – Shared pointer to the top-level reader
- Returns:
(Possibly nested) numpy array containing the read data
-
PYBIND11_MODULE(cpp, m)#
-
class AnyClassReader : public uproot::IReader#
Reader for composed class types. Similar to GroupReader, but reads a
fNBytes+fVersionheader before reading the grouped elements.Public Functions
Construct a new Any Class Reader object.
- Parameters:
name – Name of the reader.
element_readers – The element readers for the Any class. In Python, this should be a list of readers.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read the object from the buffer. First reads the
fNBytes+fVersionheader, then reads all elements sequentially.- Parameters:
buffer – The binary buffer to read from.
-
inline virtual uint32_t read_many_memberwise(BinaryBuffer &buffer, const int64_t count) override#
Read multiple objects from the buffer in member-wise mode. This method calls IReader::read_many() of each element reader sequentially.
- Parameters:
buffer – The binary buffer to read from.
count – Number of objects to read.
- Returns:
Number of objects read. Should be equal to count.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
A list of data from each element reader.
Private Members
-
vector<SharedReader> m_element_readers#
The element readers for the Any class.
-
class CStyleArrayReader : public uproot::IReader#
Reader for C-style arrays and std::array.
Public Functions
Construct a new CStyleArrayReader object.
- Parameters:
name – Name of the reader.
flat_size – Flatten size of the array. If negative, means variable size.
element_reader – Reader for the array elements.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read the array from the buffer. If m_flat_size is positive, calls IReader::read_many() function of m_element_reader. Otherwise, reads until the end of the current entry in the buffer.
- Parameters:
buffer – The binary buffer to read from.
-
inline virtual uint32_t read_many(BinaryBuffer &buffer, const int64_t count) override#
Read multiple arrays from the buffer. Only supported when m_flat_size is positive.
- Parameters:
buffer – The binary buffer to read from.
count – Number of arrays to read.
- Returns:
Number of arrays read.
-
inline virtual uint32_t read_until(BinaryBuffer &buffer, const uint8_t *end_pos) override#
Read arrays from the buffer until reaching the end position. Not supported.
- Parameters:
buffer – The binary buffer to read from.
end_pos – The end position to stop reading.
- Throws:
std::runtime_error – Always thrown since this method is not supported.
- Returns:
Number of arrays read.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
If m_flat_size is positive, directly return the data from m_element_reader. Otherwise, return a tuple contains: (offsets, elements_data).
Private Members
-
const int64_t m_flat_size#
Flatten size of the array. If negative, means variable size.
-
SharedVector<int64_t> m_offsets#
Store the offsets for each array (only used when variable size).
-
SharedReader m_element_reader#
Reader for the array elements.
-
class EmptyReader : public uproot::IReader#
Reader that does nothing and returns None.
Public Functions
-
inline EmptyReader(string name)#
Construct a new EmptyReader object.
- Parameters:
name – Name of the reader.
-
inline virtual void read(BinaryBuffer&) override#
Do nothing.
-
inline virtual py::object data() const override#
Return None.
-
inline EmptyReader(string name)#
-
class GroupReader : public uproot::IReader#
This reader groups multiple readers together and reads them sequentially.
Public Functions
Construct a new GroupReader object.
- Parameters:
name – Name of the reader.
element_readers – The grouped element readers. In Python, this should be a list of readers.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read all grouped elements from the buffer sequentially.
- Parameters:
buffer – The binary buffer to read from.
-
inline virtual uint32_t read_many_memberwise(BinaryBuffer &buffer, const int64_t count) override#
Read multiple grouped elements from the buffer sequentially in member-wise mode. This method calls IReader::read_many() of each grouped reader.
- Parameters:
buffer – The binary buffer to read from.
count – Number of objects to read.
- Returns:
Number of objects read. Should be equal to count.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
A list of data from each grouped reader.
Private Members
-
vector<SharedReader> m_element_readers#
The grouped element readers.
-
class ObjectHeaderReader : public uproot::IReader#
Wrapper reader for object headers.
Public Functions
Construct a new Object Header Reader object.
- Parameters:
name – Name of the reader.
element_reader – Reader for the object content.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read the object header from the buffer, then delegate to m_element_reader to read the object content.
- Parameters:
buffer – The binary buffer to read from.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
Directly return the data from m_element_reader.
Private Members
-
SharedReader m_element_reader#
Reader for the object content.
-
template<typename T>
class PrimitiveReader : public uproot::IReader# Reader for primitive types.
- Template Parameters:
T – Primitive type
Public Functions
-
inline PrimitiveReader(string name)#
Construct a new PrimitiveReader object.
- Parameters:
name – Name of the reader
-
inline virtual void read(BinaryBuffer &buffer) override#
Read a value from the buffer and store it. Only reads one value at a time.
- Parameters:
buffer – The binary buffer to read from
-
inline virtual py::object data() const override#
Get the read data as a numpy array.
- Returns:
Numpy array containing the read data
Private Members
-
SharedVector<T> m_data#
Store the read data.
-
template<>
class PrimitiveReader<bool> : public uproot::IReader# Specialization of PrimitiveReader for bool type. Bools are stored as uint8_t.
Public Functions
-
inline PrimitiveReader(string name)#
-
inline virtual void read(BinaryBuffer &buffer) override#
Read a uint8_t from the buffer and store it as bool.
- Parameters:
buffer – The binary buffer to read from
-
inline virtual py::object data() const override#
Get the read data as a numpy array.
- Returns:
Numpy array containing the read data
Private Members
-
SharedVector<uint8_t> m_data#
Store the read data as uint8_t.
-
inline PrimitiveReader(string name)#
-
class STLMapReader : public uproot::IReader#
Reader for STL map types (e.g., std::map, std::unordered_map).
Public Functions
Construct a new STLMapReader object.
- Parameters:
name – Name of the reader.
with_header – Whether the map has a
fNBytes+fVersionheader.objwise_or_memberwise – Object-wise or member-wise reading mode. -1: auto, 0: obj-wise, 1: member-wise.
key_reader – Reader for the keys of the map.
value_reader – Reader for the values of the map.
-
inline void check_objwise_memberwise(const bool is_memberwise)#
Check if the reading mode matches the expected mode.
- Parameters:
is_memberwise – Whether the current reading mode is member-wise.
-
inline void read_body(BinaryBuffer &buffer, bool is_memberwise)#
Read the body of the map from the buffer. First reads the size (uint32_t) of the map, then calls m_key_reader and m_value_reader to read the keys and values. If member-wise, reads all keys first, then all values. Otherwise, reads key-value pairs one by one.
- Parameters:
buffer – The binary buffer to read from.
is_memberwise – Whether the current reading mode is member-wise.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read a map from the buffer. If m_with_header is true, reads a
fNBytes+fVersionheader and skip 6 extra bytes. Then calls read_body() to read the map body.- Parameters:
buffer – The binary buffer to read from.
-
inline virtual uint32_t read_many(BinaryBuffer &buffer, const int64_t count) override#
Read multiple maps from the buffer. If m_with_header is true, reads a
fNBytes+fVersionheader and skip 6 extra bytes once before reading multiple maps.- Parameters:
buffer – The binary buffer to read from.
count – Number of maps to read. If negative, reads according to the
fNBytesheader.
- Returns:
Number of maps read.
-
inline virtual uint32_t read_until(BinaryBuffer &buffer, const uint8_t *end_pos) override#
Read sequences from the buffer until reaching the end position. If m_with_header is true, reads a
fNBytes+fVersionheader and skip 6 extra bytes once before reading sequences. If data is stored member-wise, skips 2 bytes after the header.- Parameters:
buffer – The binary buffer to read from.
end_pos – The end position to stop reading.
- Returns:
Number of sequences read.
-
inline virtual uint32_t read_many_memberwise(BinaryBuffer &buffer, const int64_t count) override#
Read multiple maps from the buffer in member-wise mode.
- Parameters:
buffer – The binary buffer to read from.
count – Number of maps to read. If negative, throws an error.
- Returns:
Number of maps read.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
A tuple contains: (offsets, keys_data, values_data).
Private Members
-
const bool m_with_header#
Whether the map has a
fNBytes+fVersionheader.
-
const int m_objwise_or_memberwise = {-1}#
-1: auto, 0: obj-wise, 1: member-wise
-
SharedVector<int64_t> m_offsets#
Store the offsets for each map.
-
SharedReader m_key_reader#
Reader for the keys of the map.
-
SharedReader m_value_reader#
Reader for the values of the map.
-
class STLSeqReader : public uproot::IReader#
Reader for STL sequence types (e.g., std::vector, std::list).
Public Functions
Construct a new STLSeqReader object.
- Parameters:
name – Name of the reader.
with_header – Whether the sequence has a
fNBytes+fVersionheader.objwise_or_memberwise – Object-wise or member-wise reading mode. -1: auto, 0: obj-wise, 1: member-wise.
element_reader – Reader for the elements of the sequence.
-
inline void check_objwise_memberwise(const bool is_memberwise)#
Check if the reading mode matches the expected mode.
- Parameters:
is_memberwise – Whether the current reading mode is member-wise.
-
inline void read_body(BinaryBuffer &buffer, bool is_memberwise)#
Read the body of the sequence from the buffer. First reads the size (uint32_t) of the sequence, then calls m_element_reader to read the elements.
- Parameters:
buffer – The binary buffer to read from.
is_memberwise – Whether the current reading mode is member-wise.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read a sequence from the buffer. If m_with_header is true, reads a
fNBytes+fVersionheader. Then calls read_body() to read the sequence body.- Parameters:
buffer – The binary buffer to read from.
-
inline virtual uint32_t read_many(BinaryBuffer &buffer, const int64_t count) override#
Read multiple sequences from the buffer. If m_with_header is true, reads a
fNBytes+fVersionheader once before reading multiple sequences.- Parameters:
buffer – The binary buffer to read from.
count – Number of sequences to read. If negative, reads according to the
fNBytesheader.
- Returns:
Number of sequences read.
-
inline virtual uint32_t read_until(BinaryBuffer &buffer, const uint8_t *end_pos) override#
Read sequences from the buffer until reaching the end position. If m_with_header is true, reads a
fNBytes+fVersionheader once before reading sequences. If data is stored member-wise, skips 2 bytes after the header.- Parameters:
buffer – The binary buffer to read from.
end_pos – The end position to stop reading.
- Returns:
Number of sequences read.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
A tuple contains: (offsets, elements_data).
Private Members
-
const bool m_with_header#
Whether the sequence has a
fNBytes+fVersionheader.
-
const int m_objwise_or_memberwise = {-1}#
-1: auto, 0: obj-wise, 1: member-wise
-
SharedReader m_element_reader#
Reader for the elements of the sequence.
-
SharedVector<int64_t> m_offsets#
Store the offsets for each sequence.
-
class STLStringReader : public uproot::IReader#
Reader for STL string (std::string).
Public Functions
-
inline STLStringReader(string name, bool with_header)#
Construct a new STLStringReader object.
- Parameters:
name – Name of the reader.
with_header – Whether the string has a
fNBytes+fVersionheader.
-
inline void read_body(BinaryBuffer &buffer)#
Read the body of the string from the buffer. A string starts with a uint8_t size. If the size is 255, then a uint32_t size follows. Then the string data follows.
- Parameters:
buffer – The binary buffer to read from.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read a string from the buffer. If m_with_header is true, reads a
fNBytes+fVersionheader before reading the string body.- Parameters:
buffer – The binary buffer to read from.
-
inline virtual uint32_t read_many(BinaryBuffer &buffer, const int64_t count) override#
Read multiple strings from the buffer. If m_with_header is true, reads a
fNBytes+fVersionheader once before reading multiple strings.- Parameters:
buffer – The binary buffer to read from.
count – Number of strings to read. If negative, reads according to the
fNBytesheader.
- Returns:
Number of strings read.
-
inline virtual uint32_t read_until(BinaryBuffer &buffer, const uint8_t *end_pos) override#
Read strings from the buffer until reaching the end position. If m_with_header is true, reads a
fNBytes+fVersionheader once before reading strings.- Parameters:
buffer – The binary buffer to read from.
end_pos – The end position to stop reading.
- Returns:
Number of strings read.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
A tuple of numpy arrays: (offsets, data).
Private Members
-
const bool m_with_header#
Whether the string has a
fNBytes+fVersionheader.
-
SharedVector<int64_t> m_offsets#
Store the offsets for each string.
-
SharedVector<uint8_t> m_data#
Store the string data as uint8_t.
-
inline STLStringReader(string name, bool with_header)#
-
template<typename T>
class TArrayReader : public uproot::IReader# Reader for TArray types.
- Template Parameters:
T – Element type of the TArray.
Public Functions
-
inline TArrayReader(string name)#
Construct a new TArrayReader object.
- Parameters:
name – Name of the reader.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read a TArray from the buffer. First reads the size (uint32_t) of the TArray, then reads the elements of the TArray.
- Parameters:
buffer – The binary buffer to read from.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
A tuple of numpy arrays: (offsets, data).
Private Members
-
SharedVector<int64_t> m_offsets#
Store the offsets for each TArray.
-
SharedVector<T> m_data#
Store the TArray data.
-
class TObjectReader : public uproot::IReader#
Reader for TObject.
Public Functions
-
inline TObjectReader(string name, bool keep_data)#
Construct a new TObjectReader object.
- Parameters:
name – Name of the reader
keep_data – Whether to keep the read data
-
inline virtual void read(BinaryBuffer &buffer) override#
Read a TObject from the buffer. A TObject contains
fVersion(int16_t),fUniqueID(int32_t),fBits(uint32_t). IffBits & kIsReferenced, then apidf(uint16_t) follows. If m_keep_data is true, the read data will be stored.- Parameters:
buffer – The binary buffer to read from
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
If m_keep_data is true, returns a tuple of numpy arrays: (unique_id, bits, pidf, pidf_offsets). Otherwise, returns None.
Private Members
-
const bool m_keep_data#
Whether to keep the read data.
-
SharedVector<int32_t> m_unique_id#
Store fUniqueID values.
-
SharedVector<uint32_t> m_bits#
Store fBits values.
-
SharedVector<uint16_t> m_pidf#
Store pidf values.
-
SharedVector<int64_t> m_pidf_offsets#
Store offsets for pidf.
-
inline TObjectReader(string name, bool keep_data)#
-
class TStringReader : public uproot::IReader#
Reader for TString.
Public Functions
-
inline TStringReader(string name, bool with_header)#
Construct a new TStringReader object.
- Parameters:
name – Name of the reader.
with_header – Whether the TString has a
fNBytes+fVersionheader.
-
inline virtual void read(BinaryBuffer &buffer) override#
Read a TString from the buffer. A TString starts with a uint8_t size. If the size is 255, then a uint32_t size follows. Then the string data follows. It m_with_header is true, read a
fNBytes+fVersionheader before reading the TString.- Parameters:
buffer – The binary buffer to read from.
-
inline virtual uint32_t read_many(BinaryBuffer &buffer, const int64_t count) override#
Read multiple TStrings from the buffer. If m_with_header is true, only read
fNBytes+fVersionheader once before reading multiple TStrings.- Parameters:
buffer – The binary buffer to read from.
count – Number of TStrings to read. If negative, throws an error.
- Returns:
Number of TStrings read.
-
inline virtual uint32_t read_until(BinaryBuffer &buffer, const uint8_t *end_pos) override#
Read TStrings from the buffer until reaching the end position. If m_with_header is true, only read
fNBytes+fVersionheader once before reading TStrings.- Parameters:
buffer – The binary buffer to read from.
end_pos – The end position to stop reading.
- Returns:
Number of TStrings read.
-
inline virtual py::object data() const override#
Get the data read by the reader. This should be called after the whole reading process.
- Returns:
A tuple of numpy arrays: (offsets, data).
Private Members
-
const bool m_with_header#
Whether the TString has a
fNBytes+fVersionheader.
-
SharedVector<uint8_t> m_data#
Store the string data.
-
SharedVector<int64_t> m_offsets#
Store the offsets for each string.
-
inline TStringReader(string name, bool with_header)#