Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions
HDF5

Low-level interface for using HDF5 with modern C++ and STL. More...

Collaboration diagram for HDF5:

Namespaces

namespace  Utopia::DataIO::Detail
 

Classes

class  Utopia::DataIO::HDFAttribute
 Class for hdf5 attribute, which can be attached to groups and datasets. More...
 
class  Utopia::DataIO::HDFBufferFactory
 Class which turns non-vector or plain-array containers into vectors. If the value_types are containers themselves, these are turned into vectors as well, because HDF5 cannot write something else. More...
 
class  Utopia::DataIO::HDFDataset
 Class representing a HDFDataset, wich reads and writes data and attributes. More...
 
class  Utopia::DataIO::HDFDataspace
 Class that wraps an HDF5 dataspace and takes care of managing its resources. More...
 
class  Utopia::DataIO::HDFFile
 Class representing a HDF5 file. More...
 
class  Utopia::DataIO::HDFGroup
 Class represting a HDFGroup, an object analogous to a folder for HDFFiles. More...
 
class  Utopia::DataIO::HDFIdentifier
 Wrapper class around an hdf5 identifier, used to manage reference counts of the object this identifier refers to. More...
 
class  Utopia::DataIO::HDFObject< objectcategory >
 Common base class for all HDF5 classes in the DATAIO Module i.e., for all classes that wrap HDF5-C-Library functionality like HDFDataset, HDFGroup, HDFFile. This class is not intendet as something to be used independently, but only as a base class to be inherited from. More...
 
class  Utopia::DataIO::HDFType
 Class which handles the conversion of C-types into hdf5types. More...
 

Typedefs

using Utopia::DataIO::HDFDataspace::Base = HDFObject< HDFCategory::dataspace >
 

Enumerations

enum struct  Utopia::DataIO::HDFCategory {
  Utopia::DataIO::HDFCategory::file = H5I_FILE , Utopia::DataIO::HDFCategory::group = H5I_GROUP , Utopia::DataIO::HDFCategory::datatype = H5I_DATATYPE , Utopia::DataIO::HDFCategory::dataspace = H5I_DATASPACE ,
  Utopia::DataIO::HDFCategory::dataset = H5I_DATASET , Utopia::DataIO::HDFCategory::attribute = H5I_ATTR
}
 Enumerate the different HDF5 object types for use in HDFObject class. More...
 

Functions

void Utopia::DataIO::swap (HDFAttribute &lhs, HDFAttribute &rhs)
 Swaps the states of Attributes rhs and lhs.
 
void Utopia::DataIO::swap (HDFDataset &lhs, HDFDataset &rhs)
 Exchange state between lhs and rhs.
 
hsize_t Utopia::DataIO::HDFDataspace::rank ()
 Get thet dataspace's rank, i.e., number of dimensions.
 
std::pair< arma::Row< hsize_t >, arma::Row< hsize_t > > Utopia::DataIO::HDFDataspace::get_properties ()
 Get the properties object: size and capacity.
 
arma::Row< hsize_tUtopia::DataIO::HDFDataspace::size ()
 Get the current size of the dataspace in each dimension.
 
arma::Row< hsize_tUtopia::DataIO::HDFDataspace::capacity ()
 Get the capacity of the dataspace in each dimension.
 
void Utopia::DataIO::HDFDataspace::open ()
 Open the dataspace - set it to be equivalent to any data that later will be used to write or read.
 
template<typename Object >
void Utopia::DataIO::HDFDataspace::open (Object &&object)
 Open the dataspace with an HDF5 object, i.e., dataset or attribute.
 
void Utopia::DataIO::HDFDataspace::open (std::string name, hsize_t rank, arma::Row< hsize_t > extent, arma::Row< hsize_t > capacity)
 Open a new dataset of type 'simple', which is equivalent to a N-dimensional array of dimension N = 'rank', a given extent, and a given maximum capacity that in each dimension must be greater or equal to the extent.
 
std::pair< arma::Row< hsize_t >, arma::Row< hsize_t > > Utopia::DataIO::HDFDataspace::get_selection_bounds ()
 Get the selection bounding box, i.e., the start and end vector of the currently selected subset of the dataspace.
 
