Skip to content

Commit db64c5c

Browse files
committed
Bootstrapping for a bunch of older versions of TClasses
1 parent 09bfa8d commit db64c5c

File tree

3 files changed

+167
-1
lines changed

3 files changed

+167
-1
lines changed

src/UnROOT.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ include("root.jl")
4747
include("iteration.jl")
4848
include("custom.jl")
4949
include("displays.jl")
50+
include("debug.jl")
5051

5152
using StructArrays: StructArray
5253

src/bootstrap.jl

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,22 @@ function readfields!(io, fields, T::Type{TAttAxis_4})
131131
end
132132

133133
abstract type TAxis <: ROOTStreamedObject end
134+
struct TAxis_9 <: TAxis end
134135
struct TAxis_10 <: TAxis end
136+
function readfields!(io, fields, T::Type{TAxis_9})
137+
# overrides things like fName,... that were set from the parent TH1 :(
138+
stream!(io, fields, TNamed)
139+
stream!(io, fields, TAttAxis)
140+
fields[:fNbins] = readtype(io, Int32)
141+
fields[:fXmin] = readtype(io, Float64)
142+
fields[:fXmax] = readtype(io, Float64)
143+
fields[:fXbins] = readtype(io, TArrayD)
144+
fields[:fFirst] = readtype(io, Int16)
145+
fields[:fLast] = readtype(io, Int16)
146+
fields[:fBits2] = readtype(io, UInt16)
147+
fields[:fTimeDisplay] = readtype(io, Bool)
148+
fields[:fTimeFormat] = readtype(io, String)
149+
end
135150
function readfields!(io, fields, T::Type{TAxis_10})
136151
# overrides things like fName,... that were set from the parent TH1 :(
137152
stream!(io, fields, TNamed)
@@ -148,6 +163,8 @@ function readfields!(io, fields, T::Type{TAxis_10})
148163
end
149164

150165
abstract type TH1 <: ROOTStreamedObject end
166+
struct TH1_7 <: TH1 end
167+
function readfields!(io, fields, T::Type{TH1_7}) end
151168
struct TH1_8 <: TH1 end
152169
function readfields!(io, fields, T::Type{TH1_8}) end
153170

@@ -976,6 +993,7 @@ function TH(io, tkey::TKey, refs)
976993
subfields = Dict{Symbol, Any}()
977994
stream!(io, subfields, TAxis, check=false)
978995
fields[Symbol(axis, :fLabels)] = readobjany!(io, tkey, refs)
996+
# FIXME: fModLabs only for TAxis v8+ !! We currently don't have access to its version... argh
979997
fields[Symbol(axis, :fModLabs)] = readobjany!(io, tkey, refs)
980998
for (k,v) in subfields
981999
fields[Symbol(axis, k)] = v
@@ -999,7 +1017,11 @@ function TH(io, tkey::TKey, refs)
9991017
skip(io, 1) # speedbump
10001018
fields[:fBuffer] = readtype(io, TArrayD)
10011019
fields[:fBinStatErrOpt] = readtype(io, Int16)
1002-
fields[:fStatOverflows] = readtype(io, Int16)
1020+
1021+
if preamble.version > 7
1022+
fields[:fStatOverflows] = readtype(io, Int16)
1023+
end
1024+
10031025

