Skip to content
Snippets Groups Projects
Verified Commit 6e95b711 authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Clean up names

parent 64ed53d2
No related branches found
No related tags found
No related merge requests found
......@@ -50,12 +50,12 @@ julia> event = f.events[1]
KM3io.DAQEvent with 96 snapshot and 18 triggered hits
julia> event.triggered_hits[4:8]
5-element Vector{KM3io.KM3NETDAQTriggeredHit}:
KM3io.KM3NETDAQTriggeredHit(808447186, 0x00, 30733214, 0x19, 0x0000000000000016)
KM3io.KM3NETDAQTriggeredHit(808447186, 0x01, 30733214, 0x15, 0x0000000000000016)
KM3io.KM3NETDAQTriggeredHit(808447186, 0x02, 30733215, 0x15, 0x0000000000000016)
KM3io.KM3NETDAQTriggeredHit(808447186, 0x03, 30733214, 0x1c, 0x0000000000000016)
KM3io.KM3NETDAQTriggeredHit(808451907, 0x07, 30733441, 0x1e, 0x0000000000000004)
5-element Vector{KM3io.TriggeredHit}:
KM3io.TriggeredHit(808447186, 0x00, 30733214, 0x19, 0x0000000000000016)
KM3io.TriggeredHit(808447186, 0x01, 30733214, 0x15, 0x0000000000000016)
KM3io.TriggeredHit(808447186, 0x02, 30733215, 0x15, 0x0000000000000016)
KM3io.TriggeredHit(808447186, 0x03, 30733214, 0x1c, 0x0000000000000016)
KM3io.TriggeredHit(808451907, 0x07, 30733441, 0x1e, 0x0000000000000004)
julia> for event f.events
@show event.header.frame_index length(event.snapshot_hits)
......
......@@ -17,10 +17,10 @@ function Base.read(s::IO, ::Type{T}; legacy=false) where T<:DAQEvent
trigger_mask = read(s, Int64)
overlays = read(s, Int32)
header = KM3NETDAQEventHeader(det_id, run_id, timeslice_id, timestamp, ticks, trigger_counter, trigger_mask, overlays)
header = EventHeader(det_id, run_id, timeslice_id, timestamp, ticks, trigger_counter, trigger_mask, overlays)
n_triggered_hits = read(s, Int32)
triggered_hits = Vector{KM3NETDAQTriggeredHit}()
triggered_hits = Vector{TriggeredHit}()
sizehint!(triggered_hits, n_triggered_hits)
@inbounds for i 1:n_triggered_hits
dom_id = read(s, Int32)
......@@ -28,11 +28,11 @@ function Base.read(s::IO, ::Type{T}; legacy=false) where T<:DAQEvent
time = bswap(read(s, Int32))
tot = read(s, UInt8)
trigger_mask = read(s, Int64)
push!(triggered_hits, KM3NETDAQTriggeredHit(dom_id, channel_id, time, tot, trigger_mask))
push!(triggered_hits, TriggeredHit(dom_id, channel_id, time, tot, trigger_mask))
end
n_hits = read(s, Int32)
snapshot_hits = Vector{KM3NETDAQSnapshotHit}()
snapshot_hits = Vector{SnapshotHit}()
sizehint!(snapshot_hits, n_hits)
@inbounds for i 1:n_hits
dom_id = read(s, Int32)
......@@ -41,7 +41,7 @@ function Base.read(s::IO, ::Type{T}; legacy=false) where T<:DAQEvent
tot = read(s, UInt8)
key = (dom_id, channel_id, time, tot)
triggered = false
push!(snapshot_hits, KM3NETDAQSnapshotHit(dom_id, channel_id, time, tot))
push!(snapshot_hits, SnapshotHit(dom_id, channel_id, time, tot))
end
T(header, snapshot_hits, triggered_hits)
......
struct KM3NETDAQSnapshotHit <: UnROOT.CustomROOTStruct
dom_id::Int32
channel_id::UInt8
t::Int32
tot::UInt8
end
function UnROOT.readtype(io, T::Type{KM3NETDAQSnapshotHit})
function UnROOT.readtype(io, T::Type{SnapshotHit})
T(UnROOT.readtype(io, Int32), read(io, UInt8), read(io, Int32), read(io, UInt8))
end
function UnROOT.interped_data(rawdata, rawoffsets, ::Type{Vector{KM3NETDAQSnapshotHit}}, ::Type{T}) where {T <: UnROOT.JaggType}
UnROOT.splitup(rawdata, rawoffsets, KM3NETDAQSnapshotHit, skipbytes=10)
end
struct KM3NETDAQTriggeredHit <: UnROOT.CustomROOTStruct
dom_id::Int32
channel_id::UInt8
t::Int32
tot::UInt8
trigger_mask::UInt64
function UnROOT.interped_data(rawdata, rawoffsets, ::Type{Vector{SnapshotHit}}, ::Type{T}) where {T <: UnROOT.JaggType}
UnROOT.splitup(rawdata, rawoffsets, SnapshotHit, skipbytes=10)
end
UnROOT.packedsizeof(::Type{KM3NETDAQTriggeredHit}) = 24 # incl. cnt and vers
function UnROOT.readtype(io, T::Type{KM3NETDAQTriggeredHit})
UnROOT.packedsizeof(::Type{TriggeredHit}) = 24 # incl. cnt and vers
function UnROOT.readtype(io, T::Type{TriggeredHit})
dom_id = UnROOT.readtype(io, Int32)
channel_id = read(io, UInt8)
tdc = read(io, Int32)
......@@ -30,24 +16,12 @@ function UnROOT.readtype(io, T::Type{KM3NETDAQTriggeredHit})
trigger_mask = UnROOT.readtype(io, UInt64)
T(dom_id, channel_id, tdc, tot, trigger_mask)
end
function UnROOT.interped_data(rawdata, rawoffsets, ::Type{Vector{KM3NETDAQTriggeredHit}}, ::Type{T}) where {T <: UnROOT.JaggType}
UnROOT.splitup(rawdata, rawoffsets, KM3NETDAQTriggeredHit, skipbytes=10)
function UnROOT.interped_data(rawdata, rawoffsets, ::Type{Vector{TriggeredHit}}, ::Type{T}) where {T <: UnROOT.JaggType}
UnROOT.splitup(rawdata, rawoffsets, TriggeredHit, skipbytes=10)
end
struct KM3NETDAQEventHeader
detector_id::Int32
run::Int32
frame_index::Int32
UTC_seconds::UInt32
UTC_16nanosecondcycles::UInt32
trigger_counter::UInt64
trigger_mask::UInt64
overlays::UInt32
end
packedsizeof(::Type{KM3NETDAQEventHeader}) = 76
function UnROOT.readtype(io::IO, T::Type{KM3NETDAQEventHeader})
packedsizeof(::Type{EventHeader}) = 76
function UnROOT.readtype(io::IO, T::Type{EventHeader})
skip(io, 18)
detector_id = UnROOT.readtype(io, Int32)
run = UnROOT.readtype(io, Int32)
......@@ -62,15 +36,10 @@ function UnROOT.readtype(io::IO, T::Type{KM3NETDAQEventHeader})
overlays = UnROOT.readtype(io, UInt32)
T(detector_id, run, frame_index, UTC_seconds, UTC_16nanosecondcycles, trigger_counter, trigger_mask, overlays)
end
function UnROOT.interped_data(rawdata, rawoffsets, ::Type{KM3NETDAQEventHeader}, ::Type{T}) where {T <: UnROOT.JaggType}
UnROOT.splitup(rawdata, rawoffsets, KM3NETDAQEventHeader, jagged=false)
function UnROOT.interped_data(rawdata, rawoffsets, ::Type{EventHeader}, ::Type{T}) where {T <: UnROOT.JaggType}
UnROOT.splitup(rawdata, rawoffsets, EventHeader, jagged=false)
end
struct DAQEvent
header::KM3NETDAQEventHeader
snapshot_hits::Vector{KM3NETDAQSnapshotHit}
triggered_hits::Vector{KM3NETDAQTriggeredHit}
end
function Base.show(io::IO, e::DAQEvent)
print(io, "$(typeof(e)) with $(length(e.snapshot_hits)) snapshot and $(length(e.triggered_hits)) triggered hits")
end
......@@ -90,9 +59,9 @@ struct OnlineFile
function OnlineFile(filename::AbstractString)
customstructs = Dict(
"KM3NETDAQ::JDAQEvent.snapshotHits" => Vector{KM3NETDAQSnapshotHit},
"KM3NETDAQ::JDAQEvent.triggeredHits" => Vector{KM3NETDAQTriggeredHit},
"KM3NETDAQ::JDAQEvent.KM3NETDAQ::JDAQEventHeader" => KM3NETDAQEventHeader
"KM3NETDAQ::JDAQEvent.snapshotHits" => Vector{SnapshotHit},
"KM3NETDAQ::JDAQEvent.triggeredHits" => Vector{TriggeredHit},
"KM3NETDAQ::JDAQEvent.KM3NETDAQ::JDAQEventHeader" => EventHeader
)
fobj = UnROOT.ROOTFile(filename, customstructs=customstructs)
......@@ -118,15 +87,15 @@ end
function read_headers(f::OnlineFile)
data, offsets = UnROOT.array(f.fobj, "KM3NET_EVENT/KM3NET_EVENT/KM3NETDAQ::JDAQEventHeader"; raw=true)
UnROOT.splitup(data, offsets, KM3NETDAQEventHeader; jagged=false)
UnROOT.splitup(data, offsets, EventHeader; jagged=false)
end
function read_snapshot_hits(f::OnlineFile)
data, offsets = UnROOT.array(f.fobj, "KM3NET_EVENT/KM3NET_EVENT/snapshotHits"; raw=true)
UnROOT.splitup(data, offsets, KM3NETDAQSnapshotHit, skipbytes=10)
UnROOT.splitup(data, offsets, SnapshotHit, skipbytes=10)
end
function read_triggered_hits(f::OnlineFile)
data, offsets = UnROOT.array(f.fobj, "KM3NET_EVENT/KM3NET_EVENT/triggeredHits"; raw=true)
UnROOT.splitup(data, offsets, KM3NETDAQTriggeredHit, skipbytes=10)
UnROOT.splitup(data, offsets, TriggeredHit, skipbytes=10)
end
......@@ -34,11 +34,10 @@ abstract type AbstractDAQHit<:AbstractHit end
abstract type AbstractMCHit<:AbstractHit end
struct SnapshotHit <: AbstractDAQHit
channel_id::UInt8
dom_id::UInt32
t::Float64
channel_id::UInt8
t::Int32
tot::UInt8
trigger_mask::Int64
end
struct TriggeredHit <: AbstractDAQHit
......@@ -46,5 +45,22 @@ struct TriggeredHit <: AbstractDAQHit
channel_id::UInt8
t::Int32
tot::UInt8
trigger_mask::Int64
trigger_mask::UInt64
end
struct EventHeader
detector_id::Int32
run::Int32
frame_index::Int32
UTC_seconds::UInt32
UTC_16nanosecondcycles::UInt32
trigger_counter::UInt64
trigger_mask::UInt64
overlays::UInt32
end
struct DAQEvent
header::EventHeader
snapshot_hits::Vector{SnapshotHit}
triggered_hits::Vector{TriggeredHit}
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment