Go to the documentation of this file.
9 #ifndef H5EASY_BITS_MISC_HPP
10 #define H5EASY_BITS_MISC_HPP
12 #include "../H5Easy.hpp"
27 std::size_t idx = path.find_last_of(
"/\\");
28 if (idx == std::string::npos) {
30 }
else if (idx == 0) {
33 return path.substr(0, idx);
46 if (!file.
exist(group_name)) {
55 std::ostringstream ss;
56 ss << message << std::endl
57 <<
"Path: " << path << std::endl
58 <<
"Filename: " << file.
getName() << std::endl;
66 return error(file, path,
67 "H5Easy: Dataset already exists, dump with H5Easy::DumpMode::Overwrite "
68 "to overwrite (with an array of the same shape).");
70 return error(file, path,
71 "H5Easy: path exists, but does not correspond to a Dataset. Dump not possible.");
79 const std::vector<size_t>& shape,
82 if (!file.
exist(path)) {
87 std::vector<hsize_t> chunks(shape.begin(), shape.end());
90 if (chunks.size() != shape.size()) {
91 throw error(file, path,
"H5Easy::dump: Incorrect rank ChunkSize");
105 throw error(file, path,
"H5Easy::dump: Inconsistent dimensions");
119 if (!file.
exist(path)) {
125 throw error(file, path,
"H5Easy::dump: Existing field not a scalar");
137 const std::vector<size_t>& shape,
140 if (!file.
exist(path)) {
141 throw error(file, path,
"H5Easy::dumpAttribute: DataSet does not exist");
144 throw error(file, path,
"H5Easy::dumpAttribute: path not a DataSet");
153 throw error(file, path,
"H5Easy::dumpAttribute: Inconsistent dimensions");
157 throw error(file, path,
158 "H5Easy: Attribute exists, overwrite with H5Easy::DumpMode::Overwrite.");
169 if (!file.
exist(path)) {
170 throw error(file, path,
"H5Easy::dumpAttribute: DataSet does not exist");
173 throw error(file, path,
"H5Easy::dumpAttribute: path not a DataSet");
182 throw error(file, path,
"H5Easy::dumpAttribute: Existing field not a scalar");
186 throw error(file, path,
187 "H5Easy: Attribute exists, overwrite with H5Easy::DumpMode::Overwrite.");
193 #endif // H5EASY_BITS_MISC_HPP
DataSpace getSpace() const
getSpace
Definition: H5Attribute_misc.hpp:46
Attribute initAttribute(File &file, const std::string &path, const std::string &key, const std::vector< size_t > &shape, const DumpOptions &options)
Definition: H5Easy_misc.hpp:134
DataSet initScalarDataset(File &file, const std::string &path, const T &data, const DumpOptions &options)
Definition: H5Easy_misc.hpp:114
bool compress() const
Check to compress.
Definition: H5Easy_public.hpp:78
std::vector< size_t > getDimensions() const
getDimensions
Definition: H5Dataspace_misc.hpp:99
DataSet getDataSet(const std::string &dataset_name, const DataSetAccessProps &accessProps=DataSetAccessProps()) const
get an existing dataset in the current file
Definition: H5Node_traits_misc.hpp:95
std::string getParentName(const std::string &path)
Definition: H5Easy_misc.hpp:26
Exception dump_error(File &file, const std::string &path)
Definition: H5Easy_misc.hpp:63
Attribute createAttribute(const std::string &attribute_name, const DataSpace &space, const DataType &type)
create a new attribute with the name attribute_name
Definition: H5Annotate_traits_misc.hpp:25
std::vector< hsize_t > getChunkSize() const
Get chunk size.
Definition: H5Easy_public.hpp:93
unsigned getCompressionLevel() const
Get compression level.
Definition: H5Easy_public.hpp:83
DataSet initDataset(File &file, const std::string &path, const std::vector< size_t > &shape, const DumpOptions &options)
Definition: H5Easy_misc.hpp:77
PropertyList< PropertyType::DATASET_CREATE > DataSetCreateProps
Definition: H5PropertyList.hpp:79
bool hasAttribute(const std::string &attr_name) const
checks an attribute exists
Definition: H5Annotate_traits_misc.hpp:114
static DataSpace From(const ScalarValue &scalar_value)
Definition: H5Dataspace_misc.hpp:129
Options for dumping data.
Definition: H5Easy.hpp:112
ObjectType getObjectType(const std::string &node_name) const
A shorthand to get the kind of object pointed to (group, dataset, type...)
Definition: H5Node_traits_misc.hpp:273
void createGroupsToDataSet(File &file, const std::string &path)
Recursively create groups in an open HDF5 file such that a DataSet can be created (see getParentName)...
Definition: H5Easy_misc.hpp:44
std::vector< size_t > getDimensions() const
Get the dimensions of the whole DataSet. This is a shorthand for getSpace().getDimensions()
Definition: H5DataSet.hpp:83
Attribute initScalarAttribute(File &file, const std::string &path, const std::string &key, const T &data, const DumpOptions &options)
Definition: H5Easy_misc.hpp:163
Definition: H5PropertyList.hpp:117
Definition: H5PropertyList.hpp:95
Definition: H5Easy.hpp:51
bool isChunked() const
Check if chunk-size is manually set (or should be computed automatically).
Definition: H5Easy_public.hpp:88
File class.
Definition: H5File.hpp:24
Class representing an attribute of a dataset or group.
Definition: H5Attribute.hpp:23
bool overwrite() const
Check to overwrite.
Definition: H5Easy_public.hpp:68
size_t getElementCount() const
getElementCount
Definition: H5Dataspace_misc.hpp:110
Attribute getAttribute(const std::string &attribute_name) const
open an existing attribute with the name attribute_name
Definition: H5Annotate_traits_misc.hpp:69
Class representing the space (dimensions) of a dataset.
Definition: H5DataSpace.hpp:37
Exception error(const File &file, const std::string &path, const std::string &message)
Definition: H5Easy_misc.hpp:52
Definition: H5PropertyList.hpp:128
Group createGroup(const std::string &group_name, bool parents=true)
create a new group, and eventually intermediate groups
Definition: H5Node_traits_misc.hpp:107
Basic HighFive Exception class.
Definition: H5Exception.hpp:24
NAME string(REPLACE ".cpp" "_bin" example_name ${example_filename}) if($
Definition: hops/Third-party/HighFive/src/examples/CMakeLists.txt:6
bool exist(const std::string &node_name) const
check a dataset or group exists in the current node / group
Definition: H5Node_traits_misc.hpp:218
size_t getElementCount() const
Get the total number of elements in the current dataset. E.g. 2x2x2 matrix has size 8....
Definition: H5DataSet.hpp:92
DataSet createDataSet(const std::string &dataset_name, const DataSpace &space, const DataType &type, const DataSetCreateProps &createProps=DataSetCreateProps(), const DataSetAccessProps &accessProps=DataSetAccessProps())
createDataSet Create a new dataset in the current file of datatype type and of size space
Definition: H5Node_traits_misc.hpp:36
const std::string & getName() const noexcept
Return the name of the file.
Definition: H5File_misc.hpp:79
Class representing a dataset.
Definition: H5DataSet.hpp:27