Skip to content

Commit

Permalink
add simpler jagged array root
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf committed Jul 2, 2021
1 parent e40e5eb commit 8fa520c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ documentation](https://github.com/scikit-hep/uproot/issues/401)
The project is in early alpha prototyping phase and contributions are very
welcome.

Reading of raw basket data is already working for uncompressed and
Zlib-compressed files. The raw data consists of two vectors: the bytes
Reading of raw basket data is already working for files of all different compression algorithms.
The raw data consists of two vectors: the bytes
and the offsets and are available using the
`UnROOT.array(f::ROOTFile, path; raw=true)` method. This data can
be reinterpreted using a custom type with the method
Expand Down
2 changes: 1 addition & 1 deletion src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function endcheck(io, preamble::T) where {T<:Preamble}
error("Object '$(preamble.type)' has $(observed) bytes; expected $(preamble.cnt)")
end
end
return true
nothing
end


Expand Down
6 changes: 2 additions & 4 deletions src/root.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ function readbasketsraw(io, branch)
idx = 1
for (basket_seek, n_bytes) in zip(seeks, bytes)
@debug "Reading raw basket data" basket_seek n_bytes
if basket_seek == 0
break
end
basket_seek == 0 && break
seek(io, basket_seek)
idx += readbasketbytes!(data, offsets, io, idx)
end
Expand Down Expand Up @@ -284,5 +282,5 @@ Efficient read of bytes into an existing array at a given offset
function readbytes!(io, b, offset, nr)
resize!(b, offset + nr - 1)
nb = UInt(nr)
GC.@preserve b unsafe_read(io, pointer(b, offset), nr)
GC.@preserve b unsafe_read(io, pointer(b, offset), nb)
end
7 changes: 6 additions & 1 deletion src/streamers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ function unpack(io, tkey::TKey, refs::Dict{Int32, Any}, T::Type{TObjArray})
name = readtype(io, String)
size = readtype(io, Int32)
low = readtype(io, Int32)
elements = [readobjany!(io, tkey, refs) for i in 1:size]
elements = Vector{Any}(undef, size)
for i in 1:size
ele = readobjany!(io, tkey, refs)
!ismissing(ele) && @show ele.fName
elements[i] = ele
end
endcheck(io, preamble)
return TObjArray(name, low, elements)
end
Expand Down
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function datastream(io, tkey::T) where T<:Union{TKey, TBasketKey}
seekstart(io, tkey)
fufilled = 0
uncomp_data = Vector{UInt8}(undef, tkey.fObjlen)
while fufilled < tkey.fObjlen # careful with 0/1-based index when thinking about offsets
while fufilled < length(uncomp_data) # careful with 0/1-based index when thinking about offsets
compression_header = unpack(io, CompressionHeader)
cname, _, compbytes, uncompbytes = unpack(compression_header)
io_buf = IOBuffer(read(io, compbytes))
Expand All @@ -122,7 +122,7 @@ function datastream(io, tkey::T) where T<:Union{TKey, TBasketKey}

fufilled += uncompbytes
end

@assert fufilled == length(uncomp_data) # fail means something bad happens we over shoot
return IOBuffer(uncomp_data)
end

Expand Down
21 changes: 21 additions & 0 deletions test/samples/tree_with_jagged_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# Example taken from https://root.cern.ch/how/how-write-ttree-python
# and modified to run...
import ROOT
from ROOT import TFile, TTree
from array import array

f = TFile('tree_with_jagged_array.root', 'recreate')
t = TTree('t1', 'tree with jagged array')

n = ROOT.vector('int')()
t.Branch('int32_array', n)

for i in range(100):
if i % 10 == 0:
n.clear()
t.Fill()
n.push_back(i)

f.Write()
f.Close()
Binary file added test/samples/tree_with_jagged_array.root
Binary file not shown.
Binary file modified test/samples/tree_with_large_array_lz4.root
Binary file not shown.

0 comments on commit 8fa520c

Please sign in to comment.