diff --git a/src/iteration.jl b/src/iteration.jl index e4bd0af8..d2ddf3eb 100644 --- a/src/iteration.jl +++ b/src/iteration.jl @@ -112,29 +112,38 @@ mutable struct LazyBranch{T,J,B} <: AbstractVector{T} buffer::Vector{B} thread_locks::Vector{ReentrantLock} buffer_range::Vector{UnitRange{Int64}} +end - function LazyBranch(f::ROOTFile, b::Union{TBranch,TBranchElement}) - T, J = auto_T_JaggT(f, b; customstructs=f.customstructs) - T = (T === Vector{Bool} ? BitVector : T) - _buffer = T[] - if J != Nojagg - # if branch is jagged, fix the buffer and eltype according to what - # VectorOfVectors would return in `getindex` - _buffer = VectorOfVectors(T(), Int32[1]) - T = SubArray{eltype(T), 1, T, Tuple{UnitRange{Int64}}, true} - end - Nthreads = _maxthreadid() - return new{T,J,typeof(_buffer)}(f, b, length(b), - b.fBasketEntry, - [_buffer for _ in 1:Nthreads], - [ReentrantLock() for _ in 1:Nthreads], - [0:-1 for _ in 1:Nthreads]) +function LazyBranch(f::ROOTFile, b::Union{TBranch,TBranchElement}) + T, J = auto_T_JaggT(f, b; customstructs=f.customstructs) + T = (T === Vector{Bool} ? BitVector : T) + _buffer = T[] + if J != Nojagg + # if branch is jagged, fix the buffer and eltype according to what + # VectorOfVectors would return in `getindex` + _buffer = VectorOfVectors(T(), Int32[1]) + T = SubArray{eltype(T), 1, T, Tuple{UnitRange{Int64}}, true} end + Nthreads = _maxthreadid() + return LazyBranch{T,J,typeof(_buffer)}(f, b, length(b), + b.fBasketEntry, + [_buffer for _ in 1:Nthreads], + [ReentrantLock() for _ in 1:Nthreads], + [0:-1 for _ in 1:Nthreads]) end + LazyBranch(f::ROOTFile, s::AbstractString) = LazyBranch(f, f[s]) basketarray(lb::LazyBranch, ithbasket) = basketarray(lb.f, lb.b, ithbasket) basketarray_iter(lb::LazyBranch) = basketarray_iter(lb.f, lb.b) +""" + copy(x::LazyBranch) + + Makes a shallow copy of x. +""" +Base.copy(x::LazyBranch{T,J,B}) where {T,J,B} = LazyBranch{T,J,B}(x.f, x.b, x.L, x.fEntry, copy.(x.buffer), + x.thread_locks, copy(x.buffer_range)) + function Base.hash(lb::LazyBranch, h::UInt) h = hash(lb.f, h) h = hash(lb.b.fClassName, h) diff --git a/test/runtests.jl b/test/runtests.jl index 8149f6db..8c26ba90 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -252,6 +252,11 @@ end @test [row.int32_array for row in table[20:30]] == BA[20:30] @test sum(table.int32_array) == sum(row.int32_array for row in table) @test [row.int32_array for row in table] == BA + BA_copy = copy(BA) + #Check the copy is a LazyBranch: + @test typeof(BA_copy) == typeof(BA) + #Check the content: + @test all(BA .== BA_copy) # do some hardcoded value checks bunches = Float32[]