1 #include "../private/hdf5_supplemental.hpp" 2 #include "../icedb/compat/gsl/gsl_assert" 3 #include "../icedb/defs.h" 22 template<>
MatchAttributeTypeType MatchAttributeType<std::string>() {
return std::make_unique<H5::StrType>(0, H5T_VARIABLE); }
23 template<>
MatchAttributeTypeType MatchAttributeType<const char*>() {
return std::make_unique<H5::StrType>(0, H5T_VARIABLE); }
41 template<>
bool isStrType<std::string>() {
return true; }
42 template<>
bool isStrType<const char*>() {
return true; }
44 template <>
void insertAttr<std::string>(
const H5::Attribute &attr, gsl::not_null<H5::AtomType*> vls_type,
const std::string& value)
46 attr.write(*vls_type, value);
48 template <>
void loadAttr<std::string>(
const H5::Attribute &attr, gsl::not_null<H5::AtomType*> vls_type, std::string& value)
50 attr.read(*vls_type, value);
66 res=std::make_unique<H5::Group>( base->openGroup( name ));
67 }
catch( H5::GroupIException not_found_error ) {
68 res=std::make_unique<H5::Group>(base->createGroup( name ));
69 }
catch( H5::FileIException not_found_error ) {
70 res=std::make_unique<H5::Group>(base->createGroup( name ));
79 res=(std::make_unique<H5::Group>(base->openGroup( name )));
80 }
catch( H5::GroupIException not_found_error ) {
82 }
catch( H5::FileIException not_found_error ) {
88 bool attrExists(gsl::not_null<H5::H5Object*> base, gsl::not_null<const char*> name)
91 H5::Attribute(base->openAttribute(name));
94 catch (H5::AttributeIException not_found_error) {
97 catch (H5::FileIException not_found_error) {
100 catch (H5::GroupIException not_found_error) {
105 bool groupExists(gsl::not_null<ICEDB_H5_GROUP_OWNER_PTR> base, gsl::not_null<const char*> name)
108 H5::Group( base->openGroup( name ));
110 }
catch( H5::GroupIException not_found_error ) {
113 catch (H5::FileIException not_found_error) {
118 std::pair<bool,bool>
symLinkExists(gsl::not_null<ICEDB_H5_GROUP_OWNER_PTR> base, gsl::not_null<const char*> name)
120 bool linkexists =
false;
121 bool linkgood =
false;
125 base->getObjinfo(name,
false, stats);
129 base->getObjinfo(name,
true, stats);
131 }
catch( H5::GroupIException not_found_error ) {
132 }
catch( H5::FileIException not_found_error) {
134 return std::pair<bool,bool>(linkexists,linkgood);
137 bool datasetExists(gsl::not_null<ICEDB_H5_GROUP_OWNER_PTR> base, gsl::not_null<const char*> name)
140 H5::DataSet(base->openDataSet(name));
143 catch (H5::GroupIException not_found_error) {
146 catch (H5::FileIException not_found_error) {
151 std::shared_ptr<H5::DSetCreatPropList>
make_plist(
size_t rows,
size_t cols,
bool compress)
154 const hsize_t chunk[2] = {
static_cast<hsize_t
>(rows), static_cast<hsize_t>(cols) };
155 auto plist = std::make_shared<H5::DSetCreatPropList>();
156 plist->setChunk(2, chunk);
158 plist->setDeflate(6);
163 std::set<std::string> res;
164 const hsize_t numObjs = base.getNumObjs();
165 for (hsize_t i = 0; i < numObjs; ++i)
167 std::string name = base.getObjnameByIdx(i);
174 std::map<std::string, H5G_obj_t> res;
175 const hsize_t numObjs = base.getNumObjs();
176 for (hsize_t i = 0; i < numObjs; ++i)
178 std::string name = base.getObjnameByIdx(i);
179 H5G_obj_t gtype = base.getObjTypeByIdx(i);
185 std::vector<std::string>
explode(std::string
const & s,
char delim)
187 std::vector<std::string> result;
188 std::istringstream iss(s);
190 for (std::string token; std::getline(iss, token, delim); )
193 result.push_back(std::move(token));
200 std::string mountStr = s;
201 std::replace(mountStr.begin(), mountStr.end(),
'\\',
'/');
208 Expects(groupName.size() > 0);
209 std::string mountStr = groupName;
210 std::replace(mountStr.begin(), mountStr.end(),
'\\',
'/');
211 std::vector<std::string> groups =
explode(mountStr,
'/');
222 std::shared_ptr<ICEDB_H5_GROUP_OWNER> current(&base, [](ICEDB_H5_GROUP_OWNER*) {});
223 std::vector<H5::Group> vgrps;
227 for (
const auto &grpname : groups) {
228 if (!grpname.size())
continue;
230 if (!members.count(grpname)) {
231 vgrps.push_back(std::move(current->createGroup(grpname)));
232 current = std::shared_ptr<H5::Group>(&(*(vgrps.rbegin())), [](H5::Group*) {});
237 vgrps.push_back(std::move(current->openGroup(grpname)));
238 current = std::shared_ptr<H5::Group>(&(*(vgrps.rbegin())), [](H5::Group*) {});
241 return std::move((*(vgrps.rbegin())));
247 unsigned int Hflags = 0;
256 template<>
bool isType<uint64_t>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_UINT64) > 0) ?
true :
false; }
257 template<>
bool isType<int64_t>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_INT64) > 0) ?
true :
false; }
258 template<>
bool isType<uint32_t>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_UINT32) > 0) ?
true :
false; }
259 template<>
bool isType<int32_t>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_INT32) > 0) ?
true :
false; }
260 template<>
bool isType<uint16_t>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_UINT16) > 0) ?
true :
false; }
261 template<>
bool isType<int16_t>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_INT16) > 0) ?
true :
false; }
262 template<>
bool isType<uint8_t>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_UINT8) > 0) ?
true :
false; }
263 template<>
bool isType<int8_t>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_INT8) > 0) ?
true :
false; }
264 template<>
bool isType<float>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_FLOAT) > 0) ?
true :
false; }
265 template<>
bool isType<double>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_DOUBLE) > 0) ?
true :
false; }
266 template<>
bool isType<char>(hid_t type_id) {
return (H5Tequal(type_id, H5T_NATIVE_CHAR) > 0) ?
true :
false; }
267 template<>
bool isType<std::string>(hid_t type_id) {
268 std::shared_ptr<H5::AtomType> a = std::make_shared<H5::StrType>(0, H5T_VARIABLE);
269 return (H5Tequal(type_id, a->getId()) > 0) ? true :
false;
275 const H5T_class_t type_class = dataset->getTypeClass();
276 DataSpace fspace = dataset->getSpace();
277 int rank = fspace.getSimpleExtentNdims();
279 std::vector<hsize_t> sz(rank);
280 const int dimensionality = fspace.getSimpleExtentDims(sz.data(), NULL);
281 for (
size_t i = 0; i < rank; ++i)
282 dims.push_back((
size_t)sz[i]);
287 const H5T_class_t type_class = dataset->getTypeClass();
288 DataSpace fspace = dataset->getSpace();
289 int rank = fspace.getSimpleExtentNdims();
MatchAttributeTypeType MatchAttributeType< int8_t >()
std::unique_ptr< H5::Group > HDFgroup_t
bool groupExists(gsl::not_null< ICEDB_H5_GROUP_OWNER_PTR > base, gsl::not_null< const char *> name)
MatchAttributeTypeType MatchAttributeType< char >()
bool isType< uint8_t >(hid_t type_id)
bool attrExists(gsl::not_null< H5::H5Object *> base, gsl::not_null< const char *> name)
bool isType< uint16_t >(hid_t type_id)
H5::Group createGroupStructure(const std::string &groupName, ICEDB_H5_GROUP_OWNER &base)
std::shared_ptr< H5::DSetCreatPropList > make_plist(size_t rows, size_t cols, bool compress)
Creates a property list with the compression + chunking as specified.
std::set< std::string > getGroupMembers(const ICEDB_H5_GETNUMOBJS_OWNER &base)
MatchAttributeTypeType MatchAttributeType< float >()
bool isType< uint64_t >(hid_t type_id)
MatchAttributeTypeType MatchAttributeType< uint16_t >()
MatchAttributeTypeType MatchAttributeType< uint32_t >()
MatchAttributeTypeType MatchAttributeType< uint64_t >()
bool isType< int8_t >(hid_t type_id)
bool isType< int16_t >(hid_t type_id)
std::vector< std::string > explode(std::string const &s, char delim)
MatchAttributeTypeType MatchAttributeType< int64_t >()
MatchAttributeTypeType MatchAttributeType< int32_t >()
bool isType< int64_t >(hid_t type_id)
void readDatasetDimensions(gsl::not_null< H5::DataSet *> dataset, std::vector< size_t > &dims)
std::vector< std::string > explodeHDF5groupPath(const std::string &s)
HDFgroup_t openGroup(gsl::not_null< ICEDB_H5_GROUP_OWNER_PTR > base, gsl::not_null< const char *> name)
bool isType< int32_t >(hid_t type_id)
bool isType< uint32_t >(hid_t type_id)
std::pair< bool, bool > symLinkExists(gsl::not_null< ICEDB_H5_GROUP_OWNER_PTR > base, gsl::not_null< const char *> name)
unsigned int getHDF5IOflags(fs::IOopenFlags flags)
bool isType< char >(hid_t type_id)
MatchAttributeTypeType MatchAttributeType< int16_t >()
bool isType< double >(hid_t type_id)
bool datasetExists(gsl::not_null< ICEDB_H5_GROUP_OWNER_PTR > base, gsl::not_null< const char *> name)
Convenience function to check if a given dataset exists.
bool isType< float >(hid_t type_id)
size_t readDatasetNumDimensions(gsl::not_null< H5::DataSet *> dataset)
MatchAttributeTypeType MatchAttributeType< double >()
std::map< std::string, H5G_obj_t > getGroupMembersTypes(const ICEDB_H5_GETNUMOBJS_OWNER &base)
std::unique_ptr< H5::AtomType > MatchAttributeTypeType
HDFgroup_t openOrCreateGroup(gsl::not_null< ICEDB_H5_GROUP_OWNER_PTR > base, gsl::not_null< const char *> name)
MatchAttributeTypeType MatchAttributeType< uint8_t >()