uproot-custom 1.0.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uproot_custom-1.0.0a1/.clang-format +127 -0
- uproot_custom-1.0.0a1/.gitignore +209 -0
- uproot_custom-1.0.0a1/LICENSE +28 -0
- uproot_custom-1.0.0a1/PKG-INFO +330 -0
- uproot_custom-1.0.0a1/README.md +303 -0
- uproot_custom-1.0.0a1/cpp/CMakeLists.txt +52 -0
- uproot_custom-1.0.0a1/cpp/include/uproot-custom/uproot-custom.hh +218 -0
- uproot_custom-1.0.0a1/cpp/share/cmake/uproot-customConfig.cmake +19 -0
- uproot_custom-1.0.0a1/cpp/src/uproot-custom.cc +407 -0
- uproot_custom-1.0.0a1/example/README.md +46 -0
- uproot_custom-1.0.0a1/example/cpp/CMakeLists.txt +31 -0
- uproot_custom-1.0.0a1/example/cpp/my_reader.cc +48 -0
- uproot_custom-1.0.0a1/example/gen-demo-data/CMakeLists.txt +29 -0
- uproot_custom-1.0.0a1/example/gen-demo-data/include/LinkDef.h +9 -0
- uproot_custom-1.0.0a1/example/gen-demo-data/include/TOverrideStreamer.hh +16 -0
- uproot_custom-1.0.0a1/example/gen-demo-data/src/TOverrideStreamer.cc +34 -0
- uproot_custom-1.0.0a1/example/gen-demo-data/src/main.cc +22 -0
- uproot_custom-1.0.0a1/example/my_reader/OverrideStreamerReader.py +45 -0
- uproot_custom-1.0.0a1/example/my_reader/__init__.py +9 -0
- uproot_custom-1.0.0a1/example/pyproject.toml +21 -0
- uproot_custom-1.0.0a1/example/read-data.py +11 -0
- uproot_custom-1.0.0a1/pyproject.toml +49 -0
- uproot_custom-1.0.0a1/tests/test-data.root +0 -0
- uproot_custom-1.0.0a1/tests/test_AsCustom.py +19 -0
- uproot_custom-1.0.0a1/uproot_custom/AsBinary.py +62 -0
- uproot_custom-1.0.0a1/uproot_custom/AsCustom.py +174 -0
- uproot_custom-1.0.0a1/uproot_custom/__init__.py +53 -0
- uproot_custom-1.0.0a1/uproot_custom/_cpp.pyi +105 -0
- uproot_custom-1.0.0a1/uproot_custom/_version.py +21 -0
- uproot_custom-1.0.0a1/uproot_custom/readers.py +839 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# This .clang_format file is derectly copied from Gaudi project.
|
|
2
|
+
---
|
|
3
|
+
Language: Cpp
|
|
4
|
+
BasedOnStyle: Google
|
|
5
|
+
AccessModifierOffset: -2
|
|
6
|
+
AlignAfterOpenBracket: Align
|
|
7
|
+
AlignConsecutiveAssignments: true
|
|
8
|
+
AlignConsecutiveDeclarations: false
|
|
9
|
+
AlignEscapedNewlines: Right
|
|
10
|
+
AlignOperands: true
|
|
11
|
+
AlignTrailingComments: true
|
|
12
|
+
AllowAllParametersOfDeclarationOnNextLine: true
|
|
13
|
+
AllowShortBlocksOnASingleLine: Always
|
|
14
|
+
AllowShortCaseLabelsOnASingleLine: true
|
|
15
|
+
AllowShortFunctionsOnASingleLine: All
|
|
16
|
+
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
|
|
17
|
+
AllowShortLoopsOnASingleLine: true
|
|
18
|
+
AlwaysBreakAfterDefinitionReturnType: None
|
|
19
|
+
AlwaysBreakAfterReturnType: None
|
|
20
|
+
AlwaysBreakBeforeMultilineStrings: false
|
|
21
|
+
AlwaysBreakTemplateDeclarations: true
|
|
22
|
+
BinPackArguments: true
|
|
23
|
+
BinPackParameters: true
|
|
24
|
+
BraceWrapping:
|
|
25
|
+
AfterClass: false
|
|
26
|
+
AfterControlStatement: true
|
|
27
|
+
AfterEnum: false
|
|
28
|
+
AfterFunction: false
|
|
29
|
+
AfterNamespace: false
|
|
30
|
+
AfterObjCDeclaration: false
|
|
31
|
+
AfterStruct: false
|
|
32
|
+
AfterUnion: false
|
|
33
|
+
AfterExternBlock: false
|
|
34
|
+
BeforeCatch: false
|
|
35
|
+
BeforeElse: true
|
|
36
|
+
IndentBraces: false
|
|
37
|
+
SplitEmptyFunction: false
|
|
38
|
+
SplitEmptyRecord: false
|
|
39
|
+
SplitEmptyNamespace: false
|
|
40
|
+
BreakBeforeBinaryOperators: None
|
|
41
|
+
BreakBeforeBraces: Custom
|
|
42
|
+
BreakBeforeInheritanceComma: false
|
|
43
|
+
BreakBeforeTernaryOperators: true
|
|
44
|
+
BreakConstructorInitializersBeforeComma: true
|
|
45
|
+
BreakConstructorInitializers: BeforeComma
|
|
46
|
+
BreakAfterJavaFieldAnnotations: false
|
|
47
|
+
BreakStringLiterals: true
|
|
48
|
+
ColumnLimit: 95
|
|
49
|
+
CommentPragmas: '^ IWYU pragma:'
|
|
50
|
+
CompactNamespaces: false
|
|
51
|
+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
|
52
|
+
ConstructorInitializerIndentWidth: 4
|
|
53
|
+
ContinuationIndentWidth: 4
|
|
54
|
+
Cpp11BracedListStyle: true
|
|
55
|
+
DerivePointerAlignment: false
|
|
56
|
+
DisableFormat: false
|
|
57
|
+
ExperimentalAutoDetectBinPacking: false
|
|
58
|
+
FixNamespaceComments: true
|
|
59
|
+
ForEachMacros:
|
|
60
|
+
- foreach
|
|
61
|
+
- Q_FOREACH
|
|
62
|
+
- BOOST_FOREACH
|
|
63
|
+
IncludeBlocks: Preserve
|
|
64
|
+
IncludeCategories:
|
|
65
|
+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
|
66
|
+
Priority: 2
|
|
67
|
+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
|
68
|
+
Priority: 3
|
|
69
|
+
- Regex: '.*'
|
|
70
|
+
Priority: 1
|
|
71
|
+
IncludeIsMainRegex: '(Test)?$'
|
|
72
|
+
IndentCaseLabels: false
|
|
73
|
+
IndentPPDirectives: AfterHash
|
|
74
|
+
IndentWidth: 4
|
|
75
|
+
IndentWrappedFunctionNames: false
|
|
76
|
+
JavaScriptQuotes: Leave
|
|
77
|
+
JavaScriptWrapImports: true
|
|
78
|
+
KeepEmptyLinesAtTheStartOfBlocks: true
|
|
79
|
+
MacroBlockBegin: ''
|
|
80
|
+
MacroBlockEnd: ''
|
|
81
|
+
MaxEmptyLinesToKeep: 1
|
|
82
|
+
NamespaceIndentation: All
|
|
83
|
+
ObjCBinPackProtocolList: Auto
|
|
84
|
+
ObjCBlockIndentWidth: 2
|
|
85
|
+
ObjCSpaceAfterProperty: false
|
|
86
|
+
ObjCSpaceBeforeProtocolList: true
|
|
87
|
+
PenaltyBreakAssignment: 2
|
|
88
|
+
PenaltyBreakBeforeFirstCallParameter: 19
|
|
89
|
+
PenaltyBreakComment: 60
|
|
90
|
+
PenaltyBreakFirstLessLess: 30
|
|
91
|
+
PenaltyBreakString: 1000
|
|
92
|
+
PenaltyBreakTemplateDeclaration: 10
|
|
93
|
+
PenaltyExcessCharacter: 1000000
|
|
94
|
+
PenaltyReturnTypeOnItsOwnLine: 60
|
|
95
|
+
PointerAlignment: Left
|
|
96
|
+
ReflowComments: true
|
|
97
|
+
SortIncludes: CaseSensitive
|
|
98
|
+
SortUsingDeclarations: true
|
|
99
|
+
SpaceAfterCStyleCast: false
|
|
100
|
+
SpaceAfterTemplateKeyword: true
|
|
101
|
+
SpaceBeforeAssignmentOperators: true
|
|
102
|
+
SpaceBeforeCpp11BracedList: false
|
|
103
|
+
SpaceBeforeCtorInitializerColon: true
|
|
104
|
+
SpaceBeforeInheritanceColon: true
|
|
105
|
+
SpaceBeforeParens: ControlStatements
|
|
106
|
+
SpaceBeforeRangeBasedForLoopColon: true
|
|
107
|
+
SpaceInEmptyParentheses: false
|
|
108
|
+
SpacesBeforeTrailingComments: 1
|
|
109
|
+
SpacesInAngles: false
|
|
110
|
+
SpacesInContainerLiterals: true
|
|
111
|
+
SpacesInCStyleCastParentheses: false
|
|
112
|
+
SpacesInParentheses: true
|
|
113
|
+
Standard: c++11
|
|
114
|
+
TabWidth: 8
|
|
115
|
+
UseTab: Never
|
|
116
|
+
---
|
|
117
|
+
Language: Json
|
|
118
|
+
IndentWidth: 4
|
|
119
|
+
ColumnLimit: 95
|
|
120
|
+
---
|
|
121
|
+
Language: JavaScript
|
|
122
|
+
ColumnLimit: 95
|
|
123
|
+
---
|
|
124
|
+
Language: ObjC
|
|
125
|
+
# Don't format Objective-C, Objective-C++ files.
|
|
126
|
+
DisableFormat: true
|
|
127
|
+
...
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
.vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
_version.py
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Mingrun Li
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: uproot-custom
|
|
3
|
+
Version: 1.0.0a1
|
|
4
|
+
Summary: uproot extension for reading custom classes
|
|
5
|
+
Author-Email: Mingrun Li <mrun_lee@foxmail.com>
|
|
6
|
+
Classifier: Development Status :: 3 - Alpha
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: C++
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Project-URL: Repository, https://github.com/mrzimu/uproot-custom
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Requires-Dist: uproot>=5.0
|
|
22
|
+
Requires-Dist: awkward
|
|
23
|
+
Requires-Dist: numpy
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest; extra == "dev"
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# uproot-custom
|
|
29
|
+
|
|
30
|
+
This is a prototype repository of an extension that allows `uproot` to read custom classes from ROOT files.
|
|
31
|
+
|
|
32
|
+
`uproot` can already read some custom classes directly. However, in some cases, custom 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`.
|
|
33
|
+
|
|
34
|
+
This extension privides a `Reader` interface and allows you to read such custom classes by providing your own `Reader`. The `Reader` interface defines how to read the data members of a class from the binary stream.
|
|
35
|
+
|
|
36
|
+
## Design overview
|
|
37
|
+
|
|
38
|
+
In ROOT, data are stored in a tree structure. For example, when a custom class is defined as:
|
|
39
|
+
|
|
40
|
+
```cpp
|
|
41
|
+
class TMySubClass : public TObject {
|
|
42
|
+
int m_index;
|
|
43
|
+
float m_x;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
class TMyClass : public TObject {
|
|
47
|
+
double m_energy;
|
|
48
|
+
std::vector<MySubClass> m_daughters;
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The data tree is:
|
|
53
|
+
|
|
54
|
+
```mermaid
|
|
55
|
+
graph TD
|
|
56
|
+
A([TMyClass]) --> B(double m_energy)
|
|
57
|
+
A --> C(std::vector<TMySubClass> m_daughters)
|
|
58
|
+
C --> D([TMySubClass])
|
|
59
|
+
D --> E(int m_index)
|
|
60
|
+
D --> F(float m_x)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
To handle the tree-like data structure, `Reader` is introduced. It consists of `Python` and `C++` parts. The `Python` part is responsible for generating the information tree, constructing C++ readers, and reconstructing data to `awkward` array. The `C++` part is responsible for reading the data members of the class from the binary stream.
|
|
64
|
+
|
|
65
|
+
### Generate information tree
|
|
66
|
+
|
|
67
|
+
`uproot` can read these structure information from the ROOT file, but not in tree format. So the first step is to generate an information tree from the ROOT file. The information tree is a nested structure that contains the data members of the class, including types, names and children if any.
|
|
68
|
+
|
|
69
|
+
### Construct C++ readers
|
|
70
|
+
|
|
71
|
+
According to the information tree, we can instantiate C++ readers and combine them into a tree structure. The top reader drives its sub-readers to read data recursively. After the reading process,
|
|
72
|
+
readers obtain the results from their sub-readers recursively, then the top reader returns the final result.
|
|
73
|
+
|
|
74
|
+
### Reconstruct data to `awkward` array
|
|
75
|
+
|
|
76
|
+
Since embedding arrays together into `awkward` array in C++ is not straightforward, we left this task to Python. After the C++ reader returns the result, we can reconstruct the data into `awkward` array according to the information tree.
|
|
77
|
+
|
|
78
|
+
## Predefined readers
|
|
79
|
+
|
|
80
|
+
`uproot-custom` provides some predefined readers for common ROOT classes:
|
|
81
|
+
|
|
82
|
+
| Reader | Description |
|
|
83
|
+
|--------------------|-------------|
|
|
84
|
+
| BasicTypeReader<T> | Reads basic types like `int`, `float`, `double`, etc. |
|
|
85
|
+
| TObjectReader | Skip `TObject` header when reading classes that inherit from `TObject`. |
|
|
86
|
+
| TStringReader | Reads `TString` |
|
|
87
|
+
| STLSeqReader | Reads `std::vector`, `std::array`, etc. |
|
|
88
|
+
| STLMapReader | Reads `std::map`, `std::unordered_map`, etc. |
|
|
89
|
+
| STLStringReader | Reads `std::string` |
|
|
90
|
+
| TArrayReader<T> | Reads `TArray` types like `TArrayI`, `TArrayF`, `TArrayD`, etc. |
|
|
91
|
+
| ObjectReader | Reads custom classes that inherit from `TObject`. |
|
|
92
|
+
| CArrayReader | Reads C-style arrays like `int[]` |
|
|
93
|
+
| EmptyReader | A reader that does nothing. Some branches may not have any data, and the information of the corresponding class will not be stored in the ROOT file. In this case, `EmptyReader` is used to skip the branch. |
|
|
94
|
+
|
|
95
|
+
## Implement your own `Reader`
|
|
96
|
+
|
|
97
|
+
### Full example
|
|
98
|
+
|
|
99
|
+
A complete example of how to impolement your own readers is available in the `example` directory of this repository.
|
|
100
|
+
|
|
101
|
+
### Pre-requisites
|
|
102
|
+
|
|
103
|
+
Make sure you have `GCC>13.1`/`Clang>=16.0.0`/`MSVC>=19.31`, `cmake` installed on your system.
|
|
104
|
+
|
|
105
|
+
1. Create a Python project and install `uproot-custom`:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
mkdir my_reader
|
|
109
|
+
cd my_reader
|
|
110
|
+
python3 -m venv .venv
|
|
111
|
+
source .venv/bin/activate
|
|
112
|
+
pip install uproot-custom
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
2. Create a `pyproject.toml` file in the root directory of your project:
|
|
116
|
+
|
|
117
|
+
```toml
|
|
118
|
+
[build-system]
|
|
119
|
+
requires = ["scikit-build-core>=0.11", "pybind11>=2.10.0", "uproot-custom"]
|
|
120
|
+
build-backend = "scikit_build_core.build"
|
|
121
|
+
|
|
122
|
+
[project]
|
|
123
|
+
name = "my-reader"
|
|
124
|
+
requires-python = ">=3.9"
|
|
125
|
+
dependencies = ["uproot-custom"]
|
|
126
|
+
version = "0.1.0"
|
|
127
|
+
|
|
128
|
+
[tool.scikit-build]
|
|
129
|
+
wheel.packages = ["my_reader"]
|
|
130
|
+
build-dir = "build/{wheel_tag}"
|
|
131
|
+
cmake.source-dir = "cpp"
|
|
132
|
+
cmake.build-type = "Debug" # Comment for release builds
|
|
133
|
+
|
|
134
|
+
[tool.black]
|
|
135
|
+
exclude = "/(build|dist|env|.git|.tox|.eggs|.venv)/"
|
|
136
|
+
line-length = 95
|
|
137
|
+
target-version = ['py39', 'py310', 'py311', 'py312', 'py313']
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
you can change the `name`, `version`, and other fields as you like.
|
|
141
|
+
|
|
142
|
+
### Reader interface
|
|
143
|
+
|
|
144
|
+
For a custom `Reader`, a C++ part and a Python part are both required.
|
|
145
|
+
|
|
146
|
+
For C++ part, the constructor must inherit from `IElementReader`, and these methods must be implemented:
|
|
147
|
+
- `void read(BinaryBuffer& buffer)`: Read data from the binary buffer.
|
|
148
|
+
- `py::object data() const`: Return the data as a Python object. You can return anything defined in `pybind11`, such as `py::tuple`, `py::list`, `py::array_t`, etc.
|
|
149
|
+
|
|
150
|
+
For Python part, the class must inherit from `uproot_custom.BaseReader` and implement the following class methods:
|
|
151
|
+
|
|
152
|
+
- `gen_tree_config`: Generate a configuration dictionary for the reader based on the information tree. It should return a dictionary if you want your reader to be used, otherwise return `None`.
|
|
153
|
+
- `get_cpp_reader`: Identify the tree configuration and return the C++ reader instance if it matches, otherwise return `None`.
|
|
154
|
+
- `reconstruct_array`: Reconstruct the raw data to an `awkward` array according to the tree configuration.
|
|
155
|
+
|
|
156
|
+
### Implement the C++ reader
|
|
157
|
+
|
|
158
|
+
1. Create a `cpp` directory in the root directory of your project, and create a `my_reader.cc` file in it.
|
|
159
|
+
|
|
160
|
+
2. In `my_reader.cc`, include the necessary headers and implement your reader class. For example:
|
|
161
|
+
|
|
162
|
+
```cpp
|
|
163
|
+
#include "uproot-custom/uproot-custom.hh"
|
|
164
|
+
using namespace uproot;
|
|
165
|
+
|
|
166
|
+
class MyReader : public IElementReader {
|
|
167
|
+
public:
|
|
168
|
+
// Must at least receive a name
|
|
169
|
+
MyReader( std::string name )
|
|
170
|
+
: IElementReader(name), m_data( std::make_shared<std::vector<int>>() ) {}
|
|
171
|
+
|
|
172
|
+
// Implement these methods
|
|
173
|
+
void read( BinaryBuffer& buffer ) {
|
|
174
|
+
// Read data from the buffer
|
|
175
|
+
// Implement your reading logic here
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
py::object data() const {
|
|
179
|
+
// Return the data as a Python object
|
|
180
|
+
return make_array( m_data );
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private:
|
|
184
|
+
const std::string m_name;
|
|
185
|
+
std::shared_ptr<std::vector<int>> m_data; // Example data member
|
|
186
|
+
};
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
then declare the C++ module in the same file:
|
|
190
|
+
|
|
191
|
+
```cpp
|
|
192
|
+
PYBIND11_MODULE( my_reader_cpp, m ) {
|
|
193
|
+
register_reader<MyReader>(m, "MyReader");
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
if the constructor requires more parameters, register it with the constructor signature (except the name):
|
|
198
|
+
|
|
199
|
+
```cpp
|
|
200
|
+
// Constructor signature:
|
|
201
|
+
MyReader( std::string name, bool param1, std::vector<IElementReader> sub_readers )
|
|
202
|
+
|
|
203
|
+
// Register the reader with the constructor signature:
|
|
204
|
+
PYBIND11_MODULE( my_reader_cpp, m ) {
|
|
205
|
+
register_reader<MyReader, bool, std::vector<IElementReader>>(m, "MyReader");
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
> [!IMPORTANT]
|
|
210
|
+
> Use `std::shared_ptr` for data members in your reader class, as `uproot-custom` will manage the memory of the data members. This is important to avoid memory leaks and ensure proper cleanup.
|
|
211
|
+
|
|
212
|
+
3. Create a `CMakeLists.txt` file in `cpp` directory:
|
|
213
|
+
|
|
214
|
+
```cmake
|
|
215
|
+
cmake_minimum_required(VERSION 3.20)
|
|
216
|
+
|
|
217
|
+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
|
|
218
|
+
cmake_policy(SET CMP0148 NEW)
|
|
219
|
+
endif()
|
|
220
|
+
|
|
221
|
+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
222
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
223
|
+
|
|
224
|
+
project(${SKBUILD_PROJECT_NAME}
|
|
225
|
+
VERSION ${SKBUILD_PROJECT_VERSION}
|
|
226
|
+
LANGUAGES CXX
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
set(PYBIND11_NEWPYTHON ON)
|
|
230
|
+
find_package(pybind11 REQUIRED)
|
|
231
|
+
find_package(uproot-custom REQUIRED)
|
|
232
|
+
|
|
233
|
+
pybind11_add_module(my_reader_cpp
|
|
234
|
+
my_reader.cc
|
|
235
|
+
# Add other source files here if needed
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
target_link_libraries(my_reader_cpp PRIVATE uproot-custom)
|
|
239
|
+
|
|
240
|
+
if(DEFINED SKBUILD_PROJECT_NAME)
|
|
241
|
+
install(
|
|
242
|
+
TARGETS my_reader_cpp
|
|
243
|
+
LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}
|
|
244
|
+
)
|
|
245
|
+
endif()
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Implement the Python reader
|
|
249
|
+
|
|
250
|
+
1. Create a `my_reader` directory in the root directory of your project, and create a `__init__.py` file in it.
|
|
251
|
+
|
|
252
|
+
2. In `__init__.py`, import the C++ module and implement your Python reader class:
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from . import my_reader_cpp as _cpp
|
|
256
|
+
from uproot_custom import BaseReader
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class MyReader(BaseReader):
|
|
260
|
+
@classmethod
|
|
261
|
+
def gen_tree_config(
|
|
262
|
+
cls,
|
|
263
|
+
top_type_name: str,
|
|
264
|
+
cls_streamer_info: dict,
|
|
265
|
+
all_streamer_info: dict,
|
|
266
|
+
item_path: str = "",
|
|
267
|
+
) -> dict | None:
|
|
268
|
+
"""
|
|
269
|
+
Identify the node in the information tree,
|
|
270
|
+
return the configuration dictionary if the node is matched,
|
|
271
|
+
otherwise return None.
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
@classmethod
|
|
275
|
+
def get_cpp_reader(cls, tree_config) -> _cpp.MyReader | None:
|
|
276
|
+
"""
|
|
277
|
+
Identify the tree_config,
|
|
278
|
+
if it is matched, return the C++ reader instance,
|
|
279
|
+
otherwise return None.
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
@classmethod
|
|
283
|
+
def reconstruct_array(cls, raw_data, tree_config):
|
|
284
|
+
"""
|
|
285
|
+
Reconstruct the raw data to an `awkward` array according to the tree_config.
|
|
286
|
+
"""
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
> ![NOTE]
|
|
290
|
+
> The `@classmethod` is not necesarry, but when a regular member method is used, you should pass the instance of the class to `registered_readers`.
|
|
291
|
+
|
|
292
|
+
### Register the reader
|
|
293
|
+
|
|
294
|
+
#### Register branch path
|
|
295
|
+
|
|
296
|
+
The default interpretation `uproot_custom.AsCustom` needs to know which branch to read with custom readers. You can export the branch path with:
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
import uproot
|
|
300
|
+
from uproot_custom import regularize_object_path
|
|
301
|
+
|
|
302
|
+
f = uproot.open("my_file.root")
|
|
303
|
+
branch = f["path/to/my_branch"]
|
|
304
|
+
|
|
305
|
+
print(regularize_object_path(branch.object_path))
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
This will print the regularized object path like `/my_tree:my_branch`. Then you can add it to the `AsCustom.target_branches` set:
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
from uproot_custom import AsCustom
|
|
312
|
+
|
|
313
|
+
AsCustom.target_branches.add("your-branch-path")
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
#### Register the reader
|
|
317
|
+
|
|
318
|
+
To let `uproot_custom.AsCustom` know your reader, you need to register it:
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
from uproot_custom import registered_readers
|
|
322
|
+
from my_reader import MyReader
|
|
323
|
+
|
|
324
|
+
registered_readers.add(MyReader)
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Then you can use `uproot` to read the custom class as usual.
|
|
328
|
+
|
|
329
|
+
> [!TIP]
|
|
330
|
+
> It is recommended to do the registration in your project `__init__.py`, so that you can use your custom reader as long as you import your project.
|