Skip to content

Commit

Permalink
Change type of Polarization-Mon in IDFF
Browse files Browse the repository at this point in the history
  • Loading branch information
xresende committed Apr 23, 2024
1 parent 6d018d6 commit 7be3fdd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion siriuspy/siriuspy/devices/idff.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ def check_valid_value(self, value):
'List of corrlabels in config is not consistent')

# check nrpts in tables
param = 'pparameter' if polarization == 'none' else 'kparameter'
pol_none = _IDSearch.POL_NONE_STR
param = 'pparameter' if polarization == pol_none else 'kparameter'
nrpts_corrtables = {len(table) for table in corrtable.values()}
nrpts_kparameter = set([len(table[param]), ])
symm_diff = nrpts_corrtables ^ nrpts_kparameter
Expand Down
5 changes: 3 additions & 2 deletions siriuspy/siriuspy/idff/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def calculate_setpoints(
if self._value:
setpoints = dict()
idff = self._value['polarizations'][polarization]
if polarization == 'none':
if polarization == _IDSearch.POL_NONE_STR:
params = idff['pparameter']
param_value = pparameter_value
else:
Expand Down Expand Up @@ -248,7 +248,8 @@ def check_valid_value(self, value):
'List of corrlabels in config is not consistent')

# check nrpts in tables
param = 'pparameter' if polarization == 'none' else 'kparameter'
pol_none = _IDSearch.POL_NONE_STR
param = 'pparameter' if polarization == pol_none else 'kparameter'
nrpts_corrtables = {len(table) for table in corrtable.values()}
nrpts_kparameter = set([len(table[param]), ])
symm_diff = nrpts_corrtables ^ nrpts_kparameter
Expand Down
5 changes: 4 additions & 1 deletion siriuspy/siriuspy/idff/csdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, idname):
fname = fname.lower()
self.autosave_fname = _os.path.join(ioc_fol, fname+'.txt')
qsnames = _IDSearch.conv_idname_2_idff_qsnames(idname)
self.pol_sts = _IDSearch.conv_idname_2_polarizations_sts(self.idname)
self.has_qscorrs = True if qsnames else False

def get_propty_database(self):
Expand All @@ -70,7 +71,9 @@ def get_propty_database(self):
'unit': 'Hz', 'prec': 3,
'lolim': self.DEFAULT_LOOP_FREQ_MIN,
'hilim': self.DEFAULT_LOOP_FREQ_MAX},
'Polarization-Mon': {'type': 'string', 'value': 'none'},
'Polarization-Mon': {
'type': 'enum', 'enums': self.pols_sts,
'value': self.pols_sts.index(_IDSearch.POL_UNDEF_STR)},
'ConfigName-SP': {'type': 'string', 'value': ''},
'ConfigName-RB': {'type': 'string', 'value': ''},
'CorrConfig-Cmd': {'type': 'int', 'value': 0},
Expand Down
20 changes: 13 additions & 7 deletions siriuspy/siriuspy/idff/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import time as _time

import epics as _epics
import numpy as _np

from ..search import IDSearch as _IDSearch
from ..util import update_bit as _updt_bit
from ..callbacks import Callback as _Callback
from ..clientconfigdb import ConfigDBException as _ConfigDBException
Expand All @@ -30,7 +29,7 @@ def __init__(self, idname):
self._loop_state = _Const.DEFAULT_LOOP_STATE
self._loop_freq = _Const.DEFAULT_LOOP_FREQ
self._control_qs = _Const.DEFAULT_CONTROL_QS
self._polarization = 'none'
self._polarization = self._const.pol_sts.index(_IDSearch.POL_UNDEF_STR)
self._config_name = ''
self.read_autosave_file()

Expand Down Expand Up @@ -291,9 +290,16 @@ def _do_sleep(self, time0, tplanned):

def _do_update_polarization(self):
new_pol, *_ = self._idff.get_polarization_state()
if new_pol is not None and new_pol != self._polarization:
self._polarization = new_pol
self.run_callbacks('Polarization-Mon', new_pol)
if new_pol is None:
self._update_log('ERR: new polarization is None')
return
try:
new_pol_idx = self._const.pol_sts.index(new_pol)
except ValueError:
self._update_log('ERR: could not find index of polarization')
if new_pol_idx != self._polarization:
self._polarization = new_pol_idx
self.run_callbacks('Polarization-Mon', new_pol_idx)

def _do_update_correctors(self):
try:
Expand All @@ -306,7 +312,7 @@ def _do_update_correctors(self):
# print('setpoints: ', setpoints)
# print()
except ValueError as err:
self._update_log('ERR:'+str(err))
self._update_log('ERR: ' + str(err))

def _do_implement_correctors(self):
corrdevs = None
Expand Down

0 comments on commit 7be3fdd

Please sign in to comment.