2

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!

1 Answers1

1

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]))
Jim Pivarski
  • 5,568
  • 2
  • 35
  • 47
  • Thanks! However, maybe I wasn't clear. I need just standard array writing (so far), no jagged arrays. I understand that jagged arrays functionality can be used for constant size arrays, but perhaps something simpler for standard arrays? – Lech Wiktor Piotrowski Dec 19 '20 at 15:24
  • If the arrays are not jagged, then they're just multidimensional NumPy arrays. The `dtype` for such arrays can be constructed with a tuple: `np.dtype((np.float64, 5))` for double-precision arrays with inner length `5`. – Jim Pivarski Dec 20 '20 at 17:30
  • Thanks! A little bit out of topic, but when do you expect writing capabilities in uproot4, and are uproot3 scripts going to work with uproot4? – Lech Wiktor Piotrowski Dec 20 '20 at 20:53
  • Writing capabilities in Uproot 4: sometime next year, maybe spring. Scripts based on Uproot 3 will not work with Uproot 4 because interface has changed. – Jim Pivarski Dec 21 '20 at 21:05