JuliaHEP / UnROOT.jl

Native Julia I/O package to work with CERN ROOT files objects (TTree and RNTuple)
https://juliahep.github.io/UnROOT.jl/
MIT License
102 stars 17 forks source link

Allow hooking into parsetobject #304

Closed tamasgal closed 9 months ago

tamasgal commented 9 months ago

Currently, when calling _getindex(f::ROOTFile, s) a streamer is picked up and when the corresponding type is defined, the streamer is then called with the file object, tkey and refs. The point is that objects can also sit at top-level. In _getindex the type has to be defined in the namespace of UnROOT. That's still something I am not fully happy with but it works so far.

If there is no type defined (called tkey.fClassName, in the namespace of UnROOT), the function parsetobject is called which essentially tries to instantiate the full data as a last resort. This approach completely goes another path and the Lazy* mechanics are also bypassed.

As of now, passing customstructs=Dict{String, Type}(...) to the ROOTFile allows to hook into the streamer logic at the late auto_T_JaggT stage which is only reached for objects in a ROOTDirectory, via getindex(d::ROOTDirectory, s).

This PR adds the ability to use a custom streamer directly inside the parsetobject function, using the same customstructs dictionary.

We really(!) need to refactor these stuff at some point; we can unify a couple of things already, but this is a lot of work.

tamasgal commented 9 months ago

I decided to increase only the patch version. Let us hide this behind the scenes for now. I need to use this mechanism but I need to think about the future implementation before I feel confident to make it fully public.

codecov[bot] commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (4d11965) 87.02% compared to head (42349bd) 86.34%. Report is 8 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #304 +/- ## ========================================== - Coverage 87.02% 86.34% -0.69% ========================================== Files 18 18 Lines 2404 2438 +34 ========================================== + Hits 2092 2105 +13 - Misses 312 333 +21 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.