Skip to content
Snippets Groups Projects
Commit 9f0ef5d2 authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

Merge branch 'master' into L2SS-574-move-hbat-code-to-recv

parents 2d670615 6c9006be
No related branches found
No related tags found
1 merge request!234Resolve L2SS-574 "Move hbat code to recv"
Subproject commit 6e48f0fddf5541bc66d9f57e31297c0027ea97b7 Subproject commit e313399d197d266e49d6da0442ea983c6f92adad
...@@ -72,7 +72,7 @@ class attribute_wrapper(attribute): ...@@ -72,7 +72,7 @@ class attribute_wrapper(attribute):
if access == AttrWriteType.READ_WRITE: if access == AttrWriteType.READ_WRITE:
""" if the attribute is of READ_WRITE type, assign the write function to it""" """ if the attribute is of READ_WRITE type, assign the write function to it"""
@only_in_states([DevState.STANDBY, DevState.ON], log=False) @only_in_states([DevState.STANDBY, DevState.ON, DevState.ALARM], log=False)
@fault_on_error() @fault_on_error()
def write_func_wrapper(device, value): def write_func_wrapper(device, value):
""" """
...@@ -86,7 +86,7 @@ class attribute_wrapper(attribute): ...@@ -86,7 +86,7 @@ class attribute_wrapper(attribute):
""" Assign the read function to the attribute""" """ Assign the read function to the attribute"""
@only_in_states([DevState.STANDBY, DevState.ON], log=False) @only_in_states([DevState.STANDBY, DevState.ON, DevState.ALARM], log=False)
@fault_on_error() @fault_on_error()
def read_func_wrapper(device): def read_func_wrapper(device):
""" """
......
...@@ -7,6 +7,7 @@ from tango import DeviceProxy, AttributeProxy, DevState, DevFailed ...@@ -7,6 +7,7 @@ from tango import DeviceProxy, AttributeProxy, DevState, DevFailed
import time import time
import json import json
import pkg_resources import pkg_resources
from functools import wraps
logger = logging.getLogger() logger = logging.getLogger()
...@@ -23,6 +24,19 @@ def attribute_name_from_url(attribute_name:str): ...@@ -23,6 +24,19 @@ def attribute_name_from_url(attribute_name:str):
return attribute_name return attribute_name
def attribute_name_url(attribute_name:str, tango_host:str = 'databaseds:10000'):
"""
For some operations Tango devices must be transformed from the form 'domain/family/name/attribute'
to 'tango://db:port/domain/family/name/attribute'
"""
if attribute_name.startswith('tango://'):
return attribute_name
if len(attribute_name.split('/')) != 4:
raise ValueError(f"Expected attribute name of format 'domain/family/name/attribute', got {attribute_name}")
return f"tango://{tango_host}/{attribute_name}"
def device_name_url(device_name:str, tango_host:str = 'databaseds:10000'): def device_name_url(device_name:str, tango_host:str = 'databaseds:10000'):
""" """
For some operations Tango devices must be transformed from the form 'domain/family/name' For some operations Tango devices must be transformed from the form 'domain/family/name'
...@@ -64,9 +78,9 @@ def warn_if_attribute_not_found(): ...@@ -64,9 +78,9 @@ def warn_if_attribute_not_found():
""" """
def inner(func): def inner(func):
@wraps(func) @wraps(func)
def warn_wrapper(self, *args, **kwargs): def warn_wrapper(self, attribute_name, *args, **kwargs):
try: try:
return func(self, *args, **kwargs) return func(self, attribute_name, *args, **kwargs)
except DevFailed as e: except DevFailed as e:
if e.args[0].reason == 'Attribute not found': if e.args[0].reason == 'Attribute not found':
logger.warning(f"Attribute {attribute_name} not found!") logger.warning(f"Attribute {attribute_name} not found!")
...@@ -245,10 +259,9 @@ class Archiver(): ...@@ -245,10 +259,9 @@ class Archiver():
for a in attrs_list: for a in attrs_list:
attr_fullname = f"{device_name}/{a}".lower() attr_fullname = f"{device_name}/{a}".lower()
attr_proxy = AttributeProxy(attr_fullname) attr_proxy = AttributeProxy(attr_fullname)
if attr_proxy.is_polled() is True: # if not polled attribute is also not archived if attr_proxy.is_polled() and not self.is_attribute_archived(attr_fullname): # if not polled attribute is also not archived
try: try:
es = DeviceProxy(es_name or self.get_next_subscriber()) # choose an e.s. or get the first one available es = DeviceProxy(es_name or self.get_next_subscriber()) # choose an e.s. or get the first one available
if es.AttributeList is None or not(self.cm.AttributeSearch(a)):
polling_period = attr_proxy.get_poll_period() or self.dev_polling_time polling_period = attr_proxy.get_poll_period() or self.dev_polling_time
archive_period = global_archive_period or int(attr_proxy.get_property('archive_period')['archive_period'][0]) or self.dev_archive_time archive_period = global_archive_period or int(attr_proxy.get_property('archive_period')['archive_period'][0]) or self.dev_archive_time
self.add_attribute_to_archiver(attr_fullname,polling_period=polling_period, self.add_attribute_to_archiver(attr_fullname,polling_period=polling_period,
...@@ -284,6 +297,7 @@ class Archiver(): ...@@ -284,6 +297,7 @@ class Archiver():
for a in attrs_list: for a in attrs_list:
try: try:
attr_fullname = f"{device_name}/{a}".lower() attr_fullname = f"{device_name}/{a}".lower()
if self.is_attribute_archived(attr_fullname):
self.remove_attribute_from_archiver(attr_fullname) self.remove_attribute_from_archiver(attr_fullname)
except Exception as e: except Exception as e:
raise Exception from e raise Exception from e
...@@ -331,16 +345,10 @@ class Archiver(): ...@@ -331,16 +345,10 @@ class Archiver():
""" """
attribute_name = attribute_name_from_url(attribute_name) attribute_name = attribute_name_from_url(attribute_name)
attributes = self.cm.AttributeSearch(attribute_name.lower()) attributes = self.cm.AttributeSearch(attribute_name.lower())
if len(attributes)>1:
# Handle case same attribute_name r/rw # search returns all matches in which attribute_name is part of the name,
if len(attributes)==2 and (attributes[0].endswith(attributes[1]+'w') or attributes[1].endswith(attributes[0]+'w')): # so check whether an exact match is included.
return True return attribute_name_url(attribute_name) in attributes
else:
raise Exception(f"Multiple Attributes Matched: {attributes}")
elif len(attributes)==1:
return True
else:
return False
def update_archiving_attribute(self, attribute_name: str, polling_period: int, event_period: int, strategy: str = 'RUN'): def update_archiving_attribute(self, attribute_name: str, polling_period: int, event_period: int, strategy: str = 'RUN'):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment