remove Tr from created aliases
changed alias creation / envlist mechanism
This commit is contained in:
@ -109,7 +109,7 @@ def frappy_start(**services):
|
|||||||
all_cfg[service] = cfginfo
|
all_cfg[service] = cfginfo
|
||||||
if secnode:
|
if secnode:
|
||||||
secnode('')
|
secnode('')
|
||||||
|
|
||||||
# check cfg is not used twice
|
# check cfg is not used twice
|
||||||
for cfg in cfginfo.split(','):
|
for cfg in cfginfo.split(','):
|
||||||
cfg = cfg.strip()
|
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)
|
printTable(['command'], [['frappy_list(%r)' % s] for s in SERVICES], session.log.info)
|
||||||
session.log.info(' ')
|
session.log.info(' ')
|
||||||
for cfgdir in bases:
|
for cfgdir in bases:
|
||||||
table.append('--- %s' % cfgdir)
|
table.append(['---\n', cfgdir])
|
||||||
for cfgfile in glob(join(cfgdir, '*.cfg')):
|
for cfgfile in glob(join(cfgdir, '*.cfg')):
|
||||||
parser = ConfigParser()
|
parser = ConfigParser()
|
||||||
parser.read(cfgfile)
|
parser.read(cfgfile)
|
||||||
|
87
devices.py
87
devices.py
@ -23,7 +23,7 @@
|
|||||||
# *****************************************************************************
|
# *****************************************************************************
|
||||||
"""managing SECoP server and connections
|
"""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
|
connected to a SEC node
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ import os
|
|||||||
from os.path import expanduser
|
from os.path import expanduser
|
||||||
|
|
||||||
from nicos import config, session
|
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.devices.secop import SecNodeDevice
|
||||||
from nicos.core import Device, anytype, listof
|
from nicos.core import Device, anytype, listof
|
||||||
from nicos.utils.comparestrings import compare
|
from nicos.utils.comparestrings import compare
|
||||||
@ -54,7 +54,6 @@ def applyAliasConfig():
|
|||||||
# reimplemented from Session.applyAliasConfig
|
# reimplemented from Session.applyAliasConfig
|
||||||
# apply also when target dev name does not change, as the target device might have
|
# apply also when target dev name does not change, as the target device might have
|
||||||
# be exchanged in the mean time
|
# be exchanged in the mean time
|
||||||
unused = set()
|
|
||||||
for aliasname, targets in session.alias_config.items():
|
for aliasname, targets in session.alias_config.items():
|
||||||
if aliasname not in session.devices:
|
if aliasname not in session.devices:
|
||||||
continue # silently ignore
|
continue # silently ignore
|
||||||
@ -70,32 +69,22 @@ def applyAliasConfig():
|
|||||||
|
|
||||||
class FrappyConfig(Device):
|
class FrappyConfig(Device):
|
||||||
# respect the order: e.g. temperature_regulation must be after temperature
|
# 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 = {
|
parameters = {
|
||||||
'temperature': Param(
|
'temperature': Param(
|
||||||
'config for sample temperature', type=anytype,
|
'config for sample temperature', type=anytype, default={}),
|
||||||
default={'alias': 'Ts'}),
|
|
||||||
'temperature_regulation': Param(
|
'temperature_regulation': Param(
|
||||||
'config for temperature regulation', type=anytype,
|
'config for temperature regulation', type=anytype, default={}),
|
||||||
default={'alias': 'Tr'}),
|
|
||||||
'temperature_drivable': Param(
|
|
||||||
'config for drivable temperature', type=anytype,
|
|
||||||
default={'alias': 'T', 'envlist': False}),
|
|
||||||
'magneticfield': Param(
|
'magneticfield': Param(
|
||||||
'config for magnetic field', type=anytype,
|
'config for magnetic field', type=anytype, default={}),
|
||||||
default={'alias': 'B'}),
|
|
||||||
'rotation_z': Param(
|
'rotation_z': Param(
|
||||||
'config for sample rotation', type=anytype,
|
'config for sample rotation', type=anytype, default={}),
|
||||||
default={'alias': 'stickrot', 'envlist': False}),
|
|
||||||
'stick_rotation_alias': Param(
|
|
||||||
'alias to assign stick rotation', type=str, settable=True, default=''),
|
|
||||||
'nodes': Param(
|
'nodes': Param(
|
||||||
'list of names of potential SEC nodes', type=listof(str), default=[]),
|
'list of names of potential SEC nodes', type=listof(str), default=[]),
|
||||||
}
|
}
|
||||||
|
|
||||||
meanings = list(parameters)
|
meanings = list(parameters)
|
||||||
meanings.remove('nodes')
|
meanings.remove('nodes')
|
||||||
meanings.remove('stick_rotation_alias')
|
|
||||||
|
|
||||||
def remove_aliases(self):
|
def remove_aliases(self):
|
||||||
for meaning in self.meanings:
|
for meaning in self.meanings:
|
||||||
@ -145,56 +134,48 @@ class FrappyConfig(Device):
|
|||||||
sample_devices.setdefault(meaning_name, []).append((importance, devname))
|
sample_devices.setdefault(meaning_name, []).append((importance, devname))
|
||||||
|
|
||||||
devset = set()
|
devset = set()
|
||||||
newenv = {e: None for e in session.experiment.envlist} # use dict instead of set because of order
|
newenv = {e: 1 for e in session.experiment.envlist} # use dict instead of set because of order
|
||||||
drivables = {}
|
|
||||||
for meaning in self.meanings:
|
for meaning in self.meanings:
|
||||||
info = getattr(self, meaning)
|
info = getattr(self, meaning)
|
||||||
aliasnames = info['alias']
|
aliasnames = info.get('alias')
|
||||||
|
if aliasnames is None:
|
||||||
|
continue
|
||||||
if isinstance(aliasnames, str):
|
if isinstance(aliasnames, str):
|
||||||
aliasnames = [aliasnames]
|
aliasnames = [aliasnames]
|
||||||
envlistflag = info.get('envlist', True)
|
|
||||||
aliascfg = info.get('targets', {})
|
aliascfg = info.get('targets', {})
|
||||||
importance_list = sample_devices.get(meaning, [])
|
importance_list = sample_devices.get(meaning, [])
|
||||||
importance_list.extend([(nr, nam) for nam, nr in aliascfg.items() if nam in session.devices])
|
importance_list.extend([(nr, nam) for nam, nr in aliascfg.items() if nam in session.devices])
|
||||||
importance_list = sorted(importance_list, reverse=True)
|
importance_list = sorted(importance_list, reverse=True)
|
||||||
session.log.debug('%s: %r', meaning, importance_list)
|
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:
|
for _, devname, in importance_list:
|
||||||
dev = session.devices.get(devname)
|
dev = session.devices.get(devname)
|
||||||
if isinstance(dev, Moveable):
|
if dev is None or info.get('drivable_only', False) and not isinstance(dev, Moveable):
|
||||||
drivables.setdefault(prefix, {})[postfix] = devname
|
|
||||||
elif postfix == 'drivable':
|
|
||||||
# marked as xxx_drivable, but not really drivable: skip
|
|
||||||
continue
|
continue
|
||||||
if dev:
|
for aliasname in aliasnames:
|
||||||
for aliasname in aliasnames:
|
devcfg = ('nicos.core.DeviceAlias', {})
|
||||||
devcfg = ('nicos.core.DeviceAlias', {})
|
session.configured_devices[aliasname] = devcfg
|
||||||
session.configured_devices[aliasname] = devcfg
|
session.dynamic_devices[aliasname] = 'frappy' # assign to frappy setup
|
||||||
session.dynamic_devices[aliasname] = 'frappy'
|
aliasdev = previous_aliases.pop(aliasname, None)
|
||||||
aliasdev = previous_aliases.pop(aliasname, None)
|
if aliasdev:
|
||||||
if aliasdev:
|
session.log.debug('change alias %r -> %r', aliasname, devname)
|
||||||
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
|
|
||||||
else:
|
else:
|
||||||
newenv.pop(aliasname, None)
|
session.log.debug('create alias %r -> %r', aliasname, devname)
|
||||||
break
|
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:
|
else:
|
||||||
for aliasname in aliasnames:
|
for aliasname in aliasnames:
|
||||||
newenv.pop(aliasname, None)
|
if aliasname in newenv:
|
||||||
|
newenv.pop(aliasname, None)
|
||||||
|
|
||||||
for aliasname in previous_aliases:
|
for aliasname in previous_aliases:
|
||||||
session.destroyDevice(aliasname)
|
session.destroyDevice(aliasname)
|
||||||
|
@ -20,17 +20,14 @@ devices = dict(
|
|||||||
# device, using the given importance number, with similar values as
|
# device, using the given importance number, with similar values as
|
||||||
# given by the SECoP standard (10: instrument, 20: cryostat, 30: insert)
|
# given by the SECoP standard (10: instrument, 20: cryostat, 30: insert)
|
||||||
temperature = { # the SECoP meaning
|
temperature = { # the SECoP meaning
|
||||||
'alias': ['Ts', 'temperature'], # the name(s) to be given to the alias
|
'alias': ['Ts', 'temperature'], # the name(s) to be given to the alias
|
||||||
'targets': # possible devices in addition with importance
|
'targets': # possible devices in addition with importance
|
||||||
{'se_ts': 20, 'se_tt': 19, 'se_tm': 18},
|
{'se_ts': 20, 'se_tt': 19, 'se_tm': 18},
|
||||||
},
|
},
|
||||||
temperature_regulation = {
|
temperature_regulation = {
|
||||||
'alias': 'Tr',
|
|
||||||
'targets': {'se_tt': 20, 'se_tm': 19, 'se_T_stat': 18},
|
|
||||||
},
|
|
||||||
temperature_drivable = {
|
|
||||||
'alias': 'T',
|
'alias': 'T',
|
||||||
'envlist': False,
|
'targets': {'se_ts': 20, 'se_tt': 19, 'se_tm': 18, 'se_T_stat': 17},
|
||||||
|
'drivable_only': True,
|
||||||
},
|
},
|
||||||
magneticfield = {
|
magneticfield = {
|
||||||
'alias': ['B', 'magfield'],
|
'alias': ['B', 'magfield'],
|
||||||
@ -38,8 +35,8 @@ devices = dict(
|
|||||||
},
|
},
|
||||||
rotation_z = {
|
rotation_z = {
|
||||||
'alias': 'dom',
|
'alias': 'dom',
|
||||||
'envlist': False,
|
|
||||||
'targets': {'se_om': 20, 'se_stickrot': 19},
|
'targets': {'se_om': 20, 'se_stickrot': 19},
|
||||||
|
'envlist': False,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user