uproot-custom 2.5.2__tar.gz → 2.6.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.
Files changed (120) hide show
  1. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.github/release.yml +2 -2
  2. uproot_custom-2.6.0/PKG-INFO +122 -0
  3. uproot_custom-2.6.0/README.md +86 -0
  4. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/docs/Doxyfile +1 -1
  5. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader/port-to-cpp.md → uproot_custom-2.6.0/docs/advanced/cpp-reader.md +60 -55
  6. uproot_custom-2.6.0/docs/advanced/index.md +58 -0
  7. uproot_custom-2.6.0/docs/advanced/python-reader.md +220 -0
  8. uproot_custom-2.6.0/docs/concepts/choosing-a-route.md +114 -0
  9. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader/pipeline.md → uproot_custom-2.6.0/docs/concepts/how-it-works.md +49 -89
  10. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/docs/conf.py +39 -16
  11. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/docs/example/override-streamer.md +104 -96
  12. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/docs/example/read-tobjarray.md +107 -88
  13. uproot_custom-2.6.0/docs/getting-started.md +213 -0
  14. uproot_custom-2.6.0/docs/index.md +126 -0
  15. uproot_custom-2.6.0/docs/reference/api/uproot-custom-ref.md +11 -0
  16. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/docs/reference/binary-format.md +41 -83
  17. uproot_custom-2.6.0/docs/reference/detree-dsl.md +195 -0
  18. uproot_custom-2.6.0/docs/reference/version-requirements.md +74 -0
  19. uproot_custom-2.6.0/docs/tutorial/debug-a-reader.md +87 -0
  20. uproot_custom-2.6.0/docs/tutorial/index.md +55 -0
  21. {uproot_custom-2.5.2/docs/tutorial/customize-factory-reader → uproot_custom-2.6.0/docs/tutorial}/investigate-data.md +25 -47
  22. uproot_custom-2.6.0/docs/tutorial/package-your-project.md +65 -0
  23. uproot_custom-2.6.0/docs/tutorial/write-a-reader.md +404 -0
  24. {uproot_custom-2.5.2/cpp → uproot_custom-2.6.0/kernel}/CMakeLists.txt +4 -4
  25. {uproot_custom-2.5.2/cpp → uproot_custom-2.6.0/kernel}/include/uproot-custom/uproot-custom.hh +131 -0
  26. {uproot_custom-2.5.2/cpp → uproot_custom-2.6.0/kernel}/src/uproot-custom.cc +11 -44
  27. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/pyproject.toml +6 -4
  28. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/conftest.py +47 -34
  29. uproot_custom-2.6.0/tests/detree/conftest.py +6 -0
  30. uproot_custom-2.6.0/tests/detree/test_decl.py +346 -0
  31. uproot_custom-2.6.0/tests/detree/test_exec.py +417 -0
  32. uproot_custom-2.6.0/tests/detree/test_frontend.py +243 -0
  33. uproot_custom-2.6.0/tests/detree/test_machine.py +154 -0
  34. uproot_custom-2.6.0/tests/detree/test_pipeline.py +214 -0
  35. uproot_custom-2.6.0/tests/test_claim.py +98 -0
  36. uproot_custom-2.6.0/tests/test_cpp_stream.py +61 -0
  37. uproot_custom-2.6.0/tests/test_python_stream.py +87 -0
  38. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/test_readers.py +49 -13
  39. uproot_custom-2.6.0/uproot_custom/__init__.py +96 -0
  40. {uproot_custom-2.5.2/uproot_custom/readers → uproot_custom-2.6.0/uproot_custom}/_forth.py +9 -21
  41. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/uproot_custom/_version.py +3 -3
  42. {uproot_custom-2.5.2/uproot_custom/readers → uproot_custom-2.6.0/uproot_custom}/backend.py +14 -14
  43. uproot_custom-2.6.0/uproot_custom/consts.py +46 -0
  44. uproot_custom-2.5.2/uproot_custom/readers/cpp.py → uproot_custom-2.6.0/uproot_custom/cpp/__init__.py +4 -3
  45. uproot_custom-2.6.0/uproot_custom/detree/__init__.py +109 -0
  46. uproot_custom-2.6.0/uproot_custom/detree/bufferproxy.py +81 -0
  47. uproot_custom-2.6.0/uproot_custom/detree/builtin.py +542 -0
  48. uproot_custom-2.6.0/uproot_custom/detree/cache.py +32 -0
  49. uproot_custom-2.6.0/uproot_custom/detree/compiler/frontend.py +1270 -0
  50. uproot_custom-2.6.0/uproot_custom/detree/compiler/ir_builder.py +432 -0
  51. uproot_custom-2.6.0/uproot_custom/detree/decl.py +560 -0
  52. uproot_custom-2.6.0/uproot_custom/detree/interp.py +104 -0
  53. uproot_custom-2.6.0/uproot_custom/detree/run.py +226 -0
  54. uproot_custom-2.6.0/uproot_custom/detree/stream.py +244 -0
  55. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/uproot_custom/factories.py +212 -120
  56. uproot_custom-2.5.2/uproot_custom/as_custom.py → uproot_custom-2.6.0/uproot_custom/interpretation.py +124 -27
  57. {uproot_custom-2.5.2/uproot_custom/readers → uproot_custom-2.6.0/uproot_custom}/python.py +73 -32
  58. uproot_custom-2.6.0/uproot_custom/share/cmake/__init__.py +0 -0
  59. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/uproot_custom/utils.py +27 -0
  60. uproot_custom-2.5.2/PKG-INFO +0 -94
  61. uproot_custom-2.5.2/README.md +0 -59
  62. uproot_custom-2.5.2/docs/get-started.md +0 -169
  63. uproot_custom-2.5.2/docs/index.md +0 -92
  64. uproot_custom-2.5.2/docs/reference/api/uproot-custom-ref.md +0 -11
  65. uproot_custom-2.5.2/docs/reference/reader-backends.md +0 -78
  66. uproot_custom-2.5.2/docs/reference/version-requirements.md +0 -50
  67. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader/project-setup.md +0 -74
  68. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader/reader-and-factory.md +0 -416
  69. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader.md +0 -65
  70. uproot_custom-2.5.2/uproot_custom/__init__.py +0 -48
  71. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.clang-format +0 -0
  72. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.github/workflows/build-wheels.yml +0 -0
  73. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.github/workflows/deploy-docs.yml +0 -0
  74. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.github/workflows/python-publish.yml +0 -0
  75. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.github/workflows/semantic-pr-titles.yml +0 -0
  76. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.github/workflows/test-package.yml +0 -0
  77. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.github/workflows/weekly-build.yml +0 -0
  78. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.gitignore +0 -0
  79. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/.pre-commit-config.yaml +0 -0
  80. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/LICENSE +0 -0
  81. /uproot_custom-2.5.2/uproot_custom/readers/__init__.py → /uproot_custom-2.6.0/docs/_static/.gitkeep +0 -0
  82. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/docs/reference/api/.gitignore +0 -0
  83. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/docs/reference/api/cpp-api.md +0 -0
  84. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/docs/reference/api.md +0 -0
  85. {uproot_custom-2.5.2/cpp → uproot_custom-2.6.0/kernel}/share/cmake/uproot-customConfig.cmake +0 -0
  86. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_cstyle_array.root +0 -0
  87. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_pointers.root +0 -0
  88. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_primitive.root +0 -0
  89. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_pure_struct.root +0 -0
  90. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_root_objects.root +0 -0
  91. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_simple_obj.root +0 -0
  92. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_stl_array.root +0 -0
  93. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_stl_complicated.root +0 -0
  94. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_stl_map.root +0 -0
  95. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_stl_map_with_obj.root +0 -0
  96. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_stl_nested.root +0 -0
  97. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_stl_seq_with_obj.root +0 -0
  98. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_stl_sequence.root +0 -0
  99. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/data/test_stl_string.root +0 -0
  100. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/CMakeLists.txt +0 -0
  101. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/README.md +0 -0
  102. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/LinkDef.h +0 -0
  103. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TBasicTypes.hh +0 -0
  104. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TCStyleArray.hh +0 -0
  105. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TComplicatedSTL.hh +0 -0
  106. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TNestedSTL.hh +0 -0
  107. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TPointers.hh +0 -0
  108. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TPureStruct.hh +0 -0
  109. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TRootObjects.hh +0 -0
  110. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TSTLArray.hh +0 -0
  111. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TSTLMap.hh +0 -0
  112. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TSTLMapWithObj.hh +0 -0
  113. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TSTLSeqWithObj.hh +0 -0
  114. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TSTLSequence.hh +0 -0
  115. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TSTLString.hh +0 -0
  116. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/include/TSimpleObject.hh +0 -0
  117. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/gen-test-data/src/main.cc +0 -0
  118. {uproot_custom-2.5.2 → uproot_custom-2.6.0}/tests/test_AsCustom.py +0 -0
  119. /uproot_custom-2.5.2/uproot_custom/cpp.pyi → /uproot_custom-2.6.0/uproot_custom/cpp/kernel.pyi +0 -0
  120. {uproot_custom-2.5.2/uproot_custom/share/cmake → uproot_custom-2.6.0/uproot_custom/detree/compiler}/__init__.py +0 -0
@@ -1,8 +1,8 @@
1
1
  changelog:
2
2
  categories:
3
- - title: C++ API Changes
3
+ - title: Breaking Changes
4
4
  labels:
5
- - break cpp
5
+ - break
6
6
  - title: New Features
7
7
  labels:
8
8
  - feature
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.2
2
+ Name: uproot-custom
3
+ Version: 2.6.0
4
+ Summary: Uproot extension for reading custom classes
5
+ Author-Email: Mingrun Li <mrli@ihep.ac.cn>
6
+ Classifier: Development Status :: 3 - Alpha
7
+ Classifier: Intended Audience :: Developers
8
+ Classifier: Intended Audience :: Information Technology
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: License :: OSI Approved :: BSD License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: POSIX
13
+ Classifier: Operating System :: Unix
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Scientific/Engineering
24
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
25
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
26
+ Classifier: Topic :: Scientific/Engineering :: Physics
27
+ Classifier: Topic :: Software Development
28
+ Classifier: Topic :: Utilities
29
+ Project-URL: Homepage, https://github.com/mrzimu/uproot-custom
30
+ Requires-Python: <3.15,>=3.9
31
+ Requires-Dist: uproot>=5.6.7
32
+ Requires-Dist: numpy
33
+ Requires-Dist: awkward>=2.8.0
34
+ Requires-Dist: detree-vm>=0.1.1
35
+ Description-Content-Type: text/markdown
36
+
37
+ # Introduction
38
+
39
+ 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`.
40
+
41
+ > [!WARNING]
42
+ > 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.
43
+
44
+ ## What Uproot-custom can do
45
+
46
+ Uproot-custom can natively read complicated combinations of nested classes and c-style arrays (e.g. `map<int, map<int, map<int, string>>>`, `vector<TString>[3]`, etc), and memberwisely stored classes. It also exposes a way for users to implement their own readers for custom classes that are not supported by Uproot or Uproot-custom built-in readers.
47
+
48
+ ## When to use Uproot-custom
49
+
50
+ Uproot-custom aims to handle cases that classes are too complex for Uproot to read, such as when their `Streamer` methods are overridden or some specific data members are not supported by Uproot.
51
+
52
+ ## Two technical routes
53
+
54
+ A downstream project adds readers for the classes its collaboration stores. There are two routes to make such a reader run, and **Detree is the recommended one**:
55
+
56
+ - **One language.** The read path is Python source, compiled to a detree-vm module; there is no second implementation to port and keep in sync.
57
+ - **No ABI.** A C++ reader is built against the Uproot-custom header, a pybind11 minor version and one Python ABI, so it must be pinned and rebuilt. A Detree reader is compiled at run time and has none of those couplings.
58
+ - **No build step.** `pip install` is the whole installation; users need no C++ toolchain.
59
+ - **Fast enough.** The read path runs as bytecode on the Detree machine, far faster than a Python reader.
60
+
61
+ The other route is **Python + C++**: write the reader as an `IReader` in Python to get the logic right, then port it to C++ for production. The Python half is slow enough that shipping it is rarely an option, so this route almost always means maintaining both implementations, shipping a compiled extension, and pinning versions. Take it when the read path needs plain Python, or when a branch needs the last measure of speed.
62
+
63
+ ## How Uproot-custom works
64
+
65
+ Uproot-custom uses a Reader / Factory mechanism to read classes:
66
+
67
+ ```mermaid
68
+ flowchart TD
69
+ subgraph py["Python"]
70
+ direction TB
71
+ AsCustom -- Recursively generate --> fac["Factory (Primitive, STLVector, TString, ...)"]
72
+ fac["Factory (Primitive, STLVector, TString, ...)"] -- Optional --> form(["construct awkward forms"])
73
+ fac --> build_reader(["build the selected backend's reader"])
74
+ fac --> build_ak(["construct awkward arrays"])
75
+ end
76
+
77
+ subgraph reader_field["Reader"]
78
+ direction TB
79
+ build_reader --> reader["Detree reader (declared fields + read)"]
80
+ reader --> compile(["compile_reader: reader -> detree-vm module"])
81
+ compile --> machine(["Detree machine: runs the module"])
82
+ end
83
+
84
+ machine --> raw_data[("buffers: numpy arrays, tuples, ...")]
85
+ raw_data --> build_ak
86
+ ```
87
+
88
+ - `Factory` is a Python class that matches a class from the streamer information, creates its reader, and post-processes the raw data into `awkward`.
89
+ - `Reader` decodes the bytes. With Detree it declares its buffers and sub-readers as fields and writes `read` in Python; the compiler lowers it to a detree-vm module, and the machine executes it for every basket.
90
+
91
+ This mechanism is implemented as the `AsCustom` interpretation, and the byte-level reader is selected by the reader backend: `detree` for the Detree route, `python` while developing on the Python + C++ route and `cpp` in production. This keeps Uproot-custom well compatible with Uproot.
92
+
93
+ > [!TIP]
94
+ > Users can implement their own Factory and Reader and register them with Uproot-custom. Write a **Detree reader** first; take the **Python + C++ route** when the read path needs plain Python, or when a branch needs more speed than Detree gives. An example downstream project can be found in [the example repository](https://github.com/mrzimu/uproot-custom-example).
95
+
96
+ ## Quick start
97
+
98
+ ```python
99
+ import uproot
100
+ import uproot_custom as uc
101
+
102
+ uc.claim("/my_tree:my_branch")
103
+
104
+ f = uproot.open("file.root")
105
+ arr = f["my_tree/my_branch"].array()
106
+ ```
107
+
108
+ ## System Requirements
109
+
110
+ - **Python 3.9+**: Uproot-custom supports Python 3.9 through 3.14.
111
+ - **C++17 compiler**: only for the C++ stage of the Python + C++ route. Detree readers need no compiler, no CMake and no build step.
112
+
113
+ ## Documentation
114
+
115
+ View the [documentation](https://mrzimu.github.io/uproot-custom/) for the reader/factory pipeline, the Detree reader reference, and the trade-offs between the two routes. The pages worth starting with:
116
+
117
+ - [Get started](https://mrzimu.github.io/uproot-custom/getting-started.html)
118
+ - [Write a Detree reader](https://mrzimu.github.io/uproot-custom/tutorial/index.html)
119
+ - [Choosing a technical route](https://mrzimu.github.io/uproot-custom/concepts/choosing-a-route.html)
120
+
121
+ > [!NOTE]
122
+ > Uproot-custom does not provide a full reimplementation of `ROOT`'s TTree I/O system. Users are expected to implement their own Factory / Reader for their custom classes that built-in factories cannot handle.
@@ -0,0 +1,86 @@
1
+ # Introduction
2
+
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
+
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. Please specify a minor version when using Uproot-custom as a dependency (e.g., `uproot-custom==2.5.*`) to avoid unexpected breaking changes.
7
+
8
+ ## What Uproot-custom can do
9
+
10
+ Uproot-custom can natively read complicated combinations of nested classes and c-style arrays (e.g. `map<int, map<int, map<int, string>>>`, `vector<TString>[3]`, etc), and memberwisely stored classes. It also exposes a way for users to implement their own readers for custom classes that are not supported by Uproot or Uproot-custom built-in readers.
11
+
12
+ ## When to use Uproot-custom
13
+
14
+ Uproot-custom aims to handle cases that classes are too complex for Uproot to read, such as when their `Streamer` methods are overridden or some specific data members are not supported by Uproot.
15
+
16
+ ## Two technical routes
17
+
18
+ A downstream project adds readers for the classes its collaboration stores. There are two routes to make such a reader run, and **Detree is the recommended one**:
19
+
20
+ - **One language.** The read path is Python source, compiled to a detree-vm module; there is no second implementation to port and keep in sync.
21
+ - **No ABI.** A C++ reader is built against the Uproot-custom header, a pybind11 minor version and one Python ABI, so it must be pinned and rebuilt. A Detree reader is compiled at run time and has none of those couplings.
22
+ - **No build step.** `pip install` is the whole installation; users need no C++ toolchain.
23
+ - **Fast enough.** The read path runs as bytecode on the Detree machine, far faster than a Python reader.
24
+
25
+ The other route is **Python + C++**: write the reader as an `IReader` in Python to get the logic right, then port it to C++ for production. The Python half is slow enough that shipping it is rarely an option, so this route almost always means maintaining both implementations, shipping a compiled extension, and pinning versions. Take it when the read path needs plain Python, or when a branch needs the last measure of speed.
26
+
27
+ ## How Uproot-custom works
28
+
29
+ Uproot-custom uses a Reader / Factory mechanism to read classes:
30
+
31
+ ```mermaid
32
+ flowchart TD
33
+ subgraph py["Python"]
34
+ direction TB
35
+ AsCustom -- Recursively generate --> fac["Factory (Primitive, STLVector, TString, ...)"]
36
+ fac["Factory (Primitive, STLVector, TString, ...)"] -- Optional --> form(["construct awkward forms"])
37
+ fac --> build_reader(["build the selected backend's reader"])
38
+ fac --> build_ak(["construct awkward arrays"])
39
+ end
40
+
41
+ subgraph reader_field["Reader"]
42
+ direction TB
43
+ build_reader --> reader["Detree reader (declared fields + read)"]
44
+ reader --> compile(["compile_reader: reader -> detree-vm module"])
45
+ compile --> machine(["Detree machine: runs the module"])
46
+ end
47
+
48
+ machine --> raw_data[("buffers: numpy arrays, tuples, ...")]
49
+ raw_data --> build_ak
50
+ ```
51
+
52
+ - `Factory` is a Python class that matches a class from the streamer information, creates its reader, and post-processes the raw data into `awkward`.
53
+ - `Reader` decodes the bytes. With Detree it declares its buffers and sub-readers as fields and writes `read` in Python; the compiler lowers it to a detree-vm module, and the machine executes it for every basket.
54
+
55
+ This mechanism is implemented as the `AsCustom` interpretation, and the byte-level reader is selected by the reader backend: `detree` for the Detree route, `python` while developing on the Python + C++ route and `cpp` in production. This keeps Uproot-custom well compatible with Uproot.
56
+
57
+ > [!TIP]
58
+ > Users can implement their own Factory and Reader and register them with Uproot-custom. Write a **Detree reader** first; take the **Python + C++ route** when the read path needs plain Python, or when a branch needs more speed than Detree gives. An example downstream project can be found in [the example repository](https://github.com/mrzimu/uproot-custom-example).
59
+
60
+ ## Quick start
61
+
62
+ ```python
63
+ import uproot
64
+ import uproot_custom as uc
65
+
66
+ uc.claim("/my_tree:my_branch")
67
+
68
+ f = uproot.open("file.root")
69
+ arr = f["my_tree/my_branch"].array()
70
+ ```
71
+
72
+ ## System Requirements
73
+
74
+ - **Python 3.9+**: Uproot-custom supports Python 3.9 through 3.14.
75
+ - **C++17 compiler**: only for the C++ stage of the Python + C++ route. Detree readers need no compiler, no CMake and no build step.
76
+
77
+ ## Documentation
78
+
79
+ View the [documentation](https://mrzimu.github.io/uproot-custom/) for the reader/factory pipeline, the Detree reader reference, and the trade-offs between the two routes. The pages worth starting with:
80
+
81
+ - [Get started](https://mrzimu.github.io/uproot-custom/getting-started.html)
82
+ - [Write a Detree reader](https://mrzimu.github.io/uproot-custom/tutorial/index.html)
83
+ - [Choosing a technical route](https://mrzimu.github.io/uproot-custom/concepts/choosing-a-route.html)
84
+
85
+ > [!NOTE]
86
+ > Uproot-custom does not provide a full reimplementation of `ROOT`'s TTree I/O system. Users are expected to implement their own Factory / Reader for their custom classes that built-in factories cannot handle.
@@ -864,7 +864,7 @@ WARN_LOGFILE =
864
864
  # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
865
865
  # Note: If this tag is empty the current directory is searched.
866
866
 
867
- INPUT = ../cpp
867
+ INPUT = ../kernel
868
868
 
869
869
  # This tag can be used to specify the character encoding of the source files
870
870
  # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
@@ -1,23 +1,24 @@
1
- # Port readers to C++
2
-
3
- Once your Python reader is working correctly, you can port its logic to C++
4
- for significantly better performance. **The C++ reader only needs to keep the
5
- same reading logic as the Python version** — the same fields read in the same
6
- order, and `data()` returning the same structure — so porting is a
7
- straightforward, mechanical process.
8
-
9
- ```{tip}
10
- Start with a Python reader for rapid prototyping and debugging. Once the
11
- logic is validated, transferring it to C++ is quick because the two readers
12
- share the same structure and only differ in language syntax.
13
- ```
1
+ # Stage 2: the C++ implementation
14
2
 
15
- ---
3
+ This is what production runs on the Python + C++ route. It is the fastest executor and the most expensive thing to ship: write it after the [Python implementation](python-reader.md) has established the byte layout, and expect to pin the uproot-custom version and rebuild for every Python version you support.
4
+
5
+ The two stages must decode the same bytes into the same `data()` shape. The factory shares `make_awkward_content` and `make_awkward_form`, so a mismatch between the implementations shows up as a wrong array, not as a build error.
6
+
7
+ ## Version pinning and the ABI
8
+
9
+ A C++ reader is compiled against the Uproot-custom header, the pybind11 it exposes, and one Python ABI. Each of those can move independently of your project:
10
+
11
+ | Coupled to | What happens when it moves |
12
+ | ---------- | -------------------------- |
13
+ | the Uproot-custom header | `IReader` is compatible only within one minor version; a newer minor may change the vtable and the module fails to load |
14
+ | the pybind11 minor version | the Python-visible base type stops resolving: `ImportError: generic_type: type "xxx" referenced unknown base type "uproot::IReader"` |
15
+ | the Python ABI | each Python minor version needs a rebuilt wheel |
16
+
17
+ A downstream project therefore pins the exact Uproot-custom minor version and the matching pybind11 minor version, ships a wheel per Python version, and rebuilds when either moves. This is the cost the [Detree path](../concepts/choosing-a-route.md) removes; [version requirements](../reference/version-requirements.md) lists the pinned versions.
16
18
 
17
19
  ## C++ `IReader` base class
18
20
 
19
- Every C++ reader must inherit from `IReader` and implement two pure-virtual
20
- methods:
21
+ Every C++ reader must inherit from `IReader` and implement two pure-virtual methods:
21
22
 
22
23
  | Method | Purpose |
23
24
  | ------ | ------- |
@@ -82,8 +83,7 @@ class IReader {
82
83
 
83
84
  ## C++ `BinaryStream`
84
85
 
85
- The C++ `BinaryStream` wraps a `uint8_t*` stream with the same convenience
86
- methods as the Python version:
86
+ The C++ `BinaryStream` wraps a `uint8_t*` stream with the same convenience methods as the Python version:
87
87
 
88
88
  **Reading**
89
89
  - `const T read<T>()`: Read a value of type `T` from the stream, and advance the cursor.
@@ -101,6 +101,27 @@ methods as the Python version:
101
101
  - `void skip_obj_header()`: Skip the object header.
102
102
  - `void skip_TObject()`: Skip a `TObject`.
103
103
 
104
+ ### Counted regions
105
+
106
+ An object framed by its byte count declares how many bytes follow it. Both forms below check that the block consumed exactly that many, and throw `std::runtime_error` with `expected N, got M`:
107
+
108
+ ```cpp
109
+ void read( BinaryStream& stream ) override {
110
+ auto frame = stream.check_nbytes();
111
+ auto fVersion = stream.read_fVersion();
112
+ if ( fVersion == 0 ) stream.skip( 4 );
113
+ for ( auto& reader : m_element_readers ) { reader->read( stream ); }
114
+ }
115
+ ```
116
+
117
+ - `void check_nbytes_start()`: read the masked `fNBytes` and remember where the region ends. Regions nest, so a framed sub-reader does not disturb its caller.
118
+ - `void check_nbytes_end()`: fail unless the cursor is at the end of the innermost region.
119
+ - `void check_nbytes_end( const uint8_t* expected )`: fail unless the cursor is at `expected`, for a region whose size was computed rather than read.
120
+ - `CountedRegion check_nbytes()`: open the region and check it when the bound guard leaves scope — the C++ form of Python's `with`. Bind it (`auto frame = ...`); the return type is `[[nodiscard]]` because a bare statement would close the region immediately.
121
+ - `size_t open_frames() const`: the number of regions still waiting for their end.
122
+
123
+ A block that throws drops the region without a second exception, so the original error survives. The Python form of this API is in [the Python reader page](python-reader.md#binarystream).
124
+
104
125
  **Miscellaneous**
105
126
  - `const uint8_t* get_data() const`: Get the start of the data stream.
106
127
  - `const uint8_t* get_cursor() const`: Get the current cursor position.
@@ -112,16 +133,13 @@ methods as the Python version:
112
133
 
113
134
  ## Accepting sub-readers
114
135
 
115
- Composite readers (e.g. `STLSeqReader`) accept sub-readers for nested types.
116
- Pass sub-readers as `std::shared_ptr<IReader>` (aliased as `SharedReader`)
117
- because ownership is shared between C++ and Python.
136
+ Composite readers (e.g. `STLSeqReader`) accept sub-readers for nested types. Pass sub-readers as `std::shared_ptr<IReader>` (aliased as `SharedReader`) because ownership is shared between C++ and Python.
118
137
 
119
138
  ---
120
139
 
121
140
  ## Zero-copy `numpy` conversion
122
141
 
123
- Use the `make_array` helper to convert a `std::shared_ptr<std::vector<T>>`
124
- into a `numpy` array **without copying**:
142
+ Use the `make_array` helper to convert a `std::shared_ptr<std::vector<T>>` into a `numpy` array **without copying**:
125
143
 
126
144
  ```cpp
