Commit 1386ece5 authored by Matias Guijarro's avatar Matias Guijarro

added config.map module: build map from config

* added 'add_axes_counter' keyword arg to 'config.get'
    - do not add to map if object is created from another object
parent 16d0d78f
......@@ -23,10 +23,6 @@ class MotionHook(LogMixin):
def __init__(self):
self.__axes = weakref.WeakValueDictionary()
session.get_current().map.register(
self, parents_list=["motion hooks"], tag=self.__class__.__name__
)
def add_axis(self, axis):
"""Add a new axis to the hook. Called by bliss when an axis is created
which is linked to this hook
......@@ -35,6 +31,7 @@ class MotionHook(LogMixin):
axis (Axis): new axis to be added to the hook
"""
self.__axes[axis.name] = axis
session.get_current().map.register(self, children_list=list(self.axes.values()))
@property
def axes(self):
......
from bliss.common.axis import Axis
from bliss.common.temperature import Input, Output, Loop
from bliss.common import session
from bliss.controllers.motor import CalcController
def register_axis(session_map, axis, add_to_axes=False):
parents_list = [axis.controller]
if add_to_axes:
parents_list.append("axes")
session_map.register(axis, parents_list=parents_list)
def register_temperature_object(session_map, obj, add_to_counters=False):
parents_list = [obj.controller]
if isinstance(obj, Loop):
children_list = [obj.input, obj.output]
else:
if add_to_counters:
parents_list.append("counters")
children_list = []
session_map.register(obj, parents_list=parents_list, children_list=children_list)
def update_map_for_object(instance_object):
session_map = session.get_current().map
if isinstance(instance_object, Axis):
build_motor_controller_map(instance_object.controller)
register_axis(session_map, instance_object, add_to_axes=True)
elif isinstance(instance_object, (Input, Output, Loop)):
build_temperature_controller_map(instance_object.controller)
register_temperature_object(session_map, instance_object, add_to_counters=True)
def build_motor_controller_map(controller):
session_map = session.get_current().map
if isinstance(controller, CalcController):
session_map.register(
controller, children_list=list(controller.reals) + list(controller.pseudos)
)
else:
for axis in controller.axes.values():
register_axis(session_map, axis)
for hook in axis.motion_hooks:
session_map.register(hook, parents_list=["motion_hooks"])
def build_temperature_controller_map(controller):
session_map = session.get_current().map
for obj in controller._objects.values():
register_temperature_object(session_map, obj)
......@@ -52,7 +52,7 @@ def _checkref(config, item_cfg_node, referenced_objects, name, value, placeholde
if placeholder:
obj = placeholder(value)
else:
obj = config.get(value)
obj = config.get(value, add_axes_counters=False)
item_cfg_node[name] = obj
referenced_objects[name] = obj
return True
......@@ -113,7 +113,7 @@ class Reference:
return self.__name
def __call__(self, *args, **kwargs):
return get_config().get(self.name)
return get_config().get(self.name, add_axes_counters=False)
def __str__(self):
return f"${self.name}"
......
......@@ -56,6 +56,7 @@ from yaml.loader import Reader, Scanner, Parser, Composer, SafeConstructor, Reso
from bliss.config.conductor import client
from bliss.config import channels
from bliss.config.map import update_map_for_object
CONFIG = None
......@@ -640,7 +641,7 @@ class Config:
"""
return set(self._usertag2node.get(tag_name, ()))
def get(self, name):
def get(self, name, add_axes_counters=True):
"""
Returns an object instance from its configuration name
......@@ -688,33 +689,8 @@ class Config:
self._name2instance.update(name2items)
instance_object = name2items.get(name)
from bliss.common.axis import Axis
from bliss.common.temperature import Input, Output, Loop
if isinstance(instance_object, Axis):
from bliss.common import session
session.get_current().map.register(
instance_object,
parents_list=[instance_object.controller, "axes"],
tag=instance_object.name,
)
elif isinstance(instance_object, (Input, Output, Loop)):
from bliss.common import session
parents_list = [instance_object.controller]
if isinstance(instance_object, Loop):
children_list = [instance_object.input, instance_object.output]
else:
parents_list.append("counters")
children_list = []
session.get_current().map.register(
instance_object,
parents_list=parents_list,
children_list=children_list,
tag=instance_object.name,
)
if add_axes_counters:
update_map_for_object(instance_object) # , add_axes_counters)
return instance_object
......
......@@ -65,7 +65,11 @@ class Controller(LogMixin):
self.axis_settings = ControllerAxisSettings()
for axis_name, axis_class, axis_config in axes:
# make Axis objects from the class,
# in case of references, eg. real axes for calc controllers,
# they are de-referenced (__call__ of Reference object)
axis = axis_class(axis_name, self, axis_config)
#
self._axes[axis_name] = axis
axis_tags = axis_config.get("tags")
if axis_tags:
......@@ -87,10 +91,7 @@ class Controller(LogMixin):
if obj_class is None:
raise ValueError("Missing **class** for '%s`" % obj_name)
object_dict[obj_name] = obj_class(obj_name, self, obj_config)
mapping_name = config.get("name") or self.__class__.__name__.lower()
session.get_current().map.register(
self, parents_list=["controllers"], tag=mapping_name
)
session.get_current().map.register(self, parents_list=["controllers"])
def _init(self):
for axis in self.axes.values():
......
......@@ -50,8 +50,6 @@ class Controller(LogMixin):
self.__name = config.get("name")
self._objects = {}
session.get_current().map.register(self, parents_list=["controllers"])
for name, klass, cfg in itertools.chain(inputs, outputs, loops):
self._logger.debug(f" {klass.__name__} name: {name}")
self._logger.debug(f" {klass.__name__} config: {cfg}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment