-
Hi all, I have a question which is related to the one I posted in the ROOT forum, see https://root-forum.cern.ch/t/ttime-saved-to-a-ttree-in-root5-and-root6/54031 . So, in short, between ROOT5 and ROOT6, what is written out in ROOT files can be a bit different, in the specific case the To give the possibility to test, I attach two ROOT files, one created with ROOT5.34.36 and one with ROOT6.24.08. Here I use a class called So when I try reading the In [1]: import uproot
In [2]: uproot.__version__
Out[2]: '4.3.7'
In [3]: rootf5 = uproot.open("example_root5.root")
In [4]: rootf5["Events"]["MTime/fTime/fTime.fMilliSec"].array(library="np")
Out[4]: array([-37390935, -28750935])
In [5]: rootf6 = uproot.open("example_root6.root")
In [6]: rootf6["Events"].keys()
Out[6]:
['MTime',
'MTime/MParContainer',
'MTime/MParContainer/TObject',
'MTime/MParContainer/TObject/fUniqueID',
'MTime/MParContainer/TObject/fBits',
'MTime/fMjd',
'MTime/fTime',
'MTime/fNanoSec']
In [7]: rootf5["Events"]["MTime/fTime"].array(library="np")
Out[7]: {'fTime.fMilliSec': array([-37390935, -28750935])}
In [8]: rootf6["Events"]["MTime/fTime"].array(library="np")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/Software/miniconda3/envs/magic-cta-pipe-analysis-school-2023/lib/python3.8/site-packages/uproot/interpretation/numerical.py in basket_array(self, data, byte_offsets, basket, branch, context, cursor_offset, library)
341 try:
--> 342 output = data.view(dtype).reshape((-1,) + shape)
343 except ValueError as err:
ValueError: When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.
The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
<ipython-input-9-6aec0c18a45a> in <cell line: 1>()
----> 1 rootf6["Events"]["MTime/fTime"].array(library="np")
~/Software/miniconda3/envs/magic-cta-pipe-analysis-school-2023/lib/python3.8/site-packages/uproot/behaviors/TBranch.py in array(self, interpretation, entry_start, entry_stop, decompression_executor, interpretation_executor, array_cache, library)
2206 ranges_or_baskets.append((branch, basket_num, range_or_basket))
2207
-> 2208 _ranges_or_baskets_to_arrays(
2209 self,
2210 ranges_or_baskets,
~/Software/miniconda3/envs/magic-cta-pipe-analysis-school-2023/lib/python3.8/site-packages/uproot/behaviors/TBranch.py in _ranges_or_baskets_to_arrays(hasbranches, ranges_or_baskets, branchid_interpretation, entry_start, entry_stop, decompression_executor, interpretation_executor, library, arrays, update_ranges_or_baskets)
3491
3492 elif isinstance(obj, tuple) and len(obj) == 3:
-> 3493 uproot.source.futures.delayed_raise(*obj)
3494
3495 else:
~/Software/miniconda3/envs/magic-cta-pipe-analysis-school-2023/lib/python3.8/site-packages/uproot/source/futures.py in delayed_raise(exception_class, exception_value, traceback)
34 Raise an exception from a background thread on the main thread.
35 """
---> 36 raise exception_value.with_traceback(traceback)
37
38
~/Software/miniconda3/envs/magic-cta-pipe-analysis-school-2023/lib/python3.8/site-packages/uproot/behaviors/TBranch.py in basket_to_array(basket)
3435 basket_arrays = branchid_arrays[branch.cache_key]
3436
-> 3437 basket_arrays[basket.basket_num] = interpretation.basket_array(
3438 basket.data,
3439 basket.byte_offsets,
~/Software/miniconda3/envs/magic-cta-pipe-analysis-school-2023/lib/python3.8/site-packages/uproot/interpretation/numerical.py in basket_array(self, data, byte_offsets, basket, branch, context, cursor_offset, library)
342 output = data.view(dtype).reshape((-1,) + shape)
343 except ValueError as err:
--> 344 raise ValueError(
345 """basket {} in tree/branch {} has the wrong number of bytes ({}) """
346 """for interpretation {}
ValueError: basket 0 in tree/branch /Events;1:MTime/fTime has the wrong number of bytes (28) for interpretation AsStridedObjects(Model_TTime_v2)
in file example_root6.root In the Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, the structures in the two files are different, but it might be just that the ROOT 5 one was written with full splitting ( >>> import uproot
>>> f5 = uproot.open("example_root5.root")
>>> f6 = uproot.open("example_root6.root")
>>> f5["Events/MTime/fTime"].show()
name | typename | interpretation
---------------------+--------------------------+-------------------------------
fTime | TTime | AsGroup(<TBranchElement 'fTime
fTime.fMilliSec | int64_t | AsDtype('>i8')
>>> f6["Events/MTime/fTime"].show()
name | typename | interpretation
---------------------+--------------------------+-------------------------------
fTime | TTime | AsStridedObjects(Model_TTime_v The The struct doesn't contain anything other than that 64-bit integer ( >>> f6.file.streamer_named("TTime").show()
TTime (v2)
fMilliSec: long long (TStreamerBasicType) When we look at the raw bytes of the first entry in >>> f6["Events/MTime/fTime"].debug_array(0)
array([ 64, 0, 0, 10, 0, 2, 255, 255, 255, 255, 253, 197, 117,
169], dtype=uint8) we see the correct value >>> import numpy as np
>>> np.array([255, 255, 255, 255, 253, 197, 117, 169], "u1").view(">i8")
array([-37390935]) preceded by 6 extra bytes. This is a header for the When Uproot tried to come up with an >>> f6["Events/MTime/fTime"].interpretation.from_dtype
dtype([('fMilliSec', '>i8')]) The interpretation ought to be >>> interp = uproot.AsDtype([("@num_bytes", ">u4"), ("@instance_version", ">u2"), ('fMilliSec', '>i8')])
>>> f6["Events/MTime/fTime"].array(interp, library="np")
array([(1073741834, 2, -37390935), (1073741834, 2, -28750935)],
dtype=[('@num_bytes', '<u4'), ('@instance_version', '<u2'), ('fMilliSec', '<i8')]) from which you can pull out the >>> f6["Events/MTime/fTime"].array(interp, library="np")["fMilliSec"]
array([-37390935, -28750935]) It's always been difficult to figure out the right We could convert this into a bug report (the In the meantime, though, you can pass the |
Beta Was this translation helpful? Give feedback.
Yes, the structures in the two files are different, but it might be just that the ROOT 5 one was written with full splitting (
splitLevel=99
) and the ROOT 6 one was written without splitting (splitLevel=0
).