Files
Jungfraujoch/image_puller/ImagePuller.h
T
leonarski_f afbe844b20
Build Packages / Create release (push) Successful in 17s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 4m41s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 20m49s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 13m6s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 23m44s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 7m28s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 11m50s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 14m9s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 16m25s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 15m42s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 20m50s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 20m36s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 22m18s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 23m29s
Build Packages / Generate python client (push) Successful in 30s
Build Packages / Build documentation (push) Successful in 1m10s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 21m38s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 17m8s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 23m10s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 19m16s
Build Packages / Unit tests (push) Successful in 2h8m4s
Build Packages / Validation Battery (push) Successful in 40m53s
v1.0.0-rc.178 (#88)
* Rugnux: Processes serial crystallography data from XFELs - SACLA (MPCCD), PAL-XFEL and European XFEL (CXI), LCLS (XTC) and SwissFEL Alvra (JUNGFRAU with a CrystFEL module geometry) - with several files or Jungfraujoch master files merged in one run (`rugnux *_master.h5`).
* Rugnux: Stills processing takes a known unit cell and space group as a starting point, finds the beam centre (and, with a cell, the detector distance) from the images, detects the saturation level in other facilities' files and refines the placement of individual detector panels.
* Rugnux: The stills report gives R_split and CC1/2 from frame half-sets, comparable with CrystFEL.
* jfjoch_viewer: Opens the same XFEL file formats.
* Validation: A stills battery checks Rugnux against deposited structures from SACLA, PAL-XFEL, LCLS, European XFEL and SwissFEL.
* Rugnux: More reliable convergence of rotation scaling, and live molecular replacement starts as soon as the model is uploaded.
* jfjoch_broker: Initialize clears the previous dataset's bearer tokens, image buffer and live Rugnux status, and a slow CUDA JIT cache is reported at start.

Reviewed-on: #88
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-10-21 11:20:01 +02:00

87 lines
3.3 KiB
C++

// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <atomic>
#include <chrono>
#include <string>
#include <memory>
#include "../common/ZMQWrappers.h"
#include "../frame_serialize/CBORStream2Deserializer.h"
#include "../common/ThreadSafeFIFO.h"
#include "../common/JfjochTCP.h"
#include "ReceiveRingBuffer.h"
struct PullerAckMessage {
TCPFrameType ack_for = TCPFrameType::DATA;
bool ok = true;
bool fatal = false;
uint64_t run_number = 0;
uint32_t socket_number = 0;
uint64_t image_number = 0;
uint64_t processed_images = 0;
TCPAckCode error_code = TCPAckCode::None;
std::string error_text;
};
struct RawFrame {
TcpFrameHeader header{};
bool end = false;
};
struct ImagePullerOutput {
// The message as it came off the socket, in the puller's ring buffer. It stays there for as long as
// any copy of this struct is alive - the deserialised image in cbor points into it, and republish
// sends it as is.
std::shared_ptr<ReceiveBufferRegion> raw;
std::shared_ptr<RawFrame> tcp_msg;
std::shared_ptr<CBORStream2DeserializerOutput> cbor;
// When the message came off the socket - before it was queued or deserialised, so a consumer that
// falls behind does not shift it.
std::chrono::steady_clock::time_point received{};
};
struct ImagePullerStatistics {
size_t outside_fifo_max_util = 0;
};
class ImagePuller {
protected:
ThreadSafeFIFO<ImagePullerOutput> outside_fifo; // assuming 1 file is <1000 files, this should be enough to buffer
// Every received message is held here until consumed; the queues count messages, this bounds bytes.
// Size 0 means no ring: messages are held on the heap, bounded by the queues alone, as they always
// were - the broker's own DECTRIS puller runs that way, jfjoch_writer sets a size.
ReceiveRingBuffer ring;
// Bytes republish holds right now. Republish keeps the OLDEST not yet sent images, and the ring is
// reclaimed in arrival order, so an image waiting for a slow republish consumer pins everything
// received after it - the writer would then run at the republish rate. What republish may hold is
// therefore capped at a share of the ring; an image over the cap is not republished, exactly as one
// that finds the republish queue full. Without a ring there is no cap.
std::atomic<size_t> repub_bytes{0};
bool RepubCanHold(size_t bytes) const {
return ring.GetCapacity() == 0 || repub_bytes.load() + bytes <= ring.GetCapacity() / 4;
}
public:
constexpr static size_t DefaultQueueSize = 1000;
constexpr static auto PollTimeout = std::chrono::milliseconds(100);
explicit ImagePuller(size_t fifo_size = DefaultQueueSize, size_t ring_size = 0);
virtual ~ImagePuller() = default;
[[nodiscard]] std::optional<ImagePullerOutput> PollImage(std::chrono::microseconds timeout = PollTimeout);
[[nodiscard]] size_t GetMaxFifoUtilization() const;
[[nodiscard]] size_t GetCurrentFifoUtilization() const;
[[nodiscard]] size_t GetRingBufferCapacity() const;
[[nodiscard]] size_t GetMaxRingBufferUtilization() const;
virtual bool SupportsAck() const { return false; }
virtual bool SendAck(const PullerAckMessage &) { return false; }
virtual void Disconnect() = 0;
};