diff --git a/src/xfel_calibrate/finalize.py b/src/xfel_calibrate/finalize.py index 88f264af0f2faba410a2a34ca54461e3e0e8afe7..7eabeb96ba531c562b6f667a05186b4fb8f6b1d1 100644 --- a/src/xfel_calibrate/finalize.py +++ b/src/xfel_calibrate/finalize.py @@ -417,7 +417,6 @@ def finalize(joblist, finaljob, run_path, out_path, version, title, author, repo ) metadata.save() - if report_to: report_to = Path(report_to) prepare_plots(run_path) @@ -435,10 +434,19 @@ def finalize(joblist, finaljob, run_path, out_path, version, title, author, repo # Store the contents of the Slurm working directory next to the report. # This contains elements needed for reproducibility. slurm_archive_dir = report_to.parent / f"slurm_out_{report_to.name}" + det = metadata['calibration-configurations'].get('karabo-id', report_to.name) else: + try: + det = metadata['calibration-configurations']['karabo-id'] + except KeyError: + # Generate a hash based on job IDs to uniquely identify this + # detector. + from hashlib import sha1 + det = sha1(''.join(joblist).encode('ascii')).hexdigest()[:8] + # If there is no report location, simply move the slurm_out_ # directory to the output. - slurm_archive_dir = Path(out_path) / f"slurm_out_{run_path.name}" + slurm_archive_dir = Path(out_path) / f"slurm_out_{det}" print(f"Moving temporary files to final location: {slurm_archive_dir}") move(str(run_path), str(slurm_archive_dir)) # Needs str until Python 3.9 @@ -448,7 +456,7 @@ def finalize(joblist, finaljob, run_path, out_path, version, title, author, repo # unique name like calibration_metadata_MID_DET_AGIPD1M-1.yml in the output # folder. In case they don't, fall back to a name like the report. # To avoid interleaved writes, we'll copy it to a temp folder, then rename. - det = metadata['calibration-configurations'].get('karabo-id', report_to.name) + with TemporaryDirectory(dir=out_path) as td: tmp_path = Path(td, f"calibration_metadata_{det}.yml") copy(md_path, tmp_path)