From 52d1f30a6aa227eecd37d4eb2c60636f8fe03f44 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Thu, 30 Apr 2026 10:27:17 +0200 Subject: [PATCH] JFJochReceiver: az_int_mapping is unique_ptr, so construction is explicit and can be profiled --- receiver/JFJochReceiver.cpp | 21 +++++++++++++-------- receiver/JFJochReceiver.h | 2 +- receiver/JFJochReceiverFPGA.cpp | 8 ++++---- receiver/JFJochReceiverLite.cpp | 4 ++-- tests/AzimuthalIntegrationTest.cpp | 10 ++++++++++ 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/receiver/JFJochReceiver.cpp b/receiver/JFJochReceiver.cpp index 1477b76d..153f193a 100644 --- a/receiver/JFJochReceiver.cpp +++ b/receiver/JFJochReceiver.cpp @@ -33,7 +33,6 @@ JFJochReceiver::JFJochReceiver(const DiffractionExperiment &in_experiment, serialmx_filter(in_experiment), numa_policy(in_numa_policy), pixel_mask(in_pixel_mask), - az_int_mapping(experiment, pixel_mask), indexer(experiment, indexing_thread_pool) { logger.Info("Initializing receiver"); // Ensure there is nothing running for now @@ -46,7 +45,13 @@ JFJochReceiver::JFJochReceiver(const DiffractionExperiment &in_experiment, current_status.SetEfficiency({}); current_status.SetStatus(JFJochReceiverStatus{}); // GetStatus() is virtual function and cannot be called yet! - plots.Setup(experiment, az_int_mapping); + auto start_time_point = std::chrono::steady_clock::now(); + az_int_mapping = std::make_unique(experiment, pixel_mask); + auto end_time_point = std::chrono::steady_clock::now(); + auto duration = std::chrono::duration(end_time_point - start_time_point); + logger.Info("Azimuthal integration mapping done in {:.5f} s", duration.count()); + + plots.Setup(experiment, *az_int_mapping); push_images_to_writer = (experiment.GetImageNum() > 0) && (!experiment.GetFilePrefix().empty()); @@ -110,12 +115,12 @@ void JFJochReceiver::SendStartMessage() { StartMessage message{}; experiment.FillMessage(message); message.arm_date = time_UTC(std::chrono::system_clock::now()); - message.az_int_q_bin_count = az_int_mapping.GetQBinCount(); - message.az_int_bin_to_q = az_int_mapping.GetBinToQ(); - message.az_int_bin_to_two_theta = az_int_mapping.GetBinToTwoTheta(); - message.az_int_phi_bin_count = az_int_mapping.GetAzimuthalBinCount(); - if (az_int_mapping.GetAzimuthalBinCount() > 1) - message.az_int_bin_to_phi = az_int_mapping.GetBinToPhi(); + message.az_int_q_bin_count = az_int_mapping->GetQBinCount(); + message.az_int_bin_to_q = az_int_mapping->GetBinToQ(); + message.az_int_bin_to_two_theta = az_int_mapping->GetBinToTwoTheta(); + message.az_int_phi_bin_count = az_int_mapping->GetAzimuthalBinCount(); + if (az_int_mapping->GetAzimuthalBinCount() > 1) + message.az_int_bin_to_phi = az_int_mapping->GetBinToPhi(); message.writer_notification_zmq_addr = image_pusher.GetWriterNotificationSocketAddress(); message.rois = experiment.ROI().ExportMetadata(); message.max_spot_count = experiment.GetMaxSpotCount(); diff --git a/receiver/JFJochReceiver.h b/receiver/JFJochReceiver.h index 82178d74..d415aadb 100644 --- a/receiver/JFJochReceiver.h +++ b/receiver/JFJochReceiver.h @@ -82,7 +82,7 @@ protected: std::vector> adu_histogram_module; PixelMask pixel_mask; - AzimuthalIntegration az_int_mapping; + std::unique_ptr az_int_mapping; std::optional max_delay; std::mutex max_delay_mutex; diff --git a/receiver/JFJochReceiverFPGA.cpp b/receiver/JFJochReceiverFPGA.cpp index d74e2e8c..a6efc0de 100644 --- a/receiver/JFJochReceiverFPGA.cpp +++ b/receiver/JFJochReceiverFPGA.cpp @@ -311,8 +311,8 @@ void JFJochReceiverFPGA::FrameTransformationThread(uint32_t threadid) { frame_transformation_ready.count_down(); - uint16_t az_int_min_bin = std::floor(az_int_mapping.QToBin(experiment.GetLowQForBkgEstimate_recipA())); - uint16_t az_int_max_bin = std::ceil(az_int_mapping.QToBin(experiment.GetHighQForBkgEstimate_recipA())); + uint16_t az_int_min_bin = std::floor(az_int_mapping->QToBin(experiment.GetLowQForBkgEstimate_recipA())); + uint16_t az_int_max_bin = std::ceil(az_int_mapping->QToBin(experiment.GetHighQForBkgEstimate_recipA())); int64_t image_number; while (images_to_go.Get(image_number) != 0) { @@ -340,7 +340,7 @@ void JFJochReceiverFPGA::FrameTransformationThread(uint32_t threadid) { ImageMetadata metadata(experiment); - AzimuthalIntegrationProfile az_int_profile_image(az_int_mapping); + AzimuthalIntegrationProfile az_int_profile_image(*az_int_mapping); auto local_spot_finding_settings = GetSpotFindingSettings(); @@ -678,5 +678,5 @@ void JFJochReceiverFPGA::LoadCalibrationToFPGA(uint16_t data_stream) { acquisition_device[data_stream].InitializeROIMap(experiment, roi_map); // Initialize data processing - acquisition_device[data_stream].InitializeDataProcessing(experiment, az_int_mapping); + acquisition_device[data_stream].InitializeDataProcessing(experiment, *az_int_mapping); } diff --git a/receiver/JFJochReceiverLite.cpp b/receiver/JFJochReceiverLite.cpp index f7e4029d..d8a33bf4 100644 --- a/receiver/JFJochReceiverLite.cpp +++ b/receiver/JFJochReceiverLite.cpp @@ -244,7 +244,7 @@ void JFJochReceiverLite::DataAnalysisThread(uint32_t id) { measurement_started.wait(); try { - analysis = std::make_unique(experiment, az_int_mapping, pixel_mask, indexer); + analysis = std::make_unique(experiment, *az_int_mapping, pixel_mask, indexer); } catch (const JFJochException &e) { Cancel(e); return; @@ -276,7 +276,7 @@ void JFJochReceiverLite::DataAnalysisThread(uint32_t id) { auto image_start_time = std::chrono::high_resolution_clock::now(); - AzimuthalIntegrationProfile profile(az_int_mapping); + AzimuthalIntegrationProfile profile(*az_int_mapping); analysis->Analyze(data_msg, profile, GetSpotFindingSettings()); auto image_end_time = std::chrono::high_resolution_clock::now(); diff --git a/tests/AzimuthalIntegrationTest.cpp b/tests/AzimuthalIntegrationTest.cpp index 0023254a..ad8e4b3c 100644 --- a/tests/AzimuthalIntegrationTest.cpp +++ b/tests/AzimuthalIntegrationTest.cpp @@ -19,6 +19,16 @@ TEST_CASE("AzimuthalIntegrationMapping_Constructor","[AzimuthalIntegration]") { REQUIRE_NOTHROW(radial = std::make_unique(x, pixel_mask)); } +TEST_CASE("AzimuthalIntegrationMapping_Create_16M","[AzimuthalIntegration]") { + DiffractionExperiment x(DetDECTRIS(2000, 2000, "E16M", "")); + x.DetectorDistance_mm(50).BeamX_pxl(1000).BeamY_pxl(1000); + x.QSpacingForAzimInt_recipA(0.1).QRangeForAzimInt_recipA(0.1, 10); + + PixelMask pixel_mask(x); + AzimuthalIntegration mapping(x, pixel_mask); + REQUIRE(mapping.GetBinNumber() == 99); +} + TEST_CASE("AzimuthalIntegrationMapping_GetBinNumber","[AzimuthalIntegration]") { DiffractionExperiment x(DetJF4M()); x.DetectorDistance_mm(50).BeamX_pxl(1000).BeamY_pxl(1000);