Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
[build-system]
build-backend = "scikit_build_core.build"
requires = ["scikit-build-core", "pybind11==3.0.*", "uproot-custom==2.1.*"]
requires = ["scikit-build-core", "pybind11==3.0.*", "uproot-custom>=2.1.1,<2.2"]

[dependency-groups]
dev = ["black", "pytest", "pyarrow", "pandas", "build", "twine", "pre-commit"]
dev = [
"black",
"pytest",
"pyarrow",
"pandas",
"build",
"twine",
"pre-commit",
"ipykernel"
]
docs = ["mkdocs", "mkdocs-material", "mkdocstrings", "mkdocstrings-python"]

[project]
Expand All @@ -28,7 +37,7 @@ dependencies = [
"awkward",
"numba",
"vector!=1.7.0", # TODO: remove this constraint when vector 1.7.0 is fixed
"uproot-custom==2.1.*"
"uproot-custom>=2.1.1,<2.2"
]
description = "Unofficial Python module for BES3"
dynamic = ["version"]
Expand Down
9 changes: 9 additions & 0 deletions src/pybes3/besio/cpp/root_io.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class Bes3TObjArrayReader : public IReader {
, m_offsets( make_shared_vector<uint32_t>( 1, 0 ) ) {}

void read( BinaryBuffer& bparser ) override {
debug_printf( "Bes3TObjArrayReader %s: reading...\n", m_name.c_str() );
debug_printf( bparser );

bparser.skip_fNBytes();
bparser.skip_fVersion();
bparser.skip_fVersion();
Expand All @@ -37,7 +40,13 @@ class Bes3TObjArrayReader : public IReader {
m_offsets->push_back( m_offsets->back() + fSize );
for ( uint32_t i = 0; i < fSize; i++ )
{

bparser.skip_obj_header();

debug_printf( "Bes3TObjArrayReader %s: skipped obj header of %d element\n",
m_name.c_str(), i );
debug_printf( bparser );

m_element_reader->read( bparser );
}
}
Expand Down
46 changes: 43 additions & 3 deletions src/pybes3/besio/root_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import uproot.behaviors.TBranch
import uproot.extras
import uproot.interpretation
import uproot_custom
import uproot_custom.cpp
from uproot_custom import (
AnyClassFactory,
AsCustom,
BaseObjectFactory,
EmptyFactory,
Factory,
GroupFactory,
PrimitiveFactory,
build_factory,
regularize_object_path,
Expand Down Expand Up @@ -109,7 +110,7 @@ def build_factory(

return cls(
name=cur_streamer_info["fName"],
element_factory=BaseObjectFactory(
element_factory=AnyClassFactory(
name=obj_typename,
sub_factories=sub_factories,
),
Expand All @@ -136,6 +137,44 @@ def make_awkward_form(self):
return awkward.forms.ListOffsetForm("i64", element_form)


class Bes3BaseObjectFactory(GroupFactory):
@classmethod
def priority(cls):
return 40

@classmethod
def build_factory(
cls,
top_type_name,
cls_streamer_info,
all_streamer_info,
item_path,
**kwargs,
):
if top_type_name != "BASE":
return None

fType = cls_streamer_info["fType"]
if fType != 0:
return None

# limit to bes3 relevant branches
if all(k not in item_path for k in bes3_branch2types.keys()):
return None

fName = cls_streamer_info["fName"]
sub_streamers: list[dict] = all_streamer_info[fName]
sub_factories = [build_factory(s, all_streamer_info, item_path) for s in sub_streamers]

return cls(name=fName, sub_factories=sub_factories)

def build_cpp_reader(self):
sub_readers = [s.build_cpp_reader() for s in self.sub_factories]
# In TObjArray, base class always contains fNBytes+fVersion header,
# so use `AnyClassReader` instead of `GroupReader` to read it.
return uproot_custom.cpp.AnyClassReader(self.name, sub_readers)


class Bes3CgemClusterColFactory(Factory):
@classmethod
def priority(cls):
Expand Down Expand Up @@ -265,6 +304,7 @@ def make_awkward_content(self, raw_data: np.ndarray):
Bes3TObjArrayFactory,
Bes3SymMatrixArrayFactory,
Bes3CgemClusterColFactory,
Bes3BaseObjectFactory,
}


Expand Down
Loading