Merge branch 'rotscale' into rc175

This commit is contained in:
leonarski_f committed 2026-10-08 14:12:15 +02:00
commit 6079c5ab44
5 files changed
+872 -693

No files matched your search

+12 -4
View File
@@ -476,7 +476,7 @@ void Rugnux::CollectSpeculativeProbe() {
speculative_probe_.reset();
}
std::vector<double> Rugnux::ExperimentKey() const {
std::vector<double> Rugnux::ExperimentKey(bool rotation_angles) const {
std::vector<double> k{experiment_.GetBeamX_pxl(), experiment_.GetBeamY_pxl(),
experiment_.GetDetectorDistance_mm(), experiment_.GetPoniRot1_rad(),
experiment_.GetPoniRot2_rad(), experiment_.GetWavelength_A(),
@@ -484,8 +484,10 @@ std::vector<double> Rugnux::ExperimentKey() const {
if (const auto g = experiment_.GetGoniometer()) {
const Coord a = g->GetAxis();
const auto helical = g->GetHelicalStep().value_or(Coord(-1, -1, -1));
k.insert(k.end(), {1.0, a.x, a.y, a.z, g->GetStart_deg(), g->GetIncrement_deg(), g->GetWedge_deg(),
g->GetScreeningWedge().value_or(-1.0f), helical.x, helical.y, helical.z});
k.insert(k.end(), {1.0, a.x, a.y, a.z, helical.x, helical.y, helical.z});
if (rotation_angles)
k.insert(k.end(), {g->GetStart_deg(), g->GetIncrement_deg(), g->GetWedge_deg(),
g->GetScreeningWedge().value_or(-1.0f)});
} else
k.push_back(0.0);
if (const auto uc = experiment_.GetUnitCell())
@@ -511,7 +513,10 @@ std::vector<double> Rugnux::ExperimentKey() const {
}
std::vector<double> Rugnux::SpotFindingKey(const AzimuthalIntegrationMapping &mapping) const {
std::vector<double> k = ExperimentKey();
// Without the rotation angles: a frame's spots are found the same under any of them, and the angle
// each spot carries is stamped again where a list is taken from the store (prefetch_spots). The
// probes of the rotation-scale walk differ only there, so they find the spots of a frame once.
std::vector<double> k = ExperimentKey(/*rotation_angles=*/false);
const auto &f = config_.spot_finding;
k.insert(k.end(), {static_cast<double>(f.enable), f.low_resolution_limit.value_or(-1.0f),
f.cutoff_spot_count_low_res, f.high_res_gap_Q_recipA.value_or(-1.0f),
@@ -858,6 +863,9 @@ ProcessResult Rugnux::RunPipeline(RugnuxObserver *observer, bool write_output, b
if (FirstPassRotationIndexing(p))
return result;
}
// The rotation-scale walk beside this pass starts once its frames are indexed (see RunAllPasses).
if (rotation_scale_check_)
rotation_scale_check_->Set(rotation_scale_check_->output_indexed);
// Whether the lattice this pass integrates on has an index-2 superstructure. Nothing before
// integration can ask it: every count the lattice decisions use is dominated by the sub-lattice's
+60 -3
View File
@@ -5,6 +5,7 @@
#include <array>
#include <atomic>
#include <condition_variable>
#include <future>
#include <memory>
#include <mutex>
@@ -595,9 +596,13 @@ class Rugnux {
// side (see RunAllPasses), so cancelling the run cancels those too.
class CancelFlag {
std::shared_ptr<std::atomic<bool>> flag = std::make_shared<std::atomic<bool>>(false);
// The run's flag, on a copy whose work can be called off by itself (Own).
std::shared_ptr<std::atomic<bool>> run;
public:
operator bool() const { return flag->load(); }
operator bool() const { return flag->load() || (run && run->load()); }
CancelFlag &operator=(bool v) { flag->store(v); return *this; }
// A flag of its own that cancelling the run still sets.
CancelFlag Own() const { CancelFlag f; f.run = flag; return f; }
};
CancelFlag cancelled_;
@@ -802,8 +807,9 @@ class Rugnux {
void StartSpeculativeGeometryProbe(std::shared_ptr<Rugnux> run, const std::array<float, 5> &geometry);
void CollectSpeculativeProbe();
[[nodiscard]] std::vector<double> FirstPassInputKey() const;
// The part of FirstPassInputKey that is the experiment and the spot-finding settings.
[[nodiscard]] std::vector<double> ExperimentKey() const;
// The part of FirstPassInputKey that is the experiment and the spot-finding settings; without the
// goniometer's angles where rotation_angles is false (SpotFindingKey).
[[nodiscard]] std::vector<double> ExperimentKey(bool rotation_angles = true) const;
// The file's detector distance, from before the first pass of the rotation two-pass: a pass whose
// distance is still this one asks the post-refinement to test "the header distance is right"
// (PostRefineSettings::distance_at_header); a pass that has walked off it does not.
@@ -860,6 +866,57 @@ class Rugnux {
// Every pass of the run, returning the canonical one. Run() wraps this to time the whole thing.
ProcessResult RunAllPasses(RugnuxObserver *observer);
// The rotation-scale walk of the rotation two-pass and the refined passes after it run side by side
// (see RunAllPasses): the walk on the run, the refined passes on a copy of it, at the stored angles.
// What the two share.
struct RotationScaleCheck {
std::mutex m;
std::condition_variable cv;
bool output_indexed = false; // the output pass has indexed: the walk can start
bool output_ended = false; // the refined passes have returned
bool called_off = false; // the walk has called them off
bool done = false; // the walk has ended
bool overturns = false; // the refined passes did not start where the walk leaves the run
int passes = 0; // the probe passes the walk ran
std::string text; // its trail, for the pass decision
void Set(bool &flag) {
{ std::lock_guard lock(m); flag = true; }
cv.notify_all();
}
void Wait(const bool &flag) {
std::unique_lock lock(m);
cv.wait(lock, [&] { return flag; });
}
// Whether the refined passes are to be thrown away, once the walk has ended or called them off.
bool Overturns() {
std::unique_lock lock(m);
cv.wait(lock, [&] { return done || called_off; });
return overturns || called_off;
}
};
// Set on the copy that runs the refined passes beside the walk.
std::shared_ptr<RotationScaleCheck> rotation_scale_check_;
// The walk's part of the canonical pass's record: the probe passes it ran and its trail.
struct RotationScaleOutcome {
int passes = 0;
std::string text;
};
// What the refined passes start from.
struct RefinedPassStart {
std::string base_prefix;
std::optional<GoniometerAxis> gonio_snapshot;
std::array<float, 5> header_geometry{};
RotationScaleOutcome scale_walk; // where the walk has ended before they start
};
// The refined passes of the rotation two-pass, from the second pass on. Empty where they ran beside
// the rotation-scale walk and it overturned them.
std::optional<ProcessResult> RefinedPasses(RugnuxObserver *observer, ProcessResult pass1,
const RefinedPassStart &start);
// The rotation-scale walk, run on the run while the refined passes run on a copy of it; `check` is
// what the two share, and output_cancel calls the copy off.
RotationScaleWalk WalkRotationScaleBeside(const ProcessResult &pass1, RotationScaleCheck &check,
CancelFlag output_cancel);
public:
Rugnux(JFJochReader &reader, DiffractionExperiment experiment,
PixelMask pixel_mask, ProcessConfig config);
+13 -1
View File
@@ -105,6 +105,15 @@ namespace {
return true;
}
// The spindle angle each spot of a list carries, stamped as DiffractionSpot::Export stamps it. It
// is the only part of a frame's spot list that depends on the goniometer, so a list found under
// other angles (see SpotFindingKey) is stamped again for the angles in hand.
void StampSpotAngles(std::vector<SpotToSave> &spots, const DiffractionGeometry &geometry) {
const auto rotation = geometry.GetRotation();
for (auto &s : spots)
s.phi = rotation ? rotation->GetAngle_deg(s.image) + rotation->GetWedge_deg() / 2.0f : 0.0f;
}
// === Is the larger of two integer-related cells real, or a spurious axis multiple? ===
//
// The validation-FRAME count cannot answer it: a spurious multiple indexes every frame its true
@@ -294,7 +303,7 @@ bool Rugnux::FirstPassRotationIndexing(PipelineLocals &p) {
double prefetch_time_s = 0.0;
const auto prefetch_spots = [&](const std::vector<int> &ordinals) {
// What an earlier pass already found under the same key (first_pass_spots_) is taken from
// there.
// there, at this pass's angles.
const std::vector<double> key = SpotFindingKey(*spot_mapping);
std::map<int, std::vector<SpotToSave>> kept;
{
@@ -305,6 +314,9 @@ bool Rugnux::FirstPassRotationIndexing(PipelineLocals &p) {
if (const auto it = spots.find(ordinal); it != spots.end())
kept.emplace(ordinal, it->second);
}
const DiffractionGeometry spot_geometry = experiment_.GetDiffractionGeometry();
for (auto &[ordinal, spots] : kept)
StampSpotAngles(spots, spot_geometry);
std::vector<int> wanted;
for (const int ordinal : ordinals)
if (!spot_cache.contains(ordinal)) {
+779 -681
View File
File diff suppressed because it is too large. Load diff
+8 -4
View File
@@ -2679,11 +2679,15 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
// Nothing below this point is read by a later pass: the analyses are report-only (see each),
// the files are rewritten by the pass that supersedes this one, and the one place that touches
// experiment_ - the model frame - is undone by the SetSpaceGroup at the top of RunPipeline.
//
// A refined pass run beside the rotation-scale walk is superseded too where the walk overturns it
// (see RunAllPasses); it waits here for the walk's answer.
superseded =
!cancelled_ && quality_guard_pass1_ && quality_guard_pass1_->has_merge_statistics
&& ((bragg_adaptive_ && bkg_starved_fraction_
&& *bkg_starved_fraction_ > spot_width::BKG_STARVED_MAX_FRACTION)
|| !RefinedPassIsWorse(*quality_guard_pass1_, result).empty());
(!cancelled_ && quality_guard_pass1_ && quality_guard_pass1_->has_merge_statistics
&& ((bragg_adaptive_ && bkg_starved_fraction_
&& *bkg_starved_fraction_ > spot_width::BKG_STARVED_MAX_FRACTION)
|| !RefinedPassIsWorse(*quality_guard_pass1_, result).empty()))
|| (rotation_scale_check_ && rotation_scale_check_->Overturns());
if (superseded) {
logger.Info("This pass is going to be re-run, so it makes no report and writes no files.");
Note("this pass is to be re-run (see the log); it writes nothing");