void Utopia::DataIO::HDFDataspace::select_slice (arma::Row< hsize_t > start, arma::Row< hsize_t > end, arma::Row< hsize_t > stride)
 Select a slice in the dataspace defined by [start, end, stride] in the manner of numpy. Overwrites old selections.
 
void Utopia::DataIO::HDFDataspace::select_all ()
 Select the entire dataspace as hyperslap to be read/written to.
 
void Utopia::DataIO::HDFDataspace::resize (arma::Row< hsize_t > new_size)
 Resize the dataspace. The new size needs to fit into the dataspaces capacity.
 
void Utopia::DataIO::HDFDataspace::release_selection ()
 Release a previously defined selection.
 
 Utopia::DataIO::HDFDataspace::HDFDataspace ()
 Construct HDFDataspace per default. Equivalent to using H5S_ALL when employing the pure C interface.
 
 Utopia::DataIO::HDFDataspace::HDFDataspace (const HDFDataspace &)=default
 Copy constructor.
 
 Utopia::DataIO::HDFDataspace::HDFDataspace (HDFDataspace &&)=default
 Move constructor.
 
HDFDataspaceUtopia::DataIO::HDFDataspace::operator= (const HDFDataspace &)=default
 Copy assign dataspace.
 
HDFDataspaceUtopia::DataIO::HDFDataspace::operator= (HDFDataspace &&)=default
 Move assign dataspace.
 
 Utopia::DataIO::HDFDataspace::HDFDataspace (std::string name, hsize_t rank, std::vector< hsize_t > extent, std::vector< hsize_t > capacity)
 Construct HDFDataspace from the given arguments.
 
template<typename Object >
 Utopia::DataIO::HDFDataspace::HDFDataspace (Object &&object, std::enable_if_t< not std::is_same_v< std::decay_t< Object >, HDFDataspace >, int >=0)
 Construct a new HDFDataspace object from an HDFDataset or HDFAttribute. This loads the file-dataspace that belongs to the dataset or attribute such that it gets managed by this class.
 
virtual Utopia::DataIO::HDFDataspace::~HDFDataspace ()=default
 Destroy the HDFDataspace object.
 
void Utopia::DataIO::HDFDataspace::swap (HDFDataspace &other)
 Swap state with argument.
 
void Utopia::DataIO::swap (HDFDataspace &lhs, HDFDataspace &rhs)
 Swap states of lhs and rhs.
 
void Utopia::DataIO::swap (HDFGroup &lhs, HDFGroup &rhs)
 Swap lhs and rhs.
 
bool Utopia::DataIO::operator== (const HDFIdentifier &lhs, const HDFIdentifier &rhs)
 Comparsion operator for equality.
 
bool Utopia::DataIO::operator!= (const HDFIdentifier &lhs, const HDFIdentifier &rhs)
 Comparsion operator for inequality.
 
void Utopia::DataIO::swap (HDFIdentifier &lhs, HDFIdentifier &rhs)
 Exchange the states of lhs and rhs.
 
template<HDFCategory cat>
void Utopia::DataIO::swap (HDFObject< cat > &lhs, HDFObject< cat > &rhs)
 Exchange state of lhs and rhs.
 
bool Utopia::DataIO::operator== (const HDFType &lhs, const HDFType &rhs)
 Check equality of argument typefactories. Two typefactories are considered equal when they refer to the same HDF5 type, e.g., H5T_INTEGER, or H5T_VLEN.
 
bool Utopia::DataIO::operator!= (const HDFType &lhs, const HDFType &rhs)
 TODO.
 
bool Utopia::DataIO::check_validity (htri_t valid, const std::string_view object_name)
 Check for validity of a hdf5 htri_t type or similar.
 
htri_t Utopia::DataIO::path_exists (hid_t loc_id, std::string path, hid_t link_property_list=H5P_DEFAULT)
 Checks iteratively if each segment of a path exists.
 
auto Utopia::DataIO::path_is_valid (hid_t id, std::string path)
 Check if the path given relative to the object identified by 'id' exists and points to a valid hdf5 object.
 
template<HDFCategory category>
std::string Utopia::DataIO::category_to_string ()
 Turn category enum into a string that names it.
 
template<class Object >
std::string Utopia::DataIO::generate_object_name (const Object &object)
 Use category and path variable of object to make a string that identifies the object it is applied to.
 
template<typename Object >
hid_t Utopia::DataIO::open_dataspace (Object &&object)
 Depending on object category, opens a dataset or attribute dataspace.
 
template<typename Object >
hid_t Utopia::DataIO::open_type (Object &&object)
 Depending on object category, invokes H5Dget_type or H5Aget_type.
 

Detailed Description

Low-level interface for using HDF5 with modern C++ and STL.

HDF5 Backend Module

Overview

This backend is a replacement of the HDF5 C++ wrappers. It does not implement the full HDF5 standard, but only the features we deemed useful and needed for the Utopia project. It was created because the C++ wrappers supplied by the HDF5 group do not support STL containers and in general no modern C++ features. Furthermore, development of the pure C implementation is much faster and it is generally more complete.

Implementation

In this module, C++ classes are created which represent HDF5 files, groups, datasets and attributes, with the associated object creation- and data I/O- capabilities, limited to one and two-dimensional datasets of arrays, containers or scalars. Additionally, helper classes for organizing type mapping and type conversion are supplied, which normally are irelevant for users. Finally a number of helper functions are supplied which are used to assert correctness.

Typedef Documentation

◆ Base

Enumeration Type Documentation

◆ HDFCategory

Enumerate the different HDF5 object types for use in HDFObject class.

Enumerator
file 
group 
datatype 
dataspace 
dataset 
attribute 
173{
174 file = H5I_FILE,
175 group = H5I_GROUP,
176 datatype = H5I_DATATYPE,
177 dataspace = H5I_DATASPACE,
178 dataset = H5I_DATASET,
179 attribute = H5I_ATTR
180};

Function Documentation

◆ capacity()

arma::Row< hsize_t > Utopia::DataIO::HDFDataspace::capacity ( )
inline

Get the capacity of the dataspace in each dimension.

Returns
arma::Row< hsize_t > Vector containing the dataspace's current capacity in each dimension
107 {
108 return get_properties().second;
109 }
std::pair< arma::Row< hsize_t >, arma::Row< hsize_t > > get_properties()
Get the properties object: size and capacity.
Definition hdfdataspace.hh:67

◆ category_to_string()

template<HDFCategory category>
std::string Utopia::DataIO::category_to_string ( )

Turn category enum into a string that names it.

Template Parameters
category
Returns
std::string
191{
192 switch (category)
193 {
194 case HDFCategory::file:
195 return "file";
196 case HDFCategory::group:
197 return "group";
198 case HDFCategory::datatype:
199 return "datatype";
200 case HDFCategory::dataspace:
201 return "dataspace";
202 case HDFCategory::dataset:
203 return "dataset";
204 case HDFCategory::attribute:
205 return "attribute";
206 }
207}

◆ check_validity()

bool Utopia::DataIO::check_validity ( htri_t  valid,
const std::string_view  object_name 
)

Check for validity of a hdf5 htri_t type or similar.

Parameters
[in]validparameter to check
[in]objectname Name of object to be referenced in thrown exceptions if valid <= 0
Returns
The valid argument for further use

This function is necessary because for instance H5Iis_valid does not return a boolean (non existant in C), but a value which is > 0 if everything is fine, < 0 if some error occurred during checking and 0 if the object to check is invalid. This has to be taken into account in order to be able to track bugs or wrong usage properly. See here:

https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.6/hdf5-1.6.7/src/unpacked/src/H5public.h which yields the following snippet:

Boolean type. Successful return values are zero (false) or positive (true). The typical true value is 1 but don't bet on it. Boolean functions cannot fail. Functions that return ‘htri_t’ however return zero (false), positive (true), or negative (failure). The proper way to test for truth from a htri_t function is:

if ((retval = H5Tcommitted(type))>0) { printf("data type is committed\n"); } else if (!retval) { printf("data type is not committed\n"); } else { printf("error determining whether data type is committed\n"); }

74{
75 if (valid > 0)
76 {
77 return true;
78 }
79
80 else if (valid < 0)
81 {
82 throw std::runtime_error("Object " + std::string(object_name) + ": " +
83 "Error in validity check");
84 return false;
85 }
86 else
87 {
88 return false;
89 }
90}

◆ generate_object_name()

template<class Object >
std::string Utopia::DataIO::generate_object_name ( const Object object)

Use category and path variable of object to make a string that identifies the object it is applied to.

Template Parameters
Objectautomatically determined
Parameters
objectobject to determine info string for
Returns
std::string category and path in the form "category `category` at `path`".
221{
222 return "category " + category_to_string< Object::category >() + " at '" +
223 object.get_path() + "'";
224}

◆ get_properties()

std::pair< arma::Row< hsize_t >, arma::Row< hsize_t > > Utopia::DataIO::HDFDataspace::get_properties ( )
inline

Get the properties object: size and capacity.

Note
The dimensions can be infered from the size of the returned vectors
Returns
auto pair containing (size, capacity) armadillo rowvectors
68 {
69 if (not is_valid())
70 {
71 throw std::runtime_error(
72 "Error, trying to get properties of invalid dataspace," +
73 std::to_string(get_C_id()));
74 }
75
76 arma::Row< hsize_t > size;
78
79 arma::Row< hsize_t > capacity;
80 capacity.resize(size.size());
81
82 H5Sget_simple_extent_dims(get_C_id(), size.memptr(), capacity.memptr());
83
84 return std::make_pair(size, capacity);
85 }
virtual bool is_valid() const
Check if the object is still valid.
Definition hdfobject.hh:143
hid_t get_C_id() const
Get the C id object.
Definition hdfobject.hh:120
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
arma::Row< hsize_t > size()
Get the current size of the dataspace in each dimension.
Definition hdfdataspace.hh:94
arma::Row< hsize_t > capacity()
Get the capacity of the dataspace in each dimension.
Definition hdfdataspace.hh:106

◆ get_selection_bounds()

std::pair< arma::Row< hsize_t >, arma::Row< hsize_t > > Utopia::DataIO::HDFDataspace::get_selection_bounds ( )
inline

Get the selection bounding box, i.e., the start and end vector of the currently selected subset of the dataspace.

Returns
std::pair<arma::Row<hsize_t>, arma::Row<hsize_t>>
196 {
197 arma::Row< hsize_t > start;
198 arma::Row< hsize_t > end;
199
200 if (is_valid())
201 {
202 hsize_t r = rank();
203 start.resize(r);
204 end.resize(r);
205
206 if (H5Sget_select_bounds(get_C_id(), start.memptr(), end.memptr()) <
207 0)
208 {
209 throw std::runtime_error(
210 "Error, cannot get selection bounds of invalid dataspace");
211 }
212 }
213 return std::make_pair(start, end);
214 }
hsize_t rank()
Get thet dataspace's rank, i.e., number of dimensions.
Definition hdfdataspace.hh:46
auto end(zip< Containers... > &zipper)
end function like std::end
Definition zip.hh:550

◆ HDFDataspace() [1/5]

Utopia::DataIO::HDFDataspace::HDFDataspace ( )
inline

Construct HDFDataspace per default. Equivalent to using H5S_ALL when employing the pure C interface.

364 {
365 open();
366 }
void open()
Open the dataspace - set it to be equivalent to any data that later will be used to write or read.
Definition hdfdataspace.hh:117

◆ HDFDataspace() [2/5]

Utopia::DataIO::HDFDataspace::HDFDataspace ( const HDFDataspace )
default

Copy constructor.

◆ HDFDataspace() [3/5]

Utopia::DataIO::HDFDataspace::HDFDataspace ( HDFDataspace &&  )
default

Move constructor.

◆ HDFDataspace() [4/5]

template<typename Object >
Utopia::DataIO::HDFDataspace::HDFDataspace ( Object &&  object,
std::enable_if_t< not std::is_same_v< std::decay_t< Object >, HDFDataspace >, int = 0 
)
inline

Construct a new HDFDataspace object from an HDFDataset or HDFAttribute. This loads the file-dataspace that belongs to the dataset or attribute such that it gets managed by this class.

Template Parameters
Objectautomatically dete rmined
Parameters
objectobject to open the dataset space to
423 {
424 open(std::forward< Object >(object));
425 }

◆ HDFDataspace() [5/5]

Utopia::DataIO::HDFDataspace::HDFDataspace ( std::string  name,
hsize_t  rank,
std::vector< hsize_t extent,
std::vector< hsize_t capacity 
)
inline

Construct HDFDataspace from the given arguments.

Parameters
rank
extent
capacity
407 {
408 open(name, rank, extent, capacity);
409 }

◆ open() [1/3]

void Utopia::DataIO::HDFDataspace::open ( )
inline

Open the dataspace - set it to be equivalent to any data that later will be used to write or read.

118 {
119
120 this->_log->debug("Opening dataspace, setting it to H5S_ALL");
121 // no explicit close function needed for H5S_ALL
122 _id.open(H5S_ALL, [](hid_t) -> herr_t { return 1; });
123 _path = "Dataspace_all";
124 }
void open(hid_t id, std::function< herr_t(hid_t) > closing_func)
Open the object and bind it to another C-Level id.
Definition hdfidentifier.hh:156
std::string _path
Name of the object.
Definition hdfobject.hh:50
std::shared_ptr< spdlog::logger > _log
pointer to the logger for dataio
Definition hdfobject.hh:56
HDFIdentifier _id
Identifier object that binds an instance of this class to an HDF5 object.
Definition hdfobject.hh:44

◆ open() [2/3]

template<typename Object >
void Utopia::DataIO::HDFDataspace::open ( Object &&  object)
inline

Open the dataspace with an HDF5 object, i.e., dataset or attribute.

Template Parameters
Object
Parameters
oHDF5 object to retrieve the dataspace for
135 {
136
137 this->_log->debug(
138 "Opening dataspace of {}", generate_object_name(object));
139
140 // open_dataspace is defined for attribute and dataset
141 // in their respective headerfiles to provide uniform
142 // interface for both, such that we do not have to
143 // differentiate between them
144 bind_to(open_dataspace(std::forward< Object >(object)),
145 &H5Sclose,
146 object.get_path() + " dataspace");
147
148 _log = spdlog::get("data_io");
149 }
std::string get_path() const
Get the name or path object.
Definition hdfobject.hh:88
void bind_to(hid_t id, std::function< herr_t(hid_t) > closing_func, std::string path={})
Open the object and bind it to a HDF5 object identified by 'id' with name 'path'. Object should be cr...
Definition hdfobject.hh:186
hid_t open_dataspace(Object &&object)
Depending on object category, opens a dataset or attribute dataspace.
Definition hdfutilities.hh:235
std::string generate_object_name(const Object &object)
Use category and path variable of object to make a string that identifies the object it is applied to...
Definition hdfutilities.hh:220

◆ open() [3/3]

void Utopia::DataIO::HDFDataspace::open ( std::string  name,
hsize_t  rank,
arma::Row< hsize_t extent,
arma::Row< hsize_t capacity 
)
inline

Open a new dataset of type 'simple', which is equivalent to a N-dimensional array of dimension N = 'rank', a given extent, and a given maximum capacity that in each dimension must be greater or equal to the extent.

