howto: "keep a reference to an object in redis"
Q: how to keep trace of such discussion ?
sort of HOWTO or recipe in bliss doc ?
Acte I scene 14 @claustre @pithan
lolo:
- Salut les blissers, quick question it seems I cannot used
BeaconObject.property_setting()
for a reference to object. In my
controller class I did use the following declaration:
class AutoFilter(BeaconObject):
energy_axis = BeaconObject.property_setting(
"energy_axis",
must_be_in_config=True,
doc="An energy motor in keV",
)
def __init__(self, name, config):
super().__init__(config, share_hardware=False)
energy = self.energy_axis.position
And in the yml config i have:
- name: autof_eh1
plugin: bliss
package: bliss.common.auto_filter
class: AutoFilter
energy_axis: $eccmono
That failed with an exception on Pickle:
File "/users/blissadm/local/bliss.git/bliss/config/settings.py", line 703, in __setitem__
value = self._write_type_conversion(value)
TypeError: can't pickle _thread.RLock objects
linus:
- In fact I am not sure that you can have $
references in the
property_setting
(something to be confirmed by Seb). What is
the reason to use a property_setting
here? something like
class AutoFilter(BeaconObject):
@property
def energy_axis(self):
return self._config['energy_axis']
def __init__(self, name, config):
super().__init__(config, share_hardware=False)
self._config=config
energy = self.energy_axis.position
but maybe I miss the point... what is the benefit to have the
axis object pickeled and saved in redis? ... I think that is what
is done in the property_Setting
as you tried to use it and
where it failed
lolo: - Thanks Linus, for your answer. I did that ( self._config['energy_axis'] . My idea, to use propery_setting is to be able to change the energy motor to a mockup one or to another one depending of which monochromator is used on the beamline. We have 2 mono on ID10 for example.
linus: - ok, do you want to change that in the config or during runtime (from the shell)?
so basically you want to be able to change the energy axis and to keep this change in the beacon object, right? in that case we should only keep the axis name in the property_setting (without $) I guess
something in this direction (not tested):
class AutoFilter(BeaconObject):
_energy_axis = BeaconObject.property_setting(
"energy_axis",
must_be_in_config=True,
doc="An energy motor in keV",
)
@property
def energy_axis(self):
return current_session.config.get("$"+self._energy_axis)
@energy_axis.setter
def energy_axis(self,axis):
self._energy_axis=axis.name
def __init__(self, name, config):
super().__init__(config, share_hardware=False)
energy = self.energy_axis.position
- name: autof_eh1
plugin: bliss
package: bliss.common.auto_filter
class: AutoFilter
energy_axis: eccmono
... I guess there are nicer ways to do that than using
config.get("$"+...
... but that is again something for Seb ...
lolo:
- ok, that's nice, I will do that, I've the same need for the
filterset, one can deal with several ones and change from one to
an other filter box
linus:
- ... However I know that @matias.guijarro does not like the idea
to use config.get("$"+
... maybe there are nicer ways to do
the same thing ... we should have a look before writing the howto
...