Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #432 from scikit-hep/issue-431
Browse files Browse the repository at this point in the history
Add handler for `map<string,string>` to streamed objects
  • Loading branch information
jpivarski authored Jan 20, 2020
2 parents 8f93f04 + ec7dba6 commit 876f5d1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Binary file added tests/samples/issue431.root
Binary file not shown.
7 changes: 5 additions & 2 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def test_issue429(self):
array = branch.array(uproot.asdtype(dtype + [("padding", "S4")]))
assert (array["padding"] == b"\xff\xff\xff\xff").all()

def test_issue431(self):
file = uproot.open("tests/samples/issue431.root")
head = file["Head"]
assert head._map_3c_string_2c_string_3e_ == {b'DAQ': b'394', b'PDF': b'4 58', b'XSecFile': b'', b'can': b'0 1027 888.4', b'can_user': b'0.00 1027.00 888.40', b'coord_origin': b'0 0 0', b'cut_in': b'0 0 0 0', b'cut_nu': b'100 1e+08 -1 1', b'cut_primary': b'0 0 0 0', b'cut_seamuon': b'0 0 0 0', b'decay': b'doesnt happen', b'detector': b'NOT', b'drawing': b'Volume', b'end_event': b'', b'genhencut': b'2000 0', b'genvol': b'0 1027 888.4 2.649e+09 100000', b'kcut': b'2', b'livetime': b'0 0', b'model': b'1 2 0 1 12', b'muon_desc_file': b'', b'ngen': b'0.1000E+06', b'norma': b'0 0', b'nuflux': b'0 3 0 0.500E+00 0.000E+00 0.100E+01 0.300E+01', b'physics': b'GENHEN 7.2-220514 181116 1138', b'seed': b'GENHEN 3 305765867 0 0', b'simul': b'JSirene 11012 11/17/18 07', b'sourcemode': b'diffuse', b'spectrum': b'-1.4', b'start_run': b'1', b'target': b'isoscalar', b'usedetfile': b'false', b'xlat_user': b'0.63297', b'xparam': b'OFF', b'zed_user': b'0.00 3450.00'}

def test_issue434(self):
f = uproot.open("tests/samples/issue434.root")
fromdtype = [("pmt", "u1"), ("tdc", "<u4"), ("tot", "u1")]
Expand All @@ -412,5 +417,3 @@ def test_issue438_accessing_memory_mapped_objects_outside_of_context_raises(self
assert 4 == len(a[0])
with pytest.raises(IOError):
len(b[0])


13 changes: 13 additions & 0 deletions uproot/rootio.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,17 @@ def _nametitle(source, cursor):
_endcheck(start, cursor, cnt)
return name, title

def _mapstrstr(source, cursor):
cursor.skip(12)
size = cursor.field(source, _mapstrstr._int32)
cursor.skip(6)
keys = [cursor.string(source) for i in range(size)]
cursor.skip(6)
values = [cursor.string(source) for i in range(size)]
return dict(zip(keys, values))

_mapstrstr._int32 = struct.Struct('>I')

def _readobjany(source, cursor, context, parent, asclass=None):
# TBufferFile::ReadObjectAny()
# https://github.com/root-project/root/blob/c4aa801d24d0b1eeb6c1623fd18160ef2397ee54/io/io/src/TBufferFile.cxx#L2684
Expand Down Expand Up @@ -854,6 +865,8 @@ def _defineclasses(streamerinfos, classes):
code.append(" cursor.skip(6)")
code.append(" self._{0} = cursor.array(source, cursor.field(source, self._int32), '>f8')".format(_safename(element._fName)))
fields.append(_safename(element._fName))
elif element._fTypeName == b"map<string,string>":
code.append(" self._{0} = _mapstrstr(source, cursor)".format(_safename(element._fName)))
else:
code.append(" _raise_notimplemented({0}, {1}, source, cursor)".format(repr(element.__class__.__name__), repr(repr(element.__dict__))))
recarray.append("raise ValueError('not a recarray')")
Expand Down
2 changes: 1 addition & 1 deletion uproot/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import re

__version__ = "3.11.0"
__version__ = "3.11.1"
version = __version__
version_info = tuple(re.split(r"[-\.]", __version__))

Expand Down

0 comments on commit 876f5d1

Please sign in to comment.