diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index e69cb093f..88800a486 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -3,6 +3,7 @@ ADD_LIBRARY(JFJochReceiver STATIC JFJochReceiverService.cpp JFJochReceiverService.h JFJochReceiverTest.cpp JFJochReceiverTest.h JFJochReceiverFPGA.cpp JFJochReceiverFPGA.h + JFJochReceiverPedestal.cpp JFJochReceiverPedestal.h ImageMetadata.cpp ImageMetadata.h LossyFilter.cpp diff --git a/receiver/JFJochReceiverFPGA.cpp b/receiver/JFJochReceiverFPGA.cpp index d22f64de4..9d6d1c4a6 100644 --- a/receiver/JFJochReceiverFPGA.cpp +++ b/receiver/JFJochReceiverFPGA.cpp @@ -36,7 +36,6 @@ JFJochReceiverFPGA::JFJochReceiverFPGA(const DiffractionExperiment &in_experimen ndatastreams(experiment.GetDataStreamsNum()), frame_transformation_nthreads( in_forward_and_sum_nthreads), - pedestal_nthreads((experiment.GetStorageCellNumber() > 2) ? 1 : 4), summation_nthreads(2), frame_transformation_ready((experiment.GetImageNum() > 0) ? frame_transformation_nthreads : 0), data_acquisition_ready(ndatastreams) { @@ -81,43 +80,7 @@ JFJochReceiverFPGA::JFJochReceiverFPGA(const DiffractionExperiment &in_experimen logger.Debug("Data acquisition devices ready"); - if ((experiment.GetDetectorMode() == DetectorMode::PedestalG0) - || (experiment.GetDetectorMode() == DetectorMode::PedestalG1) - || (experiment.GetDetectorMode() == DetectorMode::PedestalG2)) { - if (experiment.GetImageNum() > 0) { - throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, - "Saving and calculating pedestal is not supported for the time being"); - } - - switch (experiment.GetDetectorMode()) { - case DetectorMode::PedestalG1: - only_2nd_sc_pedestal = !experiment.IsFixedGainG1() && (experiment.GetStorageCellNumber() == 2); - break; - case DetectorMode::PedestalG2: - only_2nd_sc_pedestal = (experiment.GetStorageCellNumber() == 2); - break; - default: - only_2nd_sc_pedestal = false; - break; - } - - int64_t pedestal_count = (only_2nd_sc_pedestal) - ? experiment.GetModulesNum() - : experiment.GetModulesNum() * experiment.GetStorageCellNumber(); - for (int i = 0; i < pedestal_count; i++) - pedestal.emplace_back(std::make_unique(experiment)); - - for (int s = 0; s < experiment.GetStorageCellNumber(); s++) { - bool ignore = only_2nd_sc_pedestal && (s == 0); - for (int d = 0; d < ndatastreams; d++) - for (int m = 0; m < experiment.GetModulesNum(d); m++) - for (int n = 0; n < pedestal_nthreads; n++) - frame_transformation_futures.emplace_back(std::async(std::launch::async, - &JFJochReceiverFPGA::MeasurePedestalThread, - this, d, m, s, n, ignore)); - } - logger.Debug("Pedestal threads ready ({} threads/module*SC)", pedestal_nthreads); - } else if (experiment.GetImageNum() > 0) { + if (experiment.GetImageNum() > 0) { SendStartMessage(); SendCalibration(); @@ -209,44 +172,6 @@ void JFJochReceiverFPGA::AcquireThread(uint16_t data_stream) { } -void JFJochReceiverFPGA::MeasurePedestalThread(uint16_t data_stream, uint16_t module_number, uint16_t storage_cell, - uint32_t threadid, bool ignore) { - JFPedestalCalc pedestal_calc(experiment); - - uint64_t starting_frame = storage_cell + threadid * experiment.GetStorageCellNumber(); - uint64_t frame_stride = experiment.GetStorageCellNumber() * pedestal_nthreads; - uint32_t storage_cell_header = UINT32_MAX; - - try { - for (size_t frame = starting_frame; frame < experiment.GetFrameNum(); frame += frame_stride) { - // Frame will be processed only if one already collects frame+2 - acquisition_device[data_stream].Counters().WaitForFrame(frame + 2, module_number); - if (acquisition_device[data_stream].Counters().IsFullModuleCollected(frame, module_number) && !ignore) { - auto output = acquisition_device[data_stream].GetDeviceOutput(frame, module_number); - // Partial packets will bring more problems, than benefit - pedestal_calc.AnalyzeImage((uint16_t *) output->pixels); - storage_cell_header = (output->module_statistics.debug >> 8) & 0xF; - } - acquisition_device[data_stream].FrameBufferRelease(frame, module_number); - - UpdateMaxDelay(acquisition_device[data_stream].Counters().CalculateDelay(frame, module_number)); - current_status.SetProgress(GetProgress()); - current_status.SetStatus(GetStatus()); - } - - uint64_t offset = experiment.GetFirstModuleOfDataStream(data_stream) + module_number; - if (!only_2nd_sc_pedestal) - offset += experiment.GetModulesNum() * storage_cell; - - if (!ignore) - *pedestal[offset] += pedestal_calc; - } catch (const JFJochException &e) { - Cancel(e); - } - logger.Debug("Pedestal calculation thread for data stream {} module {} storage cell {} -> header {} done", - data_stream, module_number, storage_cell, storage_cell_header); -} - int64_t JFJochReceiverFPGA::SummationThread(uint16_t data_stream, int64_t image_number, uint16_t module_number, @@ -668,29 +593,10 @@ JFJochReceiverOutput JFJochReceiverFPGA::GetFinalStatistics() const { ret.received_packets.push_back(acquisition_device[d].Counters().GetTotalPackets(m)); } } - RetrievePedestal(ret.pedestal_result); return ret; } -void JFJochReceiverFPGA::RetrievePedestal(std::vector &output) const { - time_t curr_time = std::chrono::system_clock::to_time_t(start_time); - for (const auto &pc: pedestal) { - JFModulePedestal mp; - if (experiment.GetDetectorMode() == DetectorMode::PedestalG0) - pc->Export(mp, PEDESTAL_G0_WRONG_GAIN_ALLOWED_COUNT); - else - pc->Export(mp); - mp.SetCollectionTime(curr_time); - output.emplace_back(std::move(mp)); - } -} - void JFJochReceiverFPGA::LoadCalibrationToFPGA(uint16_t data_stream) { - if (experiment.IsPedestalRun()) { - acquisition_device[data_stream].InitializeEmptyPixelMask(experiment); - return; // No calibration loaded for pedestal - } - if (calibration != nullptr) acquisition_device[data_stream].InitializeCalibration(experiment, *calibration); diff --git a/receiver/JFJochReceiverFPGA.h b/receiver/JFJochReceiverFPGA.h index d4bcdf3d0..87ba1cd95 100644 --- a/receiver/JFJochReceiverFPGA.h +++ b/receiver/JFJochReceiverFPGA.h @@ -32,7 +32,6 @@ #include "../preview/PreviewImage.h" #include "LossyFilter.h" #include "JFJochReceiverCurrentStatus.h" -#include "../jungfrau/JFPedestalCalc.h" #include "../preview/ZMQPreviewSocket.h" #include "../preview/ZMQMetadataSocket.h" #include "ImageMetadata.h" @@ -44,8 +43,6 @@ class JFJochReceiverFPGA : public JFJochReceiver { const JFCalibration *calibration; - std::vector> pedestal; - std::vector roi_map; std::vector> frame_transformation_futures; @@ -59,11 +56,9 @@ class JFJochReceiverFPGA : public JFJochReceiver { uint16_t ndatastreams{0}; const int64_t frame_transformation_nthreads; - const int64_t pedestal_nthreads; const int64_t summation_nthreads; int64_t expected_packets_per_image; - bool only_2nd_sc_pedestal = false; // special mode used for pedestal G1/G2 with storage cells std::latch frame_transformation_ready; std::latch data_acquisition_ready; @@ -72,11 +67,6 @@ class JFJochReceiverFPGA : public JFJochReceiver { void LoadCalibrationToFPGA(uint16_t data_stream); void FrameTransformationThread(uint32_t threadid); - void MeasurePedestalThread(uint16_t data_stream, - uint16_t module_number, - uint16_t storage_cell, - uint32_t threadid, - bool ignore); int64_t SummationThread(uint16_t data_stream, int64_t image_number, @@ -88,7 +78,6 @@ class JFJochReceiverFPGA : public JFJochReceiver { void SendCalibration(); void SendPedestal(const std::string &prefix, const std::vector &v, int gain, int sc); - void RetrievePedestal(std::vector &output) const; public: JFJochReceiverFPGA(const DiffractionExperiment& experiment, const PixelMask &pixel_mask, diff --git a/receiver/JFJochReceiverPedestal.cpp b/receiver/JFJochReceiverPedestal.cpp new file mode 100644 index 000000000..580461833 --- /dev/null +++ b/receiver/JFJochReceiverPedestal.cpp @@ -0,0 +1,271 @@ +// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-only + +#include "JFJochReceiverPedestal.h" + +JFJochReceiverPedestal::JFJochReceiverPedestal(const DiffractionExperiment &in_experiment, + const PixelMask &in_pixel_mask, + AcquisitionDeviceGroup &in_aq_device, + ImagePusher &in_image_sender, + Logger &in_logger, + const SpotFindingSettings &in_spot_finding_settings, + JFJochReceiverCurrentStatus &in_current_status, + JFJochReceiverPlots &in_plots, + ImageBuffer &in_send_buf_ctrl, + ZMQPreviewSocket *in_zmq_preview_socket, + ZMQMetadataSocket *in_zmq_metadata_socket, + IndexerThreadPool *indexing_thread_pool) + : JFJochReceiver(in_experiment, + in_send_buf_ctrl, + in_image_sender, + in_current_status, + in_plots, + in_spot_finding_settings, + in_logger, + in_pixel_mask, + in_zmq_preview_socket, + in_zmq_metadata_socket, + indexing_thread_pool), + acquisition_device(in_aq_device), + ndatastreams(experiment.GetDataStreamsNum()), + pedestal_nthreads((experiment.GetStorageCellNumber() > 2) ? 1 : 4), + data_acquisition_ready(ndatastreams) { + // The same limit as for an image run, so a configuration is refused the same way in both. + const auto &azint_settings = experiment.GetAzimuthalIntegrationSettings(); + if (!azint_settings.IsForceCPUinFPGAWorkflow() && azint_settings.GetBinCount() > FPGA_INTEGRATION_BIN_COUNT) + throw JFJochException(JFJochExceptionCategory::InputParameterAboveMax, + fmt::format("Azimuthal integration bin count ({}) exceeds the FPGA limit ({}). " + "Enable ForceCPUinFPGAWorkflow to compute it on the CPU.", + azint_settings.GetBinCount(), FPGA_INTEGRATION_BIN_COUNT)); + + image_buffer.StartMeasurement(experiment); + + for (int m = 0; m < experiment.GetModulesNum(); m++) + adu_histogram_module.emplace_back(std::make_unique()); + + if (acquisition_device.size() < ndatastreams) + throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, + "Number of acquisition devices has to match data streams"); + + expected_packets_per_image = 0; + for (int d = 0; d < ndatastreams; d++) { + acquisition_device[d].PrepareAction(experiment); + acquisition_device[d].SetSpotFinderParameters(spot_finding_settings); + + expected_packets_per_image += acquisition_device[d].Counters().GetExpectedPacketsPerImage(); + + logger.Debug("Acquisition device {} prepared", d); + } + + logger.Debug("Data acquisition devices ready"); + + switch (experiment.GetDetectorMode()) { + case DetectorMode::PedestalG1: + only_2nd_sc_pedestal = !experiment.IsFixedGainG1() && (experiment.GetStorageCellNumber() == 2); + break; + case DetectorMode::PedestalG2: + only_2nd_sc_pedestal = (experiment.GetStorageCellNumber() == 2); + break; + default: + only_2nd_sc_pedestal = false; + break; + } + + int64_t pedestal_count = (only_2nd_sc_pedestal) + ? experiment.GetModulesNum() + : experiment.GetModulesNum() * experiment.GetStorageCellNumber(); + for (int i = 0; i < pedestal_count; i++) + pedestal.emplace_back(std::make_unique(experiment)); + + for (int s = 0; s < experiment.GetStorageCellNumber(); s++) { + bool ignore = only_2nd_sc_pedestal && (s == 0); + for (int d = 0; d < ndatastreams; d++) + for (int m = 0; m < experiment.GetModulesNum(d); m++) + for (int n = 0; n < pedestal_nthreads; n++) + pedestal_futures.emplace_back(std::async(std::launch::async, + &JFJochReceiverPedestal::MeasurePedestalThread, + this, d, m, s, n, ignore)); + } + logger.Debug("Pedestal threads ready ({} threads/module*SC)", pedestal_nthreads); + + for (int d = 0; d < ndatastreams; d++) + data_acquisition_futures.emplace_back(std::async(std::launch::async, &JFJochReceiverPedestal::AcquireThread, + this, d)); + + data_acquisition_ready.wait(); + start_time = std::chrono::system_clock::now(); + measurement = std::async(std::launch::async, &JFJochReceiverPedestal::FinalizeMeasurement, this); + logger.Info("Receiving data started"); +} + +void JFJochReceiverPedestal::AcquireThread(uint16_t data_stream) { + try { + acquisition_device[data_stream].InitializeEmptyPixelMask(experiment); + logger.Debug("Device thread {} start action", data_stream); + acquisition_device[data_stream].StartAction(experiment); + } catch (const JFJochException &e) { + Cancel(e); + data_acquisition_ready.count_down(); + logger.ErrorException(e); + logger.Warning("Device thread {} done due to an error", data_stream); + return; + } + + data_acquisition_ready.count_down(); + + try { + logger.Debug("Device thread {} wait for action complete", data_stream); + acquisition_device[data_stream].WaitForActionComplete(); + } catch (const JFJochException &e) { + logger.ErrorException(e); + Cancel(e); + logger.ErrorException(e); + logger.Warning("Device thread {} done due to an error", data_stream); + return; + } + logger.Debug("Device thread {} done", data_stream); +} + +void JFJochReceiverPedestal::MeasurePedestalThread(uint16_t data_stream, uint16_t module_number, uint16_t storage_cell, + uint32_t threadid, bool ignore) { + JFPedestalCalc pedestal_calc(experiment); + + uint64_t starting_frame = storage_cell + threadid * experiment.GetStorageCellNumber(); + uint64_t frame_stride = experiment.GetStorageCellNumber() * pedestal_nthreads; + uint32_t storage_cell_header = UINT32_MAX; + + try { + for (size_t frame = starting_frame; frame < experiment.GetFrameNum(); frame += frame_stride) { + // Frame will be processed only if one already collects frame+2 + acquisition_device[data_stream].Counters().WaitForFrame(frame + 2, module_number); + if (acquisition_device[data_stream].Counters().IsFullModuleCollected(frame, module_number) && !ignore) { + auto output = acquisition_device[data_stream].GetDeviceOutput(frame, module_number); + // Partial packets will bring more problems, than benefit + pedestal_calc.AnalyzeImage((uint16_t *) output->pixels); + storage_cell_header = (output->module_statistics.debug >> 8) & 0xF; + } + acquisition_device[data_stream].FrameBufferRelease(frame, module_number); + + UpdateMaxDelay(acquisition_device[data_stream].Counters().CalculateDelay(frame, module_number)); + current_status.SetProgress(GetProgress()); + current_status.SetStatus(GetStatus()); + } + + uint64_t offset = experiment.GetFirstModuleOfDataStream(data_stream) + module_number; + if (!only_2nd_sc_pedestal) + offset += experiment.GetModulesNum() * storage_cell; + + if (!ignore) + *pedestal[offset] += pedestal_calc; + } catch (const JFJochException &e) { + Cancel(e); + } + logger.Debug("Pedestal calculation thread for data stream {} module {} storage cell {} -> header {} done", + data_stream, module_number, storage_cell, storage_cell_header); +} + +float JFJochReceiverPedestal::GetEfficiency() const { + uint64_t expected_packets = expected_packets_per_image * experiment.GetFrameNum(); + uint64_t received_packets = 0; + + for (int d = 0; d < ndatastreams; d++) { + received_packets += acquisition_device[d].Counters().GetTotalPackets(); + } + + if ((expected_packets == received_packets) || (expected_packets == 0)) + return 1.0; + return received_packets / static_cast(expected_packets); +} + +void JFJochReceiverPedestal::Cancel(bool silent) { + JFJochReceiver::Cancel(silent); + + for (int d = 0; d < ndatastreams; d++) + acquisition_device[d].Cancel(); +} + +void JFJochReceiverPedestal::Cancel(const JFJochException &e) { + JFJochReceiver::Cancel(e); + + for (int d = 0; d < ndatastreams; d++) + acquisition_device[d].Cancel(); +} + +float JFJochReceiverPedestal::GetProgress() const { + int64_t frames = experiment.GetFrameNum(); + if ((frames == 0) || (acquisition_device[0].Counters().IsAcquisitionFinished())) + return 1.0; + + return static_cast(acquisition_device[0].Counters().GetSlowestFrameNumber()) / static_cast(frames); +} + +void JFJochReceiverPedestal::FinalizeMeasurement() { + for (auto &future: pedestal_futures) + future.get(); + + logger.Debug("All processing threads done"); + + current_status.SetProgress(1.0); + current_status.SetStatus(GetStatus()); + + SendEndMessage(); + + end_time = std::chrono::system_clock::now(); + + for (auto &future: data_acquisition_futures) + future.get(); + + logger.Debug("Devices stopped"); + logger.Info("Receiving data done"); + + current_status.SetProgress({}); + current_status.SetStatus(GetStatus()); +} + +void JFJochReceiverPedestal::SetSpotFindingSettings(const SpotFindingSettings &in_spot_finding_settings) { + std::unique_lock ul(spot_finding_settings_mutex); + DiffractionExperiment::CheckDataProcessingSettings(in_spot_finding_settings); + spot_finding_settings = in_spot_finding_settings; + for (int i = 0; i < ndatastreams; i++) + acquisition_device[i].SetSpotFinderParameters(spot_finding_settings); +} + +void JFJochReceiverPedestal::StopReceiver() { + if (measurement.valid()) { + measurement.get(); + logger.Debug("Receiver stopped"); + } +} + +JFJochReceiverPedestal::~JFJochReceiverPedestal() { + try { + if (measurement.valid()) + measurement.get(); + } catch (const std::exception &e) { + logger.Error("ReceiverPedestal teardown failed: {}", e.what()); + } catch (...) { + logger.Error("ReceiverPedestal teardown failed with unknown exception"); + } +} + +JFJochReceiverOutput JFJochReceiverPedestal::GetFinalStatistics() const { + JFJochReceiverOutput ret = JFJochReceiver::GetFinalStatistics(); + for (int d = 0; d < ndatastreams; d++) { + for (int m = 0; m < acquisition_device[d].Counters().GetModuleNumber(); m++) { + ret.expected_packets.push_back(acquisition_device[d].Counters().GetTotalExpectedPacketsPerModule()); + ret.received_packets.push_back(acquisition_device[d].Counters().GetTotalPackets(m)); + } + } + + time_t curr_time = std::chrono::system_clock::to_time_t(start_time); + for (const auto &pc: pedestal) { + JFModulePedestal mp; + if (experiment.GetDetectorMode() == DetectorMode::PedestalG0) + pc->Export(mp, PEDESTAL_G0_WRONG_GAIN_ALLOWED_COUNT); + else + pc->Export(mp); + mp.SetCollectionTime(curr_time); + ret.pedestal_result.emplace_back(std::move(mp)); + } + return ret; +} diff --git a/receiver/JFJochReceiverPedestal.h b/receiver/JFJochReceiverPedestal.h new file mode 100644 index 000000000..a56abad44 --- /dev/null +++ b/receiver/JFJochReceiverPedestal.h @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-only + +#pragma once + +#include +#include +#include +#include + +#include "JFJochReceiver.h" +#include "../acquisition_device/AcquisitionDeviceGroup.h" +#include "../jungfrau/JFPedestalCalc.h" + +// A pedestal run: raw frames from the acquisition devices go directly into JFPedestalCalc. It forwards no +// images, so it uses no image buffer slots and sends nothing to the writer. +class JFJochReceiverPedestal : public JFJochReceiver { + std::vector> pedestal; + + std::vector> pedestal_futures; + std::vector> data_acquisition_futures; + + std::future measurement; + + AcquisitionDeviceGroup &acquisition_device; + uint16_t ndatastreams{0}; + + const int64_t pedestal_nthreads; + + int64_t expected_packets_per_image; + bool only_2nd_sc_pedestal = false; // special mode used for pedestal G1/G2 with storage cells + + std::latch data_acquisition_ready; + + void AcquireThread(uint16_t data_stream); + void MeasurePedestalThread(uint16_t data_stream, + uint16_t module_number, + uint16_t storage_cell, + uint32_t threadid, + bool ignore); + void Cancel(const JFJochException &e) override; + void FinalizeMeasurement(); +public: + JFJochReceiverPedestal(const DiffractionExperiment &experiment, + const PixelMask &pixel_mask, + AcquisitionDeviceGroup &acquisition_devices, + ImagePusher &image_pusher, + Logger &logger, + const SpotFindingSettings &spot_finding_settings, + JFJochReceiverCurrentStatus ¤t_status, + JFJochReceiverPlots &plots, + ImageBuffer &image_buffer, + ZMQPreviewSocket *zmq_preview_socket, + ZMQMetadataSocket *zmq_metadata_socket, + IndexerThreadPool *indexing_thread_pool); + ~JFJochReceiverPedestal() override; + JFJochReceiverPedestal(const JFJochReceiverPedestal &other) = delete; + JFJochReceiverPedestal &operator=(const JFJochReceiverPedestal &other) = delete; + + void StopReceiver() override; + + float GetEfficiency() const override; + void Cancel(bool silent) override; + float GetProgress() const override; + + void SetSpotFindingSettings(const SpotFindingSettings &spot_finding_settings) override; + + JFJochReceiverOutput GetFinalStatistics() const override; +}; diff --git a/receiver/JFJochReceiverService.cpp b/receiver/JFJochReceiverService.cpp index a37c73ca1..bac0c12dd 100644 --- a/receiver/JFJochReceiverService.cpp +++ b/receiver/JFJochReceiverService.cpp @@ -6,6 +6,7 @@ #include "../common/ThreadAffinity.h" #include "JFJochReceiverFPGA.h" #include "JFJochReceiverLite.h" +#include "JFJochReceiverPedestal.h" #include "../preview/JFJochJPEG.h" #include "../preview/JFJochTIFF.h" @@ -131,6 +132,19 @@ void JFJochReceiverService::Start(const DiffractionExperiment &experiment, switch (detector_type) { case DetectorType::EIGER: case DetectorType::JUNGFRAU: + if (experiment.IsPedestalRun()) { + receiver = std::make_unique(experiment, pixel_mask, + aq_devices, image_pusher, + logger, + spot_finding_settings, + receiver_status, + plots, + image_buffer, + zmq_preview_socket.get(), + zmq_metadata_socket.get(), + indexer_thread_pool.get()); + break; + } receiver = std::make_unique(experiment, pixel_mask, calibration, aq_devices, image_pusher, diff --git a/tests/JFJochReceiverIntegrationTest.cpp b/tests/JFJochReceiverIntegrationTest.cpp index 3b669762a..b48974ee6 100644 --- a/tests/JFJochReceiverIntegrationTest.cpp +++ b/tests/JFJochReceiverIntegrationTest.cpp @@ -965,6 +965,41 @@ TEST_CASE("JFJochReceiverTest_Cancel", "[JFJochReceiver]") { REQUIRE(receiver_out.status.cancelled); } +TEST_CASE("JFJochReceiverTest_Pedestal_Cancel", "[JFJochReceiver]") { + Logger logger("JFJochReceiverTest_Pedestal_Cancel"); + + DiffractionExperiment x(DetJF(1)); + x.Mode(DetectorMode::PedestalG0); + x.PedestalG0Frames(100).NumTriggers(1).UseInternalPacketGenerator(false).IncidentEnergy_keV(12.4); + + std::vector frame_in(RAW_MODULE_SIZE, 1000); + + // Only the first frames of the 100 arrive, and no final packet: the run waits until it is cancelled. + AcquisitionDeviceGroup aq_devices; + auto test = std::make_unique(0, 64); + test->CreateJFPackets(x, 1, 10, 0, frame_in.data()); + aq_devices.Add(std::move(test)); + + PixelMask pixel_mask(x); + TestImagePusher pusher(0); + JFJochReceiverService service(aq_devices, logger, pusher); + service.NumThreads(4); + + service.Start(x, pixel_mask, nullptr); + std::this_thread::sleep_for(std::chrono::seconds(5)); + service.Cancel(false); + + auto output = service.Stop(); + REQUIRE(output.status.cancelled); + REQUIRE(output.efficiency < 1.0); + REQUIRE(output.received_packets.at(0) > 0); + REQUIRE(output.received_packets.at(0) < output.expected_packets.at(0)); + // Too few frames for a pedestal, so every pixel is reported as wrong + REQUIRE(output.pedestal_result.size() == 1); + REQUIRE(output.pedestal_result[0].CountMaskedPixels() == RAW_MODULE_SIZE); + REQUIRE(pusher.GetCounter() == 0); +} + TEST_CASE("JFJochReceiverTest_EIGER", "[JFJochReceiver]") { Logger logger("JFJochReceiverTest_EIGER");