// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include "JFJochReceiver.h" #include "../common/DiffractionExperiment.h" #include "../common/PixelMask.h" #include "../common/ImageBuffer.h" #include "../common/Logger.h" #include "../image_pusher/ImagePusher.h" #include "../preview/PreviewImage.h" #include "../preview/ZMQPreviewSocket.h" #include "../preview/ZMQMetadataSocket.h" #include "LossyFilter.h" #include "../common/MovingAverage.h" #include "JFJochReceiverCurrentStatus.h" #include "../common/JFJochReceiverPlots.h" #include "JFJochReceiverOutput.h" #include "../image_puller/ZMQImagePuller.h" #include "../image_analysis/MXAnalysisWithoutFPGA.h" #include "../image_analysis/dark_mask_analysis/DarkMaskAnalysis.h" class JFJochReceiverLite : public JFJochReceiver { // Overriding Cancel(bool) below would otherwise hide the Cancel(const JFJochException &) // the analysis threads call. using JFJochReceiver::Cancel; ImagePuller &image_puller; std::atomic end_message_received{false}; // Set when the caller reports the run is over - JFJochServices::Stop cancels the receiver // silently once the detector reads back idle. Only consulted while waiting for the start // message; a silent cancel must not interrupt images that are still being processed. std::atomic detector_finished{false}; // How long a start message may still be in flight after the detector reported it had finished. // The detector can also read back as idle for a moment just after it was armed, so a run is not // abandoned the instant the silent cancel arrives. constexpr static auto StartMessageGrace = std::chrono::seconds(5); const int64_t data_analysis_nthreads; std::vector> data_analysis_futures; std::future measurement; std::latch measurement_started; std::latch data_analysis_started; DarkMaskAnalysis dark_mask_analysis; void MaskThread(uint32_t id); void MeasurementThread(); void DataAnalysisThread(uint32_t id); public: // Shared with JFJochReceiverRugnux, which forwards a collection the same way. static bool SerializeImageOrDrop(CBORStream2Serializer &serializer, DataMessage &msg, ZeroCopyReturnValue &loc, size_t slot_size, Logger &logger); // Takes what the detector's start message decides into the experiment. static void ApplyStartMessage(DiffractionExperiment &experiment, const StartMessage &message); static int64_t NumberOfDataAnalysisThreads(int64_t requested_thread_number, const DiffractionExperiment& experiment); JFJochReceiverLite(const DiffractionExperiment& experiment, const PixelMask &pixel_mask, ImagePuller &image_puller, ImagePusher &image_pusher, Logger &logger, int64_t forward_and_sum_nthreads, const SpotFindingSettings &spot_finding_settings, JFJochReceiverCurrentStatus ¤t_status, JFJochReceiverPlots &plots, ImageBuffer &image_buffer, ZMQPreviewSocket *zmq_preview_socket = nullptr, ZMQMetadataSocket *zmq_metadata_socket = nullptr, IndexerThreadPool *indexing_thread_pool = nullptr); ~JFJochReceiverLite() override; void StopReceiver() override; void Cancel(bool silent) override; float GetEfficiency() const override; float GetProgress() const override; void SetSpotFindingSettings(const SpotFindingSettings &spot_finding_settings) override; JFJochReceiverOutput GetFinalStatistics() const override; };