Add naive buffer implementation

This commit is contained in:
2020-04-27 16:05:21 +02:00
parent 2a58d0b521
commit 59a5edd9eb
3 changed files with 41 additions and 18 deletions
+3
View File
@@ -20,6 +20,9 @@ class SFWriter {
H5::DataSet daq_rec_dataset_;
H5::DataSet n_received_packets_dataset_;
std::unique_ptr<char[]> image_buffer_;
size_t image_buffer_count_;
public:
SFWriter(
const std::string& output_file,
+3
View File
@@ -29,6 +29,9 @@ namespace core_buffer {
const size_t BUFFER_RB_SIZE = 1000;
const int WRITER_ZMQ_IO_THREADS = 16;
// How many frames to buffer before flushing to file.
const size_t WRITER_BUFFER_SIZE = 100;
}
#endif //BUFFERCONFIG_HPP
+35 -18
View File
@@ -15,7 +15,8 @@ SFWriter::SFWriter(
const size_t n_modules) :
n_frames_(n_frames),
n_modules_(n_modules),
current_write_index_(0)
current_write_index_(0),
image_buffer_count_(0)
{
file_ = H5::H5File(output_file, H5F_ACC_TRUNC);
@@ -57,6 +58,10 @@ SFWriter::SFWriter(
"n_received_packets",
H5::PredType::NATIVE_UINT16,
metadata_dataspace);
image_buffer_ = make_unique<char[]>(
n_modules_ * MODULE_N_BYTES * WRITER_BUFFER_SIZE);
image_buffer_count_ = 0;
}
SFWriter::~SFWriter()
@@ -95,24 +100,36 @@ void SFWriter::write(shared_ptr<DetectorFrame> metadata, char* data) {
// buffer_space,
// disk_space);
hsize_t offset[] = {current_write_index_, 0, 0};
if (image_buffer_count_ < WRITER_BUFFER_SIZE) {
char* buffer = image_buffer_.get();
if( H5DOwrite_chunk(
image_dataset_.getId(),
H5P_DEFAULT,
0,
offset,
MODULE_N_BYTES * n_modules_,
data))
{
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Error while writing data to file at offset ";
error_message << current_write_index_ << "." << endl;
memcpy(
(buffer + image_buffer_count_),
data,
MODULE_N_BYTES * n_modules_);
throw runtime_error(error_message.str());
image_buffer_count_++;
} else {
hsize_t offset[] = {current_write_index_, 0, 0};
if( H5DOwrite_chunk(
image_dataset_.getId(),
H5P_DEFAULT,
0,
offset,
MODULE_N_BYTES * n_modules_ * WRITER_BUFFER_SIZE,
image_buffer_.get()))
{
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Error while writing data to file at offset ";
error_message << current_write_index_ << "." << endl;
throw runtime_error(error_message.str());
}
current_write_index_ += WRITER_BUFFER_SIZE;
image_buffer_count_ = 0;
}
current_write_index_++;
}