diff --git a/core-buffer/include/FastH5Writer.hpp b/core-buffer/include/FastH5Writer.hpp index 67249ba..6963e5c 100644 --- a/core-buffer/include/FastH5Writer.hpp +++ b/core-buffer/include/FastH5Writer.hpp @@ -6,7 +6,6 @@ #include #include -template class FastH5Writer { const uint16_t CHUNKING_FACTOR = 1; @@ -14,11 +13,13 @@ class FastH5Writer { const size_t n_frames_per_file_; const uint16_t y_frame_size_; const uint16_t x_frame_size_; + const size_t frame_bytes_size_; std::string current_output_filename_; H5::H5File current_output_file_; H5::DataSet current_image_dataset_; uint64_t current_pulse_id_; + size_t current_frame_index_; void create_image_dataset(); diff --git a/core-buffer/src/FastH5Writer.cpp b/core-buffer/src/FastH5Writer.cpp index 4045ca2..c0dea2f 100644 --- a/core-buffer/src/FastH5Writer.cpp +++ b/core-buffer/src/FastH5Writer.cpp @@ -1,14 +1,24 @@ +#include #include "FastH5Writer.hpp" +#include "date.h" +#include +#include +extern "C" +{ + #include "H5DOpublic.h" +} -template<> -FastH5Writer::FastH5Writer( +using namespace std; + +FastH5Writer::FastH5Writer( const size_t n_frames_per_file, const uint16_t y_frame_size, const uint16_t x_frame_size) : n_frames_per_file_(n_frames_per_file), y_frame_size_(y_frame_size), x_frame_size_(y_frame_size), + frame_bytes_size_(2 * y_frame_size * y_frame_size), current_output_filename_(""), current_output_file_(), current_image_dataset_(), @@ -19,8 +29,7 @@ FastH5Writer::FastH5Writer( // auto file = H5::H5File(target_filename.c_str(), H5F_ACC_TRUNC); } -template -void FastH5Writer::create_image_dataset() +void FastH5Writer::create_image_dataset() { hsize_t dataset_dimension[3] = {n_frames_per_file_, y_frame_size_, x_frame_size_}; @@ -41,14 +50,34 @@ void FastH5Writer::create_image_dataset() "image", dataset_data_type, dataspace, dataset_properties); } -template -void FastH5Writer::set_pulse_id(const uint64_t pulse_id) +void FastH5Writer::set_pulse_id(const uint64_t pulse_id) { current_pulse_id_ = pulse_id; + current_frame_index_ = BufferUtils::get_file_frame_index(pulse_id); } -template -void FastH5Writer::write_data(const char *buffer) +void FastH5Writer::write_data(const char *buffer) { - + hsize_t offset[3] = {current_frame_index_, 0, 0}; + + if(H5DOwrite_chunk( + current_image_dataset_.getId(), + H5P_DEFAULT, + 0, // Filters + offset, // Offset + frame_bytes_size_, + buffer)) + { + stringstream err_msg; + + using namespace date; + using namespace chrono; + err_msg << "[" << system_clock::now() << "]"; + err_msg << "[FastH5Writer::write_data]"; + // TODO: This error message is bad. Extract the real error from lib. + err_msg << " Error when writing to "; + err_msg << current_output_filename_; + + throw runtime_error(err_msg.str()); + } } \ No newline at end of file