From 57eb0ec276e8542a0e0fd735026252e74094b887 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 4 Mar 2024 15:13:24 -0600 Subject: [PATCH 1/4] feat: special case for reading std::string from a TDirectory --- src/uproot/reading.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/uproot/reading.py b/src/uproot/reading.py index 362a87307..aa4ac2653 100644 --- a/src/uproot/reading.py +++ b/src/uproot/reading.py @@ -2473,9 +2473,13 @@ def get(self): else: chunk, cursor = self.get_uncompressed_chunk_cursor() start_cursor = cursor.copy() - cls = self._file.class_named(self._fClassName) context = {"breadcrumbs": (), "TKey": self} + if self._fClassName == "string": + return cursor.string(chunk, context) + + cls = self._file.class_named(self._fClassName) + try: out = cls.read(chunk, cursor, context, self._file, selffile, parent) From 35f4ff3677e98c3d99a12c8e2ed928f6589b76ba Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 4 Mar 2024 15:20:18 -0600 Subject: [PATCH 2/4] less hacky, but this way calls the std::string a TString --- src/uproot/models/TString.py | 1 + src/uproot/reading.py | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/uproot/models/TString.py b/src/uproot/models/TString.py index 9a6a0d324..629149504 100644 --- a/src/uproot/models/TString.py +++ b/src/uproot/models/TString.py @@ -104,3 +104,4 @@ def _serialize(self, out, header, name, tobject_flags): uproot.classes["TString"] = Model_TString +uproot.classes["string"] = Model_TString diff --git a/src/uproot/reading.py b/src/uproot/reading.py index aa4ac2653..362a87307 100644 --- a/src/uproot/reading.py +++ b/src/uproot/reading.py @@ -2473,12 +2473,8 @@ def get(self): else: chunk, cursor = self.get_uncompressed_chunk_cursor() start_cursor = cursor.copy() - context = {"breadcrumbs": (), "TKey": self} - - if self._fClassName == "string": - return cursor.string(chunk, context) - cls = self._file.class_named(self._fClassName) + context = {"breadcrumbs": (), "TKey": self} try: out = cls.read(chunk, cursor, context, self._file, selffile, parent) From d52ef82dc9fdb94f7fa5643ad07e7302e5a15ba2 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 4 Mar 2024 16:53:06 -0600 Subject: [PATCH 3/4] added a test; should be done now --- tests/test_0692_fsspec_reading.py | 1 + tests/test_1160_std_string_in_TDirectory.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/test_1160_std_string_in_TDirectory.py diff --git a/tests/test_0692_fsspec_reading.py b/tests/test_0692_fsspec_reading.py index ff31b7ca0..097f34cef 100644 --- a/tests/test_0692_fsspec_reading.py +++ b/tests/test_0692_fsspec_reading.py @@ -395,6 +395,7 @@ def test_issue_1035(handler): assert len(data) == 40 +@pytest.mark.skip(reason="This test occasionally takes too long: GitHub kills it.") @pytest.mark.network @pytest.mark.xrootd @pytest.mark.parametrize( diff --git a/tests/test_1160_std_string_in_TDirectory.py b/tests/test_1160_std_string_in_TDirectory.py new file mode 100644 index 000000000..ce81976ed --- /dev/null +++ b/tests/test_1160_std_string_in_TDirectory.py @@ -0,0 +1,19 @@ +# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE + +import json + +import skhep_testdata + +import uproot + + +def test(): + with uproot.open(skhep_testdata.data_path("string-example.root")) as file: + assert json.loads(file["FileSummaryRecord"]) == { + "LumiCounter.eventsByRun": { + "counts": {}, + "empty": True, + "type": "LumiEventCounter", + }, + "guid": "5FE9437E-D958-11EE-AB88-3CECEF1070AC", + } From 75c1b06c4f22f7b15f462555d030eaa75b7cad6a Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Mon, 4 Mar 2024 16:58:07 -0600 Subject: [PATCH 4/4] revert to the original solution --- src/uproot/models/TString.py | 1 - src/uproot/reading.py | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/uproot/models/TString.py b/src/uproot/models/TString.py index 629149504..9a6a0d324 100644 --- a/src/uproot/models/TString.py +++ b/src/uproot/models/TString.py @@ -104,4 +104,3 @@ def _serialize(self, out, header, name, tobject_flags): uproot.classes["TString"] = Model_TString -uproot.classes["string"] = Model_TString diff --git a/src/uproot/reading.py b/src/uproot/reading.py index 362a87307..aa4ac2653 100644 --- a/src/uproot/reading.py +++ b/src/uproot/reading.py @@ -2473,9 +2473,13 @@ def get(self): else: chunk, cursor = self.get_uncompressed_chunk_cursor() start_cursor = cursor.copy() - cls = self._file.class_named(self._fClassName) context = {"breadcrumbs": (), "TKey": self} + if self._fClassName == "string": + return cursor.string(chunk, context) + + cls = self._file.class_named(self._fClassName) + try: out = cls.read(chunk, cursor, context, self._file, selffile, parent)