-
Notifications
You must be signed in to change notification settings - Fork 17
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
Support for custom branches that contain std vectors of custom structs? #197
Comments
This can be a bit tricky. We don't have much (read: any) automatisation yet for custom stuff. There are different ways of doing it, maybe you check out how I do it for some of the KM3NeT datastructures here (we included that into UnROOT and its test suite for documentation purposes): https://github.com/JuliaHEP/UnROOT.jl/blob/master/test/runtests.jl#L439 The parsing action is defined here: https://github.com/JuliaHEP/UnROOT.jl/blob/master/src/custom.jl#L145 As you can see, it might require some manual bit-hopping. If you can provide a sample data, I can help you out. |
Thanks @tamasgal, much appreciated! Adding a bit of bit-mangling code shouldn't be a problem. So I basically implement |
For the |
the documentation is between https://juliahep.github.io/UnROOT.jl/dev/advanced/custom_branch/ and the basically, you want to implement a function
but with your own type instead of |
I am having some trouble figuring this out. Could someone help? I basically have a I tried doing the following:
The error I get when running:
is
I am really stuck. Could someone help? |
Ahm, do you have an example file? That should work "out-of-the-box" 🙈 |
Sure, actually here is one: https://drive.google.com/drive/folders/1qLURkYheLkdwoEj_tyGLG7JsV6wShSGt?usp=sharing I'm trying to read |
julia> ROOTFile("/tmp/VetoPMTAnalysis_000.root")["ODTree"]
ODTree (TTree)
└─ "ODEvent"
julia> ROOTFile("/tmp/VetoPMTAnalysis_000.root")["ODTree"]["ODEvent"]
ODEvent
├─ TObject
│ ├─ fUniqueID
│ └─ fBits
├─ eventNumber
├─ muImpactParameter
├─ LXeImpactParameter
├─ muTrackLength
├─ muEnergy
├─ totalHits
├─ totalHitsPreQE
├─ initCherenkovOP
├─ PMTIDVec
├─ PMTWaveforms
├─ PMTBinnedWaveforms
└─ PMTTriggerVec so your TTree contains custom struct, in this case it's tricky |
It's reading
and you can check the streamer for that class with The problem is that the branch splitting is limited in your case (default is 99, which means that you basically have a ROOT branch with a corresponding path for each field), so that you need a parser which is able to parse the whole class instance. This means that you are not able to read e.g. only a single field
|
Python uproot can parse it In [16]: up
Out[16]: <module 'uproot' from '/home/akako/.conda/envs/hep/lib/python3.11/site-packages/uproot/__init__.py'>
In [17]: r = up.open("/tmp/VetoPMTAnalysis_000.root")["ODTree"].arrays()
In [18]: r.PMTBinnedWaveforms[0]
Out[18]: <Array [[0, 0, 0, 0, 0, 0, ..., 0, 0, 0, 0, 0], ...] type='472 * var * int32'> but I don't think we can do much here at the moment, parsing arbitrary C++ class without maximal splitting is too hard for now. if you convert the TTree to RNTuple, we should be able to read that easily |
Automatic parsing of custom stuff is definitely on the big todo list, but I am totally overloaded 😞 still hoping that a few more contributors jump in soon 🙂 |
Yeah, I was using Python UpROOT before but stumbled on, and really like, UnROOT hence the potential swap over. Thanks for the help! I'll try converting to an RNTuple and see, I don't really need the other TTree right now anyway. |
Or set the branch splitting to 99 ;) |
I have a root file with a custom-type branch whose elements contain structs that contain vectors of custom structs, e.g.
The file uses standard ROOT autogenerated streamers. I'm trying to read it using
but I get
Should this work or can't we handle custom structs like that automatically yet?
The text was updated successfully, but these errors were encountered: