Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triply jagged branches #119

Open
aminnj opened this issue Sep 28, 2021 · 2 comments
Open

Triply jagged branches #119

aminnj opened this issue Sep 28, 2021 · 2 comments
Labels
future good first issue Good for newcomers

Comments

@aminnj
Copy link
Member

aminnj commented Sep 28, 2021

One day someone will ask about this :) (eg. each event has N tracks each of which has M subdetectors which have P hits). The doubly jagged interpretation is ~15 lines of julia, so I don't think this will be so complicated to add.

>>> import uproot4
>>> t = uproot4.open("tree_with_triply_jagged.root")["t1"]
>>> t["bi"].array()
<Array [[[[1, 2], [2]], ... []]], [[[100]]]] type='7 * var * var * var * int64'>
>>> t["bi"].array().tolist()
[[[[1, 2], [2]], [[3, 5]]], [[[7, 9, 11], [13, 15, 16]]], [[[17, 18], [19]], []], [], [[]], [[[]]], [[[100]]]]

file generated with

#!/usr/bin/env python
import ROOT as r
f = r.TFile("tree_with_triply_jagged.root", "recreate")
t = r.TTree("t1","t1")
vvvi = r.vector("vector<vector<int>>")()
vvvf = r.vector("vector<vector<float>>")()
t.Branch("bi", vvvi)
t.Branch("bf", vvvf)
data = [
        [[[1,2],[2]], [[3,5]]],
        [[[7,9,11], [13,15,16]]],
        [[[17,18], [19]], []],
        [],
        [[]],
        [[[]]],
        [[[100]]],
        ]
for row in data:
    vvvi.clear()
    vvvf.clear()
    for subrow in row:
        vvi = r.vector("vector<int>")()
        vvf = r.vector("vector<float>")()
        for subsubrow in subrow:
            vi = r.vector("int")()
            vf = r.vector("float")()
            for e in subsubrow:
                vi.push_back(e)
                vf.push_back(e + 0.5)
            vvi.push_back(vi)
            vvf.push_back(vf)
        vvvi.push_back(vvi)
        vvvf.push_back(vvf)
    t.Fill()
t.Write()
f.Close()
@oschulz
Copy link
Member

oschulz commented Mar 15, 2023

On the backend side, ArraysOfArray definitely supports nested-nested-arrays.

@tamasgal
Copy link
Member

Yes that's true, but that is not the main problem, the problem is how to parse the data in the baskets in the first place ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants