Files
Jungfraujoch/reader/JFJochImageBufferReader.h
leonarski_f 8261b7354e
Build Packages / Create release (push) Successful in 9s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m8s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m12s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 16m43s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 20m56s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 22m4s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 26m57s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 28m24s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 27m58s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 29m29s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 18m23s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 19m55s
Build Packages / Generate python client (push) Successful in 32s
Build Packages / Build documentation (push) Successful in 1m32s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 27m20s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 29m27s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 32m41s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 34m46s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 37m25s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 35m56s
Build Packages / Unit tests (push) Successful in 2h8m44s
Build Packages / Validation Battery (push) Successful in 33m35s
v1.0.0-rc.176 (#86)
* jfjoch_broker: Optional live Rugnux analysis of DECTRIS rotation collections inside the broker, with merged data, maps and the placed model written beside the master file, the rotation lattice in the scan result, and a "Rugnux live" tab and dashboard row in the web frontend.
* Rugnux: Faster processing, with molecular replacement and model validation spread over several GPUs and run on the Apple GPU on macOS.
* Rugnux: The polarization stated in miniCBF and d*TREK headers is used, twinned crystals' space groups are decided more reliably, and a run that finds no lattice still reports every image.

Reviewed-on: #86
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-10-19 07:03:28 +02:00

60 lines
2.5 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <string>
#include <vector>
#include "JFJochReader.h"
#include "../common/ImageBuffer.h"
// Reads a collection inside the broker while it arrives: the dataset comes from its start message,
// the images from the broker's image buffer, where the receiver puts each one as it forwards it. A
// read of an image not there yet waits for it; after Ended it returns false for an image that never
// came, and so does a read of an image still missing when one MAX_IMAGE_LAG past it is there. The
// buffer must hold the whole collection (slots >= images) - a slot taken again for a later
// image would hand out that image instead. However many threads wait, one at a time looks at the buffer,
// every POLL_PERIOD, so the waiting stays off the lock the receiver puts the images in under.
class JFJochImageBufferReader : public JFJochReader {
public:
constexpr static int64_t MAX_IMAGE_LAG = 100;
constexpr static auto POLL_PERIOD = std::chrono::milliseconds(2);
explicit JFJochImageBufferReader(ImageBuffer &buffer);
void Open(const StartMessage &start);
// No image comes after this: the collection is over, or abandoned.
void Ended();
[[nodiscard]] uint64_t GetNumberOfImages() const override;
void Close() override;
bool ReadRawImage(int64_t image_number, JFJochReaderRawImage &image) override;
std::vector<SpotToSave> ReadSpots(int64_t image) const override { return {}; }
private:
bool LoadImage_i(std::shared_ptr<JFJochReaderDataset> &dataset, DataMessage &message,
std::vector<uint8_t> &buffer, int64_t image_number, bool update_dataset) override;
// The image's CBOR message, as the receiver put it in the buffer; false when it never came.
bool WaitForMessage(int64_t image_number, std::vector<uint8_t> &cbor);
// Looks at the buffer (GetStatus) and notes the images it holds in present_; under m_, released while
// the buffer is asked.
void Poll(std::unique_lock<std::mutex> &ul);
ImageBuffer &buffer_;
uint64_t number_of_images_ = 0;
std::atomic<bool> ended_ = false;
std::mutex m_;
std::condition_variable cv_;
bool polling_ = false;
std::chrono::steady_clock::time_point next_poll_;
std::vector<bool> present_;
int64_t max_present_ = -1;
};