uproot-custom 2.3.1__tar.gz → 2.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.gitignore +1 -1
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.pre-commit-config.yaml +2 -2
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/PKG-INFO +2 -2
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/README.md +1 -1
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/cpp/include/uproot-custom/uproot-custom.hh +74 -69
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/cpp/src/uproot-custom.cc +239 -298
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/example/override-streamer.md +17 -16
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/example/read-tobjarray.md +56 -59
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/index.md +1 -1
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/reference/reader-backends.md +1 -1
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/tutorial/customize-factory-reader/investigate-data.md +8 -8
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/tutorial/customize-factory-reader/pipeline.md +17 -17
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/tutorial/customize-factory-reader/port-to-cpp.md +37 -37
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/tutorial/customize-factory-reader/reader-and-factory.md +29 -30
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/tutorial/customize-factory-reader.md +2 -2
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/conftest.py +6 -0
- uproot_custom-2.5.0/tests/data/test_pure_struct.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/CMakeLists.txt +1 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/README.md +2 -2
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/LinkDef.h +2 -4
- uproot_custom-2.5.0/tests/gen-test-data/include/TPureStruct.hh +16 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/src/main.cc +21 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/__init__.py +0 -2
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/_version.py +3 -3
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/cpp.pyi +0 -7
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/factories.py +4 -69
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/readers/_forth.py +1 -43
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/readers/_numba.py +3 -36
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/readers/cpp.py +0 -2
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/readers/python.py +224 -232
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/utils.py +0 -2
- uproot_custom-2.3.1/.github/workflows/auto-update.yml +0 -49
- uproot_custom-2.3.1/uv.lock +0 -3813
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.clang-format +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.github/release.yml +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.github/workflows/build-wheels.yml +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.github/workflows/deploy-docs.yml +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.github/workflows/python-publish.yml +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.github/workflows/semantic-pr-titles.yml +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.github/workflows/test-package.yml +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/.github/workflows/weekly-build.yml +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/LICENSE +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/cpp/CMakeLists.txt +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/cpp/share/cmake/uproot-customConfig.cmake +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/Doxyfile +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/conf.py +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/get-started.md +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/reference/api/.gitignore +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/reference/api/cpp-api.md +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/reference/api/cpp-module.md +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/reference/api/uproot-custom-ref.md +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/reference/api.md +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/reference/binary-format.md +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/reference/version-requirements.md +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/docs/tutorial/customize-factory-reader/project-setup.md +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/pyproject.toml +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_cstyle_array.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_pointers.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_primitive.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_root_objects.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_simple_obj.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_stl_array.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_stl_complicated.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_stl_map.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_stl_map_with_obj.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_stl_nested.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_stl_seq_with_obj.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_stl_sequence.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/data/test_stl_string.root +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TBasicTypes.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TCStyleArray.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TComplicatedSTL.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TNestedSTL.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TPointers.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TRootObjects.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TSTLArray.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TSTLMap.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TSTLMapWithObj.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TSTLSeqWithObj.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TSTLSequence.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TSTLString.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/gen-test-data/include/TSimpleObject.hh +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/test_AsCustom.py +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/tests/test_readers.py +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/AsCustom.py +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/readers/__init__.py +0 -0
- {uproot_custom-2.3.1 → uproot_custom-2.5.0}/uproot_custom/share/cmake/__init__.py +0 -0
|
@@ -98,7 +98,7 @@ ipython_config.py
|
|
|
98
98
|
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
99
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
100
|
# commonly ignored for libraries.
|
|
101
|
-
|
|
101
|
+
uv.lock
|
|
102
102
|
|
|
103
103
|
# poetry
|
|
104
104
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
@@ -23,12 +23,12 @@ repos:
|
|
|
23
23
|
- id: trailing-whitespace
|
|
24
24
|
|
|
25
25
|
- repo: https://github.com/psf/black-pre-commit-mirror
|
|
26
|
-
rev: 26.
|
|
26
|
+
rev: 26.5.1
|
|
27
27
|
hooks:
|
|
28
28
|
- id: black
|
|
29
29
|
|
|
30
30
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
31
|
-
rev: v0.15.
|
|
31
|
+
rev: v0.15.15
|
|
32
32
|
hooks:
|
|
33
33
|
- id: ruff-check
|
|
34
34
|
args: [--fix, --show-fixes]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: uproot-custom
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.0
|
|
4
4
|
Summary: uproot extension for reading custom classes
|
|
5
5
|
Author-Email: Mingrun Li <mrli@ihep.ac.cn>
|
|
6
6
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -73,7 +73,7 @@ flowchart TD
|
|
|
73
73
|
raw_data --> build_ak
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
- `Reader` is a class that implements the logic to read data from binary
|
|
76
|
+
- `Reader` is a class that implements the logic to read data from binary streams. It can be written in **Python** (for development and debugging) or **C++** (for production performance).
|
|
77
77
|
- `Factory` is a Python class that creates, combines `Reader`s, and post-processes the data read by `Reader`s.
|
|
78
78
|
|
|
79
79
|
This mechanism is implemented as `AsCustom` interpretation. This makes uproot-custom well compatible with Uproot.
|
|
@@ -38,7 +38,7 @@ flowchart TD
|
|
|
38
38
|
raw_data --> build_ak
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
- `Reader` is a class that implements the logic to read data from binary
|
|
41
|
+
- `Reader` is a class that implements the logic to read data from binary streams. It can be written in **Python** (for development and debugging) or **C++** (for production performance).
|
|
42
42
|
- `Factory` is a Python class that creates, combines `Reader`s, and post-processes the data read by `Reader`s.
|
|
43
43
|
|
|
44
44
|
This mechanism is implemented as `AsCustom` interpretation. This makes uproot-custom well compatible with Uproot.
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
*/
|
|
34
34
|
#define IMPORT_UPROOT_CUSTOM_CPP pybind11::module_::import( "uproot_custom.cpp" );
|
|
35
35
|
|
|
36
|
-
namespace
|
|
36
|
+
namespace uproot_custom {
|
|
37
37
|
namespace py = pybind11;
|
|
38
38
|
using std::shared_ptr;
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
constexpr uint32_t kNewClassTag = 0xFFFFFFFF;
|
|
41
|
+
constexpr uint32_t kClassMask = 0x80000000; // OR the class index with this
|
|
42
|
+
constexpr uint32_t kByteCountMask = 0x40000000; // OR the byte count with this
|
|
43
|
+
constexpr uint32_t kMaxMapCount = 0x3FFFFFFE; // last valid fMapCount and byte count
|
|
44
|
+
constexpr uint16_t kByteCountVMask = 0x4000; // OR the version byte count with this
|
|
45
|
+
constexpr uint16_t kMaxVersion = 0x3FFF; // highest possible version number
|
|
46
|
+
constexpr int32_t kMapOffset = 2; // first 2 map entries are taken by null obj and self obj
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
constexpr uint16_t kStreamedMemberWise = 1 << 14; // streamed member-wise mask
|
|
49
49
|
|
|
50
|
-
class
|
|
50
|
+
class BinaryStream {
|
|
51
51
|
public:
|
|
52
52
|
enum EStatusBits {
|
|
53
53
|
kCanDelete = 1ULL << 0, ///< if object in a list can be deleted
|
|
@@ -75,11 +75,11 @@ namespace uproot {
|
|
|
75
75
|
using Reference = std::variant<RefCls, RefObj>;
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
* @brief Construct a
|
|
78
|
+
* @brief Construct a BinaryStream from numpy arrays.
|
|
79
79
|
* @param data A numpy array of uint8_t containing the raw data.
|
|
80
80
|
* @param offsets A numpy array of uint32_t containing the offsets for each entry.
|
|
81
81
|
*/
|
|
82
|
-
|
|
82
|
+
BinaryStream( py::array_t<uint8_t> data, py::array_t<uint32_t> offsets,
|
|
83
83
|
uint32_t initial_cursor_position )
|
|
84
84
|
: m_data( static_cast<uint8_t*>( data.request().ptr ) )
|
|
85
85
|
, m_offsets( static_cast<uint32_t*>( offsets.request().ptr ) )
|
|
@@ -88,19 +88,18 @@ namespace uproot {
|
|
|
88
88
|
, m_cursor( static_cast<uint8_t*>( data.request().ptr ) ) {}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* @brief Read a value of type T from the
|
|
91
|
+
* @brief Read a value of type T from the stream, handling endianness.
|
|
92
92
|
*
|
|
93
93
|
* @tparam T The type to read.
|
|
94
|
-
* @return The value read from the
|
|
94
|
+
* @return The value read from the stream.
|
|
95
95
|
*/
|
|
96
96
|
template <typename T>
|
|
97
97
|
const T read() {
|
|
98
98
|
constexpr auto size = sizeof( T );
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
if constexpr ( size == 1 ) return *reinterpret_cast<const T*>( m_cursor++ );
|
|
101
|
+
else if constexpr ( size == 2 )
|
|
101
102
|
{
|
|
102
|
-
case 1: return *reinterpret_cast<const T*>( m_cursor++ );
|
|
103
|
-
case 2: {
|
|
104
103
|
union {
|
|
105
104
|
T value;
|
|
106
105
|
uint16_t bits;
|
|
@@ -110,7 +109,8 @@ namespace uproot {
|
|
|
110
109
|
val.bits = bswap16( val.bits );
|
|
111
110
|
return val.value;
|
|
112
111
|
}
|
|
113
|
-
|
|
112
|
+
else if constexpr ( size == 4 )
|
|
113
|
+
{
|
|
114
114
|
union {
|
|
115
115
|
T value;
|
|
116
116
|
uint32_t bits;
|
|
@@ -120,7 +120,8 @@ namespace uproot {
|
|
|
120
120
|
val.bits = bswap32( val.bits );
|
|
121
121
|
return val.value;
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
else if constexpr ( size == 8 )
|
|
124
|
+
{
|
|
124
125
|
union {
|
|
125
126
|
T value;
|
|
126
127
|
uint64_t bits;
|
|
@@ -130,20 +131,21 @@ namespace uproot {
|
|
|
130
131
|
val.bits = bswap64( val.bits );
|
|
131
132
|
return val.value;
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
else
|
|
135
|
+
static_assert(
|
|
136
|
+
sizeof( T ) == 0,
|
|
137
|
+
"read<T>: unsupported type size (only 1, 2, 4, 8 bytes allowed)" );
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
/**
|
|
139
|
-
* @brief Read the fVersion field from the
|
|
141
|
+
* @brief Read the fVersion field from the stream
|
|
140
142
|
*
|
|
141
143
|
* @return The fVersion value
|
|
142
144
|
*/
|
|
143
145
|
const int16_t read_fVersion() { return read<int16_t>(); }
|
|
144
146
|
|
|
145
147
|
/**
|
|
146
|
-
* @brief Read the fNBytes field from the
|
|
148
|
+
* @brief Read the fNBytes field from the stream, checking the byte count mask.
|
|
147
149
|
*
|
|
148
150
|
* @return The fNBytes value without the mask.
|
|
149
151
|
* @exception std::runtime_error if the byte count mask is not set.
|
|
@@ -156,9 +158,9 @@ namespace uproot {
|
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
/**
|
|
159
|
-
* @brief Read a null-terminated (`\0`) string from the
|
|
161
|
+
* @brief Read a null-terminated (`\0`) string from the stream.
|
|
160
162
|
*
|
|
161
|
-
* @return The string read from the
|
|
163
|
+
* @return The string read from the stream.
|
|
162
164
|
*/
|
|
163
165
|
const std::string read_null_terminated_string() {
|
|
164
166
|
auto start = m_cursor;
|
|
@@ -168,26 +170,25 @@ namespace uproot {
|
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
/**
|
|
171
|
-
* @brief Read an object header from the
|
|
173
|
+
* @brief Read an object's header from the stream. The object header has `fNBytes`,
|
|
172
174
|
* `fVersion`, `fTag`. If `fTag == kNewClassTag`, then a null-terminated class name
|
|
173
175
|
* follows.
|
|
174
176
|
*
|
|
175
|
-
* @return The class name if the object is a new class, empty string
|
|
176
|
-
* otherwise.
|
|
177
|
+
* @return The class name if the object is a new class, empty string otherwise.
|
|
177
178
|
*/
|
|
178
179
|
const std::string read_obj_header() {
|
|
179
|
-
|
|
180
|
+
skip_fNBytes();
|
|
180
181
|
auto fTag = read<uint32_t>();
|
|
181
182
|
if ( fTag == kNewClassTag ) return read_null_terminated_string();
|
|
182
183
|
else return std::string();
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
/**
|
|
186
|
-
* @brief Read a TString from the
|
|
187
|
+
* @brief Read a TString from the stream. A TString has `length` (uint8_t). If `length
|
|
187
188
|
* == 255`, then the `length` is a following uint32_t. Then following `length` bytes of
|
|
188
189
|
* string data.
|
|
189
190
|
*
|
|
190
|
-
* @return The TString data read from the
|
|
191
|
+
* @return The TString data read from the stream, as a std::string.
|
|
191
192
|
*/
|
|
192
193
|
const std::string read_TString() {
|
|
193
194
|
uint32_t length = read<uint8_t>();
|
|
@@ -198,7 +199,7 @@ namespace uproot {
|
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
/**
|
|
201
|
-
* @brief Skip `n` bytes in the
|
|
202
|
+
* @brief Skip `n` bytes in the stream.
|
|
202
203
|
*
|
|
203
204
|
* @param n Number of bytes to skip.
|
|
204
205
|
*/
|
|
@@ -216,7 +217,7 @@ namespace uproot {
|
|
|
216
217
|
void skip_fVersion() { skip( 2 ); }
|
|
217
218
|
|
|
218
219
|
/**
|
|
219
|
-
* @brief Skip a null-terminated (`\0`) string in the
|
|
220
|
+
* @brief Skip a null-terminated (`\0`) string in the stream.
|
|
220
221
|
*/
|
|
221
222
|
void skip_null_terminated_string() {
|
|
222
223
|
while ( *m_cursor != 0 ) { m_cursor++; }
|
|
@@ -224,7 +225,7 @@ namespace uproot {
|
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
/**
|
|
227
|
-
* @brief Skip an object header in the
|
|
228
|
+
* @brief Skip an object's header in the stream. The object header has `fNBytes`,
|
|
228
229
|
* `fVersion`, `fTag`. If `fTag == kNewClassTag`, then a null-terminated class name
|
|
229
230
|
* follows.
|
|
230
231
|
*/
|
|
@@ -235,12 +236,11 @@ namespace uproot {
|
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
/**
|
|
238
|
-
* @brief Skip a TObject in the
|
|
239
|
+
* @brief Skip a TObject in the stream. A TObject has `fVersion` (2 bytes), `fUniqueID`
|
|
239
240
|
* (4 bytes), `fBits` (4 bytes). If `fBits & kIsReferenced`, then a `pidf` (2 bytes)
|
|
240
241
|
* follows.
|
|
241
242
|
*/
|
|
242
243
|
void skip_TObject() {
|
|
243
|
-
// TODO: CanIgnoreTObjectStreamer() ?
|
|
244
244
|
skip_fVersion();
|
|
245
245
|
skip( 4 ); // fUniqueID
|
|
246
246
|
auto fBits = read<uint32_t>();
|
|
@@ -311,6 +311,11 @@ namespace uproot {
|
|
|
311
311
|
///< reading
|
|
312
312
|
};
|
|
313
313
|
|
|
314
|
+
// backward compatibility
|
|
315
|
+
using BinaryBuffer
|
|
316
|
+
[[deprecated( "BinaryBuffer is deprecated. Use BinaryStream instead." )]] =
|
|
317
|
+
BinaryStream;
|
|
318
|
+
|
|
314
319
|
/*
|
|
315
320
|
-----------------------------------------------------------------------------
|
|
316
321
|
-----------------------------------------------------------------------------
|
|
@@ -342,11 +347,11 @@ namespace uproot {
|
|
|
342
347
|
virtual const std::string name() const { return m_name; }
|
|
343
348
|
|
|
344
349
|
/**
|
|
345
|
-
* @brief Read an element from the
|
|
350
|
+
* @brief Read an element from the stream.
|
|
346
351
|
*
|
|
347
|
-
* @param
|
|
352
|
+
* @param stream The binary stream to read from.
|
|
348
353
|
*/
|
|
349
|
-
virtual void read(
|
|
354
|
+
virtual void read( BinaryStream& stream ) = 0;
|
|
350
355
|
|
|
351
356
|
/**
|
|
352
357
|
* @brief Get the data read by the reader. This should be called after the whole
|
|
@@ -357,53 +362,53 @@ namespace uproot {
|
|
|
357
362
|
virtual py::object data() const = 0;
|
|
358
363
|
|
|
359
364
|
/**
|
|
360
|
-
* @brief Read multiple elements from the
|
|
365
|
+
* @brief Read multiple elements from the stream in one go. Repeatedly calls @ref
|
|
361
366
|
* read() by default.
|
|
362
367
|
*
|
|
363
368
|
* @note When multiple elements are stored together, some classes may have "one common
|
|
364
369
|
* header + multiple data objects" format. This method can be overridden to handle such
|
|
365
370
|
* cases more efficiently.
|
|
366
371
|
*
|
|
367
|
-
* @param
|
|
372
|
+
* @param stream The binary stream to read from.
|
|
368
373
|
* @param count Number of elements to read.
|
|
369
374
|
* @return Number of elements read.
|
|
370
375
|
*/
|
|
371
|
-
virtual uint32_t read_many(
|
|
372
|
-
for ( int32_t i = 0; i < count; i++ ) { read(
|
|
376
|
+
virtual uint32_t read_many( BinaryStream& stream, const int64_t count ) {
|
|
377
|
+
for ( int32_t i = 0; i < count; i++ ) { read( stream ); }
|
|
373
378
|
return count;
|
|
374
379
|
}
|
|
375
380
|
|
|
376
381
|
/**
|
|
377
|
-
* @brief Read elements from the
|
|
382
|
+
* @brief Read elements from the stream until reaching the end position. Repeatedly
|
|
378
383
|
* calls @ref read() method by default.
|
|
379
384
|
*
|
|
380
385
|
* @note When multiple elements are stored together, some classes may have "one common
|
|
381
386
|
* header + multiple data objects" format. This method can be overridden to handle such
|
|
382
387
|
* cases more efficiently.
|
|
383
388
|
*
|
|
384
|
-
* @param
|
|
389
|
+
* @param stream The binary stream to read from.
|
|
385
390
|
* @param end_pos The end position pointer.
|
|
386
391
|
* @return Number of elements read.
|
|
387
392
|
*/
|
|
388
|
-
virtual uint32_t read_until(
|
|
393
|
+
virtual uint32_t read_until( BinaryStream& stream, const uint8_t* end_pos ) {
|
|
389
394
|
uint32_t cur_count = 0;
|
|
390
|
-
while (
|
|
395
|
+
while ( stream.get_cursor() < end_pos )
|
|
391
396
|
{
|
|
392
|
-
read(
|
|
397
|
+
read( stream );
|
|
393
398
|
cur_count++;
|
|
394
399
|
}
|
|
395
400
|
return cur_count;
|
|
396
401
|
}
|
|
397
402
|
|
|
398
403
|
/**
|
|
399
|
-
* @brief Read multiple elements from the
|
|
404
|
+
* @brief Read multiple elements from the stream in member-wise fashion. Readers
|
|
400
405
|
* that need to handle member-wise data reading must implement this method.
|
|
401
406
|
*
|
|
402
|
-
* @param
|
|
407
|
+
* @param stream The binary stream to read from.
|
|
403
408
|
* @param count Number of elements to read.
|
|
404
409
|
* @return Number of elements read.
|
|
405
410
|
*/
|
|
406
|
-
virtual uint32_t read_many_memberwise(
|
|
411
|
+
virtual uint32_t read_many_memberwise( BinaryStream& stream, const int64_t count ) {
|
|
407
412
|
throw std::runtime_error( name() + "::read_many_memberwise is not implemented." );
|
|
408
413
|
}
|
|
409
414
|
};
|
|
@@ -491,8 +496,8 @@ namespace uproot {
|
|
|
491
496
|
*/
|
|
492
497
|
|
|
493
498
|
/**
|
|
494
|
-
* @brief Debug print function. Prints only when
|
|
495
|
-
* `
|
|
499
|
+
* @brief Debug print function. Prints only when environment variable with name
|
|
500
|
+
* `UPROOT_CUSTOM_DEBUG` is defined. Use this function like `printf()`.
|
|
496
501
|
*
|
|
497
502
|
* @tparam Args Argument types. No need to specify explicitly.
|
|
498
503
|
* @param msg The format string.
|
|
@@ -500,29 +505,29 @@ namespace uproot {
|
|
|
500
505
|
*/
|
|
501
506
|
template <typename... Args>
|
|
502
507
|
inline void debug_printf( const char* msg, Args... args ) {
|
|
503
|
-
bool do_print = getenv( "
|
|
504
|
-
#ifdef UPROOT_DEBUG
|
|
505
|
-
do_print = true;
|
|
506
|
-
#endif
|
|
508
|
+
bool do_print = getenv( "UPROOT_CUSTOM_DEBUG" );
|
|
507
509
|
if ( !do_print ) return;
|
|
508
510
|
printf( msg, std::forward<Args>( args )... );
|
|
509
511
|
}
|
|
510
512
|
|
|
511
513
|
/**
|
|
512
|
-
* @brief Debug print function for
|
|
513
|
-
*
|
|
514
|
-
* internally.
|
|
514
|
+
* @brief Debug print function for BinaryStream. Prints only when environment
|
|
515
|
+
* variable with name `UPROOT_CUSTOM_DEBUG` is defined. Call @ref
|
|
516
|
+
* BinaryStream::debug_print() internally.
|
|
515
517
|
*
|
|
516
|
-
* @param
|
|
518
|
+
* @param stream The BinaryStream to print.
|
|
517
519
|
* @param n Number of bytes to print.
|
|
518
520
|
*/
|
|
519
|
-
inline void debug_printf(
|
|
520
|
-
bool do_print = getenv( "
|
|
521
|
-
#ifdef UPROOT_DEBUG
|
|
522
|
-
do_print = true;
|
|
523
|
-
#endif
|
|
521
|
+
inline void debug_printf( uproot_custom::BinaryStream& stream, const size_t n = 100 ) {
|
|
522
|
+
bool do_print = getenv( "UPROOT_CUSTOM_DEBUG" );
|
|
524
523
|
if ( !do_print ) return;
|
|
525
|
-
|
|
524
|
+
stream.debug_print( n );
|
|
526
525
|
}
|
|
527
526
|
|
|
528
|
-
} // namespace
|
|
527
|
+
} // namespace uproot_custom
|
|
528
|
+
|
|
529
|
+
// backward compatibility
|
|
530
|
+
// TODO: remove the uproot namespace and use uproot_custom namespace directly in the future.
|
|
531
|
+
namespace uproot {
|
|
532
|
+
using namespace uproot_custom;
|
|
533
|
+
}
|