mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-07-31 11:23:38 +02:00
ctb fix with ctb state
This commit is contained in:
@@ -14,22 +14,22 @@ namespace sls {
|
||||
namespace acq = sls::test::acquire;
|
||||
namespace checks = sls::test::checks;
|
||||
|
||||
void acquire_and_check_file_size(Detector &det) {
|
||||
void acquire_and_check_file_size(
|
||||
Detector &det, const acq::CTBState &ctb_state = acq::default_ctb_state()) {
|
||||
auto acq_state = acq::default_acquisition_state();
|
||||
acq_state.num_frames = 2;
|
||||
auto file_state = acq::default_file_state();
|
||||
acq::run(det, acq_state, file_state);
|
||||
auto image_size = acq::get_expected_image_size(det);
|
||||
auto image_size = acq::get_expected_image_size(det, ctb_state);
|
||||
REQUIRE_NOTHROW(
|
||||
checks::check_binary_file_size(image_size, acq_state.num_frames));
|
||||
}
|
||||
|
||||
void test_ctb_binary_file_size(Detector &det) {
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
acq::CTBState ctb_state =
|
||||
acq::default_ctb_state(det_type == defs::CHIPTESTBOARD);
|
||||
bool isAltera =
|
||||
(det.getDetectorType().squash(defs::GENERIC) == defs::CHIPTESTBOARD);
|
||||
acq::CTBState ctb_state = acq::default_ctb_state(isAltera);
|
||||
// default ctb state for tests
|
||||
// readout mode = defs::ANALOG_AND_DIGITAL
|
||||
// analog samples = 5000
|
||||
// digital samples = 6000
|
||||
@@ -41,160 +41,188 @@ void test_ctb_binary_file_size(Detector &det) {
|
||||
// dbit list = {0, 12, 2, 43}
|
||||
// dbit reorder = false
|
||||
// trans mask = 0x3
|
||||
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.dbit_reorder = true;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.dbit_offset = 16;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.dbit_offset = 16;
|
||||
ctb_state.dbit_reorder = true;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.dbit_list.clear();
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.dbit_offset = 16;
|
||||
ctb_state.dbit_list.clear();
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.dbit_reorder = true;
|
||||
ctb_state.dbit_list.clear();
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.dbit_offset = 16;
|
||||
ctb_state.dbit_reorder = true;
|
||||
ctb_state.dbit_list.clear();
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
|
||||
ctb_state.dbit_offset = 16;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
|
||||
ctb_state.dbit_reorder = true;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
|
||||
ctb_state.dbit_offset = 16;
|
||||
ctb_state.dbit_reorder = true;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::DIGITAL_AND_TRANSCEIVER;
|
||||
ctb_state.dbit_list.clear();
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
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));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
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));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
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));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
|
||||
ctb_state.dbit_reorder = true;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
|
||||
ctb_state.dbit_offset = 16;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
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));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::TRANSCEIVER_ONLY;
|
||||
ctb_state.dbit_list.clear();
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
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));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
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));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
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));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
{
|
||||
acq::CTBStateGuard ctb_guard(det, ctb_state);
|
||||
ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::ANALOG_ONLY;
|
||||
ctb_state.dbit_offset = 16;
|
||||
ctb_state.dbit_reorder = true;
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det));
|
||||
acq::set_ctb_state(det, ctb_state);
|
||||
REQUIRE_NOTHROW(acquire_and_check_file_size(det, ctb_state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,6 +235,7 @@ TEST_CASE("acquire_check_binary_file_size",
|
||||
Detector det;
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::CHIPTESTBOARD ||
|
||||
det_type == defs::XILINX_CHIPTESTBOARD)
|
||||
test_ctb_binary_file_size(det);
|
||||
|
||||
@@ -102,7 +102,7 @@ void test_onchip_dac_caller(defs::dacIndex index, const std::string &dacname,
|
||||
std::pair<uint64_t, int>
|
||||
calculate_ctb_image_size(const acq::CTBState &test_info, bool isXilinxCtb) {
|
||||
|
||||
// test_info.print(); // for debugging
|
||||
LOG(logDEBUG1) << test_info;
|
||||
sls::CtbImageInputs inputs{};
|
||||
inputs.mode = test_info.readout_mode;
|
||||
inputs.nAnalogSamples = test_info.num_adc_samples;
|
||||
|
||||
@@ -26,9 +26,10 @@ inline void set_acquisition_state(Detector &det, const AcquisitionState &s) {
|
||||
det.setNumberOfFrames(s.num_frames);
|
||||
}
|
||||
|
||||
inline void print_acquisition_state(const AcquisitionState &s) {
|
||||
LOG(logINFO) << "Acquisition State:"
|
||||
<< "\n Number of Frames: " << s.num_frames;
|
||||
inline std::ostream &operator<<(std::ostream &os, const AcquisitionState &s) {
|
||||
os << "Acquisition State:"
|
||||
<< "\n Number of Frames: " << s.num_frames;
|
||||
return os;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,9 @@ inline CTBState default_ctb_state(bool isAltera = false) {
|
||||
{0, 12, 2, 43}, false, 0x3};
|
||||
}
|
||||
|
||||
inline CTBState get_ctb_state(const Detector &det, bool isAltera) {
|
||||
inline CTBState get_ctb_state(const Detector &det) {
|
||||
auto isAltera =
|
||||
(det.getDetectorType().squash(defs::GENERIC) == defs::CHIPTESTBOARD);
|
||||
return CTBState{
|
||||
det.getReadoutMode().tsquash("Inconsistent readout mode"),
|
||||
det.getNumberOfAnalogSamples().tsquash(
|
||||
@@ -54,7 +56,9 @@ inline CTBState get_ctb_state(const Detector &det, bool isAltera) {
|
||||
"Inconsistent transceiver mask")};
|
||||
}
|
||||
|
||||
inline void set_ctb_state(Detector &det, const CTBState &s, bool isAltera) {
|
||||
inline void set_ctb_state(Detector &det, const CTBState &s) {
|
||||
auto isAltera =
|
||||
(det.getDetectorType().squash(defs::GENERIC) == defs::CHIPTESTBOARD);
|
||||
det.setReadoutMode(s.readout_mode);
|
||||
if (isAltera) {
|
||||
det.setTenGiga(s.ten_giga);
|
||||
@@ -70,19 +74,25 @@ inline void set_ctb_state(Detector &det, const CTBState &s, bool isAltera) {
|
||||
det.setTransceiverEnableMask(s.transceiver_mask);
|
||||
}
|
||||
|
||||
inline void print_ctb_state(const CTBState &s) {
|
||||
LOG(logINFO) << "CTB State:"
|
||||
<< "\n Readout Mode: " << ToString(s.readout_mode)
|
||||
<< "\n Num ADC Samples: " << s.num_adc_samples
|
||||
<< "\n Num DBIT Samples: " << s.num_dbit_samples
|
||||
<< "\n Num Trans Samples: " << s.num_trans_samples
|
||||
<< "\n Ten Giga: " << s.ten_giga
|
||||
<< "\n ADC Enable 1G: " << ToStringHex(s.adc_enable_1g)
|
||||
<< "\n ADC Enable 10G: " << ToStringHex(s.adc_enable_10g)
|
||||
<< "\n DBIT Offset: " << s.dbit_offset
|
||||
<< "\n DBIT List: " << ToString(s.dbit_list)
|
||||
<< "\n DBIT Reorder: " << s.dbit_reorder
|
||||
<< "\n Transceiver Mask: " << ToStringHex(s.transceiver_mask);
|
||||
inline std::ostream &operator<<(std::ostream &os, const CTBState &s) {
|
||||
os << "CTB State:"
|
||||
<< "\n Readout Mode: " << ToString(s.readout_mode)
|
||||
<< "\n Num ADC Samples: " << s.num_adc_samples
|
||||
<< "\n Num DBIT Samples: " << s.num_dbit_samples
|
||||
<< "\n Num Trans Samples: " << s.num_trans_samples
|
||||
<< "\n Ten Giga: " << s.ten_giga
|
||||
<< "\n ADC Enable 1G: " << ToStringHex(s.adc_enable_1g)
|
||||
<< "\n ADC Enable 10G: " << ToStringHex(s.adc_enable_10g)
|
||||
<< "\n DBIT Offset: " << s.dbit_offset
|
||||
<< "\n DBIT List: " << ToString(s.dbit_list)
|
||||
<< "\n DBIT Reorder: " << s.dbit_reorder
|
||||
<< "\n Transceiver Mask: " << ToStringHex(s.transceiver_mask);
|
||||
return os;
|
||||
}
|
||||
|
||||
inline void print_current_ctb_state(const Detector &det) {
|
||||
auto ctb_state = get_ctb_state(det);
|
||||
LOG(logINFO) << ctb_state;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,17 +106,16 @@ class CTBStateGuard {
|
||||
explicit CTBStateGuard(Detector &det, const CTBState &new_state)
|
||||
: det(det) {
|
||||
auto type = det.getDetectorType().squash(defs::GENERIC);
|
||||
isAltera = (type == defs::CHIPTESTBOARD);
|
||||
active =
|
||||
(type == defs::CHIPTESTBOARD || type == defs::XILINX_CHIPTESTBOARD);
|
||||
if (active) {
|
||||
saved_ = get_ctb_state(det, isAltera);
|
||||
set_ctb_state(det, new_state, isAltera);
|
||||
saved_ = get_ctb_state(det);
|
||||
set_ctb_state(det, new_state);
|
||||
}
|
||||
}
|
||||
~CTBStateGuard() {
|
||||
if (active)
|
||||
set_ctb_state(det, saved_, isAltera);
|
||||
set_ctb_state(det, saved_);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -67,16 +67,15 @@ get_first_port_first_file_name(const FileState &s = default_file_state()) {
|
||||
return file_prefix + ".h5";
|
||||
}
|
||||
|
||||
inline void print_file_state(const FileState &s) {
|
||||
LOG(logINFO) << "File State:"
|
||||
<< "\n Path: " << s.file_path
|
||||
<< "\n Prefix: " << s.file_prefix
|
||||
<< "\n Acq Index: " << s.file_acq_index
|
||||
<< "\n Write: " << s.file_write
|
||||
<< "\n Overwrite: " << s.file_overwrite
|
||||
<< "\n Format: " << ToString(s.file_format)
|
||||
<< "\n Master File: " << get_master_file_name(s)
|
||||
<< "\n Virtual File: " << get_virtual_file_name(s);
|
||||
inline std::ostream &operator<<(std::ostream &os, const FileState &s) {
|
||||
os << "File State:"
|
||||
<< "\n Path: " << s.file_path << "\n Prefix: " << s.file_prefix
|
||||
<< "\n Acq Index: " << s.file_acq_index << "\n Write: " << s.file_write
|
||||
<< "\n Overwrite: " << s.file_overwrite
|
||||
<< "\n Format: " << ToString(s.file_format)
|
||||
<< "\n Master File: " << get_master_file_name(s)
|
||||
<< "\n Virtual File: " << get_virtual_file_name(s);
|
||||
return os;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user