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

Class representing a HDF5 file. More...

#include <hdffile.hh>

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

Public Member Functions

void swap (HDFFile &other)
 Function for exchanging states.
 
void open (std::string path, std::string access)
 Open a file at location 'path' with access specifier 'access'. Keep in mind that if the object refers to another file, it has to be closed first before opening another.
 
std::shared_ptr< HDFGroupget_basegroup ()
 Get the basegroup object via shared ptr.
 
std::shared_ptr< HDFGroupopen_group (std::string path)
 Open group at path 'path', creating all intermediate objects in the path. Separation character is: /.
 
std::shared_ptr< HDFDatasetopen_dataset (std::string path, std::vector< hsize_t > capacity={}, std::vector< hsize_t > chunksizes={}, std::size_t compresslevel=0)
 open dataset
 
void delete_group (std::string &&path)
 deletes the group pointed to by absolute path 'path'
 
void flush ()
 Initiates an immediate write to disk of the data of the file.
 
 HDFFile ()=default
 Construct a new default HDFFile object.
 
 HDFFile (HDFFile &&other)=default
 Move constructor Construct a new HDFFile object via move semantics.
 
HDFFileoperator= (const HDFFile &other)=delete
 Copy assignment operator, explicitly deleted, hence cannot be used.
 
HDFFileoperator= (HDFFile &&other)=default
 Move assigment operator.
 
 HDFFile (const HDFFile &other)=delete
 Copy constructor. Explicitly deleted, hence cannot be used.
 
 HDFFile (std::string path, std::string access)
 Construct a new HDFFile object.
 
virtual ~HDFFile ()=default
 Destroy the HDFFile object.
 
- Public Member Functions inherited from Utopia::DataIO::HDFObject< HDFCategory::file >
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!
 

Private Attributes

std::shared_ptr< HDFGroup_base_group
 Pointer to base group of the file.
 

Additional Inherited Members

- Static Public Attributes inherited from Utopia::DataIO::HDFObject< HDFCategory::file >
static constexpr HDFCategory category
 Named variable for template arg.
 
- Protected Attributes inherited from Utopia::DataIO::HDFObject< HDFCategory::file >
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 representing a HDF5 file.

Constructor & Destructor Documentation

◆ HDFFile() [1/4]

Utopia::DataIO::HDFFile::HDFFile ( )
default

Construct a new default HDFFile object.

◆ HDFFile() [2/4]

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

Move constructor Construct a new HDFFile object via move semantics.

Parameters
otherrvalue reference to HDFFile object

◆ HDFFile() [3/4]

Utopia::DataIO::HDFFile::HDFFile ( const HDFFile other)
delete

Copy constructor. Explicitly deleted, hence cannot be used.

Parameters
other
Returns
HDFFile&

◆ HDFFile() [4/4]

Utopia::DataIO::HDFFile::HDFFile ( std::string  path,
std::string  access 
)
inline

Construct a new HDFFile object.

Parameters
pathPath to the new file
accessAccess specifier for the new file, possible values: 'r' (readonly, file must exist), 'r+' (read/write, file must exist), 'w' (create file, truncate if exists), 'x' (create file, fail if exists), or 'a' (read/write if exists, create otherwise)
289 : HDFFile()
290 {
291 // init the logger here because it is needed throughout the module
292 // and its existence is not guaranteed when it is initialized in `core`
293 _log = init_logger(log_data_io, spdlog::level::warn, false);
294 open(path, access);
295 }
void open(std::string path, std::string access)
Open a file at location 'path' with access specifier 'access'. Keep in mind that if the object refers...
Definition hdffile.hh:97
HDFFile()=default
Construct a new default HDFFile object.
std::shared_ptr< spdlog::logger > _log
pointer to the logger for dataio
Definition hdfobject.hh:56
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
std::shared_ptr< spdlog::logger > init_logger(const std::string name, const spdlog::level::level_enum level, const bool throw_on_exist=true)
Initialize a logger with a certain name and log level.
Definition logging.hh:31
const std::string log_data_io
Definition logging.hh:19

◆ ~HDFFile()

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

Destroy the HDFFile object.

Member Function Documentation

◆ delete_group()

void Utopia::DataIO::HDFFile::delete_group ( std::string &&  path)
inline

deletes the group pointed to by absolute path 'path'

