44#include <drain/util/TreeOrdered.h>
45#include <drain/TypeUtils.h>
46#include <drain/image/Image.h>
69 void writeFile(
const std::string &filename,
const Hi5Tree &tree);
83 void treeToH5File(
const Hi5Tree &tree, hid_t fid,
const Hi5Tree::path_t & path);
119 template <
class K,
class V>
121 void vectorToH5Compound(
const std::vector<std::pair<K,V> > & v, hid_t fid,
const Hi5Tree::path_t & path,
const char *labelFirst=
"key",
const char *labelSecond=
"value");
131 template <
class K,
class V>
133 void mapToH5Compound(
const std::map<K,V> & m, hid_t fid,
const Hi5Tree::path_t & path,
const char *labelFirst=
"key",
const char *labelSecond=
"value");
142 void linkToH5Attribute(hid_t lid, hid_t fid,
const std::string &path,
const std::string &attribute);
148 unsigned short compressionLevel;
177 const conv_t & conv(
const T & x){
186template <
class K,
class V>
187void Writer::vectorToH5Compound(
const std::vector<std::pair<K,V> > & v, hid_t fid,
const Hi5Tree::path_t & path,
const char *labelFirst,
const char *labelSecond){
191 typedef std::vector<std::pair<K,V> > vect_t;
192 typedef typename vect_t::value_type pair_t;
193 typedef typename pair_t::first_type first_type;
194 typedef typename pair_t::second_type second_type;
202 const hsize_t size =
sizeof(pair_t);
203 mout.
special(path,
": ", v.size(),
" elements x ", size,
"b");
207 mout.
debug(
"datatypes: ", first_h5t,
", ", second_h5t);
210 hid_t memtype = H5Tcreate (H5T_COMPOUND, size);
211 mout.
debug(
"H5Tcreate, memtype=", memtype);
215 status = H5Tinsert (memtype, labelFirst, 0, first_h5t);
216 handleStatus(status,
"H5Tinsert failed", mout, __LINE__);
219 status = H5Tinsert (memtype, labelSecond,
sizeof(first_type), second_h5t);
220 handleStatus(status,
"H5Tinsert failed", mout, __LINE__);
226 mout.
debug(
"h5 (file) types: ", std_t1,
", ", std_t2);
228 const hsize_t s1 = H5Tget_size(std_t1);
229 const hsize_t s2 = H5Tget_size(std_t2);
230 mout.
debug(
"h5 element sizes [bytes]: ", s1,
", ", s2);
232 hid_t filetype = H5Tcreate (H5T_COMPOUND, s1+s2);
233 H5Tinsert(filetype, labelFirst, 0, std_t1);
234 H5Tinsert(filetype, labelSecond, s1, std_t2);
239 hid_t space = H5Screate_simple (1, dims, NULL);
241 const std::string pathStr(path);
242 mout.
debug(
"experimental: creating compound at ", pathStr);
244 if (H5Lexists(fid, pathStr.c_str(), H5P_DEFAULT)){
245 mout.
warn(
"compound object exists already (combining is not supported) : ", pathStr);
249 hid_t dset = H5Dcreate(fid, pathStr.c_str(), filetype, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
250 handleStatus(dset,
"H5Dcreate failed", mout, __LINE__);
253 status = H5Dwrite (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &v.at(0));
254 handleStatus(dset,
"H5Dwrite failed", mout, __LINE__);
256 status = H5Dclose(dset);
257 handleStatus(status,
"H5Dclose failed", mout, __LINE__);
261 status = H5Sclose(space);
262 handleStatus(status,
"H5Sclose failed", mout, __LINE__);
272 typedef long int conv_t;
276 return static_cast<conv_t
>(x);
287 typedef const char * conv_t;
290 conv_t conv(
const std::string & x){
296template <
class K,
class V>
297void Writer::mapToH5Compound(
const std::map<K,V> & m, hid_t fid,
const Hi5Tree::path_t & path,
const char *labelFirst,
const char *labelSecond){
301 typedef typename CompoundConv<K>::conv_t key_t;
302 typedef typename CompoundConv<V>::conv_t val_t;
304 typedef std::vector<std::pair<key_t,val_t> > vect_t;
308 typename vect_t::iterator vit = v.begin();
309 for (
typename std::map<K,V>::const_iterator it = m.begin(); it != m.end(); ++it) {
312 mout.
debug2() << vit->first <<
':' << vit->second << mout.endl;
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:440
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:676
Logger & special(const TT &... args)
Other useful information.
Definition Log.h:541
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:686
Tuple of N elements of type T.
Definition UniTuple.h:65
Definition Geometry.h:143
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:183
Base class for Reader and Writer, essentially just wrapping some utilities.
Definition Hi5.h:169
static hid_t getH5StandardType(const std::type_info &type)
Give a native C++ type, returns a standard(?) HDF5 data type.
Definition Hi5.cpp:218
static hid_t getH5NativeDataType()
Given a native C++ type, returns a native HDF5 data type.
Definition Hi5.h:202
Definition Hi5Write.h:170
Converts Rack's h5 structure to native h5 structure applied for file output.
Definition Hi5Write.h:63
static void dataToH5Attribute(const drain::Variable &d, hid_t fid, const Hi5Tree::path_t &path, const std::string &attribute)
Converts drain::Variable to an HDF5 attribute of a group or dataset.
Definition Hi5Write.cpp:443
static void writeFile(const std::string &filename, const Hi5Tree &tree)
Writes Rack's hi5 object to an HDF5 file.
Definition Hi5Write.cpp:57
static hid_t imageToH5DataSet(const drain::image::Image &image, hid_t fid, const Hi5Tree::path_t &path)
Converts drain::image::Image to an HDF5 dataset.
Definition Hi5Write.cpp:351
static drain::UniTuple< size_t, 2 > chunkSize
chunk dimensions: width, height (channels always as actual number)
Definition Hi5Write.h:155
static void vectorToH5Compound(const std::vector< std::pair< K, V > > &v, hid_t fid, const Hi5Tree::path_t &path, const char *labelFirst="key", const char *labelSecond="value")
Write a vector of paired values.
Definition Hi5Write.h:187
static hsize_t deriveDimensions(const drain::image::Geometry &g, std::vector< hsize_t > &dims, std::vector< hsize_t > &chunkDims)
Definition Hi5Write.cpp:276
static void dataToH5AttributeString(const drain::Variable &d, hid_t fid, const Hi5Tree::path_t &path, const std::string &attribute)
Creates and writes scalar (non-std::string) attributes to group.
Definition Hi5Write.cpp:530
static void linkToH5Attribute(hid_t lid, hid_t fid, const std::string &path, const std::string &attribute)
Under constr.
static void mapToH5Compound(const std::map< K, V > &m, hid_t fid, const Hi5Tree::path_t &path, const char *labelFirst="key", const char *labelSecond="value")
TODO:
Definition Hi5Write.h:297
static void treeToH5File(const Hi5Tree &tree, hid_t fid, const Hi5Tree::path_t &path)
Writes Rack's hi5 object to an HDF5 file.
Definition Hi5Write.cpp:112
DRAIN_VARIABLE Variable
Value container supporting dynamic type.
Definition Variable.h:63
Default implementation.
Definition TypeName.h:54