Skip to content

Commit

Permalink
[TASK] now getting data form database, limited use
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreSchnizer committed Jan 30, 2025
1 parent 9537431 commit 14f85f7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
26 changes: 19 additions & 7 deletions src/dt4acc/custom_epics/ioc/liasion_translation_manager.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +13,8 @@
from ..data.constants import DEFAULTS
from ...core.model.elementmodel import MagnetElementSetup

logger = logging.getLogger("dt4acc")


class LiaisonManager(LiaisonManagerBase):
def __init__(
Expand All @@ -27,15 +29,21 @@ 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):
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:
Expand Down Expand Up @@ -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),)
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions src/dt4acc/custom_epics/ioc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
11 changes: 9 additions & 2 deletions tests/test_liasion_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
7 changes: 7 additions & 0 deletions tests/test_translation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
)

0 comments on commit 14f85f7

Please # to comment.