Add block verification to writer

This commit is contained in:
2020-05-27 13:43:19 +02:00
parent ea5473846c
commit 468176adba
3 changed files with 16 additions and 6 deletions
+2 -1
View File
@@ -10,7 +10,8 @@ struct ImageMetadataBlock
uint64_t frame_index[core_buffer::BUFFER_BLOCK_SIZE];
uint32_t daq_rec[core_buffer::BUFFER_BLOCK_SIZE];
uint8_t is_good_image[core_buffer::BUFFER_BLOCK_SIZE];
uint64_t start_pulse_id;
uint64_t block_first_pulse_id;
uint64_t block_last_pulse_id;
};
const char BUFFER_FORMAT_START_BYTE = 0xBE;
+1 -1
View File
@@ -9,7 +9,7 @@
class JFH5Writer {
const size_t start_pulse_id_;
const uint64_t start_pulse_id_;
const uint64_t stop_pulse_id_;
const size_t n_modules_;
const size_t n_images_;
+13 -4
View File
@@ -118,13 +118,22 @@ void JFH5Writer::close_file()
void JFH5Writer::write(
const ImageMetadataBlock* metadata, const char* data)
{
// TODO: Implement proper block offsetting.
size_t n_images_offset = 0;
size_t n_images_to_copy = min(n_images_ - current_write_index_,
BUFFER_BLOCK_SIZE);
if (start_pulse_id_ > metadata->block_first_pulse_id) {
n_images_offset = start_pulse_id_ - metadata->block_first_pulse_id;
}
if (n_images_offset > BUFFER_BLOCK_SIZE) {
throw runtime_error("Received unexpected block for start_pulse_id.");
}
size_t n_images_to_copy = BUFFER_BLOCK_SIZE - n_images_offset;
if (stop_pulse_id_ < metadata->block_last_pulse_id) {
n_images_to_copy -= metadata->block_last_pulse_id - stop_pulse_id_;
}
if (n_images_to_copy < 1) {
return;
throw runtime_error("Received unexpected block for stop_pulse_id.");
}
hsize_t b_i_dims[3] = {n_images_to_copy,