-
Notifications
You must be signed in to change notification settings - Fork 84
feat: Memberwise for std::pair<> #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
3faa082
b43150f
a91045c
c771290
49907f0
b0df815
54a85df
0f559bf
5d6867d
d609dc5
40c7947
e3640e3
ccdf476
a09ae2c
e763611
4d10b2f
2d714b0
3801d06
630b0e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -792,19 +792,45 @@ def read(self, chunk, cursor, context, file, selffile, parent, header=True): | |
else: | ||
is_memberwise = False | ||
|
||
# note: self._values can also be a NumPy dtype, and not necessarily a class (e.g. type(self._values)==type) | ||
_value_typename = _content_typename(self._values) | ||
if is_memberwise: | ||
raise NotImplementedError( | ||
"""memberwise serialization of {0} | ||
in file {1}""".format( | ||
type(self).__name__, selffile.file_path | ||
# let's hard-code in logic for std::pair<T1,T2> for now | ||
if not _value_typename.startswith("pair"): | ||
raise NotImplementedError( | ||
"""memberwise serialization of {0}({1}) | ||
in file {2}""".format( | ||
type(self).__name__, _value_typename, selffile.file_path | ||
) | ||
) | ||
) | ||
|
||
length = cursor.field(chunk, _stl_container_size, context) | ||
# there's extra stuff, maybe? | ||
_num_memberwise_bytes = cursor.field(chunk, _stl_container_size, context) | ||
_something_else = cursor.field(chunk, struct.Struct(">H"), context) | ||
|
||
# length is number of elements in vector | ||
length = cursor.field(chunk, _stl_container_size, context) | ||
|
||
model = self._values.new_class(file, "max") | ||
kratsg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# make a shell | ||
values = numpy.empty(length, dtype=_stl_object_type) | ||
for i in uproot._util.range(length): | ||
values[i] = model.read( | ||
chunk, cursor, {**context, "reading": False}, file, selffile, parent | ||
) | ||
|
||
|
||
# memberwise reading! | ||
for member_index in uproot._util.range(len(values[0].member_names)): | ||
for i in uproot._util.range(length): | ||
values[i].read_member_n(chunk, cursor, context, file, member_index) | ||
else: | ||
length = cursor.field(chunk, _stl_container_size, context) | ||
|
||
values = _read_nested( | ||
self._values, length, chunk, cursor, context, file, selffile, parent | ||
) | ||
|
||
values = _read_nested( | ||
self._values, length, chunk, cursor, context, file, selffile, parent | ||
) | ||
out = STLVector(values) | ||
|
||
if self._header and header: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -760,30 +760,33 @@ def read(cls, chunk, cursor, context, file, selffile, parent, concrete=None): | |
old_breadcrumbs = context.get("breadcrumbs", ()) | ||
context["breadcrumbs"] = old_breadcrumbs + (self,) | ||
|
||
self.hook_before_read(chunk=chunk, cursor=cursor, context=context, file=file) | ||
|
||
self.read_numbytes_version(chunk, cursor, context) | ||
|
||
if ( | ||
issubclass(cls, VersionedModel) | ||
and self._instance_version != classname_version(cls.__name__) | ||
and self._instance_version is not None | ||
): | ||
correct_cls = file.class_named(self.classname, self._instance_version) | ||
if classname_version(correct_cls.__name__) != classname_version( | ||
cls.__name__ | ||
if context.get("reading", True): | ||
self.hook_before_read( | ||
chunk=chunk, cursor=cursor, context=context, file=file | ||
) | ||
|
||
|
||
self.read_numbytes_version(chunk, cursor, context) | ||
|
||
if ( | ||
issubclass(cls, VersionedModel) | ||
and self._instance_version != classname_version(cls.__name__) | ||
and self._instance_version is not None | ||
): | ||
cursor.move_to(self._cursor.index) | ||
context["breadcrumbs"] = old_breadcrumbs | ||
return correct_cls.read( | ||
chunk, | ||
cursor, | ||
context, | ||
file, | ||
selffile, | ||
parent, | ||
concrete=concrete, | ||
) | ||
correct_cls = file.class_named(self.classname, self._instance_version) | ||
if classname_version(correct_cls.__name__) != classname_version( | ||
cls.__name__ | ||
): | ||
cursor.move_to(self._cursor.index) | ||
context["breadcrumbs"] = old_breadcrumbs | ||
return correct_cls.read( | ||
chunk, | ||
cursor, | ||
context, | ||
file, | ||
selffile, | ||
parent, | ||
concrete=concrete, | ||
) | ||
|
||
if context.get("in_TBranch", False): | ||
if self._num_bytes is None and self._instance_version != self.class_version: | ||
|
@@ -793,15 +796,16 @@ def read(cls, chunk, cursor, context, file, selffile, parent, concrete=None): | |
elif self._instance_version == 0: | ||
cursor.skip(4) | ||
|
||
self.hook_before_read_members( | ||
chunk=chunk, cursor=cursor, context=context, file=file | ||
) | ||
if context.get("reading", True): | ||
self.hook_before_read_members( | ||
chunk=chunk, cursor=cursor, context=context, file=file | ||
) | ||
|
||
self.read_members(chunk, cursor, context, file) | ||
self.read_members(chunk, cursor, context, file) | ||
|
||
self.hook_after_read_members( | ||
chunk=chunk, cursor=cursor, context=context, file=file | ||
) | ||
self.hook_after_read_members( | ||
chunk=chunk, cursor=cursor, context=context, file=file | ||
) | ||
|
||
self.check_numbytes(chunk, cursor, context) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This portion that we're at right now looks like
Unclear what the first 6 bytes are here, but the last 4 seem to be number of elements in the vector (
length
) in the line below. I assumed it might be 4 bytes / 2 bytes but still not sure what they're meant to match up with.