|
6 | 6 | from pathlib import Path |
7 | 7 | from typing import Optional |
8 | 8 |
|
| 9 | +from murfey.util.config import get_machine_config |
| 10 | + |
9 | 11 | try: |
10 | 12 | from murfey.server.ispyb import TransportManager # Session |
11 | 13 | except AttributeError: |
12 | 14 | pass # Ignore if ISPyB credentials environment variable not set |
13 | 15 |
|
14 | 16 |
|
15 | 17 | def zocalo_cluster_request( |
16 | | - file: Path, |
| 18 | + tiff_list: list[Path], |
17 | 19 | root_folder: str, |
| 20 | + session_id: int, |
| 21 | + instrument_name: str, |
18 | 22 | metadata: Optional[Path] = None, |
19 | 23 | messenger: Optional[TransportManager] = None, |
20 | 24 | ): |
21 | 25 | if messenger: |
22 | 26 | # Construct path to session directory |
23 | | - path_parts = list(file.parts) |
24 | | - new_path = [] |
25 | | - for p in range(len(path_parts)): |
26 | | - part = path_parts[p] |
27 | | - # Remove leading slash for subsequent rejoining |
28 | | - if part == "/": |
29 | | - part = "" |
30 | | - # Append up to, but not including, root folder |
31 | | - if part.lower() == root_folder.lower(): |
32 | | - break |
33 | | - new_path.append(part) |
34 | | - session_dir = Path("/".join(new_path)) |
| 27 | + path_parts = list(tiff_list[0].parts) |
| 28 | + # Replace leading "/" in Unix paths |
| 29 | + path_parts[0] = "" if path_parts[0] == "/" else path_parts[0] |
| 30 | + try: |
| 31 | + # Find the position of the root folder in the list |
| 32 | + root_index = [p.lower() for p in path_parts].index(root_folder.lower()) |
| 33 | + except ValueError: |
| 34 | + raise Exception( |
| 35 | + f"Unable to find the root folder {root_folder!r} in the file path {tiff_list[0]!r}" |
| 36 | + ) |
| 37 | + # Construct the session and job name |
| 38 | + session_dir = "/".join(path_parts[:root_index]) |
35 | 39 |
|
36 | 40 | # If no metadata file provided, generate path to one |
37 | 41 | if metadata is None: |
38 | | - series_name = file.stem.split("--")[0] |
39 | | - metadata = file.parent / "Metadata" / (series_name + ".xlif") |
| 42 | + series_name = tiff_list[0].stem.split("--")[0] |
| 43 | + metadata = tiff_list[0].parent / "Metadata" / (series_name + ".xlif") |
| 44 | + |
| 45 | + # Load machine config to get the feedback queue |
| 46 | + machine_config = get_machine_config() |
| 47 | + feedback_queue = machine_config[instrument_name].feedback_queue |
40 | 48 |
|
41 | 49 | messenger.send( |
42 | 50 | "processing_recipe", |
43 | 51 | { |
44 | 52 | "recipes": ["clem-tiff-to-stack"], |
45 | 53 | "parameters": { |
46 | | - "session_dir": str(session_dir), |
47 | | - "tiff_path": str(file), |
48 | | - "root_dir": root_folder, |
| 54 | + # Job parameters |
| 55 | + "tiff_list": tiff_list, |
| 56 | + "root_folder": root_folder, |
49 | 57 | "metadata": str(metadata), |
| 58 | + "tiff_file": "null", |
| 59 | + # Other recipe parameters |
| 60 | + "session_dir": str(session_dir), |
| 61 | + "session_id": session_id, |
| 62 | + "job_name": series_name, |
| 63 | + "feedback_queue": feedback_queue, |
50 | 64 | }, |
51 | 65 | }, |
52 | 66 | new_connection=True, |
|
0 commit comments