Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index range access branch with recoveredtbasket #239

Merged
merged 10 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,20 @@ function Base.iterate(tree::T, idx=1) where {T<:LazyTree}
end

function Base.getindex(ba::LazyBranch{T,J,B}, range::UnitRange) where {T,J,B}
ib1 = findfirst(x -> x > (first(range) - 1), ba.fEntry) - 1
ib2 = findfirst(x -> x > (last(range) - 1), ba.fEntry) - 1
offset = ba.fEntry[ib1]
ib1 = findfirst(x -> x > (first(range) - 1), ba.fEntry)
ib2 = findfirst(x -> x > (last(range) - 1), ba.fEntry)
if isnothing(ib1) #Check if we are completely on the recovered basket
offset = ba.b.fBasketEntry[end]
iths = [-1] # use magic number -1 as address for recovered basket only
elseif isnothing(ib2) # Check if we partially on the recovered basket
offset = ba.fEntry[ib1-1]
iths = vcat(collect(ib1-1:length(ba.fEntry)-1), -1) # append magic number -1 for recovered basket at the end of the basket address range
else # Keep everything as it was
offset = ba.fEntry[ib1-1]
iths = ib1-1:ib2-1
end
range = (first(range)-offset):(last(range)-offset)
return ChainedVector(asyncmap(i->basketarray(ba, i), ib1:ib2))[range]
return ChainedVector(asyncmap(i->basketarray(ba, i), iths))[range]
end

_clusterranges(t::LazyTree) = _clusterranges([getproperty(t,p) for p in propertynames(t)])
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ 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

# do some hardcoded value checks
bunches = Float32[]
for i in 1:10
start = 1 + 1000*(i-1)
stop = 1000*i
push!(bunches, sum(table.float_array[start:stop]))
end
testvalues = Vector{Float32}([528882.3f0, 1.5877059f6, 2.6465295f6, 3.705353f6, 4.764177f6, 5.823f6, 6.881823f6, 7.9406475f6, 8.999469f6, 1.0058294f7])
@test bunches ≈ testvalues
Moelf marked this conversation as resolved.
Show resolved Hide resolved

close(rootfile)

rootfile = UnROOT.samplefile("km3net_offline.root")
Expand Down