uproot

Can uproot3 write TBranches containing arrays?


In uproot 3 documentation there is information, that uproot can write only branches containing 1 value per entry. On the other hand, I can see some topics on uproot Github regarding writing jagged arrays, etc. So, I would like to make sure: can uproot write TBranches containing arrays to a TTree? If so, is it documented anywhere?

Thanks!


Solution

  • This will be better documented when it's ported to Uproot 4, but the best documentation we have on writing jagged arrays in Uproot 3 right now is the pull request and associated issues (all linked to each other):

    https://github.com/scikit-hep/uproot3/pull/477

    Here is an example from the tests:

    import uproot3
    import awkward0
    
    a = awkward0.fromiter([[0],
                           [1, 2],
                           [10, 11, 12]])
    
    with uproot3.recreate(filename, compression=None) as f:
        f["t"] = uproot3.newtree({
            "branch": uproot3.newbranch(numpy.dtype(">i4"), size="n")
        })
        f["t"].extend({"branch": a, "n": [1, 2, 3]})
    
    f = ROOT.TFile.Open(filename)
    tree = f.Get("t")
    for i, event in enumerate(tree):
        assert(numpy.all([x for x in event.branch] == a[i]))