uproot-custom 2.5.0__tar.gz → 2.5.1__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.5.0 → uproot_custom-2.5.1}/.pre-commit-config.yaml +1 -1
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/PKG-INFO +2 -2
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/README.md +1 -1
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/cpp/include/uproot-custom/uproot-custom.hh +21 -2
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/cpp/src/uproot-custom.cc +76 -182
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/Doxyfile +1 -1
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/conf.py +10 -2
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/example/override-streamer.md +5 -5
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/example/read-tobjarray.md +5 -5
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/index.md +1 -1
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/reference/api/uproot-custom-ref.md +0 -1
- uproot_custom-2.5.1/docs/reference/binary-format.md +662 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/reference/reader-backends.md +26 -15
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/pipeline.md +5 -5
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/port-to-cpp.md +3 -3
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader.md +4 -4
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/test_readers.py +9 -39
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/__init__.py +2 -2
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/_version.py +3 -3
- uproot_custom-2.5.0/uproot_custom/AsCustom.py → uproot_custom-2.5.1/uproot_custom/as_custom.py +33 -34
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/cpp.pyi +0 -2
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/factories.py +85 -209
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/readers/_forth.py +47 -205
- uproot_custom-2.5.1/uproot_custom/readers/backend.py +93 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/readers/python.py +26 -141
- uproot_custom-2.5.0/docs/reference/api/cpp-module.md +0 -6
- uproot_custom-2.5.0/docs/reference/binary-format.md +0 -167
- uproot_custom-2.5.0/uproot_custom/readers/_numba.py +0 -1315
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.clang-format +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.github/release.yml +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.github/workflows/build-wheels.yml +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.github/workflows/deploy-docs.yml +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.github/workflows/python-publish.yml +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.github/workflows/semantic-pr-titles.yml +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.github/workflows/test-package.yml +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.github/workflows/weekly-build.yml +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/.gitignore +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/LICENSE +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/cpp/CMakeLists.txt +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/cpp/share/cmake/uproot-customConfig.cmake +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/get-started.md +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/reference/api/.gitignore +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/reference/api/cpp-api.md +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/reference/api.md +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/reference/version-requirements.md +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/investigate-data.md +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/project-setup.md +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/reader-and-factory.md +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/pyproject.toml +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/conftest.py +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_cstyle_array.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_pointers.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_primitive.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_pure_struct.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_root_objects.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_simple_obj.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_stl_array.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_stl_complicated.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_stl_map.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_stl_map_with_obj.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_stl_nested.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_stl_seq_with_obj.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_stl_sequence.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/data/test_stl_string.root +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/CMakeLists.txt +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/README.md +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/LinkDef.h +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TBasicTypes.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TCStyleArray.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TComplicatedSTL.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TNestedSTL.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TPointers.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TPureStruct.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TRootObjects.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLArray.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLMap.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLMapWithObj.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLSeqWithObj.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLSequence.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLString.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSimpleObject.hh +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/gen-test-data/src/main.cc +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/tests/test_AsCustom.py +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/readers/__init__.py +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/readers/cpp.py +1 -1
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/share/cmake/__init__.py +0 -0
- {uproot_custom-2.5.0 → uproot_custom-2.5.1}/uproot_custom/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: uproot-custom
|
|
3
|
-
Version: 2.5.
|
|
3
|
+
Version: 2.5.1
|
|
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
|
|
@@ -38,7 +38,7 @@ Description-Content-Type: text/markdown
|
|
|
38
38
|
Uproot-custom is an extension of [Uproot](https://uproot.readthedocs.io/en/latest/basic.html) that provides an enhanced way to read custom classes stored in `TTree`.
|
|
39
39
|
|
|
40
40
|
> [!WARNING]
|
|
41
|
-
> Because of earlier mistakes in version management, the `v2.x.x` series should still be treated as a development version rather than a stable release.
|
|
41
|
+
> Because of earlier mistakes in version management, the `v2.x.x` series should still be treated as a development version rather than a stable release. Please specify a minor version when using Uproot-custom as a dependency (e.g., `uproot-custom==2.5.*`) to avoid unexpected breaking changes.
|
|
42
42
|
|
|
43
43
|
## What uproot-custom can do
|
|
44
44
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Uproot-custom is an extension of [Uproot](https://uproot.readthedocs.io/en/latest/basic.html) that provides an enhanced way to read custom classes stored in `TTree`.
|
|
4
4
|
|
|
5
5
|
> [!WARNING]
|
|
6
|
-
> Because of earlier mistakes in version management, the `v2.x.x` series should still be treated as a development version rather than a stable release.
|
|
6
|
+
> Because of earlier mistakes in version management, the `v2.x.x` series should still be treated as a development version rather than a stable release. Please specify a minor version when using Uproot-custom as a dependency (e.g., `uproot-custom==2.5.*`) to avoid unexpected breaking changes.
|
|
7
7
|
|
|
8
8
|
## What uproot-custom can do
|
|
9
9
|
|
|
@@ -47,8 +47,17 @@ namespace uproot_custom {
|
|
|
47
47
|
|
|
48
48
|
constexpr uint16_t kStreamedMemberWise = 1 << 14; // streamed member-wise mask
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* @brief A binary stream reader that wraps numpy arrays for efficient ROOT binary parsing.
|
|
52
|
+
*
|
|
53
|
+
* Provides endianness-aware reading of primitive types and manages references
|
|
54
|
+
* between objects during deserialization.
|
|
55
|
+
*/
|
|
50
56
|
class BinaryStream {
|
|
51
57
|
public:
|
|
58
|
+
/**
|
|
59
|
+
* @brief Status bits for TObject, used to track object state flags.
|
|
60
|
+
*/
|
|
52
61
|
enum EStatusBits {
|
|
53
62
|
kCanDelete = 1ULL << 0, ///< if object in a list can be deleted
|
|
54
63
|
// 2 is taken by TDataMember
|
|
@@ -64,20 +73,30 @@ namespace uproot_custom {
|
|
|
64
73
|
<< 13 ///< if object ctor succeeded but object should not be used
|
|
65
74
|
};
|
|
66
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @brief Reference to a class by name.
|
|
78
|
+
*/
|
|
67
79
|
struct RefCls {
|
|
68
|
-
std::string name;
|
|
80
|
+
std::string name; ///< The name of the referenced class.
|
|
69
81
|
};
|
|
70
82
|
|
|
83
|
+
/**
|
|
84
|
+
* @brief Reference to an object by index.
|
|
85
|
+
*/
|
|
71
86
|
struct RefObj {
|
|
72
|
-
int64_t index;
|
|
87
|
+
int64_t index; ///< The index of the referenced object.
|
|
73
88
|
};
|
|
74
89
|
|
|
90
|
+
/**
|
|
91
|
+
* @brief A variant type representing either a class reference or an object reference.
|
|
92
|
+
*/
|
|
75
93
|
using Reference = std::variant<RefCls, RefObj>;
|
|
76
94
|
|
|
77
95
|
/**
|
|
78
96
|
* @brief Construct a BinaryStream from numpy arrays.
|
|
79
97
|
* @param data A numpy array of uint8_t containing the raw data.
|
|
80
98
|
* @param offsets A numpy array of uint32_t containing the offsets for each entry.
|
|
99
|
+
* @param initial_cursor_position Initial cursor position offset for the stream.
|
|
81
100
|
*/
|
|
82
101
|
BinaryStream( py::array_t<uint8_t> data, py::array_t<uint32_t> offsets,
|
|
83
102
|
uint32_t initial_cursor_position )
|
|
@@ -91,7 +91,7 @@ namespace uproot_custom {
|
|
|
91
91
|
/**
|
|
92
92
|
* @brief Read a TObject from the stream. A TObject contains `fVersion` (int16_t),
|
|
93
93
|
* `fUniqueID` (int32_t), `fBits` (uint32_t). If `fBits & kIsReferenced`, then a `pidf`
|
|
94
|
-
* (uint16_t) follows. If
|
|
94
|
+
* (uint16_t) follows. If m_keep_data is true, the read data
|
|
95
95
|
* will be stored.
|
|
96
96
|
*
|
|
97
97
|
* @param stream The binary stream to read from
|
|
@@ -119,7 +119,7 @@ namespace uproot_custom {
|
|
|
119
119
|
* @brief Get the data read by the reader. This should be called after the whole
|
|
120
120
|
* reading process.
|
|
121
121
|
*
|
|
122
|
-
* @return If
|
|
122
|
+
* @return If m_keep_data is true, returns a tuple of numpy arrays: (unique_id,
|
|
123
123
|
* bits, pidf, pidf_offsets). Otherwise, returns None.
|
|
124
124
|
*/
|
|
125
125
|
py::object data() const override {
|
|
@@ -163,7 +163,7 @@ namespace uproot_custom {
|
|
|
163
163
|
|
|
164
164
|
/**
|
|
165
165
|
* @brief Read a TString from the stream. A TString starts with a uint8_t size. If the
|
|
166
|
-
* size is 255, then a uint32_t size follows. Then the string data follows.
|
|
166
|
+
* size is 255, then a uint32_t size follows. Then the string data follows. If
|
|
167
167
|
* m_with_header is true, read a `fNBytes+fVersion` header before reading the TString.
|
|
168
168
|
*
|
|
169
169
|
* @param stream The binary stream to read from.
|
|
@@ -177,7 +177,7 @@ namespace uproot_custom {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
|
-
* @brief Read multiple TStrings from the stream. If
|
|
180
|
+
* @brief Read multiple TStrings from the stream. If m_with_header is true, only
|
|
181
181
|
* read `fNBytes+fVersion` header once before reading multiple TStrings.
|
|
182
182
|
*
|
|
183
183
|
* @param stream The binary stream to read from.
|
|
@@ -202,7 +202,7 @@ namespace uproot_custom {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
|
-
* @brief Read TStrings from the stream until reaching the end position. If
|
|
205
|
+
* @brief Read TStrings from the stream until reaching the end position. If
|
|
206
206
|
* m_with_header is true, only read `fNBytes+fVersion` header once before reading
|
|
207
207
|
* TStrings.
|
|
208
208
|
*
|
|
@@ -253,9 +253,8 @@ namespace uproot_custom {
|
|
|
253
253
|
class STLSeqReader : public IReader {
|
|
254
254
|
private:
|
|
255
255
|
const bool m_with_header; ///< Whether the sequence has a `fNBytes+fVersion` header.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
SharedVector<int64_t> m_offsets; ///< Store the offsets for each sequence.
|
|
256
|
+
SharedReader m_element_reader; ///< Reader for the elements of the sequence.
|
|
257
|
+
SharedVector<int64_t> m_offsets; ///< Store the offsets for each sequence.
|
|
259
258
|
|
|
260
259
|
public:
|
|
261
260
|
/**
|
|
@@ -263,32 +262,14 @@ namespace uproot_custom {
|
|
|
263
262
|
*
|
|
264
263
|
* @param name Name of the reader.
|
|
265
264
|
* @param with_header Whether the sequence has a `fNBytes+fVersion` header.
|
|
266
|
-
* @param objwise_or_memberwise Object-wise or member-wise reading mode.
|
|
267
|
-
* -1: auto, 0: obj-wise, 1: member-wise.
|
|
268
265
|
* @param element_reader Reader for the elements of the sequence.
|
|
269
266
|
*/
|
|
270
|
-
STLSeqReader( string name, bool with_header,
|
|
271
|
-
SharedReader element_reader )
|
|
267
|
+
STLSeqReader( string name, bool with_header, SharedReader element_reader )
|
|
272
268
|
: IReader( name )
|
|
273
269
|
, m_with_header( with_header )
|
|
274
|
-
, m_objwise_or_memberwise( objwise_or_memberwise )
|
|
275
270
|
, m_element_reader( element_reader )
|
|
276
271
|
, m_offsets( std::make_shared<vector<int64_t>>( 1, 0 ) ) {}
|
|
277
272
|
|
|
278
|
-
/**
|
|
279
|
-
* @brief Check if the reading mode matches the expected mode.
|
|
280
|
-
*
|
|
281
|
-
* @param is_memberwise Whether the current reading mode is member-wise.
|
|
282
|
-
*/
|
|
283
|
-
void check_objwise_memberwise( const bool is_memberwise ) {
|
|
284
|
-
if ( m_objwise_or_memberwise == 0 && is_memberwise )
|
|
285
|
-
throw std::runtime_error( "STLSeqReader(" + name() +
|
|
286
|
-
"): Expect obj-wise, got member-wise!" );
|
|
287
|
-
if ( m_objwise_or_memberwise == 1 && !is_memberwise )
|
|
288
|
-
throw std::runtime_error( "STLSeqReader(" + name() +
|
|
289
|
-
"): Expect member-wise, got obj-wise!" );
|
|
290
|
-
}
|
|
291
|
-
|
|
292
273
|
/**
|
|
293
274
|
* @brief Read the element version and checksum from the stream.
|
|
294
275
|
*
|
|
@@ -304,7 +285,7 @@ namespace uproot_custom {
|
|
|
304
285
|
|
|
305
286
|
/**
|
|
306
287
|
* @brief Read the body of the sequence from the stream. First reads the size
|
|
307
|
-
* (uint32_t) of the sequence, then calls
|
|
288
|
+
* (uint32_t) of the sequence, then calls m_element_reader to read the elements.
|
|
308
289
|
*
|
|
309
290
|
* @param stream The binary stream to read from.
|
|
310
291
|
* @param is_memberwise Whether the current reading mode is member-wise.
|
|
@@ -322,7 +303,7 @@ namespace uproot_custom {
|
|
|
322
303
|
}
|
|
323
304
|
|
|
324
305
|
/**
|
|
325
|
-
* @brief Read a sequence from the stream. If
|
|
306
|
+
* @brief Read a sequence from the stream. If m_with_header is true, reads a
|
|
326
307
|
* `fNBytes+fVersion` header. Then calls @ref read_body() to read the sequence body.
|
|
327
308
|
*
|
|
328
309
|
* @param stream The binary stream to read from.
|
|
@@ -331,13 +312,12 @@ namespace uproot_custom {
|
|
|
331
312
|
stream.read_fNBytes();
|
|
332
313
|
auto fVersion = stream.read_fVersion();
|
|
333
314
|
bool is_memberwise = fVersion & kStreamedMemberWise;
|
|
334
|
-
check_objwise_memberwise( is_memberwise );
|
|
335
315
|
if ( is_memberwise ) read_element_version( stream );
|
|
336
316
|
read_body( stream, is_memberwise );
|
|
337
317
|
}
|
|
338
318
|
|
|
339
319
|
/**
|
|
340
|
-
* @brief Read multiple sequences from the stream. If
|
|
320
|
+
* @brief Read multiple sequences from the stream. If m_with_header is true,
|
|
341
321
|
* reads a `fNBytes+fVersion` header once before reading multiple sequences.
|
|
342
322
|
*
|
|
343
323
|
* @param stream The binary stream to read from.
|
|
@@ -347,46 +327,22 @@ namespace uproot_custom {
|
|
|
347
327
|
*/
|
|
348
328
|
uint32_t read_many( BinaryStream& stream, const int64_t count ) override {
|
|
349
329
|
if ( count == 0 ) return 0;
|
|
350
|
-
|
|
330
|
+
|
|
331
|
+
bool is_memberwise = false;
|
|
332
|
+
if ( m_with_header )
|
|
351
333
|
{
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
auto fNBytes = stream.read_fNBytes();
|
|
357
|
-
auto end_pos = stream.get_cursor() + fNBytes;
|
|
358
|
-
auto fVersion = stream.read_fVersion();
|
|
359
|
-
bool is_memberwise = fVersion & kStreamedMemberWise;
|
|
360
|
-
check_objwise_memberwise( is_memberwise );
|
|
361
|
-
if ( is_memberwise ) read_element_version( stream );
|
|
362
|
-
|
|
363
|
-
uint32_t cur_count = 0;
|
|
364
|
-
while ( stream.get_cursor() < end_pos )
|
|
365
|
-
{
|
|
366
|
-
read_body( stream, is_memberwise );
|
|
367
|
-
cur_count++;
|
|
368
|
-
}
|
|
369
|
-
return cur_count;
|
|
334
|
+
stream.skip_fNBytes();
|
|
335
|
+
auto fVersion = stream.read_fVersion();
|
|
336
|
+
is_memberwise = fVersion & kStreamedMemberWise;
|
|
370
337
|
}
|
|
371
|
-
|
|
372
|
-
{
|
|
373
|
-
bool is_memberwise = m_objwise_or_memberwise == 1;
|
|
374
|
-
if ( m_with_header )
|
|
375
|
-
{
|
|
376
|
-
stream.read_fNBytes();
|
|
377
|
-
auto fVersion = stream.read_fVersion();
|
|
378
|
-
is_memberwise = fVersion & kStreamedMemberWise;
|
|
379
|
-
check_objwise_memberwise( is_memberwise );
|
|
380
|
-
}
|
|
381
|
-
if ( is_memberwise ) read_element_version( stream );
|
|
338
|
+
if ( is_memberwise ) read_element_version( stream );
|
|
382
339
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
340
|
+
for ( auto i = 0; i < count; i++ ) { read_body( stream, is_memberwise ); }
|
|
341
|
+
return count;
|
|
386
342
|
}
|
|
387
343
|
|
|
388
344
|
/**
|
|
389
|
-
* @brief Read sequences from the stream until reaching the end position. If
|
|
345
|
+
* @brief Read sequences from the stream until reaching the end position. If
|
|
390
346
|
* m_with_header is true, reads a `fNBytes+fVersion` header once before reading
|
|
391
347
|
* sequences. If data is stored member-wise, skips 2 bytes after the header.
|
|
392
348
|
*
|
|
@@ -396,13 +352,12 @@ namespace uproot_custom {
|
|
|
396
352
|
*/
|
|
397
353
|
uint32_t read_until( BinaryStream& stream, const uint8_t* end_pos ) override {
|
|
398
354
|
if ( stream.get_cursor() == end_pos ) return 0;
|
|
399
|
-
bool is_memberwise =
|
|
355
|
+
bool is_memberwise = false;
|
|
400
356
|
if ( m_with_header )
|
|
401
357
|
{
|
|
402
|
-
|
|
358
|
+
stream.skip_fNBytes();
|
|
403
359
|
auto fVersion = stream.read_fVersion();
|
|
404
360
|
is_memberwise = fVersion & kStreamedMemberWise;
|
|
405
|
-
check_objwise_memberwise( is_memberwise );
|
|
406
361
|
}
|
|
407
362
|
if ( is_memberwise ) read_element_version( stream );
|
|
408
363
|
|
|
@@ -433,11 +388,10 @@ namespace uproot_custom {
|
|
|
433
388
|
*/
|
|
434
389
|
class STLMapReader : public IReader {
|
|
435
390
|
private:
|
|
436
|
-
const bool m_with_header;
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
SharedReader
|
|
440
|
-
SharedReader m_value_reader; ///< Reader for the values of the map.
|
|
391
|
+
const bool m_with_header; ///< Whether the map has a `fNBytes+fVersion` header.
|
|
392
|
+
SharedVector<int64_t> m_offsets; ///< Store the offsets for each map.
|
|
393
|
+
SharedReader m_key_reader; ///< Reader for the keys of the map.
|
|
394
|
+
SharedReader m_value_reader; ///< Reader for the values of the map.
|
|
441
395
|
|
|
442
396
|
public:
|
|
443
397
|
/**
|
|
@@ -445,34 +399,17 @@ namespace uproot_custom {
|
|
|
445
399
|
*
|
|
446
400
|
* @param name Name of the reader.
|
|
447
401
|
* @param with_header Whether the map has a `fNBytes+fVersion` header.
|
|
448
|
-
* @param objwise_or_memberwise Object-wise or member-wise reading mode.
|
|
449
|
-
* -1: auto, 0: obj-wise, 1: member-wise.
|
|
450
402
|
* @param key_reader Reader for the keys of the map.
|
|
451
403
|
* @param value_reader Reader for the values of the map.
|
|
452
404
|
*/
|
|
453
|
-
STLMapReader( string name, bool with_header,
|
|
454
|
-
SharedReader
|
|
405
|
+
STLMapReader( string name, bool with_header, SharedReader key_reader,
|
|
406
|
+
SharedReader value_reader )
|
|
455
407
|
: IReader( name )
|
|
456
408
|
, m_with_header( with_header )
|
|
457
|
-
, m_objwise_or_memberwise( objwise_or_memberwise )
|
|
458
409
|
, m_offsets( std::make_shared<vector<int64_t>>( 1, 0 ) )
|
|
459
410
|
, m_key_reader( key_reader )
|
|
460
411
|
, m_value_reader( value_reader ) {}
|
|
461
412
|
|
|
462
|
-
/**
|
|
463
|
-
* @brief Check if the reading mode matches the expected mode.
|
|
464
|
-
*
|
|
465
|
-
* @param is_memberwise Whether the current reading mode is member-wise.
|
|
466
|
-
*/
|
|
467
|
-
void check_objwise_memberwise( const bool is_memberwise ) {
|
|
468
|
-
if ( m_objwise_or_memberwise == 0 && is_memberwise )
|
|
469
|
-
throw std::runtime_error( "STLMapReader(" + name() +
|
|
470
|
-
"): Expect obj-wise, got member-wise!" );
|
|
471
|
-
if ( m_objwise_or_memberwise == 1 && !is_memberwise )
|
|
472
|
-
throw std::runtime_error( "STLMapReader(" + name() +
|
|
473
|
-
"): Expect member-wise, got obj-wise!" );
|
|
474
|
-
}
|
|
475
|
-
|
|
476
413
|
/**
|
|
477
414
|
* @brief Read the element version and checksum from the stream.
|
|
478
415
|
*
|
|
@@ -488,7 +425,7 @@ namespace uproot_custom {
|
|
|
488
425
|
|
|
489
426
|
/**
|
|
490
427
|
* @brief Read the body of the map from the stream. First reads the size
|
|
491
|
-
* (uint32_t) of the map, then calls
|
|
428
|
+
* (uint32_t) of the map, then calls m_key_reader and m_value_reader
|
|
492
429
|
* to read the keys and values. If member-wise, reads all keys first, then all values.
|
|
493
430
|
* Otherwise, reads key-value pairs one by one.
|
|
494
431
|
*
|
|
@@ -527,12 +464,11 @@ namespace uproot_custom {
|
|
|
527
464
|
read_element_version( stream );
|
|
528
465
|
|
|
529
466
|
bool is_memberwise = fVersion & kStreamedMemberWise;
|
|
530
|
-
check_objwise_memberwise( is_memberwise );
|
|
531
467
|
read_body( stream, is_memberwise );
|
|
532
468
|
}
|
|
533
469
|
|
|
534
470
|
/**
|
|
535
|
-
* @brief Read multiple maps from the stream. If
|
|
471
|
+
* @brief Read multiple maps from the stream. If m_with_header is true,
|
|
536
472
|
* reads a `fNBytes+fVersion` header and element version/checksum once before
|
|
537
473
|
* reading multiple maps.
|
|
538
474
|
*
|
|
@@ -543,48 +479,23 @@ namespace uproot_custom {
|
|
|
543
479
|
*/
|
|
544
480
|
uint32_t read_many( BinaryStream& stream, const int64_t count ) override {
|
|
545
481
|
if ( count == 0 ) return 0;
|
|
546
|
-
else if ( count < 0 )
|
|
547
|
-
{
|
|
548
|
-
if ( !m_with_header )
|
|
549
|
-
throw std::runtime_error( "STLMapReader::read with negative count only "
|
|
550
|
-
"supported when with_header is true!" );
|
|
551
482
|
|
|
483
|
+
bool is_memberwise = false;
|
|
484
|
+
if ( m_with_header )
|
|
485
|
+
{
|
|
552
486
|
auto fNBytes = stream.read_fNBytes();
|
|
553
487
|
auto fVersion = stream.read_fVersion();
|
|
554
488
|
read_element_version( stream );
|
|
555
|
-
bool is_memberwise = fVersion & kStreamedMemberWise;
|
|
556
|
-
check_objwise_memberwise( is_memberwise );
|
|
557
489
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
uint32_t cur_count = 0;
|
|
561
|
-
while ( stream.get_cursor() < end_pos )
|
|
562
|
-
{
|
|
563
|
-
read_body( stream, is_memberwise );
|
|
564
|
-
cur_count++;
|
|
565
|
-
}
|
|
566
|
-
return cur_count;
|
|
490
|
+
is_memberwise = fVersion & kStreamedMemberWise;
|
|
567
491
|
}
|
|
568
|
-
else
|
|
569
|
-
{
|
|
570
|
-
bool is_memberwise = m_objwise_or_memberwise == 1;
|
|
571
|
-
if ( m_with_header )
|
|
572
|
-
{
|
|
573
|
-
auto fNBytes = stream.read_fNBytes();
|
|
574
|
-
auto fVersion = stream.read_fVersion();
|
|
575
|
-
read_element_version( stream );
|
|
576
|
-
|
|
577
|
-
is_memberwise = fVersion & kStreamedMemberWise;
|
|
578
|
-
check_objwise_memberwise( is_memberwise );
|
|
579
|
-
}
|
|
580
492
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
493
|
+
for ( auto i = 0; i < count; i++ ) { read_body( stream, is_memberwise ); }
|
|
494
|
+
return count;
|
|
584
495
|
}
|
|
585
496
|
|
|
586
497
|
/**
|
|
587
|
-
* @brief Read maps from the stream until reaching the end position. If
|
|
498
|
+
* @brief Read maps from the stream until reaching the end position. If
|
|
588
499
|
* m_with_header is true, reads a `fNBytes+fVersion` header and element
|
|
589
500
|
* version/checksum once before reading maps.
|
|
590
501
|
*
|
|
@@ -595,7 +506,7 @@ namespace uproot_custom {
|
|
|
595
506
|
uint32_t read_until( BinaryStream& stream, const uint8_t* end_pos ) override {
|
|
596
507
|
if ( stream.get_cursor() == end_pos ) return 0;
|
|
597
508
|
|
|
598
|
-
bool is_memberwise =
|
|
509
|
+
bool is_memberwise = false;
|
|
599
510
|
if ( m_with_header )
|
|
600
511
|
{
|
|
601
512
|
stream.read_fNBytes();
|
|
@@ -603,7 +514,6 @@ namespace uproot_custom {
|
|
|
603
514
|
read_element_version( stream );
|
|
604
515
|
|
|
605
516
|
is_memberwise = fVersion & kStreamedMemberWise;
|
|
606
|
-
check_objwise_memberwise( is_memberwise );
|
|
607
517
|
}
|
|
608
518
|
|
|
609
519
|
uint32_t cur_count = 0;
|
|
@@ -615,27 +525,6 @@ namespace uproot_custom {
|
|
|
615
525
|
return cur_count;
|
|
616
526
|
}
|
|
617
527
|
|
|
618
|
-
/**
|
|
619
|
-
* @brief Read multiple maps from the stream in member-wise mode.
|
|
620
|
-
*
|
|
621
|
-
* @param stream The binary stream to read from.
|
|
622
|
-
* @param count Number of maps to read. If negative, throws an error.
|
|
623
|
-
* @return Number of maps read.
|
|
624
|
-
*/
|
|
625
|
-
virtual uint32_t read_many_memberwise( BinaryStream& stream,
|
|
626
|
-
const int64_t count ) override {
|
|
627
|
-
if ( count < 0 )
|
|
628
|
-
{
|
|
629
|
-
stringstream msg;
|
|
630
|
-
msg << name() << "::read_many_memberwise with negative count: " << count;
|
|
631
|
-
throw std::runtime_error( msg.str() );
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
bool is_memberwise = true;
|
|
635
|
-
check_objwise_memberwise( is_memberwise );
|
|
636
|
-
return read_many( stream, count );
|
|
637
|
-
}
|
|
638
|
-
|
|
639
528
|
/**
|
|
640
529
|
* @brief Get the data read by the reader. This should be called after the whole
|
|
641
530
|
* reading process.
|
|
@@ -688,7 +577,7 @@ namespace uproot_custom {
|
|
|
688
577
|
}
|
|
689
578
|
|
|
690
579
|
/**
|
|
691
|
-
* @brief Read a string from the stream. If
|
|
580
|
+
* @brief Read a string from the stream. If m_with_header is true, reads a
|
|
692
581
|
* `fNBytes+fVersion` header before reading the string body.
|
|
693
582
|
*
|
|
694
583
|
* @param stream The binary stream to read from.
|
|
@@ -703,7 +592,7 @@ namespace uproot_custom {
|
|
|
703
592
|
}
|
|
704
593
|
|
|
705
594
|
/**
|
|
706
|
-
* @brief Read multiple strings from the stream. If
|
|
595
|
+
* @brief Read multiple strings from the stream. If m_with_header is true,
|
|
707
596
|
* reads a `fNBytes+fVersion` header once before reading multiple strings.
|
|
708
597
|
*
|
|
709
598
|
* @param stream The binary stream to read from.
|
|
@@ -713,38 +602,19 @@ namespace uproot_custom {
|
|
|
713
602
|
*/
|
|
714
603
|
uint32_t read_many( BinaryStream& stream, const int64_t count ) override {
|
|
715
604
|
if ( count == 0 ) return 0;
|
|
716
|
-
|
|
605
|
+
|
|
606
|
+
if ( m_with_header )
|
|
717
607
|
{
|
|
718
|
-
if ( !m_with_header )
|
|
719
|
-
throw std::runtime_error( "STLStringReader::read with negative count only "
|
|
720
|
-
"supported when with_header is true!" );
|
|
721
608
|
auto fNBytes = stream.read_fNBytes();
|
|
722
609
|
auto fVersion = stream.read_fVersion();
|
|
723
|
-
|
|
724
|
-
auto end_pos = stream.get_cursor() + fNBytes - 2; // -2 for fVersion
|
|
725
|
-
uint32_t cur_count = 0;
|
|
726
|
-
while ( stream.get_cursor() < end_pos )
|
|
727
|
-
{
|
|
728
|
-
read_body( stream );
|
|
729
|
-
cur_count++;
|
|
730
|
-
}
|
|
731
|
-
return cur_count;
|
|
732
610
|
}
|
|
733
|
-
else
|
|
734
|
-
{
|
|
735
|
-
if ( m_with_header )
|
|
736
|
-
{
|
|
737
|
-
auto fNBytes = stream.read_fNBytes();
|
|
738
|
-
auto fVersion = stream.read_fVersion();
|
|
739
|
-
}
|
|
740
611
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
}
|
|
612
|
+
for ( auto i = 0; i < count; i++ ) { read_body( stream ); }
|
|
613
|
+
return count;
|
|
744
614
|
}
|
|
745
615
|
|
|
746
616
|
/**
|
|
747
|
-
* @brief Read strings from the stream until reaching the end position. If
|
|
617
|
+
* @brief Read strings from the stream until reaching the end position. If
|
|
748
618
|
* m_with_header is true, reads a `fNBytes+fVersion` header once before reading
|
|
749
619
|
* strings.
|
|
750
620
|
*
|
|
@@ -1016,6 +886,13 @@ namespace uproot_custom {
|
|
|
1016
886
|
-----------------------------------------------------------------------------
|
|
1017
887
|
*/
|
|
1018
888
|
|
|
889
|
+
/**
|
|
890
|
+
* @brief Reader for TObject pointers that may reference other objects.
|
|
891
|
+
*
|
|
892
|
+
* Handles the reading of objects through ROOT's pointer mechanism, resolving
|
|
893
|
+
* class references, object references, and inline objects. Maintains an index
|
|
894
|
+
* mapping for each object read.
|
|
895
|
+
*/
|
|
1019
896
|
class AnyPointerReader : public IReader {
|
|
1020
897
|
private:
|
|
1021
898
|
SharedReader m_element_reader; ///< Reader for the object content.
|
|
@@ -1028,11 +905,27 @@ namespace uproot_custom {
|
|
|
1028
905
|
string m_class_name{}; ///< Store the class name of the object
|
|
1029
906
|
|
|
1030
907
|
public:
|
|
908
|
+
/**
|
|
909
|
+
* @brief Construct a new AnyPointerReader object.
|
|
910
|
+
*
|
|
911
|
+
* @param name Name of the reader.
|
|
912
|
+
* @param element_reader Reader for the object content.
|
|
913
|
+
*/
|
|
1031
914
|
AnyPointerReader( string name, SharedReader element_reader )
|
|
1032
915
|
: IReader( name )
|
|
1033
916
|
, m_element_reader( element_reader )
|
|
1034
917
|
, m_object_indexes( std::make_shared<vector<int64_t>>() ) {}
|
|
1035
918
|
|
|
919
|
+
/**
|
|
920
|
+
* @brief Check that the cursor is at the expected position after reading.
|
|
921
|
+
*
|
|
922
|
+
* Throws a runtime error if the cursor doesn't match the expected position,
|
|
923
|
+
* indicating a mismatch in the number of bytes read.
|
|
924
|
+
*
|
|
925
|
+
* @param stream The binary stream to check.
|
|
926
|
+
* @param expected_nbytes The expected number of bytes read.
|
|
927
|
+
* @param expected_pos The expected cursor position after reading.
|
|
928
|
+
*/
|
|
1036
929
|
void check_cursor_position( BinaryStream& stream, const uint32_t expected_nbytes,
|
|
1037
930
|
const uint8_t* expected_pos ) {
|
|
1038
931
|
if ( stream.get_cursor() != expected_pos )
|
|
@@ -1195,8 +1088,8 @@ namespace uproot_custom {
|
|
|
1195
1088
|
, m_element_reader( element_reader ) {}
|
|
1196
1089
|
|
|
1197
1090
|
/**
|
|
1198
|
-
* @brief Read the array from the stream. If
|
|
1199
|
-
* IReader::read_many() function of
|
|
1091
|
+
* @brief Read the array from the stream. If m_flat_size is non-negative, calls @ref
|
|
1092
|
+
* IReader::read_many() function of m_element_reader. Otherwise, reads
|
|
1200
1093
|
* until the end of the current entry in the stream.
|
|
1201
1094
|
*
|
|
1202
1095
|
* @param stream The binary stream to read from.
|
|
@@ -1227,7 +1120,7 @@ namespace uproot_custom {
|
|
|
1227
1120
|
}
|
|
1228
1121
|
|
|
1229
1122
|
/**
|
|
1230
|
-
* @brief Read multiple arrays from the stream. Only supported when
|
|
1123
|
+
* @brief Read multiple arrays from the stream. Only supported when m_flat_size
|
|
1231
1124
|
* is positive.
|
|
1232
1125
|
*
|
|
1233
1126
|
* @param stream The binary stream to read from.
|
|
@@ -1271,7 +1164,7 @@ namespace uproot_custom {
|
|
|
1271
1164
|
* @brief Get the data read by the reader. This should be called after the whole
|
|
1272
1165
|
* reading process.
|
|
1273
1166
|
*
|
|
1274
|
-
* @return If
|
|
1167
|
+
* @return If m_flat_size is positive, directly return the data from
|
|
1275
1168
|
* m_element_reader. Otherwise, return a tuple contains: (offsets, elements_data).
|
|
1276
1169
|
*/
|
|
1277
1170
|
py::object data() const override {
|
|
@@ -1325,6 +1218,7 @@ namespace uproot_custom {
|
|
|
1325
1218
|
*
|
|
1326
1219
|
* @param data Binary data as a numpy array of uint8_t
|
|
1327
1220
|
* @param offsets Offsets for each entry as a numpy array of uint32_t
|
|
1221
|
+
* @param cursor_offset Offset of the first byte in data relative to the original stream, used to calculate reference offsets.
|
|
1328
1222
|
* @param reader Shared pointer to the top-level reader
|
|
1329
1223
|
* @return (Possibly nested) numpy array containing the read data
|
|
1330
1224
|
*/
|
|
@@ -1373,8 +1267,8 @@ namespace uproot_custom {
|
|
|
1373
1267
|
declare_reader<PrimitiveReader<double>, string>( m, "DoubleReader" );
|
|
1374
1268
|
|
|
1375
1269
|
// STL readers
|
|
1376
|
-
declare_reader<STLSeqReader, string, bool,
|
|
1377
|
-
declare_reader<STLMapReader, string, bool,
|
|
1270
|
+
declare_reader<STLSeqReader, string, bool, SharedReader>( m, "STLSeqReader" );
|
|
1271
|
+
declare_reader<STLMapReader, string, bool, SharedReader, SharedReader>(
|
|
1378
1272
|
m, "STLMapReader" );
|
|
1379
1273
|
declare_reader<STLStringReader, string, bool>( m, "STLStringReader" );
|
|
1380
1274
|
|
|
@@ -491,7 +491,7 @@ EXTRACT_ALL = NO
|
|
|
491
491
|
# be included in the documentation.
|
|
492
492
|
# The default value is: NO.
|
|
493
493
|
|
|
494
|
-
EXTRACT_PRIVATE =
|
|
494
|
+
EXTRACT_PRIVATE = YES
|
|
495
495
|
|
|
496
496
|
# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual
|
|
497
497
|
# methods of a class will be included in the documentation.
|
|
@@ -93,7 +93,9 @@ def run_sphinx_apidoc():
|
|
|
93
93
|
|
|
94
94
|
for module in apidoc_modules:
|
|
95
95
|
cmd = [
|
|
96
|
-
|
|
96
|
+
sys.executable,
|
|
97
|
+
"-m",
|
|
98
|
+
"sphinx.ext.apidoc",
|
|
97
99
|
"-o",
|
|
98
100
|
str(Path(__file__).parent / module["destination"]),
|
|
99
101
|
str(Path(__file__).parent / module["path"]),
|
|
@@ -128,6 +130,7 @@ def run_doxygen():
|
|
|
128
130
|
cwd=working_dir,
|
|
129
131
|
capture_output=True,
|
|
130
132
|
text=True,
|
|
133
|
+
check=False,
|
|
131
134
|
)
|
|
132
135
|
|
|
133
136
|
if result.returncode != 0:
|
|
@@ -145,5 +148,10 @@ def run_doxygen_and_apidoc():
|
|
|
145
148
|
def setup(app):
|
|
146
149
|
app.connect("builder-inited", lambda app: run_doxygen_and_apidoc())
|
|
147
150
|
|
|
151
|
+
# Limit in-page TOC depth to show only h2 headings for the binary-format reference page.
|
|
152
|
+
app.connect("html-page-context", _override_toc_depth)
|
|
148
153
|
|
|
149
|
-
|
|
154
|
+
|
|
155
|
+
def _override_toc_depth(app, pagename, templatename, context, doctree):
|
|
156
|
+
if pagename == "reference/binary-format":
|
|
157
|
+
context["theme_show_toc_level"] = 1
|