Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3io
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
km3io
Commits
96425e22
Commit
96425e22
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Improve performance of bit parsing
parent
df4a7905
No related branches found
No related tags found
1 merge request
!7
Summaryslice status
Pipeline
#8006
passed with warnings
5 years ago
Stage: test
Stage: coverage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
km3io/daq.py
+24
-12
24 additions, 12 deletions
km3io/daq.py
tests/test_daq.py
+4
-4
4 additions, 4 deletions
tests/test_daq.py
with
28 additions
and
16 deletions
km3io/daq.py
+
24
−
12
View file @
96425e22
...
...
@@ -13,6 +13,8 @@ MINIMAL_RATE_HZ = 2.0e3
MAXIMAL_RATE_HZ
=
2.0e6
RATE_FACTOR
=
np
.
log
(
MAXIMAL_RATE_HZ
/
MINIMAL_RATE_HZ
)
/
255
CHANNEL_BITS_TEMPLATE
=
np
.
zeros
(
31
,
dtype
=
bool
)
@nb.vectorize
([
nb
.
int32
(
nb
.
int8
),
...
...
@@ -28,20 +30,30 @@ def get_rate(value):
return
MINIMAL_RATE_HZ
*
np
.
exp
(
value
*
RATE_FACTOR
)
def
unpack_bits
(
value
):
"""
Helper to unpack bits to bool flags (little endian)
@nb.guvectorize
(
"
void(i8, b1[:], b1[:])
"
,
"
(), (n) -> (n)
"
,
target
=
"
parallel
"
,
nopython
=
True
)
def
unpack_bits
(
value
,
bits_template
,
out
):
"""
Return a boolean array for a value
'
s bit representation.
This function also accepts arrays as input, the output shape will be
NxM where N is the number of input values and M the length of the
``bits_template`` array, which is just a dummy array, due to the weird
signature system of numba.
Parameters
----------
value : int32
The integer value to be parsed.
value: int or np.array(int) with shape (N,)
The binary value of containing the bit information
bits_template: np.array() with shape (M,)
The template for the output array, the only important is its shape
Returns
-------
np.array(bool) either with shape (M,) or (N, M)
"""
value
=
np
.
array
(
value
).
astype
(
np
.
int32
)
value
=
value
.
reshape
(
-
1
,
1
)
value
=
value
.
view
(
np
.
uint8
)
value
=
np
.
flip
(
value
,
axis
=
1
)
length
=
value
.
shape
[
0
]
return
np
.
unpackbits
(
value
).
reshape
(
length
,
-
1
).
astype
(
bool
)
for
i
in
range
(
bits_template
.
shape
[
0
]):
out
[
30
-
i
]
=
value
&
(
1
<<
i
)
>
0
def
get_channel_flags
(
value
):
...
...
@@ -53,8 +65,8 @@ def get_channel_flags(value):
The integer value to be parsed.
"""
channel_bits
=
np
.
bitwise_and
(
value
,
0x3FFFFFFF
)
flags
=
unpack_bits
(
channel_bits
)
return
np
.
flip
(
flags
,
axis
=
1
)
[:,
:
31
]
flags
=
unpack_bits
(
channel_bits
,
CHANNEL_BITS_TEMPLATE
)
return
np
.
flip
(
flags
,
axis
=
-
1
)
def
get_number_udp_packets
(
value
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_daq.py
+
4
−
4
View file @
96425e22
...
...
@@ -185,7 +185,7 @@ class TestSummaryslices(unittest.TestCase):
}
for
dom_id
,
fifo_status
in
dct_fifo_stat
.
items
():
frame
=
s
[
s
.
dom_id
==
dom_id
]
assert
any
(
get_channel_flags
(
frame
.
fifo
[
0
])
[
0
]
)
==
fifo_status
assert
any
(
get_channel_flags
(
frame
.
fifo
[
0
]))
==
fifo_status
def
test_has_udp_trailer
(
self
):
s
=
self
.
ss
.
slices
[
0
]
...
...
@@ -244,7 +244,7 @@ class TestSummaryslices(unittest.TestCase):
}
for
dom_id
,
high_rate_veto
in
dct_high_rate_veto
.
items
():
frame
=
s
[
s
.
dom_id
==
dom_id
]
assert
any
(
get_channel_flags
(
frame
.
hrv
[
0
])
[
0
]
)
==
high_rate_veto
assert
any
(
get_channel_flags
(
frame
.
hrv
[
0
]))
==
high_rate_veto
def
test_max_sequence_number
(
self
):
s
=
self
.
ss
.
slices
[
0
]
...
...
@@ -344,7 +344,7 @@ class TestSummaryslices(unittest.TestCase):
frame
=
s
[
s
.
dom_id
==
dom_id
]
assert
any
([
a
==
b
for
a
,
b
in
zip
(
get_channel_flags
(
frame
.
hrv
[
0
])
[
0
]
,
hrv_flags
)
for
a
,
b
in
zip
(
get_channel_flags
(
frame
.
hrv
[
0
]),
hrv_flags
)
])
def
test_fifo_flags
(
self
):
...
...
@@ -391,7 +391,7 @@ class TestSummaryslices(unittest.TestCase):
frame
=
s
[
s
.
dom_id
==
dom_id
]
assert
any
([
a
==
b
for
a
,
b
in
zip
(
get_channel_flags
(
frame
.
fifo
[
0
])
[
0
]
,
fifo_flags
)
get_channel_flags
(
frame
.
fifo
[
0
]),
fifo_flags
)
])
...
...
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