diff --git a/src/dt4acc/custom_epics/ioc/liasion_translation_manager.py b/src/dt4acc/custom_epics/ioc/liasion_translation_manager.py index 83fa22e..e4411ab 100644 --- a/src/dt4acc/custom_epics/ioc/liasion_translation_manager.py +++ b/src/dt4acc/custom_epics/ioc/liasion_translation_manager.py @@ -1,5 +1,5 @@ -from collections.abc import Mapping -from typing import Dict, Sequence +from typing import Dict, Sequence, Mapping +import logging from bact_twin_architecture.data_model.identifiers import LatticeElementPropertyID, DevicePropertyID, ConversionID from bact_twin_architecture.interfaces.liaison_manager import LiaisonManagerBase @@ -13,6 +13,8 @@ from ..data.constants import DEFAULTS from ...core.model.elementmodel import MagnetElementSetup +logger = logging.getLogger("dt4acc") + class LiaisonManager(LiaisonManagerBase): def __init__( @@ -27,7 +29,10 @@ def forward(self, id_: LatticeElementPropertyID) -> Sequence[DevicePropertyID]: return self.forward_lut[id_] def inverse(self, id_: DevicePropertyID) -> Sequence[LatticeElementPropertyID]: - return self.inverse_lut[id_] + try: + return self.inverse_lut[id_] + except KeyError as ke: + logger.error(f"{self.__class__.__name__} I did not find id {id_} in lookup table: {ke}") class TranslatorService(TranslatorServiceBase): @@ -35,7 +40,10 @@ def __init__(self, lut: Mapping[ConversionID, StateConversion]): self.lut = lut def get(self, id_: ConversionID) -> StateConversion: - return self.lut[id_] + try: + return self.lut[id_] + except KeyError as ke: + logger.error(f"{self.__class__.__name__}: I did not find id {id_} in lookup table: {ke}") def remove_id(d: Dict) -> Dict: @@ -103,9 +111,13 @@ def build_managers() -> (LiaisonManagerBase, TranslatorServiceBase): for pc_name, magnet_names in power_converter_feeds.items() if pc_name not in steerer_pc_names }) - # Add lut for quadrupoles and sextupole axes + # Add lut for quadrupoles and sextupole + # Furthermore to feed through the K value ... + # Todo: + # is that appropriate ? + # Should one rather use a handler for lattice elements quad_updates = dict() - for axis_name in "x", "y": + for axis_name in "x", "y", "K": quad_updates.update({ DevicePropertyID(device_name=info.name, property=axis_name): (LatticeElementPropertyID(element_name=info.name, property=axis_name),) @@ -154,7 +166,7 @@ def construct_linear_conversion(slope: float) -> LinearUnitConversion: } axis_updates = dict() - for axis_name in "x", "y": + for axis_name in "x", "y", "K": axis_updates.update({ ConversionID( lattice_property_id=LatticeElementPropertyID(element_name=info.name, property=axis_name), diff --git a/src/dt4acc/custom_epics/ioc/server.py b/src/dt4acc/custom_epics/ioc/server.py index d4a1684..7e95ca3 100644 --- a/src/dt4acc/custom_epics/ioc/server.py +++ b/src/dt4acc/custom_epics/ioc/server.py @@ -13,15 +13,17 @@ initialize_cavity_pvs ) +# Create an asyncio dispatcher to handle asynchronous PV updates +dispatcher = asyncio_dispatcher.AsyncioDispatcher() + def main(): """ Main function to initialize all the process variables (PVs) and start the IOC server. """ - # Create an asyncio dispatcher to handle asynchronous PV updates - dispatcher = asyncio_dispatcher.AsyncioDispatcher() # Retrieve the device name prefix from the environment, defaulting to "Anonym" if not set prefix = os.environ.get("DT4ACC_PREFIX", "Anonym") + builder.SetDeviceName(prefix) # Initialize PVs for various accelerator components initialize_power_converter_pvs(builder, prefix) # Initialize power converters and linked magnets @@ -46,4 +48,3 @@ def main(): dispatcher(main) # Start the interactive IOC shell, allowing interaction with the server softioc.interactive_ioc(globals()) - # for testing purpose issue a command diff --git a/tests/test_liasion_manager.py b/tests/test_liasion_manager.py index 11e33da..774a37b 100644 --- a/tests/test_liasion_manager.py +++ b/tests/test_liasion_manager.py @@ -9,12 +9,12 @@ def test_liasion_service(): device_name = "HS4P2D1R" r, = lm.inverse(DevicePropertyID(device_name=device_name, property="set_current")) assert r.property == "x_kick" - assert r.element_name == device_name.replace("P", "M") + assert r.element_name == device_name.replace("P", "M")[1:] device_name = "VS2P2D1R" r, = lm.inverse(DevicePropertyID(device_name=device_name, property="set_current")) assert r.property == "y_kick" - assert r.element_name == device_name.replace("P", "M") + assert r.element_name == device_name.replace("P", "M")[1:] device_name = "S4PD1R" @@ -26,3 +26,10 @@ def test_liasion_service(): r = down_stream assert r.property == "K" assert r.element_name == device_name[:2] + "M2" + device_name[3:] + + # todo: review if these should be feed thorough + # K is a property of the lattice not the device + device_name= 'S4M1D1R' + r, = lm.inverse(DevicePropertyID(device_name=device_name, property='K')) + assert r.element_name == device_name + assert r.property == "K" \ No newline at end of file diff --git a/tests/test_translation_service.py b/tests/test_translation_service.py index 3530c4f..36cfe28 100644 --- a/tests/test_translation_service.py +++ b/tests/test_translation_service.py @@ -26,3 +26,10 @@ def test_translation_service_as_issued_by_command_test(): ) ) + device_name = 'S4M1D1R' + r = tm.get( + ConversionID( + lattice_property_id=LatticeElementPropertyID(element_name=device_name, property="K"), + device_property_id=DevicePropertyID(device_name=device_name, property="K") + ) + )