refactoring

This commit is contained in:
2026-05-28 23:22:22 +02:00
parent 22ee40c987
commit f07ecfda23
6 changed files with 105 additions and 6 deletions
@@ -73,6 +73,30 @@ void test_ctb_binary_file_size(Detector &det) {
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.dbit_reorder = true;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.dbit_offset = 16;
ctb_state.dbit_reorder = true;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
@@ -97,6 +121,34 @@ void test_ctb_binary_file_size(Detector &det) {
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.dbit_reorder = true;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.dbit_offset = 16;
ctb_state.dbit_reorder = true;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
@@ -116,11 +168,39 @@ void test_ctb_binary_file_size(Detector &det) {
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
ctb_state.dbit_offset = 16;
ctb_state.dbit_reorder = true;
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
ctb_state.dbit_offset = 16;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
ctb_state.dbit_reorder = true;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
ctb_state.dbit_offset = 16;
ctb_state.dbit_reorder = true;
ctb_state.dbit_list.clear();
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
}
{
acq::CTBStateGuard ctb_guard(det, ctb_state);
ctb_state.readout_mode = defs::ANALOG_ONLY;
@@ -39,7 +39,6 @@ void run(Detector &det, const AcquisitionState &acq_state,
void run(Detector &det, const AcquisitionState &acq_state,
const FileState &file_state, const CTBState &ctb_state) {
// CTBStateGuard ctb_guard(det, ctb_state);
FileStateGuard file_guard(det, file_state);
AcquisitionStateGuard acq_guard(det, acq_state);
run_acquisition(det);
@@ -31,6 +31,12 @@ inline void print_acquisition_state(const AcquisitionState &s) {
<< "\n Number of Frames: " << s.num_frames;
}
/**
* @brief RAII guard for restoring the acquisition state of a detector.
* The constructor saves the current acquisition state and sets a new state,
* while the destructor restores the original state.
*
*/
class AcquisitionStateGuard {
public:
explicit AcquisitionStateGuard(Detector &det,
@@ -24,6 +24,7 @@ struct CTBState {
uint32_t transceiver_mask;
};
/** an example of CTB config */
inline CTBState default_ctb_state(bool isAltera = false) {
return {defs::ANALOG_AND_DIGITAL, 5000, 6000, 288,
isAltera ? false : true, 0xFFFFFF00, 0xFF00FFFF, 0,
@@ -84,6 +85,12 @@ inline void print_ctb_state(const CTBState &s) {
<< "\n Transceiver Mask: " << ToStringHex(s.transceiver_mask);
}
/**
* @brief RAII guard for restoring the existing ctb configuration after a test.
*
* The constructor saves the current ctb config and sets a new config, while the
* destructor restores the original config.
*/
class CTBStateGuard {
public:
explicit CTBStateGuard(Detector &det, const CTBState &new_state)
@@ -138,7 +138,7 @@ defs::speedLevel get_readout_speed(const Detector &det) {
return det.getReadoutSpeed().tsquash("Inconsistent readout speed");
}
bool ten_giga(const Detector &det) {
bool get_ten_giga(const Detector &det) {
return det.getTenGiga().tsquash("Inconsistent 10Giga setting");
}
@@ -197,7 +197,7 @@ acq::EigerExpectedState build_eiger_specific_state(const Detector &det) {
acq::EigerExpectedState e;
e.rois = get_rois(det);
e.dynamic_range = get_dynamic_range(det);
e.ten_giga = ten_giga(det);
e.ten_giga = get_ten_giga(det);
e.exptime = get_exptime(det);
e.period = get_period(det);
e.threshold_energy =
@@ -219,7 +219,7 @@ acq::Mythen3ExpectedState build_mythen3_specific_state(const Detector &det) {
acq::Mythen3ExpectedState e;
e.rois = get_rois(det);
e.dynamic_range = get_dynamic_range(det);
e.ten_giga = ten_giga(det);
e.ten_giga = get_ten_giga(det);
e.period = get_period(det);
e.counter_mask = det.getCounterMask().tsquash(
"Inconsistent counter mask for Mythen3 detector");
@@ -272,8 +272,9 @@ build_detector_specific_state(const Detector &det,
case defs::CHIPTESTBOARD:
case defs::XILINX_CHIPTESTBOARD:
return build_ctb_specific_state(det, ctb_state);
default:
throw sls::RuntimeError("Unsupported detector type");
}
throw sls::RuntimeError("Unsupported detector type");
}
} // anonymous namespace
@@ -79,6 +79,12 @@ inline void print_file_state(const FileState &s) {
<< "\n Virtual File: " << get_virtual_file_name(s);
}
/**
* @brief RAII guard for restoring the file state of a detector.
*
* The constructor saves the current file state and sets a new state, while the
* destructor restores the original state.
*/
class FileStateGuard {
public:
explicit FileStateGuard(Detector &det, const FileState &new_state)