h5gt 0.2.0
C++ wrapper for HDF5 library (based on HighFive project)
Loading...
Searching...
No Matches
H5DataSet_misc.hpp
1/*
2 * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3 *
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 H5DATASET_MISC_HPP
10#define H5DATASET_MISC_HPP
11
12#include <algorithm>
13#include <functional>
14#include <numeric>
15#include <sstream>
16#include <string>
17
18#ifdef H5GT_USE_BOOST
19#include <boost/multi_array.hpp>
20#endif
21
22#include <H5Dpublic.h>
23#include <H5Ppublic.h>
24
25#include "H5Utils.hpp"
26
27namespace h5gt {
28
29inline uint64_t DataSet::getStorageSize() const {
30 return H5Dget_storage_size(_hid);
31}
32
34 return DataType(H5Dget_type(_hid));
35}
36
37inline LinkInfo DataSet::getLinkInfo() const {
39}
40
42 DataSpace space;
43 if ((space._hid = H5Dget_space(_hid)) < 0) {
44 HDF5ErrMapper::ToException<DataSetException>(
45 "Unable to get DataSpace out of DataSet");
46 }
47 return space;
48}
49
51 return getSpace();
52}
53
54inline File DataSet::getFile() const {
55 hid_t fileId = H5Iget_file_id(_hid);
56 if (!H5Iis_valid(fileId)){
57 HDF5ErrMapper::ToException<DataSetException>(
58 std::string("File ID is invalid. Probably the object doesn't belong to any file"));
59 }
60 return File::FromId(fileId, false);
61}
62
63inline std::string DataSet::unpackSoftLink() const{
64 return Object::_unpackSoftLink(getPath());
65}
66
67inline void DataSet::unlink() const{
68 return Object::_unlink(getPath());
69}
70
71inline bool DataSet::rename(const std::string& dst_path,
72 const LinkCreateProps& linkCreateProps,
73 const LinkAccessProps& linkAccessProps) const {
74 herr_t status = H5Lmove(getId(false), getPath().c_str(),
75 getId(false), dst_path.c_str(),
76 linkCreateProps.getId(false), linkAccessProps.getId(false));
77 if (status < 0) {
78 HDF5ErrMapper::ToException<DataSetException>(
79 std::string("Unable to move link to \"") + dst_path + "\":");
80 return false;
81 }
82 return true;
83}
84
85inline Group DataSet::getParent(const GroupAccessProps& groupAccessProps) const {
86 std::string path = getPath();
87 if (path == "/")
88 HDF5ErrMapper::ToException<DataSetException>(
89 std::string(path + " has no parent"));
90
91 std::string objName;
92 std::string parentPath = details::splitPathToParentAndObj(path, objName);
93 if (parentPath.empty())
94 HDF5ErrMapper::ToException<DataSetException>(
95 std::string(objName + " has no parent"));
96
97 File file = getFile();
98 return file.getGroup(parentPath, groupAccessProps);
99}
100
101inline DataSetCreateProps DataSet::getCreateProps() const{
102 hid_t prop_id = H5Dget_create_plist(_hid);
103 if (prop_id < 0) {
104 HDF5ErrMapper::ToException<DataSetException>(
105 "Cannot get creation property list for a DataSet");
106 }
107 return DataSetCreateProps::FromId(prop_id, false);
108}
109
110inline DataSetAccessProps DataSet::getAccessProps() const{
111 hid_t prop_id = H5Dget_access_plist(_hid);
112 if (prop_id < 0) {
113 HDF5ErrMapper::ToException<DataSetException>(
114 "Cannot get access property list for a DataSet");
115 }
116 return DataSetAccessProps::FromId(prop_id, false);
117}
118
119inline uint64_t DataSet::getOffset() const {
120 uint64_t addr = H5Dget_offset(_hid);
121 if (addr == HADDR_UNDEF) {
122 HDF5ErrMapper::ToException<DataSetException>(
123 "Cannot get offset of DataSet.");
124 }
125 return addr;
126}
127
128inline void DataSet::resize(const std::vector<size_t>& dims) {
129
130 const size_t numDimensions = getSpace().getDimensions().size();
131 if (dims.size() != numDimensions) {
132 HDF5ErrMapper::ToException<DataSetException>(
133 "Invalid dataspace dimensions, got " + std::to_string(dims.size()) +
134 " expected " + std::to_string(numDimensions));
135 }
136
137 std::vector<hsize_t> real_dims(dims.begin(), dims.end());
138
139 if (H5Dset_extent(getId(false), real_dims.data()) < 0) {
140 HDF5ErrMapper::ToException<DataSetException>(
141 "Could not resize dataset.");
142 }
143}
144
145inline bool DataSet::operator==(const DataSet& other) const {
146 return Object::operator==(other);
147}
148
149inline bool DataSet::operator!=(const DataSet& other) const {
150 return !(*this == other);
151}
152
153} // namespace h5gt
154
155#endif // H5DATASET_MISC_HPP
Class representing a dataset.
Definition H5DataSet.hpp:28
std::string unpackSoftLink() const
unpackSoftLink retrieve target path to this dataset
Definition H5DataSet_misc.hpp:63
uint64_t getOffset() const
getOffset
Definition H5DataSet_misc.hpp:119
void resize(const std::vector< size_t > &dims)
Change the size of the dataset.
Definition H5DataSet_misc.hpp:128
DataType getDataType() const
getDataType
Definition H5DataSet_misc.hpp:33
DataSpace getSpace() const
getSpace
Definition H5DataSet_misc.hpp:41
bool operator==(const DataSet &other) const
operator == Check if objects reside in the same file and equal to each other
Definition H5DataSet_misc.hpp:145
bool rename(const std::string &dest_path, const LinkCreateProps &linkCreateProps=LinkCreateProps(), const LinkAccessProps &linkAccessProps=LinkAccessProps()) const
rename move link within container
Definition H5DataSet_misc.hpp:71
DataSpace getMemSpace() const
getMemSpace
Definition H5DataSet_misc.hpp:50
uint64_t getStorageSize() const
getStorageSize
Definition H5DataSet_misc.hpp:29
Class representing the space (dimensions) of a dataset.
Definition H5DataSpace.hpp:37
std::vector< size_t > getDimensions() const
getDimensions
Definition H5Dataspace_misc.hpp:103
HDF5 Data Type.
Definition H5DataType.hpp:48
File class.
Definition H5File.hpp:25
Definition H5PropertyList.hpp:162
Represents an hdf5 group.
Definition H5Group.hpp:23
Group getGroup(const std::string &group_name, const GroupAccessProps &groupAccessProps=GroupAccessProps()) const
open an existing group with the name group_name
Definition H5Node_traits_misc.hpp:142
LinkInfo _getLinkInfo(const std::string &objPath) const
getLinkInfo retrieve link info from an object with 'objPath'. This object must reside in the same con...
Definition H5Object_misc.hpp:216
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
bool operator==(const Object &other) const
When coparing objects h5gt::File must be open.
Definition H5Object_misc.hpp:105