Commit 819c629a authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

[IO] Refactor writer::write_view code

parent 1f3c3e80
......@@ -354,22 +354,28 @@ namespace io
hsize_t offset[] = {frame_idx, 0U, 0U};
uint32_t filter_mask = 0;
size_t elem_size = sizeof(typename View::value_type);
size_t data_size = v.size() * elem_size; //TODO Make this alignement aware but how?
using data_type = typename View::value_type;
size_t elem_size = sizeof(data_type);
size_t nb_elems = v.size();
size_t data_size = nb_elems * elem_size; //TODO Make this alignement aware but how?
const data_type* data_ptr = &v(0, 0);
if (elem_size != H5Tget_size(m_dtype))
LIMA_THROW_EXCEPTION(lima::runtime_error("View pixel / H5Tget_size mismatch"));
std::vector<unsigned char> comp_buffer;
switch (m_compression) {
case compression_enum::none: {
herr_t res = H5Dwrite_chunk(m_dset, H5P_DEFAULT, filter_mask, offset, data_size, &v(0, 0));
herr_t res = H5Dwrite_chunk(m_dset, H5P_DEFAULT, filter_mask, offset, data_size, data_ptr);
if (res < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("H5Dwrite_chunk error") << boost::errinfo_errno(res));
break;
}
case compression_enum::zip: {
#if defined(LIMA_ENABLE_ZLIB)
//Resize compression_enum buffer
uLong bound_size = compressBound(v.size() * H5Tget_size(m_dtype));
// Resize compression_enum buffer
uLong bound_size = compressBound(nb_elems * elem_size);
comp_buffer.resize(bound_size);
uLongf comp_size = comp_buffer.size();
......@@ -378,7 +384,7 @@ namespace io
// Compress
int ret =
compress2(comp_data, &comp_size, (const Bytef*) &v(0, 0), (uLong) data_size, compression_level);
compress2(comp_data, &comp_size, (const Bytef*) data_ptr, (uLong) data_size, compression_level);
if (ret != Z_OK)
LIMA_THROW_EXCEPTION(lima::runtime_error("compress2 error") << boost::errinfo_errno(ret));
......@@ -394,10 +400,10 @@ namespace io
}
case compression_enum::bshuf_lz4:
#if defined(LIMA_ENABLE_BSHUF_LZ4)
//Resize compression_enum buffer
unsigned int block_size =
0; //Process in blocks of this many elements. Pass 0 to select automatically(recommended).
size_t bound_size = bshuf_compress_lz4_bound(v.size(), H5Tget_size(m_dtype), block_size);
// Process in blocks of this many elements. Pass 0 to select automatically (recommended)
unsigned int block_size = 0;
// Resize compression_enum buffer
size_t bound_size = bshuf_compress_lz4_bound(nb_elems, elem_size, block_size);
comp_buffer.resize(bound_size);
size_t comp_size = comp_buffer.size();
......@@ -407,8 +413,7 @@ namespace io
bshuf_write_uint64_BE(comp_data, data_size);
bshuf_write_uint32_BE(comp_data + 8, block_size);
comp_size = bshuf_compress_lz4((const void*) &v(0, 0), (void*) (comp_data + 12), v.size(),
elem_size, block_size);
comp_size = bshuf_compress_lz4(data_ptr, comp_data + 12, nb_elems, elem_size, block_size);
LIMA_LOG(trace, io) << "BS/LZ4 compression_enum size = " << comp_size
<< " (ratio=" << ((double) data_size / (double) comp_size) << ")";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment