h5gt 0.2.0
C++ wrapper for HDF5 library (based on HighFive project)
Loading...
Searching...
No Matches
H5PropertyList.hpp
1/*
2 * Copyright (c), 2017-2018, Adrien Devresse <adrien.devresse@epfl.ch>
3 * Juan Hernando <juan.hernando@epfl.ch>
4 * Distributed under the Boost Software License, Version 1.0.
5 * (See accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 *
8 */
9#ifndef H5PROPERTY_LIST_HPP
10#define H5PROPERTY_LIST_HPP
11
12#include <vector>
13#include <filesystem>
14
15#include <H5Ppublic.h>
16
17#include "H5Exception.hpp"
18#include "H5Object.hpp"
19
20namespace h5gt {
21
25enum class LayoutType : int {
26 COMPACT,
27 CONTIGUOUS,
28 CHUNKED,
29 VIRTUAL,
30};
31
32static inline LayoutType _convert_layout_type(const H5D_layout_t& h5type) {
33 switch (h5type) {
34 case H5D_COMPACT:
35 return LayoutType::COMPACT;
36 case H5D_CONTIGUOUS:
37 return LayoutType::CONTIGUOUS;
38 case H5D_CHUNKED:
39 return LayoutType::CHUNKED;
40 case H5D_VIRTUAL:
41 return LayoutType::VIRTUAL;
42 default:
43 return static_cast<LayoutType>(-1);
44 }
45}
46
50enum class PropertyType : int {
51 OBJECT_CREATE,
52 FILE_CREATE,
53 FILE_ACCESS,
54 DATASET_CREATE,
55 DATASET_ACCESS,
56 DATASET_XFER,
57 GROUP_CREATE,
58 GROUP_ACCESS,
59 DATATYPE_CREATE,
60 DATATYPE_ACCESS,
61 STRING_CREATE,
62 ATTRIBUTE_CREATE,
63 OBJECT_COPY,
64 LINK_CREATE,
65 LINK_ACCESS,
66};
67
71template <PropertyType T>
73
74 // copy and move constructors are strongly needed by pybind11
75
76public:
78 if (_hid != H5P_DEFAULT) {
79 H5Pclose(_hid);
80 }
81 }
82
83 PropertyList(const PropertyList<T>& other) :
84 _hid(other.getId(true)){};
85
86 PropertyList& operator=(const PropertyList<T>& other){
87 _hid = other.getId(true);
88 return *this;
89 };
90
91 PropertyList& operator=(PropertyList&& other) noexcept{
92 _hid = other._hid;
93 other._hid = H5I_INVALID_HID;
94 return *this;
95 }
96
97 constexpr PropertyType getObjectType() const {
98 return T;
99 }
100
101 hid_t getId(const bool& increaseRefCount = false) const {
102 if (increaseRefCount)
103 H5Iinc_ref(_hid);
104
105 return _hid;
106 }
107
108 PropertyList() noexcept{
109 initializeId();
110 }
111
112 PropertyList(PropertyList&& other) noexcept :
113 _hid(other.getId(false)){
114 other._hid = H5I_INVALID_HID;
115 }
116
117protected:
118 PropertyList(const hid_t& hid) noexcept : _hid(hid) {}
119
120 void setExternalLinkPrefix(const std::string& prefix);
121
122 std::vector<hsize_t> getChunk(int max_ndims);
123
124 void initializeId();
125
126 hid_t _hid;
127};
128
129class LinkCreateProps : public PropertyList<PropertyType::LINK_CREATE> {
130public:
132 setCreateIntermediateGroup(1); // create intermediate groups ON by default
133 }
134
135 void setCreateIntermediateGroup(unsigned val);
136};
137
138class LinkAccessProps : public PropertyList<PropertyType::LINK_ACCESS> {
139public:
141
142 void setExternalLinkPrefix(const std::string& prefix){
144 }
145};
146
147class FileCreateProps : public PropertyList<PropertyType::FILE_CREATE> {
148public:
150};
151
152class FileAccessProps : public PropertyList<PropertyType::FILE_ACCESS> {
153public:
155};
156
157class GroupCreateProps : public PropertyList<PropertyType::GROUP_CREATE> {
158public:
160};
161
162class GroupAccessProps : public PropertyList<PropertyType::GROUP_ACCESS> {
163public:
165
166 void setExternalLinkPrefix(const std::string& prefix){
168 }
169};
170
171class DataSetCreateProps : public PropertyList<PropertyType::DATASET_CREATE> {
172public:
174
175 static DataSetCreateProps FromId(const hid_t& id, const bool& increaseRefCount = false){
176 hid_t prop_class_id = H5Pget_class(id);
177
178 if (prop_class_id < 0){
179 HDF5ErrMapper::ToException<PropertyException>(
180 "Unable to get property class");
181 }
182 if (H5Pequal(prop_class_id, H5P_DATASET_CREATE) <= 0){
183 HDF5ErrMapper::ToException<PropertyException>(
184 "Property id is of different class");
185 }
186 if (increaseRefCount)
187 H5Iinc_ref(id);
188
189 return DataSetCreateProps(id);
190 };
191
199 void addExternalFile(
200 const std::string& file,
201 off_t offset = 0, hsize_t size = 0);
202
208 const DataSpace& vSpace,
209 const DataSet& srcDset,
210 const DataSpace& srcSpace);
211
212 void setShuffle();
213
214 void setDeflate(const unsigned& level);
215
216 void setChunk(const std::initializer_list<hsize_t>& items){
217 std::vector<hsize_t> dims{items};
218 setChunk(dims);
219 }
220
221 template <typename... Args>
222 void setChunk(hsize_t item, Args... args){
223 std::vector<hsize_t> dims{item, static_cast<hsize_t>(args)...};
224 setChunk(dims);
225 }
226
227 void setChunk(const std::vector<hsize_t>& dims);
228
230 size_t getExternalCount();
232 std::string getExternal(unsigned idx, off_t& offset, hsize_t& fileSize);
234 size_t getVirtualCount();
236 std::string getVirtualDataSetName(size_t idx);
237 std::string getVirtualFileName(size_t idx);
238 DataSpace getVirtualSrcSpace(size_t idx);
239 DataSpace getVirtualVSpace(size_t idx);
240
241 std::vector<hsize_t> getChunk(int max_ndims);
242
243 LayoutType getLayoutType();
244
245 bool isCompact();
246 bool isContiguous();
247 bool isChunked();
248 bool isVirtual();
249
250 // this allows to inherit all constructors `PropertyList(id)` for example
251 // https://stackoverflow.com/questions/347358/inheriting-constructors
252 using PropertyList::PropertyList;
253};
254
255class DataSetAccessProps : public PropertyList<PropertyType::DATASET_ACCESS> {
256public:
258
259 static DataSetAccessProps FromId(const hid_t& id, const bool& increaseRefCount = false){
260 hid_t prop_class_id = H5Pget_class(id);
261
262 if (prop_class_id < 0){
263 HDF5ErrMapper::ToException<PropertyException>(
264 "Unable to get property class");
265 }
266 if (H5Pequal(prop_class_id, H5P_DATASET_ACCESS) <= 0){
267 HDF5ErrMapper::ToException<PropertyException>(
268 "Property id is of different class");
269 }
270 if (increaseRefCount)
271 H5Iinc_ref(id);
272
273 return DataSetAccessProps(id);
274 };
275
276 void setChunkCache(
277 const size_t& numSlots, const size_t& cacheSize,
278 const double& w0 = static_cast<double>(H5D_CHUNK_CACHE_W0_DEFAULT));
279
280 void setExternalLinkPrefix(const std::string& prefix){
282 }
283
284 void getChunkCache(
285 size_t& numSlots, size_t& cacheSize, double& w0);
286
287 using PropertyList::PropertyList;
288};
289
290class DataTypeCreateProps : public PropertyList<PropertyType::DATATYPE_CREATE> {
291public:
293};
294
295class DataTypeAccessProps : public PropertyList<PropertyType::DATATYPE_ACCESS> {
296public:
298};
299
300class DataTransferProps : public PropertyList<PropertyType::DATASET_XFER> {
301public:
303};
304
305class ObjectCopyProps : public PropertyList<PropertyType::OBJECT_COPY> {
306public:
308};
309
310} // namespace h5gt
311
312
313#endif // H5PROPERTY_LIST_HPP
Definition H5PropertyList.hpp:255
Definition H5PropertyList.hpp:171
void addVirtualDataSet(const DataSpace &vSpace, const DataSet &srcDset, const DataSpace &srcSpace)
map source dataset Spaces must have equal number of selected elements Spaces may be given from select...
Definition H5PropertyList_misc.hpp:128
size_t getExternalCount()
return number of external files
Definition H5PropertyList_misc.hpp:171
std::string getExternal(unsigned idx, off_t &offset, hsize_t &fileSize)
retrieve info about external file under index 'idx'
Definition H5PropertyList_misc.hpp:180
std::string getVirtualDataSetName(size_t idx)
resturn virtual (source) dataset name
Definition H5PropertyList_misc.hpp:203
void addExternalFile(const std::string &file, off_t offset=0, hsize_t size=0)
map external binary file to a dataset
Definition H5PropertyList_misc.hpp:111
size_t getVirtualCount()
return number of virtual datasets
Definition H5PropertyList_misc.hpp:193
Class representing a dataset.
Definition H5DataSet.hpp:28
Class representing the space (dimensions) of a dataset.
Definition H5DataSpace.hpp:37
Definition H5PropertyList.hpp:300
Definition H5PropertyList.hpp:295
Definition H5PropertyList.hpp:290
Definition H5PropertyList.hpp:152
Definition H5PropertyList.hpp:147
Definition H5PropertyList.hpp:162
Definition H5PropertyList.hpp:157
Definition H5PropertyList.hpp:305
Base HDF5 property List.
Definition H5PropertyList.hpp:72
void setExternalLinkPrefix(const std::string &prefix)
setExternalLinkPrefix Let’s say you’ve created an external link in foo.h5 and the external link refer...
Definition H5PropertyList_misc.hpp:79