Files
Jungfraujoch/tests/FPGAAcquisitionDeviceTest.cpp
leonarski_f 4809c1622c
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 16m43s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 28m46s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 32m5s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 39m44s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 5m7s
Build Packages / Create release (push) Successful in 8s
Build Packages / Build documentation (push) Successful in 49s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 22m30s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 31m54s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 11m29s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 23m51s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 26m7s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 29m38s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 28m6s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 29m44s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 33m22s
Build Packages / Generate python client (push) Successful in 47s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 34m6s
Build Packages / Unit tests (push) Successful in 1h2m47s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 35m59s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 34m8s
Build Packages / Validation Battery (push) Successful in 38m31s
v1.0.0-rc.187 (#98)
* Rugnux: Refinement several times faster, one protocol on the CPU and the GPU, parts of it on the Apple GPU; its random draws are the same on every platform.
* Rugnux: Refinement follows common practice: the free set decides only the restraint weights and the displacement model (isotropic, TLS or anisotropic, by Hamilton's test), everything else is decided on the working set; lower R-free for placed and predicted models.
* Rugnux: Restraint dictionaries via `--restraints` (or among the inputs) and more built-in ligands; a model whose space group is a subgroup of the data's is refined in its own group; reflections plus a model select `--mode refine` on their own.
* Rugnux: `-C` fixes the crystal system on the axes as typed; `-S` alone fixes the space group only, the cell is still found and reduced; a space group or cell stored in the input file is ignored, with a line in the log.
* Rugnux: More reliable multi-sweep merging; `--mode scale` merges several stills runs as one; `_plot.txt` and the report name each input; a second crystal form is reported for stills given a cell.
* jfjoch_broker (experimental): Live Rugnux on FPGA detectors (JUNGFRAU) takes the same path as a DECTRIS stream, rotation and serial alike, model step included, with analysis threads per GPU; frames waiting for the analysis can be viewed; no host stage drops a frame - a source faster than the analysis is held at the card.
* jfjoch_broker: Summation of more than 256 frames per image is split between the card and the host (`summation_mode` is then `hybrid`), and live Rugnux runs on such collections; pedestal runs take a receiver of their own.
* jfjoch_broker (experimental): `stills_downsample` analyses 1 of every N serial images (chosen by a hash; the first 2000 all; the others written without analysis; reset to 1 by `/initialize`); `max_spot_count` left out means 250 for per-image indexing and up to 1000 for live stills; the live status gives the merge before the model work, the fitted resolution and the anomalous peak height of each unexplained blob.
* jfjoch_broker: Without a `pcie` entry the broker runs on a mock of the card instead of the HLS simulation; its spot, ROI and azimuthal results are zero then.
* Web frontend: Redesigned Rugnux live page; Vite 8, TypeScript 6, Mol* 5.13 and dependency security updates.
* Tools: `jfjoch_fpga_stills_test` measures live stills on the cards with a stored dataset; `jfjoch_fpga_test` loses the HLS-simulation option.
* Other: FFTW no longer fetched or linked (the CPU FFT indexer keeps the name `FFTW`); PCIe driver now GPL-2.0-or-later and third-party notices complete; several crash fixes.

Reviewed-on: #98
Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
2026-11-19 20:49:28 +01:00

217 lines
8.6 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
// The host side of the card - FPGAAcquisitionDevice and its AcquisitionCounters - on the mock of the card: what
// arrived, where it went, delays, the end of the data collection. The card itself is compared with the mock in
// MockAcquisitionDeviceTest.cpp.
#include <catch2/catch_all.hpp>
#include "../acquisition_device/MockAcquisitionDevice.h"
TEST_CASE("FPGAAcquisitionDevice_InternalPacketGenerator", "[FPGAAcquisitionDevice]") {
const uint16_t nmodules = 4;
DiffractionExperiment x(DetJF(nmodules));
x.Raw();
x.UseInternalPacketGenerator(true).ImagesPerTrigger(4).PedestalG0Frames(0);
MockAcquisitionDevice test(0, 64);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.GetBytesReceived() == 128 * nmodules * 4 * JUNGFRAU_PACKET_SIZE_BYTES);
for (int image = 0; image < 4; image++) {
for (int m = 0; m < nmodules; m++) {
const auto &stats = test.GetDeviceOutput(image, m)->module_statistics;
CHECK(stats.frame_number == image);
CHECK(stats.module_number == m);
CHECK(stats.timestamp == INT_PKT_GEN_EXPTTIME * image);
CHECK(stats.pulse_id == INT_PKT_GEN_BUNCHID + image);
CHECK(stats.exptime == INT_PKT_GEN_EXPTTIME);
CHECK(stats.detector_type == SLS_DETECTOR_TYPE_JUNGFRAU);
}
}
REQUIRE(test.GetExpectedDescriptorsPerModule() == DMA_DESCRIPTORS_PER_MODULE);
}
// Of four data streams, the card of the last one generates only its own module
TEST_CASE("FPGAAcquisitionDevice_InternalPacketGenerator_DataStream", "[FPGAAcquisitionDevice]") {
const uint16_t nmodules = 4;
DiffractionExperiment x(DetJF(nmodules));
x.DataStreams(4);
x.Raw();
x.UseInternalPacketGenerator(true).ImagesPerTrigger(4).PedestalG0Frames(0);
MockAcquisitionDevice test(3, 64);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.GetBytesReceived() == 128 * 4 * JUNGFRAU_PACKET_SIZE_BYTES);
for (int image = 0; image < 4; image++)
REQUIRE(test.Counters().IsFullModuleCollected(image, 0));
}
// Module 0 runs on, module 1 stops after 3 frames, modules 2 and 3 never come: the slowest frame moves on once the
// fastest module is far enough ahead
TEST_CASE("FPGAAcquisitionDevice_MissingModules", "[FPGAAcquisitionDevice]") {
const uint16_t nmodules = 4;
const uint64_t nframes = AcquisitionCounters::ThresholdFramesLost + 5;
DiffractionExperiment x(DetJF(nmodules));
x.Raw();
x.PedestalG0Frames(0).ImagesPerTrigger(nframes).NumTriggers(1);
MockAcquisitionDevice test(0, nframes + 2);
test.CreateJFPackets(x, 1, nframes, 0, nullptr);
test.CreateJFPackets(x, 1, 3, 1, nullptr);
test.CreateFinalPacket(x);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.Counters().GetSlowestFrameNumber() == 5 - 1);
REQUIRE(test.Counters().GetBufferHandle(0, 0) != AcquisitionCounters::HandleNotFound);
REQUIRE(test.Counters().GetBufferHandle(0, 1) == AcquisitionCounters::HandleNotFound);
REQUIRE(test.Counters().GetBufferHandle(0, 2) == AcquisitionCounters::HandleNotFound);
REQUIRE(test.GetBytesReceived() == nframes * 128 * JUNGFRAU_PACKET_SIZE_BYTES);
}
TEST_CASE("FPGAAcquisitionDevice_Delay", "[FPGAAcquisitionDevice]") {
const uint16_t nmodules = 4;
DiffractionExperiment x(DetJF(nmodules));
x.Raw();
x.PedestalG0Frames(0).ImagesPerTrigger(3).NumTriggers(1);
MockAcquisitionDevice test(0, 64);
for (int f = 1; f <= 3; f++)
for (int m = 0; m < nmodules; m++)
test.CreateJFPacket(x, f, 0, m, nullptr);
test.CreateFinalPacket(x);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.Counters().CalculateDelay(0) == 2);
REQUIRE(test.Counters().CalculateDelay(0, 0) == 2);
REQUIRE(test.Counters().CalculateDelay(1) == 1);
REQUIRE(test.Counters().CalculateDelay(1, 0) == 1);
REQUIRE(test.Counters().CalculateDelay(2) == 0);
REQUIRE(test.Counters().CalculateDelay(2, 0) == 0);
}
// A single packet of one module: that module of that frame is there, nothing else is
TEST_CASE("FPGAAcquisitionDevice_LostFrame", "[FPGAAcquisitionDevice]") {
const uint16_t nmodules = 4;
DiffractionExperiment x(DetJF(nmodules));
x.Raw();
x.PedestalG0Frames(0).ImagesPerTrigger(3).NumTriggers(1);
MockAcquisitionDevice test(0, 64);
test.CreateJFPacket(x, 1, 0, 0, nullptr);
test.CreateFinalPacket(x);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.GetBytesReceived() == JUNGFRAU_PACKET_SIZE_BYTES);
REQUIRE_NOTHROW(test.GetDeviceOutput(0, 0));
REQUIRE(!test.Counters().IsFullModuleCollected(0, 0));
REQUIRE_THROWS(test.GetDeviceOutput(0, 1));
REQUIRE_THROWS(test.GetDeviceOutput(1, 0));
REQUIRE_THROWS(test.GetDeviceOutput(2, 1));
}
TEST_CASE("FPGAAcquisitionDevice_OneFrame", "[FPGAAcquisitionDevice]") {
const uint16_t nmodules = 4;
DiffractionExperiment x(DetJF(nmodules));
x.PedestalG0Frames(0).NumTriggers(1).ImagesPerTrigger(1);
MockAcquisitionDevice test(0, 64);
test.CreateJFPackets(x, 1, 1, 0, nullptr);
test.CreateFinalPacket(x);
REQUIRE_NOTHROW(test.StartAction(x));
test.WaitForActionComplete();
REQUIRE(test.Counters().IsAcquisitionFinished());
// address properly aligned
REQUIRE((uint64_t) test.GetDeviceOutput(0, 0)->pixels % 128 == 0);
REQUIRE(test.Counters().GetSlowestFrameNumber() == 0);
REQUIRE(test.Counters().GetCurrFrameNumber(0) == 0);
REQUIRE(test.GetBytesReceived() == 128 * JUNGFRAU_PACKET_SIZE_BYTES);
}
// A frame far past the last one ends the data collection
TEST_CASE("FPGAAcquisitionDevice_DetectLastFrame", "[FPGAAcquisitionDevice]") {
const uint16_t nmodules = 4;
DiffractionExperiment x(DetJF(nmodules));
x.PedestalG0Frames(0).NumTriggers(2).ImagesPerTrigger(5);
MockAcquisitionDevice test(0, 64);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE(!test.Counters().IsAcquisitionFinished());
test.CreateJFPacket(x, 15, 0, 0, nullptr);
test.WaitForActionComplete();
REQUIRE(test.Counters().IsAcquisitionFinished());
}
TEST_CASE("FPGAAcquisitionDevice_BunchID", "[FPGAAcquisitionDevice]") {
const uint64_t bunchid = 0xAAAAAAAA87345600;
DiffractionExperiment x(DetJF(4));
x.Raw();
x.PedestalG0Frames(0).ImagesPerTrigger(3).NumTriggers(1);
MockAcquisitionDevice test(0, 64);
test.CreateXfelBunchIDPacket(bunchid, 0);
test.CreateFinalPacket(x);
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
REQUIRE(test.GetBytesReceived() == 0);
REQUIRE(test.GetDataCollectionStatus().current_pulseid == bunchid);
}
TEST_CASE("FPGAAcquisitionDevice_InternalGeneratorMemory", "[FPGAAcquisitionDevice]") {
// 64 module frames in the card memory; the generator takes 63 at most
DiffractionExperiment x(DetJF(2));
x.UseInternalPacketGenerator(true).ImagesPerTrigger(1).NumTriggers(1);
MockAcquisitionDevice test(0, 64);
x.InternalPacketGeneratorImages(31);
REQUIRE_NOTHROW(test.PrepareAction(x));
x.InternalPacketGeneratorImages(32);
REQUIRE_THROWS(test.PrepareAction(x));
std::vector<uint16_t> frame(RAW_MODULE_SIZE);
REQUIRE_NOTHROW(test.SetInternalGeneratorFrame(frame.data(), 62));
REQUIRE_THROWS(test.SetInternalGeneratorFrame(frame.data(), 63));
}
// The generator's frames are what the card writes when no output was set for a module
TEST_CASE("FPGAAcquisitionDevice_InternalGeneratorFrames", "[FPGAAcquisitionDevice]") {
const uint16_t nmodules = 2;
DiffractionExperiment x(DetJF(nmodules));
x.Raw();
x.UseInternalPacketGenerator(true).InternalPacketGeneratorImages(2).ImagesPerTrigger(5).PedestalG0Frames(0);
MockAcquisitionDevice test(0, 64);
std::vector<uint16_t> frame(RAW_MODULE_SIZE);
for (int slot = 0; slot < 4; slot++) {
std::fill(frame.begin(), frame.end(), 100 + slot);
test.SetInternalGeneratorFrame(frame.data(), slot);
}
REQUIRE_NOTHROW(test.StartAction(x));
REQUIRE_NOTHROW(test.WaitForActionComplete());
for (int image = 0; image < 5; image++) {
for (int m = 0; m < nmodules; m++) {
const auto pixels = reinterpret_cast<const uint16_t *>(test.GetDeviceOutput(image, m)->pixels);
CHECK(pixels[0] == 100 + (image % 2) * nmodules + m);
CHECK(pixels[RAW_MODULE_SIZE - 1] == 100 + (image % 2) * nmodules + m);
}
}
}