diff --git a/src/hyperion/experiment_plans/tests/conftest.py b/src/hyperion/experiment_plans/tests/conftest.py index d4083294c..4ea731e13 100644 --- a/src/hyperion/experiment_plans/tests/conftest.py +++ b/src/hyperion/experiment_plans/tests/conftest.py @@ -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) diff --git a/src/hyperion/experiment_plans/tests/test_flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/tests/test_flyscan_xray_centre_plan.py index d45df93cb..c45e3f10f 100644 --- a/src/hyperion/experiment_plans/tests/test_flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/tests/test_flyscan_xray_centre_plan.py @@ -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, @@ -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 @@ -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( @@ -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( @@ -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( @@ -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} ) @@ -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( @@ -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} ) @@ -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( @@ -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( diff --git a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py index fa4242b3a..6c3895a3b 100644 --- a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py +++ b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py @@ -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""" @@ -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." + ) diff --git a/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py b/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py index b42b162fa..cd74f5a2f 100644 --- a/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py +++ b/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py @@ -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( @@ -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) @@ -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)