Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3mon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
km3py
km3mon
Commits
b92d571c
Commit
b92d571c
authored
6 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Add run change indicators
parent
899d424f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/trigger_rates.py
+68
-26
68 additions, 26 deletions
scripts/trigger_rates.py
with
68 additions
and
26 deletions
scripts/trigger_rates.py
+
68
−
26
View file @
b92d571c
...
...
@@ -35,11 +35,10 @@ import matplotlib.dates as md
import
km3pipe
as
kp
from
km3pipe.config
import
Config
from
km3pipe.io.daq
import
(
DAQPreamble
,
DAQEvent
,
is_3dshower
,
is_3dmuon
,
is_mxshower
)
from
km3pipe.io.daq
import
(
DAQPreamble
,
DAQEvent
,
is_3dshower
,
is_3dmuon
,
is_mxshower
)
import
km3pipe.style
VERSION
=
"
1.0
"
km3pipe
.
style
.
use
(
'
km3pipe
'
)
...
...
@@ -47,8 +46,8 @@ km3pipe.style.use('km3pipe')
class
TriggerRate
(
kp
.
Module
):
def
configure
(
self
):
self
.
plots_path
=
self
.
require
(
'
plots_path
'
)
self
.
interval
=
self
.
get
(
"
interval
"
,
default
=
self
.
trigger_rate_sampling_period
())
self
.
interval
=
self
.
get
(
"
interval
"
,
default
=
self
.
trigger_rate_sampling_period
())
self
.
filename
=
self
.
get
(
"
filename
"
,
default
=
"
trigger_rates
"
)
self
.
with_minor_ticks
=
self
.
get
(
"
with_minor_ticks
"
,
default
=
False
)
print
(
"
Update interval: {}s
"
.
format
(
self
.
interval
))
...
...
@@ -56,18 +55,25 @@ class TriggerRate(kp.Module):
self
.
trigger_rates
=
OrderedDict
()
self
.
styles
=
{
"
xfmt
"
:
md
.
DateFormatter
(
'
%Y-%m-%d %H:%M
'
),
"
general
"
:
dict
(
markersize
=
6
,
linestyle
=
'
None
'
),
"
Overall
"
:
dict
(
marker
=
'
D
'
,
markerfacecolor
=
'
None
'
,
markeredgecolor
=
'
tomato
'
,
markeredgewidth
=
1
),
"
3DMuon
"
:
dict
(
marker
=
'
X
'
,
markerfacecolor
=
'
dodgerblue
'
),
"
MXShower
"
:
dict
(
marker
=
'
v
'
,
markerfacecolor
=
'
orange
'
),
"
3DShower
"
:
dict
(
marker
=
'
^
'
,
markerfacecolor
=
'
olivedrab
'
),
"
xfmt
"
:
md
.
DateFormatter
(
'
%Y-%m-%d %H:%M
'
),
"
general
"
:
dict
(
markersize
=
6
,
linestyle
=
'
None
'
),
"
Overall
"
:
dict
(
marker
=
'
D
'
,
markerfacecolor
=
'
None
'
,
markeredgecolor
=
'
tomato
'
,
markeredgewidth
=
1
),
"
3DMuon
"
:
dict
(
marker
=
'
X
'
,
markerfacecolor
=
'
dodgerblue
'
),
"
MXShower
"
:
dict
(
marker
=
'
v
'
,
markerfacecolor
=
'
orange
'
),
"
3DShower
"
:
dict
(
marker
=
'
^
'
,
markerfacecolor
=
'
olivedrab
'
),
}
queue_len
=
int
(
60
*
24
/
(
self
.
interval
/
60
))
queue_len
=
int
(
60
*
24
/
(
self
.
interval
/
60
))
for
trigger
in
[
"
Overall
"
,
"
3DMuon
"
,
"
MXShower
"
,
"
3DShower
"
]:
self
.
trigger_rates
[
trigger
]
=
deque
(
maxlen
=
queue_len
)
...
...
@@ -75,6 +81,9 @@ class TriggerRate(kp.Module):
self
.
thread
=
threading
.
Thread
(
target
=
self
.
plot
).
start
()
self
.
lock
=
threading
.
Lock
()
self
.
run_changes
=
[]
self
.
current_run_id
=
0
def
process
(
self
,
blob
):
if
not
str
(
blob
[
'
CHPrefix
'
].
tag
)
==
'
IO_EVT
'
:
return
blob
...
...
@@ -85,6 +94,9 @@ class TriggerRate(kp.Module):
data_io
=
BytesIO
(
data
)
preamble
=
DAQPreamble
(
file_obj
=
data_io
)
# noqa
event
=
DAQEvent
(
file_obj
=
data_io
)
if
event
.
header
.
run
>
self
.
current_run_id
:
self
.
current_run_id
=
event
.
header
.
run
self
.
_log_run_change
()
tm
=
event
.
trigger_mask
with
self
.
lock
:
self
.
trigger_counts
[
"
Overall
"
]
+=
1
...
...
@@ -96,9 +108,22 @@ class TriggerRate(kp.Module):
return
blob
def
_log_run_change
(
self
):
now
=
datetime
.
utcnow
()
self
.
run_changes
.
append
((
now
,
self
.
current_run_id
))
def
_remove_run_changes_out_of_range
(
self
):
new_run_changes
=
[]
min_timestamp
=
min
(
self
.
trigger_rates
[
'
Overall
'
])[
0
]
for
timestamp
,
run
in
self
.
run_changes
:
if
timestamp
>
min_timestamp
:
new_run_changes
.
append
((
timestamp
,
run
))
self
.
run_changes
=
new_run_changes
def
plot
(
self
):
while
self
.
run
:
time
.
sleep
(
self
.
interval
)
self_remove_run_changes_out_of_range
()
self
.
create_plot
()
def
create_plot
(
self
):
...
...
@@ -119,12 +144,27 @@ class TriggerRate(kp.Module):
self
.
log
.
warning
(
"
Empty rates, skipping...
"
)
continue
timestamps
,
trigger_rates
=
zip
(
*
rates
)
ax
.
plot
(
timestamps
,
trigger_rates
,
**
self
.
styles
[
trigger
],
**
self
.
styles
[
'
general
'
],
label
=
trigger
)
ax
.
set_title
(
"
Trigger Rates
\n
{0} UTC
"
.
format
(
datetime
.
utcnow
().
strftime
(
"
%c
"
)))
ax
.
plot
(
timestamps
,
trigger_rates
,
**
self
.
styles
[
trigger
],
**
self
.
styles
[
'
general
'
],
label
=
trigger
)
for
run_start
,
run
in
self
.
run_changes
:
plt
.
text
(
run_start
,
0.1
,
"
\n
RUN %s
"
%
run
,
rotation
=
90
,
verticalalignment
=
'
bottom
'
,
fontsize
=
8
,
color
=
'
gray
'
)
ax
.
axvline
(
run_start
,
color
=
'
#ff0f5b
'
,
linestyle
=
'
--
'
,
alpha
=
0.8
)
# added
ax
.
set_title
(
"
Trigger Rates
\n
{0} UTC
"
.
format
(
datetime
.
utcnow
().
strftime
(
"
%c
"
)))
ax
.
set_xlabel
(
"
time
"
)
ax
.
set_ylabel
(
"
trigger rate [Hz]
"
)
ax
.
xaxis
.
set_major_formatter
(
self
.
styles
[
"
xfmt
"
])
...
...
@@ -175,11 +215,13 @@ def main():
ligier_port
=
int
(
args
[
'
-p
'
])
pipe
=
kp
.
Pipeline
()
pipe
.
attach
(
kp
.
io
.
ch
.
CHPump
,
host
=
ligier_ip
,
port
=
ligier_port
,
tags
=
'
IO_EVT
'
,
timeout
=
60
*
60
*
24
*
7
,
max_queue
=
200000
)
pipe
.
attach
(
kp
.
io
.
ch
.
CHPump
,
host
=
ligier_ip
,
port
=
ligier_port
,
tags
=
'
IO_EVT
'
,
timeout
=
60
*
60
*
24
*
7
,
max_queue
=
200000
)
pipe
.
attach
(
TriggerRate
,
interval
=
300
,
plots_path
=
plots_path
)
pipe
.
drain
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment