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

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

130 lines
5.5 KiB
C++

// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <map>
#include <mutex>
#include <future>
#include <unistd.h>
#include "../common/Definitions.h"
#include "../common/DiffractionExperiment.h"
#include "../common/Logger.h"
#include "../common/PixelMask.h"
#include "../common/ThreadSafeFIFO.h"
#include "../jungfrau/JFCalibration.h"
#include "AcquisitionCounters.h"
#include "Completion.h"
#include "../fpga/pcie_driver/jfjoch_fpga.h"
#include "../common/NetworkAddressConvert.h"
#include "../common/AzimuthalIntegrationMapping.h"
struct AcquisitionDeviceStatistics {
uint64_t good_packets;
uint64_t packets_expected;
float efficiency;
uint64_t bytes_received;
time_t start_timestamp;
time_t end_timestamp;
uint64_t nmodules;
std::vector<uint64_t> packets_received_per_module;
};
class AcquisitionDevice {
std::chrono::time_point<std::chrono::system_clock> start_time;
std::chrono::time_point<std::chrono::system_clock> end_time;
int64_t expected_frames;
int64_t fpga_summation = 1;
virtual void Start(const DiffractionExperiment& experiment, uint32_t flags) = 0;
virtual void Finalize() {}; // do clean-up after action is done
virtual void StartSendingWorkRequests() {};
void SendWorkRequest(uint32_t handle);
protected:
AcquisitionCounters counters;
ThreadSafeFIFO<Completion> work_completion_queue;
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, MockAcquisitionDevice
// points these at plain heap buffers it owns.
std::vector<DeviceOutput *> buffer_device;
Logger *logger;
uint16_t data_stream;
uint32_t max_modules = 1;
// Module frames the card memory holds for the internal frame generator
uint64_t internal_generator_module_frames = 0;
// As frame_generator.cpp: the frames are in two HBM interfaces of hbm_size_bytes each
static uint64_t GeneratorModuleFrames(uint32_t hbm_size_bytes);
uint64_t mac_addr;
uint32_t ipv4_addr;
explicit AcquisitionDevice(uint16_t data_stream);
const DeviceOutput *GetDeviceOutput(size_t handle) const;
DeviceOutput *GetDeviceOutput(size_t handle);
virtual void HW_RunInternalGenerator(const FrameGeneratorConfig& config) = 0;
virtual void HW_SetSpotFinderParameters(const SpotFinderParameters &params) = 0;
public:
AcquisitionDevice(const AcquisitionDevice &other) = delete;
AcquisitionDevice &operator=(const AcquisitionDevice &other) = delete;
static constexpr const uint64_t HandleNotValid = UINT64_MAX;
virtual ~AcquisitionDevice() = default;
void StartAction(const DiffractionExperiment &experiment, uint32_t optional_flags = 0);
void PrepareAction(const DiffractionExperiment &experiment);
void WaitForActionComplete();
virtual void Cancel() = 0;
void EnableLogging(Logger *logger);
// Post measurement statistics - only guaranteed valid after WaitForActionComplete ends
uint64_t GetBytesReceived() const;
virtual DataCollectionStatus GetDataCollectionStatus() const;
virtual DeviceStatus GetDeviceStatus() const;
AcquisitionDeviceStatistics GetStatistics() const;
const DeviceOutput *GetDeviceOutput(size_t frame_number, uint16_t module_number) const;
void FrameBufferRelease(size_t frame_number, uint16_t module_number);
// Calibration
virtual void InitializeCalibration(const DiffractionExperiment &experiment, const JFCalibration &calib);
virtual void InitializeIntegrationMap(const DiffractionExperiment &experiment, const std::vector<uint16_t> &v,
const std::vector<float> &weights);
virtual void InitializeIntegrationMap(const uint16_t *map, const float *weights, size_t module_number);
virtual void InitializeSpotFinderResolutionMap(const float *data, size_t module_number);
virtual void InitializeROIMap(const uint16_t *map, size_t module_number);
void InitializeEmptyPixelMask(const DiffractionExperiment &experiment); // Empty Mask
void InitializePixelMask(const DiffractionExperiment &experiment, const PixelMask &mask_raw);
virtual void InitializePixelMask(const uint32_t *module_mask, size_t module_number);
void InitializeROIMap(const DiffractionExperiment& experiment, const std::vector<uint16_t>& raw_roi_map);
void InitializeDataProcessing(const DiffractionExperiment &experiment, const AzimuthalIntegrationMapping& azint);
const AcquisitionCounters& Counters() const;
void SetSpotFinderParameters(const SpotFindingSettings &settings);
virtual std::string GetIPv4Address() const;
virtual void SetIPv4Address(uint32_t ipv4_addr_network_order);
virtual std::string GetMACAddress() const;
virtual uint16_t GetUDPPort() const;
virtual int32_t GetNUMANode() const;
virtual void SetInternalGeneratorFrame(const uint16_t *input, size_t module_number) {}
AcquisitionDeviceNetConfig GetNetConfig() const;
virtual uint32_t GetExpectedDescriptorsPerModule() const = 0;
void RunInternalGenerator(const DiffractionExperiment& experiment);
// The module frame of the internal frame generator's images, throws if the card memory cannot hold it
void CheckInternalGeneratorFrame(size_t module_frame) const;
uint64_t GetInternalGeneratorModuleFrames() const { return internal_generator_module_frames; }
};