1 #ifndef UTOPIA_DATAIO_HDFFILE_HH
2 #define UTOPIA_DATAIO_HDFFILE_HH
7 #include <unordered_map>
97 open(std::string path, std::string access)
100 "Opening file at {} with access specifier {}", path, access);
103 throw std::runtime_error(
104 "File still bound to another HDF5 file when trying to call "
105 "'open'. Close first.");
109 hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
113 H5Pset_fapl_stdio(fapl);
114 H5Pset_fclose_degree(fapl, H5F_CLOSE_STRONG);
118 bind_to(H5Fcreate(path.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fapl),
122 else if (access ==
"r")
125 H5Fopen(path.c_str(), H5F_ACC_RDONLY, fapl), &H5Fclose, path);
127 else if (access ==
"r+")
129 bind_to(H5Fopen(path.c_str(), H5F_ACC_RDWR, fapl), &H5Fclose);
131 else if (access ==
"x")
133 bind_to(H5Fcreate(path.c_str(), H5F_ACC_EXCL, H5P_DEFAULT, fapl),
137 else if (access ==
"a")
139 hid_t file_test = H5Fopen(path.c_str(), H5F_ACC_RDWR, fapl);
144 H5Fcreate(path.c_str(), H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
151 throw std::invalid_argument(
"wrong type of access specifier, "
152 "see documentation for allowed "
156 _base_group = std::make_shared< HDFGroup >(*
this,
"/");
164 std::shared_ptr< HDFGroup >
178 std::shared_ptr< HDFGroup >
185 path = path.substr(1, path.size() - 1);
198 std::shared_ptr< HDFDataset >
200 std::vector< hsize_t > capacity = {},
201 std::vector< hsize_t > chunksizes = {},
202 std::size_t compresslevel = 0)
208 path = path.substr(1, path.size() - 1);
212 path, capacity, chunksizes, compresslevel);
223 _base_group->delete_group(std::forward< std::string&& >(path));
234 H5Fflush(
get_C_id(), H5F_SCOPE_GLOBAL);
Class representing a HDF5 file.
Definition: hdffile.hh:62
HDFFile & operator=(HDFFile &&other)=default
Move assigment operator.
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
void flush()
Initiates an immediate write to disk of the data of the file.
Definition: hdffile.hh:230
HDFFile(HDFFile &&other)=default
Move constructor Construct a new HDFFile object via move semantics.
HDFFile(const HDFFile &other)=delete
Copy constructor. Explicitly deleted, hence cannot be used.
std::shared_ptr< HDFGroup > get_basegroup()
Get the basegroup object via shared ptr.
Definition: hdffile.hh:165
std::shared_ptr< HDFGroup > open_group(std::string path)
Open group at path 'path', creating all intermediate objects in the path. Separation character is: /.
Definition: hdffile.hh:179
HDFFile()=default
Construct a new default HDFFile object.
HDFFile(std::string path, std::string access)
Construct a new HDFFile object.
Definition: hdffile.hh:289
virtual ~HDFFile()=default
Destroy the HDFFile object.
std::shared_ptr< HDFGroup > _base_group
Pointer to base group of the file.
Definition: hdffile.hh:68
void swap(HDFFile &other)
Function for exchanging states.
Definition: hdffile.hh:77
void delete_group(std::string &&path)
deletes the group pointed to by absolute path 'path'
Definition: hdffile.hh:221
std::shared_ptr< HDFDataset > open_dataset(std::string path, std::vector< hsize_t > capacity={}, std::vector< hsize_t > chunksizes={}, std::size_t compresslevel=0)
open dataset
Definition: hdffile.hh:199
HDFFile & operator=(const HDFFile &other)=delete
Copy assignment operator, explicitly deleted, hence cannot be used.
Common base class for all HDF5 classes in the DATAIO Module i.e., for all classes that wrap HDF5-C-Li...
Definition: hdfobject.hh:37
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
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
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
const std::string log_data_io
Definition: logging.hh:19
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
This is the central file of the HDF5 dataIO module of Utopia and provides a class for writing to,...
This file provides a class for creating and managing groups in a HDF5 file, which then can create oth...
This file provides metafunctions for automatically determining the nature of a C/C++ types at compile...