127
145
  std::shared_ptr<std::vector<int>> data = std::make_shared<std::vector<int>>();
@@ -136,8 +154,7 @@ py::array_t<int> np_array = make_array(data);
136
154
 
137
155
  ## Exposing a reader to Python
138
156
 
139
- Uproot-custom uses `pybind11` for bindings. The `declare_reader` helper
140
- simplifies declaration:
157
+ Uproot-custom uses `pybind11` for bindings. The `declare_reader` helper simplifies declaration:
141
158
 
142
159
  ```cpp
143
160
  PYBIND11_MODULE( my_cpp_reader, m) {
@@ -158,9 +175,7 @@ from my_cpp_reader import MyReaderClass
158
175
 
159
176
  ## C++ debug output
160
177
 
161
- Use the `debug_print` helper for conditional logging. Messages are only
162
- emitted when the `UPROOT_DEBUG` macro is defined at compile time **or** the
163
- `UPROOT_DEBUG` environment variable is set at runtime:
178
+ Use the `debug_print` helper for conditional logging. Messages are only emitted when the `UPROOT_DEBUG` macro is defined at compile time **or** the `UPROOT_DEBUG` environment variable is set at runtime:
164
179
 
165
180
  ```cpp
166
181
  // Will print "The reader name is Bob"
