Skip to content

Commit

Permalink
fix reading TLeafC (#342)
Browse files Browse the repository at this point in the history
* fix reading TLeafC

* add test sample and tests
  • Loading branch information
Moelf authored Jul 6, 2024
1 parent 0196924 commit dd2f9db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/root.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ function interped_data(rawdata, rawoffsets, ::Type{Bool}, ::Type{Nojagg})
# specialized case to get Vector{Bool} instead of BitVector
return map(ntoh,reinterpret(Bool, rawdata))
end
function interped_data(rawdata, rawoffsets, ::Type{String}, ::Type{Nojagg})
rawoffsets .= rawoffsets .+ 1
vov_bytes = VectorOfVectors(rawdata, rawoffsets)
return [readtype(IOBuffer(v), String) for v in vov_bytes]
end
function interped_data(rawdata, rawoffsets, ::Type{T}, ::Type{J}) where {T, J<:JaggType}
# there are two possibility, one is the leaf is just normal leaf but the title has "[...]" in it
# magic offsets, seems to be common for a lot of types, see auto.py in uproot3
Expand Down Expand Up @@ -481,12 +486,16 @@ function leaf_jaggtype(leaf, _jaggtype)
_fTitle = replace(leaf.fTitle, "[$(leafLen)]" => "")
# looking for more `[var]`
m = match(r"\[\D+\]", _fTitle)
_type = FixLenVector{Int(leafLen), _type}
_vtype = FixLenVector{Int(leafLen), _type}
if isnothing(m)
return _type, Nojagg
if leaf isa TLeafC
return String, Nojagg
else
return _vtype, Nojagg
end
else
#FIXME this only handles [var][fix] case
return Vector{_type}, Nooffsetjagg
return Vector{_vtype}, Nooffsetjagg
end
end
_type = _jaggtype === Nojagg ? _type : Vector{_type}
Expand Down
5 changes: 5 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ end
@test length(tree.PandoraPFOs_energy[1]) == 79
@test length(tree.var"PandoraPFOs_covMatrix[10]"[1]) == 790
end

@testset "PR 342 TLeafC" begin
df = LazyTree(UnROOT.samplefile("TLeafC_pr342.root"), "G4Sim")
@test all(df.Process[1:10] .== ["Radioactivation", "msc", "eIoni", "Transportation", "ionIoni", "Radioactivation", "msc", "eIoni", "ionIoni", "Radioactivation"])
end
Binary file added test/samples/TLeafC_pr342.root
Binary file not shown.

0 comments on commit dd2f9db

Please sign in to comment.