-
Notifications
You must be signed in to change notification settings - Fork 44
Moved all remaining beamline routes to BeamlineAdapter #1859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,72 @@ | ||
import logging | ||
from typing import ClassVar | ||
|
||
import pydantic | ||
from mxcubecore import HardwareRepository as HWR | ||
from mxcubecore.HardwareObjects.Beamline import Beamline | ||
|
||
BEAMLINE_ADAPTER = None | ||
from mxcubeweb.core.adapter.adapter_base import ActuatorAdapterBase | ||
from mxcubeweb.core.models.configmodels import ResourceHandlerConfigModel | ||
|
||
# Singleton like interface is needed to keep the same reference to the | ||
# adapter object and its corresponding hardware objects, so that the signal | ||
# system won't clean up signal handlers. (PyDispatcher removes signal handlers | ||
# when an object is garbage collected) | ||
resource_handler_config = ResourceHandlerConfigModel( | ||
commands=["prepare_beamline_for_sample"], | ||
attributes=["data", "get_value"], | ||
) | ||
|
||
|
||
def BeamlineAdapter(*args): | ||
global BEAMLINE_ADAPTER | ||
|
||
if BEAMLINE_ADAPTER is None: | ||
BEAMLINE_ADAPTER = _BeamlineAdapter(*args) | ||
|
||
return BEAMLINE_ADAPTER | ||
|
||
|
||
class _BeamlineAdapter: | ||
class BeamlineAdapter(ActuatorAdapterBase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the old some what strange custom |
||
""" | ||
Adapter between Beamline route and Beamline hardware object. | ||
""" | ||
|
||
def __init__(self, beamline_hwobj, app): | ||
SUPPORTED_TYPES: ClassVar[list[object]] = [Beamline] | ||
|
||
def __init__(self, ho, role, app): | ||
super().__init__(ho, role, app, resource_handler_config) | ||
self.app = app | ||
self._bl = beamline_hwobj | ||
self.adapter_dict = {} | ||
|
||
workflow = self._bl.workflow | ||
workflow = self._ho.workflow | ||
if workflow: | ||
workflow.connect("parametersNeeded", self.wf_parameters_needed) | ||
workflow.connect("parametersNeeded", self._wf_parameters_needed) | ||
|
||
gphl_workflow = self._bl.gphl_workflow | ||
gphl_workflow = self._ho.gphl_workflow | ||
if gphl_workflow: | ||
gphl_workflow.connect( | ||
"GphlJsonParametersNeeded", self.gphl_json_wf_parameters_needed | ||
"GphlJsonParametersNeeded", self._gphl_json_wf_parameters_needed | ||
) | ||
gphl_workflow.connect( | ||
"GphlUpdateUiParameters", self.gphl_json_wf_update_ui_parameters | ||
"GphlUpdateUiParameters", self._gphl_json_wf_update_ui_parameters | ||
) | ||
|
||
def wf_parameters_needed(self, params): | ||
from mxcubeweb.routes import signals | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this will still need some further cleanup, so that we can get rid of this import |
||
|
||
if HWR.beamline.xrf_spectrum: | ||
HWR.beamline.xrf_spectrum.connect( | ||
HWR.beamline.xrf_spectrum, | ||
"xrf_task_progress", | ||
signals.xrf_task_progress, | ||
) | ||
|
||
def _wf_parameters_needed(self, params): | ||
self.app.server.emit("workflowParametersDialog", params, namespace="/hwr") | ||
|
||
def gphl_json_wf_parameters_needed(self, schema, ui_schema): | ||
def _gphl_json_wf_parameters_needed(self, schema, ui_schema): | ||
params = {} | ||
params["schema"] = schema | ||
params["ui_schema"] = ui_schema | ||
self.app.server.emit("gphlWorkflowParametersDialog", params, namespace="/hwr") | ||
|
||
def gphl_json_wf_update_ui_parameters(self, update_dict): | ||
def _gphl_json_wf_update_ui_parameters(self, update_dict): | ||
self.app.server.emit( | ||
"gphlWorkflowUpdateUiParametersDialog", update_dict, namespace="/hwr" | ||
) | ||
|
||
def get_object(self, name): | ||
return self._ho.get_hardware_object(name) | ||
def _get_available_elements(self): | ||
escan = self._ho.energy_scan | ||
return escan.get_elements() if escan else [] | ||
|
||
def dict(self): | ||
def get_value(self) -> dict: | ||
""" | ||
Build dictionary value-representation for each beamline attribute | ||
Returns: | ||
|
@@ -68,6 +75,10 @@ def dict(self): | |
attributes = {} | ||
|
||
for attr_name in self.app.mxcubecore.adapter_dict: | ||
# We skip the beamline attribute to avoid endless recursion | ||
if attr_name == "beamline": | ||
continue | ||
|
||
try: | ||
_d = self.app.mxcubecore.get_adapter(attr_name).data().dict() | ||
except pydantic.ValidationError: | ||
|
@@ -76,13 +87,15 @@ def dict(self): | |
|
||
attributes.update({attr_name: _d}) | ||
|
||
return {"hardwareObjects": attributes} | ||
|
||
def get_available_elements(self): | ||
escan = self._bl.energy_scan | ||
elements = [] | ||
return { | ||
"energyScanElements": self._get_available_elements(), | ||
"path": HWR.beamline.session.get_base_image_directory(), | ||
"actionsList": [], | ||
"hardwareObjects": attributes, | ||
} | ||
|
||
if escan: | ||
elements = escan.get_elements() | ||
def prepare_beamline_for_sample(self) -> dict: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to #1845 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, in a way. If you decide to do something with |
||
if hasattr(HWR.beamline.collect, "prepare_for_new_sample"): | ||
HWR.beamline.collect.prepare_for_new_sample() | ||
|
||
return {"elements": elements} | ||
return {} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
BeamlineAdapter
used to be a sort of special object. Now its a Adapter object like the others. However thebeamline
HardwareObject is considered special as its the container for all (most) other HardwareObjects. It does not necessarily have to be in this way, but It was a design decision made at the time theBeamline
object was introduced. It also means that theBeamline
object does not have any id. So we specifically add theBeamline
object to the list adapted hardware objects and give the id "beamline" which is alright as far as adapters are concerned.