Parameters
pathabsolute path to the group to be deleted
222 {
223 _base_group->delete_group(std::forward< std::string&& >(path));
224 }
std::shared_ptr< HDFGroup > _base_group
Pointer to base group of the file.
Definition hdffile.hh:68

◆ flush()

void Utopia::DataIO::HDFFile::flush ( )
inline

Initiates an immediate write to disk of the data of the file.

231 {
232 if (is_valid())
233 {
235 }
236 }
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

◆ get_basegroup()

std::shared_ptr< HDFGroup > Utopia::DataIO::HDFFile::get_basegroup ( )
inline

Get the basegroup object via shared ptr.

Returns
std::shared_ptr<HDFGroup>
166 {
167 return _base_group;
168 }

◆ open()

void Utopia::DataIO::HDFFile::open ( std::string  path,
std::string  access 
)
inline

Open a file at location 'path' with access specifier 'access'. Keep in mind that if the object refers to another file, it has to be closed first before opening another.

Parameters
pathPath to open the file at
accessAccess specifier for the new file, possible values: 'r' (readonly, file must exist), 'r+' (read/write, file must exist), 'w' (create file, truncate if exists), 'x' (create file, fail if exists), or 'a' (read/write if exists, create otherwise)
98 {
99 this->_log->info(
100 "Opening file at {} with access specifier {}", path, access);
101 if (is_valid())
102 {
103 throw std::runtime_error(
104 "File still bound to another HDF5 file when trying to call "
105 "'open'. Close first.");
106 }
107
108 // create file access property list
110
111 // set driver to stdio and close strongly, i.e., close all resources
112 // with the file
115
116 if (access == "w")
117 {
119 &H5Fclose,
120 path);
121 }
122 else if (access == "r")
123 {
124 bind_to(
125 H5Fopen(path.c_str(), H5F_ACC_RDONLY, fapl), &H5Fclose, path);
126 }
127 else if (access == "r+")
128 {
129 bind_to(H5Fopen(path.c_str(), H5F_ACC_RDWR, fapl), &H5Fclose);
130 }
131 else if (access == "x")
132 {
134 &H5Fclose,
135 path);
136 }
137 else if (access == "a")
138 {
139 hid_t file_test = H5Fopen(path.c_str(), H5F_ACC_RDWR, fapl);
140
141 if (file_test < 0)
142 {
143 file_test =
144 H5Fcreate(path.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
145 }
146
148 }
149 else
150 {
151 throw std::invalid_argument("wrong type of access specifier, "
152 "see documentation for allowed "
153 "values");
154 }
155
156 _base_group = std::make_shared< HDFGroup >(*this, "/");
157 }
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

◆ open_dataset()

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

open dataset

Parameters
pathThe path to the dataset
Returns
std::shared_ptr<HDFDataset>
200 {},
201 std::vector< hsize_t > chunksizes = {},
202 std::size_t compresslevel = 0)
203 {
204 // this removes the '/' at the beginning, because this is
205 // reserved for the basegroup
206 if (path[0] == '/')
207 {
208 path = path.substr(1, path.size() - 1);
209 }
210
211 return _base_group->open_dataset(
212 path, capacity, chunksizes, compresslevel);
213 }

◆ open_group()

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

Open group at path 'path', creating all intermediate objects in the path. Separation character is: /.

Parameters
pathThe path to the group
Returns
std::shared_ptr<HDFGroup>
180 {
181 // this removes the '/' at the beginning, because this is
182 // reserved for the basegroup
183 if (path[0] == '/')
184 {
185 path = path.substr(1, path.size() - 1);
186 }
187
188 return _base_group->open_group(path);
189 }

◆ operator=() [1/2]

HDFFile & Utopia::DataIO::HDFFile::operator= ( const HDFFile other)
delete

Copy assignment operator, explicitly deleted, hence cannot be used.

Parameters
other
Returns
HDFFile&

◆ operator=() [2/2]

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

Move assigment operator.

Parameters
otherreference to HDFFile object
Returns
HDFFile&

◆ swap()

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

Function for exchanging states.

Parameters
otherThe other
78 {
79 using std::swap;
81 swap(_base_group, other._base_group);
82 }
void swap(HDFFile &other)
Function for exchanging states.
Definition hdffile.hh:77
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

Member Data Documentation

◆ _base_group

std::shared_ptr< HDFGroup > Utopia::DataIO::HDFFile::_base_group
private

Pointer to base group of the file.


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