uproot-custom 2.5.2__tar.gz → 2.6.0b1__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 (119) hide show
  1. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.github/release.yml +2 -2
  2. uproot_custom-2.6.0b1/.github/workflows/deploy-docs.yml +65 -0
  3. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.github/workflows/python-publish.yml +7 -0
  4. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.github/workflows/test-package.yml +21 -0
  5. uproot_custom-2.6.0b1/PKG-INFO +122 -0
  6. uproot_custom-2.6.0b1/README.md +86 -0
  7. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/docs/Doxyfile +1 -1
  8. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader/port-to-cpp.md → uproot_custom-2.6.0b1/docs/advanced/cpp-reader.md +39 -55
  9. uproot_custom-2.6.0b1/docs/advanced/index.md +42 -0
  10. uproot_custom-2.6.0b1/docs/advanced/python-reader.md +198 -0
  11. uproot_custom-2.6.0b1/docs/concepts/choosing-a-route.md +114 -0
  12. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader/pipeline.md → uproot_custom-2.6.0b1/docs/concepts/how-it-works.md +42 -77
  13. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/docs/conf.py +39 -16
  14. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/docs/example/override-streamer.md +104 -96
  15. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/docs/example/read-tobjarray.md +107 -88
  16. uproot_custom-2.6.0b1/docs/getting-started.md +213 -0
  17. uproot_custom-2.6.0b1/docs/index.md +126 -0
  18. uproot_custom-2.6.0b1/docs/reference/api/uproot-custom-ref.md +11 -0
  19. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/docs/reference/binary-format.md +41 -83
  20. uproot_custom-2.6.0b1/docs/reference/detree-dsl.md +169 -0
  21. uproot_custom-2.6.0b1/docs/reference/version-requirements.md +74 -0
  22. uproot_custom-2.6.0b1/docs/tutorial/debug-a-reader.md +87 -0
  23. uproot_custom-2.6.0b1/docs/tutorial/index.md +55 -0
  24. {uproot_custom-2.5.2/docs/tutorial/customize-factory-reader → uproot_custom-2.6.0b1/docs/tutorial}/investigate-data.md +25 -47
  25. uproot_custom-2.6.0b1/docs/tutorial/package-your-project.md +65 -0
  26. uproot_custom-2.6.0b1/docs/tutorial/write-a-reader.md +402 -0
  27. {uproot_custom-2.5.2/cpp → uproot_custom-2.6.0b1/kernel}/CMakeLists.txt +4 -4
  28. {uproot_custom-2.5.2/cpp → uproot_custom-2.6.0b1/kernel}/src/uproot-custom.cc +2 -2
  29. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/pyproject.toml +6 -4
  30. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/conftest.py +47 -34
  31. uproot_custom-2.6.0b1/tests/detree/conftest.py +6 -0
  32. uproot_custom-2.6.0b1/tests/detree/test_decl.py +301 -0
  33. uproot_custom-2.6.0b1/tests/detree/test_exec.py +378 -0
  34. uproot_custom-2.6.0b1/tests/detree/test_frontend.py +142 -0
  35. uproot_custom-2.6.0b1/tests/detree/test_machine.py +154 -0
  36. uproot_custom-2.6.0b1/tests/detree/test_pipeline.py +214 -0
  37. uproot_custom-2.6.0b1/tests/test_claim.py +98 -0
  38. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/test_readers.py +49 -13
  39. uproot_custom-2.6.0b1/uproot_custom/__init__.py +96 -0
  40. {uproot_custom-2.5.2/uproot_custom/readers → uproot_custom-2.6.0b1/uproot_custom}/_forth.py +9 -21
  41. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/uproot_custom/_version.py +3 -3
  42. {uproot_custom-2.5.2/uproot_custom/readers → uproot_custom-2.6.0b1/uproot_custom}/backend.py +14 -14
  43. uproot_custom-2.6.0b1/uproot_custom/consts.py +46 -0
  44. uproot_custom-2.5.2/uproot_custom/readers/cpp.py → uproot_custom-2.6.0b1/uproot_custom/cpp/__init__.py +4 -3
  45. uproot_custom-2.6.0b1/uproot_custom/detree/__init__.py +109 -0
  46. uproot_custom-2.6.0b1/uproot_custom/detree/bufferproxy.py +81 -0
  47. uproot_custom-2.6.0b1/uproot_custom/detree/builtin.py +547 -0
  48. uproot_custom-2.6.0b1/uproot_custom/detree/cache.py +32 -0
  49. uproot_custom-2.6.0b1/uproot_custom/detree/compiler/frontend.py +1139 -0
  50. uproot_custom-2.6.0b1/uproot_custom/detree/compiler/ir_builder.py +426 -0
  51. uproot_custom-2.6.0b1/uproot_custom/detree/decl.py +533 -0
  52. uproot_custom-2.6.0b1/uproot_custom/detree/interp.py +100 -0
  53. uproot_custom-2.6.0b1/uproot_custom/detree/run.py +226 -0
  54. uproot_custom-2.6.0b1/uproot_custom/detree/stream.py +187 -0
  55. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/uproot_custom/factories.py +212 -120
  56. uproot_custom-2.5.2/uproot_custom/as_custom.py → uproot_custom-2.6.0b1/uproot_custom/interpretation.py +124 -27
  57. {uproot_custom-2.5.2/uproot_custom/readers → uproot_custom-2.6.0b1/uproot_custom}/python.py +8 -6
  58. uproot_custom-2.6.0b1/uproot_custom/share/cmake/__init__.py +0 -0
  59. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/uproot_custom/utils.py +27 -0
  60. uproot_custom-2.5.2/.github/workflows/deploy-docs.yml +0 -35
  61. uproot_custom-2.5.2/PKG-INFO +0 -94
  62. uproot_custom-2.5.2/README.md +0 -59
  63. uproot_custom-2.5.2/docs/get-started.md +0 -169
  64. uproot_custom-2.5.2/docs/index.md +0 -92
  65. uproot_custom-2.5.2/docs/reference/api/uproot-custom-ref.md +0 -11
  66. uproot_custom-2.5.2/docs/reference/reader-backends.md +0 -78
  67. uproot_custom-2.5.2/docs/reference/version-requirements.md +0 -50
  68. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader/project-setup.md +0 -74
  69. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader/reader-and-factory.md +0 -416
  70. uproot_custom-2.5.2/docs/tutorial/customize-factory-reader.md +0 -65
  71. uproot_custom-2.5.2/uproot_custom/__init__.py +0 -48
  72. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.clang-format +0 -0
  73. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.github/workflows/build-wheels.yml +0 -0
  74. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.github/workflows/semantic-pr-titles.yml +0 -0
  75. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.github/workflows/weekly-build.yml +0 -0
  76. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.gitignore +0 -0
  77. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/.pre-commit-config.yaml +0 -0
  78. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/LICENSE +0 -0
  79. /uproot_custom-2.5.2/uproot_custom/readers/__init__.py → /uproot_custom-2.6.0b1/docs/_static/.gitkeep +0 -0
  80. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/docs/reference/api/.gitignore +0 -0
  81. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/docs/reference/api/cpp-api.md +0 -0
  82. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/docs/reference/api.md +0 -0
  83. {uproot_custom-2.5.2/cpp → uproot_custom-2.6.0b1/kernel}/include/uproot-custom/uproot-custom.hh +0 -0
  84. {uproot_custom-2.5.2/cpp → uproot_custom-2.6.0b1/kernel}/share/cmake/uproot-customConfig.cmake +0 -0
  85. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_cstyle_array.root +0 -0
  86. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_pointers.root +0 -0
  87. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_primitive.root +0 -0
  88. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_pure_struct.root +0 -0
  89. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_root_objects.root +0 -0
  90. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_simple_obj.root +0 -0
  91. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_stl_array.root +0 -0
  92. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_stl_complicated.root +0 -0
  93. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_stl_map.root +0 -0
  94. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_stl_map_with_obj.root +0 -0
  95. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_stl_nested.root +0 -0
  96. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_stl_seq_with_obj.root +0 -0
  97. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_stl_sequence.root +0 -0
  98. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/data/test_stl_string.root +0 -0
  99. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/CMakeLists.txt +0 -0
  100. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/README.md +0 -0
  101. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/LinkDef.h +0 -0
  102. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TBasicTypes.hh +0 -0
  103. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TCStyleArray.hh +0 -0
  104. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TComplicatedSTL.hh +0 -0
  105. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TNestedSTL.hh +0 -0
  106. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TPointers.hh +0 -0
  107. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TPureStruct.hh +0 -0
  108. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TRootObjects.hh +0 -0
  109. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TSTLArray.hh +0 -0
  110. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TSTLMap.hh +0 -0
  111. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TSTLMapWithObj.hh +0 -0
  112. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TSTLSeqWithObj.hh +0 -0
  113. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TSTLSequence.hh +0 -0
  114. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TSTLString.hh +0 -0
  115. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/include/TSimpleObject.hh +0 -0
  116. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/gen-test-data/src/main.cc +0 -0
  117. {uproot_custom-2.5.2 → uproot_custom-2.6.0b1}/tests/test_AsCustom.py +0 -0
  118. /uproot_custom-2.5.2/uproot_custom/cpp.pyi → /uproot_custom-2.6.0b1/uproot_custom/cpp/kernel.pyi +0 -0
  119. {uproot_custom-2.5.2/uproot_custom/share/cmake → uproot_custom-2.6.0b1/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,65 @@
1
+ name: Deploy docs
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ workflow_call:
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ # One deployment at a time, and never cancel one half-way: a cancelled deploy
11
+ # can leave the Pages site serving a partial artifact.
12
+ concurrency:
13
+ group: pages
14
+ cancel-in-progress: false
15
+
16
+ jobs:
17
+ build:
18
+ name: Build docs
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v6
23
+
24
+ - uses: astral-sh/setup-uv@v7
25
+ with:
26
+ python-version: '3.13'
27
+ activate-environment: true
28
+
29
+ - name: Install dependencies
30
+ run: |
31
+ sudo apt-get update
32
+ sudo apt-get install -y doxygen
33
+ uv pip install -e . --group docs
34
+
35
+ - name: Configure GitHub Pages
36
+ uses: actions/configure-pages@v5
37
+
38
+ # Sphinx writes relative links, so the project-site prefix
39
+ # (https://<owner>.github.io/uproot-custom/) needs no configuration.
40
+ - name: Build docs
41
+ run: |
42
+ uv run sphinx-build -b html -W --keep-going docs/ build/html
43
+
44
+ - name: Upload Pages artifact
45
+ uses: actions/upload-pages-artifact@v3
46
+ with:
47
+ path: build/html
48
+
49
+ deploy:
50
+ name: Deploy docs
51
+ needs: build
52
+ runs-on: ubuntu-latest
53
+
54
+ permissions:
55
+ pages: write
56
+ id-token: write
57
+
58
+ environment:
59
+ name: github-pages
60
+ url: ${{ steps.deployment.outputs.page_url }}
61
+
62
+ steps:
63
+ - name: Deploy to GitHub Pages
64
+ id: deployment
65
+ uses: actions/deploy-pages@v4
@@ -23,6 +23,13 @@ jobs:
23
23
  uses: ./.github/workflows/deploy-docs.yml
24
24
  needs:
25
25
  - pypi-publish
26
+ # A called workflow can only downgrade the caller's token permissions, and
27
+ # this workflow grants only `contents: write` above, so the Pages scopes have
28
+ # to be granted here for the deploy job to be able to publish.
29
+ permissions:
30
+ contents: read
31
+ pages: write
32
+ id-token: write
26
33
 
27
34
  pypi-publish:
28
35
  runs-on: ubuntu-latest
@@ -36,6 +36,27 @@ jobs:
36
36
  uv run pytest --version
37
37
  uv run pytest -v tests/
38
38
 
39
+ test-detree:
40
+ runs-on: ubuntu-latest
41
+ steps:
42
+ - uses: actions/checkout@v6
43
+ - uses: actions/checkout@v6
44
+ with:
45
+ repository: mrzimu/detree-vm
46
+ path: detree-vm
47
+ ref: v0.1.0
48
+ - uses: astral-sh/setup-uv@v7
49
+ with:
50
+ python-version: '3.11'
51
+ activate-environment: true
52
+ - uses: dtolnay/rust-toolchain@stable
53
+ - name: Install detree-vm
54
+ run: DETREE_SHIP_BACKEND=both uv pip install -e detree-vm
55
+ - name: Install package
56
+ run: uv pip install -e . --group dev
57
+ - name: Run the detree backend and machine tests
58
+ run: uv run pytest -v tests/detree/ tests/test_readers.py::test_detree
59
+
39
60
  test-build-docs:
40
61
  runs-on: ubuntu-latest
41
62
  steps:
@@ -0,0 +1,122 @@
1
+ Metadata-Version: 2.2
2
+ Name: uproot-custom
3
+ Version: 2.6.0b1
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
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.
@@ -112,16 +112,13 @@ methods as the Python version:
112
112
 
113
113
  ## Accepting sub-readers
114
114
 
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.
115
+ 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
116
 
119
117
  ---
120
118
 
121
119
  ## Zero-copy `numpy` conversion
122
120
 
123
- Use the `make_array` helper to convert a `std::shared_ptr<std::vector<T>>`
124
- into a `numpy` array **without copying**:
121
+ Use the `make_array` helper to convert a `std::shared_ptr<std::vector<T>>` into a `numpy` array **without copying**:
125
122
 
126
123
  ```cpp
127
124
  std::shared_ptr<std::vector<int>> data = std::make_shared<std::vector<int>>();
@@ -136,8 +133,7 @@ py::array_t<int> np_array = make_array(data);
136
133
 
137
134
  ## Exposing a reader to Python
138
135
 
139
- Uproot-custom uses `pybind11` for bindings. The `declare_reader` helper
140
- simplifies declaration:
136
+ Uproot-custom uses `pybind11` for bindings. The `declare_reader` helper simplifies declaration:
141
137
 
142
138
  ```cpp
143
139
  PYBIND11_MODULE( my_cpp_reader, m) {
@@ -158,9 +154,7 @@ from my_cpp_reader import MyReaderClass
158
154
 
159
155
  ## C++ debug output
160
156
 
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:
157
+ 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
158
 
165
159
  ```cpp
166
160
  // Will print "The reader name is Bob"
@@ -174,19 +168,13 @@ debug_print( stream, 50 )
174
168
 
175
169
  ## Adding `build_cpp_reader` to the factory
176
170
 
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.
171
+ 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
172
 
182
173
  ---
183
174
 
184
175
  ## Side-by-side comparison: `OverrideStreamerReader`
185
176
 
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.
177
+ 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
178
 
191
179
  `````{tab-set}
192
180
 
@@ -198,7 +186,7 @@ lineno-start: 1
198
186
  ---
199
187
  from array import array
200
188
  import numpy as np
201
- from uproot_custom.readers.python import IReader
189
+ from uproot_custom.python import IReader
202
190
 
203
191
 
204
192
  class OverrideStreamerReader(IReader):
@@ -293,8 +281,7 @@ class OverrideStreamerFactory(Factory):
293
281
 
294
282
  ## Worked example: `TArray` in C++
295
283
 
296
- Compare with the [Python version](reader-and-factory.md#worked-example-tarray)
297
- — the reading logic is identical; only the language syntax differs:
284
+ Compare with the [Python version](python-reader.md#worked-example-tarray) — the reading logic is identical; only the language syntax differs:
298
285
 
299
286
  ```{code-block} cpp
300
287
  ---
@@ -336,36 +323,33 @@ emphasize-lines: 2-12
336
323
  class TArrayFactory(Factory):
337
324
  def build_cpp_reader(self):
338
325
  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,
326
+ "int8": uproot_custom.cpp.TArrayCReader,
327
+ "int16": uproot_custom.cpp.TArraySReader,
328
+ "int32": uproot_custom.cpp.TArrayIReader,
329
+ "int64": uproot_custom.cpp.TArrayLReader,
330
+ "float32": uproot_custom.cpp.TArrayFReader,
331
+ "float64": uproot_custom.cpp.TArrayDReader,
345
332
  }[self.dtype](self.name)
346
333
 
347
334
  def build_python_reader(self):
348
- return uproot_custom.readers.python.TArrayReader(self.name, self.dtype)
335
+ return uproot_custom.python.TArrayReader(self.name, self.dtype)
349
336
 
350
337
  # ... make_awkward_content and make_awkward_form remain unchanged
351
338
  ```
352
339
 
353
340
  ---
354
341
 
355
- ## Switching to the C++ backend
342
+ ## Selecting the C++ stage
356
343
 
357
- After implementing `build_cpp_reader`, switch the backend to use
358
- C++ readers:
344
+ After implementing `build_cpp_reader`, select the backend:
359
345
 
360
346
  ```python
361
- from uproot_custom.readers import backend
362
- backend.set("cpp")
347
+ import uproot_custom as uc
348
+ uc.set_backend("cpp")
363
349
  ```
364
350
 
365
- Since `"cpp"` is the default value, you can simply remove any explicit
366
- ``backend.set("python")`` that was set during development.
351
+ `"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
352
 
368
353
  ```{seealso}
369
- See [](../../reference/reader-backends.md) for a full discussion of backend
370
- selection and troubleshooting.
354
+ See [](../concepts/choosing-a-route.md) for the trade-offs and backend selection.
371
355
  ```
@@ -0,0 +1,42 @@
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
+ ```{important}
24
+ 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.
25
+ ```
26
+
27
+ ## What it costs
28
+
29
+ - **Two implementations.** The Python and C++ readers must decode the same bytes into the same `data()` shape; nothing checks that beyond your tests.
30
+ - **A build step for users.** The extension is compiled per platform and per Python version.
31
+ - **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).
32
+
33
+ ## The two stages
34
+
35
+ ```{toctree}
36
+ ---
37
+ maxdepth: 2
38
+ hidden: true
39
+ ---
40
+ python-reader
41
+ cpp-reader
42
+ ```