diff --git a/src/uproot/reading.py b/src/uproot/reading.py index 96606d14a..2350c1c13 100644 --- a/src/uproot/reading.py +++ b/src/uproot/reading.py @@ -1106,6 +1106,16 @@ def class_named(self, classname, version=None): if len(streamers) == 0 and self._custom_classes is not None: cls = uproot.classes.get(classname) + if ( + cls is None + and re.match(r"(std\s*::\s*)?(vector|map|set|bitset)\s*<", classname) + is not None + ): + cls = uproot.interpretation.identify.parse_typename(classname) + cls._header = False + + return cls + if cls is None: if len(streamers) == 0: unknown_cls = uproot.unknown_classes.get(classname) @@ -2494,7 +2504,7 @@ def get(self): start_cursor = cursor.copy() context = {"breadcrumbs": (), "TKey": self} - if self._fClassName == "string": + if re.match(r"(std\s*::\s*)?string", self._fClassName): return cursor.string(chunk, context) cls = self._file.class_named(self._fClassName) diff --git a/tests/test_1180_read_free_floating_vector_issue_1179.py b/tests/test_1180_read_free_floating_vector_issue_1179.py new file mode 100644 index 000000000..c854c1502 --- /dev/null +++ b/tests/test_1180_read_free_floating_vector_issue_1179.py @@ -0,0 +1,25 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE + +import pytest +import uproot +import os +import numpy as np + +ROOT = pytest.importorskip("ROOT") + + +def test_read_free_floating_vector(tmp_path): + newfile = os.path.join(tmp_path, "test_freevec.root") + f = ROOT.TFile(newfile, "recreate") + a = np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float64) + c = np.array([0, 1, 4, 5, 6, 7, 8, 9], dtype=np.uint32) + avec = ROOT.std.vector("double")(a) + bvec = ROOT.std.vector("unsigned int")(c) + f.WriteObject(avec, "avec") + f.WriteObject(bvec, "bvec") + f.Write() + f.Close() + + with uproot.open(newfile) as f: + assert f["avec"].tolist() == [1.0, 2.0, 3.0, 4.0] + assert f["bvec"].tolist() == [0, 1, 4, 5, 6, 7, 8, 9]