You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here you can see that keys(f["KM3NET_EVENT/KM3NET_EVENT"]) lists the "branches", which are fields of the KM3NETDAQ::JDAQEvent class entry.
Of course, there is some complicated way to read this class by deserialising all the four sub-branches but it's a tough thing and I haven't even managed to do so in uproot. However, It's possible to do it branch-by-branch.
With the new API we currently work on, there is currently no easy way to access subranches of such a custom branch like f["KM3NET_EVENT/KM3NET_EVENT"]:
julia>keys(f["KM3NET_EVENT/KM3NET_EVENT"])
┌ Warning: Can't automatically create LazyBranch for branch KM3NET_EVENT/KM3NET_EVENT. Returning a branch object
└ @ UnROOT ~/Dev/UnROOT.jl/src/root.jl:93
ERROR: MethodError: no method matching keys(::UnROOT.TBranchElement_10)
Closest candidates are:keys(::Union{Tables.AbstractColumns, Tables.AbstractRow}) at /Users/tamasgal/.julia/packages/Tables/gg6Id/src/Tables.jl:181keys(::Missings.EachFailMissing) at /Users/tamasgal/.julia/packages/Missings/sx5js/src/Missings.jl:154keys(::Dictionaries.Dictionary) at /Users/tamasgal/.julia/packages/Dictionaries/YpAxR/src/Dictionary.jl:270...
Stacktrace:
[1] top-level scope
@ REPL[3]:1
That's quite an easy fix since we have the abstract type TBranchElement which we can use to implement keys(branch::TBranchElement).
However, the API to introduce the custom parsing currently only looks at the base class and is not able to distinguish between subbranches. This means that it only looks at fClassName and if there is a match, it will use the type in customstructs:
struct KM3NETDAQHit
dom_id::Int32
channel_id::UInt8
tdc::Int32
tot::UInt8endfunction UnROOT.interped_data(rawdata, rawoffsets, ::Type{Vector{KM3NETDAQHit}}, ::Type{J}) where J<:UnROOT.JaggType@viewsmap(1:length(rawoffsets)-1) do idx
idxrange = rawoffsets[idx]+10+1: rawoffsets[idx+1]
UnROOT.interped_data(rawdata[idxrange], rawoffsets[idx], KM3NETDAQHit, UnROOT.Nojagg)
end
en
function UnROOT.interped_data(rawdata, rawoffsets, T::Type{KM3NETDAQHit}, ::Type{J}) where J <:UnROOT.JaggType
splitdata = Base.Iterators.partition(rawdata, 10)
out = KM3NETDAQHit[]
sizehint!(out, length(splitdata))
for single in splitdata
io =IOBuffer(single)
push!(out, T(UnROOT.readtype(io, Int32), read(io, UInt8), read(io, Int32), read(io, UInt8)))
end
out
end
customstructs =Dict("KM3NETDAQ::JDAQEvent"=> Vector{KM3NETDAQHit})
f = UnROOT.ROOTFile("../test/samples/km3net_online.root", customstructs=customstructs)
With this code, f["KM3NET_EVENT/KM3NET_EVENT/snapshotHits"] magically becomes a jagged Vector{Vector{KM3NETDAQHit}} which is nice, but it uses the same type also for f["KM3NET_EVENT/KM3NET_EVENT/triggeredHits"] and fails.
Furthermore, the printout of f["KM3NET_EVENT/KM3NET_EVENT"] is broken when using customstructs:
The text was updated successfully, but these errors were encountered:
tamasgal
changed the title
Issue with branches of custom classes
Issue with sub-branches of custom classes
Jul 14, 2021
Moelf
changed the title
Issue with sub-branches of custom classes
Issue with sub-branches coming from slipt custom classes
Jul 14, 2021
tamasgal
changed the title
Issue with sub-branches coming from slipt custom classes
Issue with sub-branches coming from split custom classes
Jul 14, 2021
The title is a bit generic
;)
Let me rewind and show how it looked the early days of
UnROOT
(v0.1.7), where thegetindex
was different:Here you can see that
keys(f["KM3NET_EVENT/KM3NET_EVENT"])
lists the "branches", which are fields of theKM3NETDAQ::JDAQEvent
class entry.Of course, there is some complicated way to read this class by deserialising all the four sub-branches but it's a tough thing and I haven't even managed to do so in
uproot
. However, It's possible to do it branch-by-branch.With the new API we currently work on, there is currently no easy way to access subranches of such a custom branch like
f["KM3NET_EVENT/KM3NET_EVENT"]
:That's quite an easy fix since we have the abstract type
TBranchElement
which we can use to implementkeys(branch::TBranchElement)
.However, the API to introduce the custom parsing currently only looks at the base class and is not able to distinguish between subbranches. This means that it only looks at
fClassName
and if there is a match, it will use the type incustomstructs
:With this code,
f["KM3NET_EVENT/KM3NET_EVENT/snapshotHits"]
magically becomes a jaggedVector{Vector{KM3NETDAQHit}}
which is nice, but it uses the same type also forf["KM3NET_EVENT/KM3NET_EVENT/triggeredHits"]
and fails.Furthermore, the printout of
f["KM3NET_EVENT/KM3NET_EVENT"]
is broken when usingcustomstructs
:EDIT:
So all in all, what we need is the possibility to provide the types for subbranches. Given the example above, it would be something like this:
The text was updated successfully, but these errors were encountered: