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);
118 template <
class K,
class V>
120 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");
130 template <
class K,
class V>
132 void mapToH5Compound(
const std::map<K,V> & m, hid_t fid,
const Hi5Tree::path_t & path,
const char *labelFirst=
"key",
const char *labelSecond=
"value");
141 void linkToH5Attribute(hid_t lid, hid_t fid,
const std::string &path,
const std::string &attribute);
147 unsigned short compressionLevel;
169 const conv_t & conv(
const T & x){
178 template <
class K,
class V>
179 void Writer::vectorToH5Compound(
const std::vector<std::pair<K,V> > & v, hid_t fid,
const Hi5Tree::path_t & path,
const char *labelFirst,
const char *labelSecond){
183 typedef std::vector<std::pair<K,V> > vect_t;
184 typedef typename vect_t::value_type pair_t;
185 typedef typename pair_t::first_type first_type;
186 typedef typename pair_t::second_type second_type;
194 const hsize_t size =
sizeof(pair_t);
195 mout.
special(path,
": ", v.size(),
" elements x ", size,
"b");
199 mout.
debug(
"datatypes: ", first_h5t,
", ", second_h5t);
202 hid_t memtype = H5Tcreate (H5T_COMPOUND, size);
203 mout.
debug(
"H5Tcreate, memtype=", memtype);
207 status = H5Tinsert (memtype, labelFirst, 0, first_h5t);
208 handleStatus(status,
"H5Tinsert failed", mout, __LINE__);
211 status = H5Tinsert (memtype, labelSecond,
sizeof(first_type), second_h5t);
212 handleStatus(status,
"H5Tinsert failed", mout, __LINE__);
218 mout.
debug(
"h5 (file) types: ", std_t1,
", ", std_t2);
220 const hsize_t s1 = H5Tget_size(std_t1);
221 const hsize_t s2 = H5Tget_size(std_t2);
222 mout.
debug(
"h5 element sizes [bytes]: ", s1,
", ", s2);
224 hid_t filetype = H5Tcreate (H5T_COMPOUND, s1+s2);
225 H5Tinsert(filetype, labelFirst, 0, std_t1);
226 H5Tinsert(filetype, labelSecond, s1, std_t2);
231 hid_t space = H5Screate_simple (1, dims, NULL);
233 const std::string pathStr(path);
234 mout.
debug(
"experimental: creating compound at ", pathStr);
236 if (H5Lexists(fid, pathStr.c_str(), H5P_DEFAULT)){
237 mout.
warn(
"compound object exists already (combining is not supported) : ", pathStr);
241 hid_t dset = H5Dcreate(fid, pathStr.c_str(), filetype, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
242 handleStatus(dset,
"H5Dcreate failed", mout, __LINE__);
245 status = H5Dwrite (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &v.at(0));
246 handleStatus(dset,
"H5Dwrite failed", mout, __LINE__);
248 status = H5Dclose(dset);
249 handleStatus(status,
"H5Dclose failed", mout, __LINE__);
253 status = H5Sclose(space);
254 handleStatus(status,
"H5Sclose failed", mout, __LINE__);
264 typedef long int conv_t;
268 return static_cast<conv_t
>(x);
279 typedef const char * conv_t;
282 conv_t conv(
const std::string & x){
288 template <
class K,
class V>
289 void Writer::mapToH5Compound(
const std::map<K,V> & m, hid_t fid,
const Hi5Tree::path_t & path,
const char *labelFirst,
const char *labelSecond){
293 typedef typename CompoundConv<K>::conv_t key_t;
294 typedef typename CompoundConv<V>::conv_t val_t;
296 typedef std::vector<std::pair<key_t,val_t> > vect_t;
300 typename vect_t::iterator vit = v.begin();
301 for (
typename std::map<K,V>::const_iterator it = m.begin(); it != m.end(); ++it) {
304 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:308
Logger & special(const TT &... args)
Other useful information.
Definition: Log.h:527
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
Definition: Geometry.h:145
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition: Image.h:184
Base class for Reader and Writer, essentially just wrapping some utilities.
Definition: Hi5.h:122
static hid_t getH5StandardType(const std::type_info &type)
Give a native C++ type, returns a standard(?) HDF5 data type.
Definition: Hi5.cpp:128
static hid_t getH5NativeDataType()
Given a native C++ type, returns a native HDF5 data type.
Definition: Hi5.h:155
Definition: Hi5Write.h:162
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:419
static void writeFile(const std::string &filename, const Hi5Tree &tree)
Writes Rack's hi5 object to an HDF5 file.
Definition: Hi5Write.cpp:54
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:327
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:179
static hsize_t deriveDimensions(const drain::image::Geometry &g, std::vector< hsize_t > &dims, std::vector< hsize_t > &chunkDims)
Definition: Hi5Write.cpp:271
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:506
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:289
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:110
DRAIN_VARIABLE Variable
Value container supporting dynamic type.
Definition: Variable.h:63