Parameters
rankDimension of the dataspace
extentCurrent extent of the dataspace
capacityTotal capacity of the dataspace
166 {
167
168 this->_log->debug("Opening dataspace from scratch with rank {}, extent "
169 "{} and capacity {}",
170 rank,
171 Utils::str(extent),
173 if (capacity.size() == 0)
174 {
175 bind_to(
176 H5Screate_simple(rank, extent.memptr(), NULL), &H5Sclose, name);
177 }
178 else
179 {
180 bind_to(H5Screate_simple(rank, extent.memptr(), capacity.memptr()),
181 &H5Sclose,
182 name);
183 }
184
185 _log = spdlog::get("data_io");
186 }
std::string str(T &&t)
Turn any object for which operator<< exists into a string. Mostly useful for logging data via spdlog ...
Definition ostream.hh:164

◆ open_dataspace()

template<typename Object >
hid_t Utopia::DataIO::open_dataspace ( Object &&  object)

Depending on object category, opens a dataset or attribute dataspace.

Template Parameters
Object
Parameters
object
Returns
hid_t
236{
237 if constexpr (std::decay_t< Object >::category == HDFCategory::dataset)
238 {
239 return H5Dget_space(object.get_C_id());
240 }
241 else if constexpr (std::decay_t< Object >::category ==
242 HDFCategory::attribute)
243 {
244 return H5Aget_space(object.get_C_id());
245 }
246 else
247 {
248 return -1;
249 }
250}

◆ open_type()

template<typename Object >
hid_t Utopia::DataIO::open_type ( Object &&  object)

Depending on object category, invokes H5Dget_type or H5Aget_type.

Template Parameters
Object
Parameters
object
Returns
hid_t
262{
263 if constexpr (std::decay_t< Object >::category == HDFCategory::dataset)
264 {
265 return H5Dget_type(object.get_C_id());
266 }
267 else if constexpr (std::decay_t< Object >::category ==
268 HDFCategory::attribute)
269 {
270 return H5Aget_type(object.get_C_id());
271 }
272 else
273 {
274 return -1;
275 }
276}

◆ operator!=() [1/2]

bool Utopia::DataIO::operator!= ( const HDFIdentifier lhs,
const HDFIdentifier rhs 
)

Comparsion operator for inequality.

Parameters
otherObject to compare with
Returns
true other != this
false otherwise
276{
277 return not(lhs == rhs);
278}

◆ operator!=() [2/2]

bool Utopia::DataIO::operator!= ( const HDFType lhs,
const HDFType rhs 
)

TODO.

Parameters
lhs
rhs
Returns
true
false
478{
479 return not(lhs == rhs);
480}

◆ operator=() [1/2]

HDFDataspace & Utopia::DataIO::HDFDataspace::operator= ( const HDFDataspace )
default

Copy assign dataspace.

Returns
HDFDataspace&

◆ operator=() [2/2]

HDFDataspace & Utopia::DataIO::HDFDataspace::operator= ( HDFDataspace &&  )
default

Move assign dataspace.

Returns
HDFDataspace&

◆ operator==() [1/2]

bool Utopia::DataIO::operator== ( const HDFIdentifier lhs,
const HDFIdentifier rhs 
)

Comparsion operator for equality.

Parameters
otherObject to compare with
Returns
true other == this
false otherwise
263{
264 return rhs.get_id() == lhs.get_id();
265}

◆ operator==() [2/2]

bool Utopia::DataIO::operator== ( const HDFType lhs,
const HDFType rhs 
)

Check equality of argument typefactories. Two typefactories are considered equal when they refer to the same HDF5 type, e.g., H5T_INTEGER, or H5T_VLEN.

Template Parameters
T
U
Parameters
lhs
rhs
Returns
true
false
450{
451 auto equal = H5Tequal(lhs.get_C_id(), rhs.get_C_id()) &&
452 lhs.type_category() == rhs.type_category();
453 if (equal > 0)
454 {
455 return true;
456 }
457 else if (equal == 0)
458 {
459 return false;
460 }
461 else
462 {
463 throw std::runtime_error("Error when comparing dataspaces");
464 return false;
465 }
466}

◆ path_exists()

htri_t Utopia::DataIO::path_exists ( hid_t  loc_id,
std::string  path,
hid_t  link_property_list = H5P_DEFAULT 
)

Checks iteratively if each segment of a path exists.

Checks if a given path exists in a hdf5 object identitifed by its id.

Parameters
loc_idIdentifier of the file or group to query.
pathThe path of the link to check. This can be a relative or an absolute path, but (as with H5Lexists) it can NOT use the ../ syntax to go to the parent object. For such cases, an absolute path needs to be given.
link_property_listLink access property list identifier.
Returns
htri_t Variable which tells if the given path exists (true > 0, false = 0, error < 0)
110{
111 // Position of the segment cursor; all characters before are checked
112 // For absolute paths, search always needs to start behind index 1
113 std::size_t seg_pos = (path.find("/") == 0) ? 1 : 0;
114
115 // A buffer for the return value of H5Lexists
116 htri_t rv;
117
118 // Go over all segments until the whole string is
119 while (seg_pos != std::string::npos)
120 {
121 // Find the position of the next "/", strictly after the current
122 // cursor position
123 seg_pos = path.find("/", seg_pos + 1);
124
125 // Check for existence of the subpath. If seg_pos is string::npos,
126 // the substring is the full path and this is the last loop iteration.
127 rv = H5Lexists(
128 loc_id, path.substr(0, seg_pos).c_str(), link_property_list);
129
130 // If this segment does not exists, need to return already
131 if (rv <= 0)
132 {
133 return rv;
134 }
135 }
136
137 // Checked the full path. Can return the last return value now:
138 return rv;
139}

◆ path_is_valid()

auto Utopia::DataIO::path_is_valid ( hid_t  id,
std::string  path 
)

Check if the path given relative to the object identified by 'id' exists and points to a valid hdf5 object.

Parameters
idid of the starting point
pathpath from the object identified by 'id' to the object to check
Returns
auto > 0 if valid and existing, 0 if not
151{
152 auto test = H5LTpath_valid(id, path.c_str(), true);
153 if (test > 0)
154 {
155 return true;
156 }
157 else if (test == 0)
158 {
159 return false;
160 }
161 else
162 {
163 throw std::runtime_error("Error when checking path " + path);
164 return false;
165 }
166}

◆ rank()

hsize_t Utopia::DataIO::HDFDataspace::rank ( )
inline

Get thet dataspace's rank, i.e., number of dimensions.

Returns
auto rank of the dataspace
47 {
48 if (is_valid())
49 {
51 }
52 else
53 {
54 throw std::runtime_error(
55 "Error, trying to get rank of invalid dataspace");
56 return 0;
57 }
58 }

◆ release_selection()

void Utopia::DataIO::HDFDataspace::release_selection ( )
inline

Release a previously defined selection.

346 {
347 this->_log->debug("Releasing selection");
348
349 if (not is_valid())
350 {
351 throw std::runtime_error(
352 "Cannot reset selection, dataspace is invalid");
353 }
354
356 }

◆ resize()

void Utopia::DataIO::HDFDataspace::resize ( arma::Row< hsize_t new_size)
inline

Resize the dataspace. The new size needs to fit into the dataspaces capacity.

Note
Dataset needs to be chunked when new_size != capacity of the dataspace
Parameters
new_sizeDesired new size of the dataspace
312 {
313 this->_log->debug("Resizing dataset from {} to {}",
314 Utils::str(size()),
316
317 if (not is_valid())
318 {
319 throw std::runtime_error(
320 "Error, trying to resize an invalid dataspace");
321 }
322
324
325 // make capacity bigger if needed
326 auto new_capacity = arma::max(current_capacity, new_size);
327
328 // resize the dataspace
330 new_size.size(),
331 new_size.memptr(),
332 current_capacity.memptr());
333
334 if (err < 0)
335 {
336 throw std::runtime_error("Error in resizing dataspace");
337 }
338 }

◆ select_all()

void Utopia::DataIO::HDFDataspace::select_all ( )
inline

Select the entire dataspace as hyperslap to be read/written to.

285 {
286 this->_log->debug("Selecting everything in dataspace");
287
288 if (not is_valid())
289 {
290 throw std::runtime_error(
291 "Error, trying to select everything of an invalid dataspace");
292 }
293
295 if (err < 0)
296 {
297 throw std::runtime_error(
298 "Error when trying to select entire dataspace");
299 }
300 }

◆ select_slice()

void Utopia::DataIO::HDFDataspace::select_slice ( arma::Row< hsize_t start,
arma::Row< hsize_t end,
arma::Row< hsize_t stride 
)
inline

Select a slice in the dataspace defined by [start, end, stride] in the manner of numpy. Overwrites old selections.

Parameters
start
end
stride
228 {
229
230 this->_log->debug(
231 "Selecting slice in dataspace with start={}, end={}, stride={}",
233 Utils::str(end),
235
236 if (not is_valid())
237 {
238 throw std::runtime_error(
239 "Error, trying to select a slice in an invalid dataspace");
240 }
241
242 hsize_t r = rank();
243
244 if ((start.n_elem != r) or (end.n_elem != r))
245 {
246 throw std::runtime_error(
247 "Error, dimensionality of start and end has to be the same as "
248 "the dataspace's rank");
249 }
250 // stride may not be given, and hence we have to check for
251 // it in order to correctly compute the counts vector: divison
252 // can be skipped when stride.size() == 0
253
254 arma::Row< hsize_t > count;
255 hsize_t* strideptr = nullptr;
256 if (stride.size() == 0)
257 {
258 count = ((end - start)).as_row();
259 }
260 else
261 {
262 count = ((end - start) / stride).as_row();
263 strideptr = stride.memptr();
264 }
265
268 start.memptr(),
269 strideptr,
270 count.memptr(),
271 nullptr);
272 if (err < 0)
273 {
274 throw std::runtime_error(
275 "Error when trying to select slice in dataspace");
276 }
277 }

◆ size()

arma::Row< hsize_t > Utopia::DataIO::HDFDataspace::size ( )
inline

Get the current size of the dataspace in each dimension.

Returns
arma::Row< hsize_t > Vector containing the dataspace's current size in each dimension
95 {
96 return get_properties().first;
97 }

◆ swap() [1/7]

void Utopia::DataIO::swap ( HDFAttribute lhs,
HDFAttribute rhs 
)

Swaps the states of Attributes rhs and lhs.

Template Parameters
ParentObject1
ParentObject2
Parameters
lhsFirst Attribute to swap
rhsSecond Attribute to swap
989{
990 lhs.swap(rhs);
991}

◆ swap() [2/7]

void Utopia::DataIO::swap ( HDFDataset lhs,
HDFDataset rhs 
)

Exchange state between lhs and rhs.

Parameters
lhsThe left hand side
rhsThe right hand side
Template Parameters
HDFObjectThe type of the parent object
2253{ lhs.swap(rhs); }

◆ swap() [3/7]

void Utopia::DataIO::swap ( HDFDataspace lhs,
HDFDataspace rhs 
)

Swap states of lhs and rhs.

Parameters
lhsDataspace to swap states
rhsDataspace to swap states
455{
456 lhs.swap(rhs);
457}

◆ swap() [4/7]

void Utopia::DataIO::HDFDataspace::swap ( HDFDataspace other)
inline

Swap state with argument.

Parameters
otherOther HDFDataspace instance
440 {
441 using std::swap;
443 swap(static_cast< Base& >(*this), static_cast< Base& >(other));
444 }
void swap(WriteTask< BGB, DW, DB, AWG, AWD > &lhs, WriteTask< BGB, DW, DB, AWG, AWD > &rhs)
Swaps the state of lhs and rhs.
Definition write_task.hh:240
void swap(HDFDataspace &other)
Swap state with argument.
Definition hdfdataspace.hh:439
HDFObject< HDFCategory::dataspace > Base
Definition hdfdataspace.hh:39

◆ swap() [5/7]

void Utopia::DataIO::swap ( HDFGroup lhs,
HDFGroup rhs 
)

Swap lhs and rhs.

Parameters
lhsThe left hand side
rhsThe right hand side
232{
233 lhs.swap(rhs);
234}

◆ swap() [6/7]

void Utopia::DataIO::swap ( HDFIdentifier lhs,
HDFIdentifier rhs 
)

Exchange the states of lhs and rhs.

Parameters
lhs
rhs
288{
289 lhs.swap(rhs);
290}

◆ swap() [7/7]

template<HDFCategory cat>
void Utopia::DataIO::swap ( HDFObject< cat > &  lhs,
HDFObject< cat > &  rhs 
)

Exchange state of lhs and rhs.

Template Parameters
catautomatically determined
Parameters
lhs
rhs
337{
338 lhs.swap(rhs);
339}

◆ ~HDFDataspace()

virtual Utopia::DataIO::HDFDataspace::~HDFDataspace ( )
virtualdefault

Destroy the HDFDataspace object.