Skip to content

Commit

Permalink
Add FrameReceiver controllers, move FP controllers to daq.py
Browse files Browse the repository at this point in the history
format with black
  • Loading branch information
jsouter committed Aug 27, 2024
1 parent c213f25 commit e31e2a4
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 42 deletions.
4 changes: 1 addition & 3 deletions src/odin_fastcs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from fastcs.backends.epics.gui import EpicsGUIOptions
from fastcs.connections.ip_connection import IPConnectionSettings

from odin_fastcs.odin_controller import (
OdinController,
)
from odin_fastcs.odin_controller import OdinController

from . import __version__

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,22 @@
)
from odin_fastcs.util import OdinParameter, partition

UNIQUE_FP_CONFIG = [
"rank",
"number",
"ctrl_endpoint",
"meta_endpoint",
"fr_ready_cnxn",
"fr_release_cnxn",
]

class DAQController(OdinAdapterController):
def _process_parameters(self):
for parameter in self._parameters:
# Remove duplicate index from uri
parameter.uri = parameter.uri[1:]
# Remove redundant status/config from parameter path
parameter.set_path(parameter.uri[1:])


class FrameProcessorAdapterController(OdinAdapterController):
class DAQAdapterController(OdinAdapterController):
"""Sub controller for the frame processor adapter in an odin control server."""

frames_written: AttrR = AttrR(
Int(),
handler=StatusSummaryUpdater([re.compile("FP*"), "HDF"], "frames_written", sum),
)
writing: AttrR = AttrR(
Bool(),
handler=StatusSummaryUpdater([re.compile("FP*"), "HDF"], "writing", any),
)
_unique_config: list[str] = []
_subcontroller_label: str = "OD"
_subcontroller_cls: type[OdinAdapterController] = DAQController

async def initialise(self):
idx_parameters, self._parameters = partition(
Expand All @@ -45,12 +40,14 @@ async def initialise(self):
idx_parameters, lambda p, idx=idx: p.uri[0] == idx
)

adapter_controller = FrameProcessorController(
adapter_controller = self._subcontroller_cls(
self._connection,
fp_parameters,
f"{self._api_prefix}/{idx}",
)
self.register_sub_controller(f"FP{idx}", adapter_controller)
self.register_sub_controller(
f"{self._subcontroller_label}{idx}", adapter_controller
)
await adapter_controller.initialise()

self._create_attributes()
Expand All @@ -62,7 +59,7 @@ def _create_config_fan_attributes(self):
for sub_controller in get_all_sub_controllers(self):
for parameter in sub_controller._parameters:
mode, key = parameter.uri[0], parameter.uri[-1]
if mode == "config" and key not in UNIQUE_FP_CONFIG:
if mode == "config" and key not in self._unique_config:
try:
attr = getattr(sub_controller, parameter.name)
except AttributeError:
Expand All @@ -88,7 +85,12 @@ def _create_config_fan_attributes(self):
)


class FrameProcessorController(OdinAdapterController):
class FrameRecieverAdapterController(DAQAdapterController):
_subcontroller_label = "FR"
_subcontroller_cls = DAQController


class FrameProcessorController(DAQController):
"""Sub controller for a frame processor application."""

async def initialise(self):
Expand All @@ -109,13 +111,6 @@ async def initialise(self):
await self._create_plugin_sub_controllers(plugins)
self._create_attributes()

def _process_parameters(self):
for parameter in self._parameters:
# Remove duplicate index from uri
parameter.uri = parameter.uri[1:]
# Remove redundant status/config from parameter path
parameter.set_path(parameter.uri[1:])

async def _create_plugin_sub_controllers(self, plugins: Sequence[str]):
for plugin in plugins:

Expand Down Expand Up @@ -145,6 +140,27 @@ def _process_parameters(self):
parameter.set_path(parameter.path[1:])


class FrameProcessorAdapterController(DAQAdapterController):
frames_written: AttrR = AttrR(
Int(),
handler=StatusSummaryUpdater([re.compile("FP*"), "HDF"], "frames_written", sum),
)
writing: AttrR = AttrR(
Bool(),
handler=StatusSummaryUpdater([re.compile("FP*"), "HDF"], "writing", any),
)
_unique_config = [
"rank",
"number",
"ctrl_endpoint",
"meta_endpoint",
"fr_ready_cnxn",
"fr_release_cnxn",
]
_subcontroller_label = "FP"
_subcontroller_cls = FrameProcessorController


def get_all_sub_controllers(
controller: "OdinAdapterController",
) -> list["OdinAdapterController"]:
Expand Down
5 changes: 0 additions & 5 deletions src/odin_fastcs/frame_receiver.py

This file was deleted.

4 changes: 1 addition & 3 deletions src/odin_fastcs/odin_adapter_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
from fastcs.util import snake_to_pascal

from odin_fastcs.http_connection import HTTPConnection
from odin_fastcs.util import (
OdinParameter,
)
from odin_fastcs.util import OdinParameter

types = {"float": Float(), "int": Int(), "bool": Bool(), "str": String()}

Expand Down
9 changes: 8 additions & 1 deletion src/odin_fastcs/odin_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
from fastcs.controller import Controller
from fastcs.datatypes import Bool, Float, Int, String

from odin_fastcs.daq_controller import (
FrameProcessorAdapterController,
FrameRecieverAdapterController,
)
from odin_fastcs.eiger_fan import EigerFanAdapterController
from odin_fastcs.frame_processor import FrameProcessorAdapterController
from odin_fastcs.http_connection import HTTPConnection
from odin_fastcs.meta_writer import MetaWriterAdapterController
from odin_fastcs.odin_adapter_controller import OdinAdapterController
Expand Down Expand Up @@ -70,6 +73,10 @@ def _create_adapter_controller(
return FrameProcessorAdapterController(
connection, parameters, f"{self.API_PREFIX}/fp"
)
case "fr":
return FrameRecieverAdapterController(
connection, parameters, f"{self.API_PREFIX}/fr"
)
case "mw":
return MetaWriterAdapterController(
connection, parameters, f"{self.API_PREFIX}/mw"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastcs.datatypes import Bool, Float, Int
from pytest_mock import MockerFixture

from odin_fastcs.frame_processor import (
from odin_fastcs.daq_controller import (
FrameProcessorController,
FrameProcessorPluginController,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from pytest_mock import MockerFixture

from odin_fastcs.frame_processor import FrameProcessorAdapterController
from odin_fastcs.daq_controller import FrameProcessorAdapterController
from odin_fastcs.util import create_odin_parameters

HERE = Path(__file__).parent
Expand Down

0 comments on commit e31e2a4

Please sign in to comment.