9#ifndef H5PROPERTY_LIST_MISC_HPP
10#define H5PROPERTY_LIST_MISC_HPP
17inline hid_t convert_plist_type(PropertyType propertyType) {
20 switch (propertyType) {
21 case PropertyType::OBJECT_CREATE:
22 return H5P_OBJECT_CREATE;
23 case PropertyType::FILE_CREATE:
24 return H5P_FILE_CREATE;
25 case PropertyType::FILE_ACCESS:
26 return H5P_FILE_ACCESS;
27 case PropertyType::DATASET_CREATE:
28 return H5P_DATASET_CREATE;
29 case PropertyType::DATASET_ACCESS:
30 return H5P_DATASET_ACCESS;
31 case PropertyType::DATASET_XFER:
32 return H5P_DATASET_XFER;
33 case PropertyType::GROUP_CREATE:
34 return H5P_GROUP_CREATE;
35 case PropertyType::GROUP_ACCESS:
36 return H5P_GROUP_ACCESS;
37 case PropertyType::DATATYPE_CREATE:
38 return H5P_DATATYPE_CREATE;
39 case PropertyType::DATATYPE_ACCESS:
40 return H5P_DATATYPE_ACCESS;
41 case PropertyType::STRING_CREATE:
42 return H5P_STRING_CREATE;
43 case PropertyType::ATTRIBUTE_CREATE:
44 return H5P_ATTRIBUTE_CREATE;
45 case PropertyType::OBJECT_COPY:
46 return H5P_OBJECT_COPY;
47 case PropertyType::LINK_CREATE:
48 return H5P_LINK_CREATE;
49 case PropertyType::LINK_ACCESS:
50 return H5P_LINK_ACCESS;
52 HDF5ErrMapper::ToException<PropertyException>(
53 "Unsupported property list type");
59template <PropertyType T>
60inline void PropertyList<T>::initializeId() {
61 if ((_hid = H5Pcreate(convert_plist_type(T))) < 0) {
62 HDF5ErrMapper::ToException<PropertyException>(
63 "Unable to create property list");
67template <PropertyType T>
80 if (H5Pset_elink_prefix(_hid, prefix.c_str()) < 0){
81 HDF5ErrMapper::ToException<PropertyException>(
82 "Unable to set external link prefix property");
86inline void LinkCreateProps::setCreateIntermediateGroup(
unsigned val) {
87 if (H5Pset_create_intermediate_group(_hid, val) < 0){
88 HDF5ErrMapper::ToException<PropertyException>(
89 "Unable to set create intermediate group property");
93inline void DataSetAccessProps::setChunkCache(
94 const size_t& numSlots,
const size_t& cacheSize,
const double& w0)
96 if (H5Pset_chunk_cache(_hid, numSlots, cacheSize, w0) < 0){
97 HDF5ErrMapper::ToException<PropertyException>(
98 "Unable to set chunk cache property");
102inline void DataSetAccessProps::getChunkCache(
103 size_t& numSlots,
size_t& cacheSize,
double& w0)
105 if (H5Pget_chunk_cache(_hid, &numSlots, &cacheSize, &w0) < 0){
106 HDF5ErrMapper::ToException<PropertyException>(
107 "Unable to get chunk cache property");
115 size = std::filesystem::file_size(file);
116 size = size - offset;
117 }
catch(std::filesystem::filesystem_error& e) {
118 std::cout << e.what() << std::endl;
122 if (H5Pset_external(_hid, file.c_str(), offset, size) < 0){
123 HDF5ErrMapper::ToException<PropertyException>(
124 "Unable to add external file");
133 if (H5Pset_virtual( _hid, vSpace.
getId(), srcDset.getFileName().c_str(),
135 HDF5ErrMapper::ToException<PropertyException>(
136 "Unable to add set dataset virtual");
140inline void DataSetCreateProps::setShuffle() {
141 if (!H5Zfilter_avail(H5Z_FILTER_SHUFFLE)){
142 HDF5ErrMapper::ToException<PropertyException>(
143 "Z-FILTER is unavailable");
146 if (H5Pset_shuffle(_hid) < 0){
147 HDF5ErrMapper::ToException<PropertyException>(
148 "Unable to set shuffle property");
152inline void DataSetCreateProps::setDeflate(
const unsigned& level) {
153 if (!H5Zfilter_avail(H5Z_FILTER_SHUFFLE)){
154 HDF5ErrMapper::ToException<PropertyException>(
155 "Z-FILTER is unavailable");
158 if (H5Pset_deflate(_hid, level) < 0){
159 HDF5ErrMapper::ToException<PropertyException>(
160 "Unable to set deflate property");
164inline void DataSetCreateProps::setChunk(
const std::vector<hsize_t>& dims) {
165 if (H5Pset_chunk(_hid,
static_cast<int>(dims.size()), dims.data()) < 0){
166 HDF5ErrMapper::ToException<PropertyException>(
167 "Unable to set chunk property");
172 int num = H5Pget_external_count(_hid);
174 HDF5ErrMapper::ToException<PropertyException>(
175 "Unable to get number of external files");
181 unsigned idx, off_t& offset, hsize_t& fileSize) {
182 char buffer[H5GT_MAX_PATH_LEN + 1];
183 herr_t status = H5Pget_external(
184 _hid, idx,
static_cast<hsize_t
>(H5GT_MAX_PATH_LEN) + 1,
185 buffer, &offset, &fileSize);
187 HDF5ErrMapper::ToException<PropertyException>(
188 "Unable to get info about external file");
190 return std::string(buffer);
195 herr_t status = H5Pget_virtual_count(_hid, &num);
197 HDF5ErrMapper::ToException<PropertyException>(
198 "Unable to get number of virtual datasets");
204 char buffer[H5GT_MAX_PATH_LEN + 1];
205 ssize_t retcode = H5Pget_virtual_dsetname(
207 static_cast<size_t>(H5GT_MAX_PATH_LEN) + 1);
209 HDF5ErrMapper::ToException<PropertyException>(
"Error accessing object name");
211 const size_t length =
static_cast<std::size_t
>(retcode);
212 if (length <= H5GT_MAX_PATH_LEN) {
213 return std::string(buffer, length);
215 std::vector<char> bigBuffer(length + 1, 0);
216 H5Pget_virtual_dsetname(
217 _hid, idx, bigBuffer.data(),
218 static_cast<hsize_t
>(length) + 1);
219 return std::string(bigBuffer.data(), length);
222inline std::string DataSetCreateProps::getVirtualFileName(
size_t idx) {
223 char buffer[H5GT_MAX_PATH_LEN + 1];
224 ssize_t retcode = H5Pget_virtual_filename(
226 static_cast<size_t>(H5GT_MAX_PATH_LEN) + 1);
228 HDF5ErrMapper::ToException<PropertyException>(
"Error accessing object name");
230 const size_t length =
static_cast<std::size_t
>(retcode);
231 if (length <= H5GT_MAX_PATH_LEN) {
232 return std::string(buffer, length);
234 std::vector<char> bigBuffer(length + 1, 0);
235 H5Pget_virtual_filename(
236 _hid, idx, bigBuffer.data(),
237 static_cast<hsize_t
>(length) + 1);
238 return std::string(bigBuffer.data(), length);
241inline DataSpace DataSetCreateProps::getVirtualSrcSpace(
size_t idx){
242 return DataSpace::FromId(H5Pget_virtual_srcspace(_hid, idx));
245inline DataSpace DataSetCreateProps::getVirtualVSpace(
size_t idx){
246 return DataSpace::FromId(H5Pget_virtual_vspace(_hid, idx));
249inline std::vector<hsize_t> DataSetCreateProps::getChunk(
int max_ndims)
252 hsize_t* dims = (hsize_t *) calloc(max_ndims,
sizeof(hsize_t*));
253 if (H5Pget_chunk(_hid, max_ndims, dims) < 0 ){
254 HDF5ErrMapper::ToException<PropertyException>(
255 "Unable to get chunk property");
257 std::vector<hsize_t> v;
258 v.reserve(max_ndims);
259 for (
int i = 0; i < max_ndims; i++){
262 v.push_back(dims[i]);
270inline LayoutType DataSetCreateProps::getLayoutType()
272 return _convert_layout_type(H5Pget_layout(_hid));
275inline bool DataSetCreateProps::isCompact(){
276 if (getLayoutType() == LayoutType::COMPACT)
281inline bool DataSetCreateProps::isContiguous(){
282 if (getLayoutType() == LayoutType::CONTIGUOUS)
287inline bool DataSetCreateProps::isChunked(){
288 if (getLayoutType() == LayoutType::CHUNKED)
293inline bool DataSetCreateProps::isVirtual(){
294 if (getLayoutType() == LayoutType::VIRTUAL)
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
std::string getPath() const
return the path to the current group, dataset, datatype or attribute's holder
Definition H5Object_misc.hpp:185
hid_t getId(const bool &increaseRefCount=false) const noexcept
getId
Definition H5Object_misc.hpp:172
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