Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
e8afb0c2
Commit
e8afb0c2
authored
Aug 22, 2022
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-909
: Do not allow writes of smaller arrays
parent
ac25d4e9
No related branches found
No related tags found
1 merge request
!399
L2SS-909: Do not allow writes of smaller arrays
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py
+26
-0
26 additions, 0 deletions
...ncontrol/tangostationcontrol/clients/attribute_wrapper.py
with
26 additions
and
0 deletions
tangostationcontrol/tangostationcontrol/clients/attribute_wrapper.py
+
26
−
0
View file @
e8afb0c2
from
operator
import
mul
from
operator
import
mul
from
functools
import
reduce
from
functools
import
reduce
import
numpy
from
tango.server
import
attribute
from
tango.server
import
attribute
from
tango
import
AttrWriteType
,
AttReqType
from
tango
import
AttrWriteType
,
AttReqType
...
@@ -40,6 +41,21 @@ class attribute_io(object):
...
@@ -40,6 +41,21 @@ class attribute_io(object):
def
cached_write_function
(
self
,
value
):
def
cached_write_function
(
self
,
value
):
"""
Writes the given value to the device, and updates the cache.
"""
"""
Writes the given value to the device, and updates the cache.
"""
# flexible array sizes are not supported by all clients. make sure we only write arrays of maximum size.
if
self
.
attribute_wrapper
.
write_max_shape
and
self
.
attribute_wrapper
.
shape
!=
():
if
isinstance
(
value
,
numpy
.
ndarray
):
value_shape
=
value
.
shape
else
:
if
len
(
value
)
>
0
and
isinstance
(
value
[
0
],
list
):
# nested list
value_shape
=
(
len
(
value
),
len
(
value
[
0
]))
else
:
# straight list
value_shape
=
(
len
(
value
),)
if
value_shape
!=
self
.
attribute_wrapper
.
shape
:
raise
ValueError
(
f
"
Tried writing an array of shape
{
value_shape
}
into an attribute of shape
{
self
.
attribute_wrapper
.
shape
}
"
)
self
.
write_function
(
value
)
self
.
write_function
(
value
)
self
.
cached_value
=
value
self
.
cached_value
=
value
...
@@ -77,20 +93,30 @@ class attribute_wrapper(attribute):
...
@@ -77,20 +93,30 @@ class attribute_wrapper(attribute):
max_dim_x
=
1
max_dim_x
=
1
max_dim_y
=
0
max_dim_y
=
0
dtype
=
datatype
dtype
=
datatype
shape
=
()
elif
len
(
dims
)
==
1
:
elif
len
(
dims
)
==
1
:
max_dim_x
=
dims
[
0
]
max_dim_x
=
dims
[
0
]
max_dim_y
=
0
max_dim_y
=
0
dtype
=
(
datatype
,)
dtype
=
(
datatype
,)
shape
=
(
max_dim_x
,)
elif
len
(
dims
)
==
2
:
elif
len
(
dims
)
==
2
:
max_dim_x
=
dims
[
1
]
max_dim_x
=
dims
[
1
]
max_dim_y
=
dims
[
0
]
max_dim_y
=
dims
[
0
]
dtype
=
((
datatype
,),)
dtype
=
((
datatype
,),)
shape
=
(
max_dim_y
,
max_dim_x
)
else
:
else
:
# >2D arrays collapse into the X and Y dimensions. The Y (major) dimension mirrors the first dimension given, the
# >2D arrays collapse into the X and Y dimensions. The Y (major) dimension mirrors the first dimension given, the
# rest collapses into the X (minor) dimension.
# rest collapses into the X (minor) dimension.
max_dim_x
=
reduce
(
mul
,
dims
[
1
:])
max_dim_x
=
reduce
(
mul
,
dims
[
1
:])
max_dim_y
=
dims
[
0
]
max_dim_y
=
dims
[
0
]
dtype
=
((
datatype
,),)
dtype
=
((
datatype
,),)
shape
=
(
max_dim_y
,
max_dim_x
)
# actual shape of the data as it is read/written
self
.
shape
=
shape
# force maximum shape to be written (do not accept writes with shapes smaller than the maximum for each dimension)
self
.
write_max_shape
=
True
if
access
==
AttrWriteType
.
READ_WRITE
:
if
access
==
AttrWriteType
.
READ_WRITE
:
"""
If the attribute is of READ_WRITE type, assign the write and read functions to it
"""
"""
If the attribute is of READ_WRITE type, assign the write and read functions to it
"""
...
...
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
sign in
to comment