diff --git a/rugnux/Rugnux.cpp b/rugnux/Rugnux.cpp index b79718c88..91dceda14 100644 --- a/rugnux/Rugnux.cpp +++ b/rugnux/Rugnux.cpp @@ -2704,6 +2704,11 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) { ValidationSpotEvidence best_evidence = pass2.validation_evidence; std::optional probe_at_best; // the indexing probe at best_geometry, once run bool large_walk = false; // a round of this walk was started by a move of a step or more + // What the last round started from: a pass can leave the run changed behind it (a spot budget + // it shortened, an axis sign it flipped, a beam-centre search it ran), so a round is written + // from here, not from where its own probe left the run. + DiffractionExperiment last_round_start = experiment_; + bool last_round_searched = beam_center_searched_; while (!cancelled_ && prepass_detector_geometry_ && pass2.post_refine && pass2.post_refine->detector_refined) { if (geometry_rounds == MAX_GEOMETRY_ROUNDS) { @@ -2738,8 +2743,14 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) { "asks for (round {} of at most {})", fit.distance_before_mm, fit.distance_after_mm, geometry_rounds + 1, MAX_GEOMETRY_ROUNDS); set_geometry(g); + last_round_start = experiment_; + last_round_searched = beam_center_searched_; + // A round is a probe pass: the walk reads only its fit and its validation evidence, both in + // hand before the merge, so the files are written once, below, at the round the walk keeps. speculate_geometry_probe_ = !large_walk; - pass2 = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false); + postrefine_probe_only_ = true; + pass2 = RunPipeline(observer, /*write_output=*/false, /*geometry_prepass=*/false); + postrefine_probe_only_ = false; speculate_geometry_probe_ = false; ++geometry_rounds; ++walk_passes; @@ -2776,12 +2787,18 @@ ProcessResult Rugnux::RunAllPasses(RugnuxObserver *observer) { last_pushback = pushback; } postrefine_probe_ = false; - // The canonical files were written by the last round; where that is not the best one, the best - // one is run again to write them. - if (!cancelled_ && geometry_rounds > best_round) { - logger.Info("Two-pass: going back to round {} of the geometry walk (distance {:.3f} mm), the " - "last one that lowered the realised residual", best_round, best_geometry[2]); - set_geometry(best_geometry); + // The rounds wrote nothing, so the round the walk kept is run again to write the canonical files. + if (!cancelled_ && geometry_rounds > 0) { + if (best_round == geometry_rounds) { + logger.Info("Two-pass: writing round {} of the geometry walk (distance {:.3f} mm)", + best_round, best_geometry[2]); + experiment_ = last_round_start; + beam_center_searched_ = last_round_searched; + } else { + logger.Info("Two-pass: going back to round {} of the geometry walk (distance {:.3f} mm), " + "the last one that lowered the realised residual", best_round, best_geometry[2]); + set_geometry(best_geometry); + } pass2 = RunPipeline(observer, /*write_output=*/true, /*geometry_prepass=*/false); ++walk_passes; }