revert to: allow multiple names for SE aliases
remark: 'frappy' setup should be moved to instrument setups
This commit is contained in:
74
devices.py
74
devices.py
@ -54,6 +54,7 @@ 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
|
||||||
@ -67,67 +68,45 @@ def applyAliasConfig():
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
class FrappyAliases(Device):
|
|
||||||
parameters = {
|
|
||||||
'temperature': Param(
|
|
||||||
'config for sample temperature', type=str, default='Ts'),
|
|
||||||
'temperature_regulation': Param(
|
|
||||||
'config for temperature regulation', type=str, default='Tr'),
|
|
||||||
'temperature_drivable': Param(
|
|
||||||
'config for drivable temperature', type=anytype, default='T'),
|
|
||||||
'magneticfield': Param(
|
|
||||||
'config for magnetic field', type=anytype, default='B'),
|
|
||||||
'rotation_z': Param(
|
|
||||||
'config for sample rotation', type=anytype, default='dom'),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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
|
# and temperature_drivable must be the last in the temperature group
|
||||||
parameters = {
|
parameters = {
|
||||||
'temperature': Param(
|
'temperature': Param(
|
||||||
'config for sample temperature', type=anytype,
|
'config for sample temperature', type=anytype,
|
||||||
default={'alias': 'temperature'}),
|
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(
|
'temperature_drivable': Param(
|
||||||
'config for drivable temperature', type=anytype,
|
'config for drivable temperature', type=anytype,
|
||||||
default={'envlist': False}),
|
default={'alias': 'T', 'envlist': False}),
|
||||||
'magneticfield': Param(
|
'magneticfield': Param(
|
||||||
'config for magnetic field', type=anytype,
|
'config for magnetic field', type=anytype,
|
||||||
default={'alias': 'magfield'}),
|
default={'alias': 'B'}),
|
||||||
'rotation_z': Param(
|
'rotation_z': Param(
|
||||||
'config for sample rotation', type=anytype,
|
'config for sample rotation', type=anytype,
|
||||||
default={'envlist': False}),
|
default={'alias': 'stickrot', 'envlist': False}),
|
||||||
'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=[]),
|
||||||
}
|
}
|
||||||
parameter_overrides = {
|
|
||||||
# frappy_config does not need to be visible
|
|
||||||
'visibility': Override(default=[])
|
|
||||||
}
|
|
||||||
|
|
||||||
meanings = list(parameters)
|
meanings = list(parameters)
|
||||||
meanings.remove('nodes')
|
meanings.remove('nodes')
|
||||||
|
|
||||||
def remove_aliases(self):
|
def remove_aliases(self):
|
||||||
|
for meaning in self.meanings:
|
||||||
def remove_alias(aliasname):
|
info = getattr(self, meaning)
|
||||||
if aliasname:
|
aliasnames = info['alias']
|
||||||
|
if isinstance(aliasname, str):
|
||||||
|
aliasnames = [aliasnames]
|
||||||
|
for aliasname in aliasnames:
|
||||||
aliasdev = session.devices.get(aliasname)
|
aliasdev = session.devices.get(aliasname)
|
||||||
if aliasdev:
|
if aliasdev:
|
||||||
session.destroyDevice(aliasname)
|
session.destroyDevice(aliasname)
|
||||||
session.configured_devices.pop(aliasname, None)
|
session.configured_devices.pop(aliasname, None)
|
||||||
session.dynamic_devices.pop(aliasname, None)
|
session.dynamic_devices.pop(aliasname, None)
|
||||||
|
|
||||||
frappy_aliases = session.devices.get('frappy_aliases')
|
|
||||||
for meaning in self.meanings:
|
|
||||||
info = getattr(self, meaning)
|
|
||||||
remove_alias(info.get('alias'))
|
|
||||||
remove_alias(getattr(frappy_aliases, meaning, None))
|
|
||||||
|
|
||||||
def set_envlist(self):
|
def set_envlist(self):
|
||||||
"""create aliases for SECoP devices
|
"""create aliases for SECoP devices
|
||||||
|
|
||||||
@ -151,11 +130,11 @@ class FrappyConfig(Device):
|
|||||||
devset = set()
|
devset = set()
|
||||||
newenv = {e: None for e in session.experiment.envlist} # use dict instead of set because of order
|
newenv = {e: None for e in session.experiment.envlist} # use dict instead of set because of order
|
||||||
drivables = {}
|
drivables = {}
|
||||||
frappy_aliases = session.get('frappy_aliases')
|
|
||||||
for meaning in self.meanings:
|
for meaning in self.meanings:
|
||||||
info = getattr(self, meaning)
|
info = getattr(self, meaning)
|
||||||
aliasname = getattr(frappy_aliases, meaning, None)
|
aliasnames = info['alias']
|
||||||
additional = info.get('alias')
|
if isinstance(aliasnames, str):
|
||||||
|
aliasnames = [aliasnames]
|
||||||
envlistflag = info.get('envlist', True)
|
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, [])
|
||||||
@ -177,12 +156,14 @@ class FrappyConfig(Device):
|
|||||||
# marked as xxx_drivable, but not really drivable: skip
|
# marked as xxx_drivable, but not really drivable: skip
|
||||||
continue
|
continue
|
||||||
if dev:
|
if dev:
|
||||||
session.log.debug('create alias %r pointing to %r', aliasname, devname)
|
for aliasname in aliasnames:
|
||||||
devcfg = ('nicos.core.DeviceAlias', {})
|
session.log.debug('create alias %r pointing to %r', aliasname, devname)
|
||||||
session.configured_devices[aliasname] = devcfg
|
devcfg = ('nicos.core.DeviceAlias', {})
|
||||||
session.dynamic_devices[aliasname] = 'frappy_alias'
|
session.configured_devices[aliasname] = devcfg
|
||||||
aliasdev = session.createDevice(aliasname, recreate=True, explicit=True)
|
session.dynamic_devices[aliasname] = 'frappy'
|
||||||
aliasdev.alias = devname
|
aliasdev = session.createDevice(aliasname, recreate=True, explicit=True)
|
||||||
|
aliasdev.alias = devname
|
||||||
|
aliasname = aliasnames[0]
|
||||||
if devname not in devset and envlistflag:
|
if devname not in devset and envlistflag:
|
||||||
# take only the first one
|
# take only the first one
|
||||||
devset.add(devname)
|
devset.add(devname)
|
||||||
@ -190,14 +171,9 @@ class FrappyConfig(Device):
|
|||||||
else:
|
else:
|
||||||
newenv.pop(aliasname, None)
|
newenv.pop(aliasname, None)
|
||||||
break
|
break
|
||||||
if additional:
|
|
||||||
session.configured_devices[additional] = devcfg.copy()
|
|
||||||
session.dynamic_devices[additional] = 'frappy'
|
|
||||||
aliasdev = session.createDevice(additional, recreate=True, explicit=True)
|
|
||||||
aliasdev.alias = devname
|
|
||||||
else:
|
else:
|
||||||
newenv.pop(aliasname, None)
|
for aliasname in aliasnames:
|
||||||
newenv.pop(additional, None)
|
newenv.pop(aliasname, None)
|
||||||
|
|
||||||
applyAliasConfig() # for other aliases
|
applyAliasConfig() # for other aliases
|
||||||
if set(newenv) != set(session.experiment.envlist):
|
if set(newenv) != set(session.experiment.envlist):
|
||||||
|
@ -6,6 +6,8 @@ modules = ['nicos_sinq.frappy_sinq.commands']
|
|||||||
devices = dict(
|
devices = dict(
|
||||||
frappy_config = device(
|
frappy_config = device(
|
||||||
'nicos_sinq.frappy_sinq.devices.FrappyConfig',
|
'nicos_sinq.frappy_sinq.devices.FrappyConfig',
|
||||||
|
# frappy_config does not need to be visible
|
||||||
|
visibility = [],
|
||||||
# the possible SECoP connections
|
# the possible SECoP connections
|
||||||
nodes = ['se_main', 'se_stick', 'se_addons'],
|
nodes = ['se_main', 'se_stick', 'se_addons'],
|
||||||
#
|
#
|
||||||
@ -17,22 +19,25 @@ devices = dict(
|
|||||||
# the devices with the names given by key are added to determine the
|
# the devices with the names given by key are added to determine the
|
||||||
# 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)
|
||||||
# for the name of the created aliases see the instrument specific
|
|
||||||
# setup 'frappy_aliases'
|
|
||||||
temperature = { # the SECoP meaning
|
temperature = { # the SECoP meaning
|
||||||
# possible devices in addition to SECoP meaning (with importance)
|
'alias': ['Ts', 'temperature'], # the name(s) to be given to the alias
|
||||||
'targets': {'se_ts': 20, 'se_tt': 19, 'se_tm': 18},
|
'targets': # possible devices in addition with importance
|
||||||
|
{'se_ts': 20, 'se_tt': 19, 'se_tm': 18},
|
||||||
},
|
},
|
||||||
temperature_regulation = {
|
temperature_regulation = {
|
||||||
'targets': {'se_tt': 20, 'se_tm': 19},
|
'alias': 'Tr',
|
||||||
|
'targets': {'se_tt': 20, 'se_tm': 19},
|
||||||
},
|
},
|
||||||
temperature_drivable = {
|
temperature_drivable = {
|
||||||
'envlist': False, # do not put into env list
|
'alias': 'T',
|
||||||
|
'envlist': False,
|
||||||
},
|
},
|
||||||
magneticfield = {
|
magneticfield = {
|
||||||
|
'alias': ['B', 'magfield'],
|
||||||
'targets': {'se_mf': 20},
|
'targets': {'se_mf': 20},
|
||||||
},
|
},
|
||||||
rotation_z = {
|
rotation_z = {
|
||||||
|
'alias': 'dom',
|
||||||
'envlist': False,
|
'envlist': False,
|
||||||
'targets': {'se_om': 20},
|
'targets': {'se_om': 20},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user