Files
Jungfraujoch/image_pusher/HDF5FilePusher.h
T
leonarski_f 086129f767 receiver: count only images the pusher accepted
images_sent was incremented right after image_pusher.SendImage(*loc), but the
ZeroCopyReturnValue overload was void and, for the TCP pusher, asynchronous: it
silently drops the image (releases the slot and returns) when there is no live
connection or the 2 s enqueue deadline expires. So images_sent over-counted on a
broken/slow writer connection and disagreed with the ACK-based GetImagesWritten().

Make SendImage(ZeroCopyReturnValue&) return whether the image was accepted
(enqueued/handed off) and only increment images_sent on success. The slot is
still released on the drop path. The authoritative delivered count remains
GetImagesWritten() (total_data_acked_ok for TCP). File/ZMQ pushers return true on
accept, preserving their previous always-counted behaviour.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 14:24:48 +02:00

46 lines
1.7 KiB
C++

// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <future>
#include "ImagePusher.h"
#include "../writer/FileWriter.h"
#include "../common/ThreadSafeFIFO.h"
#include "../common/ZMQWrappers.h"
#include "../common/Logger.h"
class HDF5FilePusher : public ImagePusher {
std::unique_ptr<FileWriter> writer;
std::mutex m;
std::future<void> writer_future;
ThreadSafeFIFO<ImagePusherQueueElement> writer_queue;
void WriterThread();
std::atomic<uint64_t> images_written = 0;
static constexpr uint32_t default_repub_watermark = 220;
static constexpr auto RepubTimeout = std::chrono::milliseconds(100);
std::unique_ptr<ZMQSocket> repub_socket;
bool repub_active = false;
Logger logger{"HDF5FilePusher"};
public:
explicit HDF5FilePusher(const std::string &repub_address = "",
const std::optional<int32_t> &repub_watermark = {});
// Thread safety: StartDataCollection, EndDataCollection and SendCalibration must run poorly in serial context
// SendImage can be executed in parallel
void StartDataCollection(StartMessage &message) override;
bool EndDataCollection(const EndMessage &message) override;
bool SendImage(const uint8_t *image_data, size_t image_size, int64_t image_number) override;
bool SendImage(ZeroCopyReturnValue &z) override;
bool SendCalibration(const CompressedImage &message) override;
std::string PrintSetup() const override;
std::optional<uint64_t> GetImagesWritten() const override;
size_t GetConnectedWriters() const override;
ImagePusherType GetType() const override { return ImagePusherType::HDF5; }
};