mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-04 09:54:12 +02:00
Introduce tests for different steps
This commit is contained in:
@@ -134,14 +134,14 @@ TEST(JFH5Writer, test_step_pulse_id)
|
||||
runtime_error);
|
||||
}
|
||||
|
||||
TEST(JFH5Writer, test_writing_with_step)
|
||||
void test_writing_with_step(
|
||||
uint64_t start_pulse_id, uint64_t stop_pulse_id, size_t step)
|
||||
{
|
||||
size_t n_modules = 2;
|
||||
uint64_t start_pulse_id = 500;
|
||||
uint64_t stop_pulse_id = 599;
|
||||
// 50Hz test.
|
||||
auto n_images = 50;
|
||||
int step = 2;
|
||||
size_t n_modules = 3;
|
||||
|
||||
size_t n_images = 1;
|
||||
n_images += (stop_pulse_id / step);
|
||||
n_images -= start_pulse_id / step;
|
||||
|
||||
auto meta = get_test_block_metadata(start_pulse_id, stop_pulse_id, step);
|
||||
auto data = get_test_block_data(n_modules);
|
||||
@@ -159,7 +159,7 @@ TEST(JFH5Writer, test_writing_with_step)
|
||||
{
|
||||
JFH5Writer writer(
|
||||
"ignore.h5", "detector",
|
||||
n_modules, start_pulse_id, stop_pulse_id, 1);
|
||||
n_modules, start_pulse_id, stop_pulse_id, step);
|
||||
writer.write(meta.get(), (char*)(&data[0]));
|
||||
}
|
||||
|
||||
@@ -173,43 +173,64 @@ TEST(JFH5Writer, test_writing_with_step)
|
||||
ASSERT_EQ(dims[1], n_modules * MODULE_Y_SIZE);
|
||||
ASSERT_EQ(dims[2], MODULE_X_SIZE);
|
||||
|
||||
for (int i_image=0; i_image < n_images; i_image++) {
|
||||
for (int i_module=0; i_module<n_modules; i_module++) {
|
||||
|
||||
auto offset = i_image * MODULE_N_PIXELS;
|
||||
offset += i_module * MODULE_N_PIXELS;
|
||||
|
||||
for (int i_pixel=0; i_pixel<MODULE_N_PIXELS; i_pixel++) {
|
||||
ASSERT_EQ(data[offset + i_pixel], i_pixel % 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto pulse_id_data = make_unique<uint64_t[]>(n_images);
|
||||
auto pulse_id_dataset = reader.openDataSet("/data/detector/pulse_id");
|
||||
pulse_id_dataset.read(&pulse_id_data[0], H5::PredType::NATIVE_UINT64);
|
||||
pulse_id_dataset.getSpace().getSimpleExtentDims(dims);
|
||||
ASSERT_EQ(dims[0], n_images);
|
||||
ASSERT_EQ(dims[1], 1);
|
||||
|
||||
auto frame_index_data = make_unique<uint64_t[]>(n_images);
|
||||
auto frame_index_dataset = reader.openDataSet("/data/detector/frame_index");
|
||||
frame_index_dataset.read(&frame_index_data[0], H5::PredType::NATIVE_UINT64);
|
||||
frame_index_dataset.getSpace().getSimpleExtentDims(dims);
|
||||
ASSERT_EQ(dims[0], n_images);
|
||||
ASSERT_EQ(dims[1], 1);
|
||||
|
||||
auto daq_rec_data = make_unique<uint32_t[]>(n_images);
|
||||
auto daq_rec_dataset = reader.openDataSet("/data/detector/daq_rec");
|
||||
daq_rec_dataset.read(&daq_rec_data[0], H5::PredType::NATIVE_UINT32);
|
||||
daq_rec_dataset.getSpace().getSimpleExtentDims(dims);
|
||||
ASSERT_EQ(dims[0], n_images);
|
||||
ASSERT_EQ(dims[1], 1);
|
||||
|
||||
auto is_good_frame_data = make_unique<uint8_t[]>(n_images);
|
||||
auto is_good_frame_dataset =
|
||||
reader.openDataSet("/data/detector/is_good_frame");
|
||||
is_good_frame_dataset.read(
|
||||
&is_good_frame_data[0], H5::PredType::NATIVE_UINT8);
|
||||
is_good_frame_dataset.getSpace().getSimpleExtentDims(dims);
|
||||
ASSERT_EQ(dims[0], n_images);
|
||||
ASSERT_EQ(dims[1], 1);
|
||||
|
||||
uint64_t i_pulse = 0;
|
||||
for (uint64_t pulse_id=start_pulse_id;
|
||||
pulse_id<=stop_pulse_id;
|
||||
pulse_id++) {
|
||||
|
||||
ASSERT_EQ(pulse_id_data[pulse_id - start_pulse_id], pulse_id);
|
||||
ASSERT_EQ(frame_index_data[pulse_id - start_pulse_id], pulse_id + 10);
|
||||
ASSERT_EQ(daq_rec_data[pulse_id - start_pulse_id], pulse_id + 100);
|
||||
ASSERT_EQ(is_good_frame_data[pulse_id - start_pulse_id], 1);
|
||||
if (pulse_id % step != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSERT_EQ(pulse_id_data[i_pulse], pulse_id);
|
||||
ASSERT_EQ(frame_index_data[i_pulse], pulse_id + 10);
|
||||
ASSERT_EQ(daq_rec_data[i_pulse], pulse_id + 100);
|
||||
ASSERT_EQ(is_good_frame_data[i_pulse], 1);
|
||||
|
||||
i_pulse++;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(JFH5Writer, test_writing_with_step)
|
||||
{
|
||||
// 100Hz
|
||||
test_writing_with_step(500, 599, 1);
|
||||
// 50Hz
|
||||
test_writing_with_step(500, 598, 2);
|
||||
// 25Hz
|
||||
test_writing_with_step(500, 596, 4);
|
||||
// 10Hz
|
||||
test_writing_with_step(500, 590, 10);
|
||||
// 1Hz
|
||||
test_writing_with_step(500, 500, 100);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user