diff --git a/core-buffer/include/formats.hpp b/core-buffer/include/formats.hpp index 80bea40..72222b0 100644 --- a/core-buffer/include/formats.hpp +++ b/core-buffer/include/formats.hpp @@ -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; diff --git a/sf-writer/include/JFH5Writer.hpp b/sf-writer/include/JFH5Writer.hpp index b8c559c..6d51341 100644 --- a/sf-writer/include/JFH5Writer.hpp +++ b/sf-writer/include/JFH5Writer.hpp @@ -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_; diff --git a/sf-writer/src/JFH5Writer.cpp b/sf-writer/src/JFH5Writer.cpp index 3d0b7d5..dcff400 100644 --- a/sf-writer/src/JFH5Writer.cpp +++ b/sf-writer/src/JFH5Writer.cpp @@ -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,