Skip to content

Commit

Permalink
batch reading for TBaskets
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf committed Oct 24, 2024
1 parent 1b190d2 commit 554da4a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions src/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ to obtain raw bytes and offsets of a basket, then calls [`auto_T_JaggT`](@ref) f
by [`interped_data`](@ref) to translate raw bytes into actual data.
"""
function basketarray(f::ROOTFile, path::AbstractString, ithbasket)
return basketarray(f, f[path], ithbasket)
end
function basketarray(f::ROOTFile, branch, ithbasket)
branch = f[path]
ismissing(branch) && error("No branch found at $path")
return basketarray(f, branch, ithbasket)
end

function rawbasketarray(f::ROOTFile, branch, ithbasket::Integer;)
length(branch.fLeaves.elements) > 1 && error(
"Branches with multiple leaves are not supported yet. Try reading with `array(...; raw=true)`.",
)
Expand All @@ -60,6 +62,20 @@ function basketarray(f::ROOTFile, branch, ithbasket)
recovered_basket = branch.fBaskets.elements[end]
rawdata, rawoffsets = recovered_basket.data, recovered_basket.offsets
end
return rawdata, rawoffsets
end

function basketarray(f::ROOTFile, branch, ithbasket::AbstractVector{<:Integer})
tuples = [rawbasketarray(f, branch, i) for i in ithbasket]
rawdata = reduce(vcat, first.(tuples))
rawoffsets = reduce(vcat, last.(tuples))
T, J = auto_T_JaggT(f, branch; customstructs=f.customstructs)
return interped_data(rawdata, rawoffsets, T, J)
end


function basketarray(f::ROOTFile, branch, ithbasket::Integer)
rawdata, rawoffsets = rawbasketarray(f, branch, ithbasket)
T, J = auto_T_JaggT(f, branch; customstructs=f.customstructs)
return interped_data(rawdata, rawoffsets, T, J)
end
Expand Down Expand Up @@ -483,7 +499,7 @@ function Base.getindex(ba::LazyBranch{T,J,B}, range::UnitRange) where {T,J,B}
iths = ib1-1:ib2-1
end
range = (first(range)-offset):(last(range)-offset)
return ChainedVector(map(i->basketarray(ba, i), iths))[range]
return basketarray(ba, iths)[range]
end

_clusterranges(t::LazyTree) = _clusterranges([getproperty(t,p) for p in propertynames(t)])
Expand Down
2 changes: 1 addition & 1 deletion src/root.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ end
readbasket(f::ROOTFile, branch, ith)
readbasketseek(f::ROOTFile, branch::Union{TBranch, TBranchElement}, seek_pos::Int, nbytes)
The fundamental building block of reading read data from a .root file. Read read one
The fundamental building block of reading read data from a .root file. Read one
basket's raw bytes and offsets at a time. These raw bytes and offsets then (potentially) get
processed by [`interped_data`](@ref).
Expand Down

0 comments on commit 554da4a

Please sign in to comment.