Files
Jungfraujoch/receiver/RugnuxLiveStatus.cpp
T
leonarski_fandClaude Opus 5.5 3a44779d79 broker: rugnux live - rugnux runs inside the broker while a DECTRIS rotation collection arrives (demo prototype)
A DECTRIS rotation collection, with the mode switched on (PUT /config/rugnux), goes to
JFJochReceiverRugnux instead of JFJochReceiverLite: the images are forwarded as before, without the
per-image analysis, and one rugnux thread reads them back from the image buffer
(JFJochImageBufferReader) as they arrive. END waits for rugnux and carries its lattice, refined
geometry and per-image results. A small second run on the first 60 degrees reports early whether
there is a lattice. The live state, steps and result are at GET /rugnux/status and on a new
"Rugnux live" frontend page.

rugnux: ProcessConfig::fast_live takes every decision where it is first made and does nothing again
once the sweep is in (near-tie re-checks and the run made again, rotation-scale walk, metric-symmetry
arms, geometry walk, the supercell and quality guards, the doubled cell), so the run ends a fixed
time after the last image. A cut (/cancel, or deadline_s after the last image) hands over what is
established. Off by default: the CLI and the battery are unchanged (--fast-live is hidden, with
--simulate-live).

With the mode off the broker is unchanged. Not built yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 12:20:38 +02:00

96 lines
2.7 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#include "RugnuxLiveStatus.h"
double RugnuxLiveStatus::Now() const {
return std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
}
void RugnuxLiveStatus::CloseStep() {
if (!s.steps.empty() && !s.steps.back().duration_s)
s.steps.back().duration_s = Now() - s.steps.back().started_s;
}
void RugnuxLiveStatus::Start(int64_t images_expected) {
std::unique_lock ul(m);
s = RugnuxLiveSnapshot{};
s.state = RugnuxLiveState::Running;
s.images_expected = images_expected;
start = std::chrono::steady_clock::now();
}
void RugnuxLiveStatus::ImageReceived() {
std::unique_lock ul(m);
++s.images_received;
}
void RugnuxLiveStatus::Step(const std::string &title) {
std::unique_lock ul(m);
CloseStep();
s.steps.push_back(RugnuxLiveStep{.title = title, .started_s = Now()});
s.step_progress.reset();
}
void RugnuxLiveStatus::Note(const std::string &text) {
std::unique_lock ul(m);
if (s.steps.empty())
s.steps.push_back(RugnuxLiveStep{.title = "", .started_s = Now()});
s.steps.back().notes.push_back(text);
}
void RugnuxLiveStatus::Progress(uint64_t done, uint64_t total) {
std::unique_lock ul(m);
if (total > 0)
s.step_progress = static_cast<float>(done) / static_cast<float>(total);
}
void RugnuxLiveStatus::Finish(RugnuxLiveState state, const std::string &message) {
std::unique_lock ul(m);
CloseStep();
s.elapsed_s = Now();
s.state = state;
s.message = message;
s.step_progress.reset();
}
void RugnuxLiveStatus::Result(const std::string &verdict, const std::string &verdict_text,
const std::vector<std::pair<std::string, std::string>> &summary,
const std::vector<std::string> &warnings) {
std::unique_lock ul(m);
s.verdict = verdict;
s.verdict_text = verdict_text;
s.summary = summary;
s.warnings = warnings;
}
void RugnuxLiveStatus::Latency(double last_image_to_written_s) {
std::unique_lock ul(m);
s.last_image_to_written_s = last_image_to_written_s;
}
void RugnuxLiveStatus::LastImage() {
std::unique_lock ul(m);
s.last_image_s = Now();
}
void RugnuxLiveStatus::Cut(const std::string &reason) {
std::unique_lock ul(m);
s.cut = reason;
s.cut_s = Now();
}
void RugnuxLiveStatus::Probe(const std::string &text) {
std::unique_lock ul(m);
s.probe = text;
s.probe_s = Now();
}
RugnuxLiveSnapshot RugnuxLiveStatus::Get() const {
std::unique_lock ul(m);
RugnuxLiveSnapshot ret = s;
if (s.state == RugnuxLiveState::Running)
ret.elapsed_s = Now();
return ret;
}