From a2826768236f7fd0554005a09829e1b81c971cc5 Mon Sep 17 00:00:00 2001 From: Nick Amin Date: Tue, 14 Sep 2021 21:30:00 -0700 Subject: [PATCH 1/2] fix bool vector interpretation --- src/root.jl | 8 ++++++-- test/runtests.jl | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/root.jl b/src/root.jl index 123771e0..b7c9ad98 100644 --- a/src/root.jl +++ b/src/root.jl @@ -193,6 +193,10 @@ on type `T` and jagg type `J`. In order to retrieve data from custom branches, user should defined more speialized method of this function with specific `T` and `J`. See `TLorentzVector` example. """ +function interped_data(rawdata, rawoffsets, ::Type{T}, ::Type{Nojagg}) where {T<:Bool} + # specialized case to get Vector{Bool} instead of BitVector + return map(ntoh,reinterpret(T, rawdata)) +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 @@ -200,9 +204,9 @@ function interped_data(rawdata, rawoffsets, ::Type{T}, ::Type{J}) where {T, J<:J # the jaggedness comes from having "[]" in TLeaf's title # the other is where we need to auto detector T bsaed on class name # we want the fundamental type as `reinterpret` will create vector - if J == Nojagg + if J === Nojagg return ntoh.(reinterpret(T, rawdata)) - elseif J == Offsetjaggjagg # the branch is doubly jagged + elseif J === Offsetjaggjagg # the branch is doubly jagged jagg_offset = 10 subT = eltype(eltype(T)) out = VectorOfVectors(T(), Int32[1]) diff --git a/test/runtests.jl b/test/runtests.jl index 74edad6a..bef4dd79 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -322,6 +322,7 @@ end tree = LazyTree(rootfile, "Events", r"Muon_(pt|eta)$") @test sort(propertynames(tree) |> collect) == sort([:Muon_pt, :Muon_eta]) @test occursin("LazyEvent", repr(first(iterate(tree)))) + @test sum(rootfile["Events/HLT_Mu3_PFJet40"]) == 443 close(rootfile) end From 773cb42bde1301e60009a411c45013a27c54be43 Mon Sep 17 00:00:00 2001 From: Nick Amin Date: Wed, 15 Sep 2021 07:39:32 -0700 Subject: [PATCH 2/2] Update src/root.jl Co-authored-by: Jerry Ling --- src/root.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/root.jl b/src/root.jl index b7c9ad98..5573a8ee 100644 --- a/src/root.jl +++ b/src/root.jl @@ -193,7 +193,7 @@ on type `T` and jagg type `J`. In order to retrieve data from custom branches, user should defined more speialized method of this function with specific `T` and `J`. See `TLorentzVector` example. """ -function interped_data(rawdata, rawoffsets, ::Type{T}, ::Type{Nojagg}) where {T<:Bool} +function interped_data(rawdata, rawoffsets, ::Type{Bool}, ::Type{Nojagg}) # specialized case to get Vector{Bool} instead of BitVector return map(ntoh,reinterpret(T, rawdata)) end