From a3e5dd6af6657f1c80b9239ae852116a6c011920 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 23 Aug 2022 16:49:39 +0200 Subject: [PATCH] remove Tr from created aliases changed alias creation / envlist mechanism --- commands.py | 4 +-- devices.py | 87 +++++++++++++++++++----------------------------- setups/frappy.py | 15 ++++----- 3 files changed, 42 insertions(+), 64 deletions(-) diff --git a/commands.py b/commands.py index 99d0e1c..4c6f025 100644 --- a/commands.py +++ b/commands.py @@ -109,7 +109,7 @@ def frappy_start(**services): all_cfg[service] = cfginfo if secnode: secnode('') - + # check cfg is not used twice for cfg in cfginfo.split(','): cfg = cfg.strip() @@ -230,7 +230,7 @@ def frappy_list(service=None): printTable(['command'], [['frappy_list(%r)' % s] for s in SERVICES], session.log.info) session.log.info(' ') for cfgdir in bases: - table.append('--- %s' % cfgdir) + table.append(['---\n', cfgdir]) for cfgfile in glob(join(cfgdir, '*.cfg')): parser = ConfigParser() parser.read(cfgfile) diff --git a/devices.py b/devices.py index c6d5caa..267e4ef 100644 --- a/devices.py +++ b/devices.py @@ -23,7 +23,7 @@ # ***************************************************************************** """managing SECoP server and connections -SEC Node with added functionality for starting and stoping frappy servers +SEC Node with added functionality for starting and stopping frappy servers connected to a SEC node """ @@ -31,7 +31,7 @@ import os from os.path import expanduser from nicos import config, session -from nicos.core import Override, Param, Moveable, status, UsageError +from nicos.core import Override, Param, Moveable, status from nicos.devices.secop import SecNodeDevice from nicos.core import Device, anytype, listof from nicos.utils.comparestrings import compare @@ -54,7 +54,6 @@ def applyAliasConfig(): # reimplemented from Session.applyAliasConfig # apply also when target dev name does not change, as the target device might have # be exchanged in the mean time - unused = set() for aliasname, targets in session.alias_config.items(): if aliasname not in session.devices: continue # silently ignore @@ -70,32 +69,22 @@ def applyAliasConfig(): class FrappyConfig(Device): # respect the order: e.g. temperature_regulation must be after temperature - # and temperature_drivable must be the last in the temperature group + # because it will not be added to envlist when temperature is the same device parameters = { 'temperature': Param( - 'config for sample temperature', type=anytype, - default={'alias': 'Ts'}), + 'config for sample temperature', type=anytype, default={}), 'temperature_regulation': Param( - 'config for temperature regulation', type=anytype, - default={'alias': 'Tr'}), - 'temperature_drivable': Param( - 'config for drivable temperature', type=anytype, - default={'alias': 'T', 'envlist': False}), + 'config for temperature regulation', type=anytype, default={}), 'magneticfield': Param( - 'config for magnetic field', type=anytype, - default={'alias': 'B'}), + 'config for magnetic field', type=anytype, default={}), 'rotation_z': Param( - 'config for sample rotation', type=anytype, - default={'alias': 'stickrot', 'envlist': False}), - 'stick_rotation_alias': Param( - 'alias to assign stick rotation', type=str, settable=True, default=''), + 'config for sample rotation', type=anytype, default={}), 'nodes': Param( 'list of names of potential SEC nodes', type=listof(str), default=[]), } meanings = list(parameters) meanings.remove('nodes') - meanings.remove('stick_rotation_alias') def remove_aliases(self): for meaning in self.meanings: @@ -145,56 +134,48 @@ class FrappyConfig(Device): sample_devices.setdefault(meaning_name, []).append((importance, devname)) devset = set() - newenv = {e: None for e in session.experiment.envlist} # use dict instead of set because of order - drivables = {} + newenv = {e: 1 for e in session.experiment.envlist} # use dict instead of set because of order for meaning in self.meanings: info = getattr(self, meaning) - aliasnames = info['alias'] + aliasnames = info.get('alias') + if aliasnames is None: + continue if isinstance(aliasnames, str): aliasnames = [aliasnames] - envlistflag = info.get('envlist', True) aliascfg = info.get('targets', {}) importance_list = sample_devices.get(meaning, []) importance_list.extend([(nr, nam) for nam, nr in aliascfg.items() if nam in session.devices]) importance_list = sorted(importance_list, reverse=True) session.log.debug('%s: %r', meaning, importance_list) - prefix, _, postfix = meaning.partition('_') - if postfix == 'drivable': - # append the previously collected drivables in the group to the importance_list - group = drivables.get(prefix, {}) - for key in 'regulation', '': - if key in group: - importance_list.append((None, group[key])) for _, devname, in importance_list: dev = session.devices.get(devname) - if isinstance(dev, Moveable): - drivables.setdefault(prefix, {})[postfix] = devname - elif postfix == 'drivable': - # marked as xxx_drivable, but not really drivable: skip + if dev is None or info.get('drivable_only', False) and not isinstance(dev, Moveable): continue - if dev: - for aliasname in aliasnames: - devcfg = ('nicos.core.DeviceAlias', {}) - session.configured_devices[aliasname] = devcfg - session.dynamic_devices[aliasname] = 'frappy' - aliasdev = previous_aliases.pop(aliasname, None) - if aliasdev: - session.log.debug('change alias %r -> %r', aliasname, devname) - else: - session.log.debug('create alias %r -> %r', aliasname, devname) - aliasdev = session.createDevice(aliasname, recreate=True, explicit=True) - aliasdev.alias = devname - aliasname = aliasnames[0] - if devname not in devset and envlistflag: - # take only the first one - devset.add(devname) - newenv[aliasname] = None + for aliasname in aliasnames: + devcfg = ('nicos.core.DeviceAlias', {}) + session.configured_devices[aliasname] = devcfg + session.dynamic_devices[aliasname] = 'frappy' # assign to frappy setup + aliasdev = previous_aliases.pop(aliasname, None) + if aliasdev: + session.log.debug('change alias %r -> %r', aliasname, devname) else: - newenv.pop(aliasname, None) - break + session.log.debug('create alias %r -> %r', aliasname, devname) + aliasdev = session.createDevice(aliasname, recreate=True, explicit=True) + aliasdev.alias = devname + aliasname = aliasnames[0] + if devname not in devset and info.get('envlist', True): + # take only the first one + # example: when 'temperature' and 'temperature_regulation' are the + # same device, it is not added twice + devset.add(devname) + newenv[aliasname] = 1 + elif aliasname in newenv: + newenv.pop(aliasname, None) + break else: for aliasname in aliasnames: - newenv.pop(aliasname, None) + if aliasname in newenv: + newenv.pop(aliasname, None) for aliasname in previous_aliases: session.destroyDevice(aliasname) diff --git a/setups/frappy.py b/setups/frappy.py index 3e73588..d813692 100644 --- a/setups/frappy.py +++ b/setups/frappy.py @@ -20,17 +20,14 @@ devices = dict( # device, using the given importance number, with similar values as # given by the SECoP standard (10: instrument, 20: cryostat, 30: insert) temperature = { # the SECoP meaning - 'alias': ['Ts', 'temperature'], # the name(s) to be given to the alias - 'targets': # possible devices in addition with importance - {'se_ts': 20, 'se_tt': 19, 'se_tm': 18}, + 'alias': ['Ts', 'temperature'], # the name(s) to be given to the alias + 'targets': # possible devices in addition with importance + {'se_ts': 20, 'se_tt': 19, 'se_tm': 18}, }, temperature_regulation = { - 'alias': 'Tr', - 'targets': {'se_tt': 20, 'se_tm': 19, 'se_T_stat': 18}, - }, - temperature_drivable = { 'alias': 'T', - 'envlist': False, + 'targets': {'se_ts': 20, 'se_tt': 19, 'se_tm': 18, 'se_T_stat': 17}, + 'drivable_only': True, }, magneticfield = { 'alias': ['B', 'magfield'], @@ -38,8 +35,8 @@ devices = dict( }, rotation_z = { 'alias': 'dom', - 'envlist': False, 'targets': {'se_om': 20, 'se_stickrot': 19}, + 'envlist': False, } ) )