Commit a83cf488 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

[IO] Add h5::prop_list wrapper

parent aa97b21c
......@@ -16,6 +16,7 @@
#include <lima/io/h5/wrapper/dataspace.hpp>
#include <lima/io/h5/wrapper/datatype.hpp>
#include <lima/io/h5/wrapper/path.hpp>
#include <lima/io/h5/wrapper/prop_list.hpp>
namespace lima
{
......
......@@ -22,6 +22,7 @@ namespace io
using unique_group_hid_t = unique_handle<hid_t, decltype(&::H5Gclose), ::H5Gclose, raii::not_negative>;
using unique_attribute_hid_t = unique_handle<hid_t, decltype(&::H5Aclose), ::H5Aclose, raii::not_negative>;
using unique_type_hid_t = unique_handle<hid_t, decltype(&::H5Tclose), ::H5Tclose, raii::not_negative>;
using unique_prop_list_hid_t = unique_handle<hid_t, decltype(&::H5Pclose), ::H5Pclose, raii::not_negative>;
using shared_file_hid_t = shared_handle<unique_file_hid_t>;
using shared_dataset_hid_t = shared_handle<unique_dataset_hid_t>;
......@@ -29,6 +30,7 @@ namespace io
using shared_group_hid_t = shared_handle<unique_group_hid_t>;
using shared_attribute_hid_t = shared_handle<unique_attribute_hid_t>;
using shared_type_hid_t = shared_handle<unique_type_hid_t>;
using shared_prop_list_hid_t = shared_handle<unique_prop_list_hid_t>;
} //namespace h5
} //namespace io
......
// Copyright (C) 2020 Alejandro Homs Puron, ESRF.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include <string>
#include <type_traits>
#include <hdf5.h>
#include <lima/exceptions.hpp>
#include <lima/io/h5/wrapper/errinfo.hpp>
#include <lima/io/h5/wrapper/errstack.hpp>
#include <lima/io/h5/wrapper/handle.hpp>
namespace lima
{
namespace io
{
namespace h5
{
struct prop_list
{
prop_list(hid_t hid) : m_hid(hid) {}
/// Create property list from a class type (H5P_xxxx_yyyy)
static prop_list create(hid_t cls_id)
{
hid_t res = H5Pcreate(cls_id);
if (res < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("Failed to create H5 Property List") << make_errinfo_stack());
return res;
}
void set_deflate(uint level)
{
if (H5Pset_deflate(m_hid.get(), level) < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("Failed to set H5 Property List deflate level")
<< make_errinfo_stack());
}
void set_filter(H5Z_filter_t filter_id, unsigned int flags, size_t cd_nelmts,
const unsigned int cd_values[])
{
if (H5Pset_filter(m_hid.get(), filter_id, flags, cd_nelmts, cd_values) < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("Failed to set H5 Property List filter")
<< make_errinfo_stack());
}
void set_chunk(int ndims, const hsize_t dim[])
{
if (H5Pset_chunk(m_hid.get(), ndims, dim) < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("Failed to set H5 Property List chunk")
<< make_errinfo_stack());
}
operator hid_t() const { return m_hid.get(); }
shared_prop_list_hid_t m_hid;
};
} //namespace h5
} //namespace io
} //namespace lima
......@@ -193,11 +193,10 @@ namespace io
////#endif //defined(LIMA_ENABLE_MPIIO)
//// herr_t status = H5Sselect_hyperslab(m_filespace_id, H5S_SELECT_SET, offset, NULL, memdims, NULL);
herr_t res;
std::size_t size = m_dimensions.x * m_dimensions.y;
// Dataset Creation Property List
hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
auto dcpl = prop_list::create(H5P_DATASET_CREATE);
// Set the compression_enum
switch (m_compression) {
......@@ -210,7 +209,7 @@ namespace io
}
const unsigned int compression_level = 6;
res = H5Pset_deflate(dcpl, compression_level);
dcpl.set_deflate(compression_level);
#else
LIMA_THROW_EXCEPTION(std::runtime_error("Not built with zlib library"));
#endif //defined(LIMA_ENABLE_ZLIB)
......@@ -224,7 +223,7 @@ namespace io
LIMA_THROW_EXCEPTION(std::runtime_error("Cannot register H5BSHUF filter"));
unsigned int c_values[2] = {0, BSHUF_H5_COMPRESS_LZ4};
res = H5Pset_filter(dcpl, H5Z_FILTER_BSHUF, H5Z_FLAG_MANDATORY, lengthof(c_values), c_values);
dcpl.set_filter(H5Z_FILTER_BSHUF, H5Z_FLAG_MANDATORY, lengthof(c_values), c_values);
#else
LIMA_THROW_EXCEPTION(std::runtime_error("Not built with bitshuffle library"));
#endif //defined(LIMA_ENABLE_BSHUF_LZ4)
......@@ -240,7 +239,7 @@ namespace io
// Set chunk size
hsize_t chunk[] = {hsize_t(nb_frames_per_chunk), m_dimensions.y, m_dimensions.x};
res = H5Pset_chunk(dcpl, lengthof(chunk), chunk);
dcpl.set_chunk(lengthof(chunk), chunk);
// Create dataspace
auto file_space = dataspace::create_simple(lengthof(dims), dims);
......@@ -425,11 +424,10 @@ namespace io
h5::path data_path = "instrument"_p / detector_name / "data"_p;
herr_t res;
std::size_t size = m_dimensions.x * m_dimensions.y;
// Dataset Creation Property List
hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);
auto dcpl = prop_list::create(H5P_DATASET_CREATE);
// Set the compression_enum
switch (m_compression) {
......@@ -442,7 +440,7 @@ namespace io
}
const unsigned int compression_level = 6;
res = H5Pset_deflate(dcpl, compression_level);
dcpl.set_deflate(compression_level);
#else
LIMA_THROW_EXCEPTION(std::runtime_error("Not built with zlib library"));
#endif //defined(LIMA_ENABLE_ZLIB)
......@@ -456,7 +454,7 @@ namespace io
LIMA_THROW_EXCEPTION(std::runtime_error("Cannot register H5BSHUF filter"));
unsigned int c_values[2] = {0, BSHUF_H5_COMPRESS_LZ4};
res = H5Pset_filter(dcpl, H5Z_FILTER_BSHUF, H5Z_FLAG_MANDATORY, lengthof(c_values), c_values);
dcpl.set_filter(H5Z_FILTER_BSHUF, H5Z_FLAG_MANDATORY, lengthof(c_values), c_values);
#else
LIMA_THROW_EXCEPTION(std::runtime_error("Not built with bitshuffle library"));
#endif //defined(LIMA_ENABLE_BSHUF_LZ4)
......@@ -539,7 +537,7 @@ namespace io
// Set chunk size
hsize_t chunk[] = {hsize_t(nb_frames_per_chunk), m_nb_bins};
res = H5Pset_chunk(dcpl, lengthof(chunk), chunk);
dcpl.set_chunk(lengthof(chunk), chunk);
// Create dataspace
auto file_space = dataspace::create_simple(lengthof(dims), dims);
......@@ -583,7 +581,7 @@ namespace io
// Set chunk size
hsize_t chunk[] = {4096};
res = H5Pset_chunk(dcpl, lengthof(chunk), chunk);
dcpl.set_chunk(lengthof(chunk), chunk);
// Create dataspace
auto file_space = dataspace::create_simple(lengthof(dims), dims, max_dims);
......
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