remove Tr from created aliases
changed alias creation / envlist mechanism
This commit is contained in:
87
devices.py
87
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)
|
||||
|
Reference in New Issue
Block a user