From 9a2dde1cc9db7e6ec4676ab76f55cfe8d6f1ec16 Mon Sep 17 00:00:00 2001 From: Tamas Gal <himself@tamasgal.com> Date: Thu, 5 Dec 2024 14:31:20 +0100 Subject: [PATCH] Improved displays --- src/KM3io.jl | 2 ++ src/displays.jl | 60 +++++++++++++++++++++++++++++++++++++++++++++ src/hardware.jl | 5 ---- src/root/offline.jl | 3 --- 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 src/displays.jl diff --git a/src/KM3io.jl b/src/KM3io.jl index 12a66790..c3f8394f 100644 --- a/src/KM3io.jl +++ b/src/KM3io.jl @@ -79,6 +79,8 @@ include("tools/helpers.jl") include("physics.jl") +include("displays.jl") + function __init__() @static if !isdefined(Base, :get_extension) diff --git a/src/displays.jl b/src/displays.jl new file mode 100644 index 00000000..fb2fa906 --- /dev/null +++ b/src/displays.jl @@ -0,0 +1,60 @@ +description(::Type) = "" +hasdescription(T::Type) = description(T) != "" + +function Base.show(io::IO, p::T) where T<:Union{Position, Direction} + @printf(io, "%s(%.3f, %.3f, %.3f)", T, p...) +end + +# DetectorModule +function Base.show(io::IO, m::DetectorModule) + print_object(io, m, multiline = false) +end + +function Base.show(io::IO, ::MIME"text/plain", m::DetectorModule) + multiline = get(io, :multiline, true) + print_object(io, m, multiline = multiline) +end + +function print_object(io::IO, m::DetectorModule; multiline::Bool) + if multiline + info = isbasemodule(m) ? "base" : "optical, $(m.n_pmts) PMTs" + println(io, "DetectorModule $(m.id) ($(info))") + println(io, " Location: string $(m.location.string), floor $(m.location.floor)") + println(io, " Position: $(m.pos)") + print(io, " Time offset: $(m.tâ‚€) ns") + else + info = isbasemodule(m) ? "BM" : "DOM" + print(io, "$info($(m.id)") + @printf(io, ", S%03d F%02d)", m.location.string, m.location.floor) + end +end + + +# Detector +Base.show(io::IO, d::Detector) = print(io, "Detector $(d.id) (v$(d.version)) with $(length(d.strings)) strings and $(d.n_modules) modules.") + +# Evt +function Base.show(io::IO, e::Evt) + print(io, "$(typeof(e)) ($(length(e.hits)) hits, $(length(e.mc_hits)) MC hits, $(length(e.trks)) tracks, $(length(e.mc_trks)) MC tracks)") +end + +function Base.show(io::IO, ::MIME"text/plain", e::Evt) + println(io, "MC Event (Evt) ($(length(e.hits)) hits, $(length(e.mc_hits)) MC hits, $(length(e.trks)) tracks, $(length(e.mc_trks)) MC tracks)") + println(io, " ID: $(e.id)") + println(io, " Detector ID: $(e.det_id)") + println(io, " MC ID: $(e.mc_id)") + println(io, " MC event time: $(e.mc_event_time)") + println(io, " Primary particle: $(first(e.mc_trks))") +end + +description(::Type{Trk}) = "Reconstructed track" +description(::Type{MCTrk}) = "Monte Carlo track" + +function Base.show(io::IO, ::MIME"text/plain", obj::T) where T<:Union{Trk, MCTrk, PMT, AbstractCalibratedHit, AbstractDAQHit} + print(io, T) + hasdescription(T) && print(io, " ($(description(T)))") + for (fn, ft) in zip(fieldnames(T), fieldtypes(T)) + val = getfield(obj, fn) + print(io, "\n $(fn): $(val)") + end +end diff --git a/src/hardware.jl b/src/hardware.jl index 9e690189..e32a7dcb 100644 --- a/src/hardware.jl +++ b/src/hardware.jl @@ -55,10 +55,6 @@ struct DetectorModule status::Int32 tâ‚€::Float64 end -function Base.show(io::IO, m::DetectorModule) - info = m.location.floor == 0 ? "base" : "optical, $(m.n_pmts) PMTs" - print(io, "Detectormodule ($(info)) on string $(m.location.string) floor $(m.location.floor)") -end Base.length(d::DetectorModule) = d.n_pmts Base.eltype(::Type{DetectorModule}) = PMT Base.iterate(d::DetectorModule, state=1) = state > d.n_pmts ? nothing : (d.pmts[state], state+1) @@ -287,7 +283,6 @@ end Return a vector of all modules of a given detector. """ modules(d::Detector) = collect(values(d.modules)) -Base.show(io::IO, d::Detector) = print(io, "Detector $(d.id) (v$(d.version)) with $(length(d.strings)) strings and $(d.n_modules) modules.") Base.length(d::Detector) = d.n_modules Base.eltype(::Type{Detector}) = DetectorModule function Base.iterate(d::Detector, state=(Int[], 1)) diff --git a/src/root/offline.jl b/src/root/offline.jl index 527036c8..2bcf756d 100644 --- a/src/root/offline.jl +++ b/src/root/offline.jl @@ -136,9 +136,6 @@ struct Evt flags::Int64 usr::Dict{String, Float64} end -function Base.show(io::IO, e::Evt) - print(io, "$(typeof(e)) ($(length(e.hits)) hits, $(length(e.mc_hits)) MC hits, $(length(e.trks)) tracks, $(length(e.mc_trks)) MC tracks)") -end struct MCHeader _raw::Dict{String, String} -- GitLab