10041026
if is2d
10051027
for symb in [:fScalefactor, :fTsumwy, :fTsumwy2, :fTsumwxy]
@@ -1221,3 +1243,89 @@ function readfields!(c::Cursor, fields, ::Type{TFriendElement_2})
12211243
fields[:fTreeName] = readtype(c.io, String)
12221244
fields[:fOwnFile] = readtype(c.io, Bool)
12231245
end
1246+
1247+
1248+
abstract type TPaveStats <: ROOTStreamedObject end
1249+
Base.@kwdef struct TPaveStats_4 <: TPaveStats
1250+
fOptFit::Int
1251+
fOptStat::Int
1252+
fFitFormat::String
1253+
fStatFormat::String
1254+
fParent
1255+
end
1256+
function readfields!(c::Cursor, fields, ::Type{TPaveStats_4})
1257+
io = c.io
1258+
tkey = c.tkey
1259+
refs = c.refs
1260+
1261+
fields[:fOptFit] = readtype(c.io, Int32)
1262+
fields[:fOptStat] = readtype(c.io, Int32)
1263+
fields[:fFitFormat] = readtype(c.io, String)
1264+
fields[:fStatFormat] = readtype(c.io, String)
1265+
1266+
fields[:fParent] = unpack(io, tkey, refs, TObjArray)
1267+
end
1268+
1269+
abstract type TText <: ROOTStreamedObject end
1270+
Base.@kwdef struct TText_2 <: TText
1271+
fName
1272+
fTitle
1273+
fTextAngle::Float64
1274+
fTextSize::Float64
1275+
fTextAlign::Int8
1276+
fTextColor::Int8
1277+
fTextFont::Int8
1278+
fX::Float64
1279+
fY::Float64
1280+
end
1281+
function readfields!(io::IO, fields, ::Type{TText_2})
1282+
stream!(io, fields, TNamed)
1283+
stream!(io, fields, TAttText)
1284+
fields[:fX] = readtype(io, Float64)
1285+
fields[:fY] = readtype(io, Float64)
1286+
end
1287+
1288+
abstract type TAttText <: ROOTStreamedObject end
1289+
Base.@kwdef struct TAttText_1 <: TText
1290+
fTextAngle::Float32
1291+
fTextSize::Float32
1292+
fTextAlign::Int16
1293+
fTextColor::Int16
1294+
fTextFont::Int16
1295+
end
1296+
function readfields!(io::IO, fields, ::Type{TAttText_1})
1297+
fields[:fTextAngle] = readtype(io, Float32)
1298+
fields[:fTextSize] = readtype(io, Float32)
1299+
fields[:fTextAlign] = readtype(io, Int16)
1300+
fields[:fTextColor] = readtype(io, Int16)
1301+
fields[:fTextFont] = readtype(io, Int16)
1302+
end
1303+
1304+
abstract type TLatex <: ROOTStreamedObject end
1305+
Base.@kwdef struct TLatex_2 <: TLatex
1306+
cursor::Cursor
1307+
fName
1308+
fTitle
1309+
fTextAngle::Float32
1310+
fTextSize::Float32
1311+
fTextAlign::Int8
1312+
fTextColor::Int8
1313+
fTextFont::Int8
1314+
fX::Float64
1315+
fY::Float64
1316+
1317+
# TAttLine
1318+
fLineColor
1319+
fLineStyle
1320+
fLineWidth
1321+
1322+
fLimitFactorSize::Int
1323+
fOriginSize::Float64
1324+
end
1325+
1326+
function readfields!(c::Cursor, fields, ::Type{TLatex_2})
1327+
stream!(c.io, fields, TText)
1328+
stream!(c.io, fields, TAttLine)
1329+
fields[:fLimitFactorSize] = readtype(c.io, Int32)
1330+
fields[:fOriginSize] = readtype(c.io, Float64)
1331+
end

src/debug.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module Debug
2+
3+
import ..UnROOT: ROOTFile, streamerfor
4+
5+
function streamerdiff(f1::ROOTFile, f2::ROOTFile, classname::AbstractString)
6+
sinfo1 = streamerfor(f1, classname)
7+
sinfo2 = streamerfor(f2, classname)
8+
9+
println("==========")
10+
println("A: class version $(sinfo1.streamer.fClassVersion) (checksum: $(sinfo1.streamer.fCheckSum))")
11+
println("B: class version $(sinfo2.streamer.fClassVersion) (checksum: $(sinfo2.streamer.fCheckSum))")
12+
println()
13+
14+
deps1 = sinfo1.dependencies
15+
deps2 = sinfo2.dependencies
16+
17+
common_deps = union(deps1, deps2)
18+
println("Common dependencies: " * join(common_deps, ", "))
19+
20+
streamers1 = copy(sinfo1.streamer.fElements.elements)
21+
streamers2 = copy(sinfo2.streamer.fElements.elements)
22+
23+
while length(streamers1) > 0 && length(streamers2) > 0
24+
s1 = popfirst!(streamers1)
25+
s2 = popfirst!(streamers2)
26+
println("--------------")
27+
println("A: $(s1.fName)")
28+
println("B: $(s2.fName)")
29+
if s1 != s2
30+
fields1 = collect(fieldnames(typeof(s1)))
31+
fields2 = collect(fieldnames(typeof(s2)))
32+
while length(fields1) > 0 && length(fields2) > 0
33+
f1 = popfirst!(fields1)
34+
f2 = popfirst!(fields2)
35+
if f1 != f2
36+
println("Mismatch of fields: $f1 - $f2")
37+
break
38+
end
39+
v1 = getfield(s1, f1)
40+
v2 = getfield(s2, f2)
41+
if v1 != v2
42+
println("Mismatch of field values in $f1:")
43+
println(" A: $v1")
44+
println(" B: $v2")
45+
end
46+
end
47+
end
48+
end
49+
if length(streamers1) > 0
50+
println("\nMissing in B: " * join([s.fName for s in streamers1], ", "))
51+
end
52+
if length(streamers2) > 0
53+
println("\nMissing in A: " * join([s.fName for s in streamers2], ", "))
54+
end
55+
end
56+
57+
end

0 commit comments

Comments
 (0)