Skip to content
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
8 changes: 8 additions & 0 deletions src/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ function array(f::ROOTFile, path::AbstractString; raw=false)
return array(f::ROOTFile, f[path]; raw=raw)
end

function array(f::ROOTFile, tree::TTree; raw=false)
error(
"$(tree.fName) is a TTree (not a branch). " *
"To read all branches use `LazyTree(f, \"$(tree.fName)\")` or `arrays(f, \"$(tree.fName)\")`. " *
"To read a single branch use `array(f, \"$(tree.fName)/branchname\")`."
)
end

function array(f::ROOTFile, branch; raw=false)
ismissing(branch) && error("No branch found (branch is missing)")
(!raw && length(branch.fLeaves.elements) > 1) && error(
Expand Down
18 changes: 18 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ SAMPLES_DIR = joinpath(@__DIR__, "samples")


@testset "Issues" begin
# issue 9 — fixed-size array branches ([N]/D, [M][N]/D, name[N]/D)
rootfile = UnROOT.samplefile("issue9.root")
@test_throws "is a TTree" UnROOT.array(rootfile, "arrays")
@test_throws "is a TTree" UnROOT.array(rootfile, "structs")
# individual branch reading
@test UnROOT.array(rootfile, "arrays/nInt") == Int32[1]
@test UnROOT.array(rootfile, "arrays/6dVec") == [UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))]
@test UnROOT.array(rootfile, "arrays/2x3Mat") == [UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))]
@test UnROOT.array(rootfile, "structs/2x3mat") == [UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))]
# LazyTree and arrays() (plural) work
t = LazyTree(rootfile, "arrays")
@test t[1].nInt == 1
@test t[1].var"6dVec" == UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))
res = UnROOT.arrays(rootfile, "structs")
@test res[1] == Int32[1]
@test res[2] == [UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))]
close(rootfile)

rootfile = UnROOT.samplefile("issue7.root")
@test 2 == length(keys(rootfile))
@test [1.0, 2.0, 3.0] == UnROOT.array(rootfile, "TreeD/nums")
Expand Down
Binary file added test/samples/issue9.root
Binary file not shown.
Loading