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
* 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>
100 lines
3.8 KiB
C++
100 lines
3.8 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "JFJochImageBufferReader.h"
|
|
|
|
#include <algorithm>
|
|
#include <cstring>
|
|
|
|
#include "JFJochStartMessageReader.h"
|
|
#include "../common/JFJochException.h"
|
|
#include "../frame_serialize/CBORStream2Deserializer.h"
|
|
|
|
JFJochImageBufferReader::JFJochImageBufferReader(ImageBuffer &buffer) : buffer_(buffer) {}
|
|
|
|
void JFJochImageBufferReader::Open(const StartMessage &start) {
|
|
{
|
|
std::unique_lock ul(m_);
|
|
number_of_images_ = start.number_of_images;
|
|
present_.assign(number_of_images_, false);
|
|
max_present_ = -1;
|
|
ended_ = false;
|
|
}
|
|
SetStartMessage(DatasetFromStartMessage(start, default_experiment));
|
|
}
|
|
|
|
void JFJochImageBufferReader::Ended() {
|
|
{
|
|
std::unique_lock ul(m_);
|
|
ended_ = true;
|
|
}
|
|
cv_.notify_all();
|
|
}
|
|
|
|
uint64_t JFJochImageBufferReader::GetNumberOfImages() const {
|
|
return number_of_images_;
|
|
}
|
|
|
|
void JFJochImageBufferReader::Close() {
|
|
SetStartMessage({});
|
|
}
|
|
|
|
void JFJochImageBufferReader::Poll(std::unique_lock<std::mutex> &ul) {
|
|
polling_ = true;
|
|
next_poll_ = std::chrono::steady_clock::now() + POLL_PERIOD;
|
|
ul.unlock();
|
|
const std::vector<int64_t> images = buffer_.GetStatus().images_in_the_buffer;
|
|
ul.lock();
|
|
polling_ = false;
|
|
for (const int64_t i: images)
|
|
if (i >= 0 && static_cast<uint64_t>(i) < number_of_images_) {
|
|
present_[i] = true;
|
|
max_present_ = std::max(max_present_, i);
|
|
}
|
|
cv_.notify_all();
|
|
}
|
|
|
|
bool JFJochImageBufferReader::WaitForMessage(int64_t image_number, std::vector<uint8_t> &cbor) {
|
|
if (image_number < 0 || static_cast<uint64_t>(image_number) >= number_of_images_)
|
|
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Image out of bounds");
|
|
std::unique_lock ul(m_);
|
|
// Images arrive in order, give or take a few: one still missing when the buffer already holds an
|
|
// image MAX_IMAGE_LAG past it is lost, not late. After the end, one is asked for once more, as it
|
|
// may have come in just before.
|
|
while (!present_[image_number] && !ended_ && max_present_ < image_number + MAX_IMAGE_LAG) {
|
|
const auto now = std::chrono::steady_clock::now();
|
|
if (!polling_ && now >= next_poll_)
|
|
Poll(ul);
|
|
else
|
|
cv_.wait_until(ul, polling_ ? now + POLL_PERIOD : next_poll_);
|
|
}
|
|
ul.unlock();
|
|
return buffer_.GetImage(cbor, image_number);
|
|
}
|
|
|
|
bool JFJochImageBufferReader::ReadRawImage(int64_t image_number, JFJochReaderRawImage &ret) {
|
|
if (!WaitForMessage(image_number, ret.read_buffer))
|
|
return false;
|
|
const auto msg = CBORStream2Deserialize(ret.read_buffer);
|
|
if (msg->msg_type != CBORImageType::IMAGE || !msg->data_message)
|
|
return false;
|
|
// Copied out of the message: read_buffer is scratch a caller may hand to the next read.
|
|
const CompressedImage &image = msg->data_message->image;
|
|
ret.image_buffer.resize(image.GetCompressedSize());
|
|
memcpy(ret.image_buffer.data(), image.GetCompressed(), image.GetCompressedSize());
|
|
ret.image = CompressedImage(ret.image_buffer.data(), ret.image_buffer.size(), image.GetWidth(),
|
|
image.GetHeight(), image.GetMode(), image.GetCompressionAlgorithm());
|
|
return true;
|
|
}
|
|
|
|
bool JFJochImageBufferReader::LoadImage_i(std::shared_ptr<JFJochReaderDataset> &dataset, DataMessage &message,
|
|
std::vector<uint8_t> &buffer, int64_t image_number, bool) {
|
|
if (!dataset || !WaitForMessage(image_number, buffer))
|
|
return false;
|
|
const auto msg = CBORStream2Deserialize(buffer);
|
|
if (msg->msg_type != CBORImageType::IMAGE || !msg->data_message)
|
|
return false;
|
|
message = *msg->data_message;
|
|
return true;
|
|
}
|