mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-06 12:52:26 +02:00
wip, fixing acquire
This commit is contained in:
@@ -10,7 +10,9 @@
|
||||
|
||||
#include "acquire/Acquire.h"
|
||||
#include "acquire/CTBState.h"
|
||||
#include "acquire/ExpectedState.h"
|
||||
#include "acquire/FileState.h"
|
||||
#include "checks/MasterFileChecks.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
@@ -18,6 +20,7 @@
|
||||
namespace sls {
|
||||
|
||||
namespace acq = sls::test::acquire;
|
||||
namespace checks = sls::test::checks;
|
||||
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
@@ -25,140 +28,32 @@ using test::PUT;
|
||||
// disable for jungfrau as it requires higher maximum receive buffer size
|
||||
// sysctl net.core.rmem_max=$((100*1024*1024))
|
||||
// sysctl net.core.rmem_default=$((100*1024*1024))
|
||||
TEST_CASE("jungfrau_or_moench_acquire_check_file_size",
|
||||
TEST_CASE("acquire_check_binary_file_size",
|
||||
"[.detectorintegration][.disable_check_data_file]") {
|
||||
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
|
||||
|
||||
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
|
||||
"inconsistent number of udp interfaces");
|
||||
|
||||
int64_t num_frames_to_acquire = 2;
|
||||
auto f = acq::default_file_state();
|
||||
acq::run(det, num_frames_to_acquire, f);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
int bytes_per_pixel = det.getDynamicRange().squash() / 8;
|
||||
// if 2 udp interfaces, data split into half
|
||||
size_t expected_image_size = (par.nChanX * par.nChanY * par.nChipX *
|
||||
par.nChipY * bytes_per_pixel) /
|
||||
num_udp_interfaces;
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
f, num_frames_to_acquire, expected_image_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("eiger_acquire_check_file_size",
|
||||
"[.detectorintegration][.disable_check_data_file]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::EIGER) {
|
||||
|
||||
int dynamic_range = det.getDynamicRange().squash();
|
||||
if (dynamic_range != 16) {
|
||||
throw RuntimeError(
|
||||
"Eiger detector must have dynamic range 16 to test");
|
||||
}
|
||||
int64_t num_frames_to_acquire = 2;
|
||||
auto f = acq::default_file_state();
|
||||
acq::run(det, num_frames_to_acquire, f);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
// data split into half due to 2 udp interfaces per half module
|
||||
int num_chips = (par.nChipX / 2);
|
||||
int bytes_per_pixel = (dynamic_range / 8);
|
||||
size_t expected_image_size =
|
||||
par.nChanX * par.nChanY * num_chips * bytes_per_pixel;
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
f, num_frames_to_acquire, expected_image_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("mythen3_acquire_check_file_size",
|
||||
"[.detectorintegration][.disable_check_data_file]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::MYTHEN3) {
|
||||
|
||||
int dynamic_range = det.getDynamicRange().squash();
|
||||
int counter_mask = det.getCounterMask().squash();
|
||||
if (dynamic_range != 16 && counter_mask != 0x3) {
|
||||
throw RuntimeError("Mythen3 detector must have dynamic range 16 "
|
||||
"and counter mask 0x3 to test");
|
||||
}
|
||||
int num_counters = __builtin_popcount(counter_mask);
|
||||
int64_t num_frames_to_acquire = 2;
|
||||
auto f = acq::default_file_state();
|
||||
acq::run(det, num_frames_to_acquire, f);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
int bytes_per_pixel = dynamic_range / 8;
|
||||
int num_channels_per_counter = par.nChanX / 3;
|
||||
size_t expected_image_size = num_channels_per_counter *
|
||||
num_counters * par.nChipX *
|
||||
bytes_per_pixel;
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
f, num_frames_to_acquire, expected_image_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("gotthard2_acquire_check_file_size",
|
||||
"[.detectorintegration][.disable_check_data_file]") {
|
||||
Detector det;
|
||||
Caller caller(&det);
|
||||
auto det_type =
|
||||
det.getDetectorType().tsquash("Inconsistent detector types to test");
|
||||
|
||||
if (det_type == defs::GOTTHARD2) {
|
||||
|
||||
int64_t num_frames_to_acquire = 2;
|
||||
auto f = acq::default_file_state();
|
||||
acq::run(det, num_frames_to_acquire, f);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
{
|
||||
detParameters par(det_type);
|
||||
int bytes_per_pixel = det.getDynamicRange().squash() / 8;
|
||||
size_t expected_image_size =
|
||||
par.nChanX * par.nChipX * bytes_per_pixel;
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
f, num_frames_to_acquire, expected_image_size));
|
||||
}
|
||||
if (det_type == defs::CHIPTESTBOARD ||
|
||||
det_type == defs::XILINX_CHIPTESTBOARD) {
|
||||
// skip for CTB as it has different tests for file size
|
||||
return;
|
||||
}
|
||||
auto acq_state = acq::default_acquisition_state();
|
||||
acq_state.num_frames = 2;
|
||||
acq::run(det, acq_state);
|
||||
auto image_size = acq::get_expected_image_size(det);
|
||||
checks::check_binary_file_size(image_size, acq_state.num_frames);
|
||||
}
|
||||
|
||||
void test_ctb_file_size_with_acquire(Detector &det, int64_t num_frames,
|
||||
const acq::CTBState &test_info,
|
||||
bool isXilinxCtb) {
|
||||
|
||||
auto f = acq::default_file_state();
|
||||
acq::run(det, num_frames, test_info, f);
|
||||
|
||||
// check file size (assuming local pc)
|
||||
uint64_t expected_image_size =
|
||||
calculate_ctb_image_size(test_info, isXilinxCtb).first;
|
||||
REQUIRE_NOTHROW(
|
||||
test_acquire_binary_file_size(f, num_frames, expected_image_size));
|
||||
auto acq_state = acq::default_acquisition_state();
|
||||
acq_state.num_frames = num_frames;
|
||||
acq::run(det, acq_state);
|
||||
auto image_size = acq::get_expected_image_size(det, test_info);
|
||||
checks::check_binary_file_size(image_size, acq_state.num_frames);
|
||||
}
|
||||
|
||||
// disable for xilinx_ctb as it requires higher maximum receive buffer size
|
||||
|
||||
@@ -231,26 +231,32 @@ TEST_CASE("check_master_file_attributes",
|
||||
"[.detectorintegration][.disable_check_data_file]") {
|
||||
|
||||
Detector det;
|
||||
// currently num frame = 1 (default)
|
||||
auto acq_state = acq::default_acquisition_state();
|
||||
auto file_state = acq::default_file_state();
|
||||
|
||||
// binary => /tmp/sls_test_master_0.json
|
||||
file_state.file_format = defs::BINARY;
|
||||
acq::run(det, acq_state, file_state);
|
||||
// (/tmp/sls_test_master_0.json)
|
||||
// get json context
|
||||
std::string fname = acq::get_master_file_name(file_state);
|
||||
auto doc = parse_binary_master_attributes(fname);
|
||||
mf::Checker<mf::JsonContext> checker(mf::JsonContext{doc});
|
||||
acq::ExpectedState expected_state = acq::build_expected_state(det);
|
||||
// get expected state of parameters and check against master file
|
||||
acq::ExpectedState expected_state =
|
||||
acq::build_expected_state(det, acq_state, file_state);
|
||||
checks::check_metadata(checker, expected_state);
|
||||
|
||||
#ifdef HDF5C
|
||||
try {
|
||||
// hdf5 => /tmp/sls_test_master_0.h5
|
||||
file_state.file_format = defs::HDF5;
|
||||
acq::run(det, num_frames, file_state);
|
||||
// (/tmp/sls_test_master_0.h5)
|
||||
acq::run(det, acq_state, file_state);
|
||||
// get h5 context
|
||||
std::string fname = acq::get_master_file_name(file_state);
|
||||
mf::Checker<mf::H5Context> checker(mf::H5Context{fname});
|
||||
acq::ExpectedState expected_state = acq::build_expected_state(det);
|
||||
acq::ExpectedState expected_state =
|
||||
acq::build_expected_state(det, acq_state, file_state);
|
||||
checks::check_metadata(checker, expected_state);
|
||||
} catch (H5::Exception &e) {
|
||||
LOG(logERROR) << "HDF5 error: " << e.getDetailMsg();
|
||||
|
||||
@@ -12,10 +12,10 @@ namespace sls::test::acquire {
|
||||
|
||||
struct CTBState {
|
||||
defs::readoutMode readout_mode;
|
||||
bool ten_giga;
|
||||
int num_adc_samples;
|
||||
int num_dbit_samples;
|
||||
int num_trans_samples;
|
||||
bool ten_giga;
|
||||
uint32_t adc_enable_1g;
|
||||
uint32_t adc_enable_10g;
|
||||
int dbit_offset;
|
||||
@@ -25,30 +25,22 @@ struct CTBState {
|
||||
};
|
||||
|
||||
inline CTBState default_ctb_state(bool isAltera = false) {
|
||||
return {defs::ANALOG_AND_DIGITAL,
|
||||
isAltera ? false : true,
|
||||
5000,
|
||||
6000,
|
||||
288,
|
||||
0xFFFFFF00,
|
||||
0xFF00FFFF,
|
||||
0,
|
||||
{0, 12, 2, 43},
|
||||
false,
|
||||
0x3};
|
||||
return {defs::ANALOG_AND_DIGITAL, 5000, 6000, 288,
|
||||
isAltera ? false : true, 0xFFFFFF00, 0xFF00FFFF, 0,
|
||||
{0, 12, 2, 43}, false, 0x3};
|
||||
}
|
||||
|
||||
inline CTBState get_ctb_state(const Detector &det, bool isAltera) {
|
||||
return CTBState{
|
||||
det.getReadoutMode().tsquash("Inconsistent readout mode"),
|
||||
isAltera ? det.getTenGiga().tsquash("Inconsisten ten giga enable")
|
||||
: true,
|
||||
det.getNumberOfAnalogSamples().tsquash(
|
||||
"Inconsistent number of analog samples"),
|
||||
det.getNumberOfDigitalSamples().tsquash(
|
||||
"Inconsistent number of digital samples"),
|
||||
det.getNumberOfTransceiverSamples().tsquash(
|
||||
"Inconsistent number of transceiver samples"),
|
||||
isAltera ? det.getTenGiga().tsquash("Inconsisten ten giga enable")
|
||||
: true,
|
||||
isAltera
|
||||
? det.getADCEnableMask().tsquash("Inconsistent adc enable mask")
|
||||
: 0,
|
||||
@@ -80,10 +72,10 @@ inline void set_ctb_state(Detector &det, const CTBState &s, bool isAltera) {
|
||||
inline void print_ctb_state(const CTBState &s) {
|
||||
LOG(logINFO) << "CTB State:"
|
||||
<< "\n Readout Mode: " << ToString(s.readout_mode)
|
||||
<< "\n Ten Giga: " << s.ten_giga
|
||||
<< "\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
|
||||
|
||||
@@ -26,48 +26,6 @@ int get_dynamic_range(const Detector &det) {
|
||||
return det.getDynamicRange().tsquash("Inconsistent dynamic range");
|
||||
}
|
||||
|
||||
int get_image_size(const Detector &det) {
|
||||
auto det_type = get_detector_type(det);
|
||||
auto dynamic_range = get_dynamic_range(det);
|
||||
int bytes_per_pixel = dynamic_range / 8;
|
||||
int image_size = 0;
|
||||
detParameters par(det_type);
|
||||
|
||||
switch (det_type) {
|
||||
case defs::EIGER: {
|
||||
int num_chips = (par.nChipX / 2);
|
||||
image_size = par.nChanX * par.nChanY * num_chips * bytes_per_pixel;
|
||||
} break;
|
||||
case defs::JUNGFRAU:
|
||||
case defs::MOENCH: {
|
||||
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
|
||||
"inconsistent number of udp interfaces");
|
||||
image_size = (par.nChanX * par.nChanY * par.nChipX * par.nChipY *
|
||||
bytes_per_pixel) /
|
||||
num_udp_interfaces;
|
||||
} break;
|
||||
case defs::MYTHEN3: {
|
||||
int counter_mask = det.getCounterMask().squash();
|
||||
int num_counters = __builtin_popcount(counter_mask);
|
||||
int num_channels_per_counter = par.nChanX / MAX_NUM_COUNTERS;
|
||||
image_size = num_channels_per_counter * num_counters * par.nChipX *
|
||||
bytes_per_pixel;
|
||||
} break;
|
||||
case defs::GOTTHARD2: {
|
||||
image_size = par.nChanX * par.nChipX * bytes_per_pixel;
|
||||
} break;
|
||||
case defs::CHIPTESTBOARD:
|
||||
case defs::XILINX_CHIPTESTBOARD: {
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
image_size = sls::calculate_ctb_image_size(
|
||||
test_info, (det_type == defs::XILINX_CHIPTESTBOARD))
|
||||
.first;
|
||||
} break;
|
||||
default:
|
||||
throw sls::RuntimeError("Unsupported detector type for this test");
|
||||
}
|
||||
}
|
||||
|
||||
defs::xy get_port_shape(const Detector &det) {
|
||||
auto det_type = get_detector_type(det);
|
||||
auto portSize = det.getPortSize()[0];
|
||||
@@ -190,12 +148,13 @@ std::pair<ns, ns> get_sub_exptime_and_sub_period(const Detector& det) {
|
||||
return std::make_pair(ns(exptime), ns(sub_period));
|
||||
}
|
||||
|
||||
acq::CommonExpectedState build_common_state(const Detector& det) {
|
||||
acq::CommonExpectedState build_common_state(const Detector &det,
|
||||
const acq::CTBState &ctb_state) {
|
||||
acq::CommonExpectedState e;
|
||||
e.det_type = get_detector_type(det);
|
||||
e.timing_mode = det.getTimingMode().tsquash("Inconsistent timing mode");
|
||||
e.geometry = get_geometry(det);
|
||||
e.image_size = get_image_size(det);
|
||||
e.image_size = acq::get_expected_image_size(det, ctb_state);
|
||||
e.port_shape = get_port_shape(det);
|
||||
e.max_frames_per_file =
|
||||
det.getFramesPerFile().tsquash("Inconsistent frames per file");
|
||||
@@ -311,11 +270,53 @@ namespace sls::test::acquire {
|
||||
|
||||
ExpectedState build_expected_state(const Detector& det, const AcquisitionState &acq_state, const FileState &file_state, const CTBState &ctb_state) {
|
||||
ExpectedState e;
|
||||
e.common_state = build_common_state(det);
|
||||
e.common_state = build_common_state(det, ctb_state);
|
||||
e.file_state = file_state;
|
||||
e.acquisition_state = acq_state;
|
||||
e.detector_specific_state = build_detector_specific_state(det, ctb_state);
|
||||
return e;
|
||||
}
|
||||
|
||||
int get_expected_image_size(const Detector &det, const CTBState &ctb_state) {
|
||||
auto det_type = get_detector_type(det);
|
||||
auto dynamic_range = get_dynamic_range(det);
|
||||
int bytes_per_pixel = dynamic_range / 8;
|
||||
int image_size = 0;
|
||||
detParameters par(det_type);
|
||||
|
||||
switch (det_type) {
|
||||
case defs::EIGER: {
|
||||
int num_chips = (par.nChipX / 2);
|
||||
image_size = par.nChanX * par.nChanY * num_chips * bytes_per_pixel;
|
||||
} break;
|
||||
case defs::JUNGFRAU:
|
||||
case defs::MOENCH: {
|
||||
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
|
||||
"inconsistent number of udp interfaces");
|
||||
image_size = (par.nChanX * par.nChanY * par.nChipX * par.nChipY *
|
||||
bytes_per_pixel) /
|
||||
num_udp_interfaces;
|
||||
} break;
|
||||
case defs::MYTHEN3: {
|
||||
int counter_mask = det.getCounterMask().squash();
|
||||
int num_counters = __builtin_popcount(counter_mask);
|
||||
int num_channels_per_counter = par.nChanX / MAX_NUM_COUNTERS;
|
||||
image_size = num_channels_per_counter * num_counters * par.nChipX *
|
||||
bytes_per_pixel;
|
||||
} break;
|
||||
case defs::GOTTHARD2: {
|
||||
image_size = par.nChanX * par.nChipX * bytes_per_pixel;
|
||||
} break;
|
||||
case defs::CHIPTESTBOARD:
|
||||
image_size = sls::calculate_ctb_image_size(ctb_state, false).first;
|
||||
break;
|
||||
case defs::XILINX_CHIPTESTBOARD: {
|
||||
image_size = sls::calculate_ctb_image_size(ctb_state, true).first;
|
||||
} break;
|
||||
default:
|
||||
throw sls::RuntimeError("Unsupported detector type for this test");
|
||||
}
|
||||
return image_size;
|
||||
}
|
||||
|
||||
} // namespace sls::test::acquire
|
||||
@@ -18,8 +18,8 @@ struct CommonExpectedState {
|
||||
int image_size{};
|
||||
defs::xy port_shape{};
|
||||
int max_frames_per_file{};
|
||||
int frame_discard_policy{};
|
||||
int partial_frames_padding{};
|
||||
defs::frameDiscardPolicy frame_discard_policy{};
|
||||
bool partial_frames_padding{};
|
||||
defs::scanParameters scan_parameters{};
|
||||
uint64_t total_frames{};
|
||||
uint64_t frames_in_file{};
|
||||
@@ -106,6 +106,13 @@ const T& get_detector_specific_state(const ExpectedState& expected_state) {
|
||||
return std::get<T>(expected_state.detector_specific_state);
|
||||
}
|
||||
|
||||
template <typename T> bool is_type(const ExpectedState &e) {
|
||||
return std::holds_alternative<T>(e.detector_specific_state);
|
||||
}
|
||||
|
||||
ExpectedState build_expected_state(const Detector& det, const AcquisitionState &acq_state = default_acquisition_state(), const FileState &file_state = default_file_state(), const CTBState &ctb_state = default_ctb_state());
|
||||
|
||||
int get_expected_image_size(const Detector &det,
|
||||
const CTBState &ctb_state = default_ctb_state());
|
||||
|
||||
} // namespace sls::test::acquire
|
||||
@@ -58,6 +58,15 @@ get_virtual_file_name(const FileState &s = default_file_state()) {
|
||||
std::to_string(s.file_acq_index) + ".h5";
|
||||
}
|
||||
|
||||
inline std::string
|
||||
get_first_port_first_file_name(const FileState &s = default_file_state()) {
|
||||
auto file_prefix = s.file_path + "/" + s.file_prefix + "_" + "_d0_f0_" +
|
||||
std::to_string(s.file_acq_index);
|
||||
if (s.file_format == defs::BINARY)
|
||||
return file_prefix + ".bin";
|
||||
return file_prefix + ".h5";
|
||||
}
|
||||
|
||||
inline void print_file_state(const FileState &s) {
|
||||
LOG(logINFO) << "File State:"
|
||||
<< "\n Path: " << s.file_path
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user