mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-07-13 15:12:22 +02:00
acquire moved out
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
target_sources(tests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test-SharedMemory.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/acquire/Acquire.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Caller/test-Caller.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Caller/test-Caller-rx.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Caller/test-Caller-rx-running.cpp
|
||||
|
||||
@@ -38,8 +38,9 @@ TEST_CASE("jungfrau_or_moench_acquire_check_file_size",
|
||||
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
|
||||
"inconsistent number of udp interfaces");
|
||||
|
||||
int num_frames_to_acquire = 2;
|
||||
acq::run(det, num_frames_to_acquire);
|
||||
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)
|
||||
{
|
||||
@@ -50,8 +51,7 @@ TEST_CASE("jungfrau_or_moench_acquire_check_file_size",
|
||||
par.nChipY * bytes_per_pixel) /
|
||||
num_udp_interfaces;
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
acq::default_file_state(), num_frames_to_acquire,
|
||||
expected_image_size));
|
||||
f, num_frames_to_acquire, expected_image_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,8 +70,9 @@ TEST_CASE("eiger_acquire_check_file_size",
|
||||
throw RuntimeError(
|
||||
"Eiger detector must have dynamic range 16 to test");
|
||||
}
|
||||
int num_frames_to_acquire = 2;
|
||||
acq::run(det, num_frames_to_acquire);
|
||||
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)
|
||||
{
|
||||
@@ -82,8 +83,7 @@ TEST_CASE("eiger_acquire_check_file_size",
|
||||
size_t expected_image_size =
|
||||
par.nChanX * par.nChanY * num_chips * bytes_per_pixel;
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
acq::default_file_state(), num_frames_to_acquire,
|
||||
expected_image_size));
|
||||
f, num_frames_to_acquire, expected_image_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,8 +104,9 @@ TEST_CASE("mythen3_acquire_check_file_size",
|
||||
"and counter mask 0x3 to test");
|
||||
}
|
||||
int num_counters = __builtin_popcount(counter_mask);
|
||||
int num_frames_to_acquire = 2;
|
||||
acq::run(det, num_frames_to_acquire);
|
||||
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)
|
||||
{
|
||||
@@ -116,8 +117,7 @@ TEST_CASE("mythen3_acquire_check_file_size",
|
||||
num_counters * par.nChipX *
|
||||
bytes_per_pixel;
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
acq::default_file_state(), num_frames_to_acquire,
|
||||
expected_image_size));
|
||||
f, num_frames_to_acquire, expected_image_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,8 +131,9 @@ TEST_CASE("gotthard2_acquire_check_file_size",
|
||||
|
||||
if (det_type == defs::GOTTHARD2) {
|
||||
|
||||
int num_frames_to_acquire = 2;
|
||||
acq::run(det, num_frames_to_acquire);
|
||||
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)
|
||||
{
|
||||
@@ -141,23 +142,23 @@ TEST_CASE("gotthard2_acquire_check_file_size",
|
||||
size_t expected_image_size =
|
||||
par.nChanX * par.nChipX * bytes_per_pixel;
|
||||
REQUIRE_NOTHROW(test_acquire_binary_file_size(
|
||||
acq::default_file_state(), num_frames_to_acquire,
|
||||
expected_image_size));
|
||||
f, num_frames_to_acquire, expected_image_size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_ctb_file_size_with_acquire(Detector &det, int64_t num_frames,
|
||||
const CTBState &test_info,
|
||||
const acq::CTBState &test_info,
|
||||
bool isXilinxCtb) {
|
||||
|
||||
acq::run(det, num_frames, test_info);
|
||||
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(
|
||||
acq::default_file_state(), num_frames, expected_image_size));
|
||||
REQUIRE_NOTHROW(
|
||||
test_acquire_binary_file_size(f, num_frames, expected_image_size));
|
||||
}
|
||||
|
||||
// disable for xilinx_ctb as it requires higher maximum receive buffer size
|
||||
@@ -172,8 +173,9 @@ TEST_CASE("ctb_acquire_check_file_size",
|
||||
|
||||
if (det_type == defs::CHIPTESTBOARD ||
|
||||
det_type == defs::XILINX_CHIPTESTBOARD) {
|
||||
bool isAltera = (det_type == defs::CHIPTESTBOARD);
|
||||
int num_frames_to_acquire = 2;
|
||||
bool isXilinxCtb = (det_type == defs::XILINX_CHIPTESTBOARD);
|
||||
bool isAltera = !isXilinxCtb;
|
||||
int64_t num_frames_to_acquire = 2;
|
||||
// all the test cases
|
||||
acq::CTBState ctb_state = acq::default_ctb_state(isAltera);
|
||||
ctb_state.readout_mode = defs::ANALOG_AND_DIGITAL;
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include "sls/logger.h"
|
||||
#include "tests/globals.h"
|
||||
|
||||
#include "acquire/Acquire.h"
|
||||
|
||||
namespace sls {
|
||||
|
||||
namespace acq = sls::test::acquire;
|
||||
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
void test_valid_port_caller(const std::string &command,
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "sls/sls_detector_defs.h"
|
||||
|
||||
#include "acquire/Acquire.h"
|
||||
#include "acquire/CTBState.h"
|
||||
#include "acquire/FileState.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#ifdef HDF5C
|
||||
#include "master_file/ReadersH5.h"
|
||||
#endif
|
||||
#include "acquire/Acquire.h"
|
||||
#include "acquire/FileState.h"
|
||||
#include "master_file/Checker.h"
|
||||
|
||||
#include "Caller.h"
|
||||
@@ -123,7 +121,7 @@ void test_master_file_image_size(const Detector &det, CheckerT &checker) {
|
||||
|
||||
case defs::CHIPTESTBOARD:
|
||||
case defs::XILINX_CHIPTESTBOARD: {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
image_size = calculate_ctb_image_size(
|
||||
test_info, (det_type == defs::XILINX_CHIPTESTBOARD))
|
||||
.first;
|
||||
@@ -154,7 +152,7 @@ void test_master_file_det_size(const Detector &det, CheckerT &checker) {
|
||||
portSize.x = nchan * num_counters;
|
||||
} else if (det_type == defs::CHIPTESTBOARD ||
|
||||
det_type == defs::XILINX_CHIPTESTBOARD) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
portSize.x = calculate_ctb_image_size(
|
||||
test_info, det_type == defs::XILINX_CHIPTESTBOARD)
|
||||
.second;
|
||||
@@ -456,7 +454,7 @@ void test_master_file_burst_mode(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_adc_mask(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_ctb_config{};
|
||||
acq::CTBState test_ctb_config = acq::default_ctb_state();
|
||||
auto adc_mask = test_ctb_config.adc_enable_10g;
|
||||
auto det_type = det.getDetectorType().squash();
|
||||
if (det_type == defs::CHIPTESTBOARD) {
|
||||
@@ -471,7 +469,7 @@ void test_master_file_adc_mask(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_analog_flag(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto romode = test_info.readout_mode;
|
||||
auto analog = static_cast<int>(
|
||||
(romode == defs::ANALOG_ONLY || romode == defs::ANALOG_AND_DIGITAL));
|
||||
@@ -482,7 +480,7 @@ void test_master_file_analog_flag(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_analog_samples(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto analog_samples = test_info.num_adc_samples;
|
||||
|
||||
REQUIRE_NOTHROW(checker.template check<int>(
|
||||
@@ -491,7 +489,7 @@ void test_master_file_analog_samples(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_digital_flag(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto romode = test_info.readout_mode;
|
||||
auto digital = static_cast<int>(romode == defs::DIGITAL_ONLY ||
|
||||
romode == defs::ANALOG_AND_DIGITAL ||
|
||||
@@ -503,7 +501,7 @@ void test_master_file_digital_flag(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_digital_samples(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto digital_samples = test_info.num_dbit_samples;
|
||||
|
||||
REQUIRE_NOTHROW(checker.template check<int>(
|
||||
@@ -512,7 +510,7 @@ void test_master_file_digital_samples(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_dbit_offset(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto dbit_offset = test_info.dbit_offset;
|
||||
|
||||
REQUIRE_NOTHROW(checker.template check<int>(
|
||||
@@ -521,7 +519,7 @@ void test_master_file_dbit_offset(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_dbit_reorder(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto dbit_reorder = test_info.dbit_reorder;
|
||||
|
||||
REQUIRE_NOTHROW(checker.template check<int>(
|
||||
@@ -530,7 +528,7 @@ void test_master_file_dbit_reorder(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_dbit_bitset(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
uint64_t dbit_bitset = 0;
|
||||
for (auto &i : test_info.dbit_list) {
|
||||
dbit_bitset |= (static_cast<uint64_t>(1) << i);
|
||||
@@ -542,7 +540,7 @@ void test_master_file_dbit_bitset(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_transceiver_mask(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto trans_mask = test_info.transceiver_mask;
|
||||
|
||||
REQUIRE_NOTHROW(checker.template check<int>(
|
||||
@@ -551,7 +549,7 @@ void test_master_file_transceiver_mask(const Detector &det, CheckerT &checker) {
|
||||
|
||||
template <typename CheckerT>
|
||||
void test_master_file_transceiver_flag(const Detector &det, CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto romode = test_info.readout_mode;
|
||||
auto trans = static_cast<int>(romode == defs::DIGITAL_AND_TRANSCEIVER ||
|
||||
romode == defs::TRANSCEIVER_ONLY);
|
||||
@@ -563,7 +561,7 @@ void test_master_file_transceiver_flag(const Detector &det, CheckerT &checker) {
|
||||
template <typename CheckerT>
|
||||
void test_master_file_transceiver_samples(const Detector &det,
|
||||
CheckerT &checker) {
|
||||
testCtbAcquireInfo test_info{};
|
||||
acq::CTBState test_info = acq::default_ctb_state();
|
||||
auto trans_samples = test_info.num_trans_samples;
|
||||
REQUIRE_NOTHROW(checker.template check<int>(
|
||||
MasterAttributes::N_TRANSCEIVER_SAMPLES.data(), trans_samples));
|
||||
@@ -716,7 +714,7 @@ rapidjson::Document parse_binary_master_attributes(std::string file_path) {
|
||||
std::string json_str = buffer.str();
|
||||
|
||||
rapidjson::Document doc;
|
||||
ParseResult result = doc.Parse(json_str.c_str());
|
||||
rapidjson::ParseResult result = doc.Parse(json_str.c_str());
|
||||
if (!result) {
|
||||
std::cout << "JSON parse error: " << GetParseError_En(result.Code())
|
||||
<< " (at offset " << result.Offset() << ")" << std::endl;
|
||||
@@ -737,9 +735,9 @@ TEST_CASE("check_master_file_attributes",
|
||||
Detector det;
|
||||
int64_t num_frames = 1;
|
||||
|
||||
acq::run(det, num_frames);
|
||||
std::string master_file_prefix =
|
||||
get_master_file_name_prefix(acq::default_file_state());
|
||||
auto f = acq::default_file_state();
|
||||
acq::run(det, num_frames, f);
|
||||
std::string master_file_prefix = acq::get_master_file_name_prefix(f);
|
||||
|
||||
// binary (/tmp/sls_test_master_0.json)
|
||||
std::string fname = master_file_prefix + ".json";
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
namespace sls {
|
||||
|
||||
namespace acq = sls::test::acquire;
|
||||
|
||||
using test::GET;
|
||||
using test::PUT;
|
||||
|
||||
@@ -835,10 +837,11 @@ TEST_CASE("rx_roi", "[.detectorintegration][.disable_check_data_file]") {
|
||||
// check master file creation
|
||||
// TODO: check roi in master file
|
||||
{
|
||||
REQUIRE_NOTHROW(create_files_for_acquire(det, caller));
|
||||
testFileInfo file_info;
|
||||
auto f = acq::default_file_state();
|
||||
int64_t num_frames = 1;
|
||||
REQUIRE_NOTHROW(acq::run(det, num_frames, f));
|
||||
std::string master_file_prefix =
|
||||
file_info.getMasterFileNamePrefix();
|
||||
acq::get_master_file_name_prefix(f);
|
||||
|
||||
std::string fname = master_file_prefix + ".json";
|
||||
REQUIRE(std::filesystem::exists(fname) == true);
|
||||
@@ -846,7 +849,7 @@ TEST_CASE("rx_roi", "[.detectorintegration][.disable_check_data_file]") {
|
||||
fname = master_file_prefix + ".h5";
|
||||
REQUIRE(std::filesystem::exists(fname) == true);
|
||||
if (det.size() > 1 || numinterfaces > 1) {
|
||||
fname = file_info.getVirtualFileName();
|
||||
fname = acq::get_virtual_file_name(f);
|
||||
REQUIRE(std::filesystem::exists(fname) == true);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,11 @@ void run_acquisition(Detector &det) {
|
||||
det.stopReceiver();
|
||||
}
|
||||
|
||||
void run(Detector &det, int64_t num_frames, const FileState &file_state) {
|
||||
auto ctb_state = default_ctb_state();
|
||||
run(det, num_frames, ctb_state, file_state);
|
||||
}
|
||||
|
||||
void run(Detector &det, int64_t num_frames, const CTBState &ctb_state,
|
||||
const FileState &file_state) {
|
||||
FrameGuard frame_guard(det, num_frames);
|
||||
@@ -42,7 +47,7 @@ void run(Detector &det, int64_t num_frames, const CTBState &ctb_state,
|
||||
auto binary_state = file_state;
|
||||
binary_state.file_format = defs::BINARY;
|
||||
FileStateGuard file_guard(det, binary_state);
|
||||
acquire(det);
|
||||
run_acquisition(det);
|
||||
auto frames_caught = det.getFramesCaught()[0][0];
|
||||
REQUIRE(frames_caught == num_frames);
|
||||
}
|
||||
@@ -53,7 +58,7 @@ void run(Detector &det, int64_t num_frames, const CTBState &ctb_state,
|
||||
auto h5_state = file_state;
|
||||
h5_state.file_format = defs::HDF5;
|
||||
FileStateGuard file_guard(det, h5_state);
|
||||
acquire(det);
|
||||
run_acquisition(det);
|
||||
auto frames_caught = det.getFramesCaught()[0][0];
|
||||
REQUIRE(frames_caught == num_frames);
|
||||
}
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
class FileState;
|
||||
class CTBState;
|
||||
class Detector;
|
||||
#include "sls/Detector.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace sls::test::acquire {
|
||||
|
||||
class FileState;
|
||||
class CTBState;
|
||||
|
||||
void wait_until_idle(const Detector &det);
|
||||
void run_acquisition(Detector &det);
|
||||
void run(Detector &det, int64_t num_frames = 1,
|
||||
const CTBState &ctb_state = default_ctb_state(),
|
||||
const FileState &file_state = default_file_state());
|
||||
void run(Detector &det, int64_t num_frames, const CTBState &ctb_state,
|
||||
const FileState &file_state);
|
||||
void run(Detector &det, int64_t num_frames, const FileState &file_state);
|
||||
|
||||
class FrameGuard {
|
||||
public:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "sls/Detector.h"
|
||||
#include "sls/logger.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
@@ -23,7 +24,7 @@ struct CTBState {
|
||||
uint32_t transceiver_mask;
|
||||
};
|
||||
|
||||
inline CTBState default_ctb_state(bool isAltera) {
|
||||
inline CTBState default_ctb_state(bool isAltera = false) {
|
||||
return {defs::ANALOG_AND_DIGITAL,
|
||||
isAltera ? false : true,
|
||||
5000,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "sls/Detector.h"
|
||||
#include "sls/logger.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -41,12 +42,14 @@ inline void set_file_state(Detector &det, const FileState &s) {
|
||||
det.setFileFormat(s.file_format);
|
||||
}
|
||||
|
||||
inline std::string get_master_file_name_prefix(const FileState &s) {
|
||||
inline std::string
|
||||
get_master_file_name_prefix(const FileState &s = default_file_state()) {
|
||||
return s.file_path + "/" + s.file_prefix + "_master_" +
|
||||
std::to_string(s.file_acq_index);
|
||||
}
|
||||
|
||||
inline std::string get_virtual_file_name(const FileState &s) {
|
||||
inline std::string
|
||||
get_virtual_file_name(const FileState &s = default_file_state()) {
|
||||
return s.file_path + "/" + s.file_prefix + "_virtual_" +
|
||||
std::to_string(s.file_acq_index) + ".h5";
|
||||
}
|
||||
@@ -61,18 +64,19 @@ inline void print_file_state(const FileState &s) {
|
||||
<< "\n Format: " << ToString(s.file_format)
|
||||
<< "\n Master File: " << get_master_file_name_prefix(s)
|
||||
<< "\n Virtual File: " << get_virtual_file_name(s);
|
||||
}
|
||||
|
||||
class FileStateGuard {
|
||||
public:
|
||||
explicit FileStateGuard(Detector &det, const FileState &new_state)
|
||||
: det(det), saved_(get_file_state(det)) {
|
||||
set_file_state(det, new_state);
|
||||
}
|
||||
~FileStateGuard() { set_file_state(det, saved_); }
|
||||
class FileStateGuard {
|
||||
public:
|
||||
explicit FileStateGuard(Detector &det, const FileState &new_state)
|
||||
: det(det), saved_(get_file_state(det)) {
|
||||
set_file_state(det, new_state);
|
||||
}
|
||||
~FileStateGuard() { set_file_state(det, saved_); }
|
||||
|
||||
private:
|
||||
Detector &det;
|
||||
FileState saved_;
|
||||
};
|
||||
private:
|
||||
Detector &det;
|
||||
FileState saved_;
|
||||
};
|
||||
|
||||
} // namespace sls::test::acquire
|
||||
Reference in New Issue
Block a user