Merge branch 'rc188-h' into rc188-int
This commit is contained in:
commit
0f16c44e84
34 files changed
+1532
-5926
No files matched your search
@@ -317,9 +317,12 @@ Check first and do not duplicate a credit an adjacent comment already carries.
|
||||
|
||||
## Local end-to-end run (no detector / no FPGA)
|
||||
|
||||
The FPGA HLS logic can be simulated on the CPU (`HLSSimulatedDevice`), so the full software
|
||||
stack runs without hardware (slowly — fixed-point math on CPU). See
|
||||
`docs/JFJOCH_BROKER.md` for the canonical walkthrough.
|
||||
Without a `pcie` entry in its config the broker runs on `MockAcquisitionDevice`
|
||||
(`acquisition_device/`), a black-box mock of the FPGA card: it reproduces the card's interface
|
||||
towards the host (frames, completions, counters, start/stop/cancel, internal frame generator, the
|
||||
error and timeout paths) but computes nothing — the images are the uploaded generator images as
|
||||
given, and the card's spot-finding/ROI/azimuthal results are zero. The same mock carries the
|
||||
receiver, state-machine and writer tests. See `docs/JFJOCH_BROKER.md` for the canonical walkthrough.
|
||||
|
||||
```
|
||||
cd build/broker
|
||||
@@ -400,10 +403,11 @@ with cuFFT on a GPU and with pocketfft without one (or under `--no-gpu`), while
|
||||
implementation each. Only rugnux's CLI spells it this way: internally (and in the broker's OpenAPI)
|
||||
`FFT` is the GPU implementation, which the CLI's `cufft` maps onto.
|
||||
|
||||
**FPGA** (`fpga/`): `hls/` is the Vitis HLS source (image-analysis kernels), `hls_simulation/`
|
||||
runs that same HLS on CPU for hardware-free testing, `hdl/` is the Verilog RTL, `host_library/` is
|
||||
the host-side driver, `pcie_driver/` is the kernel module. The HLS algorithms are documented in
|
||||
`docs/FPGA_DATA_ANALYSIS.md`.
|
||||
**FPGA** (`fpga/`): `hls/` is the Vitis HLS source (image-analysis kernels; its CPU library
|
||||
`JFJochHLSCores` and the Xilinx headers in `fpga/include/` are no longer part of the software
|
||||
build), `hdl/` is the Verilog RTL, `host_library/` is the host-side driver, `pcie_driver/` is the
|
||||
kernel module. The HLS algorithms are documented in `docs/FPGA_DATA_ANALYSIS.md`. The software is
|
||||
tested without hardware on `MockAcquisitionDevice`, not on a simulation of the firmware.
|
||||
|
||||
**Detector control** (`detector_control/`): wrappers for SLS (JUNGFRAU) and DECTRIS SIMPLON
|
||||
(EIGER). **`jungfrau/`**: JUNGFRAU ADU→energy gain/pedestal calibration.
|
||||
|
||||
@@ -50,7 +50,7 @@ protected:
|
||||
ThreadSafeFIFO<WorkRequest> work_request_queue;
|
||||
|
||||
// Non-owning view of the per-buffer addresses. Each device subclass owns the backing memory
|
||||
// and its lifecycle: PCIExpressDevice mmap's/munmap's kernel DMA buffers, HLSSimulatedDevice
|
||||
// and its lifecycle: PCIExpressDevice mmap's/munmap's kernel DMA buffers, MockAcquisitionDevice
|
||||
// points these at plain heap buffers it owns.
|
||||
std::vector<DeviceOutput *> buffer_device;
|
||||
Logger *logger;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "AcquisitionDeviceGroup.h"
|
||||
#include "PCIExpressDevice.h"
|
||||
#include "HLSSimulatedDevice.h"
|
||||
#include "MockAcquisitionDevice.h"
|
||||
|
||||
AcquisitionDevice &AcquisitionDeviceGroup::operator[](int idx) {
|
||||
if ((idx < 0) || (idx >= aq_devices.size()))
|
||||
@@ -28,8 +28,8 @@ void AcquisitionDeviceGroup::AddPCIeDevice(const std::string &device_name, std::
|
||||
aq_devices.emplace_back(std::move(tmp));
|
||||
}
|
||||
|
||||
void AcquisitionDeviceGroup::AddHLSDevice(int64_t buffer_size_modules) {
|
||||
aq_devices.emplace_back(std::make_unique<HLSSimulatedDevice>(aq_devices.size(), buffer_size_modules));
|
||||
void AcquisitionDeviceGroup::AddMockDevice(int64_t buffer_size_modules) {
|
||||
aq_devices.emplace_back(std::make_unique<MockAcquisitionDevice>(aq_devices.size(), buffer_size_modules));
|
||||
}
|
||||
|
||||
std::vector<AcquisitionDeviceNetConfig> AcquisitionDeviceGroup::GetNetworkConfig() {
|
||||
|
||||
@@ -14,7 +14,8 @@ public:
|
||||
size_t size();
|
||||
void Add(std::unique_ptr<AcquisitionDevice> &&device);
|
||||
void AddPCIeDevice(const std::string &device_name, std::optional<uint32_t> ipv4_addr = {});
|
||||
void AddHLSDevice(int64_t buffer_size_modules);
|
||||
// The mock of the card, for the broker without hardware
|
||||
void AddMockDevice(int64_t buffer_size_modules);
|
||||
std::vector<AcquisitionDeviceNetConfig> GetNetworkConfig();
|
||||
std::vector<DeviceStatus> GetDeviceStatus() const;
|
||||
void EnableLogging(Logger *logger);
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
ADD_LIBRARY(JFJochAcquisitionDevice STATIC
|
||||
AcquisitionDevice.cpp AcquisitionDevice.h
|
||||
AcquisitionCounters.cpp AcquisitionCounters.h
|
||||
HLSSimulatedDevice.cpp HLSSimulatedDevice.h
|
||||
MockAcquisitionDevice.cpp MockAcquisitionDevice.h
|
||||
Completion.cpp Completion.h ../fpga/pcie_driver/jfjoch_fpga.h
|
||||
PCIExpressDevice.cpp PCIExpressDevice.h
|
||||
FPGAAcquisitionDevice.cpp FPGAAcquisitionDevice.h
|
||||
AcquisitionDeviceGroup.cpp
|
||||
AcquisitionDeviceGroup.h)
|
||||
|
||||
TARGET_LINK_LIBRARIES(JFJochAcquisitionDevice JFJochDevice JFJochCommon JFJochHLSSimulation JFCalibration)
|
||||
TARGET_LINK_LIBRARIES(JFJochAcquisitionDevice JFJochDevice JFJochCommon JFCalibration)
|
||||
@@ -1,117 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include "HLSSimulatedDevice.h"
|
||||
|
||||
HLSSimulatedDevice::HLSSimulatedDevice(uint16_t data_stream, size_t in_frame_buffer_size_modules)
|
||||
: FPGAAcquisitionDevice(data_stream) {
|
||||
mac_addr = 0xCCAA11223344;
|
||||
ipv4_addr = 0x0132010A;
|
||||
|
||||
max_modules = MAX_MODULES_FPGA;
|
||||
|
||||
buffers.reserve(in_frame_buffer_size_modules);
|
||||
for (size_t i = 0; i < in_frame_buffer_size_modules; i++) {
|
||||
buffers.push_back(std::make_unique<FrameBuffer>()); // zero-initialised, 64-byte aligned
|
||||
buffer_device.push_back(reinterpret_cast<DeviceOutput *>(buffers.back().get()));
|
||||
}
|
||||
|
||||
device = std::make_unique<HLSDevice>(buffer_device);
|
||||
internal_generator_module_frames = GeneratorModuleFrames(device->GetDataCollectionStatus().hbm_size_bytes);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::CreateFinalPacket(const DiffractionExperiment& experiment) {
|
||||
device->CreateFinalPacket();
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::CreateJFPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet,
|
||||
uint32_t module_number, const uint16_t *data, int8_t adjust_axis, uint8_t user) {
|
||||
device->CreateJFPacket(frame_number, eth_packet, module_number, data, adjust_axis, user);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::CreateJFPackets(const DiffractionExperiment& experiment, uint64_t frame_number_0, uint64_t frames,
|
||||
uint32_t module_number, const uint16_t *data) {
|
||||
for (uint64_t i = 0; i < frames; i++) {
|
||||
for (int j = 0; j < 128; j++)
|
||||
CreateJFPacket(experiment, frame_number_0 + i, j, module_number, data + (i * 128 + j) * 4096, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::CreateEIGERPacket(const DiffractionExperiment &experiment, uint64_t frame_number,
|
||||
uint32_t eth_packet, uint32_t module_number, uint32_t col, uint32_t row,
|
||||
const uint16_t *data) {
|
||||
device->CreateEIGERPacket(frame_number, eth_packet, module_number, col, row, data);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::HW_ReadActionRegister(DataCollectionConfig *job) {
|
||||
device->HW_ReadActionRegister(job);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::HW_WriteActionRegister(const DataCollectionConfig *job) {
|
||||
device->HW_WriteActionRegister(job);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::FPGA_StartAction(const DiffractionExperiment &experiment) {
|
||||
device->FPGA_StartAction();
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::HW_RunInternalGenerator(const FrameGeneratorConfig &config) {
|
||||
device->HW_RunInternalGenerator(config);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::FPGA_EndAction() {
|
||||
device->FPGA_EndAction();
|
||||
if (const int result = device->GetFrameGeneratorResult(); result != 0)
|
||||
throw JFJochException(JFJochExceptionCategory::AcquisitionDeviceError,
|
||||
"Internal frame generator refused its configuration, error code " + std::to_string(result));
|
||||
}
|
||||
|
||||
|
||||
bool HLSSimulatedDevice::HW_ReadMailbox(uint32_t *values) {
|
||||
return device->HW_ReadMailbox(values);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::Cancel() {
|
||||
device->Cancel();
|
||||
}
|
||||
|
||||
bool HLSSimulatedDevice::HW_IsIdle() const {
|
||||
return device->HW_IsIdle();
|
||||
}
|
||||
|
||||
|
||||
bool HLSSimulatedDevice::HW_SendWorkRequest(uint32_t handle) {
|
||||
return device->HW_SendWorkRequest(handle);
|
||||
}
|
||||
|
||||
DataCollectionStatus HLSSimulatedDevice::GetDataCollectionStatus() const {
|
||||
return device->GetDataCollectionStatus();
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::HW_LoadCalibration(const LoadCalibrationConfig &config) {
|
||||
device->HW_LoadCalibration(config);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) {
|
||||
device->HW_SetSpotFinderParameters(params);
|
||||
}
|
||||
|
||||
void HLSSimulatedDevice::CreateXfelBunchIDPacket(double pulse_id, uint32_t event_code) {
|
||||
device->CreateXfelBunchIDPacket(pulse_id, event_code);
|
||||
}
|
||||
|
||||
DeviceStatus HLSSimulatedDevice::GetDeviceStatus() const {
|
||||
DeviceStatus status{};
|
||||
|
||||
strncpy(status.serial_number, "HLS1", sizeof(status.device_number));
|
||||
strncpy(status.device_number, "HLS device", sizeof(status.device_number));
|
||||
status.fpga_default_mac_addr = mac_addr;
|
||||
status.eth_link_count = 1;
|
||||
status.eth_link_status = 1;
|
||||
status.packets_sls = device->GetSLSPackets();
|
||||
status.packets_udp = device->GetUDPPackets();
|
||||
status.hbm_0_temp_C = 0;
|
||||
status.hbm_1_temp_C = 0;
|
||||
status.fpga_temp_C = 0;
|
||||
return status;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "../common/DiffractionExperiment.h"
|
||||
#include "../fpga/hls_simulation/HLSDevice.h"
|
||||
|
||||
#include "FPGAAcquisitionDevice.h"
|
||||
|
||||
class HLSSimulatedDevice : public FPGAAcquisitionDevice {
|
||||
// Owns the simulated frame buffers. Plain heap (this path is not performance-critical, so no
|
||||
// NUMA placement and no mmap), but page-aligned (4 KiB) to match the real device's kernel DMA
|
||||
// buffers - more than enough for the data path's alignment needs (AXI datamover 64 B,
|
||||
// FPGAIntegrationTest 128 B). Declared before `device` so the buffers outlive the HLSDevice
|
||||
// action thread that writes into them; buffer_device points into these.
|
||||
struct alignas(4096) FrameBuffer { uint8_t data[FPGA_BUFFER_LOCATION_SIZE]; };
|
||||
std::vector<std::unique_ptr<FrameBuffer>> buffers;
|
||||
std::unique_ptr<HLSDevice> device;
|
||||
|
||||
void HW_ReadActionRegister(DataCollectionConfig *job) override;
|
||||
void HW_WriteActionRegister(const DataCollectionConfig *job) override;
|
||||
|
||||
void FPGA_StartAction(const DiffractionExperiment &experiment) override;
|
||||
void FPGA_EndAction() override;
|
||||
bool HW_IsIdle() const override;
|
||||
bool HW_ReadMailbox(uint32_t *values) override;
|
||||
bool HW_SendWorkRequest(uint32_t handle) override;
|
||||
void HW_LoadCalibration(const LoadCalibrationConfig &config) override;
|
||||
void HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) override;
|
||||
void HW_RunInternalGenerator(const FrameGeneratorConfig &config) override;
|
||||
public:
|
||||
HLSSimulatedDevice(uint16_t data_stream, size_t in_frame_buffer_size_modules);
|
||||
~HLSSimulatedDevice() override = default;
|
||||
void CreateJFPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet,
|
||||
uint32_t module_number, const uint16_t *data, int8_t adjust_axis = 0, uint8_t user = 0);
|
||||
void CreateJFPackets(const DiffractionExperiment& experiment, uint64_t frame_number_0, uint64_t frames,
|
||||
uint32_t module_number, const uint16_t *data);
|
||||
void CreateEIGERPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet,
|
||||
uint32_t module_number, uint32_t col, uint32_t row,
|
||||
const uint16_t *data);
|
||||
void CreateXfelBunchIDPacket(double bunchid, uint32_t event_code);
|
||||
void CreateFinalPacket(const DiffractionExperiment& experiment);
|
||||
DataCollectionStatus GetDataCollectionStatus() const override;
|
||||
void Cancel() override;
|
||||
DeviceStatus GetDeviceStatus() const override;
|
||||
};
|
||||
@@ -0,0 +1,556 @@
|
||||
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "MockAcquisitionDevice.h"
|
||||
|
||||
namespace {
|
||||
// Memory of one HBM interface, as the HLS simulation has it: 64 module frames for the internal generator
|
||||
constexpr uint32_t CardMemoryBytes = 32 * 1024 * 1024;
|
||||
|
||||
bool MaskEmpty(const uint64_t packet_mask[8]) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (packet_mask[i] != 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
MockAcquisitionDevice::MockAcquisitionDevice(uint16_t data_stream, size_t in_frame_buffer_size_modules)
|
||||
: FPGAAcquisitionDevice(data_stream),
|
||||
collected_modules(2 * MAX_MODULES_FPGA),
|
||||
summation_completions(MAX_MODULES_FPGA * MAX_FPGA_SUMMATION),
|
||||
summation_mask(MAX_MODULES_FPGA, std::vector<bool>(MAX_FPGA_SUMMATION)),
|
||||
summation_count(MAX_MODULES_FPGA),
|
||||
summation_frame_prefix(MAX_MODULES_FPGA) {
|
||||
mac_addr = 0xCCAA11223344;
|
||||
ipv4_addr = 0x0132010A;
|
||||
|
||||
max_modules = MAX_MODULES_FPGA;
|
||||
internal_generator_module_frames = GeneratorModuleFrames(CardMemoryBytes);
|
||||
generator_frames.resize(internal_generator_module_frames);
|
||||
|
||||
buffers.reserve(in_frame_buffer_size_modules);
|
||||
for (size_t i = 0; i < in_frame_buffer_size_modules; i++) {
|
||||
buffers.push_back(std::make_unique<FrameBuffer>());
|
||||
buffer_device.push_back(reinterpret_cast<DeviceOutput *>(buffers.back().get()));
|
||||
}
|
||||
}
|
||||
|
||||
MockAcquisitionDevice::~MockAcquisitionDevice() {
|
||||
if (action_thread.joinable())
|
||||
action_thread.join();
|
||||
stop_frame_generator = true;
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::SetOutput(uint64_t image, uint32_t module_number, const DeviceOutput &output) {
|
||||
if (outputs.size() <= image)
|
||||
outputs.resize(image + 1);
|
||||
if (outputs[image].size() <= module_number)
|
||||
outputs[image].resize(module_number + 1);
|
||||
outputs[image][module_number] = std::make_unique<DeviceOutput>(output);
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::AddPacket(const Packet &packet) {
|
||||
std::unique_lock ul(packets_mutex);
|
||||
packets.push_back(packet);
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::CreateJFPacket(const DiffractionExperiment &experiment, uint64_t frame_number,
|
||||
uint32_t eth_packet, uint32_t module_number, const uint16_t *data,
|
||||
int8_t adjust_axis, uint8_t user) {
|
||||
uint32_t half_module = ((eth_packet >= 64) ? 1 : 0);
|
||||
AddPacket(Packet{
|
||||
.frame_number = frame_number,
|
||||
.packet_number = eth_packet % 64,
|
||||
.udp_port = static_cast<uint16_t>(2 * module_number + half_module),
|
||||
.column = 0,
|
||||
.detector_type = SLS_DETECTOR_TYPE_JUNGFRAU,
|
||||
.exptime = 0,
|
||||
.bunchid = 0x1234567898765431L,
|
||||
.timestamp = 0xABCDEF0000FEDCBAL,
|
||||
.debug = 0,
|
||||
.eth_error = (user % 2 == 1),
|
||||
.len_error = (adjust_axis != 0),
|
||||
.generator_slot = NoGeneratorSlot
|
||||
});
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::CreateJFPackets(const DiffractionExperiment &experiment, uint64_t frame_number_0,
|
||||
uint64_t frames, uint32_t module_number, const uint16_t *data) {
|
||||
for (uint64_t i = 0; i < frames; i++) {
|
||||
for (int j = 0; j < 128; j++)
|
||||
CreateJFPacket(experiment, frame_number_0 + i, j, module_number, nullptr, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::CreateEIGERPacket(const DiffractionExperiment &experiment, uint64_t frame_number,
|
||||
uint32_t eth_packet, uint32_t module_number, uint32_t col,
|
||||
uint32_t row, const uint16_t *data) {
|
||||
AddPacket(Packet{
|
||||
.frame_number = frame_number,
|
||||
.packet_number = eth_packet % 128,
|
||||
.udp_port = static_cast<uint16_t>(2 * module_number + row),
|
||||
.column = static_cast<uint16_t>(col % 2),
|
||||
.detector_type = SLS_DETECTOR_TYPE_EIGER,
|
||||
.exptime = 0,
|
||||
.bunchid = 0x1234567898765431L,
|
||||
.timestamp = 0xABCDEF0000FEDCBAL,
|
||||
.debug = 0,
|
||||
.generator_slot = NoGeneratorSlot
|
||||
});
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::CreateXfelBunchIDPacket(double pulse_id, uint32_t event_code) {
|
||||
Packet packet{.bunchid_packet = true, .generator_slot = NoGeneratorSlot};
|
||||
memcpy(&packet.bunchid, &pulse_id, sizeof(uint64_t));
|
||||
AddPacket(packet);
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::CreateFinalPacket(const DiffractionExperiment &experiment) {
|
||||
CreateJFPacket(experiment, UINT64_MAX, 0, 0, nullptr, false);
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::HW_ReadActionRegister(DataCollectionConfig *job) {
|
||||
memcpy(job, &cfg, sizeof(DataCollectionConfig));
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::HW_WriteActionRegister(const DataCollectionConfig *job) {
|
||||
memcpy(&cfg, job, sizeof(DataCollectionConfig));
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::FPGA_StartAction(const DiffractionExperiment &experiment) {
|
||||
if (action_thread.joinable())
|
||||
action_thread.join();
|
||||
|
||||
run_counter += 1;
|
||||
idle = false;
|
||||
action_thread = std::thread(&MockAcquisitionDevice::DataCollectionThread, this);
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::FPGA_EndAction() {
|
||||
if (action_thread.joinable())
|
||||
action_thread.join();
|
||||
if (frame_generator_result != 0)
|
||||
throw JFJochException(JFJochExceptionCategory::AcquisitionDeviceError,
|
||||
"Internal frame generator refused its configuration, error code "
|
||||
+ std::to_string(frame_generator_result));
|
||||
}
|
||||
|
||||
bool MockAcquisitionDevice::HW_IsIdle() const {
|
||||
return idle;
|
||||
}
|
||||
|
||||
bool MockAcquisitionDevice::HW_ReadMailbox(uint32_t *values) {
|
||||
return completions.Get(*values);
|
||||
}
|
||||
|
||||
bool MockAcquisitionDevice::HW_SendWorkRequest(uint32_t handle) {
|
||||
work_requests.Put(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::Cancel() {
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
// The mock does not process data: of what the host loads into the card only the frames of the internal
|
||||
// generator are kept
|
||||
void MockAcquisitionDevice::HW_LoadCalibration(const LoadCalibrationConfig &config) {
|
||||
const DeviceOutput *input = buffer_device[config.handle];
|
||||
if (input->module_statistics.load_calibration_destination != LOAD_CALIBRATION_DEST_FRAME_GEN)
|
||||
return;
|
||||
auto &frame = generator_frames.at(input->module_statistics.module_number);
|
||||
frame.resize(RAW_MODULE_SIZE);
|
||||
memcpy(frame.data(), input->pixels, RAW_MODULE_SIZE * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) {}
|
||||
|
||||
void MockAcquisitionDevice::HW_RunInternalGenerator(const FrameGeneratorConfig &config) {
|
||||
frame_generator_result = 0;
|
||||
frame_generator_future = std::async(std::launch::async, [this, config] {
|
||||
frame_generator_result = FrameGenerator(config);
|
||||
// A generator that refused its configuration sends no frame: the data collection ends instead of waiting
|
||||
if (frame_generator_result != 0)
|
||||
cancel = true;
|
||||
});
|
||||
}
|
||||
|
||||
int MockAcquisitionDevice::FrameGenerator(FrameGeneratorConfig config) {
|
||||
// frame_generator.cpp: its checks and return codes, then packet headers only
|
||||
if ((config.modules > MAX_MODULES_FPGA) || (config.modules == 0))
|
||||
return 1;
|
||||
if ((config.detector_type != SLS_DETECTOR_TYPE_EIGER) && (config.detector_type != SLS_DETECTOR_TYPE_JUNGFRAU))
|
||||
return 2;
|
||||
if ((config.detector_type == SLS_DETECTOR_TYPE_EIGER)
|
||||
&& (config.eiger_bit_depth != 8) && (config.eiger_bit_depth != 16) && (config.eiger_bit_depth != 32))
|
||||
return 2;
|
||||
if (config.frames == 0)
|
||||
return 0;
|
||||
// The frames for the generator have to fit in the card memory
|
||||
uint32_t module_slots = config.modules * (config.images_in_memory + 1);
|
||||
if ((config.detector_type == SLS_DETECTOR_TYPE_EIGER) && (config.eiger_bit_depth == 32))
|
||||
module_slots *= 2;
|
||||
if (module_slots >= internal_generator_module_frames)
|
||||
return 3;
|
||||
|
||||
double pulse_id = config.pulse_id;
|
||||
uint16_t data_stream_port = (config.data_stream & UINT8_MAX) << 8;
|
||||
|
||||
// The packets wait until the data collection takes them - only a limited number of them
|
||||
auto send = [this] (const Packet &packet) {
|
||||
while (!cancel && !stop_frame_generator) {
|
||||
{
|
||||
std::unique_lock ul(packets_mutex);
|
||||
if (packets.size() < 16384) {
|
||||
packets.push_back(packet);
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||
}
|
||||
};
|
||||
|
||||
// One packet with TUSER = 1, to reset the network cores on the way - it is dropped as an Ethernet error
|
||||
send(Packet{.frame_number = 1, .udp_port = data_stream_port, .detector_type = SLS_DETECTOR_TYPE_JUNGFRAU,
|
||||
.eth_error = true, .generator_slot = NoGeneratorSlot});
|
||||
|
||||
uint32_t frame_cell = 0;
|
||||
for (uint32_t f = 0; f < config.frames; f++) {
|
||||
if (cancel || stop_frame_generator)
|
||||
break;
|
||||
uint64_t bunchid;
|
||||
memcpy(&bunchid, &pulse_id, sizeof(uint64_t));
|
||||
|
||||
for (uint32_t m = 0; m < config.modules; m++) {
|
||||
if (config.detector_type == SLS_DETECTOR_TYPE_JUNGFRAU) {
|
||||
for (uint32_t p = 0; p < 128; p++)
|
||||
send(Packet{
|
||||
.frame_number = f + 1,
|
||||
.packet_number = p,
|
||||
.udp_port = static_cast<uint16_t>(data_stream_port | (2 * m)),
|
||||
.column = 0,
|
||||
.detector_type = SLS_DETECTOR_TYPE_JUNGFRAU,
|
||||
.exptime = config.exptime,
|
||||
.bunchid = bunchid,
|
||||
.timestamp = config.exptime * f,
|
||||
.debug = config.debug,
|
||||
.generator_slot = frame_cell * config.modules + m
|
||||
});
|
||||
} else {
|
||||
uint32_t bit_depth = config.eiger_bit_depth;
|
||||
for (uint32_t p = 0; p < 16 * bit_depth; p++) {
|
||||
uint32_t half_module = (p >= 8 * bit_depth) ? 1 : 0;
|
||||
send(Packet{
|
||||
.frame_number = f + 1,
|
||||
.packet_number = (p / 2) % (4 * bit_depth),
|
||||
.udp_port = static_cast<uint16_t>(data_stream_port | (2 * m + half_module)),
|
||||
.column = static_cast<uint16_t>(p % 2),
|
||||
.detector_type = SLS_DETECTOR_TYPE_EIGER,
|
||||
.exptime = config.exptime,
|
||||
.bunchid = 0,
|
||||
.timestamp = config.exptime * f,
|
||||
.debug = config.debug,
|
||||
.generator_slot = (bit_depth == 32 ? 2 : 1) * (frame_cell * config.modules + m)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
pulse_id += 1.0;
|
||||
frame_cell = (frame_cell == config.images_in_memory) ? 0 : frame_cell + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::DataCollectionThread() {
|
||||
cancel = false;
|
||||
stop_frame_generator = false;
|
||||
|
||||
for (auto &c: collected_modules)
|
||||
c = ModuleCompletion{.frame_number = UINT64_MAX};
|
||||
for (int m = 0; m < MAX_MODULES_FPGA; m++) {
|
||||
summation_mask[m].assign(MAX_FPGA_SUMMATION, false);
|
||||
summation_count[m] = 0;
|
||||
summation_frame_prefix[m] = 0;
|
||||
}
|
||||
frames_in_group = 0;
|
||||
handle_to_complete = HANDLE_START;
|
||||
|
||||
uint32_t data_collection_id = (cfg.mode >> 16) & UINT16_MAX;
|
||||
|
||||
// host_writer.cpp: work requests left from the previous data collection are returned unused
|
||||
uint32_t handle;
|
||||
while (work_requests.Get(handle))
|
||||
completions.Put((DATA_COLLECTION_ID_PURGE << 16) | handle);
|
||||
completions.Put((data_collection_id << 16) | HANDLE_START);
|
||||
|
||||
// data_collection_fsm.cpp: cancel is checked between packets
|
||||
while (!cancel) {
|
||||
Packet packet;
|
||||
bool received = false;
|
||||
{
|
||||
std::unique_lock ul(packets_mutex);
|
||||
if (!packets.empty()) {
|
||||
packet = packets.front();
|
||||
packets.pop_front();
|
||||
received = true;
|
||||
}
|
||||
}
|
||||
if (!received)
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||
else if (!ReceivePacket(packet))
|
||||
break;
|
||||
}
|
||||
|
||||
EndDataCollection();
|
||||
|
||||
// Packets after the end of the data collection are dropped
|
||||
stop_frame_generator = true;
|
||||
if (frame_generator_future.valid())
|
||||
frame_generator_future.get();
|
||||
{
|
||||
std::unique_lock ul(packets_mutex);
|
||||
packets.clear();
|
||||
}
|
||||
idle = true;
|
||||
}
|
||||
|
||||
bool MockAcquisitionDevice::ReceivePacket(const Packet &packet) {
|
||||
// udp.cpp and sls_detector.cpp
|
||||
udp_packets++;
|
||||
if (packet.bunchid_packet) {
|
||||
current_pulse_id = packet.bunchid;
|
||||
return true;
|
||||
}
|
||||
if (packet.eth_error || packet.len_error)
|
||||
return true;
|
||||
if ((((packet.udp_port >> 8) & 0xF) != (cfg.data_stream & 0xF)) || (packet.frame_number == 0))
|
||||
return true;
|
||||
sls_packets++;
|
||||
|
||||
// data_collection_fsm.cpp: a frame far enough after the last one ends the data collection
|
||||
uint64_t frame_number = packet.frame_number - 1;
|
||||
if (frame_number >= static_cast<uint64_t>(cfg.nframes) - 1 + DELAY_FRAMES_STOP_AND_QUIT)
|
||||
return false;
|
||||
|
||||
// stream512to768.cpp: location of the packet in the module, in units of 32 beats = 1024 pixels
|
||||
uint32_t module = (packet.udp_port >> 1) & 0x1F;
|
||||
uint32_t row = packet.udp_port & 1;
|
||||
uint32_t column = packet.column & 1;
|
||||
uint32_t eth_packet = packet.packet_number & 0x1FF;
|
||||
uint32_t packet_parts;
|
||||
|
||||
if (packet.detector_type == SLS_DETECTOR_TYPE_JUNGFRAU) {
|
||||
packet_parts = 4;
|
||||
eth_packet = (eth_packet % 128) | (row * 64);
|
||||
} else if (cfg.mode & MODE_EIGER_8BIT) {
|
||||
packet_parts = 4;
|
||||
eth_packet = (row ? (64 + (eth_packet % 32) * 2) : (62 - (eth_packet % 32) * 2)) | column;
|
||||
} else if (cfg.mode & MODE_EIGER_32BIT) {
|
||||
packet_parts = 1;
|
||||
uint32_t pos_of_4_line = (eth_packet % 128) / 2;
|
||||
uint32_t pos_within_2_lines = eth_packet % 2;
|
||||
eth_packet = (row ? (256 + pos_of_4_line * 4) : (252 - pos_of_4_line * 4)) | (2 * column) | pos_within_2_lines;
|
||||
} else {
|
||||
packet_parts = 2;
|
||||
eth_packet = (row ? (128 + (eth_packet % 64) * 2) : (126 - (eth_packet % 64) * 2)) | column;
|
||||
}
|
||||
|
||||
// save_to_hbm.cpp: a module is complete only when the next frame of the same parity arrives
|
||||
// for that module, or at the end of the data collection
|
||||
ModuleCompletion &c = collected_modules[module * 2 + frame_number % 2];
|
||||
if (c.frame_number != frame_number) {
|
||||
if (!MaskEmpty(c.packet_mask))
|
||||
SendCompletion(c);
|
||||
c = ModuleCompletion{
|
||||
.frame_number = frame_number,
|
||||
.exptime = packet.exptime,
|
||||
.timestamp = packet.timestamp,
|
||||
.bunchid = packet.bunchid,
|
||||
.debug = packet.debug,
|
||||
.module = module,
|
||||
.detector_type = packet.detector_type,
|
||||
.generator_slot = packet.generator_slot
|
||||
};
|
||||
}
|
||||
for (uint32_t i = eth_packet * packet_parts; i < (eth_packet + 1) * packet_parts; i++)
|
||||
c.packet_mask[i / 64] |= (1LU << (i % 64));
|
||||
c.packet_count += packet_parts;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::SendCompletion(const ModuleCompletion &c) {
|
||||
// frame_summation_reorder_compl.cpp: with summation, frames are grouped per module and only complete
|
||||
// groups are written
|
||||
uint32_t sum = cfg.nsummation & UINT8_MAX;
|
||||
if (sum == 0) {
|
||||
LoadModule(c);
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t frame_prefix = c.frame_number / (sum + 1);
|
||||
uint32_t frame_loc = c.frame_number % (sum + 1);
|
||||
uint32_t m = c.module;
|
||||
|
||||
if (frame_prefix > summation_frame_prefix[m]) {
|
||||
SendSummationGroup(m);
|
||||
summation_mask[m].assign(MAX_FPGA_SUMMATION, false);
|
||||
summation_completions[m * MAX_FPGA_SUMMATION + frame_loc] = c;
|
||||
summation_mask[m][frame_loc] = true;
|
||||
summation_count[m] = 1;
|
||||
summation_frame_prefix[m] = frame_prefix;
|
||||
} else if (frame_prefix == summation_frame_prefix[m]) {
|
||||
summation_completions[m * MAX_FPGA_SUMMATION + frame_loc] = c;
|
||||
summation_mask[m][frame_loc] = true;
|
||||
summation_count[m] += 1;
|
||||
} else {
|
||||
ModuleCompletion late = c;
|
||||
late.ignore = true;
|
||||
LoadModule(late);
|
||||
}
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::SendSummationGroup(uint32_t m) {
|
||||
uint32_t sum = cfg.nsummation & UINT8_MAX;
|
||||
for (int i = 0; i <= sum; i++) {
|
||||
if (summation_mask[m][i]) {
|
||||
ModuleCompletion c = summation_completions[m * MAX_FPGA_SUMMATION + i];
|
||||
if (summation_count[m] != sum + 1)
|
||||
c.ignore = true;
|
||||
LoadModule(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::LoadModule(const ModuleCompletion &c) {
|
||||
// load_from_hbm.cpp: an incomplete summation group is dropped
|
||||
if (c.ignore)
|
||||
return;
|
||||
|
||||
// frame_summation.cpp: one module per group, with the header of the first frame and the packets
|
||||
// present in all frames
|
||||
uint32_t sum = cfg.nsummation & UINT8_MAX;
|
||||
if (sum == 0) {
|
||||
WriteToHost(c);
|
||||
return;
|
||||
}
|
||||
if (frames_in_group == 0) {
|
||||
group_completion = c;
|
||||
group_completion.frame_number = c.frame_number / (sum + 1);
|
||||
} else {
|
||||
for (int i = 0; i < 8; i++)
|
||||
group_completion.packet_mask[i] &= c.packet_mask[i];
|
||||
group_completion.packet_count += c.packet_count;
|
||||
}
|
||||
frames_in_group++;
|
||||
if (frames_in_group == sum + 1) {
|
||||
frames_in_group = 0;
|
||||
WriteToHost(group_completion);
|
||||
}
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::WriteToHost(const ModuleCompletion &c) {
|
||||
// host_writer.cpp: waits for a host buffer; only when the data collection is cancelled the module
|
||||
// is dropped instead
|
||||
uint32_t handle;
|
||||
while (!work_requests.Get(handle)) {
|
||||
if (cancel)
|
||||
return;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||
}
|
||||
if (handle >= buffer_device.size())
|
||||
return;
|
||||
DeviceOutput *output = buffer_device[handle];
|
||||
|
||||
const DeviceOutput *ready_output = nullptr;
|
||||
if (!outputs.empty()) {
|
||||
auto &image = outputs[c.frame_number % outputs.size()];
|
||||
if (c.module < image.size())
|
||||
ready_output = image[c.module].get();
|
||||
}
|
||||
if (ready_output != nullptr)
|
||||
memcpy(output, ready_output, sizeof(DeviceOutput));
|
||||
else {
|
||||
memset(output, 0, sizeof(DeviceOutput));
|
||||
if ((c.generator_slot != NoGeneratorSlot) && !generator_frames[c.generator_slot].empty())
|
||||
memcpy(output->pixels, generator_frames[c.generator_slot].data(), RAW_MODULE_SIZE * sizeof(uint16_t));
|
||||
}
|
||||
|
||||
ModuleStatistics &stats = output->module_statistics;
|
||||
stats.frame_number = c.frame_number;
|
||||
stats.timestamp = c.timestamp;
|
||||
memcpy(&stats.pulse_id, &c.bunchid, sizeof(uint64_t));
|
||||
stats.detector_type = c.detector_type;
|
||||
stats.exptime = c.exptime;
|
||||
stats.debug = c.debug;
|
||||
stats.pedestal = 0;
|
||||
stats.packet_count = c.packet_count;
|
||||
stats.module_number = c.module;
|
||||
stats.load_calibration_destination = 0;
|
||||
memcpy(stats.packet_mask, c.packet_mask, sizeof(stats.packet_mask));
|
||||
|
||||
// host_writer.cpp: a module is announced to the host only when the next one is written, or at the end
|
||||
uint32_t data_collection_id = (cfg.mode >> 16) & UINT16_MAX;
|
||||
if (handle_to_complete != HANDLE_START)
|
||||
completions.Put((data_collection_id << 16) | handle_to_complete);
|
||||
handle_to_complete = handle;
|
||||
}
|
||||
|
||||
void MockAcquisitionDevice::EndDataCollection() {
|
||||
// save_to_hbm.cpp: modules still being collected, for each module the older frame first
|
||||
for (int m = 0; m < MAX_MODULES_FPGA; m++) {
|
||||
const ModuleCompletion &c0 = collected_modules[2 * m];
|
||||
const ModuleCompletion &c1 = collected_modules[2 * m + 1];
|
||||
const ModuleCompletion &first = (c0.frame_number < c1.frame_number) ? c0 : c1;
|
||||
const ModuleCompletion &second = (c0.frame_number < c1.frame_number) ? c1 : c0;
|
||||
if (!MaskEmpty(first.packet_mask))
|
||||
SendCompletion(first);
|
||||
if (!MaskEmpty(second.packet_mask))
|
||||
SendCompletion(second);
|
||||
}
|
||||
|
||||
// frame_summation_reorder_compl.cpp
|
||||
if ((cfg.nsummation & UINT8_MAX) > 0) {
|
||||
for (int m = 0; m < MAX_MODULES_FPGA; m++)
|
||||
SendSummationGroup(m);
|
||||
}
|
||||
|
||||
// host_writer.cpp
|
||||
uint32_t data_collection_id = (cfg.mode >> 16) & UINT16_MAX;
|
||||
if (handle_to_complete != HANDLE_START)
|
||||
completions.Put((data_collection_id << 16) | handle_to_complete);
|
||||
completions.Put((data_collection_id << 16) | HANDLE_END);
|
||||
}
|
||||
|
||||
DataCollectionStatus MockAcquisitionDevice::GetDataCollectionStatus() const {
|
||||
DataCollectionStatus status{};
|
||||
|
||||
uint64_t pulse_id_u64 = current_pulse_id;
|
||||
double pulse_id;
|
||||
memcpy(&pulse_id, &pulse_id_u64, sizeof(double));
|
||||
|
||||
status.ctrl_reg = idle ? (1 << 4) : 0;
|
||||
status.max_modules = MAX_MODULES_FPGA;
|
||||
status.hbm_size_bytes = CardMemoryBytes;
|
||||
status.run_counter = run_counter;
|
||||
status.current_pulseid = pulse_id;
|
||||
status.packets_udp = udp_packets;
|
||||
status.packets_sls = sls_packets;
|
||||
return status;
|
||||
}
|
||||
|
||||
DeviceStatus MockAcquisitionDevice::GetDeviceStatus() const {
|
||||
DeviceStatus status{};
|
||||
|
||||
strncpy(status.serial_number, "MOCK1", sizeof(status.serial_number));
|
||||
strncpy(status.device_number, "Mock device", sizeof(status.device_number));
|
||||
status.fpga_default_mac_addr = mac_addr;
|
||||
status.eth_link_count = 1;
|
||||
status.eth_link_status = 1;
|
||||
status.packets_sls = sls_packets;
|
||||
status.packets_udp = udp_packets;
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <atomic>
|
||||
|
||||
#include "FPGAAcquisitionDevice.h"
|
||||
|
||||
// Behavioural mock of the FPGA card, for tests and for the broker without hardware. The card is a black
|
||||
// box: the mock computes nothing (no conversion, summation, spot finding, integration or ROI), it
|
||||
// reproduces what the host sees of the card - which module is written to which host buffer and when, the
|
||||
// order of completions, packet counts and masks, frames that are missing or late, summation groups,
|
||||
// counters, the end of the data collection, cancel and the internal frame generator with its refusals.
|
||||
//
|
||||
// The packets are given with CreateJFPacket() etc., or come from the internal frame generator; their
|
||||
// pixel content is ignored. What the card writes for a module - pixels, spot finder, integration, ADU
|
||||
// histogram, ROI and pixel statistics - is given ready-made with SetOutput(): the module written for
|
||||
// frame (after summation) F and module M is the output set for image F % (number of images set) and M.
|
||||
// Without one, the pixels are the frame the internal generator sent for it (as loaded with
|
||||
// SetInternalGeneratorFrame(), 16-bit, not reordered), or zeros for a packet made by a test, and every
|
||||
// result is zero. The header part of ModuleStatistics (frame number, timestamp, pulse ID, exposure time,
|
||||
// debug, detector type, module number, packet count and mask) is filled by the mock from the packets.
|
||||
//
|
||||
// Any number of these devices can run at the same time.
|
||||
class MockAcquisitionDevice : public FPGAAcquisitionDevice {
|
||||
struct alignas(4096) FrameBuffer { uint8_t data[FPGA_BUFFER_LOCATION_SIZE]; };
|
||||
std::vector<std::unique_ptr<FrameBuffer>> buffers;
|
||||
|
||||
// Header of one UDP packet, as the network cores of the card see it
|
||||
struct Packet {
|
||||
uint64_t frame_number; // as in the detector header, i.e. counted from one
|
||||
uint32_t packet_number;
|
||||
uint16_t udp_port;
|
||||
uint16_t column;
|
||||
uint8_t detector_type;
|
||||
uint32_t exptime;
|
||||
uint64_t bunchid;
|
||||
uint64_t timestamp;
|
||||
uint32_t debug;
|
||||
bool eth_error;
|
||||
bool len_error;
|
||||
bool bunchid_packet;
|
||||
uint32_t generator_slot; // frame of the internal generator the packet carries, NoGeneratorSlot if none
|
||||
};
|
||||
static constexpr uint32_t NoGeneratorSlot = UINT32_MAX;
|
||||
|
||||
// axis_completion in fpga/hls/hls_jfjoch.h
|
||||
struct ModuleCompletion {
|
||||
uint64_t packet_mask[8];
|
||||
uint64_t frame_number;
|
||||
uint64_t exptime;
|
||||
uint64_t timestamp;
|
||||
uint64_t bunchid;
|
||||
uint32_t debug;
|
||||
uint16_t packet_count;
|
||||
uint32_t module;
|
||||
uint32_t detector_type;
|
||||
bool ignore;
|
||||
uint32_t generator_slot;
|
||||
};
|
||||
|
||||
std::vector<std::vector<std::unique_ptr<DeviceOutput>>> outputs;
|
||||
// The frames of the internal generator, by slot (module frame of the card memory)
|
||||
std::vector<std::vector<uint16_t>> generator_frames;
|
||||
|
||||
std::mutex packets_mutex;
|
||||
std::deque<Packet> packets;
|
||||
|
||||
ThreadSafeFIFO<uint32_t> work_requests;
|
||||
ThreadSafeFIFO<uint32_t> completions;
|
||||
|
||||
DataCollectionConfig cfg{};
|
||||
|
||||
// save_to_hbm.cpp: module being collected, for each module and frame parity
|
||||
std::vector<ModuleCompletion> collected_modules;
|
||||
|
||||
// frame_summation_reorder_compl.cpp and frame_summation.cpp
|
||||
std::vector<ModuleCompletion> summation_completions;
|
||||
std::vector<std::vector<bool>> summation_mask;
|
||||
std::vector<uint32_t> summation_count;
|
||||
std::vector<uint64_t> summation_frame_prefix;
|
||||
uint32_t frames_in_group = 0;
|
||||
ModuleCompletion group_completion{};
|
||||
|
||||
// host_writer.cpp
|
||||
uint32_t handle_to_complete = HANDLE_START;
|
||||
|
||||
std::thread action_thread;
|
||||
std::future<void> frame_generator_future;
|
||||
std::atomic<bool> cancel = false;
|
||||
std::atomic<bool> stop_frame_generator = false;
|
||||
std::atomic<int> frame_generator_result = 0;
|
||||
std::atomic<bool> idle = true;
|
||||
|
||||
uint32_t run_counter = 0;
|
||||
std::atomic<uint64_t> current_pulse_id = UINT64_MAX;
|
||||
std::atomic<uint64_t> udp_packets = 0;
|
||||
std::atomic<uint64_t> sls_packets = 0;
|
||||
|
||||
void HW_ReadActionRegister(DataCollectionConfig *job) override;
|
||||
void HW_WriteActionRegister(const DataCollectionConfig *job) override;
|
||||
void FPGA_StartAction(const DiffractionExperiment &experiment) override;
|
||||
void FPGA_EndAction() override;
|
||||
bool HW_IsIdle() const override;
|
||||
bool HW_ReadMailbox(uint32_t *values) override;
|
||||
bool HW_SendWorkRequest(uint32_t handle) override;
|
||||
void HW_LoadCalibration(const LoadCalibrationConfig &config) override;
|
||||
void HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) override;
|
||||
void HW_RunInternalGenerator(const FrameGeneratorConfig &config) override;
|
||||
|
||||
void AddPacket(const Packet &packet);
|
||||
// frame_generator.cpp: its return code, 0 when it ran
|
||||
int FrameGenerator(FrameGeneratorConfig config);
|
||||
|
||||
void DataCollectionThread();
|
||||
bool ReceivePacket(const Packet &packet);
|
||||
void SendCompletion(const ModuleCompletion &c);
|
||||
void SendSummationGroup(uint32_t module);
|
||||
void LoadModule(const ModuleCompletion &c);
|
||||
void WriteToHost(const ModuleCompletion &c);
|
||||
void EndDataCollection();
|
||||
public:
|
||||
MockAcquisitionDevice(uint16_t data_stream, size_t in_frame_buffer_size_modules);
|
||||
~MockAcquisitionDevice() override;
|
||||
|
||||
void SetOutput(uint64_t image, uint32_t module_number, const DeviceOutput &output);
|
||||
|
||||
void CreateJFPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet,
|
||||
uint32_t module_number, const uint16_t *data, int8_t adjust_axis = 0, uint8_t user = 0);
|
||||
void CreateJFPackets(const DiffractionExperiment& experiment, uint64_t frame_number_0, uint64_t frames,
|
||||
uint32_t module_number, const uint16_t *data);
|
||||
void CreateEIGERPacket(const DiffractionExperiment& experiment, uint64_t frame_number, uint32_t eth_packet,
|
||||
uint32_t module_number, uint32_t col, uint32_t row,
|
||||
const uint16_t *data);
|
||||
void CreateXfelBunchIDPacket(double bunchid, uint32_t event_code);
|
||||
void CreateFinalPacket(const DiffractionExperiment& experiment);
|
||||
DataCollectionStatus GetDataCollectionStatus() const override;
|
||||
void Cancel() override;
|
||||
DeviceStatus GetDeviceStatus() const override;
|
||||
};
|
||||
@@ -252,7 +252,7 @@ std::unique_ptr<ImagePusher> ParseImagePusher(const org::openapitools::server::m
|
||||
void ParseAcquisitionDeviceGroup(const org::openapitools::server::model::Jfjoch_settings &input,
|
||||
AcquisitionDeviceGroup &aq_devices) {
|
||||
if (!input.pcieIsSet())
|
||||
aq_devices.AddHLSDevice(256);
|
||||
aq_devices.AddMockDevice(256);
|
||||
else for (auto &p: input.getPcie()) {
|
||||
std::optional<uint32_t> ipv4_addr = {};
|
||||
if (p.ipv4IsSet())
|
||||
|
||||
@@ -429,9 +429,11 @@ For development, it is possible to set up a local installation of Jungfraujoch.
|
||||
This will work without FPGA installed in the computer and allows testing the Jungfraujoch software layer, including
|
||||
ZeroMQ streaming and file writing.
|
||||
|
||||
The workflow simulates FPGA behavior, by running high-level synthesis code on the CPU - the performance is therefore
|
||||
very low, as fixed-point calculations have a large performance penalty on the CPU. In the CPU simulation mode, one can simulate
|
||||
using only a single FPGA device.
|
||||
Without a `pcie` entry in the configuration, the broker runs on a mock of the FPGA card (`MockAcquisitionDevice`):
|
||||
it behaves like the card towards the host - frames, completions, counters, start/stop/cancel, the internal frame
|
||||
generator - but computes nothing. The images streamed and written are the ones uploaded as the internal generator's
|
||||
images, unconverted; the card's spot finding, ROI and azimuthal results are zero in this mode (with rugnux live on,
|
||||
the GPU analysis finds its own spots).
|
||||
|
||||
To run the test:
|
||||
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ ELSE()
|
||||
MESSAGE(STATUS "Xilinx HLS compiler not found")
|
||||
ENDIF()
|
||||
|
||||
ADD_SUBDIRECTORY(hls)
|
||||
ADD_SUBDIRECTORY(hls_simulation)
|
||||
# The CPU library of the HLS kernels is not part of the software build; the firmware targets below build it on demand
|
||||
ADD_SUBDIRECTORY(hls EXCLUDE_FROM_ALL)
|
||||
ADD_SUBDIRECTORY(pcie_driver)
|
||||
ADD_SUBDIRECTORY(host_library)
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
ADD_LIBRARY(JFJochHLSSimulation STATIC
|
||||
HLSDevice.cpp
|
||||
HLSDevice.h
|
||||
hls_cores.h
|
||||
sls_packet.h)
|
||||
|
||||
TARGET_LINK_LIBRARIES(JFJochHLSSimulation JFJochHLSCores)
|
||||
@@ -1,813 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <future>
|
||||
#include <bitset>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "HLSDevice.h"
|
||||
#include "hls_cores.h"
|
||||
#include "datamover_model.h"
|
||||
#include "sls_packet.h"
|
||||
|
||||
struct HLSDeviceImpl {
|
||||
AXI_STREAM din_eth;
|
||||
AXI_STREAM dout_eth;
|
||||
|
||||
constexpr static const size_t hbm_if_count = 32;
|
||||
constexpr static const size_t hbm_if_size = 32 * 1024 * 1024LU;
|
||||
|
||||
std::vector<ap_uint<256>> hbm;
|
||||
|
||||
hls::stream<ap_uint<32> > work_request_stream;
|
||||
hls::stream<ap_uint<32> > completion_stream;
|
||||
|
||||
Datamover<512> datamover_in;
|
||||
Datamover<512> datamover_out;
|
||||
Datamover<256, 4> datamover_in_hbm_0;
|
||||
Datamover<256, 4> datamover_in_hbm_1;
|
||||
Datamover<256, 4> datamover_in_hbm_2;
|
||||
Datamover<256, 4> datamover_out_hbm_0;
|
||||
Datamover<256, 4> datamover_out_hbm_1;
|
||||
Datamover<256, 4> datamover_out_hbm_2;
|
||||
|
||||
ap_uint<1> run_data_collection;
|
||||
ap_uint<1> cancel_data_collection;
|
||||
volatile ap_uint<1> host_writer_idle;
|
||||
std::vector<uint32_t> pixel_mask;
|
||||
|
||||
HLSDeviceImpl()
|
||||
: hbm(hbm_if_size / 32 * hbm_if_count),
|
||||
pixel_mask(MAX_MODULES_FPGA*RAW_MODULE_SIZE/32),
|
||||
datamover_in(Direction::Input, nullptr),
|
||||
datamover_out(Direction::Output, nullptr),
|
||||
datamover_out_hbm_0(Direction::Output, (char *) hbm.data()),
|
||||
datamover_out_hbm_1(Direction::Output, (char *) hbm.data()),
|
||||
datamover_out_hbm_2(Direction::Output, (char *) hbm.data()),
|
||||
datamover_in_hbm_0(Direction::Input, (char *) hbm.data()),
|
||||
datamover_in_hbm_1(Direction::Input, (char *) hbm.data()),
|
||||
datamover_in_hbm_2(Direction::Input, (char *) hbm.data()) {}
|
||||
};
|
||||
|
||||
HLSDevice::HLSDevice(std::vector<DeviceOutput *> &buffer_device) : idle(true), dma_address_table(65536) {
|
||||
impl_ = std::make_unique<HLSDeviceImpl>();
|
||||
|
||||
auto in_mem_location32 = (uint32_t *) dma_address_table.data();
|
||||
|
||||
for (int i = 0; i < buffer_device.size(); i++) {
|
||||
in_mem_location32[2 * i ] = ((uint64_t) buffer_device[i]) & UINT32_MAX;
|
||||
in_mem_location32[2 * i + 1] = ((uint64_t) buffer_device[i]) >> 32;
|
||||
}
|
||||
}
|
||||
|
||||
HLSDevice::~HLSDevice() {
|
||||
if (action_thread.joinable())
|
||||
action_thread.join();
|
||||
impl_.reset();
|
||||
}
|
||||
|
||||
void HLSDevice::CreateFinalPacket() {
|
||||
CreateJFPacket(UINT64_MAX, 0, 0, nullptr, false);
|
||||
}
|
||||
|
||||
void HLSDevice::SendPacket(char *buffer, int len, uint8_t user) {
|
||||
auto obuff = (ap_uint<512> *)buffer;
|
||||
|
||||
for (int i = 0; i < (len + 63) / 64; i++) {
|
||||
packet_512_t packet_in;
|
||||
if (i == (len + 63) / 64 - 1) packet_in.last = 1;
|
||||
else packet_in.last = 0;
|
||||
packet_in.keep = 0xFFFFFFFFFFFFFFFF;
|
||||
packet_in.user = user;
|
||||
packet_in.data = obuff[i];
|
||||
impl_->din_eth.write(packet_in);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma GCC push_options
|
||||
#pragma GCC optimize ("O0")
|
||||
|
||||
uint16_t checksum(const uint16_t *addr, size_t count) {
|
||||
/* Compute Internet Checksum for "count" bytes
|
||||
* beginning at location "addr".
|
||||
*/
|
||||
uint64_t sum = 0;
|
||||
|
||||
for (int i = 0; i < count / 2; i++)
|
||||
sum += addr[i];
|
||||
|
||||
/* Add left-over byte, if any */
|
||||
if (count % 2 == 1)
|
||||
sum += ((uint8_t *) addr)[count / 2];
|
||||
|
||||
/* Fold 32-bit sum to 16 bits */
|
||||
while (sum>>16)
|
||||
sum = (sum & 0xffff) + (sum >> 16);
|
||||
|
||||
return ~sum;
|
||||
}
|
||||
|
||||
void HLSDevice::CreateJFPacket(uint64_t frame_number, uint32_t eth_packet,
|
||||
uint32_t module_number, const uint16_t *data, int8_t adjust_axis, uint8_t user) {
|
||||
std::vector<char> buff(256*64);
|
||||
|
||||
auto packet = (jf_raw_packet *)buff.data();
|
||||
|
||||
packet->ether_type = htons(0x0800);
|
||||
packet->sour_mac[0] = 0x00; // module 0
|
||||
|
||||
uint64_t tmp_mac = mac_addr;
|
||||
for (int i = 0; i < 6; i++)
|
||||
packet->dest_mac[i] = (tmp_mac >> (8*i)) % 256;
|
||||
|
||||
uint32_t half_module = ((eth_packet >= 64) ? 1 : 0);
|
||||
|
||||
packet->ipv4_header_h = htons(0x4500); // Big endian in IP header!
|
||||
packet->ipv4_header_total_length = htons(8268); // Big endian in IP header!
|
||||
packet->ipv4_header_dest_ip = ipv4_addr;
|
||||
packet->ipv4_header_sour_ip = 0;
|
||||
packet->ipv4_header_ttl_protocol = htons(0x0011);
|
||||
packet->ipv4_header_checksum = checksum( (uint16_t *) (buff.data() + 14), 20); // checksum is already in network order
|
||||
|
||||
packet->udp_dest_port = htons(2 * module_number + half_module);
|
||||
packet->udp_sour_port = htons(0xDFAC);
|
||||
packet->udp_length = htons(8248);
|
||||
|
||||
// JF headers are little endian
|
||||
packet->jf.detectortype = SLS_DETECTOR_TYPE_JUNGFRAU;
|
||||
packet->jf.timestamp = 0xABCDEF0000FEDCBAL;
|
||||
packet->jf.bunchid = 0x1234567898765431L;
|
||||
packet->jf.row = half_module;
|
||||
packet->jf.column = 0;
|
||||
packet->jf.framenum = frame_number;
|
||||
packet->jf.packetnum = eth_packet % 64;
|
||||
if (data != nullptr) {
|
||||
for (int i = 0; i < 4096; i++)
|
||||
packet->jf.data[i] = data[i];
|
||||
}
|
||||
packet->udp_checksum = htons(checksum( (uint16_t *) (buff.data()+42), 8192+48));
|
||||
|
||||
SendPacket(buff.data(), (130+adjust_axis)*64, user);
|
||||
}
|
||||
|
||||
void HLSDevice::CreateEIGERPacket(uint64_t frame_number,
|
||||
uint32_t eth_packet, uint32_t module_number, uint32_t col, uint32_t row,
|
||||
const uint16_t *data) {
|
||||
std::vector<char> buff(256*64);
|
||||
|
||||
auto packet = (eiger_raw_packet *)buff.data();
|
||||
|
||||
packet->ether_type = htons(0x0800);
|
||||
packet->sour_mac[0] = 0x00; // module 0
|
||||
|
||||
uint64_t tmp_mac = mac_addr;
|
||||
for (int i = 0; i < 6; i++)
|
||||
packet->dest_mac[i] = (tmp_mac >> (8*i)) % 256;
|
||||
|
||||
packet->ipv4_header_h = htons(0x4500); // Big endian in IP header!
|
||||
packet->ipv4_header_total_length = htons(4172); // Big endian in IP header!
|
||||
packet->ipv4_header_dest_ip = ipv4_addr;
|
||||
packet->ipv4_header_sour_ip = 0x0;
|
||||
|
||||
packet->ipv4_header_ttl_protocol = htons(0x0011);
|
||||
packet->ipv4_header_checksum = checksum( (uint16_t *) (buff.data() + 14), 20); // checksum is already in network order
|
||||
|
||||
packet->udp_dest_port = htons(2 * module_number + row);
|
||||
packet->udp_sour_port = htons(0xDFAC);
|
||||
packet->udp_length = htons(4152);
|
||||
|
||||
// JF headers are little endian
|
||||
packet->eiger.detectortype = SLS_DETECTOR_TYPE_EIGER;
|
||||
packet->eiger.timestamp = 0xABCDEF0000FEDCBAL;
|
||||
packet->eiger.bunchid = 0x1234567898765431L;
|
||||
packet->eiger.row = (row % 2);
|
||||
packet->eiger.column = col % 2;
|
||||
packet->eiger.framenum = frame_number;
|
||||
packet->eiger.packetnum = eth_packet % 128;
|
||||
if (data != nullptr) {
|
||||
for (int i = 0; i < 2048; i++)
|
||||
packet->eiger.data[i] = data[i];
|
||||
}
|
||||
packet->udp_checksum = htons(checksum( (uint16_t *) (buff.data()+42), 4096+48));
|
||||
|
||||
SendPacket(buff.data(), 66*64, 0);
|
||||
}
|
||||
|
||||
#pragma GCC pop_options
|
||||
|
||||
void HLSDevice::HW_ReadActionRegister(DataCollectionConfig *job) {
|
||||
memcpy(job, &cfg, sizeof(DataCollectionConfig));
|
||||
}
|
||||
|
||||
void HLSDevice::HW_WriteActionRegister(const DataCollectionConfig *job) {
|
||||
memcpy(&cfg, job, sizeof(DataCollectionConfig));
|
||||
}
|
||||
|
||||
void HLSDevice::FPGA_StartAction() {
|
||||
if (action_thread.joinable())
|
||||
action_thread.join();
|
||||
|
||||
run_counter += 1;
|
||||
idle = false;
|
||||
|
||||
impl_->datamover_out.ClearCompletedDescriptors();
|
||||
|
||||
action_thread = std::thread(&HLSDevice::HLSMainThread, this );
|
||||
}
|
||||
|
||||
void HLSDevice::FrameGeneratorFuture(FrameGeneratorConfig config) {
|
||||
frame_generator_result = frame_generator(impl_->din_eth,
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm_if_size,
|
||||
mac_addr,
|
||||
ipv4_addr,
|
||||
impl_->cancel_data_collection,
|
||||
config);
|
||||
// A generator that refused its configuration sends no frame: the data collection ends instead of waiting for them
|
||||
if (frame_generator_result != 0)
|
||||
impl_->cancel_data_collection = 1;
|
||||
}
|
||||
|
||||
int HLSDevice::GetFrameGeneratorResult() const {
|
||||
return frame_generator_result;
|
||||
}
|
||||
|
||||
void HLSDevice::HW_RunInternalGenerator(const FrameGeneratorConfig &config) {
|
||||
frame_generator_result = 0;
|
||||
frame_generator_future = std::async(std::launch::async, &HLSDevice::FrameGeneratorFuture, this, config);
|
||||
}
|
||||
|
||||
void HLSDevice::FPGA_EndAction() {
|
||||
if (action_thread.joinable())
|
||||
action_thread.join();
|
||||
}
|
||||
|
||||
bool HLSDevice::HW_ReadMailbox(uint32_t *values) {
|
||||
std::unique_lock ul(completion_mutex);
|
||||
|
||||
ap_uint<32> tmp;
|
||||
bool ret = impl_->completion_stream.read_nb(tmp);
|
||||
values[0] = tmp;
|
||||
// equivalent to driver functionality
|
||||
if (ret) {
|
||||
uint32_t data_collection_id = (values[0] >> 16) & 0xFFFF;
|
||||
uint32_t handle = values[0] & 0xFFFF;
|
||||
if (handle == HANDLE_START)
|
||||
completion_count = 0;
|
||||
else if ((handle != HANDLE_END) && (data_collection_id != DATA_COLLECTION_ID_PURGE)) {
|
||||
completion_count++;
|
||||
while (completion_count * DMA_DESCRIPTORS_PER_MODULE > impl_->datamover_out.GetCompletedDescriptors())
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void HLSDevice::Cancel() {
|
||||
impl_->cancel_data_collection = 1;
|
||||
}
|
||||
|
||||
bool HLSDevice::HW_IsIdle() const {
|
||||
return idle && impl_->datamover_out.IsIdle();
|
||||
}
|
||||
|
||||
|
||||
bool HLSDevice::HW_SendWorkRequest(uint32_t handle) {
|
||||
impl_->work_request_stream.write(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline uint32_t float2uint(float f) {
|
||||
float_uint32 fu;
|
||||
fu.f = f;
|
||||
return fu.u;
|
||||
}
|
||||
|
||||
void HLSDevice::HLSMainThread() {
|
||||
ap_uint<1> clear_counters = 0;
|
||||
|
||||
uint64_t packets_processed;
|
||||
|
||||
std::vector<std::thread> hls_cores;
|
||||
|
||||
STREAM_512 ip1("ip1"), udp1("udp1"), udp2("udp2"), icmp1("icmp1"), arp1("arp1"), ptp1("ptp1");
|
||||
|
||||
STREAM_768 stream_768_00("stream_768_00");
|
||||
STREAM_768 stream_768_01("stream_768_01");
|
||||
STREAM_768 stream_768_02("stream_768_02");
|
||||
STREAM_768 stream_768_03("stream_768_03");
|
||||
STREAM_768 stream_768_04("stream_768_04");
|
||||
STREAM_768 stream_768_0("stream_768_0");
|
||||
STREAM_768 stream_768_1("stream_768_1");
|
||||
STREAM_768 stream_768_2("stream_768_2");
|
||||
STREAM_768 stream_768_3("stream_768_3");
|
||||
STREAM_768 stream_768_4("stream_768_4");
|
||||
STREAM_768 stream_768_4a("stream_768_4a");
|
||||
STREAM_768 stream_768_5("stream_768_5");
|
||||
STREAM_768 stream_768_6("stream_768_6");
|
||||
STREAM_768 stream_768_7("stream_768_7");
|
||||
STREAM_768 stream_768_8("stream_768_8");
|
||||
|
||||
STREAM_512 data_0("data_0");
|
||||
STREAM_512 data_1("data_1");
|
||||
hls::stream<ap_axiu<768, 1, 1, 1>, 2> data_2("data_2");
|
||||
STREAM_768 data_3("data_3");
|
||||
STREAM_768 data_4("data_4");
|
||||
STREAM_768 data_5("data_5");
|
||||
STREAM_768 data_6("data_6");
|
||||
STREAM_512 data_7("data_7");
|
||||
STREAM_512 data_8("data_8");
|
||||
STREAM_512 data_9("data_9");
|
||||
STREAM_512 data_10("data_10");
|
||||
STREAM_512 data_12("data_12");
|
||||
STREAM_512 data_13("data_13");
|
||||
|
||||
hls::stream<axis_addr> addr0("addr0");
|
||||
hls::stream<axis_addr> addr1("addr1");
|
||||
hls::stream<axis_addr> addr2("addr2");
|
||||
|
||||
hls::stream<axis_completion> axi_compl[13];
|
||||
|
||||
hls::stream<ap_uint<16>> hbm_handles("hbm_handles");
|
||||
hls::stream<ap_uint<512>> adu_histo_result("adu_histo_result");
|
||||
|
||||
hls::stream<ap_axiu<64,1,1,1>> integration_result_0("integration_result_0");
|
||||
hls::stream<ap_uint<512>> integration_result_1("integration_result_1");
|
||||
|
||||
hls::stream<ap_axiu<32,1,1,1>> spot_finder_result_0("spot_finder_result_0");
|
||||
hls::stream<ap_axiu<32,1,1,1>> spot_finder_result_1("spot_finder_result_1");
|
||||
hls::stream<ap_axiu<32,1,1,1>> spot_finder_result_0a("spot_finder_result_0a");
|
||||
hls::stream<ap_uint<32>> spot_finder_conn_0("spot_finder_conn_0");
|
||||
hls::stream<ap_axiu<32,1,1,1>> spot_finder_result_2("spot_finder_result_2");
|
||||
hls::stream<ap_uint<512>> spot_finder_result_3("spot_finder_result_3");
|
||||
|
||||
hls::stream<ap_uint<512>> roi_calc_result_0("roi_calc_result_0");
|
||||
hls::stream<ap_uint<PIXEL_COUNT_WIDTH>> pixel_count_result_0("pixel_calc_result_0");
|
||||
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata("udp_metadata");
|
||||
|
||||
volatile ap_uint<1> idle_data_collection = 1;
|
||||
ap_uint<1> load_to_hbm_idle;
|
||||
ap_uint<1> save_to_hbm_idle;
|
||||
ap_uint<1> integration_idle;
|
||||
ap_uint<1> stream512to768_idle;
|
||||
ap_uint<1> stream768to512_idle;
|
||||
ap_uint<1> frame_summation_idle;
|
||||
|
||||
volatile bool done = false;
|
||||
volatile bool udp_done = false; // done AND udp_idle
|
||||
volatile bool sls_done = false; // done AND sls_idle
|
||||
|
||||
// Sent gratuitous ARP message
|
||||
arp(arp1, impl_->dout_eth, mac_addr, ipv4_addr, 1);
|
||||
|
||||
volatile rcv_state_t state = RCV_INIT;
|
||||
impl_->run_data_collection = 0;
|
||||
|
||||
// Read state, check if ready to start
|
||||
data_collection_fsm(data_0, data_1,
|
||||
addr0, addr1,
|
||||
impl_->run_data_collection,
|
||||
impl_->cancel_data_collection,
|
||||
idle_data_collection,
|
||||
cfg.mode,
|
||||
float2uint(cfg.energy_kev),
|
||||
cfg.nframes,
|
||||
cfg.nmodules,
|
||||
cfg.nstorage_cells,
|
||||
cfg.nsummation ,
|
||||
cfg.sqrtmult,
|
||||
cfg.pxlthreshold_min,
|
||||
cfg.pxlthreshold_max,
|
||||
state);
|
||||
|
||||
impl_->run_data_collection = 1;
|
||||
impl_->cancel_data_collection = 0;
|
||||
|
||||
if (state != rcv_state_t::RCV_WAIT_FOR_START)
|
||||
throw std::runtime_error("HLS device not ready to receive data");
|
||||
|
||||
// Start data collection
|
||||
data_collection_fsm(data_0, data_1,
|
||||
addr0, addr1,
|
||||
impl_->run_data_collection,
|
||||
impl_->cancel_data_collection,
|
||||
idle_data_collection,
|
||||
cfg.mode,
|
||||
float2uint(cfg.energy_kev),
|
||||
cfg.nframes,
|
||||
cfg.nmodules,
|
||||
cfg.nstorage_cells,
|
||||
cfg.nsummation ,
|
||||
cfg.sqrtmult,
|
||||
cfg.pxlthreshold_min,
|
||||
cfg.pxlthreshold_max,
|
||||
state);
|
||||
|
||||
impl_->run_data_collection = 0;
|
||||
data_collection_fsm(data_0, data_1,
|
||||
addr0, addr1,
|
||||
impl_->run_data_collection,
|
||||
impl_->cancel_data_collection,
|
||||
idle_data_collection,
|
||||
cfg.mode,
|
||||
float2uint(cfg.energy_kev),
|
||||
cfg.nframes,
|
||||
cfg.nmodules,
|
||||
cfg.nstorage_cells,
|
||||
cfg.nsummation,
|
||||
cfg.sqrtmult,
|
||||
cfg.pxlthreshold_min,
|
||||
cfg.pxlthreshold_max,
|
||||
state);
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
while (!udp_done) {
|
||||
if (impl_->din_eth.empty())
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||
else
|
||||
ethernet(impl_->din_eth, ip1, arp1, ptp1,
|
||||
mac_addr, 1, 0, eth_packets, clear_counters);
|
||||
}
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
while (!udp_done) {
|
||||
if (ip1.empty())
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||
else
|
||||
ipv4(ip1, udp1, icmp1, ipv4_addr, 0);
|
||||
}
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
ap_uint<1> udp_idle = 1;
|
||||
while (!done || !udp_idle) {
|
||||
if (udp1.empty())
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(10));
|
||||
else
|
||||
udp(udp1, udp2, udp_metadata, udp_packets, clear_counters, udp_idle);
|
||||
}
|
||||
udp_done = true;
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
ap_uint<1> sls_idle = 1;
|
||||
|
||||
while (!done || !sls_idle) {
|
||||
if (udp2.empty())
|
||||
std::this_thread::sleep_for(std::chrono::microseconds (10));
|
||||
else
|
||||
sls_detector(udp2, udp_metadata, data_0, addr0, sls_packets, udp_eth_err, udp_len_err, current_pulse_id,
|
||||
cfg.data_stream, clear_counters, sls_idle);
|
||||
}
|
||||
sls_done = true;
|
||||
});
|
||||
|
||||
// 1. Parse incoming UDP packets
|
||||
hls_cores.emplace_back([&] {
|
||||
while ((state != RCV_WAIT_FOR_START) || (idle_data_collection.read() == 0) || (!data_0.empty())) {
|
||||
data_collection_fsm(data_0, data_1,
|
||||
addr0, addr1,
|
||||
impl_->run_data_collection,
|
||||
impl_->cancel_data_collection,
|
||||
idle_data_collection,
|
||||
cfg.mode,
|
||||
float2uint(cfg.energy_kev),
|
||||
cfg.nframes,
|
||||
cfg.nmodules,
|
||||
cfg.nstorage_cells,
|
||||
cfg.nsummation,
|
||||
cfg.sqrtmult,
|
||||
cfg.pxlthreshold_min,
|
||||
cfg.pxlthreshold_max,
|
||||
state);
|
||||
}
|
||||
done = true;
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] { stream512to768(data_1, data_2, addr1, addr2, stream512to768_idle);});
|
||||
|
||||
// 2. Cache images in HBM
|
||||
hls_cores.emplace_back([&] { save_to_hbm(addr2, axi_compl[0], hbm_handles,
|
||||
impl_->datamover_out_hbm_0.GetCtrlStream(),
|
||||
impl_->datamover_out_hbm_1.GetCtrlStream(),
|
||||
impl_->datamover_out_hbm_2.GetCtrlStream(),
|
||||
save_to_hbm_idle,
|
||||
impl_->hbm_if_size);});
|
||||
|
||||
hls_cores.emplace_back([&] { save_to_hbm_data(data_2,
|
||||
data_3,
|
||||
impl_->datamover_out_hbm_0.GetDataStream(),
|
||||
impl_->datamover_out_hbm_1.GetDataStream(),
|
||||
impl_->datamover_out_hbm_2.GetDataStream());});
|
||||
|
||||
hls_cores.emplace_back([&] {frame_summation_reorder_compl(data_3, data_4, axi_compl[0], axi_compl[1]);});
|
||||
|
||||
uint32_t ignore_counter = 0;
|
||||
hls_cores.emplace_back([&] { load_from_hbm(data_4, data_5, axi_compl[1], axi_compl[3], hbm_handles,
|
||||
impl_->datamover_in_hbm_0.GetDataStream(),
|
||||
impl_->datamover_in_hbm_1.GetDataStream(),
|
||||
impl_->datamover_in_hbm_2.GetDataStream(),
|
||||
impl_->datamover_in_hbm_0.GetCtrlStream(),
|
||||
impl_->datamover_in_hbm_1.GetCtrlStream(),
|
||||
impl_->datamover_in_hbm_2.GetCtrlStream(),
|
||||
load_to_hbm_idle, ignore_counter,
|
||||
impl_->hbm_if_size);});
|
||||
|
||||
// 3. Calculate histogram of ADU values
|
||||
hls_cores.emplace_back([&] { adu_histo(data_5, stream_768_01, adu_histo_result, axi_compl[3], axi_compl[4]);});
|
||||
|
||||
// 4. Mask missing pixels
|
||||
hls_cores.emplace_back([&] { mask_missing(stream_768_01, stream_768_02, axi_compl[4], axi_compl[5]);});
|
||||
|
||||
// 5. Handle EIGER packets properly
|
||||
hls_cores.emplace_back([&] { eiger_reorder(stream_768_02, stream_768_03, axi_compl[5], axi_compl[6]);});
|
||||
|
||||
// 6. Apply pixel mask
|
||||
hls_cores.emplace_back([&] {
|
||||
pixel_mask(stream_768_03,
|
||||
stream_768_04,
|
||||
impl_->pixel_mask.data(),
|
||||
axi_compl[6],
|
||||
axi_compl[7]);
|
||||
});
|
||||
|
||||
// 7. Apply pedestal & gain corrections
|
||||
hls_cores.emplace_back([&] {
|
||||
jf_conversion(stream_768_04, stream_768_0,
|
||||
axi_compl[7], axi_compl[8],
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm_if_size);
|
||||
});
|
||||
|
||||
// 8. Pixel thresholding
|
||||
hls_cores.emplace_back([&] { pixel_threshold(stream_768_0, stream_768_1);});
|
||||
|
||||
// 9. Frame summation
|
||||
hls_cores.emplace_back([&] { frame_summation(stream_768_1, stream_768_2, axi_compl[8], axi_compl[9], frame_summation_idle);});
|
||||
|
||||
// 10. Integration of pixels
|
||||
hls_cores.emplace_back([&] { integration(stream_768_2, stream_768_3, integration_result_0, axi_compl[9], axi_compl[10],
|
||||
impl_->hbm.data(), impl_->hbm.data(), impl_->hbm.data(), impl_->hbm.data(), integration_idle, impl_->hbm_if_size);});
|
||||
hls_cores.emplace_back([&] { axis_64_to_512(integration_result_0, integration_result_1);});
|
||||
|
||||
// 11. Spot finding
|
||||
ap_uint<32> tmp_snr_threshold = float2uint(spot_finder_parameters.snr_threshold);
|
||||
ap_uint<32> min_d = float2uint(spot_finder_parameters.min_d);
|
||||
ap_uint<32> max_d = float2uint(spot_finder_parameters.max_d);
|
||||
ap_int<32> tmp_count_threshold = spot_finder_parameters.count_threshold;
|
||||
ap_uint<32> min_pix_per_spot = spot_finder_parameters.min_pix_per_spot;
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
spot_finder_mask(stream_768_3,
|
||||
stream_768_4,
|
||||
axi_compl[10],
|
||||
axi_compl[11],
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
min_d,
|
||||
max_d,
|
||||
impl_->hbm_if_size);
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
spot_finder(stream_768_4, stream_768_4a, spot_finder_result_0, tmp_count_threshold, tmp_snr_threshold);
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
while (spot_finder_result_0.read().user == 0);
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
spot_finder(stream_768_4a, stream_768_5, spot_finder_result_0a, tmp_count_threshold, tmp_snr_threshold);
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
spot_finder_connectivity(spot_finder_result_0a,
|
||||
spot_finder_result_1,
|
||||
spot_finder_conn_0);
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
spot_finder_merge(spot_finder_result_1,
|
||||
spot_finder_conn_0,
|
||||
spot_finder_result_2,
|
||||
min_pix_per_spot);
|
||||
});
|
||||
|
||||
hls_cores.emplace_back([&] {
|
||||
axis_32_to_512(spot_finder_result_2, spot_finder_result_3);
|
||||
});
|
||||
|
||||
// 12. ROI calculation
|
||||
hls_cores.emplace_back([&] {
|
||||
roi_calc(stream_768_5,
|
||||
stream_768_6,
|
||||
roi_calc_result_0,
|
||||
axi_compl[11],
|
||||
axi_compl[12],
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm.data(),
|
||||
impl_->hbm_if_size);
|
||||
});
|
||||
|
||||
// 13. Calc pixel statistics
|
||||
hls_cores.emplace_back([&] { pixel_calc(stream_768_6, stream_768_7, pixel_count_result_0); });
|
||||
|
||||
// 14. Pixel sq root
|
||||
hls_cores.emplace_back([&] { pixel_sqrt(stream_768_7,stream_768_8); });
|
||||
|
||||
// 15. Reduce/extend 24-bit stream
|
||||
hls_cores.emplace_back([&] { stream768to512(stream_768_8, data_12, stream768to512_idle);});
|
||||
|
||||
// 16. Prepare data to write to host memory
|
||||
hls_cores.emplace_back([&] {
|
||||
ap_uint<3> state;
|
||||
host_writer(data_12, adu_histo_result, integration_result_1, spot_finder_result_3, roi_calc_result_0,
|
||||
pixel_count_result_0,
|
||||
axi_compl[12], impl_->datamover_out.GetDataStream(),
|
||||
impl_->datamover_out.GetCtrlStream(), impl_->work_request_stream, impl_->completion_stream,
|
||||
dma_address_table.data(), packets_processed, impl_->host_writer_idle, impl_->cancel_data_collection, state);
|
||||
});
|
||||
|
||||
for (auto &i : hls_cores)
|
||||
i.join();
|
||||
|
||||
if (frame_generator_future.valid())
|
||||
frame_generator_future.get();
|
||||
|
||||
// reset static counter
|
||||
arp(arp1, impl_->dout_eth, mac_addr, ipv4_addr, 0);
|
||||
try {
|
||||
while (!impl_->din_eth.empty())
|
||||
impl_->din_eth.read();
|
||||
|
||||
if (!addr1.empty())
|
||||
throw std::runtime_error("Addr1 queue not empty");
|
||||
|
||||
if (!addr2.empty())
|
||||
throw std::runtime_error("Addr2 queue not empty");
|
||||
|
||||
if (!data_1.empty())
|
||||
throw std::runtime_error("data_1 queue not empty");
|
||||
|
||||
if (!data_3.empty())
|
||||
throw std::runtime_error("data_3 queue not empty");
|
||||
|
||||
if (!data_4.empty())
|
||||
throw std::runtime_error("data_4 queue not empty");
|
||||
|
||||
if (!data_5.empty())
|
||||
throw std::runtime_error("data_5 queue not empty");
|
||||
|
||||
if (!data_7.empty())
|
||||
throw std::runtime_error("data_7 queue not empty");
|
||||
|
||||
if (!data_8.empty())
|
||||
throw std::runtime_error("data_8 queue not empty");
|
||||
|
||||
if (!data_9.empty())
|
||||
throw std::runtime_error("data_9 queue not empty");
|
||||
|
||||
if (!data_10.empty())
|
||||
throw std::runtime_error("data_10 queue not empty");
|
||||
|
||||
if (!data_12.empty())
|
||||
throw std::runtime_error("data_12 queue not empty");
|
||||
|
||||
if (!data_13.empty())
|
||||
throw std::runtime_error("data_13 queue not empty");
|
||||
|
||||
for (auto &c: axi_compl) {
|
||||
if (!c.empty())
|
||||
throw std::runtime_error("Compl queue not empty");
|
||||
}
|
||||
|
||||
if (!stream_768_0.empty())
|
||||
throw std::runtime_error("stream_768_0 queue not empty");
|
||||
|
||||
if (!stream_768_2.empty())
|
||||
throw std::runtime_error("stream_768_2 queue not empty");
|
||||
|
||||
if (!stream_768_3.empty())
|
||||
throw std::runtime_error("stream_768_3 queue not empty");
|
||||
|
||||
if (!stream_768_4.empty())
|
||||
throw std::runtime_error("stream_768_4 queue not empty");
|
||||
|
||||
if (!stream_768_5.empty())
|
||||
throw std::runtime_error("stream_768_5 queue not empty");
|
||||
|
||||
if (!hbm_handles.empty())
|
||||
throw std::runtime_error("Handles queue not empty");
|
||||
|
||||
if (!integration_result_0.empty())
|
||||
throw std::runtime_error("Integration result queue not empty");
|
||||
|
||||
if (!integration_result_1.empty())
|
||||
throw std::runtime_error("Integration result queue not empty");
|
||||
|
||||
if (!impl_->datamover_in.GetDataStream().empty())
|
||||
throw std::runtime_error("Datamover queue is not empty");
|
||||
|
||||
while (!impl_->datamover_out.IsIdle())
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
} catch (const std::runtime_error &e) {
|
||||
throw e;
|
||||
}
|
||||
idle = true;
|
||||
}
|
||||
|
||||
DataCollectionStatus HLSDevice::GetDataCollectionStatus() const {
|
||||
DataCollectionStatus status{};
|
||||
|
||||
union {
|
||||
uint64_t u64;
|
||||
double d;
|
||||
} pulse_id_conv;
|
||||
pulse_id_conv.u64 = current_pulse_id;
|
||||
|
||||
status.ctrl_reg = ap_uint<1>(impl_->host_writer_idle) ? (1 << 4) : 0;
|
||||
status.max_modules = MAX_MODULES_FPGA;
|
||||
status.hbm_size_bytes = impl_->hbm_if_size;
|
||||
status.run_counter = run_counter;
|
||||
status.current_pulseid = pulse_id_conv.d;
|
||||
status.packets_udp = udp_packets;
|
||||
status.packets_sls = sls_packets;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void HLSDevice::HW_LoadCalibration(const LoadCalibrationConfig &config) {
|
||||
int ret = load_calibration(impl_->hbm.data(), impl_->hbm.data(),
|
||||
impl_->pixel_mask.data(),
|
||||
config,
|
||||
impl_->hbm_if_size,
|
||||
impl_->datamover_in.GetCtrlStream(),
|
||||
impl_->datamover_in.GetDataStream(),
|
||||
dma_address_table.data());
|
||||
if (ret)
|
||||
throw std::runtime_error("Error in loading calibration " + std::to_string(ret));
|
||||
|
||||
if (!impl_->datamover_in.GetDataStream().empty())
|
||||
throw std::runtime_error("Datamover queue is not empty");
|
||||
}
|
||||
|
||||
void HLSDevice::HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms) {
|
||||
spot_finder_parameters = params;
|
||||
}
|
||||
|
||||
void HLSDevice::CreateXfelBunchIDPacket(double pulse_id, uint32_t event_code) {
|
||||
|
||||
union {
|
||||
uint64_t u64;
|
||||
double d;
|
||||
} pulse_id_conv;
|
||||
pulse_id_conv.d = pulse_id;
|
||||
|
||||
bunchid_raw_packet packet{};
|
||||
|
||||
packet.ether_type = htons(0x0800);
|
||||
for (int i = 0; i < 6; i++)
|
||||
packet.dest_mac[i] = 0xFF;
|
||||
|
||||
packet.ipv4_header_h = htons(0x4500); // Big endian in IP header!
|
||||
packet.ipv4_header_total_length = htons(sizeof(bunchid_payload) + 8 + 20); // Big endian in IP header!
|
||||
packet.ipv4_header_dest_ip = UINT32_MAX;
|
||||
|
||||
packet.ipv4_header_ttl_protocol = htons(0x0011);
|
||||
packet.ipv4_header_checksum = checksum( (uint16_t *) &packet.ipv4_header_h, 20); // checksum is already in network order
|
||||
|
||||
packet.udp_length = htons(sizeof(bunchid_payload) + 8);
|
||||
packet.payload.magicn[0] = BUNCHID_MAGICN;
|
||||
packet.payload.magicn[1] = BUNCHID_MAGICN;
|
||||
packet.payload.magicn[2] = BUNCHID_MAGICN;
|
||||
packet.payload.bunchid_msb[0] = (pulse_id_conv.u64 >> 32) & UINT32_MAX;
|
||||
packet.payload.bunchid_msb[1] = (pulse_id_conv.u64 >> 32) & UINT32_MAX;
|
||||
packet.payload.bunchid_lsb[0] = pulse_id_conv.u64 & UINT32_MAX;
|
||||
packet.payload.bunchid_lsb[1] = pulse_id_conv.u64 & UINT32_MAX;
|
||||
packet.payload.montrig = event_code;
|
||||
|
||||
SendPacket((char *) &packet, sizeof(bunchid_raw_packet));
|
||||
}
|
||||
|
||||
uint64_t HLSDevice::GetUDPPackets() {
|
||||
return udp_packets;
|
||||
}
|
||||
|
||||
uint64_t HLSDevice::GetSLSPackets() {
|
||||
return sls_packets;
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <vector>
|
||||
|
||||
#include "../pcie_driver/jfjoch_fpga.h"
|
||||
|
||||
struct HLSDeviceImpl;
|
||||
|
||||
class HLSDevice {
|
||||
// Hide all HLS simulation structures here
|
||||
std::unique_ptr<HLSDeviceImpl> impl_;
|
||||
|
||||
std::mutex completion_mutex;
|
||||
uint32_t completion_count;
|
||||
|
||||
std::thread action_thread;
|
||||
std::future<void> frame_generator_future;
|
||||
std::atomic<int> frame_generator_result{0};
|
||||
std::vector<uint64_t> dma_address_table;
|
||||
uint64_t eth_packets = 0;
|
||||
uint64_t icmp_packets = 0;
|
||||
uint64_t udp_packets = 0;
|
||||
uint64_t sls_packets = 0;
|
||||
uint32_t udp_len_err = 0;
|
||||
uint32_t udp_eth_err = 0;
|
||||
|
||||
uint64_t current_pulse_id = 0;
|
||||
uint32_t run_counter = 0;
|
||||
|
||||
DataCollectionConfig cfg;
|
||||
SpotFinderParameters spot_finder_parameters;
|
||||
|
||||
const uint64_t mac_addr = 0xCCAA11223344;
|
||||
const uint32_t ipv4_addr = 0x0132010A;
|
||||
volatile bool idle;
|
||||
|
||||
void FrameGeneratorFuture(FrameGeneratorConfig config);
|
||||
void HLSMainThread();
|
||||
public:
|
||||
explicit HLSDevice(std::vector<DeviceOutput *> &device_buffer);
|
||||
~HLSDevice();
|
||||
void SendPacket(char *buffer, int len, uint8_t user = 0);
|
||||
void CreateJFPacket(uint64_t frame_number, uint32_t eth_packet,
|
||||
uint32_t module_number, const uint16_t *data, int8_t adjust_axis = 0, uint8_t user = 0);
|
||||
void CreateEIGERPacket(uint64_t frame_number, uint32_t eth_packet,
|
||||
uint32_t module_number, uint32_t col, uint32_t row,
|
||||
const uint16_t *data);
|
||||
void CreateFinalPacket();
|
||||
void CreateXfelBunchIDPacket(double bunchid, uint32_t event_code);
|
||||
|
||||
DataCollectionStatus GetDataCollectionStatus() const ;
|
||||
// What frame_generator returned in the last run, 0 if it was not run or went fine
|
||||
int GetFrameGeneratorResult() const;
|
||||
void Cancel() ;
|
||||
|
||||
void HW_ReadActionRegister(DataCollectionConfig *job);
|
||||
void HW_WriteActionRegister(const DataCollectionConfig *job);
|
||||
|
||||
void FPGA_StartAction();
|
||||
void FPGA_EndAction();
|
||||
bool HW_IsIdle() const;
|
||||
bool HW_ReadMailbox(uint32_t *values);
|
||||
bool HW_SendWorkRequest(uint32_t handle);
|
||||
void HW_LoadCalibration(const LoadCalibrationConfig &config);
|
||||
void HW_SetSpotFinderParameters(const SpotFinderParameters ¶ms);
|
||||
void HW_RunInternalGenerator(const FrameGeneratorConfig &config) ;
|
||||
|
||||
uint64_t GetSLSPackets();
|
||||
uint64_t GetUDPPackets();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <thread>
|
||||
#include "../hls/hls_jfjoch.h"
|
||||
|
||||
enum class Direction {Input, Output};
|
||||
|
||||
template <int N, int DEPTH=0> class Datamover {
|
||||
volatile int stop_signal;
|
||||
Direction dir;
|
||||
char *offset;
|
||||
hls::stream<axis_datamover_ctrl> control;
|
||||
hls::stream<ap_axiu<N,1,1,1>, DEPTH> data;
|
||||
std::thread datamover_thread;
|
||||
|
||||
size_t bytes_transferred;
|
||||
std::atomic<uint32_t> descriptors_done = 0;
|
||||
|
||||
void Move() {
|
||||
axis_datamover_ctrl command = control.read();
|
||||
|
||||
uint64_t addr = command.data(31+64,32);
|
||||
uint32_t bytes = command.data(22,0);
|
||||
if (bytes % (N/8) != 0)
|
||||
throw std::runtime_error("AXI datamover transfer must be aligned to " + std::to_string(N/8) + " bytes");
|
||||
if (addr % (N/8) != 0)
|
||||
throw std::runtime_error("AXI datamover addr must be aligned to " + std::to_string(N/8) + " bytes");
|
||||
if (bytes == 0)
|
||||
throw std::runtime_error("AXI datamover transfer cannot be 0");
|
||||
|
||||
uint32_t xfers = bytes / (N/8);
|
||||
auto host_mem = (ap_uint<N> *) (offset + addr);
|
||||
ap_axiu<N,1,1,1> data_packet;
|
||||
if (dir == Direction::Input) {
|
||||
for (uint64_t i = 0; i < xfers; i++) {
|
||||
data_packet.data = host_mem[i];
|
||||
for (int j = 0; j < N / 8; j++)
|
||||
data_packet.keep[j] = 1;
|
||||
data_packet.last = ((i == xfers - 1) ? 1 : 0);
|
||||
data << data_packet;
|
||||
bytes_transferred += N/8;
|
||||
}
|
||||
} else {
|
||||
for (uint64_t i = 0; i < xfers; i++) {
|
||||
data >> data_packet;
|
||||
host_mem[i] = data_packet.data;
|
||||
for (int j = 0; j < N / 8; j++) {
|
||||
if (data_packet.keep[j] != 1)
|
||||
throw std::runtime_error("TKEEP set low for bit " + std::to_string(i));
|
||||
}
|
||||
if (data_packet.last != ((i == xfers - 1) ? 1 : 0))
|
||||
throw std::runtime_error("TLAST packet flag set incorrectly for packet " + std::to_string(i) + " Expected xfers: " + std::to_string(xfers));
|
||||
bytes_transferred += N/8;
|
||||
}
|
||||
}
|
||||
descriptors_done++;
|
||||
}
|
||||
public:
|
||||
void Run() {
|
||||
while (!stop_signal || !control.empty()) {
|
||||
while (!stop_signal && control.empty())
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
// All commands that arrive till stop signal is executed, are executed
|
||||
while (!control.empty()) {
|
||||
Move();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
size_t Stop() noexcept { stop_signal = true; datamover_thread.join(); return bytes_transferred; }
|
||||
|
||||
Datamover(Direction in_dir, char* in_offset)
|
||||
: dir(in_dir), offset(in_offset), stop_signal(0), bytes_transferred(0) {
|
||||
datamover_thread = std::thread([this] {this->Run(); });
|
||||
};
|
||||
|
||||
bool IsIdle() const {
|
||||
return control.empty();
|
||||
}
|
||||
|
||||
uint32_t GetCompletedDescriptors() const {
|
||||
return descriptors_done;
|
||||
}
|
||||
|
||||
void ClearCompletedDescriptors() {
|
||||
descriptors_done = 0;
|
||||
}
|
||||
|
||||
hls::stream<axis_datamover_ctrl>& GetCtrlStream() { return control; }
|
||||
hls::stream<ap_axiu<N,1,1,1> >& GetDataStream() { return data; }
|
||||
~Datamover() { Stop(); }
|
||||
};
|
||||
@@ -26,4 +26,4 @@ ADD_LIBRARY(JFJochReceiver STATIC
|
||||
JFJochReceiver.cpp
|
||||
JFJochReceiver.h)
|
||||
|
||||
TARGET_LINK_LIBRARIES(JFJochReceiver ImagePusher JFJochImagePuller JFJochImageAnalysis JFJochAcquisitionDevice JFJochCommon JFJochHLSSimulation JFJochPreview JFJochRugnux JFJochModelWriter)
|
||||
TARGET_LINK_LIBRARIES(JFJochReceiver ImagePusher JFJochImagePuller JFJochImageAnalysis JFJochAcquisitionDevice JFJochCommon JFJochPreview JFJochRugnux JFJochModelWriter)
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#define STORAGE_CELL_FOR_TEST 11
|
||||
|
||||
static JFCalibration GeneratePedestalCalibration(const DiffractionExperiment &x) {
|
||||
JFCalibration GeneratePedestalCalibration(const DiffractionExperiment &x) {
|
||||
JFCalibration ret(x);
|
||||
|
||||
std::vector<float> pedestal_g0( RAW_MODULE_SIZE), pedestal_g1(RAW_MODULE_SIZE), pedestal_g2(RAW_MODULE_SIZE);
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// The calibration JFJochReceiverTest() converts with
|
||||
JFCalibration GeneratePedestalCalibration(const DiffractionExperiment &x);
|
||||
|
||||
bool JFJochReceiverTest(JFJochReceiverOutput &output, Logger &logger,
|
||||
AcquisitionDeviceGroup &aq_devices,
|
||||
const DiffractionExperiment &x,
|
||||
|
||||
@@ -69,7 +69,8 @@ ADD_EXECUTABLE(jfjoch_test
|
||||
../common/RawToConvertedGeometry.h
|
||||
../common/DiffractionExperiment.h
|
||||
CheckImageOutput.h
|
||||
FPGAIntegrationTest.cpp
|
||||
MockCardOutput.h
|
||||
FPGAAcquisitionDeviceTest.cpp
|
||||
StrongPixelSetTest.cpp
|
||||
AdaptiveThresholdTest.cpp
|
||||
AdaptiveSpotFinderCPUTest.cpp
|
||||
@@ -84,17 +85,13 @@ ADD_EXECUTABLE(jfjoch_test
|
||||
FFBIDXIndexerCPUTest.cpp
|
||||
ThreadSafeFIFOSetTest.cpp
|
||||
ReceiveRingBufferTest.cpp
|
||||
FPGANetworkTest.cpp
|
||||
JFPedestalTest.cpp
|
||||
JFCalibrationTest.cpp
|
||||
AzimuthalIntegrationTest.cpp
|
||||
StatusVectorTest.cpp
|
||||
CBORTest.cpp
|
||||
DetectorGeometryTest.cpp DetectorSetupTest.cpp DiffractionGeometryTest.cpp
|
||||
FPGASpotFindingUnitTest.cpp
|
||||
PreviewCounterTest.cpp
|
||||
FPGAFrameGeneratorTest.cpp
|
||||
FPGAHostWriterTest.cpp
|
||||
DiffractionSpotTest.cpp
|
||||
TIFFTest.cpp
|
||||
JFJochReceiverProcessingTest.cpp
|
||||
@@ -116,7 +113,6 @@ ADD_EXECUTABLE(jfjoch_test
|
||||
JFJochImageBufferReaderTest.cpp
|
||||
PixelMaskTest.cpp
|
||||
RegressionTest.cpp
|
||||
FPGAHLSModulesTest.cpp
|
||||
ZMQPreviewSocketTest.cpp
|
||||
DetectorSettingsTest.cpp
|
||||
AutoIncrVectorTest.cpp
|
||||
@@ -169,7 +165,6 @@ ADD_EXECUTABLE(jfjoch_test
|
||||
XtalRefineTest.cpp
|
||||
XtalRefineCeres.h
|
||||
CrystalLatticeTest.cpp
|
||||
FPGAPTPTest.cpp
|
||||
ResolutionShellsTest.cpp
|
||||
ImageSpotFinderCPUTest.cpp
|
||||
ImageSpotFinderGPUTest.cpp
|
||||
@@ -249,7 +244,7 @@ ADD_EXECUTABLE(jfjoch_test
|
||||
)
|
||||
|
||||
target_link_libraries(jfjoch_test Catch2WithMain JFJochBroker JFJochReceiver JFJochReader JFJochStreamWriter
|
||||
JFJochRugnuxOutput JFJochRugnux JFJochModelWriter JFJochImageAnalysis JFJochCommon JFJochHLSSimulation JFJochPreview
|
||||
JFJochRugnuxOutput JFJochRugnux JFJochModelWriter JFJochImageAnalysis JFJochCommon JFJochPreview
|
||||
jfjoch_xds_plugin ZLIB::ZLIB httplib::httplib)
|
||||
target_include_directories(jfjoch_test PRIVATE .)
|
||||
IF (JFJOCH_CUDA_AVAILABLE)
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
// 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 "../fpga/hls_simulation/hls_cores.h"
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_Cancel") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 1;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 256,
|
||||
.modules = 8,
|
||||
.detector_type = SLS_DETECTOR_TYPE_JUNGFRAU,
|
||||
.images_in_memory = 0
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) == 0);
|
||||
REQUIRE(data_out.size() == 130);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_WrongDetectorType") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 1;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 256,
|
||||
.modules = 8,
|
||||
.detector_type = 0,
|
||||
.images_in_memory = 0
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) != 0);
|
||||
REQUIRE(data_out.size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_WrongModuleCount") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 1;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 256,
|
||||
.modules = MAX_MODULES_FPGA + 1,
|
||||
.detector_type = SLS_DETECTOR_TYPE_JUNGFRAU,
|
||||
.images_in_memory = 0
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) != 0);
|
||||
REQUIRE(data_out.size() == 0);
|
||||
|
||||
config.modules = 0;
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) != 0);
|
||||
REQUIRE(data_out.size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_TooManyCells") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 1;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 256,
|
||||
.modules = 4,
|
||||
.detector_type = SLS_DETECTOR_TYPE_JUNGFRAU,
|
||||
.images_in_memory = 8
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) == 3);
|
||||
REQUIRE(data_out.size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_Run_JF") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 0;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 2,
|
||||
.modules = 2,
|
||||
.detector_type = SLS_DETECTOR_TYPE_JUNGFRAU,
|
||||
.images_in_memory = 0
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) == 0);
|
||||
REQUIRE(data_out.size() == (config.frames * config.modules * 128 + 1) * 130);
|
||||
}
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_Run_EIGER") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 0;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 2,
|
||||
.modules = 2,
|
||||
.detector_type = SLS_DETECTOR_TYPE_EIGER,
|
||||
.images_in_memory = 0,
|
||||
.eiger_bit_depth = 16
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) == 0);
|
||||
REQUIRE(data_out.size() == (config.frames * config.modules * 256) * 66 + 130); // Trailing packet is JF type!
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_Run_EIGER_32bit") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 0;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 2,
|
||||
.modules = 2,
|
||||
.detector_type = SLS_DETECTOR_TYPE_EIGER,
|
||||
.images_in_memory = 0,
|
||||
.eiger_bit_depth = 32
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) == 0);
|
||||
REQUIRE(data_out.size() == (config.frames * config.modules * 512) * 66 + 130); // Trailing packet is JF type!
|
||||
}
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_Run_EIGER_8bit") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 0;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 2,
|
||||
.modules = 2,
|
||||
.detector_type = SLS_DETECTOR_TYPE_EIGER,
|
||||
.images_in_memory = 0,
|
||||
.eiger_bit_depth = 8
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) == 0);
|
||||
REQUIRE(data_out.size() == (config.frames * config.modules * 128) * 66 + 130); // Trailing packet is JF type!
|
||||
}
|
||||
|
||||
TEST_CASE("FPGA_FrameGenerator_Run_EIGER_wrong_depth") {
|
||||
STREAM_512 data_out;
|
||||
std::vector<ap_uint<256> > d_hbm_p0(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
std::vector<ap_uint<256> > d_hbm_p1(RAW_MODULE_SIZE / (256 / 8) * 22 * 32);
|
||||
ap_uint<1> cancel = 0;
|
||||
FrameGeneratorConfig config{
|
||||
.frames = 2,
|
||||
.modules = 2,
|
||||
.detector_type = SLS_DETECTOR_TYPE_EIGER,
|
||||
.images_in_memory = 0,
|
||||
.eiger_bit_depth = 0
|
||||
};
|
||||
REQUIRE(frame_generator(data_out, d_hbm_p0.data(), d_hbm_p1.data(), 16*1024*1024, 0, 0, cancel, config) != 0);
|
||||
REQUIRE(data_out.size() == 0); // Trailing packet is JF type!
|
||||
}
|
||||
@@ -1,231 +0,0 @@
|
||||
// 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 <random>
|
||||
|
||||
#include "../fpga/hls_simulation/hls_cores.h"
|
||||
|
||||
|
||||
TEST_CASE("HLS_DataCollectionFSM","[OpenCAPI]") {
|
||||
DataCollectionConfig act_reg;
|
||||
|
||||
STREAM_512 raw0;
|
||||
STREAM_512 raw1;
|
||||
|
||||
hls::stream<axis_addr> addr0;
|
||||
hls::stream<axis_addr> addr1;
|
||||
|
||||
ap_uint<1> run_data_collection = 0;
|
||||
ap_uint<1> cancel_data_collection = 0;
|
||||
ap_uint<1> idle_data_collection;
|
||||
uint32_t save_data_collection_counter;
|
||||
act_reg.mode = MODE_CONV;
|
||||
|
||||
// state = WAIT_FOR_START
|
||||
volatile rcv_state_t state;
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
REQUIRE(idle_data_collection == 1);
|
||||
REQUIRE(addr1.empty());
|
||||
REQUIRE(raw1.empty());
|
||||
REQUIRE( state == RCV_WAIT_FOR_START);
|
||||
run_data_collection = 1;
|
||||
|
||||
// state = WAIT_FOR_START
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
REQUIRE(idle_data_collection == 0);
|
||||
REQUIRE(addr1.empty());
|
||||
REQUIRE(raw1.empty());
|
||||
REQUIRE( state == RCV_WAIT_FOR_START_LOW);
|
||||
// state = WAIT_FOR_START_LOW
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
REQUIRE(idle_data_collection == 0);
|
||||
REQUIRE(addr1.empty());
|
||||
REQUIRE(raw1.empty());
|
||||
REQUIRE( state == RCV_WAIT_FOR_START_LOW);
|
||||
// state = WAIT_FOR_START_LOW
|
||||
|
||||
run_data_collection = 0;
|
||||
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
REQUIRE(idle_data_collection == 0);
|
||||
REQUIRE(addr1.empty());
|
||||
REQUIRE(raw1.empty());
|
||||
REQUIRE( state == RCV_START);
|
||||
// state = START
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
|
||||
REQUIRE(idle_data_collection == 0);
|
||||
REQUIRE(raw1.size() == 1);
|
||||
|
||||
REQUIRE( state == RCV_INIT);
|
||||
// state = INIT
|
||||
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
|
||||
REQUIRE(idle_data_collection == 0);
|
||||
REQUIRE(raw1.size() == 1);
|
||||
REQUIRE( state == RCV_INIT);
|
||||
// state = INIT
|
||||
|
||||
cancel_data_collection = 1;
|
||||
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
|
||||
REQUIRE(idle_data_collection == 0);
|
||||
REQUIRE(raw1.size() == 1);
|
||||
|
||||
// state = LAST
|
||||
REQUIRE( state == RCV_LAST);
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
|
||||
REQUIRE(idle_data_collection == 0);
|
||||
REQUIRE(addr1.size() == 1);
|
||||
REQUIRE(raw1.size() == 2);
|
||||
REQUIRE( state == RCV_WAIT_FOR_START);
|
||||
// state = WAIT_FOR_START
|
||||
|
||||
data_collection_fsm(raw0, raw1,
|
||||
addr0, addr1,
|
||||
run_data_collection,
|
||||
cancel_data_collection,
|
||||
idle_data_collection,
|
||||
act_reg.mode,
|
||||
act_reg.energy_kev,
|
||||
act_reg.nframes,
|
||||
act_reg.nmodules,
|
||||
act_reg.nstorage_cells,
|
||||
act_reg.nsummation,
|
||||
act_reg.sqrtmult,
|
||||
act_reg.pxlthreshold_min,
|
||||
act_reg.pxlthreshold_max,
|
||||
state);
|
||||
|
||||
REQUIRE( state == RCV_WAIT_FOR_START);
|
||||
REQUIRE(idle_data_collection == 1);
|
||||
REQUIRE(addr1.size() == 1);
|
||||
REQUIRE(raw1.size() == 2);
|
||||
|
||||
auto packet = raw1.read();
|
||||
REQUIRE(packet.last == 1);
|
||||
REQUIRE(packet.dest == 0);
|
||||
|
||||
packet = raw1.read();
|
||||
REQUIRE(packet.last);
|
||||
REQUIRE(packet.dest == 0);
|
||||
|
||||
auto addr = addr1.read();
|
||||
REQUIRE(addr.last);
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
// 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 "../fpga/hls_simulation/hls_cores.h"
|
||||
#include "../common/Logger.h"
|
||||
|
||||
TEST_CASE("FPGA_FrameWriterTestIgnore") {
|
||||
Logger logger(Catch::getResultCapture().getCurrentTestName());
|
||||
STREAM_512 data_in;
|
||||
hls::stream<ap_uint<512>> adu_histo_in;
|
||||
hls::stream<ap_uint<512>> integration_in;
|
||||
hls::stream<ap_uint<512>> spot_finder_in;
|
||||
hls::stream<ap_uint<512>> roi_calc_in;
|
||||
hls::stream<ap_uint<PIXEL_COUNT_WIDTH>> pixel_calc_in;
|
||||
hls::stream<axis_completion > s_axis_completion;
|
||||
hls::stream<ap_axiu<512,1,1,1> > host_memory_out;
|
||||
hls::stream<axis_datamover_ctrl> datamover_out_cmd;
|
||||
hls::stream<ap_uint<32> > s_axis_work_request;
|
||||
hls::stream<ap_uint<32> > m_axis_completion;
|
||||
uint64_t dma_address_table[1024];
|
||||
uint64_t packets_processed = 0;
|
||||
ap_uint<1> idle;
|
||||
ap_uint<1> in_cancel = 0;
|
||||
|
||||
data_in.write(packet_512_t{.data = 0, .user = 0});
|
||||
|
||||
uint64_t nframes = 128;
|
||||
for (int i = 0; i < nframes; i++) {
|
||||
for (int j = 0; j < RAW_MODULE_SIZE * 2 / 64; j++)
|
||||
data_in.write(packet_512_t{.data = 0, .user = 0, .last = (j == RAW_MODULE_SIZE * 2 / 64 - 1)});
|
||||
for (int j = 0; j < RAW_MODULE_SIZE / (64 * 8) + 1; j++)
|
||||
spot_finder_in.write(0);
|
||||
for (int j = 0; j < FPGA_INTEGRATION_BIN_COUNT / 8; j++)
|
||||
integration_in.write(0);
|
||||
for (int j = 0; j < ADU_HISTO_BIN_COUNT / 16; j++)
|
||||
adu_histo_in.write(0);
|
||||
for (int j = 0; j < FPGA_ROI_COUNT; j++)
|
||||
roi_calc_in.write(0);
|
||||
pixel_calc_in.write(0);
|
||||
s_axis_completion.write(axis_completion{.frame_number = i, .last = 0});
|
||||
}
|
||||
|
||||
ap_uint<3> state;
|
||||
|
||||
s_axis_completion.write(axis_completion{.last = 1});
|
||||
data_in.write(packet_512_t{.data = 0, .user = 1});
|
||||
REQUIRE(data_in.size() == nframes * RAW_MODULE_SIZE * 2 / 64 + 2 );
|
||||
std::thread thr([&] { std::this_thread::sleep_for(std::chrono::seconds(1)); in_cancel = 1; });
|
||||
host_writer(data_in,
|
||||
adu_histo_in,
|
||||
integration_in,
|
||||
spot_finder_in,
|
||||
roi_calc_in,
|
||||
pixel_calc_in,
|
||||
s_axis_completion,
|
||||
host_memory_out,
|
||||
datamover_out_cmd,
|
||||
s_axis_work_request,
|
||||
m_axis_completion,
|
||||
dma_address_table,
|
||||
packets_processed,
|
||||
idle,
|
||||
in_cancel,
|
||||
state);
|
||||
CHECK(data_in.empty());
|
||||
CHECK(host_memory_out.empty());
|
||||
CHECK(datamover_out_cmd.empty());
|
||||
CHECK(m_axis_completion.size() == 2);
|
||||
CHECK(packets_processed == 0);
|
||||
CHECK(idle == 1);
|
||||
thr.join();
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,630 +0,0 @@
|
||||
// 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 <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <net/if_arp.h>
|
||||
|
||||
#include "../fpga/hls_simulation/hls_cores.h"
|
||||
#include "../fpga/hls_simulation/sls_packet.h"
|
||||
|
||||
// ARP packet - from if_arp.h
|
||||
#pragma pack(push)
|
||||
#pragma pack(2)
|
||||
struct RAW_ARP_Packet
|
||||
{
|
||||
unsigned char dest_mac[6];
|
||||
unsigned char sour_mac[6];
|
||||
uint16_t ether_type;
|
||||
unsigned short int ar_hrd; /* Format of hardware address. */
|
||||
unsigned short int ar_pro; /* Format of protocol address. */
|
||||
unsigned char ar_hln; /* Length of hardware address. */
|
||||
unsigned char ar_pln; /* Length of protocol address. */
|
||||
unsigned short int ar_op; /* ARP opcode (command). */
|
||||
|
||||
unsigned char __ar_sha[6]; /* Sender hardware address. */
|
||||
unsigned char __ar_sip[4]; /* Sender IP address. */
|
||||
unsigned char __ar_tha[6]; /* Target hardware address. */
|
||||
unsigned char __ar_tip[4]; /* Target IP address. */
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
TEST_CASE("HLS_Network_ARP_Gratuitous") {
|
||||
|
||||
AXI_STREAM arp_in;
|
||||
AXI_STREAM arp_out;
|
||||
|
||||
arp(arp_in, arp_out, 0x1, 0x1, 1);
|
||||
|
||||
packet_512_t network_packet;
|
||||
REQUIRE(arp_out.read_nb(network_packet));
|
||||
auto arp_packet = (RAW_ARP_Packet *) &network_packet.data;
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
REQUIRE(arp_packet->dest_mac[i] == 0xFF);
|
||||
REQUIRE(arp_packet->__ar_tha[i] == 0xFF);
|
||||
}
|
||||
|
||||
REQUIRE(arp_packet->ether_type == htons(ETHER_ARP));
|
||||
REQUIRE(arp_packet->ar_op == htons(ARPOP_REQUEST));
|
||||
REQUIRE(arp_packet->ar_hrd == htons(ARPHRD_ETHER));
|
||||
REQUIRE(arp_packet->ar_pro == htons(ETHER_IP));
|
||||
REQUIRE(arp_packet->ar_hln == 6);
|
||||
REQUIRE(arp_packet->ar_pln == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP") {
|
||||
char packet[130*64];
|
||||
|
||||
auto jf_packet = (jf_raw_packet *) packet;
|
||||
|
||||
jf_packet->ipv4_header_sour_ip = htonl(0x12345640);
|
||||
jf_packet->udp_length = htons(8248);
|
||||
jf_packet->udp_dest_port = htons(129);
|
||||
jf_packet->jf.framenum = 123456;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
auto jf_packet_axi = (ap_uint<512> *) packet;
|
||||
uint64_t packet_counter;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
ap_uint<1> udp_idle = 0;
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 1);
|
||||
REQUIRE(udp_out.size() == 129);
|
||||
|
||||
packet_512_t packet_out;
|
||||
udp_out.read(packet_out);
|
||||
REQUIRE(packet_out.data(63,0) == jf_packet->jf.framenum);
|
||||
|
||||
ap_uint<UDP_METADATA_STREAM_WIDTH> udp_metadata_out;
|
||||
udp_metadata.read(udp_metadata_out);
|
||||
REQUIRE(udp_metadata_dest_port(udp_metadata_out) == 129);
|
||||
REQUIRE(udp_metadata_payload_size(udp_metadata_out) == 8240);
|
||||
REQUIRE(udp_metadata_eth_err(udp_metadata_out) == 0);
|
||||
REQUIRE(udp_metadata_len_err(udp_metadata_out) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP_EthErr") {
|
||||
char packet[130*64];
|
||||
|
||||
auto jf_packet = (jf_raw_packet *) packet;
|
||||
|
||||
jf_packet->udp_length = htons(8248);
|
||||
jf_packet->udp_dest_port = htons(129);
|
||||
jf_packet->jf.framenum = 123456;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
auto jf_packet_axi = (ap_uint<512> *) packet;
|
||||
uint64_t packet_counter;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
ap_uint<1> udp_idle = 1;
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = (i == 129) ? 1 : 0;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
REQUIRE(udp_idle == 1);
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 1);
|
||||
REQUIRE(udp_out.size() == 129);
|
||||
|
||||
packet_512_t packet_out;
|
||||
udp_out.read(packet_out);
|
||||
REQUIRE(packet_out.data(63,0) == jf_packet->jf.framenum);
|
||||
|
||||
ap_uint<UDP_METADATA_STREAM_WIDTH> udp_metadata_out;
|
||||
udp_metadata.read(udp_metadata_out);
|
||||
REQUIRE(udp_metadata_dest_port(udp_metadata_out) == 129);
|
||||
REQUIRE(udp_metadata_payload_size(udp_metadata_out) == 8240);
|
||||
REQUIRE(udp_metadata_eth_err(udp_metadata_out) == 1);
|
||||
REQUIRE(udp_metadata_len_err(udp_metadata_out) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP_LenErr") {
|
||||
char packet[130*64];
|
||||
|
||||
auto jf_packet = (jf_raw_packet *) packet;
|
||||
|
||||
jf_packet->udp_length = htons(8248);
|
||||
jf_packet->udp_dest_port = htons(129);
|
||||
jf_packet->jf.framenum = 123456;
|
||||
|
||||
uint64_t packet_counter;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
ap_uint<1> udp_idle = 0;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
auto jf_packet_axi = (ap_uint<512> *) packet;
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 127);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 1);
|
||||
REQUIRE(udp_out.size() == 127);
|
||||
|
||||
packet_512_t packet_out;
|
||||
udp_out.read(packet_out);
|
||||
REQUIRE(packet_out.data(63,0) == jf_packet->jf.framenum);
|
||||
|
||||
ap_uint<UDP_METADATA_STREAM_WIDTH> udp_metadata_out;
|
||||
udp_metadata.read(udp_metadata_out);
|
||||
REQUIRE(udp_metadata_dest_port(udp_metadata_out) == 129);
|
||||
REQUIRE(udp_metadata_payload_size(udp_metadata_out) == 8240);
|
||||
REQUIRE(udp_metadata_eth_err(udp_metadata_out) == 0);
|
||||
REQUIRE(udp_metadata_len_err(udp_metadata_out) == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP_SLS_detector_1") {
|
||||
char packet[130*64];
|
||||
|
||||
uint8_t data_stream = 3;
|
||||
|
||||
auto jf_packet = (jf_raw_packet *) packet;
|
||||
jf_packet->ipv4_header_sour_ip = htonl(32);
|
||||
jf_packet->udp_length = htons(8248);
|
||||
jf_packet->udp_dest_port = htons((data_stream << 8) + 5);
|
||||
jf_packet->jf.framenum = 123456;
|
||||
jf_packet->jf.packetnum = 60;
|
||||
jf_packet->jf.row = 5;
|
||||
jf_packet->jf.column = 0;
|
||||
jf_packet->jf.detectortype = SLS_DETECTOR_TYPE_JUNGFRAU;
|
||||
for (int i = 0; i < 4096; i++)
|
||||
jf_packet->jf.data[i] = i;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
STREAM_512 raw_out;
|
||||
hls::stream<axis_addr> addr0;
|
||||
|
||||
uint64_t packet_counter;
|
||||
uint64_t sls_packet_counter;
|
||||
uint32_t err_counter1, err_counter2;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
ap_uint<1> udp_idle = 0;
|
||||
ap_uint<1> sls_idle = 0;
|
||||
uint64_t bunchid = 0;
|
||||
|
||||
auto jf_packet_axi = (ap_uint<512> *) packet;
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 1);
|
||||
REQUIRE(udp_out.size() == 129);
|
||||
REQUIRE(udp_idle == 1);
|
||||
while (!udp_out.empty()) {
|
||||
sls_detector(udp_out, udp_metadata, raw_out, addr0, sls_packet_counter, err_counter1, err_counter2,
|
||||
bunchid, data_stream, clear_counter, sls_idle);
|
||||
}
|
||||
REQUIRE(sls_idle == 1);
|
||||
REQUIRE(raw_out.size() == 128);
|
||||
REQUIRE(addr0.size() == 1);
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
auto packet_out = raw_out.read();
|
||||
REQUIRE(memcmp(&(packet_out.data), jf_packet->jf.data + 32 * i, 64) == 0);
|
||||
}
|
||||
|
||||
auto addr = addr0.read();
|
||||
REQUIRE(addr.frame_number == jf_packet->jf.framenum - 1);
|
||||
REQUIRE(addr.module == 5 / 2);
|
||||
REQUIRE(addr.column == 0);
|
||||
REQUIRE(addr.row == 1);
|
||||
REQUIRE(addr.eth_packet == jf_packet->jf.packetnum);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP_SLS_detector_2") {
|
||||
char packet[130*64];
|
||||
|
||||
uint8_t data_stream = 7;
|
||||
auto jf_packet = (jf_raw_packet *) packet;
|
||||
|
||||
jf_packet->udp_length = htons(8248);
|
||||
jf_packet->udp_dest_port = htons((data_stream<<8) + 2*2);
|
||||
jf_packet->ipv4_header_sour_ip = htonl(32+4);
|
||||
jf_packet->jf.framenum = UINT64_MAX - 300;
|
||||
jf_packet->jf.packetnum = 35;
|
||||
jf_packet->jf.row = 4;
|
||||
jf_packet->jf.detectortype = SLS_DETECTOR_TYPE_JUNGFRAU;
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
jf_packet->jf.data[i] = i;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
STREAM_512 raw_out;
|
||||
hls::stream<axis_addr> addr0;
|
||||
|
||||
auto jf_packet_axi = (ap_uint<512> *) packet;
|
||||
|
||||
uint64_t packet_counter;
|
||||
uint64_t sls_packet_counter;
|
||||
uint32_t err_counter1, err_counter2;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
ap_uint<1> udp_idle = 1;
|
||||
ap_uint<1> sls_idle = 1;
|
||||
uint64_t bunchid = 0;
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 1);
|
||||
REQUIRE(udp_out.size() == 129);
|
||||
REQUIRE(udp_idle == 1);
|
||||
|
||||
while (!udp_out.empty()) {
|
||||
sls_detector(udp_out, udp_metadata, raw_out, addr0, sls_packet_counter, err_counter1, err_counter2,
|
||||
bunchid, data_stream, clear_counter, sls_idle);
|
||||
}
|
||||
|
||||
REQUIRE(raw_out.size() == 128);
|
||||
REQUIRE(addr0.size() == 1);
|
||||
REQUIRE(sls_idle == 1);
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
auto packet_out = raw_out.read();
|
||||
REQUIRE(memcmp(&(packet_out.data), jf_packet->jf.data + 32 * i, 64) == 0);
|
||||
}
|
||||
|
||||
auto addr = addr0.read();
|
||||
REQUIRE(addr.frame_number == jf_packet->jf.framenum - 1);
|
||||
REQUIRE(addr.module == 2);
|
||||
REQUIRE(addr.eth_packet == jf_packet->jf.packetnum);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP_SLS_detector_2_packets") {
|
||||
char packet[130*64];
|
||||
|
||||
auto jf_packet = (jf_raw_packet *) packet;
|
||||
|
||||
jf_packet->ipv4_header_sour_ip = htonl(192);
|
||||
jf_packet->udp_length = htons(8248);
|
||||
jf_packet->udp_dest_port = htons(16384 + 2);
|
||||
jf_packet->jf.framenum = UINT64_MAX - 300;
|
||||
jf_packet->jf.packetnum = 35;
|
||||
jf_packet->jf.row = 0;
|
||||
jf_packet->jf.detectortype = SLS_DETECTOR_TYPE_JUNGFRAU;
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
jf_packet->jf.data[i] = i;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
STREAM_512 raw_out;
|
||||
hls::stream<axis_addr> addr0;
|
||||
|
||||
auto jf_packet_axi = (ap_uint<512> *) packet;
|
||||
|
||||
uint64_t packet_counter;
|
||||
uint64_t sls_packet_counter;
|
||||
uint32_t err_counter1, err_counter2;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
ap_uint<1> udp_idle = 1;
|
||||
ap_uint<1> sls_idle = 1;
|
||||
uint64_t bunchid = 0;
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 2);
|
||||
REQUIRE(udp_out.size() == 2*129);
|
||||
|
||||
while (!udp_out.empty()) {
|
||||
sls_detector(udp_out, udp_metadata, raw_out, addr0, sls_packet_counter, err_counter1, err_counter2,
|
||||
bunchid, 0, clear_counter, sls_idle);
|
||||
}
|
||||
|
||||
REQUIRE(raw_out.size() == 256);
|
||||
REQUIRE(addr0.size() == 2);
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
for (int i = 0; i < 128; i++) {
|
||||
auto packet_out = raw_out.read();
|
||||
REQUIRE(memcmp(&(packet_out.data), jf_packet->jf.data + 32 * i, 64) == 0);
|
||||
}
|
||||
|
||||
auto addr = addr0.read();
|
||||
REQUIRE(addr.frame_number == jf_packet->jf.framenum - 1);
|
||||
REQUIRE(addr.module == 1);
|
||||
REQUIRE(addr.eth_packet == jf_packet->jf.packetnum);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP_SLS_detector_packets_err") {
|
||||
char packet[130*64];
|
||||
|
||||
auto jf_packet = (jf_raw_packet *) packet;
|
||||
|
||||
jf_packet->ipv4_header_sour_ip = htonl(32+4);
|
||||
jf_packet->udp_length = htons(8248);
|
||||
jf_packet->udp_dest_port = htons(4);
|
||||
jf_packet->jf.framenum = UINT64_MAX - 300;
|
||||
jf_packet->jf.packetnum = 35;
|
||||
jf_packet->jf.row = 0;
|
||||
jf_packet->jf.detectortype = SLS_DETECTOR_TYPE_JUNGFRAU;
|
||||
|
||||
for (int i = 0; i < 4096; i++)
|
||||
jf_packet->jf.data[i] = i;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
STREAM_512 raw_out;
|
||||
hls::stream<axis_addr> addr0;
|
||||
|
||||
auto jf_packet_axi = (ap_uint<512> *) packet;
|
||||
|
||||
uint64_t udp_packet_counter;
|
||||
uint64_t sls_packet_counter;
|
||||
uint32_t err_counter_eth, err_counter_len;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
ap_uint<1> udp_idle = 1;
|
||||
ap_uint<1> sls_idle = 1;
|
||||
uint64_t bunchid = 0;
|
||||
|
||||
clear_counter = 1;
|
||||
for (int i = 0; i < 125; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 124);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, udp_packet_counter, clear_counter, udp_idle);
|
||||
clear_counter = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, udp_packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 1;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, udp_packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 130; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 1;
|
||||
packet_in.last = (i == 129);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, udp_packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 4);
|
||||
REQUIRE(udp_out.size() == 129*3+124);
|
||||
|
||||
clear_counter = 1;
|
||||
while (!udp_out.empty()) {
|
||||
sls_detector(udp_out, udp_metadata, raw_out, addr0, sls_packet_counter, err_counter_eth, err_counter_len,
|
||||
bunchid, 0, clear_counter, sls_idle);
|
||||
clear_counter = 0;
|
||||
}
|
||||
|
||||
REQUIRE(raw_out.size() == 128);
|
||||
REQUIRE(addr0.size() == 1);
|
||||
|
||||
for (int i = 0; i < 128; i++) {
|
||||
auto packet_out = raw_out.read();
|
||||
REQUIRE(memcmp(&(packet_out.data), jf_packet->jf.data + 32 * i, 64) == 0);
|
||||
}
|
||||
|
||||
auto addr = addr0.read();
|
||||
REQUIRE(addr.frame_number == jf_packet->jf.framenum - 1);
|
||||
REQUIRE(addr.module == 2);
|
||||
REQUIRE(addr.eth_packet == jf_packet->jf.packetnum);
|
||||
|
||||
REQUIRE(udp_packet_counter == 4);
|
||||
REQUIRE(sls_packet_counter == 1);
|
||||
REQUIRE(err_counter_eth == 2);
|
||||
REQUIRE(err_counter_len == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP_SLS_detector_4kB") {
|
||||
char packet[130*64];
|
||||
|
||||
auto jf_packet = (eiger_raw_packet *) packet;
|
||||
|
||||
jf_packet->udp_length = htons(4096+48+8);
|
||||
jf_packet->udp_dest_port = htons(16384 + 5); // bit 14 should not matter
|
||||
jf_packet->eiger.framenum = 123456;
|
||||
jf_packet->eiger.packetnum = 60;
|
||||
jf_packet->eiger.row = 0;
|
||||
jf_packet->eiger.column = 1;
|
||||
jf_packet->eiger.detectortype = SLS_DETECTOR_TYPE_EIGER;
|
||||
|
||||
for (int i = 0; i < 2048; i++)
|
||||
jf_packet->eiger.data[i] = i;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
STREAM_512 raw_out;
|
||||
hls::stream<axis_addr> addr0;
|
||||
ap_uint<1> udp_idle;
|
||||
|
||||
uint64_t packet_counter;
|
||||
uint64_t sls_packet_counter;
|
||||
uint32_t err_counter_eth, err_counter_len;
|
||||
ap_uint<1> sls_idle = 1;
|
||||
uint64_t bunchid = 0;
|
||||
|
||||
auto jf_packet_axi = (ap_uint<512> *) packet;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
|
||||
for (int i = 0; i < 66; i++) {
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = (i == 65);
|
||||
packet_in.data = jf_packet_axi[i];
|
||||
udp_in.write(packet_in);
|
||||
udp(udp_in, udp_out, udp_metadata, packet_counter, clear_counter, udp_idle);
|
||||
}
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 1);
|
||||
REQUIRE(udp_out.size() == 65);
|
||||
|
||||
while (!udp_out.empty()) {
|
||||
sls_detector(udp_out, udp_metadata, raw_out, addr0, sls_packet_counter, err_counter_eth, err_counter_len,
|
||||
bunchid, 0, clear_counter, sls_idle);
|
||||
}
|
||||
|
||||
REQUIRE(raw_out.size() == 64);
|
||||
REQUIRE(addr0.size() == 1);
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
auto packet_out = raw_out.read();
|
||||
REQUIRE(memcmp(&(packet_out.data), jf_packet->eiger.data + 32 * i, 64) == 0);
|
||||
}
|
||||
|
||||
auto addr = addr0.read();
|
||||
REQUIRE(addr.frame_number == jf_packet->eiger.framenum - 1);
|
||||
REQUIRE(addr.eth_packet == jf_packet->eiger.packetnum);
|
||||
REQUIRE(addr.column == 1);
|
||||
REQUIRE(addr.row == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_Network_UDP_SLS_detector_bunchid") {
|
||||
ap_uint<512> tmp[2];
|
||||
|
||||
auto packet = (bunchid_raw_packet *) tmp;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
packet->dest_mac[i] = 0xFF;
|
||||
|
||||
packet->udp_dest_port = 0;
|
||||
packet->udp_length = htons(sizeof(bunchid_payload) + 8);
|
||||
packet->payload.magicn[0] = BUNCHID_MAGICN;
|
||||
packet->payload.magicn[1] = BUNCHID_MAGICN;
|
||||
packet->payload.magicn[2] = BUNCHID_MAGICN;
|
||||
packet->payload.bunchid_msb[0] = 0xAABBCCDD;
|
||||
packet->payload.bunchid_msb[1] = 0xAABBCCDD;
|
||||
packet->payload.bunchid_lsb[0] = 0xFFDDCCBB;
|
||||
packet->payload.bunchid_lsb[1] = 0xFFDDCCBB;
|
||||
|
||||
STREAM_512 udp_in;
|
||||
STREAM_512 udp_out;
|
||||
hls::stream<ap_uint<UDP_METADATA_STREAM_WIDTH> > udp_metadata;
|
||||
|
||||
STREAM_512 raw_out;
|
||||
hls::stream<axis_addr> addr0;
|
||||
|
||||
uint64_t udp_packet_counter;
|
||||
uint64_t sls_packet_counter;
|
||||
uint32_t err_counter_eth, err_counter_len;
|
||||
ap_uint<1> clear_counter = 0;
|
||||
ap_uint<1> udp_idle = 1;
|
||||
ap_uint<1> sls_idle = 1;
|
||||
uint64_t bunchid = 0;
|
||||
|
||||
clear_counter = 1;
|
||||
|
||||
packet_512_t packet_in;
|
||||
packet_in.user = 0;
|
||||
packet_in.last = 0;
|
||||
packet_in.data = tmp[0];
|
||||
udp_in.write(packet_in);
|
||||
|
||||
packet_in.last = 1;
|
||||
packet_in.data = tmp[1];
|
||||
udp_in.write(packet_in);
|
||||
|
||||
udp(udp_in, udp_out, udp_metadata, udp_packet_counter, clear_counter, udp_idle);
|
||||
udp(udp_in, udp_out, udp_metadata, udp_packet_counter, clear_counter, udp_idle);
|
||||
|
||||
clear_counter = 0;
|
||||
REQUIRE(udp_in.size() == 0);
|
||||
REQUIRE(udp_metadata.size() == 1);
|
||||
REQUIRE(udp_out.size() == 1);
|
||||
|
||||
clear_counter = 1;
|
||||
|
||||
sls_detector(udp_out, udp_metadata, raw_out, addr0, sls_packet_counter, err_counter_eth, err_counter_len,
|
||||
bunchid, 0, clear_counter, sls_idle);
|
||||
|
||||
clear_counter = 0;
|
||||
|
||||
REQUIRE(raw_out.size() == 0);
|
||||
REQUIRE(addr0.size() == 0);
|
||||
|
||||
REQUIRE(bunchid == 0xAABBCCDDFFDDCCBB);
|
||||
REQUIRE(udp_packet_counter == 1);
|
||||
REQUIRE(sls_packet_counter == 0);
|
||||
REQUIRE(err_counter_eth == 0);
|
||||
REQUIRE(err_counter_len == 0);
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <arpa/inet.h> // htons, htonl
|
||||
#include "../fpga/hls_simulation/hls_cores.h"
|
||||
#include "../fpga/hls/ptp.cpp"
|
||||
|
||||
// Minimal 64-byte frame layout for a single-beat 512-bit AXI packet.
|
||||
// We only care about:
|
||||
// - Ethernet header (14 bytes) as padding
|
||||
// - PTP common header fields: messageType nibble, flagField
|
||||
// - preciseOriginTimestamp: ns(32) + seconds(48)
|
||||
// Other fields are left as zero.
|
||||
#pragma pack(push, 1)
|
||||
struct EthernetPTP512 {
|
||||
uint8_t eth_pad[14]; // Ethernet dest/src/type (unused in tests)
|
||||
|
||||
// PTP common header (we only fill what we need)
|
||||
uint8_t ts_msgType; // transportSpecific (upper nibble) | messageType (lower nibble)
|
||||
uint8_t versionPTP; // not used, keep zero
|
||||
uint16_t messageLength; // not used
|
||||
uint8_t domainNumber; // not used
|
||||
uint8_t reserved1; // not used
|
||||
uint16_t flagField; // network order
|
||||
uint64_t correctionField; // not used
|
||||
uint32_t reserved2; // not used
|
||||
uint8_t sourcePortIdentity[10]; // not used
|
||||
uint16_t sequenceId; // not used
|
||||
uint8_t controlField; // not used
|
||||
int8_t logMessageInterval; // not used
|
||||
|
||||
// payload for Sync/Follow_Up we care about: preciseOriginTimestamp
|
||||
// Offset chosen to match your parser: ns first (32-bit), then seconds (48-bit).
|
||||
uint32_t preciseOriginTimestamp_ns_be; // network order
|
||||
uint8_t preciseOriginTimestamp_sec_be[6]; // 48-bit, big-endian
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
// Helper: host-to-big-endian for 48-bit seconds into a 6-byte array.
|
||||
static inline void htobe48(uint64_t host_val, uint8_t out[6]) {
|
||||
// Keep low 48 bits
|
||||
uint64_t v = host_val & 0x0000FFFFFFFFFFFFULL;
|
||||
out[0] = static_cast<uint8_t>((v >> 40) & 0xFF);
|
||||
out[1] = static_cast<uint8_t>((v >> 32) & 0xFF);
|
||||
out[2] = static_cast<uint8_t>((v >> 24) & 0xFF);
|
||||
out[3] = static_cast<uint8_t>((v >> 16) & 0xFF);
|
||||
out[4] = static_cast<uint8_t>((v >> 8) & 0xFF);
|
||||
out[5] = static_cast<uint8_t>(v & 0xFF);
|
||||
}
|
||||
|
||||
// Build a 512-bit single-beat AXI PTP packet via a C struct, then cast to ap_uint<512>.
|
||||
static packet_512_t make_ptp_packet(uint8_t message_type, bool two_step, uint64_t sec48, uint32_t ns32) {
|
||||
ap_uint<512> word = 0;
|
||||
|
||||
auto frame = reinterpret_cast<EthernetPTP512 *>(&word);
|
||||
|
||||
// Byte 0 of PTP: transportSpecific=0, messageType in low nibble
|
||||
frame->ts_msgType = (0x0 << 4) | (message_type & 0x0F);
|
||||
|
||||
// twoStepFlag: bit 1 (0x0002) in flagField (big-endian)
|
||||
uint16_t flags = two_step ? 0x0002 : 0x0000;
|
||||
frame->flagField = htons(flags);
|
||||
|
||||
// preciseOriginTimestamp: ns (32-bit BE), seconds (48-bit BE)
|
||||
frame->preciseOriginTimestamp_ns_be = htonl(ns32);
|
||||
htobe48(sec48, frame->preciseOriginTimestamp_sec_be);
|
||||
|
||||
packet_512_t pkt{};
|
||||
pkt.data = word;
|
||||
pkt.last = 1;
|
||||
return pkt;
|
||||
}
|
||||
|
||||
static void run_cycles(AXI_STREAM& s, int cycles,
|
||||
volatile ap_uint<80>& counter_ns,
|
||||
volatile ap_uint<32>& counter_error,
|
||||
volatile ap_uint<1>& synced_to_ptp) {
|
||||
for (int i = 0; i < cycles; ++i) {
|
||||
ptp(s, counter_ns, counter_error, synced_to_ptp);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_PTP_OneStep") {
|
||||
AXI_STREAM eth_in;
|
||||
volatile ap_uint<80> counter_ns = 0;
|
||||
volatile ap_uint<32> counter_error = 0;
|
||||
volatile ap_uint<1> synced_to_ptp = 0;
|
||||
|
||||
run_cycles(eth_in, 10, counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
uint64_t sec = 56789;
|
||||
uint32_t ns = 999999999U;
|
||||
auto pkt = make_ptp_packet(/*message_type=*/0x0, /*two_step=*/false, sec, ns);
|
||||
eth_in.write(pkt);
|
||||
|
||||
run_cycles(eth_in, 1, counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
ap_uint<80> combined = counter_ns; // upper 48 bits = sec, lower 32 bits = ns
|
||||
uint64_t sec_read = (uint64_t)(combined >> 32);
|
||||
uint32_t ns_read = (uint32_t)(combined & 0xFFFFFFFFu);
|
||||
|
||||
REQUIRE(synced_to_ptp.read() == 1);
|
||||
CHECK(sec_read == sec);
|
||||
CHECK(ns_read == ns);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_PTP_OneStep_incr_1sec") {
|
||||
AXI_STREAM eth_in;
|
||||
volatile ap_uint<80> counter_ns = 0;
|
||||
volatile ap_uint<32> counter_error = 0;
|
||||
volatile ap_uint<1> synced_to_ptp = 0;
|
||||
|
||||
run_cycles(eth_in, 10, counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
uint64_t sec = 56789;
|
||||
uint32_t ns = 999999999U;
|
||||
auto pkt = make_ptp_packet(/*message_type=*/0x0, /*two_step=*/false, sec, ns);
|
||||
eth_in.write(pkt);
|
||||
|
||||
run_cycles(eth_in, 2, counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
ap_uint<80> combined = counter_ns; // upper 48 bits = sec, lower 32 bits = ns
|
||||
uint64_t sec_read = (uint64_t)(combined >> 32);
|
||||
uint32_t ns_read = (uint32_t)(combined & 0xFFFFFFFFu);
|
||||
|
||||
REQUIRE(synced_to_ptp.read() == 1);
|
||||
CHECK(sec_read == 56789 + 1);
|
||||
CHECK(ns_read == 4);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_PTP_TwoStep") {
|
||||
AXI_STREAM eth_in;
|
||||
volatile ap_uint<80> counter_ns = 0;
|
||||
volatile ap_uint<32> counter_error = 0;
|
||||
volatile ap_uint<1> synced_to_ptp = 0;
|
||||
|
||||
run_cycles(eth_in, 5, counter_ns, counter_error, synced_to_ptp);
|
||||
ap_uint<80> before = counter_ns;
|
||||
|
||||
// Two-step Sync
|
||||
auto sync_pkt = make_ptp_packet(/*message_type=*/0x0, /*two_step=*/true, /*sec*/5, /*ns*/500);
|
||||
eth_in.write(sync_pkt);
|
||||
run_cycles(eth_in, 1, counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
ap_uint<80> after_sync = counter_ns;
|
||||
REQUIRE(after_sync > before); // clock advanced by tick, but no snap to sec=5
|
||||
uint64_t sec_sync = (uint64_t)(after_sync >> 32);
|
||||
REQUIRE(sec_sync != 5);
|
||||
|
||||
// Follow_Up updates to its timestamp
|
||||
uint64_t fu_sec = 123456;
|
||||
uint32_t fu_ns = 3456;
|
||||
auto follow_up_pkt = make_ptp_packet(/*message_type=*/0x8, /*two_step=*/true, fu_sec, fu_ns);
|
||||
eth_in.write(follow_up_pkt);
|
||||
run_cycles(eth_in, 1, counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
ap_uint<80> combined = counter_ns;
|
||||
uint64_t sec_read = (uint64_t)(combined >> 32);
|
||||
uint32_t ns_read = (uint32_t)(combined & 0xFFFFFFFFu);
|
||||
|
||||
REQUIRE(synced_to_ptp.read() == 1);
|
||||
CHECK(sec_read == fu_sec);
|
||||
CHECK(ns_read == fu_ns);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_PTP_OneStep_error") {
|
||||
AXI_STREAM eth_in;
|
||||
volatile ap_uint<80> counter_ns = 0;
|
||||
volatile ap_uint<32> counter_error = 0;
|
||||
volatile ap_uint<1> synced_to_ptp = 0;
|
||||
|
||||
run_cycles(eth_in, 10, counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
uint64_t sec = 100;
|
||||
uint32_t ns = 100;
|
||||
auto pkt = make_ptp_packet(/*message_type=*/0x0, /*two_step=*/false, sec, ns);
|
||||
eth_in.write(pkt);
|
||||
|
||||
run_cycles(eth_in, 11, counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
ap_uint<80> combined = counter_ns; // upper 48 bits = sec, lower 32 bits = ns
|
||||
uint64_t sec_read = (uint64_t)(combined >> 32);
|
||||
uint32_t ns_read = (uint32_t)(combined & 0xFFFFFFFFu);
|
||||
|
||||
REQUIRE(synced_to_ptp.read() == 1);
|
||||
CHECK(sec_read == 100);
|
||||
CHECK(ns_read == 100 + 5 * 10);
|
||||
|
||||
ns = 100 + 5 * 11 - 7;
|
||||
pkt = make_ptp_packet(/*message_type=*/0x0, /*two_step=*/false, sec, ns);
|
||||
eth_in.write(pkt);
|
||||
|
||||
run_cycles(eth_in, 1, counter_ns, counter_error, synced_to_ptp);
|
||||
CHECK(counter_error.read() == 7);
|
||||
combined = counter_ns; // upper 48 bits = sec, lower 32 bits = ns
|
||||
sec_read = (uint64_t)(combined >> 32);
|
||||
ns_read = (uint32_t)(combined & 0xFFFFFFFFu);
|
||||
|
||||
CHECK(sec_read == 100);
|
||||
CHECK(ns_read == ns);
|
||||
}
|
||||
|
||||
TEST_CASE("HLS_PTP_2s_out_of_sync") {
|
||||
AXI_STREAM eth_in;
|
||||
volatile ap_uint<80> counter_ns = 0;
|
||||
volatile ap_uint<32> counter_error = 0;
|
||||
volatile ap_uint<1> synced_to_ptp = 0;
|
||||
|
||||
auto pkt = make_ptp_packet(/*message_type=*/0x0, /*two_step=*/false, /*sec*/100, /*ns*/0);
|
||||
eth_in.write(pkt);
|
||||
run_cycles(eth_in, 1, counter_ns, counter_error, synced_to_ptp);
|
||||
REQUIRE(synced_to_ptp.read() == 1);
|
||||
|
||||
const uint64_t ticks_2s = (2ULL * 1000000000ULL) / 5ULL;
|
||||
run_cycles(eth_in, (int)(ticks_2s + 2), counter_ns, counter_error, synced_to_ptp);
|
||||
|
||||
REQUIRE(synced_to_ptp.read() == 0);
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <iostream>
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include "../fpga/hls_simulation/hls_cores.h"
|
||||
|
||||
TEST_CASE("FPGA_spot_finder_core","[FPGA][SpotFinder]") {
|
||||
STREAM_768 input;
|
||||
STREAM_768 output;
|
||||
hls::stream<ap_axiu<32,1,1,1>> strong_pixel;
|
||||
|
||||
ap_int<32> in_photon_count_threshold = 8;
|
||||
float_uint32 in_strong_pixel_threshold;
|
||||
in_strong_pixel_threshold.f = 4.0;
|
||||
|
||||
std::vector<int32_t> input_frame(RAW_MODULE_SIZE), output_frame(RAW_MODULE_SIZE);
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++) {
|
||||
if (i % RAW_MODULE_COLS == 1023)
|
||||
input_frame[i] = INT24_MIN;
|
||||
else
|
||||
input_frame[i] = i % RAW_MODULE_COLS;
|
||||
}
|
||||
|
||||
input << packet_768_t{.user = 0};
|
||||
for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / 64; i++) {
|
||||
ap_int<24> tmp[32];
|
||||
for (int j = 0; j < 32; j++)
|
||||
tmp[j] = input_frame[i * 32 + j];
|
||||
|
||||
input << packet_768_t{.data = pack32(tmp), .keep = UINT32_MAX, .user = 0};
|
||||
}
|
||||
|
||||
input << packet_768_t{.user = 1};
|
||||
|
||||
ap_uint<32> tmp_strong_pixel_threshold = in_strong_pixel_threshold.u;
|
||||
spot_finder(input,
|
||||
output,
|
||||
strong_pixel,
|
||||
in_photon_count_threshold,
|
||||
tmp_strong_pixel_threshold);
|
||||
|
||||
REQUIRE(input.size() == 0);
|
||||
REQUIRE(output.size() == RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 2);
|
||||
REQUIRE(strong_pixel.size() == RAW_MODULE_SIZE * sizeof(uint16_t) / 64 + 16 + 1);
|
||||
}
|
||||
|
||||
void spot_finder_prepare(hls::stream<spot_finder_packet> &data_in,
|
||||
hls::stream<spot_finder_packet> &data_out,
|
||||
hls::stream<ap_int<SUM_BITWIDTH>> &sum_out,
|
||||
hls::stream<ap_int<SUM2_BITWIDTH>> &sum2_out,
|
||||
hls::stream<ap_int<VALID_BITWIDTH>> &valid_out);
|
||||
|
||||
TEST_CASE("FPGA_spot_finder_prepare", "FPGA") {
|
||||
hls::stream<spot_finder_packet> data_in;
|
||||
hls::stream<spot_finder_packet> data_out;
|
||||
hls::stream<ap_int<SUM_BITWIDTH>> sum_out;
|
||||
hls::stream<ap_int<SUM2_BITWIDTH>> sum2_out;
|
||||
hls::stream<ap_int<VALID_BITWIDTH>> valid_out;
|
||||
|
||||
// Empty packet, just forward
|
||||
data_in << spot_finder_packet{
|
||||
.data = 348,
|
||||
.user = 0
|
||||
};
|
||||
|
||||
std::vector<int32_t> input_frame(RAW_MODULE_SIZE);
|
||||
std::vector<uint8_t> mask(RAW_MODULE_SIZE);
|
||||
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++) {
|
||||
input_frame[i] = i;
|
||||
mask[i] = 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < RAW_MODULE_SIZE * sizeof(uint16_t) / 64; i++) {
|
||||
ap_int<24> tmp[32];
|
||||
ap_uint<32> mask_tmp;
|
||||
|
||||
for (int j = 0; j < 32; j++) {
|
||||
tmp[j] = input_frame[i * 32 + j];
|
||||
mask_tmp[j] = (mask[i * 32 + j] != 0);
|
||||
}
|
||||
|
||||
data_in << spot_finder_packet{
|
||||
.data = pack32(tmp),
|
||||
.mask = mask_tmp,
|
||||
.user = 0,
|
||||
};
|
||||
}
|
||||
|
||||
data_in << spot_finder_packet{.user = 1};
|
||||
spot_finder_prepare(data_in,
|
||||
data_out,
|
||||
sum_out,
|
||||
sum2_out,
|
||||
valid_out);
|
||||
|
||||
REQUIRE(data_in.empty());
|
||||
REQUIRE(data_out.size() == 16384 + 2);
|
||||
REQUIRE(sum_out.size() == 16384);
|
||||
REQUIRE(sum2_out.size() == 16384);
|
||||
REQUIRE(valid_out.size() == 16384);
|
||||
|
||||
int64_t sum[16384];
|
||||
int64_t sum2[16384];
|
||||
int64_t valid[16384];
|
||||
|
||||
for (int i = 0; i < 16384; i++) {
|
||||
sum[i] = sum_out.read().to_int64();
|
||||
sum2[i] = sum2_out.read().to_int64();
|
||||
valid[i] = valid_out.read().to_int64();
|
||||
}
|
||||
|
||||
REQUIRE(sum_out.empty());
|
||||
REQUIRE(sum2_out.empty());
|
||||
REQUIRE(valid_out.empty());
|
||||
|
||||
int sum_err = 0;
|
||||
int sum2_err = 0;
|
||||
int valid_err = 0;
|
||||
|
||||
for (int i = 0; i < 16384; i++) {
|
||||
int64_t sum_ref = 0;
|
||||
int64_t sum2_ref = 0;
|
||||
int64_t valid_ref = 0;
|
||||
|
||||
int32_t col = i % 32;
|
||||
int32_t line = i / 32;
|
||||
|
||||
for (int l = line - 15; l <= line + 15; l++) {
|
||||
if (l >= 0 && l < 512) {
|
||||
for (int c = 0; c < 32; c++) {
|
||||
int64_t val = input_frame[(col * 32 + c) + l * RAW_MODULE_COLS];
|
||||
auto mask_val = mask[(col * 32 + c) + l * RAW_MODULE_COLS];
|
||||
valid_ref += mask_val;
|
||||
|
||||
if (mask_val == 0)
|
||||
val = 0;
|
||||
|
||||
sum_ref += val;
|
||||
sum2_ref += val * val;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (valid_ref != valid[i])
|
||||
valid_err++;
|
||||
|
||||
if (sum2_ref != sum2[i])
|
||||
sum2_err++;
|
||||
|
||||
if (sum_ref != sum[i]) {
|
||||
std::cout << i << " " << sum_ref << " " << sum[i] << " " << valid[i] << " " << valid_ref << std::endl;
|
||||
sum_err++;
|
||||
}
|
||||
}
|
||||
CHECK(sum_err == 0);
|
||||
CHECK(sum2_err == 0);
|
||||
CHECK(valid_err == 0);
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include "../receiver/JFJochReceiverTest.h"
|
||||
#include "../acquisition_device/HLSSimulatedDevice.h"
|
||||
#include "MockCardOutput.h"
|
||||
#include "../jungfrau/JFPedestalCalc.h"
|
||||
#include "../image_pusher/TestImagePusher.h"
|
||||
#include "../receiver/JFJochReceiverService.h"
|
||||
@@ -19,15 +19,11 @@ TEST_CASE("JFJochReceiverTest_Raw", "[JFJochReceiver]") {
|
||||
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
||||
.ImagesPerTrigger(100).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::NO_COMPRESSION);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
Logger logger("JFJochReceiverTest_Raw");
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -41,6 +37,31 @@ TEST_CASE("JFJochReceiverTest_Raw", "[JFJochReceiver]") {
|
||||
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");
|
||||
|
||||
@@ -51,15 +72,11 @@ TEST_CASE("JFJochReceiverTest_Conversion", "[JFJochReceiver]") {
|
||||
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
REQUIRE(x.IsGeometryTransformed());
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -94,12 +111,12 @@ TEST_CASE("JFJochReceiverTest_ForceCPUAzInt", "[JFJochReceiver]") {
|
||||
for (int i = 0; i < raw_image.size(); i++)
|
||||
raw_image[i] = 1000 + i % 1000;
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++)
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(i, 64));
|
||||
|
||||
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);
|
||||
@@ -136,7 +153,7 @@ TEST_CASE("JFJochReceiverTest_AzIntBinsExceedFPGA", "[JFJochReceiver]") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++)
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(i, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
PixelMask mask(x);
|
||||
TestImagePusher pusher(0);
|
||||
@@ -157,13 +174,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_NoGeomTransform", "[JFJochReceiver]") {
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
||||
.GeometryTransformation(false);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -187,13 +200,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_Poisson", "[JFJochReceiver]") {
|
||||
CompressionAlgorithm::BSHUF_ZSTD);
|
||||
x.LossyCompressionPoisson(1);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i, 64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -217,13 +226,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_Threshold", "[JFJochReceiver]") {
|
||||
CompressionAlgorithm::BSHUF_ZSTD);
|
||||
x.PixelValueLowThreshold(50);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i, 64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -246,13 +251,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_ApplyMask", "[JFJochReceiver]") {
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
||||
x.ApplyPixelMask(true).MaskChipEdges(true).MaskModuleEdges(true);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i, 64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -276,13 +277,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_Threshold_Summation", "[JFJochReceiver]
|
||||
CompressionAlgorithm::BSHUF_ZSTD);
|
||||
x.PixelValueLowThreshold(10);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i, 64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -305,13 +302,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_FixedGainG1", "[JFJochReceiver]") {
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
||||
.FixedGainG1(true);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -336,13 +329,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_FixedGainG1_onlyG1", "[JFJochReceiver]"
|
||||
.FixedGainG1(true);
|
||||
|
||||
std::vector<uint16_t> input(RAW_MODULE_SIZE*2, 0x4000 + 3000);
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask, input);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -366,13 +355,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_U16", "[JFJochReceiver]") {
|
||||
.BitDepthImage(16).PixelSigned(false);
|
||||
|
||||
REQUIRE(!x.IsPixelSigned());
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -398,13 +383,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_U8", "[JFJochReceiver]") {
|
||||
REQUIRE(!x.IsPixelSigned());
|
||||
REQUIRE(x.GetByteDepthImage() == 1);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -427,13 +408,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_I32", "[JFJochReceiver]") {
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
||||
.PixelSigned(true).BitDepthImage(32);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -455,13 +432,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_Summation2", "[JFJochReceiver]") {
|
||||
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD).Summation(2);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -484,13 +457,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_Summation7_CPU", "[JFJochReceiver]") {
|
||||
.ImagesPerTrigger(8).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD)
|
||||
.Summation(7).CPUSummation(true);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -515,13 +484,9 @@ TEST_CASE("JFJochReceiverTest_Conversion_StorageCell", "[JFJochReceiver]") {
|
||||
REQUIRE(x.GetImageNum() == 16);
|
||||
REQUIRE(x.GetStorageCellNumber() == 16);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -537,10 +502,10 @@ 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*nframes);
|
||||
|
||||
for (auto &i: pedestal_in) i = 16384 | 14000;
|
||||
std::vector<uint16_t> pedestal_in(RAW_MODULE_SIZE * distinct_frames);
|
||||
|
||||
// Predictable random number generator
|
||||
std::mt19937 g1(1900);
|
||||
@@ -560,15 +525,17 @@ TEST_CASE("JFJochReceiverTest_PedestalG1", "[JFJochReceiver]") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
test->CreateJFPackets(x, 1, nframes, 0, pedestal_in.data());
|
||||
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 * RAW_MODULE_SIZE);
|
||||
pc.AnalyzeImage(pedestal_in.data() + (i % distinct_frames) * RAW_MODULE_SIZE);
|
||||
|
||||
Logger logger("JFJochReceiverTest_PedestalG1");
|
||||
|
||||
@@ -594,8 +561,10 @@ 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*nframes), pedestal_in2(RAW_MODULE_SIZE*nframes);;
|
||||
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);
|
||||
@@ -625,10 +594,14 @@ TEST_CASE("JFJochReceiverTest_PedestalG2_storage_cell", "[JFJochReceiver]") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
auto test = std::make_unique<HLSSimulatedDevice>(i, nframes * 2);
|
||||
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, pedestal_in2.data() + j * RAW_MODULE_SIZE);
|
||||
test->CreateJFPackets(x, 2 * j + 2, 1, 0, pedestal_in.data() + j * RAW_MODULE_SIZE);
|
||||
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));
|
||||
@@ -636,7 +609,7 @@ TEST_CASE("JFJochReceiverTest_PedestalG2_storage_cell", "[JFJochReceiver]") {
|
||||
|
||||
JFPedestalCalc pc(x);
|
||||
for (int i = 0; i < nframes; i++)
|
||||
pc.AnalyzeImage(pedestal_in.data() + i * RAW_MODULE_SIZE);
|
||||
pc.AnalyzeImage(pedestal_in.data() + (i % distinct_frames) * RAW_MODULE_SIZE);
|
||||
|
||||
Logger logger("JFJochReceiverTest_PedestalG2_storage_cell");
|
||||
|
||||
@@ -660,10 +633,10 @@ 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*nframes);
|
||||
|
||||
for (auto &i: pedestal_in) i = 16384 | 14000;
|
||||
std::vector<uint16_t> pedestal_in(RAW_MODULE_SIZE * distinct_frames);
|
||||
|
||||
// Predictable random number generator
|
||||
std::mt19937 g1(1900);
|
||||
@@ -683,15 +656,17 @@ TEST_CASE("JFJochReceiverTest_PedestalG0", "[JFJochReceiver]") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
auto test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
test->CreateJFPackets(x, 1, nframes, 0, pedestal_in.data());
|
||||
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 * RAW_MODULE_SIZE);
|
||||
pc.AnalyzeImage(pedestal_in.data() + (i % distinct_frames) * RAW_MODULE_SIZE);
|
||||
|
||||
PixelMask mask(x);
|
||||
|
||||
@@ -732,13 +707,12 @@ TEST_CASE("JFJochReceiverTest_PedestalG0_StorageCell", "[JFJochReceiver]") {
|
||||
.ImagesPerTrigger(0).IncidentEnergy_keV(12.4);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
auto test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int i = 0; i < nframes; i++) {
|
||||
test->CreateJFPackets(x, i * 4 + 1, 1, 0, pedestal_in_0.data());
|
||||
test->CreateJFPackets(x, i * 4 + 2, 1, 0, pedestal_in_1.data());
|
||||
test->CreateJFPackets(x, i * 4 + 3, 1, 0, pedestal_in_2.data());
|
||||
test->CreateJFPackets(x, i * 4 + 4, 1, 0, pedestal_in_3.data());
|
||||
}
|
||||
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));
|
||||
|
||||
@@ -790,13 +764,12 @@ TEST_CASE("JFJochReceiverTest_PedestalFixedG1_StorageCell", "[JFJochReceiver]")
|
||||
REQUIRE(x.GetStorageCellNumber() == 4);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
auto test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int i = 0; i < nframes; i++) {
|
||||
test->CreateJFPackets(x, i * 4 + 1, 1, 0, pedestal_in_0.data());
|
||||
test->CreateJFPackets(x, i * 4 + 2, 1, 0, pedestal_in_1.data());
|
||||
test->CreateJFPackets(x, i * 4 + 3, 1, 0, pedestal_in_2.data());
|
||||
test->CreateJFPackets(x, i * 4 + 4, 1, 0, pedestal_in_3.data());
|
||||
}
|
||||
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));
|
||||
|
||||
@@ -840,7 +813,7 @@ TEST_CASE("JFJochReceiverTest_PedestalG1_NoFrames", "[JFJochReceiver]") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
auto test = std::make_unique<HLSSimulatedDevice>(i, nframes + 8);
|
||||
auto test = std::make_unique<MockAcquisitionDevice>(i, nframes + 8);
|
||||
test->CreateFinalPacket(x);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
@@ -875,19 +848,28 @@ TEST_CASE("JFJochReceiverTest_PacketLost_Raw", "[JFJochReceiver]") {
|
||||
|
||||
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<HLSSimulatedDevice>(i, 64);
|
||||
test->CreateJFPackets(x, 1, 1, 0, frame_in.data());
|
||||
test->CreateJFPackets(x, 1, 1, 1, frame_in.data());
|
||||
test->CreateJFPackets(x, 2, 1, 0, frame_in.data());
|
||||
test->CreateJFPackets(x, 2, 1, 1, frame_in.data());
|
||||
test->CreateJFPackets(x, 3, 1, 0, frame_in.data());
|
||||
test->CreateJFPackets(x, 3, 1, 1, frame_in.data());
|
||||
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, frame_in.data() + (i * 128 + j) * 4096);
|
||||
test->CreateJFPackets(x, 4, 1, 1, frame_in.data());
|
||||
test->CreateJFPacket(x, 4, j, 0, nullptr);
|
||||
test->CreateJFPackets(x, 4, 1, 1, nullptr);
|
||||
test->CreateFinalPacket(x);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
@@ -939,13 +921,15 @@ TEST_CASE("JFJochReceiverTest_Cancel", "[JFJochReceiver]") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
auto test = std::make_unique<HLSSimulatedDevice>(i, 64);
|
||||
test->CreateJFPackets(x, 1, 1, 0, frame_in.data());
|
||||
test->CreateJFPackets(x, 1, 1, 1, frame_in.data());
|
||||
test->CreateJFPackets(x, 2, 1, 0, frame_in.data());
|
||||
test->CreateJFPackets(x, 2, 1, 1, frame_in.data());
|
||||
test->CreateJFPackets(x, 3, 1, 0, frame_in.data());
|
||||
test->CreateJFPackets(x, 3, 1, 1, frame_in.data());
|
||||
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");
|
||||
@@ -958,13 +942,49 @@ TEST_CASE("JFJochReceiverTest_Cancel", "[JFJochReceiver]") {
|
||||
|
||||
service.Start(x, pixel_mask, &calib);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(60));
|
||||
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");
|
||||
|
||||
@@ -975,13 +995,9 @@ TEST_CASE("JFJochReceiverTest_EIGER", "[JFJochReceiver]") {
|
||||
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -1003,13 +1019,9 @@ TEST_CASE("JFJochReceiverTest_EIGER_8bit", "[JFJochReceiver]") {
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
||||
x.EigerBitDepth(8);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -1031,13 +1043,9 @@ TEST_CASE("JFJochReceiverTest_EIGER_32bit", "[JFJochReceiver]") {
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
||||
x.EigerBitDepth(32);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
@@ -1059,13 +1067,9 @@ TEST_CASE("JFJochReceiverTest_EIGER_conversion", "[JFJochReceiver]") {
|
||||
x.PedestalG0Frames(0).NumTriggers(1).UseInternalPacketGenerator(true)
|
||||
.ImagesPerTrigger(32).ImagesPerFile(10).IncidentEnergy_keV(12.4).Compression(CompressionAlgorithm::BSHUF_ZSTD);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++) {
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(i,64);
|
||||
aq_devices.Add(std::move(test));
|
||||
}
|
||||
|
||||
PixelMask mask(x);
|
||||
AcquisitionDeviceGroup aq_devices = ConvertingMocks(x, mask);
|
||||
|
||||
JFJochReceiverOutput output;
|
||||
bool ret;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <fstream>
|
||||
|
||||
#include "../receiver/JFJochReceiverTest.h"
|
||||
#include "../acquisition_device/HLSSimulatedDevice.h"
|
||||
#include "MockCardOutput.h"
|
||||
#include "../writer/HDF5Objects.h"
|
||||
#include "../receiver/JFJochReceiverService.h"
|
||||
#include "../preview/JFJochTIFF.h"
|
||||
@@ -50,13 +50,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index", "[JFJochReceiver]"
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -72,13 +76,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index", "[JFJochReceiver]"
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -142,7 +139,7 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_GPUStills", "[JFJoch
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
auto test = std::make_unique<MockAcquisitionDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
@@ -225,7 +222,7 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_GPUStills_writer_down", "[JFJochReceiver]")
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
auto test = std::make_unique<MockAcquisitionDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
aq_devices.Add(std::move(test));
|
||||
@@ -257,11 +254,10 @@ TEST_CASE("JFJochIntegrationTest_GPUStills_cancel_during_prepass", "[JFJochRecei
|
||||
// A cancel while the frames are held for the pre-pass ends the collection.
|
||||
Logger logger(Catch::getResultCapture().getCurrentTestName());
|
||||
|
||||
// Few images: after the cancel, the simulated FPGA still processes, at CPU speed, the frames it has already
|
||||
// taken in, which takes minutes for a long collection on a loaded machine. For the same reason, how long the
|
||||
// stop takes is not checked.
|
||||
// Fewer frames arrive than the pre-pass waits for, and no final packet: the frames stay held until the cancel.
|
||||
// How long the stop takes is not checked.
|
||||
DiffractionExperiment experiment(DetJF4M());
|
||||
experiment.ImagesPerTrigger(30).NumTriggers(1).UseInternalPacketGenerator(true)
|
||||
experiment.ImagesPerTrigger(30).NumTriggers(1).UseInternalPacketGenerator(false)
|
||||
.FilePrefix("gpu_stills_cancel").JungfrauConvPhotonCnt(false)
|
||||
.DetectorDistance_mm(75).BeamY_pxl(1136).BeamX_pxl(1090).IncidentEnergy_keV(12.4)
|
||||
.SetUnitCell(UnitCell{.a = 36.9, .b = 78.95, .c = 78.95, .alpha =90, .beta = 90, .gamma = 90});
|
||||
@@ -269,7 +265,10 @@ TEST_CASE("JFJochIntegrationTest_GPUStills_cancel_during_prepass", "[JFJochRecei
|
||||
PixelMask pixel_mask(experiment);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(0, 64));
|
||||
auto test = std::make_unique<MockAcquisitionDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->CreateJFPackets(experiment, 1, 10, m, nullptr);
|
||||
aq_devices.Add(std::move(test));
|
||||
|
||||
NonePusher pusher;
|
||||
JFJochReceiverService service(aq_devices, logger, pusher);
|
||||
@@ -278,7 +277,7 @@ TEST_CASE("JFJochIntegrationTest_GPUStills_cancel_during_prepass", "[JFJochRecei
|
||||
service.RugnuxLive(true, nullptr, 4, 60);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
service.Cancel(false);
|
||||
JFJochReceiverOutput receiver_out;
|
||||
@@ -323,13 +322,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_refinement", "[JFJoc
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -345,13 +348,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_refinement", "[JFJoc
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -416,13 +412,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_refinement_tetragona
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -438,13 +438,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_refinement_tetragona
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -504,13 +497,18 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_index_no_integration", "[JFJoc
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
settings.quick_integration = true; // asked for, and still not done
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -526,14 +524,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_index_no_integration", "[JFJoc
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
settings.quick_integration = true; // asked for, and still not done
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -603,13 +593,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_index_no_spots", "[JFJochRecei
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 20; // make sure there are zero spots possible
|
||||
settings.photon_count_threshold = 10000;
|
||||
settings.min_pix_per_spot = 5;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -625,13 +619,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_index_no_spots", "[JFJochRecei
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 20; // make sure there are zero spots possible
|
||||
settings.photon_count_threshold = 10000;
|
||||
settings.min_pix_per_spot = 5;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -684,13 +671,11 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_azint_2d", "[JFJochReceiver]") {
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom,
|
||||
DiffractionExperiment::DefaultDataProcessingSettings()));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -757,13 +742,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_FFT", "[JFJochReceiv
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -779,13 +768,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_FFT", "[JFJochReceiv
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -846,13 +828,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_FFTW", "[JFJochRecei
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -868,13 +854,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_FFTW", "[JFJochRecei
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -936,13 +915,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_FFT_reference", "[JF
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -958,13 +941,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_FFT_reference", "[JF
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -1026,13 +1002,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_FFT_wrong_reference"
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -1048,13 +1028,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_FFT_wrong_reference"
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -1120,13 +1093,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_grid", "[JFJochRecei
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -1142,13 +1119,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_grid", "[JFJochRecei
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -1224,13 +1194,17 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_32", "[JFJochReceive
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -1246,13 +1220,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_32", "[JFJochReceive
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -1313,12 +1280,15 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_min_pix_2", "[JFJoch
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 3;
|
||||
settings.min_pix_per_spot = 2;
|
||||
settings.max_pix_per_spot = 200;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
ZMQImagePuller puller(pusher.GetAddress()[0]);
|
||||
@@ -1329,11 +1299,6 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_crystal_spot_and_index_min_pix_2", "[JFJoch
|
||||
service.NumThreads(nthreads);
|
||||
service.Indexing(experiment.GetIndexingSettings());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 3;
|
||||
settings.min_pix_per_spot = 2;
|
||||
settings.max_pix_per_spot = 200;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -1449,13 +1414,11 @@ TEST_CASE("JFJochIntegrationTest_ZMQ_ROI", "[JFJochReceiver]") {
|
||||
}
|
||||
}
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom,
|
||||
DiffractionExperiment::DefaultDataProcessingSettings()));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
ZMQImagePuller puller(pusher.GetAddress()[0]);
|
||||
@@ -1523,7 +1486,7 @@ TEST_CASE("JFJochIntegrationTest_ZMQPreview", "[JFJochReceiver]") {
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(0, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(0, 64));
|
||||
|
||||
NonePusher pusher;
|
||||
|
||||
@@ -1587,7 +1550,7 @@ TEST_CASE("JFJochIntegrationTest_ZMQMetadata", "[JFJochReceiver]") {
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(0, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(0, 64));
|
||||
|
||||
NonePusher pusher;
|
||||
|
||||
@@ -1647,7 +1610,7 @@ TEST_CASE("JFJochIntegrationTest_HDF5FilePusher", "[JFJochReceiver]") {
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(0, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(0, 64));
|
||||
|
||||
HDF5FilePusher pusher;
|
||||
|
||||
@@ -1681,7 +1644,7 @@ TEST_CASE("JFJochIntegrationTest_HDF5FilePusher_republish", "[JFJochReceiver]")
|
||||
PixelMask pixel_mask(experiment);
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(0, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(0, 64));
|
||||
|
||||
HDF5FilePusher pusher(repub_addr);
|
||||
|
||||
@@ -1743,7 +1706,7 @@ TEST_CASE("JFJochIntegrationTest_HDF5FilePusher_Raw", "[JFJochReceiver]") {
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(0, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(0, 64));
|
||||
|
||||
HDF5FilePusher pusher;
|
||||
|
||||
@@ -1793,13 +1756,13 @@ TEST_CASE("JFJochIntegrationTest_TCP_crystal_no_processing", "[JFJochReceiver]")
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.enable = false;
|
||||
settings.indexing = true;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
TCPStreamPusher pusher("tcp://127.0.0.1:*", 1);
|
||||
TCPImagePuller puller(pusher.GetAddress()[0]);
|
||||
@@ -1813,9 +1776,6 @@ TEST_CASE("JFJochIntegrationTest_TCP_crystal_no_processing", "[JFJochReceiver]")
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.enable = false;
|
||||
settings.indexing = true;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -1870,13 +1830,17 @@ TEST_CASE("JFJochIntegrationTest_TCP_crystal_spot_and_index", "[JFJochReceiver]"
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
TCPStreamPusher pusher("tcp://127.0.0.1:*", 1);
|
||||
|
||||
@@ -1891,13 +1855,6 @@ TEST_CASE("JFJochIntegrationTest_TCP_crystal_spot_and_index", "[JFJochReceiver]"
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
@@ -1952,9 +1909,7 @@ TEST_CASE("JFJochIntegrationTest_TCP_calibration", "[JFJochReceiver]") {
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(0, 64));
|
||||
|
||||
TCPStreamPusher pusher("tcp://127.0.0.1:*", 1);
|
||||
|
||||
@@ -2012,13 +1967,17 @@ TEST_CASE("JFJochIntegrationTest_TCP_crystal_spot_and_index_single_file", "[JFJo
|
||||
ConvertedToRawGeometry(experiment, image_raw_geom.data(), image_conv.data());
|
||||
logger.Info("Loaded image");
|
||||
|
||||
// Setup acquisition device
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
std::unique_ptr<HLSSimulatedDevice> test = std::make_unique<HLSSimulatedDevice>(0, 64);
|
||||
for (int m = 0; m < experiment.GetModulesNum(); m++)
|
||||
test->SetInternalGeneratorFrame((uint16_t *) image_raw_geom.data() + m * RAW_MODULE_SIZE, m);
|
||||
|
||||
aq_devices.Add(std::move(test));
|
||||
// Setup acquisition device: the card writes the image, with the strong pixels of its spot finder
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
std::vector<CardImage> images;
|
||||
images.push_back(Int16Image(experiment, pixel_mask, image_raw_geom, settings));
|
||||
AcquisitionDeviceGroup aq_devices = MockDevices(experiment, images);
|
||||
|
||||
TCPStreamPusher pusher("tcp://127.0.0.1:*", 1);
|
||||
|
||||
@@ -2033,13 +1992,6 @@ TEST_CASE("JFJochIntegrationTest_TCP_crystal_spot_and_index_single_file", "[JFJo
|
||||
// No progress value at the start of measurement
|
||||
REQUIRE(!service.GetProgress().has_value());
|
||||
|
||||
SpotFindingSettings settings = DiffractionExperiment::DefaultDataProcessingSettings();
|
||||
settings.signal_to_noise_threshold = 2.5;
|
||||
settings.photon_count_threshold = 5;
|
||||
settings.min_pix_per_spot = 1;
|
||||
settings.max_pix_per_spot = 200;
|
||||
settings.high_resolution_limit = 2.0;
|
||||
settings.low_resolution_limit = 50.0;
|
||||
service.SetSpotFindingSettings(settings);
|
||||
|
||||
service.Start(experiment, pixel_mask, nullptr);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include "../broker/JFJochStateMachine.h"
|
||||
#include "../acquisition_device/HLSSimulatedDevice.h"
|
||||
#include "../acquisition_device/MockAcquisitionDevice.h"
|
||||
#include "../receiver/JFJochReceiverService.h"
|
||||
#include "../broker/OpenAPIConvert.h"
|
||||
#include "../broker/ModulePlacementConvert.h"
|
||||
@@ -278,7 +278,7 @@ TEST_CASE("JFJochStateMachine_AsyncStartFailure") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < experiment.GetDataStreamsNum(); i++)
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(i, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
RefusingImagePusher pusher;
|
||||
JFJochReceiverService receiver_service(aq_devices, logger, pusher);
|
||||
@@ -452,7 +452,7 @@ TEST_CASE("JFJochStateMachine_CancelledRunIsNotAnError") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < experiment.GetDataStreamsNum(); i++)
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(i, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
GatedPusher pusher;
|
||||
JFJochReceiverService receiver_service(aq_devices, logger, pusher);
|
||||
@@ -508,7 +508,7 @@ TEST_CASE("JFJochStateMachine_WriterFailureAtEndIsAnError") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < experiment.GetDataStreamsNum(); i++)
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(i, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
FinalizeFailingPusher pusher;
|
||||
JFJochReceiverService receiver_service(aq_devices, logger, pusher);
|
||||
@@ -563,7 +563,7 @@ TEST_CASE("JFJochStateMachine_PreflightRefusesBeforeStarting") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < experiment.GetDataStreamsNum(); i++)
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(i, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
PreflightRefusingPusher pusher;
|
||||
JFJochReceiverService receiver_service(aq_devices, logger, pusher);
|
||||
@@ -682,7 +682,7 @@ TEST_CASE("JFJochStateMachine_StartModulePlacement") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < experiment.GetDataStreamsNum(); i++)
|
||||
aq_devices.Add(std::make_unique<HLSSimulatedDevice>(i, 64));
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
StartMessageCapture pusher;
|
||||
JFJochReceiverService receiver_service(aq_devices, logger, pusher);
|
||||
JFJochServices services(logger);
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#pragma once
|
||||
|
||||
// What the FPGA card writes, precalculated on the CPU for the tests on MockAcquisitionDevice. It does not matter how
|
||||
// it is calculated here: that the mock gives the host what the card gives is checked against the HLS simulation in
|
||||
// MockAcquisitionDeviceTest.cpp.
|
||||
|
||||
#include "CheckImageOutput.h"
|
||||
#include "../acquisition_device/AcquisitionDeviceGroup.h"
|
||||
#include "../acquisition_device/MockAcquisitionDevice.h"
|
||||
#include "../common/PixelMask.h"
|
||||
#include "../image_analysis/spot_finding/DetModuleSpotFinder_cpu.h"
|
||||
#include "../receiver/JFJochReceiverTest.h"
|
||||
|
||||
// The card output of one image, one entry per module (absolute module number)
|
||||
using CardImage = std::vector<std::unique_ptr<DeviceOutput>>;
|
||||
|
||||
inline std::unique_ptr<DeviceOutput> OutputWithPixels(const uint16_t *pixels) {
|
||||
auto ret = std::make_unique<DeviceOutput>();
|
||||
memcpy(ret->pixels, pixels, RAW_MODULE_SIZE * sizeof(uint16_t));
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void StorePixels(DeviceOutput &output, const std::vector<int64_t> &values) {
|
||||
auto pixels = reinterpret_cast<T *>(output.pixels);
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++)
|
||||
pixels[i] = static_cast<T>(values[i]);
|
||||
}
|
||||
|
||||
// The values in the pixel format the card writes for the experiment
|
||||
inline void StorePixels(DeviceOutput &output, const DiffractionExperiment &x, const std::vector<int64_t> &values) {
|
||||
switch (x.GetByteDepthFPGA()) {
|
||||
case 1:
|
||||
x.IsPixelSigned() ? StorePixels<int8_t>(output, values) : StorePixels<uint8_t>(output, values);
|
||||
break;
|
||||
case 2:
|
||||
x.IsPixelSigned() ? StorePixels<int16_t>(output, values) : StorePixels<uint16_t>(output, values);
|
||||
break;
|
||||
default:
|
||||
x.IsPixelSigned() ? StorePixels<int32_t>(output, values) : StorePixels<uint32_t>(output, values);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Error and saturated pixels counted, the others summed, masked pixels left out; and the same for each ROI of
|
||||
// the experiment's ROI map (one bit per ROI)
|
||||
inline void PixelStatistics(DeviceOutput &output, const DiffractionExperiment &x, const PixelMask &mask,
|
||||
const std::vector<uint16_t> &experiment_roi_map, size_t module,
|
||||
const std::vector<int64_t> &values, int64_t err, int64_t sat) {
|
||||
std::vector<uint16_t> roi_map(RAW_MODULE_SIZE);
|
||||
ConvertedToRawGeometry(x, module, roi_map.data(), experiment_roi_map.data());
|
||||
const uint32_t *module_mask = mask.GetMaskRaw().data() + module * RAW_MODULE_SIZE;
|
||||
|
||||
auto &stats = output.module_statistics;
|
||||
stats.max_value = INT24_MIN;
|
||||
stats.min_value = INT24_MAX;
|
||||
for (int r = 0; r < FPGA_ROI_COUNT; r++)
|
||||
output.roi_counts[r].max_value = INT24_MIN;
|
||||
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++) {
|
||||
const int64_t v = values[i];
|
||||
if (module_mask[i] != 0) {
|
||||
stats.masked_pixels++;
|
||||
continue;
|
||||
}
|
||||
if (v == err)
|
||||
stats.err_pixels++;
|
||||
else if (v == sat)
|
||||
stats.saturated_pixels++;
|
||||
else {
|
||||
stats.pixel_sum += v;
|
||||
stats.max_value = std::max<int64_t>(stats.max_value, v);
|
||||
stats.min_value = std::min<int64_t>(stats.min_value, v);
|
||||
}
|
||||
|
||||
// roi_calc.cpp: the coordinates include the multipixels
|
||||
const int64_t line = i / RAW_MODULE_COLS + (i / RAW_MODULE_COLS / 256) * 2;
|
||||
const int64_t col = i % RAW_MODULE_COLS + (i % RAW_MODULE_COLS / 256) * 2;
|
||||
for (int r = 0; r < FPGA_ROI_COUNT; r++) {
|
||||
if (((roi_map[i] >> r) & 1) == 0 || v == err)
|
||||
continue;
|
||||
ROICount &roi = output.roi_counts[r];
|
||||
if (v != sat) {
|
||||
roi.sum += v;
|
||||
roi.sum2 += v * v;
|
||||
roi.good_pixels++;
|
||||
roi.sum_x_weighted += v * col;
|
||||
roi.sum_y_weighted += v * line;
|
||||
}
|
||||
roi.max_value = std::max<int64_t>(roi.max_value, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The strong pixels of the card's spot finder, by its CPU version, on the pixels in the output
|
||||
inline void FindStrongPixels(DeviceOutput &output, const DiffractionExperiment &x, const SpotFindingSettings &settings,
|
||||
size_t module) {
|
||||
std::vector<float> d_map(RAW_MODULE_SIZE), mean(RAW_MODULE_SIZE), stddev(RAW_MODULE_SIZE);
|
||||
std::vector<uint32_t> valid_count(RAW_MODULE_SIZE), strong_pixel(RAW_MODULE_SIZE);
|
||||
x.CalcSpotFinderResolutionMap(d_map.data(), module);
|
||||
switch (x.GetByteDepthFPGA()) {
|
||||
case 1:
|
||||
FindSpots<int8_t>(output, settings, d_map.data(), mean.data(), stddev.data(), valid_count.data(),
|
||||
strong_pixel.data());
|
||||
break;
|
||||
case 2:
|
||||
FindSpots<int16_t>(output, settings, d_map.data(), mean.data(), stddev.data(), valid_count.data(),
|
||||
strong_pixel.data());
|
||||
break;
|
||||
default:
|
||||
FindSpots<int32_t>(output, settings, d_map.data(), mean.data(), stddev.data(), valid_count.data(),
|
||||
strong_pixel.data());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// JUNGFRAU conversion of a raw image (all modules) as CheckImageOutput.h computes it; with host summation the card
|
||||
// converts single frames to 16 bit. With conversion, error and saturated pixels are counted from the conversion into
|
||||
// signed 32 bit, as the card counts them before the pixel is written in the image's format, where unsigned they have
|
||||
// one value; without, the card reads UINT16_MAX from the detector as saturated.
|
||||
inline CardImage ConvertedImage(const DiffractionExperiment &x, const JFCalibration &calib, const PixelMask &mask,
|
||||
const std::vector<uint16_t> &raw, size_t storage_cell = 0) {
|
||||
DiffractionExperiment card_x(x);
|
||||
if (x.IsCPUSummation())
|
||||
card_x.Summation(1).BitDepthImage(16);
|
||||
DiffractionExperiment signed_x(card_x);
|
||||
signed_x.PixelSigned(true).BitDepthImage(32);
|
||||
|
||||
const auto ref = ConversionRef(card_x, calib, raw.data(), x.GetModulesNum(), storage_cell);
|
||||
const auto ref_signed = ConversionRef(signed_x, calib, raw.data(), x.GetModulesNum(), storage_cell);
|
||||
const auto roi_map = x.ExportROIMap();
|
||||
|
||||
CardImage ret;
|
||||
std::vector<int64_t> values(RAW_MODULE_SIZE), stats_values(RAW_MODULE_SIZE);
|
||||
for (int m = 0; m < x.GetModulesNum(); m++) {
|
||||
for (size_t i = 0; i < RAW_MODULE_SIZE; i++) {
|
||||
const size_t pxl = m * RAW_MODULE_SIZE + i;
|
||||
values[i] = std::llround(ref[pxl]);
|
||||
if (x.IsJungfrauConvPhotonCnt())
|
||||
stats_values[i] = std::llround(ref_signed[pxl]);
|
||||
else
|
||||
stats_values[i] = (raw[pxl] == UINT16_MAX) ? INT32_MAX : values[i];
|
||||
}
|
||||
auto output = std::make_unique<DeviceOutput>();
|
||||
StorePixels(*output, card_x, values);
|
||||
PixelStatistics(*output, x, mask, roi_map, m, stats_values, INT32_MIN, INT32_MAX);
|
||||
ret.push_back(std::move(output));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// The card passing a signed 16-bit image (raw geometry, all modules) through, INT16_MIN marking an error and
|
||||
// INT16_MAX a saturated pixel, with the strong pixels of its spot finder
|
||||
inline CardImage Int16Image(const DiffractionExperiment &x, const PixelMask &mask, const std::vector<int16_t> &image,
|
||||
const SpotFindingSettings &settings) {
|
||||
const int64_t err = (x.GetByteDepthFPGA() == 4) ? INT32_MIN : INT16_MIN;
|
||||
const int64_t sat = (x.GetByteDepthFPGA() == 4) ? INT32_MAX : INT16_MAX;
|
||||
const auto roi_map = x.ExportROIMap();
|
||||
|
||||
CardImage ret;
|
||||
std::vector<int64_t> values(RAW_MODULE_SIZE);
|
||||
for (int m = 0; m < x.GetModulesNum(); m++) {
|
||||
for (int i = 0; i < RAW_MODULE_SIZE; i++) {
|
||||
const int16_t v = image[m * RAW_MODULE_SIZE + i];
|
||||
values[i] = (v == INT16_MIN) ? err : ((v == INT16_MAX) ? sat : v);
|
||||
}
|
||||
auto output = std::make_unique<DeviceOutput>();
|
||||
StorePixels(*output, x, values);
|
||||
PixelStatistics(*output, x, mask, roi_map, m, values, err, sat);
|
||||
FindStrongPixels(*output, x, settings, m);
|
||||
ret.push_back(std::move(output));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Frame F of the mock of data stream d writes images[F % images.size()]
|
||||
inline void SetOutputs(MockAcquisitionDevice &mock, const DiffractionExperiment &x, uint16_t data_stream,
|
||||
const std::vector<CardImage> &images) {
|
||||
for (size_t i = 0; i < images.size(); i++)
|
||||
for (int m = 0; m < x.GetModulesNum(data_stream); m++)
|
||||
mock.SetOutput(i, m, *images[i][x.GetFirstModuleOfDataStream(data_stream) + m]);
|
||||
}
|
||||
|
||||
// One mock per data stream
|
||||
inline AcquisitionDeviceGroup MockDevices(const DiffractionExperiment &x, const std::vector<CardImage> &images) {
|
||||
AcquisitionDeviceGroup ret;
|
||||
for (int d = 0; d < x.GetDataStreamsNum(); d++) {
|
||||
auto mock = std::make_unique<MockAcquisitionDevice>(d, 64);
|
||||
SetOutputs(*mock, x, d, images);
|
||||
ret.Add(std::move(mock));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// The mocks for JFJochReceiverTest(): the conversion of its raw image with its calibration, the pixel mask applied
|
||||
// if the experiment asks for it, one image per storage cell
|
||||
inline AcquisitionDeviceGroup ConvertingMocks(const DiffractionExperiment &x, const PixelMask &mask,
|
||||
std::vector<uint16_t> raw) {
|
||||
if (x.IsApplyPixelMask()) {
|
||||
for (int i = 0; i < raw.size(); i++)
|
||||
if (mask.GetMaskRaw().at(i) != 0)
|
||||
raw[i] = UINT16_MAX;
|
||||
}
|
||||
const JFCalibration calib = GeneratePedestalCalibration(x);
|
||||
std::vector<CardImage> images;
|
||||
for (int s = 0; s < x.GetStorageCellNumber(); s++)
|
||||
images.push_back(ConvertedImage(x, calib, mask, raw, s));
|
||||
return MockDevices(x, images);
|
||||
}
|
||||
|
||||
// The default raw image of JFJochReceiverTest()
|
||||
inline AcquisitionDeviceGroup ConvertingMocks(const DiffractionExperiment &x, const PixelMask &mask) {
|
||||
std::vector<uint16_t> raw(RAW_MODULE_SIZE * x.GetModulesNum());
|
||||
for (int i = 0; i < raw.size(); i++)
|
||||
raw[i] = i % 65536;
|
||||
return ConvertingMocks(x, mask, raw);
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "../receiver/JFJochReceiverService.h"
|
||||
#include "../image_pusher/ZMQWriterNotificationPuller.h"
|
||||
#include "../image_puller/TestImagePuller.h"
|
||||
#include "../acquisition_device/MockAcquisitionDevice.h"
|
||||
|
||||
TEST_CASE("StreamWriterTest_ZMQ", "[StreamWriter]") {
|
||||
RegisterHDF5Filter();
|
||||
@@ -27,7 +28,7 @@ TEST_CASE("StreamWriterTest_ZMQ", "[StreamWriter]") {
|
||||
JFModuleGainCalibration gain;
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++)
|
||||
aq_devices.AddHLSDevice(64);
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
JFJochReceiverService fpga_receiver_service(aq_devices, logger, pusher);
|
||||
@@ -83,7 +84,7 @@ TEST_CASE("StreamWriterTest_ZMQ_Update", "[StreamWriter]") {
|
||||
JFModuleGainCalibration gain;
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++)
|
||||
aq_devices.AddHLSDevice(64);
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -144,7 +145,7 @@ TEST_CASE("StreamWriterTest_ZMQ_Update_NoNotification", "[StreamWriter]") {
|
||||
JFModuleGainCalibration gain;
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++)
|
||||
aq_devices.AddHLSDevice(64);
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
@@ -208,7 +209,7 @@ TEST_CASE("StreamWriterTest_ZMQ_MasterAfterAllDataFiles", "[StreamWriter]") {
|
||||
|
||||
AcquisitionDeviceGroup aq_devices;
|
||||
for (int i = 0; i < x.GetDataStreamsNum(); i++)
|
||||
aq_devices.AddHLSDevice(64);
|
||||
aq_devices.Add(std::make_unique<MockAcquisitionDevice>(i, 64));
|
||||
|
||||
ZMQStream2Pusher pusher({"ipc://*", "ipc://*"});
|
||||
pusher.WriterNotificationSocket("ipc://*");
|
||||
|
||||
+10
-26
@@ -4,7 +4,6 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "../acquisition_device/PCIExpressDevice.h"
|
||||
#include "../acquisition_device/HLSSimulatedDevice.h"
|
||||
#include "../receiver/JFJochReceiverTest.h"
|
||||
#include "../tests/CheckImageOutput.h"
|
||||
#include "../common/print_license.h"
|
||||
@@ -13,7 +12,6 @@ void print_usage(Logger &logger) {
|
||||
logger.Info("Usage ./jfjoch_fpga_test {<options>} <path to repository>");
|
||||
logger.Info("Options:");
|
||||
logger.Info(" -v Verbose");
|
||||
logger.Info(" -H Simulation with C HLS model (doesn't require FPGA device)");
|
||||
logger.Info(" -E{<num>} EIGER detector mode (with optional bit depth: 8, 16, 32)");
|
||||
logger.Info(" -R Raw");
|
||||
logger.Info(" -S<num> Number of summed frames");
|
||||
@@ -57,7 +55,6 @@ int main(int argc, char **argv) {
|
||||
bool apply_pixel_mask = false;
|
||||
std::optional<int64_t> eiger_bit_depth;
|
||||
DetectorType detector_type = DetectorType::JUNGFRAU;
|
||||
bool hls_simulation = false;
|
||||
size_t send_buffer_size_MiB = 2048;
|
||||
std::optional<int64_t> lossy_compression_poisson;
|
||||
int64_t thresholding = 0;
|
||||
@@ -69,7 +66,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "s:i:m:N:P:vRIS:E::HB:q:T:cM0ZX:t:f:")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "s:i:m:N:P:vRIS:E::B:q:T:cM0ZX:t:f:")) != -1) {
|
||||
switch (opt) {
|
||||
case '0':
|
||||
compr = CompressionAlgorithm::NO_COMPRESSION;
|
||||
@@ -116,9 +113,6 @@ int main(int argc, char **argv) {
|
||||
eiger_bit_depth = atol(optarg);
|
||||
}
|
||||
break;
|
||||
case 'H':
|
||||
hls_simulation = true;
|
||||
break;
|
||||
case 'B':
|
||||
send_buffer_size_MiB = atol(optarg);
|
||||
break;
|
||||
@@ -213,26 +207,16 @@ int main(int argc, char **argv) {
|
||||
for (int m = 0; m < x.GetModulesNum(); m++)
|
||||
memcpy(input.data() + RAW_MODULE_SIZE * m, tmp.data(), RAW_MODULE_SIZE * sizeof(uint16_t));
|
||||
|
||||
if (hls_simulation) {
|
||||
if (nstreams != 1) {
|
||||
logger.Error("HLS simulation can work with only one device");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
auto tmp = std::make_unique<HLSSimulatedDevice>(0, 128);
|
||||
tmp->EnableLogging(&logger);
|
||||
aq_devices.Add(std::move(tmp));
|
||||
} else {
|
||||
if (nstreams > dev_name.size()) {
|
||||
logger.Error("Only {} data streams allowed on this platform", dev_name.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (nstreams > dev_name.size()) {
|
||||
logger.Error("Only {} data streams allowed on this platform", dev_name.size());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nstreams; i++) {
|
||||
auto tmp = std::make_unique<PCIExpressDevice>(i, dev_name[i]);
|
||||
tmp->EnableLogging(&logger);
|
||||
tmp->SetIPv4Address((i << 24) + 0x010a0a0a);
|
||||
aq_devices.Add(std::move(tmp));
|
||||
}
|
||||
for (int i = 0; i < nstreams; i++) {
|
||||
auto tmp = std::make_unique<PCIExpressDevice>(i, dev_name[i]);
|
||||
tmp->EnableLogging(&logger);
|
||||
tmp->SetIPv4Address((i << 24) + 0x010a0a0a);
|
||||
aq_devices.Add(std::move(tmp));
|
||||
}
|
||||
|
||||
std::atomic<bool> done = false;
|
||||
|
||||
Reference in new issue
Block a user