Build Packages / Create release (push) Successful in 8s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 4m52s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 9m14s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 15m2s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 20m44s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 21m49s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 22m3s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 26m5s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 26m45s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 27m15s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 28m0s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 22m22s
Build Packages / Generate python client (push) Successful in 24s
Build Packages / Build documentation (push) Successful in 1m16s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 23m36s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 27m10s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 26m35s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 22m7s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 25m14s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 26m56s
Build Packages / Unit tests (push) Successful in 1h33m16s
Build Packages / Validation Battery (push) Successful in 32m33s
Initialize is the fresh start between users. It already cleared the images, plots, scan result and live rugnux status; it now also drops the tokens, resets the dataset settings (name, file prefix, unit cell, ...) to their defaults and forgets the last collection followed through /live/events, so after it nothing of the previous dataset is readable, with or without its token - the broker is as open and as empty as a freshly started one. The auth test checks that after /initialize the data-collection statistics and the /statistics aggregate are open and no longer carry the previous dataset's name. SECURITY.md also lists /rugnux/status among the protected endpoints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXc1zD1yxHqaR1DGdCTHL4
115 lines
3.2 KiB
C++
115 lines
3.2 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "LiveCollection.h"
|
|
|
|
#include "../writer/HDF5NXmx.h"
|
|
|
|
void LiveCollection::Expect() {
|
|
{
|
|
std::unique_lock ul(m);
|
|
const uint64_t generation = state.generation + 1;
|
|
state = Snapshot{};
|
|
state.generation = generation;
|
|
start_cbor.clear();
|
|
}
|
|
cv.notify_all();
|
|
}
|
|
|
|
void LiveCollection::Begin(const StartMessage &start, std::vector<uint8_t> cbor) {
|
|
{
|
|
std::unique_lock ul(m);
|
|
// The collection Expect announced, or - when nothing announced it - a new one.
|
|
if (state.generation == 0 || state.started || state.ended) {
|
|
const uint64_t generation = state.generation + 1;
|
|
state = Snapshot{};
|
|
state.generation = generation;
|
|
}
|
|
state.started = true;
|
|
state.run_number = start.run_number;
|
|
state.run_name = start.run_name;
|
|
state.file_prefix = start.file_prefix;
|
|
state.number_of_images = start.number_of_images;
|
|
state.images_per_file = start.images_per_file;
|
|
start_message = start;
|
|
start_cbor = std::move(cbor);
|
|
}
|
|
cv.notify_all();
|
|
}
|
|
|
|
void LiveCollection::FileClosed(uint64_t file_number, uint64_t image_count) {
|
|
{
|
|
std::unique_lock ul(m);
|
|
if (!state.started || state.ended)
|
|
return;
|
|
state.files.push_back(DataFile{
|
|
.file_number = file_number,
|
|
.file = HDF5Metadata::DataFileName(start_message, static_cast<int64_t>(file_number)),
|
|
.first_image = file_number * static_cast<uint64_t>(state.images_per_file),
|
|
.image_count = image_count
|
|
});
|
|
}
|
|
cv.notify_all();
|
|
}
|
|
|
|
void LiveCollection::End(uint64_t images, const std::string &error) {
|
|
{
|
|
std::unique_lock ul(m);
|
|
if (state.generation == 0 || state.ended)
|
|
return;
|
|
state.ended = true;
|
|
state.end_images = images;
|
|
state.end_error = error;
|
|
}
|
|
cv.notify_all();
|
|
}
|
|
|
|
void LiveCollection::EndIfOpen(const std::string &error) {
|
|
End(0, error);
|
|
}
|
|
|
|
void LiveCollection::Forget() {
|
|
{
|
|
std::unique_lock ul(m);
|
|
state = Snapshot{};
|
|
start_message = StartMessage{};
|
|
start_cbor.clear();
|
|
}
|
|
cv.notify_all();
|
|
}
|
|
|
|
std::optional<std::vector<uint8_t>> LiveCollection::StartCBOR() const {
|
|
std::unique_lock ul(m);
|
|
if (!state.started)
|
|
return {};
|
|
return start_cbor;
|
|
}
|
|
|
|
LiveCollection::Snapshot LiveCollection::Wait(uint64_t generation, bool started_seen, size_t files_seen,
|
|
std::chrono::milliseconds wait) {
|
|
std::unique_lock ul(m);
|
|
cv.wait_for(ul, wait, [&] {
|
|
return state.generation != generation || state.ended || state.files.size() > files_seen
|
|
|| (state.started && !started_seen);
|
|
});
|
|
return state;
|
|
}
|
|
|
|
LiveCollection::Snapshot LiveCollection::Get() const {
|
|
std::unique_lock ul(m);
|
|
return state;
|
|
}
|
|
|
|
bool LiveCollection::AcquireFollower() {
|
|
std::unique_lock ul(m);
|
|
if (follower)
|
|
return false;
|
|
follower = true;
|
|
return true;
|
|
}
|
|
|
|
void LiveCollection::ReleaseFollower() {
|
|
std::unique_lock ul(m);
|
|
follower = false;
|
|
}
|