pythonroot-frameworkuproot

Uproot issue: Trouble making sense of a particular 'branch'


I have a root file open in python as such:

file = uproot.open('C:\\Users\\me\\Documents\\test.root')
print(file.keys())
[b'evts;1', b'miscAccum;1', b'cal;1', b'configstr;1', b'time;1', b'Plugs;1', b'acc;1']
print(file[b'Plugs'].keys())
[b'veto;1', b'miscAccum;1', b'calfine;1']

All good but if I try to explore the time branch with print(file[b'time'].keys()) I get an error saying

'TVectorT_3c_double_3e_' object has no attribute 'keys'

How can I explore the value(s) within this branch?


Solution

  • Directories (uproot.ReadOnlyDirectory) and TTrees (uproot.TTree) are objects that can initiate more reading, so they are navigable as Mappings with keys() and square-bracket syntax (__getitem__).

    This object evidently has class type TVectorT_3c_double_3e_ (a Python model, uproot.Model, of C++ class TVectorT<double>). Some objects like this have custom "behaviors," which are user-friendly properties and methods. For example, the model of TParameter<double> has a value property (see uproot.behaviors.TParameter). This one does not.

    When Uproot reads an object and does not have custom behaviors, you can still access its C++ private member data through the uproot.Model.member method or the uproot.Model.all_members property (dict). In fact, these are how high-level behaviors get implemented: the reading of C++ private member data is automatic, but humans have to design high-level APIs by writing functions to access them in a more user-friendly way, something that's happened for TParameter<double> but not TVectorT<double> yet.

    (To first order, ROOT has infinitely many classes.)

    So, to be explicit, do

    file["time"].all_members
    

    and see what you get.


    One other thing, unrelated to that: I noticed that you're using Uproot 3 because all of the keys are bytes instead of str. Since you're not maintaining a legacy script, you should upgrade to Uproot 4. Since Dec 2020, Uproot 4 is just "uproot":

    pip install uproot awkward
    

    (Usually, you want Awkward Array as well, so I included that in the pip-install. You might need to pip uninstall the versions you have now to get a clean slate.)

    The documentation links and interface I described above is all for Uproot 4.