Build Packages / Build documentation (push) Successful in 48s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 15m47s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 23m19s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 18m47s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m54s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m27s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 26m59s
Build Packages / Unit tests (push) Successful in 1h50m25s
Build Packages / Validation Battery (push) Successful in 46m38s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 32m52s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 32m32s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 28m34s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 29m19s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 30m11s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 33m58s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 31m26s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 34m4s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 32m17s
Build Packages / Generate python client (push) Successful in 32s
Build Packages / Create release (push) Successful in 9s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 31m50s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 19m38s
* jfjoch_broker (experimental): Live Rugnux covers serial collections from DECTRIS detectors; a rotation collection too large for the image buffer falls back to standard per-image processing with a warning, and a stream that ends without its end message finishes the collection instead of hanging it. * jfjoch_broker (experimental): Live Rugnux settings to build the solvent during refinement and to process a rotation collection as stills, a Clear action for the last result, a `_report.txt` for live rotation runs, R-free reported for the refined model, and ice-ring detection on by default for rotation as in the command line. * jfjoch_broker (experimental): More complete and reproducible live serial merges, analysed for twinning, pseudo-translation and anisotropy, with merging statistics by resolution shell in the live status. * jfjoch_writer: Live results with large models are written reliably; update jfjoch_writer together with jfjoch_broker. * Rugnux: Several masters can be processed together with `--force-still`, including grid scans; more robust and faster merging of several sweeps; improved twinning, pseudo-translation, anisotropy, anomalous-signal and space-group decisions. * Rugnux: Molecular replacement places the copies of a multi-copy solution together; the pseudo-translation warning quotes the Patterson peak and is not raised once a model is placed; the report advises on extending the rotation or reorienting the crystal where the coverage would gain from it. * Web frontend: Light and dark modes, a phone layout, a hideable page list, a redesigned Rugnux live page with step-through of the Fo-Fc peaks in the structure view. * jfjoch_viewer: A broker URL given on the command line follows the running collection. Reviewed-on: #97 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
104 lines
3.6 KiB
C++
104 lines
3.6 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include "ThreadSafeFIFO.h"
|
|
#include "DiffractionExperiment.h"
|
|
|
|
class ZeroCopyReturnValue;
|
|
|
|
enum class ImageBufferEntryStatus {Empty, InPreparation, Sending, Idle};
|
|
|
|
struct ImageBufferStatus {
|
|
std::vector<int64_t> images_in_the_buffer;
|
|
int64_t min_image_number;
|
|
int64_t max_image_number;
|
|
|
|
int64_t total_slots;
|
|
int64_t available_slots;
|
|
int64_t preparation_slots;
|
|
int64_t sending_slots;
|
|
std::optional<int64_t> current_counter;
|
|
};
|
|
|
|
struct ImageBufferEntry {
|
|
int64_t image_number = -1;
|
|
size_t image_size = 0;
|
|
int64_t readers = 0;
|
|
ImageBufferEntryStatus status = ImageBufferEntryStatus::Empty;
|
|
bool indexed = false;
|
|
};
|
|
|
|
class ImageBuffer {
|
|
mutable std::mutex m;
|
|
std::condition_variable cv_preview_done;
|
|
std::condition_variable cv_preparation_done;
|
|
std::condition_variable cv_send_done;
|
|
uint8_t *buffer;
|
|
const size_t buffer_size;
|
|
|
|
size_t slot_size = 0;
|
|
int64_t slot_count = 0;
|
|
|
|
std::queue<uint32_t> free_slots;
|
|
std::vector<ImageBufferEntry> v;
|
|
std::vector<ZeroCopyReturnValue> send_buffer_zero_copy_ret_val;
|
|
int64_t slots_preparation = 0;
|
|
int64_t slots_sending = 0;
|
|
int64_t slots_in_preview = 0;
|
|
|
|
bool disable_requests = true; // All requests fail in this state
|
|
int64_t counter = 0; // Counter is increased when something changes in the image buffer
|
|
|
|
std::mutex start_message_mutex;
|
|
std::vector<uint8_t> start_message;
|
|
|
|
// Assumes existing lock
|
|
bool FinalizeInternal(std::unique_lock<std::mutex> &ul,
|
|
std::chrono::microseconds timeout = std::chrono::milliseconds(2500));
|
|
|
|
std::optional<uint32_t> getHandle(int64_t image_number) const;
|
|
std::optional<uint32_t> getHandleMaxImage() const;
|
|
std::optional<uint32_t> getHandleMaxIndexedImage() const;
|
|
|
|
uint8_t *GetBufferLocation(size_t id); // image metadata + image
|
|
public:
|
|
constexpr static int64_t MaxImage = -1;
|
|
constexpr static int64_t MaxIndexedImage = -2;
|
|
|
|
explicit ImageBuffer(size_t buffer_size_bytes);
|
|
~ImageBuffer();
|
|
ImageBuffer(const ImageBuffer &) = delete;
|
|
ImageBuffer &operator=(const ImageBuffer &) = delete;
|
|
|
|
void StartMeasurement(size_t buffer_location_size);
|
|
void StartMeasurement(const DiffractionExperiment& experiment);
|
|
|
|
// Nullptr where no more than `keep_free` slots are free.
|
|
ZeroCopyReturnValue *GetImageSlot(int64_t keep_free = 0);
|
|
void ReadyToSend(uint32_t location, int64_t image_number, size_t image_size, bool indexed);
|
|
void ReleaseSlot(uint32_t location);
|
|
// Gives the slot back unsent, in preparation or sending, and forgets its image: no request finds it again
|
|
void DiscardSlot(uint32_t location);
|
|
|
|
// Results kept beside the images (plots, scan result) changed: counted as a change of the buffer, which is
|
|
// what a client following the collection (jfjoch_viewer) watches before it reads them again
|
|
void ResultsChanged();
|
|
|
|
int64_t GetAvailSlots() const;
|
|
size_t GetBufferSize() const;
|
|
|
|
bool CheckIfBufferReturned(std::chrono::microseconds timeout);
|
|
bool Finalize(std::chrono::microseconds timeout);
|
|
|
|
bool GetImage(std::vector<uint8_t> &out_v, int64_t image_number = MaxImage);
|
|
|
|
void SaveStartMessage(const std::vector<uint8_t> &msg);
|
|
void GetStartMessage(std::vector<uint8_t> &out_v);
|
|
|
|
// Only the slot counters, no image list: cheap enough to call for every image
|
|
ImageBufferStatus GetSlotStatus() const;
|
|
ImageBufferStatus GetStatus() const;
|
|
};
|