Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
python-handel
Commits
b940c64f
Commit
b940c64f
authored
Sep 14, 2017
by
Vincent Michel
Browse files
Enhance statistics
parent
1daa7c07
Pipeline
#985
passed with stages
in 1 minute and 19 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
handel/interface.py
View file @
b940c64f
...
...
@@ -38,6 +38,28 @@ Stats = namedtuple(
'Stats'
,
'realtime livetime triggers events icr ocr deadtime'
)
def
stats_from_buffer
(
array
):
# Raw statistics
realtime
=
float
(
array
[
0
])
livetime
=
float
(
array
[
1
])
triggers
=
int
(
array
[
3
])
events
=
int
(
array
[
4
])
# ICR/OCR computation
# It turns out the hardware only keeps the integer part of the rate
# computations. It is improved here.
icr
=
triggers
/
livetime
ocr
=
events
/
realtime
assert
int
(
icr
)
==
int
(
array
[
5
])
assert
int
(
ocr
)
==
int
(
array
[
6
])
# Deadtime computation
# It's unclear whether icr=ocr=0 should result in a 0.0 or 1.0 deadtime
deadtime
=
1
-
float
(
ocr
)
/
icr
if
icr
!=
0
else
1.
return
Stats
(
realtime
,
livetime
,
triggers
,
events
,
icr
,
ocr
,
deadtime
)
def
to_bytes
(
arg
):
if
isinstance
(
arg
,
bytes
):
return
arg
...
...
@@ -174,19 +196,9 @@ def get_module_statistics(module):
code
=
handel
.
xiaGetRunData
(
master
,
b
'module_statistics'
,
data
)
check_error
(
code
)
# Parse raw data
result
=
{}
for
index
,
channel
in
enumerate
(
channels
):
if
channel
!=
-
1
:
realtime
=
array
[
index
*
7
+
0
]
livetime
=
array
[
index
*
7
+
1
]
triggers
=
int
(
array
[
index
*
7
+
3
])
events
=
int
(
array
[
index
*
7
+
4
])
icr
=
int
(
array
[
index
*
7
+
5
])
ocr
=
int
(
array
[
index
*
7
+
6
])
deadtime
=
1
-
float
(
ocr
)
/
icr
if
icr
!=
0
else
1.
result
[
channel
]
=
Stats
(
realtime
,
livetime
,
triggers
,
events
,
icr
,
ocr
,
deadtime
)
return
result
return
{
channel
:
stats_from_buffer
(
array
[
index
*
7
:])
for
index
,
channel
in
enumerate
(
channels
)
if
channel
!=
-
1
}
def
get_statistics
():
...
...
tests/test_interface.py
View file @
b940c64f
...
...
@@ -277,13 +277,28 @@ def test_get_module_statistics(interface):
m
=
interface
.
handel
.
xiaGetRunData
def
side_effect
(
channel
,
dtype
,
arg
):
arg
[
3
*
7
:
4
*
7
]
=
[
1.0
,
2.0
,
255
,
3
,
4
,
8
,
6
]
arg
[
3
*
7
:
4
*
7
]
=
[
1.00758784
,
0.98603936
,
255.
,
3088.
,
2742.
,
3131.
,
2721.
]
return
0
expected
=
{
8
:
interface
.
Stats
(
1.00758784
,
0.98603936
,
3088.
,
2742.
,
3131.720827046904
,
2721.350825353351
,
0.13103658479051494
)}
m
.
side_effect
=
side_effect
with
mock
.
patch
(
'handel.interface.get_module_channels'
)
as
m2
:
m2
.
return_value
=
[
-
1
,
-
1
,
-
1
,
8
]
expected
=
{
8
:
interface
.
Stats
(
1.0
,
2.0
,
3
,
4
,
8
,
6
,
0.25
)}
assert
interface
.
get_module_statistics
(
'module3'
)
==
expected
m2
.
assert_called_once_with
(
'module3'
)
arg
=
m
.
call_args
[
0
][
2
]
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment