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

[RNTuple] fix multi page reading for Index32/Index64 columns #315

Merged
merged 2 commits into from
Mar 15, 2024
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
9 changes: 4 additions & 5 deletions src/RNTuple/bootstrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function decompress_bytes!(uncomp_data, compbytes, NTarget::Integer)
compression_header = unpack(io, CompressionHeader)
cname, _, compbytes, uncompbytes = unpack(compression_header)
rawbytes = read(io, compbytes)
if cname == "L4"
if cname == @SVector UInt8['L', '4']
# skip checksum which is 8 bytes
# original: lz4_decompress(rawbytes[9:end], uncompbytes)
input = @view rawbytes[9:end]
Expand All @@ -82,17 +82,16 @@ function decompress_bytes!(uncomp_data, compbytes, NTarget::Integer)
output_ptr = pointer(uncomp_data) + fulfilled
output_size = uncompbytes
_decompress_lz4!(input_ptr, input_size, output_ptr, output_size)
elseif cname == "ZL"
elseif cname == @SVector UInt8['Z', 'L']
output = @view(uncomp_data[fulfilled+1:fulfilled+uncompbytes])
zlib_decompress!(Decompressor(), output, rawbytes, uncompbytes)
elseif cname == "XZ"
elseif cname == @SVector UInt8['X', 'Z']
@view(uncomp_data[fulfilled+1:fulfilled+uncompbytes]) .= transcode(XzDecompressor, rawbytes)
elseif cname == "ZS"
elseif cname == @SVector UInt8['Z', 'S']
@view(uncomp_data[fulfilled+1:fulfilled+uncompbytes]) .= transcode(ZstdDecompressor, rawbytes)
else
error("Unsupported compression type '$(String(compression_header.algo))'")
end

fulfilled += uncompbytes
end
return uncomp_data
Expand Down
13 changes: 13 additions & 0 deletions src/RNTuple/fieldcolumn_reading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
_from_zigzag(n) = (n >> 1) ⊻ -(n & 1)
_to_zigzag(n) = (n << 1) ⊻ (n >> 63)

function _reset_to_incremental(res::AbstractVector, pages, ::Type{T}) where T
endpoint = 0
for pi in firstindex(pages):lastindex(pages)-1
endpoint += pages[pi].num_elements
res[endpoint+1] -= sum(@view res[begin:endpoint])
end

Check warning on line 90 in src/RNTuple/fieldcolumn_reading.jl

View check run for this annotation

Codecov / codecov/patch

src/RNTuple/fieldcolumn_reading.jl#L85-L90

Added lines #L85 - L90 were not covered by tests
end

_field_output_type(::Type{LeafField{T}}) where {T} = Vector{T}
function read_field(io, field::LeafField{T}, page_list) where T
nbits = field.nbits
Expand All @@ -98,6 +106,11 @@
res[i] = _from_zigzag(res[i])
end
elseif delta
# the Index32/64 resets to absolute offset page-by-page
# https://github.com/JuliaHEP/UnROOT.jl/issues/312#issuecomment-1999875348
if T <: Union{Index32, Index64} && length(pages) > 1
_reset_to_incremental(res, pages, T)

Check warning on line 112 in src/RNTuple/fieldcolumn_reading.jl

View check run for this annotation

Codecov / codecov/patch

src/RNTuple/fieldcolumn_reading.jl#L112

Added line #L112 was not covered by tests
end
cumsum!(res, res)
end
return res::_field_output_type(field)
Expand Down
10 changes: 5 additions & 5 deletions src/streamers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ function Streamers(io)
# notice our `TKey` size is not the same as official TKey, can't use sizeof()
skipped = position(io) - start
compressedbytes = read(io, tkey.fNbytes - skipped)
cname = String(compression_header.algo)
cname = compression_header.algo

if cname == "ZL"
if cname == @SVector UInt8['Z', 'L']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comparisons look a bit weird but it is what it is ;) If we do such checks at more places in future, we should probably extract that or do some dispatch magic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, and we have like 3 different such ifelse right now.

poly-Decompression is hard

output = Vector{UInt8}(undef, tkey.fObjlen)
zlib_decompress!(Decompressor(), output, compressedbytes, length(output))
IOBuffer(output)
elseif cname == "XZ"
elseif cname == @SVector UInt8['X', 'Z']
IOBuffer(transcode(XzDecompressor, compressedbytes))
elseif cname == "ZS"
elseif cname == @SVector UInt8['Z', 'S']
IOBuffer(transcode(ZstdDecompressor, compressedbytes))
elseif cname == "L4"
elseif cname == @SVector UInt8['L', '4']
IOBuffer(lz4_decompress(compressedbytes[9:end], tkey.fObjlen))
else
error("Unsupported compression type '$(String(compression_header.algo))'")
Expand Down
8 changes: 4 additions & 4 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function decompress_datastreambytes(compbytes, tkey)
@debug "Compression type: $(cname)"
@debug "Compressed/uncompressed size in bytes: $(compbytes) / $(uncompbytes)"

if cname == "L4"
if cname == @SVector UInt8['L', '4']
# skip checksum which is 8 bytes
# original: lz4_decompress(rawbytes[9:end], uncompbytes)
input = @view rawbytes[9:end]
Expand All @@ -163,12 +163,12 @@ function decompress_datastreambytes(compbytes, tkey)
output_ptr = pointer(uncomp_data) + fulfilled
output_size = uncompbytes
_decompress_lz4!(input_ptr, input_size, output_ptr, output_size)
elseif cname == "ZL"
elseif cname == @SVector UInt8['Z', 'L']
output = @view(uncomp_data[fulfilled+1:fulfilled+uncompbytes])
zlib_decompress!(Decompressor(), output, rawbytes, uncompbytes)
elseif cname == "XZ"
elseif cname == @SVector UInt8['X', 'Z']
@view(uncomp_data[fulfilled+1:fulfilled+uncompbytes]) .= transcode(XzDecompressor, rawbytes)
elseif cname == "ZS"
elseif cname == @SVector UInt8['Z', 'S']
@view(uncomp_data[fulfilled+1:fulfilled+uncompbytes]) .= transcode(ZstdDecompressor, rawbytes)
else
error("Unsupported compression type '$(String(compression_header.algo))'")
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Return the following information:
- compressedbytes and uncompressedbytes according to [uproot3](https://github.com/scikit-hep/uproot3/blob/54f5151fb7c686c3a161fbe44b9f299e482f346b/uproot3/source/compressed.py#L132)
"""
function unpack(x::CompressionHeader)
algname = String(x.algo)
algname = x.algo
# shift without casting to `Int` will give you 0x00 because we're shifting 0 bits into UInt8
compressedbytes = x.c1 + (Int(x.c2) << 8) + (Int(x.c3) << 16)
uncompressedbytes = x.u1 + (Int(x.u2) << 8) + (Int(x.u3) << 16)
Expand Down
Loading