diff --git a/common/DatasetSettings.cpp b/common/DatasetSettings.cpp index 3d7cc769..d42e6f39 100644 --- a/common/DatasetSettings.cpp +++ b/common/DatasetSettings.cpp @@ -51,8 +51,8 @@ DatasetSettings &DatasetSettings::NumTriggers(int64_t input) { DatasetSettings &DatasetSettings::PhotonEnergy_keV(float input) { check_finite("Energy (keV)", input); - check_min("Energy (keV)", input, MIN_ENERGY); - check_max("Energy (keV)", input, MAX_ENERGY); + check_min("Energy (keV)", input, MIN_ENERGY_KEV); + check_max("Energy (keV)", input, MAX_ENERGY_KEV); photon_energy_keV = input; return *this; } diff --git a/common/Definitions.h b/common/Definitions.h index b60c26d9..238da3bd 100644 --- a/common/Definitions.h +++ b/common/Definitions.h @@ -1,55 +1,51 @@ // SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only -#ifndef DEFINITIONS_H -#define DEFINITIONS_H +#pragma once #include "../fpga/pcie_driver/jfjoch_fpga.h" +#include +#include +#include #include -#define WVL_1A_IN_KEV 12.39854f +constexpr float WVL_1A_IN_KEV = 12.39854f; -#define CONVERTED_MODULE_LINES (514L) -#define CONVERTED_MODULE_COLS (1030L) -#define CONVERTED_MODULE_SIZE (CONVERTED_MODULE_LINES * CONVERTED_MODULE_COLS) -#define JUNGFRAU_PACKET_SIZE_BYTES (8192) +constexpr size_t CONVERTED_MODULE_LINES = 514; +constexpr size_t CONVERTED_MODULE_COLS = 1030; +constexpr size_t CONVERTED_MODULE_SIZE = CONVERTED_MODULE_LINES * CONVERTED_MODULE_COLS; +constexpr size_t JUNGFRAU_PACKET_SIZE_BYTES = 8192; -#define MIN_FRAME_TIME_JUNGFRAU_HALF_SPEED_IN_US 1000 -#define MIN_FRAME_TIME_JUNGFRAU_FULL_SPEED_IN_US 470 -#define MIN_FRAME_TIME_EIGER_IN_US 250 -#define MAX_COUNT_TIME_JUNGFRAU_IN_US 2000 +constexpr std::chrono::nanoseconds MIN_COUNT_TIME = std::chrono::microseconds(3); +constexpr std::chrono::nanoseconds MIN_STORAGE_CELL_DELAY = std::chrono::nanoseconds(2100); +constexpr std::chrono::nanoseconds MIN_FRAME_TIME_JUNGFRAU_HALF_SPEED = std::chrono::microseconds(1000); +constexpr std::chrono::nanoseconds MIN_FRAME_TIME_JUNGFRAU_FULL_SPEED = std::chrono::microseconds(470); +constexpr std::chrono::nanoseconds MIN_FRAME_TIME_EIGER = std::chrono::microseconds(250); +constexpr std::chrono::nanoseconds MAX_COUNT_TIME_JUNGFRAU = std::chrono::microseconds(2000); +constexpr std::chrono::nanoseconds FRAME_TIME_PEDE_G1G2 = std::chrono::microseconds(10*1000); -#define MIN_COUNT_TIME_IN_US 3 +constexpr float MIN_ENERGY_KEV = 0.001; +constexpr float MAX_ENERGY_KEV = 500.0; -#define MIN_STORAGE_CELL_DELAY_IN_NS 2100 +constexpr float DEFAULT_G0_FACTOR = 41.0f; +constexpr float DEFAULT_G1_FACTOR = -1.439f; +constexpr float DEFAULT_G2_FACTOR = -0.1145f; +constexpr float DEFAULT_HG0_FACTOR = 100.0f; -#define MIN_ENERGY 0.001 -#define MAX_ENERGY 500.0 +constexpr int MAX_SPOT_COUNT = 64 * 1024; -#define FRAME_TIME_PEDE_G1G2_IN_US (10*1000) +constexpr uint32_t MASK_PEDESTAL_G0_RMS_LIMIT = (1U<<4); -#define DEFAULT_G0_FACTOR (41.0) -#define DEFAULT_G1_FACTOR (-1.439) -#define DEFAULT_G2_FACTOR (-0.1145) -#define DEFAULT_HG0_FACTOR (100.0) +constexpr size_t PEDESTAL_MIN_IMAGE_COUNT = 128; +constexpr uint16_t PEDESTAL_WRONG = (UINT16_MAX); +constexpr size_t PEDESTAL_G0_WRONG_GAIN_ALLOWED_COUNT = 2; -#define MAX_SPOT_COUNT (64*1024) - -#define MASK_PEDESTAL_G0_RMS_LIMIT (1U<<4) - -#define PEDESTAL_MIN_IMAGE_COUNT 128 -#define PEDESTAL_WRONG (UINT16_MAX) -#define PEDESTAL_G0_WRONG_GAIN_ALLOWED_COUNT 2 - -#define MESSAGE_SIZE_FOR_START_END (256*1024*1024) // pessimistic highest value - -#define LAB6_CELL_A 4.156468f +constexpr size_t MESSAGE_SIZE_FOR_START_END = (256*1024*1024); // pessimistic highest value +constexpr float LAB6_CELL_A = 4.156468f; // Ice ring resolution taken from: // Moreau, Atakisi, Thorne, Acta Cryst D77, 2021, 540,554 // https://journals.iucr.org/d/issues/2021/04/00/tz5104/index.html constexpr std::array ICE_RING_RES_A = {3.895, 3.661, 3.438, 2.667, 2.249, 2.068, 1.947, 1.916, 1.882, 1.719, 1.522}; - -#endif //DEFINITIONS_H diff --git a/common/DetectorSettings.cpp b/common/DetectorSettings.cpp index b2c76677..c7b31e59 100644 --- a/common/DetectorSettings.cpp +++ b/common/DetectorSettings.cpp @@ -35,7 +35,7 @@ DetectorSettings &DetectorSettings::StorageCellStart(int64_t input) { } DetectorSettings &DetectorSettings::StorageCellDelay(const std::chrono::nanoseconds &input) { - check_min("Storage cell delay [ns]", input.count(), MIN_STORAGE_CELL_DELAY_IN_NS); + check_min("Storage cell delay [ns]", input.count(), MIN_STORAGE_CELL_DELAY.count()); storage_cell_delay = input; return *this; } @@ -82,7 +82,7 @@ DetectorSettings &DetectorSettings::FrameTime(const std::chrono::microseconds &i DetectorSettings &DetectorSettings::FrameTime(const std::chrono::microseconds &in_frame_time, const std::chrono::microseconds &in_count_time) { - check_min("Count time (us)", in_count_time.count(), MIN_COUNT_TIME_IN_US); + check_min("Count time (us)", in_count_time.count(), std::chrono::duration_cast(MIN_COUNT_TIME).count()); frame_time = in_frame_time; count_time = in_count_time; return *this; diff --git a/common/DetectorSettings.h b/common/DetectorSettings.h index c9fb4c87..fe4ccbd9 100644 --- a/common/DetectorSettings.h +++ b/common/DetectorSettings.h @@ -14,14 +14,14 @@ enum class DetectorTiming {Auto, Trigger, Burst, Gated}; class DetectorSettings { - std::chrono::microseconds frame_time_pedestalG1G2 = std::chrono::microseconds(FRAME_TIME_PEDE_G1G2_IN_US); + std::chrono::microseconds frame_time_pedestalG1G2 = std::chrono::duration_cast(FRAME_TIME_PEDE_G1G2); bool internal_fpga_packet_generator = false; int64_t internal_fpga_packet_generator_images = 1; int64_t storage_cells = 1; int64_t storage_cell_start = 15; - std::chrono::nanoseconds storage_cell_delay = std::chrono::nanoseconds{2100}; + std::chrono::nanoseconds storage_cell_delay = MIN_STORAGE_CELL_DELAY; std::chrono::nanoseconds detector_delay = std::chrono::nanoseconds{0}; int64_t pedestal_g0_frames = 0; int64_t pedestal_g1_frames = 0; diff --git a/common/DetectorSetup.cpp b/common/DetectorSetup.cpp index c6ae8c8b..9fd6a287 100644 --- a/common/DetectorSetup.cpp +++ b/common/DetectorSetup.cpp @@ -47,7 +47,7 @@ DetectorSetup::DetectorSetup(std::shared_ptr in_geometry, detector_type(in_detector_type), read_out_time(0), min_frame_time(std::chrono::milliseconds(1)), - min_count_time(std::chrono::microseconds(MIN_COUNT_TIME_IN_US)) { + min_count_time(std::chrono::duration_cast(MIN_COUNT_TIME)) { if (description.empty()) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, @@ -279,11 +279,11 @@ std::chrono::nanoseconds DetectorSetup::GetReadOutTime() const { std::chrono::microseconds DetectorSetup::GetMinFrameTime() const { switch (GetDetectorType()) { case DetectorType::EIGER: - return std::chrono::microseconds(MIN_FRAME_TIME_EIGER_IN_US); + return std::chrono::duration_cast(MIN_FRAME_TIME_EIGER); case DetectorType::JUNGFRAU: if (GetUDPInterfaceCount() == 1) - return std::chrono::microseconds(MIN_FRAME_TIME_JUNGFRAU_HALF_SPEED_IN_US); - return std::chrono::microseconds(MIN_FRAME_TIME_JUNGFRAU_FULL_SPEED_IN_US); + return std::chrono::duration_cast(MIN_FRAME_TIME_JUNGFRAU_HALF_SPEED); + return std::chrono::duration_cast(MIN_FRAME_TIME_JUNGFRAU_FULL_SPEED); case DetectorType::DECTRIS: return min_frame_time; default: diff --git a/common/DiffractionExperiment.cpp b/common/DiffractionExperiment.cpp index a2c014f9..847063ee 100644 --- a/common/DiffractionExperiment.cpp +++ b/common/DiffractionExperiment.cpp @@ -256,7 +256,7 @@ std::chrono::microseconds DiffractionExperiment::GetDetectorPeriod() const { case DetectorMode::PedestalG2: return detector_settings.GetFrameTimePedestalG1G2(); default: - return std::chrono::microseconds(MIN_FRAME_TIME_JUNGFRAU_FULL_SPEED_IN_US) * GetStorageCellNumber(); + return std::chrono::round(MIN_FRAME_TIME_JUNGFRAU_FULL_SPEED * GetStorageCellNumber()); } } @@ -1256,11 +1256,11 @@ DiffractionExperiment &DiffractionExperiment::ImportDetectorSettings(const Detec if (!input.GetCountTime().has_value()) { // implicit count time check_max("Frame time [us]", input.GetFrameTime().count(), - MAX_COUNT_TIME_JUNGFRAU_IN_US + std::chrono::duration_cast(detector.GetReadOutTime()).count()); + std::chrono::duration_cast(MAX_COUNT_TIME_JUNGFRAU + detector.GetReadOutTime()).count()); } else { // explicit count time check_max("Count time [us]", input.GetCountTime().value().count(), - MAX_COUNT_TIME_JUNGFRAU_IN_US); + std::chrono::duration_cast(MAX_COUNT_TIME_JUNGFRAU).count()); } if ((input.GetTiming() == DetectorTiming::Burst) || diff --git a/common/ImageFormatSettings.cpp b/common/ImageFormatSettings.cpp index 83e04309..488494ce 100644 --- a/common/ImageFormatSettings.cpp +++ b/common/ImageFormatSettings.cpp @@ -39,8 +39,8 @@ ImageFormatSettings &ImageFormatSettings::JungfrauConvFactor_keV(const std::opti if (!input.has_value() || (input.value() == 0.0f)) jungfrau_conversion_factor_keV = {}; else { - check_min("JUNGFRAU conversion factor (keV)", input.value(), MIN_ENERGY); - check_max("JUNGFRAU conversion factor (keV)", input.value(), MAX_ENERGY); + check_min("JUNGFRAU conversion factor (keV)", input.value(), MIN_ENERGY_KEV); + check_max("JUNGFRAU conversion factor (keV)", input.value(), MAX_ENERGY_KEV); jungfrau_conversion_factor_keV = input; } return *this; diff --git a/detector_control/SLSDetectorWrapper.cpp b/detector_control/SLSDetectorWrapper.cpp index bdfb1213..ae9035ba 100644 --- a/detector_control/SLSDetectorWrapper.cpp +++ b/detector_control/SLSDetectorWrapper.cpp @@ -369,8 +369,7 @@ void SLSDetectorWrapper::Configure(const DiffractionExperiment &experiment) { det.setStorageCellStart(experiment.GetStorageCellStart()); det.setNumberOfAdditionalStorageCells(experiment.GetStorageCellNumber() - 1); - det.setStorageCellDelay( - experiment.GetStorageCellDelay() - std::chrono::nanoseconds(MIN_STORAGE_CELL_DELAY_IN_NS)); + det.setStorageCellDelay(experiment.GetStorageCellDelay() - MIN_STORAGE_CELL_DELAY); if (experiment.IsUsingGainHG0()) det.setSettings(slsDetectorDefs::HIGHGAIN0); diff --git a/tests/DetectorSetupTest.cpp b/tests/DetectorSetupTest.cpp index 9315bae0..810134eb 100644 --- a/tests/DetectorSetupTest.cpp +++ b/tests/DetectorSetupTest.cpp @@ -169,10 +169,10 @@ TEST_CASE("DetectorSetup_LoadGainFile") { TEST_CASE("DetectorSetup_MaxFrameTime") { DetectorSetup s1(DetectorGeometryModular(8), DetectorType::JUNGFRAU); s1.UDPInterfaceCount(1); - REQUIRE(s1.GetMinFrameTime() == std::chrono::microseconds(MIN_FRAME_TIME_JUNGFRAU_HALF_SPEED_IN_US)); + REQUIRE(s1.GetMinFrameTime() == MIN_FRAME_TIME_JUNGFRAU_HALF_SPEED); s1.UDPInterfaceCount(2); - REQUIRE(s1.GetMinFrameTime() == std::chrono::microseconds(MIN_FRAME_TIME_JUNGFRAU_FULL_SPEED_IN_US)); + REQUIRE(s1.GetMinFrameTime() == MIN_FRAME_TIME_JUNGFRAU_FULL_SPEED); DetectorSetup s2(DetectorGeometryModular(8), DetectorType::EIGER); - REQUIRE(s2.GetMinFrameTime() == std::chrono::microseconds(MIN_FRAME_TIME_EIGER_IN_US)); + REQUIRE(s2.GetMinFrameTime() == MIN_FRAME_TIME_EIGER); } \ No newline at end of file diff --git a/tests/DiffractionExperimentTest.cpp b/tests/DiffractionExperimentTest.cpp index 285aca9c..e6ef6b35 100644 --- a/tests/DiffractionExperimentTest.cpp +++ b/tests/DiffractionExperimentTest.cpp @@ -407,7 +407,7 @@ TEST_CASE("DiffractionExperiment_FrameCountTime_JUNGFRAU_PedestalG1G2","[Diffrac REQUIRE(x.GetFrameTime() == 1000us); REQUIRE(x.GetFrameCountTime() == 1000us - 50us); x.Mode(DetectorMode::PedestalG1); - REQUIRE(x.GetFrameTime().count() == FRAME_TIME_PEDE_G1G2_IN_US); + REQUIRE(x.GetFrameTime() == FRAME_TIME_PEDE_G1G2); REQUIRE(x.GetFrameCountTime() == 1000us - 50us); }