icedb  version 0.5.1
Snow particle scattering database API
hdf5_supplemental.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <memory>
3 #include <set>
4 #include <string>
5 #include <vector>
6 #include <functional>
7 #include <stdexcept>
8 #include <sstream>
9 #include <iostream> // For debugging
10 
11 #include "../icedb/compat/gsl/gsl"
12 #include "icedb_h5.h" // Auto-generated. Gets installed in the correct location.
13 #include "hdf5_load.h"
14 #include "../icedb/fs.hpp"
15 #include "../icedb/util.hpp"
16 
17 #define INST_ATTR(y) \
18  y(double); \
19  y(float); \
20  y(uint64_t); \
21  y(int64_t); \
22  y(uint32_t); \
23  y(int32_t); \
24  y(uint16_t); \
25  y(int16_t); \
26  y(uint8_t); \
27  y(int8_t); \
28  y(char); \
29  y(std::string);
30 
31 namespace icedb {
32  namespace fs {
33  namespace hdf5 {
34  int useZLIB();
35  void useZLIB(int);
36 
38 # define ARRAYOFFSET(TYPE, INDEX) [](){TYPE a; return (size_t) &a[INDEX] - (size_t) &a; }()
39 
40  std::set<std::string> getGroupMembers(const ICEDB_H5_GETNUMOBJS_OWNER &base);
41  std::map<std::string, H5G_obj_t> getGroupMembersTypes(const ICEDB_H5_GETNUMOBJS_OWNER &base);
42 
43 
44  typedef std::unique_ptr<H5::Group > HDFgroup_t;
45  //typedef std::unique_ptr<H5::Group, mem::icedb_delete<H5::Group> > HDFgroup_t;
46 
47  HDFgroup_t openOrCreateGroup(gsl::not_null<ICEDB_H5_GROUP_OWNER_PTR> base, gsl::not_null<const char*> name);
48  HDFgroup_t openGroup(gsl::not_null<ICEDB_H5_GROUP_OWNER_PTR> base, gsl::not_null<const char*> name);
49  bool groupExists(gsl::not_null<ICEDB_H5_GROUP_OWNER_PTR> base, gsl::not_null<const char*> name);
50 
53  typedef std::unique_ptr<H5::AtomType> MatchAttributeTypeType;
54  template <class DataType>
55  MatchAttributeTypeType MatchAttributeType()
56  {
57  throw(std::invalid_argument("Unsupported type during attribute conversion in rtmath::plugins::hdf5::MatchAttributeType."));
58  }
59  template<> MatchAttributeTypeType MatchAttributeType<std::string>();
60  template<> MatchAttributeTypeType MatchAttributeType<const char*>();
61  template<> MatchAttributeTypeType MatchAttributeType<char>();
62 
63  template<> MatchAttributeTypeType MatchAttributeType<uint8_t>();
64  template<> MatchAttributeTypeType MatchAttributeType<uint16_t>();
65  template<> MatchAttributeTypeType MatchAttributeType<uint32_t>();
66  template<> MatchAttributeTypeType MatchAttributeType<uint64_t>();
67  template<> MatchAttributeTypeType MatchAttributeType<int8_t>();
68  template<> MatchAttributeTypeType MatchAttributeType<int16_t>();
69  template<> MatchAttributeTypeType MatchAttributeType<int32_t>();
70  template<> MatchAttributeTypeType MatchAttributeType<int64_t>();
71  template<> MatchAttributeTypeType MatchAttributeType<float>();
72  template<> MatchAttributeTypeType MatchAttributeType<double>();
73 
75  template <class DataType> bool isStrType() { return false; }
76  template<> bool isStrType<std::string>();
77  template<> bool isStrType<const char*>();
78 
80  template <class DataType>
81  void insertAttr(const H5::Attribute &attr, gsl::not_null<H5::AtomType*> vls_type, const DataType& value)
82  {
83  attr.write(*vls_type, &value);
84  }
85  template <> void insertAttr<std::string>(const H5::Attribute &attr, gsl::not_null<H5::AtomType*> vls_type, const std::string& value);
86 
88  template <class DataType, class Container>
89  void addAttr(gsl::not_null<Container*> obj, gsl::not_null<const char*> attname, const DataType &value)
90  {
91  auto vls_type = MatchAttributeType<DataType>();
92  //H5::DataSpace att_space(H5S_SCALAR); // Will not work with older NetCDF versions
93  //H5::DataSpace att_space(H5S_SIMPLE);
94  hsize_t dsize = 1; //static_cast<hsize_t>(data.size());
95  H5::DataSpace att_space(1, &dsize);
96  H5::Attribute attr = obj->createAttribute(attname, *vls_type, att_space);
97  insertAttr<DataType>(attr, vls_type.get(), value);
98  }
99 
101  template <class DataType, class Container>
103  gsl::not_null<Container*> obj,
104  gsl::not_null<const char*> attname,
105  const std::vector<size_t> &dimensionality,
106  const std::vector<DataType> &value)
107  {
108  auto ftype = MatchAttributeType<DataType>();
109  std::vector<hsize_t> hdims;
110  for (const auto &d : dimensionality)
111  hdims.push_back(static_cast<hsize_t>(d));
112 
113  // This newer form can be read by old NetCDF versions (like 4.1.1, 01/2014)
114  // The older form could only be read by newer NetCDF versions
115  // Of course, NC can only ever read singular-dimension attributes.
116  H5::DataSpace att_space(static_cast<int>(dimensionality.size()), hdims.data());
117  H5::Attribute attr = obj->createAttribute(attname, *(ftype.get()), att_space);
118  attr.write(*ftype, value.data());
119 
120  // Older form cannot be read by older versions of NetCDF.
121  //H5::ArrayType vls_type(*ftype, static_cast<int>(dimensionality.size()), (hdims.data()));
122  //H5::DataSpace att_space(H5S_SCALAR); // Will not work with older NetCDF versions.
123  //H5::Attribute attr = obj->createAttribute(attname, vls_type, att_space);
124  //attr.write(vls_type, value.data());
125  }
126 
128  template <class DataType, class Container>
130  gsl::not_null<Container*> obj,
131  gsl::not_null<const char*> attname,
132  const std::vector<DataType> &data)
133  {
134  auto ftype = MatchAttributeType<DataType>();
135  hsize_t dsize = static_cast<hsize_t>(data.size());
136  H5::DataSpace att_space(1, &dsize);
137  H5::Attribute attr = obj->createAttribute(attname, *(ftype.get()), att_space);
138  attr.write(*ftype, data.data());
139  }
140 
142  template <class DataType>
143  void loadAttr(const H5::Attribute &attr, gsl::not_null<H5::AtomType*> vls_type, DataType& value)
144  {
145  attr.read(*vls_type, &value);
146  }
147  template <> void loadAttr<std::string>(const H5::Attribute &attr, gsl::not_null<H5::AtomType*> vls_type, std::string& value);
148 
150  template <class DataType, class Container>
151  void readAttr(gsl::not_null<Container*> obj, gsl::not_null<const char*> attname, DataType &value)
152  {
153  auto vls_type = MatchAttributeType<DataType>();
154  H5::DataSpace att_space(H5S_SCALAR);
155  H5::Attribute attr = obj->openAttribute(attname); //, *vls_type, att_space);
156  loadAttr<DataType>(attr, vls_type.get(), value);
157  }
158 
160  template <class DataType, class Container>
161  void readAttrArray(gsl::not_null<Container*> obj, gsl::not_null<const char*> attname,
162  std::vector<size_t> &dims,
163  std::vector<DataType> &value)
164  {
165  H5::Attribute attr = obj->openAttribute(attname);
166  int dimensionality = attr.getArrayType().getArrayNDims();
167  Expects(dimensionality > 0);
168  std::vector<hsize_t> sz(static_cast<size_t>(dimensionality));
169  attr.getArrayType().getArrayDims(sz.data());
170 
171  dims.resize(static_cast<size_t>(dimensionality));
172  size_t numElems = 1;
173  for (size_t i = 0; i < dimensionality; ++i) {
174  dims[i] = static_cast<size_t>(sz[i]);
175  numElems *= dims[i];
176  }
177  value.resize(numElems);
178 
179  auto ftype = MatchAttributeType<DataType>();
180  //H5::IntType ftype(H5::PredType::NATIVE_FLOAT);
181  H5::ArrayType vls_type(*ftype, dimensionality, sz.data());
182 
183  //H5::DataSpace att_space(H5S_SCALAR);
184  //H5::Attribute attr = obj->createAttribute(attname, vls_type, att_space);
185  attr.read(vls_type, value.data());
186  }
187 
189  template <class DataType, class Container>
190  void readAttrVector(gsl::not_null<Container*> obj, gsl::not_null<const char*> attname,
191  std::vector<DataType> &value)
192  {
193  /*
194  std::shared_ptr<H5::AtomType> ftype = MatchAttributeType<DataType>();
195  hsize_t dsize = (hsize_t) data.size();
196  H5::DataSpace att_space(1, &dsize);
197  H5::Attribute attr = obj->createAttribute(attname, *(ftype.get()), att_space);
198  attr.write(*ftype, data.data());
199  */
200  H5::Attribute attr = obj->openAttribute(attname);
201  auto ftype = MatchAttributeType<DataType>();
202  H5::DataSpace dspace = attr.getSpace();
203  value.resize(dspace.getSimpleExtentNdims());
204  attr.read(*(ftype.get()), value.data());
205  }
206 
207  enum class DataContainerType {
208  BASIC,
209  ARRAY,
210  COMPOUND,
211  ENUM,
212  OPAQUE,
213  VLEN,
214  STRING,
215  UNKNOWN
216  };
217 
218  template <class Container>
219  DataContainerType getAttributeGroupingType(gsl::not_null<Container*> obj, gsl::not_null<const char*> attname)
220  {
221  H5::Attribute attr = obj->openAttribute(attname);
222  //const hid_t attrid = attr.getId();
223  H5::DataType dtype = attr.getDataType();
224  //const hid_t dtypeid = dtype.getId();
225  //const H5T_class_t class_type = H5Tget_class(dtypeid);
226  H5T_class_t class_type = dtype.getClass();
227  // I could also use the H5::DataType::detectClass method here...
228  if (class_type == H5T_class_t::H5T_ARRAY) return DataContainerType::ARRAY;
229  else if (class_type == H5T_class_t::H5T_COMPOUND) return DataContainerType::COMPOUND;
230  else if (class_type == H5T_class_t::H5T_ENUM) return DataContainerType::ENUM;
231  else if (class_type == H5T_class_t::H5T_OPAQUE) return DataContainerType::OPAQUE;
232  else if (class_type == H5T_class_t::H5T_INTEGER) return DataContainerType::BASIC;
233  else if (class_type == H5T_class_t::H5T_FLOAT) return DataContainerType::BASIC;
234  else if (class_type == H5T_class_t::H5T_VLEN) return DataContainerType::VLEN;
235  else if (class_type == H5T_class_t::H5T_STRING) return DataContainerType::STRING;
236 
238  }
239 
240  template <class Container>
241  std::vector<hsize_t> getAttrArrayDimensionality(
242  gsl::not_null<Container*> obj, gsl::not_null<const char*> attname)
243  {
244  std::vector<hsize_t> dims;
245  H5::Attribute attr = obj->openAttribute(attname);
246  int dimensionality = attr.getArrayType().getArrayNDims();
247  dims.resize(dimensionality);
248  attr.getArrayType().getArrayDims(dims.data());
249  return dims;
250  }
251 
252  bool attrExists(gsl::not_null<H5::H5Object*> obj, gsl::not_null<const char*> attname);
253 
258  std::pair<bool, bool> symLinkExists(gsl::not_null<ICEDB_H5_GROUP_OWNER_PTR> base, gsl::not_null<const char*> name);
259 
260  // \brief Convenience function to open a group, if it exists
261  // \returns nullptr is the group does not exist.
262  //HDFgroup_t openGroup(gsl::not_null<H5::H5Location*> base, gsl::not_null<const char*> name);
263 
265  bool datasetExists(gsl::not_null<ICEDB_H5_GROUP_OWNER_PTR> base, gsl::not_null<const char*> name);
266 
267  //typedef std::unique_ptr<H5::DataSet, mem::icedb_delete<H5::DataSet> > HDFdataset_t;
268  typedef std::unique_ptr<H5::DataSet > HDFdataset_t;
269 
270 
271  template <class DataType, class Container>
272  HDFdataset_t addDatasetArray(
273  gsl::not_null<Container*> obj, gsl::not_null<const char*> name, size_t rows, size_t cols,
274  gsl::not_null<const DataType*> values, std::shared_ptr<H5::DSetCreatPropList> iplist = nullptr)
275  {
276  using namespace H5;
277  std::vector<hsize_t> sz{ (hsize_t)rows, (hsize_t)cols };
278  int dimensionality = 2;
279  if (cols == 1) dimensionality = 1;
280  H5::DataSpace fspace(dimensionality, sz.data());
281  auto ftype = MatchAttributeType<DataType>();
282  std::shared_ptr<DSetCreatPropList> plist;
283  if (iplist) plist = iplist;
284  else
285  {
286  plist = std::shared_ptr<DSetCreatPropList>(new DSetCreatPropList);
287  if (!isStrType<DataType>())
288  {
289  int fillvalue = -1;
290  plist->setFillValue(PredType::NATIVE_INT, &fillvalue);
291  if (useZLIB()) {
292  plist->setChunk(static_cast<int>(sz.size()), sz.data());
293  plist->setDeflate(useZLIB());
294  }
295  }
296  }
297 
298  HDFdataset_t dataset(new DataSet(obj->createDataSet(name, *(ftype.get()),
299  fspace, *(plist.get()))));
300  dataset->write(values, *(ftype.get()));
301  return dataset;
302  }
303 
304  template <class DataType, class Container>
305  HDFdataset_t addDatasetArray(
306  gsl::not_null<Container*> obj, gsl::not_null<const char*> name, size_t rows,
307  gsl::not_null<const DataType*> values, std::shared_ptr<H5::DSetCreatPropList> iplist = nullptr)
308  {
309  return std::move(addDatasetArray(obj, name, rows, 1, values, iplist));
310  }
311 
312  template <class DataType, class Container>
313  gsl::not_null<H5::DataSet*> writeDatasetArray(
314  const std::vector<size_t> &dimensions,
315  gsl::not_null<H5::DataSet*> dset,
316  gsl::not_null<const DataType*> values)
317  {
318  using namespace H5;
319  std::vector<hsize_t> sz(dimensions.size());
320  for (size_t i = 0; i < sz.size(); ++i)
321  sz[i] = static_cast<hsize_t>(dimensions[i]);
322  //DataSpace fspace(static_cast<int>(sz.size()), sz);
323  auto ftype = MatchAttributeType<DataType>();
324 
325  dset->write(values, *(ftype.get()));
326  return dset;
327  }
328 
329  template <class DataType, class Container>
330  HDFdataset_t createDatasetRaw(
331  gsl::not_null<Container*> parent,
332  gsl::not_null<const char*> name,
333  const std::vector<size_t> &dims,
334  std::shared_ptr<H5::DSetCreatPropList> iplist = nullptr)
335  {
336  using namespace H5;
337  std::vector<hsize_t> sz(dims.size());
338  for (size_t i = 0; i < sz.size(); ++i)
339  sz[i] = static_cast<hsize_t>(dims[i]);
340 
341  DataSpace fspace(static_cast<int>(sz.size()), sz.data());
342  auto ftype = MatchAttributeType<DataType>();
343  std::shared_ptr<DSetCreatPropList> plist;
344  if (iplist) plist = iplist;
345  else
346  {
347  plist = std::shared_ptr<DSetCreatPropList>(new DSetCreatPropList);
348  if (!isStrType<DataType>())
349  {
350  int fillvalue = -1;
351  plist->setFillValue(PredType::NATIVE_INT, &fillvalue);
352  if (useZLIB()) {
353  plist->setChunk(static_cast<int>(sz.size()), sz.data());
354  plist->setDeflate(useZLIB());
355  }
356  }
357  }
358 
359  HDFdataset_t dataset(new DataSet(parent->createDataSet(name, *(ftype.get()),
360  fspace, *(plist.get()))));
361  return dataset;
362  }
363 
364 
365  template <class Container>
366  HDFdataset_t readDatasetDimensions(
367  gsl::not_null<Container*> obj,
368  gsl::not_null<const char*> name,
369  std::vector<size_t> &out)
370  {
371  using namespace H5;
372 
373  HDFdataset_t dataset(new H5::DataSet(obj->openDataSet(name)));
374  H5T_class_t type_class = dataset->getTypeClass();
375  DataSpace fspace = dataset->getSpace();
376  int rank = fspace.getSimpleExtentNdims();
377 
378  std::vector<hsize_t> sz(rank);
379  int dimensionality = fspace.getSimpleExtentDims( sz.data(), NULL);
380  for (size_t i = 0; i < rank; ++i)
381  out.push_back(sz[i]);
382 
383  return dataset;
384  }
385 
386  void readDatasetDimensions(gsl::not_null<H5::DataSet*> dataset, std::vector<size_t> &dims);
387 
388  size_t readDatasetNumDimensions(gsl::not_null<H5::DataSet*> dataset);
389 
390  template <class DataType, class Container>
391  HDFdataset_t readDatasetArray(
392  gsl::not_null<Container*> obj, gsl::not_null<const char*> name,
393  gsl::not_null<DataType*> values)
394  {
395  using namespace H5;
396 
397  HDFdataset_t dataset(new H5::DataSet(obj->openDataSet(name)));
398  H5T_class_t type_class = dataset->getTypeClass();
399  DataSpace fspace = dataset->getSpace();
400 
401  //DataSpace fspace(dimensionality, sz);
402  auto ftype = MatchAttributeType<DataType>();
403 
404  dataset->read(values, *(ftype.get()));
405  return std::move(dataset);
406  }
407 
408  template <class DataType, class Container>
409  gsl::not_null<Container*> readDatasetArray(
410  gsl::not_null<Container*> dataset,
411  gsl::not_null<DataType*> values)
412  {
413  using namespace H5;
414 
415  H5T_class_t type_class = dataset->getTypeClass();
416  DataSpace fspace = dataset->getSpace();
417 
418  //DataSpace fspace(dimensionality, sz);
419  auto ftype = MatchAttributeType<DataType>();
420 
421  dataset->read(values, *(ftype.get()));
422  return dataset;
423  }
424 
428  template <class Container>
429  void addNames(
430  gsl::not_null<Container*> obj,
431  const std::string &prefix,
432  size_t num,
433  const std::function<std::string(int)> &s, size_t stride = 0, size_t mCols = 0)
434  {
435  size_t nstride = stride;
436  if (!nstride) nstride = 1;
437  for (size_t i = 0; i < num; ++i)
438  {
439  size_t j = i / nstride;
440  std::string lbl = s((int)j);
441  std::ostringstream fldname;
442  fldname << std::string(prefix);
443  fldname.width(2);
444  fldname.fill('0');
445  fldname << std::right << i << "_NAME";
446  std::string sfldname = fldname.str();
447  addAttr<std::string, Container>(obj, sfldname.c_str(), lbl);
448  }
449  }
450 
451 
455  template <class Container>
456  void addColNames(gsl::not_null<Container*> obj, size_t num, const std::function<std::string(int)> &s, size_t stride = 0, size_t mCols = 0)
457  {
458  size_t nstride = stride;
459  if (!nstride) nstride = 1;
460  for (size_t i = 0; i < num; ++i)
461  {
462  size_t j = i / nstride;
463  std::string lbl = s((int)j);
464  std::ostringstream fldname;
465  fldname << "COLUMN_";
466  fldname.width(2);
467  fldname.fill('0');
468  fldname << std::right << i << "_NAME";
469  std::string sfldname = fldname.str();
470  if (stride)
471  {
472  size_t k = i % nstride;
473  if (!mCols) {
474  if (k == 0) lbl.append("_X");
475  if (k == 1) lbl.append("_Y");
476  if (k == 2) lbl.append("_Z");
477  if (k == 3) lbl.append("_R");
478  }
479  else {
480  size_t row = k / mCols;
481  size_t col = k % mCols;
482  std::ostringstream iappend;
483  iappend << "_" << row << "_" << col;
484  lbl.append(iappend.str());
485  }
486  }
487  addAttr<std::string, Container>(obj, sfldname.c_str(), lbl);
488  }
489  }
490 
491 
493  std::shared_ptr<H5::DSetCreatPropList> make_plist(size_t rows, size_t cols, bool compress = true);
494 
495  std::vector<std::string> explode(std::string const & s, char delim);
496  std::vector<std::string> explodeHDF5groupPath(const std::string &s);
497 
498  H5::Group createGroupStructure(const std::string &groupName, ICEDB_H5_GROUP_OWNER &base);
499  H5::Group createGroupStructure(const std::vector<std::string> &groupNames, ICEDB_H5_GROUP_OWNER &base);
500 
501 
502  unsigned int getHDF5IOflags(fs::IOopenFlags flag);
503 
505  template <class DataType>
506  bool isType(hid_t) { throw(std::invalid_argument("Unsupported type. (icedb::fs::hdf5::isType(hid_t))")); return false; }
507 
508  template <class DataType, class Container>
509  bool isType(gsl::not_null<const Container*> obj, const std::string &attributeName) {
510  H5::Attribute attr = obj->openAttribute(attributeName);
511  return isType<DataType>(attr.getDataType().getId());
512  }
513  template <class DataType, class Container>
514  bool isType(gsl::not_null<const Container*> obj) {
515  return isType<DataType>(obj->getDataType().getId());
516  }
517  template<> bool isType<uint64_t>(hid_t type_id);
518  template<> bool isType<int64_t>(hid_t type_id);
519  template<> bool isType<uint32_t>(hid_t type_id);
520  template<> bool isType<int32_t>(hid_t type_id);
521  template<> bool isType<uint16_t>(hid_t type_id);
522  template<> bool isType<int16_t>(hid_t type_id);
523  template<> bool isType<uint8_t>(hid_t type_id);
524  template<> bool isType<int8_t>(hid_t type_id);
525  template<> bool isType<float>(hid_t type_id);
526  template<> bool isType<double>(hid_t type_id);
527  template<> bool isType<char>(hid_t type_id);
528  template<> bool isType<std::string>(hid_t type_id);
529 
530  }
531  }
532 }
MatchAttributeTypeType MatchAttributeType< int8_t >()
Definition: export-hdf5.cpp:30
std::unique_ptr< H5::Group > HDFgroup_t
void addAttrVector(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, const std::vector< DataType > &data)
Writes a vector of objects.
bool groupExists(gsl::not_null< ICEDB_H5_GROUP_OWNER_PTR > base, gsl::not_null< const char *> name)
Definition: Data_Types.hpp:9
MatchAttributeTypeType MatchAttributeType< char >()
Definition: export-hdf5.cpp:24
bool isType< uint8_t >(hid_t type_id)
bool attrExists(gsl::not_null< H5::H5Object *> base, gsl::not_null< const char *> name)
Definition: export-hdf5.cpp:88
bool isType< uint16_t >(hid_t type_id)
H5::Group createGroupStructure(const std::string &groupName, ICEDB_H5_GROUP_OWNER &base)
IOopenFlags
Definition: fs.hpp:16
HDFdataset_t createDatasetRaw(gsl::not_null< Container *> parent, gsl::not_null< const char *> name, const std::vector< size_t > &dims, std::shared_ptr< H5::DSetCreatPropList > iplist=nullptr)
MatchAttributeTypeType MatchAttributeType()
bool isStrType()
Check to see if output type is for a string.
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 >()
Definition: export-hdf5.cpp:36
DataContainerType getAttributeGroupingType(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname)
void loadAttr(const H5::Attribute &attr, gsl::not_null< H5::AtomType *> vls_type, DataType &value)
Handles proper insertion of strings versus other data types.
bool isType< uint64_t >(hid_t type_id)
MatchAttributeTypeType MatchAttributeType< uint16_t >()
Definition: export-hdf5.cpp:27
MatchAttributeTypeType MatchAttributeType< uint32_t >()
Definition: export-hdf5.cpp:28
std::vector< hsize_t > getAttrArrayDimensionality(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname)
MatchAttributeTypeType MatchAttributeType< uint64_t >()
Definition: export-hdf5.cpp:29
void addAttr(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, const DataType &value)
Convenient template to add an attribute of a variable type to a group or dataset. ...
bool isType< int8_t >(hid_t type_id)
void insertAttr(const H5::Attribute &attr, gsl::not_null< H5::AtomType *> vls_type, const DataType &value)
Handles proper insertion of strings versus other data types.
void readAttrVector(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, std::vector< DataType > &value)
Reads an array (or vector) of objects.
bool isType< int16_t >(hid_t type_id)
std::vector< std::string > explode(std::string const &s, char delim)
MatchAttributeTypeType MatchAttributeType< int64_t >()
Definition: export-hdf5.cpp:33
MatchAttributeTypeType MatchAttributeType< int32_t >()
Definition: export-hdf5.cpp:32
bool isType< int64_t >(hid_t type_id)
bool isType(hid_t)
Functions to detect the type of data.
void readDatasetDimensions(gsl::not_null< H5::DataSet *> dataset, std::vector< size_t > &dims)
std::vector< std::string > explodeHDF5groupPath(const std::string &s)
void addColNames(gsl::not_null< Container *> obj, size_t num, const std::function< std::string(int)> &s, size_t stride=0, size_t mCols=0)
Add column names to table.
HDFgroup_t openGroup(gsl::not_null< ICEDB_H5_GROUP_OWNER_PTR > base, gsl::not_null< const char *> name)
Definition: export-hdf5.cpp:75
void readAttr(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, DataType &value)
Convenient template to read an attribute of a variable.
HDFdataset_t readDatasetArray(gsl::not_null< Container *> obj, gsl::not_null< const char *> name, gsl::not_null< DataType *> values)
bool isType< int32_t >(hid_t type_id)
bool isType< uint32_t >(hid_t type_id)
gsl::not_null< H5::DataSet * > writeDatasetArray(const std::vector< size_t > &dimensions, gsl::not_null< H5::DataSet *> dset, gsl::not_null< const DataType *> values)
HDFdataset_t addDatasetArray(gsl::not_null< Container *> obj, gsl::not_null< const char *> name, size_t rows, size_t cols, gsl::not_null< const DataType *> values, std::shared_ptr< H5::DSetCreatPropList > iplist=nullptr)
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)
std::unique_ptr< H5::DataSet > HDFdataset_t
bool isType< char >(hid_t type_id)
MatchAttributeTypeType MatchAttributeType< int16_t >()
Definition: export-hdf5.cpp:31
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)
void addAttrArray(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, const std::vector< size_t > &dimensionality, const std::vector< DataType > &value)
Writes an array of objects.
MatchAttributeTypeType MatchAttributeType< double >()
Definition: export-hdf5.cpp:37
void readAttrArray(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, std::vector< size_t > &dims, std::vector< DataType > &value)
Reads an array (or vector) of objects.
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)
Definition: export-hdf5.cpp:62
void addNames(gsl::not_null< Container *> obj, const std::string &prefix, size_t num, const std::function< std::string(int)> &s, size_t stride=0, size_t mCols=0)
Add column names to table.
MatchAttributeTypeType MatchAttributeType< uint8_t >()
Definition: export-hdf5.cpp:26