@@ -174,19 +189,13 @@ debug_print( stream, 50 )
174
189
 
175
190
  ## Adding `build_cpp_reader` to the factory
176
191
 
177
- Once the C++ reader is ready, add a `build_cpp_reader` method to the factory
178
- alongside the existing `build_python_reader`. This is the **only** Python-side
179
- change needed — `make_awkward_content` and `make_awkward_form` remain exactly
180
- the same, because both readers return data in the same structure.
192
+ Once the C++ reader is ready, add a `build_cpp_reader` method to the factory alongside the Detree reader. This is the **only** Python-side change needed — `make_awkward_content` and `make_awkward_form` remain exactly the same, because both readers return data in the same structure.
181
193
 
182
194
  ---
183
195
 
184
196
  ## Side-by-side comparison: `OverrideStreamerReader`
185
197
 
186
- The following tabs show the same `OverrideStreamerReader` (from the
187
- [pipeline example](pipeline.md#complete-example-putting-it-all-together))
188
- in Python and C++. Notice how the reading logic is identical — only the
189
- language syntax differs.
198
+ The following tabs show the same `OverrideStreamerReader` (from the [pipeline example](../concepts/how-it-works.md#complete-example-putting-it-all-together)) in Python and C++. Notice how the reading logic is identical — only the language syntax differs.
190
199
 
191
200
  `````{tab-set}
192
201
 
@@ -198,7 +207,7 @@ lineno-start: 1
198
207
  ---
199
208
  from array import array
200
209
  import numpy as np
201
- from uproot_custom.readers.python import IReader
210
+ from uproot_custom.python import IReader
202
211
 
203
212
 
204
213
  class OverrideStreamerReader(IReader):
@@ -293,8 +302,7 @@ class OverrideStreamerFactory(Factory):
293
302
 
294
303
  ## Worked example: `TArray` in C++
295
304
 
296
- Compare with the [Python version](reader-and-factory.md#worked-example-tarray)
297
- — the reading logic is identical; only the language syntax differs:
305
+ Compare with the [Python version](python-reader.md#worked-example-tarray) — the reading logic is identical; only the language syntax differs:
298
306
 
299
307
  ```{code-block} cpp
300
308
  ---
@@ -336,36 +344,33 @@ emphasize-lines: 2-12
336
344
  class TArrayFactory(Factory):
337
345
  def build_cpp_reader(self):
338
346
  return {
339
- "int8": uproot_custom.readers.cpp.TArrayCReader,
340
- "int16": uproot_custom.readers.cpp.TArraySReader,
341
- "int32": uproot_custom.readers.cpp.TArrayIReader,
342
- "int64": uproot_custom.readers.cpp.TArrayLReader,
343
- "float32": uproot_custom.readers.cpp.TArrayFReader,
344
- "float64": uproot_custom.readers.cpp.TArrayDReader,
347
+ "int8": uproot_custom.cpp.TArrayCReader,
348
+ "int16": uproot_custom.cpp.TArraySReader,
349
+ "int32": uproot_custom.cpp.TArrayIReader,
350
+ "int64": uproot_custom.cpp.TArrayLReader,
351
+ "float32": uproot_custom.cpp.TArrayFReader,
352
+ "float64": uproot_custom.cpp.TArrayDReader,
345
353
  }[self.dtype](self.name)
346
354
 
347
355
  def build_python_reader(self):
348
- return uproot_custom.readers.python.TArrayReader(self.name, self.dtype)
356
+ return uproot_custom.python.TArrayReader(self.name, self.dtype)
349
357
 
350
358
  # ... make_awkward_content and make_awkward_form remain unchanged
351
359
  ```
352
360
 
353
361
  ---
354
362
 
355
- ## Switching to the C++ backend
363
+ ## Selecting the C++ stage
356
364
 
357
- After implementing `build_cpp_reader`, switch the backend to use
358
- C++ readers:
365
+ After implementing `build_cpp_reader`, select the backend:
359
366
 
360
367
  ```python
361
- from uproot_custom.readers import backend
362
- backend.set("cpp")
368
+ import uproot_custom as uc
369
+ uc.set_backend("cpp")
363
370
  ```
364
371
 
365
- Since `"cpp"` is the default value, you can simply remove any explicit
366
- ``backend.set("python")`` that was set during development.
372
+ `"cpp"` is the code default, so a project that ships only C++ readers needs no call — but a project that also selects Detree elsewhere must set it explicitly.
367
373
 
368
374
  ```{seealso}
369
- See [](../../reference/reader-backends.md) for a full discussion of backend
370
- selection and troubleshooting.
375
+ See [](../concepts/choosing-a-route.md) for the trade-offs and backend selection.
371
376
  ```
@@ -0,0 +1,58 @@
1
+ # The Python + C++ route
2
+
3
+ Detree is the recommended route: one reader, written in Python source, compiled at run time, with no build step and no version pinning. This section documents the other one, in which a branch is decoded by an `IReader` written twice — once in Python, then again in C++.
4
+
5
+ Read [choosing a technical route](../concepts/choosing-a-route.md) first; the trade-offs below are the short version.
6
+
7
+ ## Why take this route
8
+
9
+ Two reasons, and only two:
10
+
11
+ - **The read path needs plain Python.** A construct outside the [compilable subset](../reference/detree-dsl.md#the-compilable-subset) — a `try`, a lookup into a dictionary keyed by a name read from the file, a call into another package — cannot be expressed as a Detree reader.
12
+ - **Detree is not fast enough.** The branch is a measurable fraction of the analysis time, and the last factor of speed matters more than the cost listed below.
13
+
14
+ ## How the route works
15
+
16
+ The route has two stages, and they must stay in step:
17
+
18
+ 1. **[The Python implementation](python-reader.md)** — an `IReader` whose `read` is ordinary Python. It accepts anything Python can do, needs no build step, and runs at Python speed. This is where the logic is worked out and debugged.
19
+ 2. **[The C++ implementation](cpp-reader.md)** — the same fields in the same order, written in C++, compiled into a pybind11 extension. This is what runs in production.
20
+
21
+ Both stages share one factory: `build_python_reader` returns the first, `build_cpp_reader` returns the second, and `make_awkward_content` / `make_awkward_form` are written once. Only the stage matching the selected backend runs.
22
+
23
+ ### One stream API in both languages
24
+
25
+ The two stages read the same bytes through the same `BinaryStream`, method for method, so a reader ports by translating syntax rather than by re-learning the stream. The counted-region API is the clearest example:
26
+
27
+ ```python
28
+ with stream.check_nbytes():
29
+ ...
30
+ ```
31
+
32
+ ```cpp
33
+ auto frame = stream.check_nbytes();
34
+ ...
35
+ ```
36
+
37
+ Both read the masked `fNBytes`, both check the end position when the block ends, and both name the two positions in the error. Method names are identical in the two pages: [`python-reader.md`](python-reader.md) and [`cpp-reader.md`](cpp-reader.md).
38
+
39
+ ```{important}
40
+ The Python stage is not a deployment target. It is several times slower than Detree, so a project on this route is expected to finish the port to C++ before it ships. The Python implementation stays in the repository as the readable statement of the byte layout and as a debugging oracle.
41
+ ```
42
+
43
+ ## What it costs
44
+
45
+ - **Two implementations.** The Python and C++ readers must decode the same bytes into the same `data()` shape; nothing checks that beyond your tests.
46
+ - **A build step for users.** The extension is compiled per platform and per Python version.
47
+ - **Version pinning.** The C++ header is compatible only within one uproot-custom minor version, the pybind11 minor version must match, and each Python ABI needs a rebuild. See [version requirements](../reference/version-requirements.md).
48
+
49
+ ## The two stages
50
+
51
+ ```{toctree}
52
+ ---
53
+ maxdepth: 2
54
+ hidden: true
55
+ ---
56
+ python-reader
57
+ cpp-reader
58
+ ```