Skip to content

Commit 88b05cb

Browse files
committed
Add support for awkward.array.objects.ObjectArray
1 parent 5ac08bb commit 88b05cb

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/UpROOT.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ uproot = PyNULL()
1414

1515
include("testdata.jl")
1616
include("pywrappers.jl")
17+
include("opaque.jl")
1718
include("pyjlconv.jl")
1819
include("tdirectory.jl")
1920
include("ttree.jl")

src/opaque.jl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This file is a part of UpROOT.jl, licensed under the MIT License (MIT).
2+
3+
const AbstractBlob = AbstractVector{UInt8}
4+
5+
"""
6+
UpROOT.OpaqueObject{tp,B<:AbstractVector{UInt8}}
7+
8+
An opaque object of symbolic type `tp`. `tp` must be a `Symbol`. Use the
9+
`data` field to access the byte representation.
10+
"""
11+
struct OpaqueObject{tp,B<:AbstractBlob}
12+
data::B
13+
end
14+
15+
16+
OpaqueObject{tp}(data::AbstractBlob) where {tp} = OpaqueObject{tp,typeof(data)}(data)
17+
18+
19+
20+
"""
21+
OpaqueObjectArray{tp,N,BA<:AbstractArray{<:AbstractBlob,N}}
22+
23+
An array of [`UpROOT.OpaqueObject`]s.
24+
"""
25+
struct OpaqueObjectArray{tp,N,BA<:AbstractArray{<:AbstractBlob,N}} <: AbstractArray{OpaqueObject{tp},N}
26+
data::BA
27+
end
28+
29+
30+
OpaqueObjectArray{tp}(data::AbstractArray{<:AbstractBlob,N}) where {tp,N} = OpaqueObjectArray{tp,N,typeof(data)}(data)
31+
32+
33+
Base.size(A::OpaqueObjectArray) = size(A.data)
34+
35+
Base.IndexStyle(A::OpaqueObjectArray) = IndexStyle(A.data)
36+
37+
Base.@propagate_inbounds function Base.getindex(A::OpaqueObjectArray{tp}, idxs::Vararg{Integer,N}) where {tp,N}
38+
OpaqueObject{tp}(getindex(A.data, idxs...))
39+
end
40+
41+
Base.@propagate_inbounds function Base.getindex(A::OpaqueObjectArray{tp}, idxs...) where {tp}
42+
OpaqueObjectArray{tp}(getindex(A.data, idxs...))
43+
end

src/pyjlconv.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,23 @@ function pyjaggedarray2jl(x::PyObject)
2121
end
2222

2323

24+
function awkwardobjectarray2jl(x::PyObject)
25+
tp = Symbol(x.generator.cls.__name__)
26+
data = pyjaggedarray2jl(x._content)
27+
28+
OpaqueObjectArray{tp}(data)
29+
end
30+
31+
2432
py2jl(x::Any) = x
2533

2634
function py2jl(x::PyObject)
2735
if pybuiltin(:isinstance)(x, awkward.JaggedArray)
2836
pyjaggedarray2jl(x)
29-
elseif pybuiltin(:isinstance)(x, awkward.array.base.AwkwardArray)
37+
elseif pybuiltin(:isinstance)(x, awkward.array.table.Table)
3038
Table(_dict2nt(x._contents))
39+
elseif pybuiltin(:isinstance)(x, awkward.array.objects.ObjectArray)
40+
awkwardobjectarray2jl(x)
3141
elseif pybuiltin(:isinstance)(x, uproot.rootio.ROOTDirectory)
3242
TDirectory(x)
3343
elseif pybuiltin(:isinstance)(x, uproot.tree.TTreeMethods)

0 commit comments

Comments
 (0)