So that rugnux can process a collection while it is written, the broker reports each data file once
a writer has closed it and renamed it into place:
- Writer: FileWriter takes a callback, called for every closed data file. StreamWriter uses it on TCP
to send an acknowledgement with ack_for = FILE_CLOSED (new TCPFrameType 10): file number and the
images the file holds. TCP protocol version 5. Files closed at END are reported before the END
acknowledgement.
- LiveCollection (image_pusher): the start message the writer of the master file received, the
closed files, the end. Fed by the TCP pusher (FILE_CLOSED acknowledgements; end once every writer
acknowledged END) and by the in-process HDF5 pusher (the FileWriter callback). The ZeroMQ pusher
has no back channel and offers none.
- Two routes, protected by the dataset's bearer tokens like the other dataset routes:
- GET /live/start.cbor: that start message;
- GET /live/events: server-sent events (collection, file, end, superseded) with the history first
and a keepalive every 10 s. One follower at a time; a second gets 409.
Documented in jfjoch_api.yaml; they add no schema, so the generated C++ model is unchanged.
- The HTTP server's thread pool is set explicitly (16, up to 64): an event stream holds a thread for
the whole collection.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SVmAWnzCmRKAXVUCdc4iNi
96 lines
4.1 KiB
C++
96 lines
4.1 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#pragma once
|
|
|
|
#include <mutex>
|
|
#include <memory>
|
|
|
|
#include "JFJochReceiver.h"
|
|
#include "../acquisition_device/AcquisitionDeviceGroup.h"
|
|
|
|
#include "../preview/ZMQMetadataSocket.h"
|
|
#include "../preview/ZMQPreviewSocket.h"
|
|
|
|
class JFJochReceiverService {
|
|
std::unique_ptr<JFJochReceiver> receiver;
|
|
AcquisitionDeviceGroup &aq_devices;
|
|
Logger &logger;
|
|
ImageBuffer image_buffer;
|
|
ImagePusher &image_pusher;
|
|
std::shared_ptr<ImagePuller> image_puller;
|
|
int64_t nthreads = 8;
|
|
|
|
enum class ReceiverState {Idle, Running};
|
|
ReceiverState state = ReceiverState::Idle;
|
|
mutable std::mutex state_mutex;
|
|
std::condition_variable measurement_done;
|
|
std::future<void> measurement;
|
|
void FinalizeMeasurement();
|
|
void FinalizeMeasurementChangeState();
|
|
SpotFindingSettings spot_finding_settings;
|
|
|
|
PreviewImage preview_image;
|
|
std::unique_ptr<ZMQPreviewSocket> zmq_preview_socket;
|
|
std::unique_ptr<ZMQMetadataSocket> zmq_metadata_socket;
|
|
std::unique_ptr<IndexerThreadPool> indexer_thread_pool;
|
|
|
|
JFJochReceiverCurrentStatus receiver_status;
|
|
JFJochReceiverPlots plots;
|
|
public:
|
|
JFJochReceiverService(AcquisitionDeviceGroup &aq_devices,
|
|
Logger &logger,
|
|
ImagePusher &pusher,
|
|
size_t send_buffer_size_MiB = 512);
|
|
JFJochReceiverService& NumThreads(int64_t input);
|
|
JFJochReceiverService& PreviewSocket(const std::string &addr, const std::optional<int32_t> &watermark = {});
|
|
JFJochReceiverService& MetadataSocket(const std::string &addr);
|
|
|
|
JFJochReceiverService& PreviewSocketSettings(const ZMQPreviewSettings &input);
|
|
JFJochReceiverService& MetadataSocketSettings(const ZMQMetadataSettings &input);
|
|
JFJochReceiverService& Indexing(const IndexingSettings& input);
|
|
|
|
ZMQPreviewSettings GetPreviewSocketSettings() const;
|
|
ZMQMetadataSettings GetMetadataSocketSettings() const;
|
|
|
|
std::string GetPreviewSocketAddress() const;
|
|
std::string GetMetadataSocketAddress() const;
|
|
|
|
void LoadInternalGeneratorImage(const DiffractionExperiment& experiment,
|
|
const std::vector<uint16_t> &raw_expected_image,
|
|
uint64_t image_number);
|
|
// Ask the writer whether this run's output could be written, before anything is started.
|
|
// Throws if it could not.
|
|
void Preflight(const DiffractionExperiment &experiment);
|
|
void Start(const DiffractionExperiment &experiment,
|
|
const PixelMask &pixel_mask,
|
|
const JFCalibration *calibration,
|
|
std::shared_ptr<ImagePuller> puller = {});
|
|
void Cancel(bool silent);
|
|
JFJochReceiverOutput Stop();
|
|
void SetSpotFindingSettings(const SpotFindingSettings& settings);
|
|
MultiLinePlot GetDataProcessingPlot(const PlotRequest& request);
|
|
void GetPlotRaw(std::vector<float> &v, PlotType type, const std::string &roi);
|
|
|
|
std::optional<JFJochReceiverStatus> GetStatus();
|
|
std::vector<AcquisitionDeviceNetConfig> GetNetworkConfig();
|
|
std::vector<DeviceStatus> GetDeviceStatus() const;
|
|
std::optional<float> GetProgress() const;
|
|
|
|
void GetXFELEventCode(std::vector<uint64_t> &v) const;
|
|
void GetXFELPulseID(std::vector<uint64_t> &v) const;
|
|
|
|
void GetStartMessageFromBuffer(std::vector<uint8_t> &v);
|
|
bool GetImageFromBuffer(std::vector<uint8_t> &v, int64_t image_number = ImageBuffer::MaxImage);
|
|
std::string GetTIFFFromBuffer(int64_t image_number = ImageBuffer::MaxImage);
|
|
std::string GetJPEGFromBuffer(const PreviewImageSettings &settings, int64_t image_number = ImageBuffer::MaxImage);
|
|
ImageBufferStatus GetImageBufferStatus() const;
|
|
void ClearImageBuffer();
|
|
// Drop everything the previous run left readable - its status, plots and buffered images - so
|
|
// nothing of it is served under the next run's tokens. Idle only.
|
|
void ClearResults();
|
|
|
|
ImagePusherStatus GetImagePusherStatus() const;
|
|
LiveCollection *GetLiveCollection() { return image_pusher.GetLiveCollection(); }
|
|
};
|