rough draft of test acquire of all detectors for frames caught and file size. ctb not included yet

This commit is contained in:
maliakal_d 2025-04-29 17:35:55 +02:00
parent e1f46d4747
commit adf0124ea3

View File

@ -12,6 +12,7 @@
#include <thread>
#include "tests/globals.h"
#include <filesystem>
namespace sls {
@ -3608,4 +3609,172 @@ TEST_CASE("sleep", "[.cmdcall]") {
REQUIRE_THROWS(caller.call("sleep", {}, -1, GET));
}
TEST_CASE("acquire_check_file_size", "[.cmdcall]") {
Detector det;
Caller caller(&det);
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types to test");
// save previous file state
auto file_write =
det.getFileWrite().tsquash("Inconsistent file write state");
auto file_overwrite =
det.getFileOverWrite().tsquash("Inconsistent file overwrite state");
auto file_format = det.getFileFormat().tsquash("Inconsistent file format");
auto file_path = det.getFilePath().tsquash("Inconsistent file path");
auto file_prefix =
det.getFileNamePrefix().tsquash("Inconsistent file prefix");
auto file_acq_index = det.getAcquisitionIndex().tsquash(
"Inconsistent file acquisition index");
// save previous det config state
auto timing_mode = det.getTimingMode().tsquash("Inconsistent timing mode");
auto num_frames =
det.getNumberOfFrames().tsquash("Inconsistent number of frames");
auto num_triggers =
det.getNumberOfTriggers().tsquash("Inconsistent number of triggers");
auto period = det.getPeriod().tsquash("Inconsistent period");
std::array<std::chrono::nanoseconds, 3> exptime{};
if (det_type != defs::MYTHEN3) {
exptime[0] = det.getExptime().tsquash("inconsistent exptime to test");
} else {
exptime =
det.getExptimeForAllGates().tsquash("inconsistent exptime to test");
}
// save previous specific det type config
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of udp interfaces");
auto n_rows = 0;
if (det_type == defs::EIGER || det_type == defs::JUNGFRAU ||
det_type == defs::MOENCH) {
n_rows =
det.getReadNRows().tsquash("inconsistent number of rows to test");
}
auto dynamic_range =
det.getDynamicRange().tsquash("inconsistent dynamic range to test");
uint32_t counter_mask = 0;
if (det_type == defs::MYTHEN3) {
counter_mask =
det.getCounterMask().tsquash("inconsistent counter mask to test");
}
int num_counters = __builtin_popcount(counter_mask);
// defaults
int num_frames_to_acquire = 2;
int bytes_per_pixel = 2;
// set default file state
det.setFileWrite(true);
det.setFileOverWrite(true);
det.setFileFormat(defs::BINARY);
det.setFilePath("/tmp");
det.setFileNamePrefix("sls_test");
det.setAcquisitionIndex(0);
// set default det config state
det.setTimingMode(defs::AUTO_TIMING);
det.setNumberOfFrames(num_frames_to_acquire);
det.setNumberOfTriggers(1);
det.setPeriod(std::chrono::milliseconds{2});
det.setExptime(-1, std::chrono::microseconds{200});
// set default specific det type config
if (det_type == defs::EIGER) {
det.setReadNRows(256);
} else if (det_type == defs::JUNGFRAU) {
det.setReadNRows(512);
} else if (det_type == defs::MOENCH) {
det.setReadNRows(400);
}
if (det_type == defs::EIGER || det_type == defs::MYTHEN3) {
det.setDynamicRange(bytes_per_pixel * 8);
}
if (det_type == defs::MYTHEN3) {
det.setCounterMask(0x1);
}
// acquire
REQUIRE_NOTHROW(caller.call("rx_start", {}, -1, PUT));
REQUIRE_NOTHROW(caller.call("start", {}, -1, PUT));
std::this_thread::sleep_for(std::chrono::seconds{1});
REQUIRE_NOTHROW(caller.call("rx_stop", {}, -1, PUT));
// check frames caught
auto frames_caught = det.getFramesCaught().tsquash(
"Inconsistent number of frames caught")[0];
REQUIRE(frames_caught == num_frames_to_acquire);
// check file size (assuming local pc)
size_t expected_image_size = 0;
switch (det_type) {
case defs::EIGER:
// pixels_row_per_chip * pixels_col_per_chip * num_chips *
// bytes_per_pixel
expected_image_size = 256 * 256 * 2 * bytes_per_pixel;
break;
case defs::JUNGFRAU:
// pixels_row_per_chip * pixels_col_per_chip * num_chips *
// bytes_per_pixel
if (num_udp_interfaces == 1) {
expected_image_size = 256 * 256 * 8 * bytes_per_pixel;
} else {
expected_image_size = 256 * 256 * 4 * bytes_per_pixel;
}
break;
case defs::MOENCH:
// pixels_row * pixels_col * bytes_per_pixel
if (num_udp_interfaces == 1) {
expected_image_size = 400 * 400 * bytes_per_pixel;
} else {
expected_image_size = 200 * 400 * bytes_per_pixel;
}
break;
case defs::GOTTHARD2:
// num_channels * num_chips
expected_image_size = 128 * 10 * bytes_per_pixel;
break;
case defs::MYTHEN3:
// num_channels * num_chips * num_counters
expected_image_size = 128 * 10 * num_counters * bytes_per_pixel;
break;
// to include ctb and xilinx_ctb
default:
break;
}
size_t expected_file_size =
num_frames_to_acquire *
(expected_image_size + sizeof(defs::sls_receiver_header));
std::string fname = file_path + "/" + file_prefix + "f0_" +
std::to_string(file_acq_index) + ".raw";
auto actual_file_size = std::filesystem::file_size(fname);
REQUIRE(actual_file_size == expected_file_size);
// restore to previous file state
det.setFileWrite(file_write);
det.setFileOverWrite(file_overwrite);
det.setFileFormat(file_format);
det.setFilePath(file_path);
det.setFileNamePrefix(file_prefix);
det.setAcquisitionIndex(file_acq_index);
// restore to previous det config state
det.setTimingMode(timing_mode);
det.setNumberOfFrames(num_frames);
det.setNumberOfTriggers(num_triggers);
det.setPeriod(period);
if (det_type != defs::MYTHEN3) {
det.setExptime(exptime[0]);
} else {
for (int iGate = 0; iGate < 3; ++iGate) {
det.setExptime(iGate, exptime[iGate]);
}
}
// restore previous specific det type config
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
det.setNumberofUDPInterfaces(num_udp_interfaces);
}
if (det_type == defs::EIGER || det_type == defs::MYTHEN3) {
det.setDynamicRange(dynamic_range);
}
if (det_type == defs::MYTHEN3) {
det.setCounterMask(counter_mask);
}
} // namespace sls