A bit of refactoring of FastWriter

This commit is contained in:
2020-04-19 18:25:34 +02:00
parent ec70382663
commit 5bc03f202d
2 changed files with 40 additions and 10 deletions
+2 -1
View File
@@ -6,7 +6,6 @@
#include <string>
#include <H5Cpp.h>
template <class B>
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();
+38 -9
View File
@@ -1,14 +1,24 @@
#include <BufferUtils.hpp>
#include "FastH5Writer.hpp"
#include "date.h"
#include <chrono>
#include <sstream>
extern "C"
{
#include "H5DOpublic.h"
}
template<>
FastH5Writer<uint16_t>::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<uint16_t>::FastH5Writer(
// auto file = H5::H5File(target_filename.c_str(), H5F_ACC_TRUNC);
}
template <class B>
void FastH5Writer<B>::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<B>::create_image_dataset()
"image", dataset_data_type, dataspace, dataset_properties);
}
template <class B>
void FastH5Writer<B>::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 <class B>
void FastH5Writer<B>::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());
}
}