Skip to content

Commit

Permalink
fix split branches (JuliaHEP#155)
Browse files Browse the repository at this point in the history
* fix split branches
  • Loading branch information
Moelf committed Jun 23, 2022
1 parent f6a0d4a commit 00e7815
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ function getbranchnamesrecursive(obj)
out = Vector{String}()
for b in obj.fBranches.elements
push!(out, b.fName)
for subname in getbranchnamesrecursive(b)
subs = getbranchnamesrecursive(b)
!isempty(subs) && pop!(out)
for subname in subs
push!(out, "$(b.fName)/$(subname)")
end
end
Expand Down Expand Up @@ -294,12 +296,20 @@ function LazyTree(f::ROOTFile, s::AbstractString, branches)
tree = f[s]
tree isa TTree || error("$s is not a tree name.")
d = Dict{Symbol,LazyBranch}()
_m(s::AbstractString) = isequal(s)
_m(r::Regex) = Base.Fix1(occursin, r)
branches = mapreduce(b -> filter(_m(b), getbranchnamesrecursive(tree)), , branches)
SB = Symbol.(branches)
for b in SB
d[b] = f["$s/$b"]
all_bnames = getbranchnamesrecursive(tree)
res_bnames = mapreduce(, branches) do b
if b isa Regex
filter(_m(b), all_bnames)
elseif b isa String
expand = filter(n->startswith(n, "$b/$b"), all_bnames)
isempty(expand) ? filter(isequal(b), all_bnames) : expand
else
error("branch selection must be string or regex")
end
end
for b in res_bnames
d[Symbol(b)] = f["$s/$b"]
end
return LazyTree(TypedTables.Table(d))
end
Expand Down
2 changes: 2 additions & 0 deletions src/root.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ function auto_T_JaggT(f::ROOTFile, branch; customstructs::Dict{String, Type})
Bool
elseif elname == "unsigned int"
UInt32
elseif elname == "signed char"
Int8
elseif elname == "unsigned char"
UInt8
elseif elname == "unsigned short"
Expand Down

0 comments on commit 00e7815

Please sign in to comment.