Skip to content

Commit dd2f9db

Browse files
authored
fix reading TLeafC (#342)
* fix reading TLeafC * add test sample and tests
1 parent 0196924 commit dd2f9db

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/root.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ function interped_data(rawdata, rawoffsets, ::Type{Bool}, ::Type{Nojagg})
247247
# specialized case to get Vector{Bool} instead of BitVector
248248
return map(ntoh,reinterpret(Bool, rawdata))
249249
end
250+
function interped_data(rawdata, rawoffsets, ::Type{String}, ::Type{Nojagg})
251+
rawoffsets .= rawoffsets .+ 1
252+
vov_bytes = VectorOfVectors(rawdata, rawoffsets)
253+
return [readtype(IOBuffer(v), String) for v in vov_bytes]
254+
end
250255
function interped_data(rawdata, rawoffsets, ::Type{T}, ::Type{J}) where {T, J<:JaggType}
251256
# there are two possibility, one is the leaf is just normal leaf but the title has "[...]" in it
252257
# magic offsets, seems to be common for a lot of types, see auto.py in uproot3
@@ -481,12 +486,16 @@ function leaf_jaggtype(leaf, _jaggtype)
481486
_fTitle = replace(leaf.fTitle, "[$(leafLen)]" => "")
482487
# looking for more `[var]`
483488
m = match(r"\[\D+\]", _fTitle)
484-
_type = FixLenVector{Int(leafLen), _type}
489+
_vtype = FixLenVector{Int(leafLen), _type}
485490
if isnothing(m)
486-
return _type, Nojagg
491+
if leaf isa TLeafC
492+
return String, Nojagg
493+
else
494+
return _vtype, Nojagg
495+
end
487496
else
488497
#FIXME this only handles [var][fix] case
489-
return Vector{_type}, Nooffsetjagg
498+
return Vector{_vtype}, Nooffsetjagg
490499
end
491500
end
492501
_type = _jaggtype === Nojagg ? _type : Vector{_type}

test/issues.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,8 @@ end
9494
@test length(tree.PandoraPFOs_energy[1]) == 79
9595
@test length(tree.var"PandoraPFOs_covMatrix[10]"[1]) == 790
9696
end
97+
98+
@testset "PR 342 TLeafC" begin
99+
df = LazyTree(UnROOT.samplefile("TLeafC_pr342.root"), "G4Sim")
100+
@test all(df.Process[1:10] .== ["Radioactivation", "msc", "eIoni", "Transportation", "ionIoni", "Radioactivation", "msc", "eIoni", "ionIoni", "Radioactivation"])
101+
end

test/samples/TLeafC_pr342.root

27.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)