Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
#950 fix some errors from merging
Browse files Browse the repository at this point in the history
  • Loading branch information
dperl-dls committed Nov 21, 2023
1 parent 2e8bf7e commit 0635428
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/hyperion/experiment_plans/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ def mock_subscriptions(test_fgs_params):
"subplan_name": GRIDSCAN_OUTER_PLAN,
"hyperion_internal_parameters": test_fgs_params.json(),
}
subscriptions.ispyb_handler.start(start_doc)
subscriptions.zocalo_handler.start(start_doc)
subscriptions.ispyb_handler.activity_gated_start(start_doc)
subscriptions.zocalo_handler.activity_gated_start(start_doc)
subscriptions.ispyb_handler.ispyb = MagicMock(spec=Store3DGridscanInIspyb)
subscriptions.ispyb_handler.ispyb.begin_deposition = lambda: IspybIds(
data_collection_ids=(0, 0), data_collection_group_id=0, grid_ids=(0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
GridscanISPyBCallback,
)
from hyperion.external_interaction.callbacks.xray_centre.tests.conftest import TestData
from hyperion.external_interaction.ispyb.store_in_ispyb import Store3DGridscanInIspyb
from hyperion.external_interaction.ispyb.store_in_ispyb import (
IspybIds,
Store3DGridscanInIspyb,
)
from hyperion.external_interaction.system_tests.conftest import (
TEST_RESULT_LARGE,
TEST_RESULT_MEDIUM,
Expand Down Expand Up @@ -70,10 +73,8 @@ def ispyb_plan(test_fgs_params):
}
)
def standalone_read_hardware_for_ispyb(und, syn, slits, attn, fl):
yield from bps.open_run()
yield from read_hardware_for_ispyb_pre_collection(und, syn, slits)
yield from read_hardware_for_ispyb_during_collection(attn, fl)
yield from bps.close_run()

return standalone_read_hardware_for_ispyb

Expand Down Expand Up @@ -138,6 +139,9 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices(
test_ispyb_callback = GridscanISPyBCallback()
test_ispyb_callback.active = True
test_ispyb_callback.ispyb = MagicMock(spec=Store3DGridscanInIspyb)
test_ispyb_callback.ispyb.begin_deposition.return_value = IspybIds(
data_collection_ids=(2, 3), data_collection_group_id=5, grid_ids=(7, 8, 9)
)
RE.subscribe(test_ispyb_callback)

RE(
Expand Down Expand Up @@ -186,13 +190,13 @@ def test_results_adjusted_and_passed_to_move_xyz(
set_up_logging_handlers(logging_level="INFO", dev_mode=True)
RE.subscribe(VerbosePlanExecutionLoggingCallback())

mock_subscriptions.ispyb_handler.start(
mock_subscriptions.ispyb_handler.activity_gated_start(
{
"subplan_name": GRIDSCAN_OUTER_PLAN,
"hyperion_internal_parameters": test_fgs_params.json(),
}
)
mock_subscriptions.ispyb_handler.descriptor(
mock_subscriptions.ispyb_handler.activity_gated_descriptor(
{"uid": "123abc", "name": ISPYB_HARDWARE_READ_PLAN}
)
mock_subscriptions.ispyb_handler.activity_gated_event(
Expand All @@ -206,7 +210,7 @@ def test_results_adjusted_and_passed_to_move_xyz(
},
}
)
mock_subscriptions.ispyb_handler.descriptor(
mock_subscriptions.ispyb_handler.activity_gated_descriptor(
{"uid": "abc123", "name": ISPYB_TRANSMISSION_FLUX_READ_PLAN}
)
mock_subscriptions.ispyb_handler.activity_gated_event(
Expand Down Expand Up @@ -336,9 +340,9 @@ def test_individual_plans_triggered_once_and_only_once_in_composite_run(
RE: RunEngine,
):
td = TestData()
mock_subscriptions.ispyb_handler.start(td.test_start_document)
mock_subscriptions.zocalo_handler.start(td.test_start_document)
mock_subscriptions.ispyb_handler.descriptor(
mock_subscriptions.ispyb_handler.activity_gated_start(td.test_start_document)
mock_subscriptions.zocalo_handler.activity_gated_start(td.test_start_document)
mock_subscriptions.ispyb_handler.activity_gated_descriptor(
{"uid": "123abc", "name": ISPYB_HARDWARE_READ_PLAN}
)

Expand All @@ -353,7 +357,7 @@ def test_individual_plans_triggered_once_and_only_once_in_composite_run(
},
}
)
mock_subscriptions.ispyb_handler.descriptor(
mock_subscriptions.ispyb_handler.activity_gated_descriptor(
{"uid": "abc123", "name": ISPYB_TRANSMISSION_FLUX_READ_PLAN}
)
mock_subscriptions.ispyb_handler.activity_gated_event(
Expand Down Expand Up @@ -381,7 +385,7 @@ def test_when_gridscan_finished_then_smargon_stub_offsets_are_set(
test_fgs_params: GridscanInternalParameters,
RE: RunEngine,
):
mock_subscriptions.ispyb_handler.descriptor(
mock_subscriptions.ispyb_handler.activity_gated_descriptor(
{"uid": "123abc", "name": ISPYB_HARDWARE_READ_PLAN}
)

Expand All @@ -396,7 +400,7 @@ def test_when_gridscan_finished_then_smargon_stub_offsets_are_set(
},
}
)
mock_subscriptions.ispyb_handler.descriptor(
mock_subscriptions.ispyb_handler.activity_gated_descriptor(
{"uid": "abc123", "name": ISPYB_TRANSMISSION_FLUX_READ_PLAN}
)
mock_subscriptions.ispyb_handler.activity_gated_event(
Expand All @@ -411,9 +415,11 @@ def test_when_gridscan_finished_then_smargon_stub_offsets_are_set(

set_up_logging_handlers(logging_level="INFO", dev_mode=True)
RE.subscribe(VerbosePlanExecutionLoggingCallback())
mock_subscriptions.zocalo_handler.wait_for_results.return_value = (
(0, 0, 0),
None,
mock_subscriptions.zocalo_handler.wait_for_results = MagicMock(
return_value=(
(0, 0, 0),
None,
)
)

RE(
Expand Down
24 changes: 12 additions & 12 deletions src/hyperion/external_interaction/callbacks/ispyb_callback_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,13 @@ def __init__(self) -> None:
self.uid_to_finalize_on: Optional[str] = None
self.ispyb_ids: IspybIds = IspybIds()

def _append_to_comment(self, id: int, comment: str):
assert isinstance(self.ispyb, StoreInIspyb)
try:
self.ispyb.append_to_comment(id, comment)
except TypeError:
ISPYB_LOGGER.warning(
"ISPyB deposition not initialised, can't update comment."
)

def activity_gated_descriptor(self, doc: dict):
self.descriptors[doc["uid"]] = doc

def activity_gated_start(self, doc: dict):
if self.uid_to_finalize_on is None:
self.uid_to_finalize_on = doc.get("uid")

def activity_gated_descriptor(self, doc: dict):
self.descriptors[doc["uid"]] = doc

def activity_gated_event(self, doc: dict):
"""Subclasses should extend this to add a call to set_dcig_tag from
hyperion.log"""
Expand Down Expand Up @@ -114,3 +105,12 @@ def activity_gated_stop(self, doc: dict):
ISPYB_LOGGER.warning(
f"Failed to finalise ISPyB deposition on stop document: {doc} with exception: {e}"
)

def _append_to_comment(self, id: int, comment: str):
assert isinstance(self.ispyb, StoreInIspyb)
try:
self.ispyb.append_to_comment(id, comment)
except TypeError:
ISPYB_LOGGER.warning(
"ISPyB deposition not initialised, can't update comment."
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self) -> None:
self.ispyb: StoreGridscanInIspyb
self.ispyb_ids: IspybIds = IspybIds()

def start(self, doc: dict):
def activity_gated_start(self, doc: dict):
if doc.get("subplan_name") == GRIDSCAN_OUTER_PLAN:
self.uid_to_finalize_on = doc.get("uid")
ISPYB_LOGGER.info(
Expand All @@ -55,11 +55,6 @@ def start(self, doc: dict):
else Store2DGridscanInIspyb(self.ispyb_config, self.params)
)

def append_to_comment(self, comment: str):
assert isinstance(self.ispyb_ids.data_collection_ids, tuple)
for id in self.ispyb_ids.data_collection_ids:
self._append_to_comment(id, comment)

def activity_gated_event(self, doc: dict):
super().activity_gated_event(doc)
set_dcgid_tag(self.ispyb_ids.data_collection_group_id)
Expand All @@ -73,3 +68,8 @@ def activity_gated_stop(self, doc: dict):
if self.ispyb_ids == IspybIds():
raise ISPyBDepositionNotMade("ispyb was not initialised at run start")
super().activity_gated_stop(doc)

def append_to_comment(self, comment: str):
assert isinstance(self.ispyb_ids.data_collection_ids, tuple)
for id in self.ispyb_ids.data_collection_ids:
self._append_to_comment(id, comment)

0 comments on commit 0635428

Please sign in to comment.