diff --git a/src/mx_bluesky/beamlines/i24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py b/src/mx_bluesky/beamlines/i24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py index 7ced41871..0737b8018 100755 --- a/src/mx_bluesky/beamlines/i24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py +++ b/src/mx_bluesky/beamlines/i24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py @@ -65,6 +65,11 @@ def setup_logging(): log.config(logfile) +def _create_directory_for_eiger_collection(filepath: str): + logger.debug(f"Creating the directory for the collection in {filepath}.") + Path(filepath).mkdir(parents=True) + + def flush_print(text): sys.stdout.write(str(text)) sys.stdout.flush() @@ -269,23 +274,8 @@ def main_extruder_plan( elif parameters.detector_name == "eiger": logger.info("Using Eiger detector") - logger.warning( - """TEMPORARY HACK! - Running a Single image pilatus data collection to create directory.""" - ) # See https://github.com/DiamondLightSource/mx_bluesky/issues/45 - num_shots = 1 - sup.pilatus( - "quickshot-internaltrig", - [filepath, parameters.filename, num_shots, parameters.exposure_time_s], - ) - logger.debug("Sleep 2s waiting for pilatus to arm") - sleep(2.5) - caput(pv.pilat_acquire, "0") # Disarm pilatus - sleep(0.5) - caput(pv.pilat_acquire, "1") # Arm pilatus - logger.debug("Pilatus data collection DONE") - sup.pilatus("return to normal", None) - logger.info("Pilatus back to normal. Single image pilatus data collection DONE") + # STILL TO BE TESTED!!! + _create_directory_for_eiger_collection(filepath) caput(pv.eiger_seqID, int(caget(pv.eiger_seqID)) + 1) logger.info(f"Eiger quickshot setup: filepath {filepath}") diff --git a/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py b/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py index 8f61bbc73..94b35af53 100755 --- a/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py +++ b/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py @@ -67,6 +67,11 @@ def setup_logging(): log.config(logfile) +def _create_directory_for_eiger_collection(filepath: str): + logger.debug(f"Creating the directory for the collection in {filepath}.") + Path(filepath).mkdir(parents=True) + + def calculate_collection_timeout(parameters: FixedTargetParameters) -> float: """Give an estimation of the time the plan should wait for the data collection \ to be finished. @@ -474,24 +479,8 @@ def start_i24( elif parameters.detector_name == "eiger": logger.info("Using Eiger detector") - logger.warning( - """TEMPORARY HACK! - Running a Single image pilatus data collection to create directory.""" - ) - num_imgs = 1 - sup.pilatus( - "quickshot-internaltrig", - [filepath, filename, num_imgs, parameters.exposure_time_s], - ) - logger.debug("Sleep 2s waiting for pilatus to arm") - sleep(2) - sleep(0.5) - caput(pv.pilat_acquire, "0") # Disarm pilatus - sleep(0.5) - caput(pv.pilat_acquire, "1") # Arm pilatus - logger.debug("Pilatus data collection DONE") - sup.pilatus("return to normal", None) - logger.info("Pilatus back to normal. Single image pilatus data collection DONE") + # STILL TO BE TESTED!!! + _create_directory_for_eiger_collection(filepath) logger.info(f"Triggered Eiger setup: filepath {filepath}") logger.info(f"Triggered Eiger setup: filename {filename}") diff --git a/src/mx_bluesky/beamlines/i24/serial/iocStart.sh b/src/mx_bluesky/beamlines/i24/serial/iocStart.sh new file mode 100644 index 000000000..4bd2623e9 --- /dev/null +++ b/src/mx_bluesky/beamlines/i24/serial/iocStart.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Starts a blueapi server on a python IOC to run with procserv + +# Get the directory of this script +current_directory=$( realpath "$( dirname "$0" )" ) +cd $current_directory + +# Source modules environment +source /dls_sw/etc/profile + +# Activate virtual environment +source $current_directory/.venv/bin/activate + +# Start blueapi server +blueapi -c "${current_directory}/blueapi_config.yaml" serve diff --git a/src/mx_bluesky/beamlines/i24/serial/run_extruder.sh b/src/mx_bluesky/beamlines/i24/serial/run_extruder.sh index 8bb54e1d2..daacb81dd 100755 --- a/src/mx_bluesky/beamlines/i24/serial/run_extruder.sh +++ b/src/mx_bluesky/beamlines/i24/serial/run_extruder.sh @@ -1,13 +1,27 @@ #!/bin/bash +NO_PROCESERV_TEST=false + +case "$2" in + -t | --test) + echo "Will run serial in test mode without procserv." + NO_PROCESERV_TEST=true + ;; +esac + + # Get edm path from input edm_path=$1 -# Get the directory of this script -current=$( realpath "$( dirname "$0" )" ) +if [[ $NO_PROCESERV_TEST == true ]]; then + echo "Start the blueapi sever" + + # Get the directory of this script + current=$( realpath "$( dirname "$0" )" ) -# Run script to start blueapi serve -. $current/start_blueapi.sh + # Run script to start blueapi serve + . $current/start_blueapi.sh +fi # Open the edm screen for an extruder serial collection echo "Starting extruder edm screen." @@ -15,5 +29,8 @@ edm -x "${edm_path}/EX-gui/DiamondExtruder-I24-py3v1.edl" echo "Edm screen closed, bye!" -pgrep blueapi | xargs kill -echo "Blueapi process killed" +if [[ $NO_PROCESERV_TEST == true ]]; then + # In this case blueapi server needs to be killed. + pgrep blueapi | xargs kill + echo "Blueapi process killed" +fi diff --git a/src/mx_bluesky/beamlines/i24/serial/run_fixed_target.sh b/src/mx_bluesky/beamlines/i24/serial/run_fixed_target.sh index 011c60713..08be18d04 100755 --- a/src/mx_bluesky/beamlines/i24/serial/run_fixed_target.sh +++ b/src/mx_bluesky/beamlines/i24/serial/run_fixed_target.sh @@ -1,16 +1,29 @@ #!/bin/bash +NO_PROCESERV_TEST=false + +case "$2" in + -t | --test) + echo "Will run serial in test mode without procserv." + NO_PROCESERV_TEST=true + ;; +esac + # Get edm path from input edm_path=$1 # Export env variable for the stages edm to work properly export EDMDATAFILES="/dls_sw/prod/R3.14.12.3/support/motor/6-7-1dls14/motorApp/opi/edl" -# Get the directory of this script -current=$( realpath "$( dirname "$0" )" ) +if [[ $NO_PROCESERV_TEST == true ]]; then + echo "Start the blueapi sever" + + # Get the directory of this script + current=$( realpath "$( dirname "$0" )" ) -# Run script to start blueapi serve -. $current/start_blueapi.sh + # Run script to start blueapi serve + . $current/start_blueapi.sh +fi # Open the edm screen for a fixed target serial collection echo "Starting fixed target edm screen." @@ -18,5 +31,8 @@ edm -x "${edm_path}/FT-gui/DiamondChipI24-py3v1.edl" echo "Edm screen closed, bye!" -pgrep blueapi | xargs kill -echo "Blueapi process killed" +if [[ $NO_PROCESERV_TEST == true ]]; then + # In this case blueapi server needs to be killed. + pgrep blueapi | xargs kill + echo "Blueapi process killed" +fi diff --git a/tests/unit_tests/beamlines/i24/serial/extruder/test_extruder_collect.py b/tests/unit_tests/beamlines/i24/serial/extruder/test_extruder_collect.py index 79e2fcdfd..e6f26f0c9 100644 --- a/tests/unit_tests/beamlines/i24/serial/extruder/test_extruder_collect.py +++ b/tests/unit_tests/beamlines/i24/serial/extruder/test_extruder_collect.py @@ -8,6 +8,7 @@ from mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2 import ( TTL_EIGER, TTL_PILATUS, + _create_directory_for_eiger_collection, collection_aborted_plan, collection_complete_plan, enter_hutch, @@ -82,6 +83,12 @@ def test_initialise_extruder( assert fake_caget.call_count == 1 +@patch("mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.Path") +def test_create_directory_for_eiger_collection(fake_path): + _create_directory_for_eiger_collection("") + fake_path.assert_called_once() + + @patch( "mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.setup_logging" ) @@ -139,7 +146,11 @@ async def test_laser_check( "mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.setup_logging" ) @patch("mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.bps.rd") +@patch( + "mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2._create_directory_for_eiger_collection" +) def test_run_extruder_quickshot_with_eiger( + fake_mkdir, fake_read, fake_log_setup, mock_quickshot_plan, @@ -180,9 +191,9 @@ def test_run_extruder_quickshot_with_eiger( assert fake_dcid.generate_dcid.call_count == 1 assert fake_dcid.notify_start.call_count == 1 assert fake_sup.setup_beamline_for_collection_plan.call_count == 1 - # Check temporary piilatus hack is in there - assert fake_sup.pilatus.call_count == 2 mock_quickshot_plan.assert_called_once() + assert fake_mkdir.call_count == 1 + fake_mkdir.assert_called_with(dummy_params.collection_directory.as_posix()) @patch("mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.sleep") diff --git a/tests/unit_tests/beamlines/i24/serial/fixed_target/test_ft_collect.py b/tests/unit_tests/beamlines/i24/serial/fixed_target/test_ft_collect.py index 3fc1924ce..8e7551be4 100644 --- a/tests/unit_tests/beamlines/i24/serial/fixed_target/test_ft_collect.py +++ b/tests/unit_tests/beamlines/i24/serial/fixed_target/test_ft_collect.py @@ -15,6 +15,7 @@ PumpProbeSetting, ) from mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1 import ( + calculate_collection_timeout, datasetsizei24, finish_i24, get_chip_prog_values, @@ -37,6 +38,25 @@ def fake_generator(value): return value +def test_calculate_collection_timeout(dummy_params_without_pp): + dummy_params_without_pp.total_num_images = 400 + expected_collection_time = ( + dummy_params_without_pp.total_num_images + * dummy_params_without_pp.exposure_time_s + ) + timeout = calculate_collection_timeout(dummy_params_without_pp) + + assert timeout == expected_collection_time + 30.0 + + +def test_calculate_collection_timeout_for_eava(dummy_params_with_pp): + dummy_params_with_pp.total_num_images = 400 + expected_pump_and_probe_time = 12.05 + timeout = calculate_collection_timeout(dummy_params_with_pp) + + assert timeout == expected_pump_and_probe_time + 30.0 + + @patch("mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1.caput") def test_datasetsizei24_for_one_block_and_two_exposures( fake_caput, dummy_params_without_pp @@ -134,7 +154,11 @@ def test_load_motion_program_data( @patch("mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1.caget") @patch("mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1.sup") @patch("mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1.sleep") +@patch( + "mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1._create_directory_for_eiger_collection" +) def test_start_i24_with_eiger( + fake_mkdir, fake_sleep, fake_sup, fake_caget, @@ -165,9 +189,11 @@ def test_start_i24_with_eiger( assert fake_sup.eiger.call_count == 1 assert fake_sup.setup_beamline_for_collection_plan.call_count == 1 assert fake_sup.move_detector_stage_to_position_plan.call_count == 1 - # Pilatus gets called for hack to create directory - assert fake_sup.pilatus.call_count == 2 assert fake_dcid.generate_dcid.call_count == 1 + assert fake_mkdir.call_count == 1 + fake_mkdir.assert_called_with( + dummy_params_without_pp.collection_directory.as_posix() + ) shutter_call_list = [ call("Reset", wait=True, timeout=10.0),