Skip to content

Commit b385bbb

Browse files
committed
Better error for array when reading tree, tests for issue9
1 parent cd56b58 commit b385bbb

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/iteration.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ function array(f::ROOTFile, path::AbstractString; raw=false)
2121
return array(f::ROOTFile, f[path]; raw=raw)
2222
end
2323

24+
function array(f::ROOTFile, tree::TTree; raw=false)
25+
error(
26+
"$(tree.fName) is a TTree (not a branch). " *
27+
"To read all branches use `LazyTree(f, \"$(tree.fName)\")` or `arrays(f, \"$(tree.fName)\")`. " *
28+
"To read a single branch use `array(f, \"$(tree.fName)/branchname\")`."
29+
)
30+
end
31+
2432
function array(f::ROOTFile, branch; raw=false)
2533
ismissing(branch) && error("No branch found (branch is missing)")
2634
(!raw && length(branch.fLeaves.elements) > 1) && error(

test/issues.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ SAMPLES_DIR = joinpath(@__DIR__, "samples")
55

66

77
@testset "Issues" begin
8+
# issue 9 — fixed-size array branches ([N]/D, [M][N]/D, name[N]/D)
9+
rootfile = UnROOT.samplefile("issue9.root")
10+
@test_throws "is a TTree" UnROOT.array(rootfile, "arrays")
11+
@test_throws "is a TTree" UnROOT.array(rootfile, "structs")
12+
# individual branch reading
13+
@test UnROOT.array(rootfile, "arrays/nInt") == Int32[1]
14+
@test UnROOT.array(rootfile, "arrays/6dVec") == [UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))]
15+
@test UnROOT.array(rootfile, "arrays/2x3Mat") == [UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))]
16+
@test UnROOT.array(rootfile, "structs/2x3mat") == [UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))]
17+
# LazyTree and arrays() (plural) work
18+
t = LazyTree(rootfile, "arrays")
19+
@test t[1].nInt == 1
20+
@test t[1].var"6dVec" == UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))
21+
res = UnROOT.arrays(rootfile, "structs")
22+
@test res[1] == Int32[1]
23+
@test res[2] == [UnROOT.FixLenVector(SVector{6,Float64}(1,2,3,4,5,6))]
24+
close(rootfile)
25+
826
rootfile = UnROOT.samplefile("issue7.root")
927
@test 2 == length(keys(rootfile))
1028
@test [1.0, 2.0, 3.0] == UnROOT.array(rootfile, "TreeD/nums")

test/samples/issue9.root

6.53 KB
Binary file not shown.

0 commit comments

Comments
 (0)