Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Utopia::DataIO::HDFGroup Class Referencefinal

Class represting a HDFGroup, an object analogous to a folder for HDFFiles. More...

#include <hdfgroup.hh>

Inheritance diagram for Utopia::DataIO::HDFGroup:
Inheritance graph
[legend]
Collaboration diagram for Utopia::DataIO::HDFGroup:
Collaboration graph
[legend]

Public Types

using Base = HDFObject< HDFCategory::group >
 

Public Member Functions

template<typename Attrdata >
void add_attribute (std::string name, Attrdata attribute_data)
 write attribute
 
template<HDFCategory cat>
void open (HDFObject< cat > &parent, std::string path)
 Bind the object to a new HDF5 Group, either opening existing or creating a new one at path 'path' in the HDF5 group 'parent'.
 
std::shared_ptr< HDFGroupopen_group (std::string path)
 Opens a group.
 
std::shared_ptr< HDFDatasetopen_dataset (std::string path, std::vector< hsize_t > capacity={}, std::vector< hsize_t > chunksizes={}, std::size_t compresslevel=0)
 open a HDFDataset
 
void delete_group (std::string path)
 Delete the group at the given relative path.
 
 HDFGroup ()=default
 Default constructor.
 
 HDFGroup (const HDFGroup &other)=default
 Construct a new HDFGroup object.
 
 HDFGroup (HDFGroup &&other)=default
 Construct a new HDFGroup object.
 
HDFGroupoperator= (HDFGroup &&other)=default
 assignment operator
 
HDFGroupoperator= (const HDFGroup &other)=default
 Copy assignment operator.
 
template<HDFCategory cat>
 HDFGroup (HDFObject< cat > &parent, std::string path)
 Construct a new HDFGroup object.
 
virtual ~HDFGroup ()=default
 Destroy the HDFGroup object.
 
- Public Member Functions inherited from Utopia::DataIO::HDFObject< HDFCategory::group >
void swap (HDFObject &other)
 swap the state of the caller with the state of the argument
 
std::string get_path () const
 Get the name or path object.
 
auto get_id_object () const
 Get the id object.
 
auto get_logger () const
 Get the logger object.
 
hid_t get_C_id () const
 Get the C id object.
 
auto get_refcount ()
 Get the reference count of object.
 
virtual bool is_valid () const
 Check if the object is still valid.
 
void close ()
 Close function which takes care of correctly closing the object and managing the reference counter.
 
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 created beforehand.
 
 HDFObject ()
 Construct HDFObject from the given arguments.
 
 HDFObject (HDFObject &&other)
 Construct HDFObject by moving.
 
 HDFObject (const HDFObject &other)=default
 Construct HDFObject by copying another object.
 
 HDFObject (hid_t id, std::function< herr_t(hid_t) > closing_func, std::string path={})
 Construct HDFObject from the given argument.
 
HDFObjectoperator= (const HDFObject &other)
 Copy assignment operator.
 
HDFObjectoperator= (HDFObject &&other)
 move assignment operator
 
virtual ~HDFObject ()
 Destroy the HDFObject object. Has to be implemented in subclass!
 

Additional Inherited Members

- Static Public Attributes inherited from Utopia::DataIO::HDFObject< HDFCategory::group >
static constexpr HDFCategory category
 Named variable for template arg.
 
- Protected Attributes inherited from Utopia::DataIO::HDFObject< HDFCategory::group >
HDFIdentifier _id
 Identifier object that binds an instance of this class to an HDF5 object.
 
std::string _path
 Name of the object.
 
std::shared_ptr< spdlog::logger > _log
 pointer to the logger for dataio
 

Detailed Description

Class represting a HDFGroup, an object analogous to a folder for HDFFiles.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ HDFGroup() [1/4]

Utopia::DataIO::HDFGroup::HDFGroup ( )
default

Default constructor.

◆ HDFGroup() [2/4]

Utopia::DataIO::HDFGroup::HDFGroup ( const HDFGroup other)
default

Construct a new HDFGroup object.

Parameters
otherThe other

◆ HDFGroup() [3/4]

Utopia::DataIO::HDFGroup::HDFGroup ( HDFGroup &&  other)
default

Construct a new HDFGroup object.

Parameters
otherThe other

◆ HDFGroup() [4/4]

template<HDFCategory cat>
Utopia::DataIO::HDFGroup::HDFGroup ( HDFObject< cat > &  parent,
std::string  path 
)
inline

Construct a new HDFGroup object.

