uproot-custom 2.4.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.
Files changed (87) hide show
  1. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.pre-commit-config.yaml +2 -2
  2. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/PKG-INFO +2 -2
  3. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/README.md +1 -1
  4. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/cpp/include/uproot-custom/uproot-custom.hh +59 -40
  5. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/cpp/src/uproot-custom.cc +83 -248
  6. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/Doxyfile +1 -1
  7. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/conf.py +10 -2
  8. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/example/override-streamer.md +11 -10
  9. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/example/read-tobjarray.md +43 -46
  10. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/index.md +1 -1
  11. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/reference/api/uproot-custom-ref.md +0 -1
  12. uproot_custom-2.5.1/docs/reference/binary-format.md +662 -0
  13. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/reference/reader-backends.md +26 -15
  14. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/pipeline.md +8 -8
  15. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/port-to-cpp.md +3 -3
  16. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/reader-and-factory.md +1 -2
  17. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader.md +5 -5
  18. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/conftest.py +6 -0
  19. uproot_custom-2.5.1/tests/data/test_pure_struct.root +0 -0
  20. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/CMakeLists.txt +1 -0
  21. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/README.md +2 -2
  22. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/LinkDef.h +2 -4
  23. uproot_custom-2.5.1/tests/gen-test-data/include/TPureStruct.hh +16 -0
  24. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/src/main.cc +21 -0
  25. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/test_readers.py +9 -39
  26. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/__init__.py +2 -4
  27. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/_version.py +3 -3
  28. uproot_custom-2.4.0/uproot_custom/AsCustom.py → uproot_custom-2.5.1/uproot_custom/as_custom.py +33 -34
  29. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/cpp.pyi +0 -9
  30. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/factories.py +89 -278
  31. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/readers/_forth.py +48 -248
  32. uproot_custom-2.5.1/uproot_custom/readers/backend.py +93 -0
  33. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/readers/cpp.py +1 -3
  34. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/readers/python.py +55 -181
  35. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/utils.py +0 -2
  36. uproot_custom-2.4.0/docs/reference/api/cpp-module.md +0 -6
  37. uproot_custom-2.4.0/docs/reference/binary-format.md +0 -167
  38. uproot_custom-2.4.0/uproot_custom/readers/_numba.py +0 -1348
  39. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.clang-format +0 -0
  40. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.github/release.yml +0 -0
  41. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.github/workflows/build-wheels.yml +0 -0
  42. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.github/workflows/deploy-docs.yml +0 -0
  43. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.github/workflows/python-publish.yml +0 -0
  44. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.github/workflows/semantic-pr-titles.yml +0 -0
  45. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.github/workflows/test-package.yml +0 -0
  46. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.github/workflows/weekly-build.yml +0 -0
  47. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/.gitignore +0 -0
  48. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/LICENSE +0 -0
  49. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/cpp/CMakeLists.txt +0 -0
  50. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/cpp/share/cmake/uproot-customConfig.cmake +0 -0
  51. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/get-started.md +0 -0
  52. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/reference/api/.gitignore +0 -0
  53. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/reference/api/cpp-api.md +0 -0
  54. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/reference/api.md +0 -0
  55. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/reference/version-requirements.md +0 -0
  56. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/investigate-data.md +0 -0
  57. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/docs/tutorial/customize-factory-reader/project-setup.md +0 -0
  58. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/pyproject.toml +0 -0
  59. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_cstyle_array.root +0 -0
  60. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_pointers.root +0 -0
  61. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_primitive.root +0 -0
  62. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_root_objects.root +0 -0
  63. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_simple_obj.root +0 -0
  64. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_stl_array.root +0 -0
  65. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_stl_complicated.root +0 -0
  66. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_stl_map.root +0 -0
  67. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_stl_map_with_obj.root +0 -0
  68. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_stl_nested.root +0 -0
  69. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_stl_seq_with_obj.root +0 -0
  70. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_stl_sequence.root +0 -0
  71. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/data/test_stl_string.root +0 -0
  72. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TBasicTypes.hh +0 -0
  73. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TCStyleArray.hh +0 -0
  74. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TComplicatedSTL.hh +0 -0
  75. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TNestedSTL.hh +0 -0
  76. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TPointers.hh +0 -0
  77. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TRootObjects.hh +0 -0
  78. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLArray.hh +0 -0
  79. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLMap.hh +0 -0
  80. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLMapWithObj.hh +0 -0
  81. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLSeqWithObj.hh +0 -0
  82. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLSequence.hh +0 -0
  83. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSTLString.hh +0 -0
  84. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/gen-test-data/include/TSimpleObject.hh +0 -0
  85. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/tests/test_AsCustom.py +0 -0
  86. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/readers/__init__.py +0 -0
  87. {uproot_custom-2.4.0 → uproot_custom-2.5.1}/uproot_custom/share/cmake/__init__.py +0 -0
@@ -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.3.1
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.12
31
+ rev: v0.16.6
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.4.0
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
 
@@ -33,22 +33,31 @@
33
33
  */
34
34
  #define IMPORT_UPROOT_CUSTOM_CPP pybind11::module_::import( "uproot_custom.cpp" );
35
35
 
36
- namespace uproot {
36
+ namespace uproot_custom {
37
37
  namespace py = pybind11;
38
38
  using std::shared_ptr;
39
39
 
40
- const uint32_t kNewClassTag = 0xFFFFFFFF;
41
- const uint32_t kClassMask = 0x80000000; // OR the class index with this
42
- const uint32_t kByteCountMask = 0x40000000; // OR the byte count with this
43
- const uint32_t kMaxMapCount = 0x3FFFFFFE; // last valid fMapCount and byte count
44
- const uint16_t kByteCountVMask = 0x4000; // OR the version byte count with this
45
- const uint16_t kMaxVersion = 0x3FFF; // highest possible version number
46
- const int32_t kMapOffset = 2; // first 2 map entries are taken by null obj and self obj
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
- const uint16_t kStreamedMemberWise = 1 << 14; // streamed member-wise mask
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 {
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 )
@@ -97,10 +116,9 @@ namespace uproot {
97
116
  const T read() {
98
117
  constexpr auto size = sizeof( T );
99
118
 
100
- switch ( size )
119
+ if constexpr ( size == 1 ) return *reinterpret_cast<const T*>( m_cursor++ );
120
+ else if constexpr ( size == 2 )
101
121
  {
102
- case 1: return *reinterpret_cast<const T*>( m_cursor++ );
103
- case 2: {
104
122
  union {
105
123
  T value;
106
124
  uint16_t bits;
@@ -110,7 +128,8 @@ namespace uproot {
110
128
  val.bits = bswap16( val.bits );
111
129
  return val.value;
112
130
  }
113
- case 4: {
131
+ else if constexpr ( size == 4 )
132
+ {
114
133
  union {
115
134
  T value;
116
135
  uint32_t bits;
@@ -120,7 +139,8 @@ namespace uproot {
120
139
  val.bits = bswap32( val.bits );
121
140
  return val.value;
122
141
  }
123
- case 8: {
142
+ else if constexpr ( size == 8 )
143
+ {
124
144
  union {
125
145
  T value;
126
146
  uint64_t bits;
@@ -130,9 +150,10 @@ namespace uproot {
130
150
  val.bits = bswap64( val.bits );
131
151
  return val.value;
132
152
  }
133
- default:
134
- throw std::runtime_error( "Unsupported type size: " + std::to_string( size ) );
135
- }
153
+ else
154
+ static_assert(
155
+ sizeof( T ) == 0,
156
+ "read<T>: unsupported type size (only 1, 2, 4, 8 bytes allowed)" );
136
157
  }
137
158
 
138
159
  /**
@@ -168,15 +189,14 @@ namespace uproot {
168
189
  }
169
190
 
170
191
  /**
171
- * @brief Read an object header from the stream. The object header has `fNBytes`,
192
+ * @brief Read an object's header from the stream. The object header has `fNBytes`,
172
193
  * `fVersion`, `fTag`. If `fTag == kNewClassTag`, then a null-terminated class name
173
194
  * follows.
174
195
  *
175
- * @return The class name if the object is a new class, empty string
176
- * otherwise.
196
+ * @return The class name if the object is a new class, empty string otherwise.
177
197
  */
178
198
  const std::string read_obj_header() {
179
- read_fNBytes();
199
+ skip_fNBytes();
180
200
  auto fTag = read<uint32_t>();
181
201
  if ( fTag == kNewClassTag ) return read_null_terminated_string();
182
202
  else return std::string();
@@ -224,7 +244,7 @@ namespace uproot {
224
244
  }
225
245
 
226
246
  /**
227
- * @brief Skip an object header in the stream. The object header has `fNBytes`,
247
+ * @brief Skip an object's header in the stream. The object header has `fNBytes`,
228
248
  * `fVersion`, `fTag`. If `fTag == kNewClassTag`, then a null-terminated class name
229
249
  * follows.
230
250
  */
@@ -240,7 +260,6 @@ namespace uproot {
240
260
  * follows.
241
261
  */
242
262
  void skip_TObject() {
243
- // TODO: CanIgnoreTObjectStreamer() ?
244
263
  skip_fVersion();
245
264
  skip( 4 ); // fUniqueID
246
265
  auto fBits = read<uint32_t>();
@@ -496,8 +515,8 @@ namespace uproot {
496
515
  */
497
516
 
498
517
  /**
499
- * @brief Debug print function. Prints only when macro or environment varialbe with name
500
- * `UPROOT_DEBUG` is defined. Use this function like `printf()`.
518
+ * @brief Debug print function. Prints only when environment variable with name
519
+ * `UPROOT_CUSTOM_DEBUG` is defined. Use this function like `printf()`.
501
520
  *
502
521
  * @tparam Args Argument types. No need to specify explicitly.
503
522
  * @param msg The format string.
@@ -505,29 +524,29 @@ namespace uproot {
505
524
  */
506
525
  template <typename... Args>
507
526
  inline void debug_printf( const char* msg, Args... args ) {
508
- bool do_print = getenv( "UPROOT_DEBUG" );
509
- #ifdef UPROOT_DEBUG
510
- do_print = true;
511
- #endif
527
+ bool do_print = getenv( "UPROOT_CUSTOM_DEBUG" );
512
528
  if ( !do_print ) return;
513
529
  printf( msg, std::forward<Args>( args )... );
514
530
  }
515
531
 
516
532
  /**
517
- * @brief Debug print function for BinaryStream. Prints only when macro or environment
518
- * variable with name `UPROOT_DEBUG` is defined. Call @ref BinaryStream::debug_print()
519
- * internally.
533
+ * @brief Debug print function for BinaryStream. Prints only when environment
534
+ * variable with name `UPROOT_CUSTOM_DEBUG` is defined. Call @ref
535
+ * BinaryStream::debug_print() internally.
520
536
  *
521
537
  * @param stream The BinaryStream to print.
522
538
  * @param n Number of bytes to print.
523
539
  */
524
- inline void debug_printf( uproot::BinaryStream& stream, const size_t n = 100 ) {
525
- bool do_print = getenv( "UPROOT_DEBUG" );
526
- #ifdef UPROOT_DEBUG
527
- do_print = true;
528
- #endif
540
+ inline void debug_printf( uproot_custom::BinaryStream& stream, const size_t n = 100 ) {
541
+ bool do_print = getenv( "UPROOT_CUSTOM_DEBUG" );
529
542
  if ( !do_print ) return;
530
543
  stream.debug_print( n );
531
544
  }
532
545
 
533
- } // namespace uproot
546
+ } // namespace uproot_custom
547
+
548
+ // backward compatibility
549
+ // TODO: remove the uproot namespace and use uproot_custom namespace directly in the future.
550
+ namespace uproot {
551
+ using namespace uproot_custom;
552
+ }