mirror of
https://gitlab.cern.ch/wotsubo/PSBoardDataBase.git
synced 2025-06-08 05:55:42 +09:00
fix & new clock skew related functions
- exclude psbid 630 runid 190 from skew since the file is broken - add rise up span measure function
This commit is contained in:
parent
d0058f7f7b
commit
f551d66fd2
3 changed files with 65 additions and 4 deletions
|
@ -711,6 +711,7 @@ See [`ClockParser.get_skew`](@ref) for parse detail.
|
|||
|
||||
# Abnormal logs:
|
||||
- `48_nagoya_irradition_...`: skipped
|
||||
- `630_190`: broken file
|
||||
"""
|
||||
function add_skew_from_slave_clk_logs(db::SQLite.DB, logs_dir::AbstractString)
|
||||
stmt_insrt = DBInterface.prepare(
|
||||
|
@ -733,6 +734,11 @@ function add_skew_from_slave_clk_logs(db::SQLite.DB, logs_dir::AbstractString)
|
|||
error("Invalid filename $(file)")
|
||||
end
|
||||
|
||||
if m[:psbid] == "630" && m[:runid] == "190"
|
||||
@debug "skipping... (psbid=630 runid=190 is broken)"
|
||||
continue
|
||||
end
|
||||
|
||||
DBInterface.execute(
|
||||
stmt_insrt,
|
||||
(skew = ClockParser.get_skew(file), runid = m[:runid], psbid = m[:psbid]),
|
||||
|
|
|
@ -19,6 +19,7 @@ Invalid cases are:
|
|||
- no measurement has >500 counts => "Clock skew out of range"
|
||||
"""
|
||||
function get_skew(file::T) where {T <: AbstractString}
|
||||
@debug "file: $(file)"
|
||||
lines = Iterators.Stateful(eachline(file))
|
||||
|
||||
first_line = popfirst!(lines)
|
||||
|
@ -28,8 +29,6 @@ function get_skew(file::T) where {T <: AbstractString}
|
|||
if high > 0
|
||||
@debug "Unexpected first line" file
|
||||
return missing
|
||||
elseif high >= 500
|
||||
return time
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -83,4 +82,51 @@ function count_riseup(file::T) where {T <: AbstractString}
|
|||
# return sum(edges)
|
||||
end
|
||||
|
||||
"""
|
||||
Return Tuple of
|
||||
- skew (first time >500)
|
||||
- rise up full (last 0 to first 1000)
|
||||
|
||||
If clock is abnormal (i.e., which returns `missing` when [`get_skew`](@ref) is applied),
|
||||
this returns Tuple of 2 `missing`s.
|
||||
"""
|
||||
function get_skew_and_riseup(file::T) where {T <: AbstractString}
|
||||
lines = Iterators.Stateful(eachline(file))
|
||||
|
||||
last_low_time = 0.0
|
||||
first_high_time = 0.0
|
||||
skew = 0.0
|
||||
is_rised = false
|
||||
|
||||
let
|
||||
_time, high = _parse_line(popfirst!(lines))
|
||||
if high > 0
|
||||
@debug "Unexpected first line"
|
||||
return (missing, missing)
|
||||
elseif high == 0
|
||||
last_low_time = time
|
||||
end
|
||||
end
|
||||
|
||||
for line in lines
|
||||
time, high = _parse_line(line)
|
||||
if high == 0
|
||||
last_low_time = time
|
||||
elseif !is_rised && high >= 500
|
||||
skew = time
|
||||
is_rised = true
|
||||
elseif high == 1000
|
||||
first_high_time = time
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if first_high_time == 0
|
||||
@debug "Clock skew out of range"
|
||||
return (missing, missing)
|
||||
end
|
||||
|
||||
return (skew, first_high_time - last_low_time)
|
||||
end
|
||||
|
||||
end # module ClockParser
|
||||
|
|
|
@ -17,8 +17,17 @@ true || include("../src/PSBoardDataBase.jl")
|
|||
end
|
||||
|
||||
@testset "parse clk log" begin
|
||||
@test PSBoardDataBase.ClockParser.get_skew("input/slavelogs/main/230_51_clk.txt") |> ismissing
|
||||
@test PSBoardDataBase.ClockParser.get_skew("input/slavelogs/main/448_103_clk.txt") ≈ 12.000000000000000
|
||||
@test PSBoardDataBase.ClockParser.get_skew("input/slavelogs/main/230_51_clk.txt") |>
|
||||
ismissing
|
||||
@test PSBoardDataBase.ClockParser.get_skew("input/slavelogs/main/448_103_clk.txt") ≈
|
||||
12.000000000000000
|
||||
|
||||
@test PSBoardDataBase.ClockParser.get_skew_and_riseup(
|
||||
"input/slavelogs/main/230_51_clk.txt",
|
||||
) === (missing, missing, missing)
|
||||
@test PSBoardDataBase.ClockParser.get_skew_and_riseup(
|
||||
"input/slavelogs/main/448_103_clk.txt",
|
||||
) == (12.0, 12.053571428571429 - 11.982142857142858)
|
||||
end
|
||||
|
||||
@testset "Download data csv" begin
|
||||
|
|
Loading…
Add table
Reference in a new issue