Every test whose subject is not the card's pixel arithmetic now runs on the mock of the card, with what the card writes given by the test, precalculated on the CPU (tests/MockCardOutput.h): - JUNGFRAU conversion, threshold, Poisson, summation, storage cells, applied pixel mask, EIGER: the reference conversion of CheckImageOutput.h, rounded into the card's pixel format; - a signed 16-bit image passed through (the crystal tests): the image itself, INT16_MIN error and INT16_MAX saturated as the card reads them, the strong pixels from the CPU version of the card's spot finder (DetModuleSpotFinder_cpu.h); - pixel statistics and ROI sums from the same values, masked pixels left out; - pedestal runs and lost packets: the raw frames, the missing packet as UINT16_MAX. Integration bins and the ADU histogram are left at zero: no test asserts on their values. Moved: JFJochReceiverIntegrationTest.cpp (30 cases), JFJochReceiverProcessingTest.cpp (23), FPGAImagePullerTest.cpp (20), JFJochReceiverRugnuxTest.cpp (1), JFJochStateMachineTest.cpp (5), StreamWriterTest.cpp (4). JFJochReceiverTest_Raw_TwoDevices comes from MockAcquisitionDeviceTest.cpp, whose other ported receiver tests duplicated the originals now on the mock and are removed. What changes in meaning: the conversion tests check that the receiver carries the card's pixels into the image (geometry, multipixels, pixel format, compression), no longer that the card converts correctly; JFJochIntegrationTest_ZMQ_ROI checks the receiver's ROI and pixel counts against the hand sums with the card's sums calculated on the CPU. The card itself is compared with the mock in MockAcquisitionDeviceTest.cpp. The pedestal tests repeat 25-32 distinct frames instead of all distinct ones, the reference pedestal taken from the same frames. Waits sized for the HLS simulation are shortened: cancel after 1 s instead of 60 s / 5 s, the puller cancel after 2 s instead of 30 s, the dead-module puller gives up after 5 s without an image instead of 60 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK
1083 lines
39 KiB
C++
1083 lines
39 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include "../receiver/JFJochReceiverTest.h"
|
|
#include "MockCardOutput.h"
|
|
#include "../jungfrau/JFPedestalCalc.h"
|
|
#include "../image_pusher/TestImagePusher.h"
|
|
#include "../receiver/JFJochReceiverService.h"
|
|
|
|
using namespace std::literals::chrono_literals;
|
|
|
|
TEST_CASE("JFJochReceiverTest_Raw", "[JFJochReceiver]") {
|
|
DiffractionExperiment x(DetJF(4));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Raw();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(100).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::NO_COMPRESSION);
|
|
|
|
|
|
Logger logger("JFJochReceiverTest_Raw");
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
REQUIRE(output.status.compressed_ratio == 1.0);
|
|
REQUIRE(output.status.compressed_size == x.GetImageNum() * x.GetByteDepthImage() * x.GetPixelsNum());
|
|
REQUIRE(output.status.max_image_number_sent == x.GetImageNum());
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
// Two cards running at the same time - not possible with the HLS simulation
|
|
TEST_CASE("JFJochReceiverTest_Raw_TwoDevices", "[JFJochReceiver]") {
|
|
DiffractionExperiment x(DetJF(4));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Raw();
|
|
x.DataStreams(2);
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(100).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::NO_COMPRESSION);
|
|
REQUIRE(x.GetDataStreamsNum() == 2);
|
|
|
|
Logger logger("JFJochReceiverTest_Raw_TwoDevices");
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
|
|
|
|
|
REQUIRE(x.IsGeometryTransformed());
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_ForceCPUAzInt", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_ForceCPUAzInt");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(8).ImagesPerFile(10).IncidentEnergy_keV(12.4)
|
|
.JungfrauConvPhotonCnt(false).Compression(CompressionAlgorithm::NO_COMPRESSION);
|
|
|
|
// Request more azimuthal integration bins than the FPGA integration core can handle.
|
|
// This is only possible on the CPU backend - the FPGA path would throw on read-back.
|
|
AzimuthalIntegrationSettings azim;
|
|
azim.QSpacing_recipA(0.05).QRange_recipA(0.05, 6.05).AzimuthalBinCount(20)
|
|
.ForceCPUinFPGAWorkflow(true);
|
|
REQUIRE(azim.GetBinCount() > FPGA_INTEGRATION_BIN_COUNT);
|
|
x.ImportAzimuthalIntegrationSettings(azim);
|
|
|
|
std::vector<uint16_t> raw_image(RAW_MODULE_SIZE * x.GetModulesNum());
|
|
for (int i = 0; i < raw_image.size(); i++)
|
|
raw_image[i] = 1000 + i % 1000;
|
|
|
|
PixelMask mask(x);
|
|
|
|
std::vector<CardImage> images;
|
|
images.push_back(ConvertedImage(x, JFCalibration(x), mask, raw_image));
|
|
AcquisitionDeviceGroup aq_devices = MockDevices(x, images);
|
|
|
|
TestImagePusher pusher(x.GetImageNum() - 1);
|
|
JFJochReceiverService service(aq_devices, logger, pusher);
|
|
service.NumThreads(nthreads);
|
|
service.LoadInternalGeneratorImage(x, raw_image, 0);
|
|
|
|
service.Start(x, mask, nullptr);
|
|
auto output = service.Stop();
|
|
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
REQUIRE(!output.status.cancelled);
|
|
|
|
// The CPU backend produced the full-resolution profile (more bins than the FPGA supports)
|
|
auto azim_plot = service.GetDataProcessingPlot(PlotRequest{.type = PlotType::AzInt, .binning = 1});
|
|
REQUIRE(azim_plot.GetPlots().size() == 1);
|
|
REQUIRE(azim_plot.GetPlots()[0].x.size() == azim.GetBinCount());
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_AzIntBinsExceedFPGA", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_AzIntBinsExceedFPGA");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(8).IncidentEnergy_keV(12.4);
|
|
|
|
// More bins than the FPGA can integrate, and the CPU backend is not forced.
|
|
AzimuthalIntegrationSettings azim;
|
|
azim.QSpacing_recipA(0.05).QRange_recipA(0.05, 6.05).AzimuthalBinCount(20);
|
|
REQUIRE(azim.GetBinCount() > FPGA_INTEGRATION_BIN_COUNT);
|
|
REQUIRE_FALSE(azim.IsForceCPUinFPGAWorkflow());
|
|
x.ImportAzimuthalIntegrationSettings(azim);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
for (int i = 0; i < x.GetDataStreamsNum(); i++)
|
|
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
|
|
|
PixelMask mask(x);
|
|
TestImagePusher pusher(0);
|
|
JFJochReceiverService service(aq_devices, logger, pusher);
|
|
|
|
// The limit is enforced at acquisition start, before any thread is spawned
|
|
REQUIRE_THROWS_AS(service.Start(x, mask, nullptr), JFJochException);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_NoGeomTransform", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion_NoGeomTransform");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
|
.GeometryTransformation(false);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_Poisson", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion_Poisson");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(
|
|
CompressionAlgorithm::BSHUF_ZSTD);
|
|
x.LossyCompressionPoisson(1);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_Threshold", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion_Threshold");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(
|
|
CompressionAlgorithm::BSHUF_ZSTD);
|
|
x.PixelValueLowThreshold(50);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_ApplyMask", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion_ApplyMask");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
|
x.ApplyPixelMask(true).MaskChipEdges(true).MaskModuleEdges(true);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_Threshold_Summation", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion_Threshold");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(1).Summation(4).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(
|
|
CompressionAlgorithm::BSHUF_ZSTD);
|
|
x.PixelValueLowThreshold(10);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_FixedGainG1", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
|
.FixedGainG1(true);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_FixedGainG1_onlyG1", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
|
.FixedGainG1(true);
|
|
|
|
std::vector<uint16_t> input(RAW_MODULE_SIZE*2, 0x4000 + 3000);
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask, input);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, input, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_U16", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
|
.BitDepthImage(16).PixelSigned(false);
|
|
|
|
REQUIRE(!x.IsPixelSigned());
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_U8", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion_U8");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
|
.BitDepthImage(8).PixelSigned(false);
|
|
|
|
REQUIRE(!x.IsPixelSigned());
|
|
REQUIRE(x.GetByteDepthImage() == 1);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_I32", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
|
.PixelSigned(true).BitDepthImage(32);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_Summation2", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD).Summation(2);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_Summation7_CPU", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(8).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
|
.Summation(7).CPUSummation(true);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
CHECK(ret);
|
|
CHECK(output.efficiency == 1.0);
|
|
CHECK(output.status.images_sent == x.GetImageNum());
|
|
|
|
CHECK(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Conversion_StorageCell", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_Conversion_StorageCell");
|
|
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD).StorageCells(16);
|
|
|
|
REQUIRE(x.GetImageNum() == 16);
|
|
REQUIRE(x.GetStorageCellNumber() == 16);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_PedestalG1", "[JFJochReceiver]") {
|
|
|
|
const uint16_t nthreads = 4;
|
|
size_t nframes = 256;
|
|
// The card output repeats every distinct_frames frames
|
|
size_t distinct_frames = 32;
|
|
|
|
std::vector<uint16_t> pedestal_in(RAW_MODULE_SIZE * distinct_frames);
|
|
|
|
// Predictable random number generator
|
|
std::mt19937 g1(1900);
|
|
std::normal_distribution<double> distribution(14000, 100);
|
|
|
|
for (auto &i: pedestal_in) {
|
|
uint16_t number = distribution(g1);
|
|
if (number < 20) number = 20;
|
|
if (number > 16300) number = 16300;
|
|
i = 16384 | number;
|
|
}
|
|
|
|
DiffractionExperiment x(DetJF(1));
|
|
x.Mode(DetectorMode::PedestalG1).PedestalG0Frames(0)
|
|
.PedestalG1Frames(nframes).NumTriggers(1).UseInternalPacketGenerator(false)
|
|
.ImagesPerTrigger(0).IncidentEnergy_keV(12.4);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
|
auto test = std::make_unique<MockAcquisitionDevice>(i, 64);
|
|
for (int f = 0; f < distinct_frames; f++)
|
|
test->SetOutput(f, 0, *OutputWithPixels(pedestal_in.data() + f * RAW_MODULE_SIZE));
|
|
test->CreateJFPackets(x, 1, nframes, 0, nullptr);
|
|
test->CreateFinalPacket(x);
|
|
aq_devices.Add(std::move(test));
|
|
}
|
|
|
|
JFPedestalCalc pc(x);
|
|
for (int i = 0; i < nframes; i++)
|
|
pc.AnalyzeImage(pedestal_in.data() + (i % distinct_frames) * RAW_MODULE_SIZE);
|
|
|
|
Logger logger("JFJochReceiverTest_PedestalG1");
|
|
|
|
PixelMask mask(x);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
REQUIRE(output.efficiency == 1.0);
|
|
|
|
JFModulePedestal ref_pedestal;
|
|
pc.Export(ref_pedestal, 0);
|
|
JFModulePedestal out_pedestal = output.pedestal_result.at(0);
|
|
REQUIRE(abs(ref_pedestal.Mean() - out_pedestal.Mean()) < 0.65);
|
|
REQUIRE(out_pedestal.CountMaskedPixels() == 0);
|
|
REQUIRE(out_pedestal.GetFrameCount() == nframes);
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_PedestalG2_storage_cell", "[JFJochReceiver]") {
|
|
|
|
const uint16_t nthreads = 4;
|
|
size_t nframes = 150;
|
|
// The card output repeats every 2 * distinct_frames frames
|
|
size_t distinct_frames = 25;
|
|
|
|
std::vector<uint16_t> pedestal_in(RAW_MODULE_SIZE * distinct_frames), pedestal_in2(RAW_MODULE_SIZE * distinct_frames);
|
|
|
|
// Predictable random number generator
|
|
std::mt19937 g2(1900);
|
|
std::normal_distribution<double> distribution1(13000, 100);
|
|
std::normal_distribution<double> distribution2(12000, 100);
|
|
|
|
for (auto &i: pedestal_in) {
|
|
uint16_t number = distribution1(g2);
|
|
if (number < 20) number = 20;
|
|
if (number > 16300) number = 16300;
|
|
i = 32768 | 16384 | number;
|
|
}
|
|
|
|
for (auto &i: pedestal_in2) {
|
|
uint16_t number = distribution2(g2);
|
|
if (number < 20) number = 20;
|
|
if (number > 16300) number = 16300;
|
|
i = 32768 | 16384 | number;
|
|
}
|
|
DiffractionExperiment x(DetJF(1));
|
|
x.Mode(DetectorMode::PedestalG2).PedestalG0Frames(0)
|
|
.PedestalG2Frames(nframes).NumTriggers(1).UseInternalPacketGenerator(false)
|
|
.ImagesPerTrigger(0).IncidentEnergy_keV(12.4).StorageCells(16);
|
|
|
|
REQUIRE(x.GetStorageCellNumber() == 2);
|
|
REQUIRE(x.GetFrameNum() == nframes * 2);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
|
auto test = std::make_unique<MockAcquisitionDevice>(i, nframes * 2);
|
|
for (int j = 0; j < distinct_frames; j++) {
|
|
test->SetOutput(2 * j, 0, *OutputWithPixels(pedestal_in2.data() + j * RAW_MODULE_SIZE));
|
|
test->SetOutput(2 * j + 1, 0, *OutputWithPixels(pedestal_in.data() + j * RAW_MODULE_SIZE));
|
|
}
|
|
for (int j = 0; j < nframes; j++) {
|
|
test->CreateJFPackets(x, 2 * j + 1, 1, 0, nullptr);
|
|
test->CreateJFPackets(x, 2 * j + 2, 1, 0, nullptr);
|
|
}
|
|
test->CreateFinalPacket(x);
|
|
aq_devices.Add(std::move(test));
|
|
}
|
|
|
|
JFPedestalCalc pc(x);
|
|
for (int i = 0; i < nframes; i++)
|
|
pc.AnalyzeImage(pedestal_in.data() + (i % distinct_frames) * RAW_MODULE_SIZE);
|
|
|
|
Logger logger("JFJochReceiverTest_PedestalG2_storage_cell");
|
|
|
|
PixelMask mask(x);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
REQUIRE(output.efficiency == 1.0);
|
|
|
|
JFModulePedestal ref_pedestal;
|
|
pc.Export(ref_pedestal, 0);
|
|
JFModulePedestal out_pedestal = output.pedestal_result.at(0);
|
|
REQUIRE(abs(ref_pedestal.Mean() - out_pedestal.Mean()) < 0.65);
|
|
REQUIRE(out_pedestal.CountMaskedPixels() == 0);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_PedestalG0", "[JFJochReceiver]") {
|
|
DiffractionExperiment x(DetJF(1));
|
|
const uint16_t nthreads = 4;
|
|
size_t nframes = 500;
|
|
// The card output repeats every distinct_frames frames
|
|
size_t distinct_frames = 25;
|
|
|
|
std::vector<uint16_t> pedestal_in(RAW_MODULE_SIZE * distinct_frames);
|
|
|
|
// Predictable random number generator
|
|
std::mt19937 g1(1900);
|
|
std::normal_distribution<double> distribution(3000, 50);
|
|
|
|
for (auto &i: pedestal_in) {
|
|
uint16_t number = distribution(g1);
|
|
if (number < 20) number = 20;
|
|
if (number > 16300) number = 16300;
|
|
i = number;
|
|
}
|
|
|
|
x.Mode(DetectorMode::PedestalG0);
|
|
x.PedestalG0Frames(nframes)
|
|
.NumTriggers(1).UseInternalPacketGenerator(false)
|
|
.ImagesPerTrigger(0).IncidentEnergy_keV(12.4);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
|
auto test = std::make_unique<MockAcquisitionDevice>(i, 64);
|
|
for (int f = 0; f < distinct_frames; f++)
|
|
test->SetOutput(f, 0, *OutputWithPixels(pedestal_in.data() + f * RAW_MODULE_SIZE));
|
|
test->CreateJFPackets(x, 1, nframes, 0, nullptr);
|
|
test->CreateFinalPacket(x);
|
|
aq_devices.Add(std::move(test));
|
|
}
|
|
|
|
JFPedestalCalc pc(x);
|
|
for (int i = 0; i < nframes; i++)
|
|
pc.AnalyzeImage(pedestal_in.data() + (i % distinct_frames) * RAW_MODULE_SIZE);
|
|
|
|
PixelMask mask(x);
|
|
|
|
Logger logger("JFJochReceiverTest_PedestalG0");
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
REQUIRE(output.efficiency == 1.0);
|
|
|
|
JFModulePedestal ref_pedestal;
|
|
pc.Export(ref_pedestal, 0);
|
|
JFModulePedestal out_pedestal = output.pedestal_result.at(0);
|
|
REQUIRE(abs(ref_pedestal.Mean() - out_pedestal.Mean()) < 0.65);
|
|
REQUIRE(out_pedestal.CountMaskedPixels() == 0);
|
|
REQUIRE(out_pedestal.GetFrameCount() == nframes);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_PedestalG0_StorageCell", "[JFJochReceiver]") {
|
|
DiffractionExperiment x(DetJF(1));
|
|
const uint16_t nthreads = 4;
|
|
size_t nframes = 140;
|
|
|
|
std::vector<uint16_t> pedestal_in_0(RAW_MODULE_SIZE);
|
|
std::vector<uint16_t> pedestal_in_1(RAW_MODULE_SIZE);
|
|
std::vector<uint16_t> pedestal_in_2(RAW_MODULE_SIZE);
|
|
std::vector<uint16_t> pedestal_in_3(RAW_MODULE_SIZE);
|
|
|
|
for (auto &i: pedestal_in_0) i = 5670;
|
|
for (auto &i: pedestal_in_1) i = 4560;
|
|
for (auto &i: pedestal_in_2) i = 3450;
|
|
for (auto &i: pedestal_in_3) i = 2000;
|
|
|
|
x.Mode(DetectorMode::PedestalG0).StorageCells(4);
|
|
x.PedestalG0Frames(nframes)
|
|
.NumTriggers(1).UseInternalPacketGenerator(false)
|
|
.ImagesPerTrigger(0).IncidentEnergy_keV(12.4);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
auto test = std::make_unique<MockAcquisitionDevice>(0, 64);
|
|
test->SetOutput(0, 0, *OutputWithPixels(pedestal_in_0.data()));
|
|
test->SetOutput(1, 0, *OutputWithPixels(pedestal_in_1.data()));
|
|
test->SetOutput(2, 0, *OutputWithPixels(pedestal_in_2.data()));
|
|
test->SetOutput(3, 0, *OutputWithPixels(pedestal_in_3.data()));
|
|
test->CreateJFPackets(x, 1, nframes * 4, 0, nullptr);
|
|
test->CreateFinalPacket(x);
|
|
aq_devices.Add(std::move(test));
|
|
|
|
PixelMask mask(x);
|
|
|
|
Logger logger("JFJochReceiverTest_PedestalG0_StorageCell");
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.pedestal_result.size() == 4);
|
|
JFModulePedestal out_pedestal_0 = output.pedestal_result[0];
|
|
JFModulePedestal out_pedestal_1 = output.pedestal_result[1];
|
|
JFModulePedestal out_pedestal_2 = output.pedestal_result[2];
|
|
JFModulePedestal out_pedestal_3 = output.pedestal_result[3];
|
|
|
|
REQUIRE(out_pedestal_0.Mean() == Catch::Approx(5670));
|
|
REQUIRE(out_pedestal_0.GetFrameCount() == nframes);
|
|
REQUIRE(out_pedestal_1.Mean() == Catch::Approx(4560));
|
|
REQUIRE(out_pedestal_1.GetFrameCount() == nframes);
|
|
REQUIRE(out_pedestal_2.Mean() == Catch::Approx(3450));
|
|
REQUIRE(out_pedestal_2.GetFrameCount() == nframes);
|
|
REQUIRE(out_pedestal_3.Mean() == Catch::Approx(2000));
|
|
REQUIRE(out_pedestal_3.GetFrameCount() == nframes);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_PedestalFixedG1_StorageCell", "[JFJochReceiver]") {
|
|
DiffractionExperiment x(DetJF(1));
|
|
const uint16_t nthreads = 4;
|
|
size_t nframes = 140;
|
|
|
|
std::vector<uint16_t> pedestal_in_0(RAW_MODULE_SIZE);
|
|
std::vector<uint16_t> pedestal_in_1(RAW_MODULE_SIZE);
|
|
std::vector<uint16_t> pedestal_in_2(RAW_MODULE_SIZE);
|
|
std::vector<uint16_t> pedestal_in_3(RAW_MODULE_SIZE);
|
|
|
|
for (auto &i: pedestal_in_0) i = 16384 | 5670;
|
|
for (auto &i: pedestal_in_1) i = 16384 | 4560;
|
|
for (auto &i: pedestal_in_2) i = 16384 | 3450;
|
|
for (auto &i: pedestal_in_3) i = 16384 | 2000;
|
|
|
|
x.Mode(DetectorMode::PedestalG1).StorageCells(4).FixedGainG1(true);
|
|
x.PedestalG1Frames(nframes)
|
|
.NumTriggers(1).UseInternalPacketGenerator(false)
|
|
.ImagesPerTrigger(0).IncidentEnergy_keV(12.4);
|
|
|
|
REQUIRE(x.GetStorageCellNumber() == 4);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
auto test = std::make_unique<MockAcquisitionDevice>(0, 64);
|
|
test->SetOutput(0, 0, *OutputWithPixels(pedestal_in_0.data()));
|
|
test->SetOutput(1, 0, *OutputWithPixels(pedestal_in_1.data()));
|
|
test->SetOutput(2, 0, *OutputWithPixels(pedestal_in_2.data()));
|
|
test->SetOutput(3, 0, *OutputWithPixels(pedestal_in_3.data()));
|
|
test->CreateJFPackets(x, 1, nframes * 4, 0, nullptr);
|
|
test->CreateFinalPacket(x);
|
|
aq_devices.Add(std::move(test));
|
|
|
|
PixelMask mask(x);
|
|
|
|
Logger logger("JFJochReceiverTest_PedestalFixedG1_StorageCell");
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.pedestal_result.size() == 4);
|
|
JFModulePedestal out_pedestal_0 = output.pedestal_result[0];
|
|
JFModulePedestal out_pedestal_1 = output.pedestal_result[1];
|
|
JFModulePedestal out_pedestal_2 = output.pedestal_result[2];
|
|
JFModulePedestal out_pedestal_3 = output.pedestal_result[3];
|
|
|
|
REQUIRE(out_pedestal_0.Mean() == Catch::Approx(5670));
|
|
REQUIRE(out_pedestal_0.GetFrameCount() == nframes);
|
|
REQUIRE(out_pedestal_1.Mean() == Catch::Approx(4560));
|
|
REQUIRE(out_pedestal_1.GetFrameCount() == nframes);
|
|
REQUIRE(out_pedestal_2.Mean() == Catch::Approx(3450));
|
|
REQUIRE(out_pedestal_2.GetFrameCount() == nframes);
|
|
REQUIRE(out_pedestal_3.Mean() == Catch::Approx(2000));
|
|
REQUIRE(out_pedestal_3.GetFrameCount() == nframes);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_PedestalG1_NoFrames", "[JFJochReceiver]") {
|
|
DiffractionExperiment x(DetJF(1));
|
|
const uint16_t nthreads = 4;
|
|
size_t nframes = 256;
|
|
|
|
std::vector<uint16_t> pedestal_in(RAW_MODULE_SIZE*nframes);
|
|
|
|
for (auto &i: pedestal_in) i = 16384 | 14000;
|
|
|
|
x.Mode(DetectorMode::PedestalG1);
|
|
x.PedestalG0Frames(0).PedestalG1Frames(256).NumTriggers(1)
|
|
.UseInternalPacketGenerator(false).ImagesPerTrigger(0).IncidentEnergy_keV(12.4);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
|
auto test = std::make_unique<MockAcquisitionDevice>(i, nframes + 8);
|
|
test->CreateFinalPacket(x);
|
|
aq_devices.Add(std::move(test));
|
|
}
|
|
|
|
PixelMask mask(x);
|
|
|
|
Logger logger("JFJochReceiverTest_PedestalG1_NoFrames");
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.expected_packets[0] != 0);
|
|
REQUIRE(output.received_packets[0] == 0);
|
|
REQUIRE(output.status.images_sent == 0);
|
|
REQUIRE(output.efficiency < 1.0);
|
|
|
|
JFModulePedestal out_pedestal = output.pedestal_result.at(0);
|
|
REQUIRE(out_pedestal.CountMaskedPixels() == RAW_MODULE_SIZE);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_PacketLost_Raw", "[JFJochReceiver]") {
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
std::vector<uint16_t> frame_in(RAW_MODULE_SIZE);
|
|
for (auto &i: frame_in) i = 776;
|
|
|
|
x.Raw();
|
|
x.PedestalG0Frames(0).NumTriggers(1)
|
|
.UseInternalPacketGenerator(false).ImagesPerTrigger(4).IncidentEnergy_keV(12.4)
|
|
.Compression(CompressionAlgorithm::NO_COMPRESSION);
|
|
|
|
PixelMask pixel_mask(x);
|
|
|
|
// The card writes the missing packet as UINT16_MAX
|
|
std::vector<uint16_t> frame_lost = frame_in;
|
|
for (int i = 127 * 4096; i < RAW_MODULE_SIZE; i++)
|
|
frame_lost[i] = UINT16_MAX;
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
|
auto test = std::make_unique<MockAcquisitionDevice>(i, 64);
|
|
for (int image = 0; image < 4; image++) {
|
|
test->SetOutput(image, 0, *OutputWithPixels((image == 3) ? frame_lost.data() : frame_in.data()));
|
|
test->SetOutput(image, 1, *OutputWithPixels(frame_in.data()));
|
|
}
|
|
test->CreateJFPackets(x, 1, 1, 0, nullptr);
|
|
test->CreateJFPackets(x, 1, 1, 1, nullptr);
|
|
test->CreateJFPackets(x, 2, 1, 0, nullptr);
|
|
test->CreateJFPackets(x, 2, 1, 1, nullptr);
|
|
test->CreateJFPackets(x, 3, 1, 0, nullptr);
|
|
test->CreateJFPackets(x, 3, 1, 1, nullptr);
|
|
|
|
for (int j = 0; j < 127; j++)
|
|
test->CreateJFPacket(x, 4, j, 0, nullptr);
|
|
test->CreateJFPackets(x, 4, 1, 1, nullptr);
|
|
test->CreateFinalPacket(x);
|
|
|
|
aq_devices.Add(std::move(test));
|
|
}
|
|
Logger logger("JFJochReceiverTest_PacketLost_Raw");
|
|
|
|
JFCalibration calib(x);
|
|
|
|
TestImagePusher pusher(x.GetImageNum() - 1);
|
|
|
|
JFJochReceiverService service(aq_devices, logger, pusher);
|
|
service.NumThreads(nthreads);
|
|
|
|
service.Start(x, pixel_mask, &calib);
|
|
auto receiver_out = service.Stop();
|
|
|
|
const auto image = pusher.GetImage();
|
|
|
|
REQUIRE(aq_devices[0].GetBytesReceived() == (8*128-1) * 8192UL);
|
|
REQUIRE(image.size() == 2 * RAW_MODULE_SIZE * sizeof(uint16_t));
|
|
REQUIRE(pusher.GetCounter() == x.GetImageNum());
|
|
|
|
auto raw = (const uint16_t *) (image.data());
|
|
CHECK(raw[0] == 776);
|
|
CHECK(raw[256*1024+315] == 776);
|
|
CHECK(raw[RAW_MODULE_SIZE-4095] == UINT16_MAX);
|
|
CHECK(raw[RAW_MODULE_SIZE-1] == UINT16_MAX);
|
|
|
|
CHECK(raw[RAW_MODULE_SIZE+0] == 776);
|
|
CHECK(raw[RAW_MODULE_SIZE+256*1024+315] == 776);
|
|
CHECK(raw[2*RAW_MODULE_SIZE-1] == 776);
|
|
|
|
REQUIRE(receiver_out.efficiency < 1.0);
|
|
REQUIRE(receiver_out.status.images_sent == x.GetImageNum());
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_Cancel", "[JFJochReceiver]") {
|
|
DiffractionExperiment x(DetJF(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
std::vector<uint16_t> frame_in(RAW_MODULE_SIZE);
|
|
for (auto &i: frame_in) i = 776;
|
|
|
|
x.Raw();
|
|
x.PedestalG0Frames(0).NumTriggers(1)
|
|
.UseInternalPacketGenerator(false).ImagesPerTrigger(4).IncidentEnergy_keV(12.4);
|
|
|
|
PixelMask pixel_mask(x);
|
|
|
|
AcquisitionDeviceGroup aq_devices;
|
|
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
|
auto test = std::make_unique<MockAcquisitionDevice>(i, 64);
|
|
test->SetOutput(0, 0, *OutputWithPixels(frame_in.data()));
|
|
test->SetOutput(0, 1, *OutputWithPixels(frame_in.data()));
|
|
test->CreateJFPackets(x, 1, 1, 0, nullptr);
|
|
test->CreateJFPackets(x, 1, 1, 1, nullptr);
|
|
test->CreateJFPackets(x, 2, 1, 0, nullptr);
|
|
test->CreateJFPackets(x, 2, 1, 1, nullptr);
|
|
test->CreateJFPackets(x, 3, 1, 0, nullptr);
|
|
test->CreateJFPackets(x, 3, 1, 1, nullptr);
|
|
aq_devices.Add(std::move(test));
|
|
}
|
|
Logger logger("JFJochReceiverTest_Cancel");
|
|
|
|
JFCalibration calib(x);
|
|
|
|
TestImagePusher pusher(x.GetImageNum() - 1);
|
|
JFJochReceiverService service(aq_devices, logger, pusher);
|
|
service.NumThreads(nthreads);
|
|
|
|
service.Start(x, pixel_mask, &calib);
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
service.Cancel(false);
|
|
|
|
auto receiver_out = service.Stop();
|
|
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<uint16_t> 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<MockAcquisitionDevice>(0, 64);
|
|
test->SetOutput(0, 0, *OutputWithPixels(frame_in.data()));
|
|
test->CreateJFPackets(x, 1, 10, 0, nullptr);
|
|
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(1));
|
|
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");
|
|
|
|
DiffractionExperiment x(DetEIGER(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Raw();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_EIGER_8bit", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_EIGER_8bit");
|
|
|
|
DiffractionExperiment x(DetEIGER(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
|
x.EigerBitDepth(8);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_EIGER_32bit", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_EIGER_32bit");
|
|
|
|
DiffractionExperiment x(DetEIGER(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
|
x.EigerBitDepth(32);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|
|
|
|
TEST_CASE("JFJochReceiverTest_EIGER_conversion", "[JFJochReceiver]") {
|
|
Logger logger("JFJochReceiverTest_EIGER_conversion");
|
|
|
|
DiffractionExperiment x(DetEIGER(2));
|
|
const uint16_t nthreads = 4;
|
|
|
|
x.Conversion();
|
|
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
|
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
|
|
|
|
|
PixelMask mask(x);
|
|
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
|
|
|
JFJochReceiverOutput output;
|
|
bool ret;
|
|
REQUIRE_NOTHROW(ret = JFJochReceiverTest(output, logger, aq_devices, x, mask, nthreads));
|
|
REQUIRE(ret);
|
|
REQUIRE(output.efficiency == 1.0);
|
|
REQUIRE(output.status.images_sent == x.GetImageNum());
|
|
|
|
REQUIRE(!output.status.cancelled);
|
|
}
|