Skip to content

Commit 08a5a57

Browse files
authored
Adds TStreamerSTLstring support (#378)
* Adds TStreamerSTLstring support * Fix readout for STLstring * Add tests * Fix typo
1 parent 26bec3d commit 08a5a57

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/custom.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ end
3030

3131

3232
# running length coded string
33-
function runlength_string(::Type{T}, data) where T
33+
function runlength_string(::Type{T}, data; offset=10) where T
3434
out = T[]
3535
maxlength = length(data)
36-
# offsetjagg skip 10 bytes
37-
i = 11
36+
# offsetjagg skip
37+
i = offset + 1
3838
while true
3939
i+1 > maxlength && break
4040
_len = data[i]
@@ -46,10 +46,10 @@ function runlength_string(::Type{T}, data) where T
4646
out
4747
end
4848

49-
function interped_data(data::Vector{UInt8}, rawoffsets::Vector{Int32}, ::Type{Vector{T}}, ::Type{Offsetjagg}) where {T<:AbstractString}
49+
function interped_data(data::Vector{UInt8}, rawoffsets::Vector{Int32}, ::Type{Vector{T}}, ::Type{J}) where {T<:AbstractString, J<:Union{Offsetjagg, Offset6jagg}}
5050
rawoffsets .+= 1
5151
v = VectorOfVectors(data, rawoffsets)
52-
res = runlength_string.(T, v)
52+
res = runlength_string.(T, v; offset=offsetof(J))
5353
dummy = VectorOfVectors(res)
5454
# to maintain Int32 indexing
5555
return VectorOfVectors(dummy.data, Vector{Int32}(dummy.elem_ptr))

src/root.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ function auto_T_JaggT(f::ROOTFile, branch; customstructs::Dict{String, Type})
418418
streamer.fTypeName == "vector<unsigned char>" && return Vector{Vector{UInt8}}, _jaggtype
419419
end
420420

421+
# TODO: unclear if it's always a 6 byte offset but it solve issue #377
422+
# also note that utils.jl (JaggType(f, branch, leaf)) might be the better
423+
# place to determine jaggedness and offset size
424+
streamer.fTypeName == "string" && return Vector{String}, Offset6jagg
425+
421426
end
422427

423428
# some standard cases

src/utils.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ abstract type JaggType end
5454
struct Nojagg <:JaggType end
5555
struct Nooffsetjagg<:JaggType end
5656
struct Offsetjagg <:JaggType end
57+
struct Offset6jagg <:JaggType end
5758
struct Offsetjaggjagg <:JaggType end
5859
# this is a preliminary workaround for 6 byte offset jaggedness
5960
struct Offset6jaggjagg <:JaggType end
61+
offsetof(::Type{Offsetjagg}) = 10
62+
offsetof(::Type{Offset6jagg}) = 6
6063

6164
function JaggType(f, branch, leaf)
6265
# https://github.com/scikit-hep/uproot3/blob/54f5151fb7c686c3a161fbe44b9f299e482f346b/uproot3/interp/auto.py#L144
@@ -75,6 +78,11 @@ function JaggType(f, branch, leaf)
7578
# TODO: there are for sure also jagged strings, need to find files with those
7679
return Nojagg
7780
end
81+
# if typeof(streamer) <: TStreamerSTLstring
82+
# # TODO: unclear if this jagged/offset info should be passed from here
83+
# # or dealt with in root.jl. see issue #377 and PR #378
84+
# return Offsetjagg
85+
# end
7886
if streamer.fSTLtype == Const.kSTLvector
7987
(match(r"\[.*\]", leaf.fTitle) !== nothing) && return Offset6jaggjagg
8088
return Offsetjagg

test/issues.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ SAMPLES_DIR = joinpath(@__DIR__, "samples")
5757
@test 1200 == length(t)
5858
@test t[1].time[2] 36.396744f0
5959
@test t[end].xpos[end] 788.35144f0
60+
61+
# issue 377
62+
f = UnROOT.samplefile("issue377.root")
63+
arr = UnROOT.array(f, "podio_metadata/events___CollectionTypeInfo/events___CollectionTypeInfo.dataType")
64+
t = LazyTree(f, "podio_metadata", ["events___CollectionTypeInfo"])
65+
@test 1 == length(t.events___CollectionTypeInfo_dataType)
66+
@test 26 == length(t.events___CollectionTypeInfo_dataType[1])
67+
@test "edm4hep::CaloHitContributionCollection" == t.events___CollectionTypeInfo_dataType[1][1]
68+
@test "podio::LinkCollection<edm4hep::Vertex,edm4hep::ReconstructedParticle>" == t.events___CollectionTypeInfo_dataType[1][end]
69+
@test arr == t.events___CollectionTypeInfo_dataType
6070
end
6171

6272
function _test_clean_GC(fname)

test/samples/issue377.root

111 KB
Binary file not shown.

0 commit comments

Comments
 (0)