9 #ifndef RMF_HDF5_CONST_DATA_SET_D_H
10 #define RMF_HDF5_CONST_DATA_SET_D_H
12 #include "RMF/config.h"
28 typedef ConstAttributes<Object> ConstDataSetAttributes;
30 typedef std::vector<ConstDataSetAttributes> ConstDataSetAttributesList;
41 template <
class TypeTraits,
unsigned int D>
52 std::shared_ptr<Data> data_;
55 if (data_ && !o.data_)
57 else if (o.data_ && !data_)
59 else if (!o.data_ && !data_)
61 else if (get_name() < o.get_name())
63 else if (get_name() > o.get_name())
70 return TypeTraits::get_is_null_value(get_value(ijk));
74 data_->ids_.open(H5Screate_simple(1, &one,
nullptr), &H5Sclose);
75 std::fill(data_->ones_, data_->ones_ + D, 1);
79 RMF_TRACE(
"Opened data set with size " << get_size());
87 ConstDataSetD(std::shared_ptr<SharedHandle> parent, std::string name,
92 !H5Lexists(parent->get_hid(), name.c_str(), H5P_DEFAULT),
93 RMF::internal::get_error_message(
"Data set ", name,
" already exists"));
94 hsize_t dims[D] = {0};
96 std::fill(maxs, maxs + D, H5S_UNLIMITED);
97 RMF_HDF5_HANDLE(ds, H5Screate_simple(D, dims, maxs), &H5Sclose);
99 P::open(std::make_shared<SharedHandle>(
100 H5Dcreate2(parent->get_hid(), name.c_str(),
101 TypeTraits::get_hdf5_disk_type(), ds, H5P_DEFAULT,
102 props.get_handle(), H5P_DEFAULT),
107 ConstDataSetD(std::shared_ptr<SharedHandle> parent, std::string name,
109 : data_(
new Data()) {
111 H5Lexists(parent->get_hid(), name.c_str(), H5P_DEFAULT),
112 RMF::internal::get_error_message(
"Data set ", name,
" does not exist"));
113 P::open(std::make_shared<SharedHandle>(
114 H5Dopen2(parent->get_hid(), name.c_str(), props.get_handle()),
117 RMF_HDF5_HANDLE(sel, H5Dget_space(Object::get_handle()), &H5Sclose);
118 RMF_USAGE_CHECK(H5Sget_simple_extent_ndims(sel) == D,
119 RMF::internal::get_error_message(
120 "Dimensions don't match. Got ",
121 H5Sget_simple_extent_ndims(sel),
" but expected ", D));
124 hsize_t* get_ones()
const {
return data_->ones_; }
125 const Handle& get_row_data_space()
const {
return data_->rds_; }
126 const Handle& get_data_space()
const {
return data_->sel_; }
127 const Handle& get_input_data_space()
const {
return data_->ids_; }
130 for (
unsigned int i = 0; i < D; ++i) {
131 RMF_USAGE_CHECK(ijk[i] < sz[i],
132 RMF::internal::get_error_message(
133 "Index is out of range: ", ijk[i],
" >= ", sz[i]));
136 void initialize_handles() {
137 data_->sel_.open(H5Dget_space(Object::get_handle()), &H5Sclose);
140 std::fill(ret, ret + D, -1);
141 RMF_HDF5_CALL(H5Sget_simple_extent_dims(get_data_space(), ret,
nullptr));
142 RMF_INTERNAL_CHECK(ret[D - 1] < 1000000,
"extents not returned properly");
143 if (ret[D - 1] > 0) {
147 data_->rds_.open(H5Screate_simple(1, ret + D - 1,
nullptr), &H5Sclose);
153 data_->size_.begin(),
nullptr));
157 #if !defined(SWIG) && !defined(RMF_DOXYGEN)
158 ConstDataSetD(hid_t file, std::string name) : data_(
new Data()) {
160 H5Lexists(file, name.c_str(), H5P_DEFAULT),
161 RMF::internal::get_error_message(
"Data set ", name,
" does not exist"));
162 P::open(std::make_shared<SharedHandle>(
163 H5Dopen2(file, name.c_str(), H5P_DEFAULT), &H5Dclose, name));
165 RMF_HDF5_HANDLE(sel, H5Dget_space(Object::get_handle()), &H5Sclose);
166 RMF_USAGE_CHECK(H5Sget_simple_extent_ndims(sel) == D,
167 RMF::internal::get_error_message(
168 "Dimensions don't match. Got ",
169 H5Sget_simple_extent_ndims(sel),
" but expected ", D));
180 RMF_IF_CHECK { check_index(ijk); }
182 RMF_HDF5_CALL(H5Sselect_hyperslab(get_data_space(), H5S_SELECT_SET,
183 ijk.get(), data_->ones_, data_->ones_,
185 return TypeTraits::read_value_dataset(
186 Object::get_handle(), data_->ids_.get_hid(), get_data_space());
188 RMF_SHOWABLE(
ConstDataSetD,
"ConstDataSet" << D <<
"D " << P::get_name());
191 typename TypeTraits::Types get_row(
const RowIndex ijkr)
const {
193 std::copy(ijkr.begin(), ijkr.end(), ijk.begin());
195 RMF_IF_CHECK { check_index(ijk); }
197 std::fill(size, size + D - 1, 1);
198 size[D - 1] = get_size()[D - 1];
200 RMF_HDF5_CALL(H5Sselect_hyperslab(get_data_space(), H5S_SELECT_SET,
201 ijk.get(), data_->ones_, &size[0],
203 return TypeTraits::read_values_dataset(Object::get_handle(),
204 get_row_data_space().get_hid(),
205 get_data_space(), size[D - 1]);
210 const Index& size)
const {
212 for (
unsigned int i = 0; i < D; ++i) {
215 RMF_IF_CHECK { check_index(lb); }
217 RMF_HDF5_CALL(H5Sselect_hyperslab(get_data_space(), H5S_SELECT_SET,
218 lb.get(), data_->ones_, size.get(),
220 RMF_HDF5_HANDLE(input, H5Screate_simple(1, &total,
nullptr), &H5Sclose);
221 typename TypeTraits::Types ret = TypeTraits::read_values_dataset(
222 Object::get_handle(), input, get_data_space(), total);
223 RMF_INTERNAL_CHECK(ret.size() == total,
"Size mismatch");
230 #define RMF_HDF5_DECLARE_CONST_DATA_SET(lcname, Ucname, PassValue, \
231 ReturnValue, PassValues, ReturnValues) \
232 typedef ConstDataSetD<Ucname##Traits, 1> Ucname##ConstDataSet1D; \
233 typedef std::vector<Ucname##ConstDataSet1D> Ucname##ConstDataSet1Ds; \
234 typedef ConstDataSetD<Ucname##Traits, 2> Ucname##ConstDataSet2D; \
235 typedef std::vector<Ucname##ConstDataSet2D> Ucname##ConstDataSet2Ds; \
236 typedef ConstDataSetD<Ucname##Traits, 3> Ucname##ConstDataSet3D; \
237 typedef std::vector<Ucname##ConstDataSet3D> Ucname##ConstDataSet3Ds
243 RMF_HDF5_FOREACH_TYPE(RMF_HDF5_DECLARE_CONST_DATA_SET);
Handle read/write of Model data from/to files.
Various general useful macros for IMP.
Make sure an HDF5 handle is released.
Handle read/write of Model data from/to files.
#define RMF_COMPARISONS(Name)
Implement comparison in a class using field as the variable to compare.
TypeTraits::Types get_block(const Index &lb, const Index &size) const
Read a rectangular block starting at ln of size size.
Handle read/write of Model data from/to files.
Handle read/write of Model data from/to files.
Functions and macros for logging.
Handle read/write of Model data from/to files.