Skip to content

Commit

Permalink
Add an else plan for extruder
Browse files Browse the repository at this point in the history
  • Loading branch information
noemifrisina committed Jul 24, 2024
1 parent ac9f0bc commit ae9c202
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
40 changes: 22 additions & 18 deletions src/mx_bluesky/I24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
usage = "%(prog)s command [options]"
logger = logging.getLogger("I24ssx.extruder")

ABORTED = False

SAFE_DET_Z = 1480


Expand Down Expand Up @@ -391,22 +389,22 @@ def main_extruder_plan(
raise TimeoutError("Data collection timed out.")

logger.debug("Collection completed without errors.")
global ABORTED
ABORTED = False


@log.log_on_entry
def collection_aborted_plan(zebra: Zebra, detector_name: str) -> MsgGenerator:
def collection_aborted_plan(
zebra: Zebra, detector_name: str, dcid: DCID
) -> MsgGenerator:
"""A plan to run in case the collection is aborted before the end."""
global ABORTED
ABORTED = True
logger.warning("Data Collection Aborted")
yield from disarm_zebra(zebra) # If aborted/timed out zebra still armed
if detector_name == "pilatus":
caput(pv.pilat_acquire, 0)
elif detector_name == "eiger":
caput(pv.eiger_acquire, 0)
sleep(1.0)
sleep(0.5)
end_time = datetime.now()
dcid.collection_complete(end_time, aborted=True)


@log.log_on_entry
Expand All @@ -425,8 +423,6 @@ def tidy_up_at_collection_end_plan(
"""
yield from reset_zebra_when_collection_done_plan(zebra)

end_time = datetime.now()

if parameters.detector_name == "pilatus":
logger.info("Pilatus Acquire STOP")
caput(pv.pilat_acquire, 0)
Expand All @@ -447,10 +443,21 @@ def tidy_up_at_collection_end_plan(
logger.debug("Close hutch shutter")
yield from bps.abs_set(shutter, ShutterDemand.CLOSE, wait=True)

dcid.collection_complete(end_time, aborted=ABORTED)
dcid.notify_end()


@log.log_on_entry
def collection_complete_plan(collection_directory: Path, dcid: DCID):
end_time = datetime.now()
dcid.collection_complete(end_time, aborted=False)
logger.info("End Time = %s" % end_time.ctime())

# Copy parameter file
shutil.copy2(
PARAM_FILE_PATH / PARAM_FILE_NAME,
collection_directory / PARAM_FILE_NAME,
)


def run_extruder_plan(
zebra: Zebra = inject("zebra"),
Expand Down Expand Up @@ -489,16 +496,13 @@ def run_extruder_plan(
start_time,
),
except_plan=lambda e: (
yield from collection_aborted_plan(zebra, parameters.detector_name)
yield from collection_aborted_plan(zebra, parameters.detector_name, dcid)
),
else_plan=lambda: (
yield from collection_complete_plan(parameters.collection_directory, dcid)
),
final_plan=lambda: (
yield from tidy_up_at_collection_end_plan(zebra, shutter, parameters, dcid)
),
auto_raise=False,
)

# Copy parameter file
shutil.copy2(
PARAM_FILE_PATH / PARAM_FILE_NAME,
parameters.collection_directory / PARAM_FILE_NAME,
)
9 changes: 6 additions & 3 deletions tests/I24/serial/extruder/test_extruder_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ def test_tidy_up_at_collection_end_plan_with_eiger(
mock_shutter = get_mock_put(shutter.control)
mock_shutter.assert_has_calls([call("Close", wait=True, timeout=10.0)])

assert fake_dcid.collection_complete.call_count == 1
assert fake_dcid.notify_end.call_count == 1
assert fake_caget.call_count == 1

Expand All @@ -265,9 +264,13 @@ def test_tidy_up_at_collection_end_plan_with_eiger(

@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.sleep")
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caput")
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.DCID")
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.disarm_zebra")
def test_aborted_plan_with_pilatus(mock_disarm, fake_caput, fake_sleep, RE, zebra):
RE(collection_aborted_plan(zebra, "pilatus"))
def test_aborted_plan_with_pilatus(
mock_disarm, fake_dcid, fake_caput, fake_sleep, RE, zebra
):
RE(collection_aborted_plan(zebra, "pilatus", fake_dcid))

mock_disarm.assert_called_once()
fake_caput.assert_has_calls([call(ANY, 0)])
fake_dcid.collection_complete.assert_called_once_with(ANY, aborted=True)

0 comments on commit ae9c202

Please sign in to comment.