Parameters
parentThe parent group to create or open the group in
nameThe name of the group
Template Parameters
HDFObject{ description }
213 {
214 open(parent, path);
215 }
void open(HDFObject< cat > &parent, std::string path)
Bind the object to a new HDF5 Group, either opening existing or creating a new one at path 'path' in ...
Definition hdfgroup.hh:68
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

◆ ~HDFGroup()

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

Destroy the HDFGroup object.

Member Function Documentation

◆ add_attribute()

template<typename Attrdata >
void Utopia::DataIO::HDFGroup::add_attribute ( std::string  name,
Attrdata  attribute_data 
)
inline

write attribute

Parameters
nameThe name
attribute_dataThe attribute data
Template Parameters
Attrdatatype of attribute data
55 {
56 HDFAttribute(*this, name).write(attribute_data);
57 }

◆ delete_group()

void Utopia::DataIO::HDFGroup::delete_group ( std::string  path)
inline

Delete the group at the given relative path.

Parameters
pathrelative path to group to delete
150 {
151 this->_log->debug("Deleting group {} in {}", path, _path);
152
153 // check if group exists in file. If it does, delete the link
154 herr_t status = 1;
155 if (is_valid())
156 {
157 // group exists, can be deleted
158 status = H5Ldelete(get_C_id(), path.c_str(), H5P_DEFAULT);
159 if (status < 0)
160 {
161 throw std::runtime_error("Deletion of group at path '" + path +
162 "' failed! Wrong path?");
163 }
164 }
165 // group does not exist, do nothing
166 }
std::string _path
Name of the object.
Definition hdfobject.hh:50
virtual bool is_valid() const
Check if the object is still valid.
Definition hdfobject.hh:143
std::shared_ptr< spdlog::logger > _log
pointer to the logger for dataio
Definition hdfobject.hh:56
hid_t get_C_id() const
Get the C id object.
Definition hdfobject.hh:120

◆ open()

template<HDFCategory cat>
void Utopia::DataIO::HDFGroup::open ( HDFObject< cat > &  parent,
std::string  path 
)
inline

Bind the object to a new HDF5 Group, either opening existing or creating a new one at path 'path' in the HDF5 group 'parent'.

Parameters
parent
path
69 {
70
71 this->_log->debug(
72 "Opening group with path {} at parent {}", path, parent.get_path());
73 // check if given path exists in parent
74 if (path_is_valid(parent.get_C_id(), path))
75 {
76 // manage new group using his class
77 bind_to(H5Gopen(parent.get_C_id(), path.c_str(), H5P_DEFAULT),
78 &H5Gclose,
79 path);
80
81 if (get_C_id() < 0)
82 {
83 throw std::runtime_error("Group opening for path '" + path +
84 "' failed!");
85 }
86 }
87 else
88 { // group does not exist yet
89 // create the group and intermediates
92
93 // manage new group using his class
94 bind_to(H5Gcreate(parent.get_C_id(),
95 path.c_str(),
99 &H5Gclose,
100 path);
101
103
104 if (get_C_id() < 0)
105 {
106 throw std::runtime_error("Group creation for path '" + path +
107 "' failed!");
108 }
109 }
110 }
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
auto 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 o...
Definition hdfutilities.hh:150

◆ open_dataset()

std::shared_ptr< HDFDataset > Utopia::DataIO::HDFGroup::open_dataset ( std::string  path,
std::vector< hsize_t capacity = {},
std::vector< hsize_t chunksizes = {},
std::size_t  compresslevel = 0 
)
inline

open a HDFDataset

Template Parameters
HDFDatasetdataset type with parent type
Parameters
pathThe path of the HDFDataset
Returns
A std::shared_ptr pointing at the newly created dataset
135 {},
136 std::vector< hsize_t > chunksizes = {},
137 std::size_t compresslevel = 0)
138 {
139 return std::make_shared< HDFDataset >(
140 *this, path, capacity, chunksizes, compresslevel);
141 }

◆ open_group()

std::shared_ptr< HDFGroup > Utopia::DataIO::HDFGroup::open_group ( std::string  path)
inline

Opens a group.

Parameters
pathThe path to open
Returns
std::shared_ptr<HDFGroup>
121 {
122 return std::make_shared< HDFGroup >(*this, path);
123 }

◆ operator=() [1/2]

HDFGroup & Utopia::DataIO::HDFGroup::operator= ( const HDFGroup other)
default

Copy assignment operator.

Parameters
other
Returns
HDFGroup&

◆ operator=() [2/2]

HDFGroup & Utopia::DataIO::HDFGroup::operator= ( HDFGroup &&  other)
default

assignment operator

Parameters
otherThe other
Returns
HDFGroup&

The documentation for this class was generated from the following file: