v1.0.0-rc.38
This commit is contained in:
+54
-3
@@ -196,6 +196,24 @@ bool HDF5DataType::IsFloat() const {
|
||||
|
||||
HDF5Dcpl::HDF5Dcpl() : HDF5Id() {
|
||||
id = H5Pcreate(H5P_DATASET_CREATE);
|
||||
ndim = 0;
|
||||
}
|
||||
|
||||
HDF5Dcpl::HDF5Dcpl(const HDF5DataSet &data_set) : HDF5Id() {
|
||||
id = H5Dget_create_plist(data_set.GetID());
|
||||
|
||||
// Check if chunking is enabled
|
||||
H5D_layout_t layout = H5Pget_layout(id);
|
||||
if (layout != H5D_CHUNKED) {
|
||||
ndim = 0;
|
||||
} else {
|
||||
ndim = H5Pget_chunk(id, 0, nullptr);
|
||||
if (ndim <= 0) {
|
||||
H5Pclose(id);
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5,
|
||||
"Error getting number of chunk dimensions");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HDF5Dcpl::~HDF5Dcpl() {
|
||||
@@ -210,6 +228,17 @@ void HDF5Dcpl::SetChunking(const std::vector<hsize_t> &dims) {
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5, "Cannot set chunking");
|
||||
}
|
||||
|
||||
std::vector<hsize_t> HDF5Dcpl::GetChunking() {
|
||||
if (ndim <= 0)
|
||||
return {};
|
||||
|
||||
std::vector<hsize_t> ret(ndim);
|
||||
if (H5Pget_chunk(id, ndim, ret.data()) < 0)
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5, "Cannot get chunk dimensions");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t HDF5Dcpl::GetNumOfDimensions() const {
|
||||
return ndim;
|
||||
}
|
||||
@@ -559,7 +588,7 @@ void RegisterHDF5Filter() {
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5, "Cannot register Bitshuffle filter");
|
||||
}
|
||||
|
||||
void HDF5Dcpl::SetCompression(CompressionAlgorithm c, size_t elem_size, size_t block_size) {
|
||||
void HDF5Dcpl::SetCompression(CompressionAlgorithm c, size_t block_size) {
|
||||
constexpr uint32_t cd_nelmts = 2;
|
||||
unsigned int params[cd_nelmts];
|
||||
switch (c) {
|
||||
@@ -588,6 +617,28 @@ void HDF5Dcpl::SetCompression(CompressionAlgorithm c, size_t elem_size, size_t b
|
||||
|
||||
}
|
||||
|
||||
CompressionAlgorithm HDF5Dcpl::GetCompression() {
|
||||
int num_filters = H5Pget_nfilters(id);
|
||||
if (num_filters > 1)
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5, "Only single filter supported");
|
||||
if (num_filters == 0)
|
||||
return CompressionAlgorithm::NO_COMPRESSION;
|
||||
|
||||
uint32_t cd_values[8];
|
||||
size_t cd_nelemts = sizeof(cd_values);
|
||||
memset(cd_values, 0, sizeof(cd_values));
|
||||
|
||||
if (H5Pget_filter2(id, 0, nullptr, &cd_nelemts, cd_values, 0, nullptr, nullptr)
|
||||
!= BSHUF_H5FILTER)
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5,"Only Bitshuffle filter supported");
|
||||
|
||||
if (cd_values[4] == BSHUF_H5_COMPRESS_LZ4)
|
||||
return CompressionAlgorithm::BSHUF_LZ4;
|
||||
if (cd_values[4] == BSHUF_H5_COMPRESS_ZSTD)
|
||||
return CompressionAlgorithm::BSHUF_ZSTD;
|
||||
throw JFJochException(JFJochExceptionCategory::HDF5,"Weird value of parameter " + std::to_string(cd_values[1]));
|
||||
}
|
||||
|
||||
std::string ExtractFilename(const std::string& str) {
|
||||
std::filesystem::path path(str);
|
||||
// if (std::filesystem::is_regular_file(path))
|
||||
@@ -616,12 +667,12 @@ std::optional<int64_t> HDF5Object::GetOptInt(const std::string &name) const {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string HDF5Object::GetString(const std::string &name) const {
|
||||
std::string HDF5Object::GetString(const std::string &name, const std::string &def) const {
|
||||
if (Exists(name)) {
|
||||
HDF5DataSet dataset(*this, name);
|
||||
return dataset.ReadString();
|
||||
}
|
||||
return "";
|
||||
return def;
|
||||
}
|
||||
|
||||
bool HDF5Object::Exists(const std::string &name) const {
|
||||
|
||||
Reference in New Issue
Block a user