36 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_H5_H
37 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_H5_H
39 #include <boost/enable_shared_from_this.hpp>
40 #include <boost/functional/hash.hpp>
41 #include <boost/shared_ptr.hpp>
52 namespace LibUtilities
57 #define H5_CONSTRUCT(ans, func, args) \
59 hid_t ret = func args; \
61 ErrorUtil::Error(ErrorUtil::efatal, \
64 "HDF5 error in API function " #func, \
68 #define H5_CALL(func, args) \
70 herr_t ret = func args; \
72 ErrorUtil::Error(ErrorUtil::efatal, \
75 "HDF5 error in API function " #func, \
79 class Error :
public std::exception
106 class Object :
public boost::enable_shared_from_this<Object>
109 virtual void Close() = 0;
116 inline operator hid_t()
const
133 static PListSharedPtr
Default();
170 void SetChunk(
const std::vector<hsize_t> &dims);
187 LinkIterator(CanHaveGroupsDataSetsSharedPtr grp, hsize_t idx = 0);
193 return !(*
this == other);
201 static herr_t
helper(hid_t g_id,
203 const H5L_info_t *info,
205 CanHaveGroupsDataSetsSharedPtr
m_grp;
214 GroupSharedPtr
CreateGroup(
const std::string &name,
221 DataTypeSharedPtr type,
222 DataSpaceSharedPtr space,
230 const std::string &name,
231 const std::vector<T> &data,
237 GroupSharedPtr
OpenGroup(
const std::string &name,
243 const std::string &name,
259 AttrIterator(CanHaveAttributesSharedPtr obj, hsize_t idx = 0);
265 return !(*
this == other);
273 static herr_t
helper(hid_t g_id,
275 const H5A_info_t *info,
285 DataTypeSharedPtr type,
286 DataSpaceSharedPtr space);
290 void SetAttribute(
const std::string &name,
const T &value);
292 void SetAttribute(
const std::string &name,
const std::vector<T> &value);
294 template <
class T>
void GetAttribute(
const std::string &name, T &value);
296 void GetAttribute(
const std::string &name, std::vector<T> &value);
307 static DataSpaceSharedPtr
Null();
308 static DataSpaceSharedPtr
Scalar();
309 static DataSpaceSharedPtr
OneD(hsize_t size);
312 DataSpace(hsize_t size, hsize_t max = H5S_UNLIMITED - 1);
313 DataSpace(
const std::vector<hsize_t> &dims);
314 DataSpace(
const std::vector<hsize_t> &dims,
315 const std::vector<hsize_t> &max_dims);
319 void SelectRange(
const hsize_t start,
const hsize_t count);
339 static ConvertedType
Convert(
const T &obj);
340 static T
Deconvert(
const ConvertedType &obj);
356 static ConvertedType
Convert(
const T &obj);
357 static T
Deconvert(
const ConvertedType &obj);
362 static const void *
GetAddress(
const ConvertedType &obj);
368 static DataTypeSharedPtr
GetType();
369 static DataTypeSharedPtr
GetType(
const T &obj);
377 static DataTypeSharedPtr
String(
size_t len = 0);
378 template <
class T>
static DataTypeSharedPtr
OfObject(
const T &obj)
382 virtual void Close();
383 DataTypeSharedPtr
Copy()
const;
393 template <
class T>
static DataTypeSharedPtr
Native();
394 static DataTypeSharedPtr
CS1();
407 DataSpaceSharedPtr
GetSpace()
const;
413 static AttributeSharedPtr
Create(hid_t parent,
414 const std::string &name,
415 DataTypeSharedPtr type,
416 DataSpaceSharedPtr space);
417 static AttributeSharedPtr
Open(hid_t parent,
const std::string &name);
425 static FileSharedPtr
Create(
const std::string &filename,
429 static FileSharedPtr
Open(
const std::string &filename,
447 CanHaveAttributesSharedPtr
operator[](hsize_t idx);
448 CanHaveAttributesSharedPtr
operator[](
const std::string &key);
460 DataSpaceSharedPtr
GetSpace()
const;
462 template <
class T>
void Write(
const std::vector<T> &data)
467 (
m_Id, mem_t->GetId(), H5S_ALL, H5S_ALL, H5P_DEFAULT, &data[0]));
470 void Write(
const std::vector<T> &data,
471 DataSpaceSharedPtr filespace,
484 template <
class T>
void Read(std::vector<T> &data)
487 DataSpaceSharedPtr space =
GetSpace();
488 ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
489 "vector data not 1D");
491 H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
497 (
m_Id, mem_t->GetId(), H5S_ALL, H5S_ALL, H5P_DEFAULT, &data[0]));
500 void Read(std::vector<T> &data,
501 DataSpaceSharedPtr filespace,
506 len = H5Sget_select_npoints(filespace->GetId());
526 T>::Convert(
const T &obj)
540 return PredefinedDataType::Native<T>();
560 return Converter::Convert(obj);
567 return Converter::Deconvert(obj);
574 inline static ConvertedType
Convert(
const std::string &obj)
578 inline static std::string
Deconvert(
const ConvertedType &obj)
580 return std::string(obj);
595 template <
typename T>
609 template <
typename T>
611 const std::vector<T> &value)
621 const void *converted_buf = NULL;
624 converted_vals.resize(value.size());
625 for (
size_t i = 0; i < value.size(); ++i)
629 converted_buf = &converted_vals[0];
633 converted_buf = &value[0];
636 H5_CALL(H5Awrite, (attr->GetId(), type->GetId(), converted_buf));
639 template <
typename T>
654 template <
typename T>
656 std::vector<T> &value)
664 DataSpaceSharedPtr space = attr->GetSpace();
665 ASSERTL0(H5Sget_simple_extent_ndims(space->GetId()) == 1,
666 "vector data not 1D");
668 H5Sget_simple_extent_dims(space->GetId(), &len, &maxdim);
671 void *converted_buf = NULL;
674 converted_vals.resize(len);
675 converted_buf = &converted_vals[0];
679 converted_buf = &value[0];
682 H5_CALL(H5Aread, (attr->GetId(), type->GetId(), converted_buf));
687 end = converted_vals.end();
689 for (; src != end; ++src, ++
dest)
698 const std::string &name,
699 const std::vector<T> &data,
700 PListSharedPtr createPL,
701 PListSharedPtr accessPL)
705 DataSetSharedPtr dataset =
707 dataset->Write(data);
#define H5_CALL(func, args)
static ConvertedType Convert(const T &obj)
static PListSharedPtr DatatypeCreate()
Properties for datatype creation.
void Write(const std::vector< T > &data)
#define ASSERTL0(condition, msg)
boost::shared_ptr< Group > GroupSharedPtr
CanHaveAttributesSharedPtr m_obj
const std::string & operator*()
static DataTypeSharedPtr CS1()
static FileSharedPtr Create(const std::string &filename, unsigned mode, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
static const void * GetAddress(const ConvertedType &obj)
void SelectRange(const hsize_t start, const hsize_t count)
static AttributeSharedPtr Create(hid_t parent, const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
LinkIterator(CanHaveGroupsDataSetsSharedPtr grp, hsize_t idx=0)
static DataTypeSharedPtr OfObject(const T &obj)
PredefinedDataType(hid_t)
static herr_t helper(hid_t g_id, const char *name, const H5L_info_t *info, void *op_data)
boost::shared_ptr< DataSet > DataSetSharedPtr
virtual hsize_t GetNumElements()=0
static T Deconvert(const ConvertedType &obj)
static DataTypeSharedPtr GetType()
AttrIterator(CanHaveAttributesSharedPtr obj, hsize_t idx=0)
DataSetSharedPtr CreateDataSet(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
static DataTypeSharedPtr String(size_t len=0)
Converter::ConvertedType ConvertedType
static PListSharedPtr GroupAccess()
Properties for group access.
boost::shared_ptr< File > FileSharedPtr
DataSetSharedPtr OpenDataSet(const std::string &name, PListSharedPtr accessPL=PList::Default()) const
Mixin for objects that can have attributes (Group, DataSet, DataType)
boost::shared_ptr< DataType > DataTypeSharedPtr
AttrIterator & operator++()
boost::shared_ptr< PList > PListSharedPtr
static PListSharedPtr DatasetCreate()
Properties for dataset creation.
const char * ConvertedVectorElemType
const char * ConvertedType
DataSetSharedPtr CreateWriteDataSet(const std::string &name, const std::vector< T > &data, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
void SetDxMpioIndependent()
bool operator!=(const AttrIterator &other) const
bool operator!=(const LinkIterator &other) const
DataTypeConversionPolicy< T > Converter
static PListSharedPtr GroupCreate()
Properties for group creation.
AttrIterator attr_begin()
const std::string & operator*()
friend class key_iterator
Wrap and HDF5 data type object. Technically this can have attributes, but not really bothered...
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
boost::shared_ptr< DataSpace > DataSpaceSharedPtr
static ConvertedType Convert(const T &obj)
static DataSpaceSharedPtr OneD(hsize_t size)
T ConvertedVectorElemType
static FileSharedPtr Open(const std::string &filename, unsigned mode, PListSharedPtr accessPL=PList::Default())
boost::shared_ptr< Attribute > AttributeSharedPtr
void SetChunk(const std::vector< hsize_t > &dims)
static PListSharedPtr ObjectCreate()
Properties for object creation.
static const hid_t NativeType
DataSpaceSharedPtr GetSpace() const
Traits class for HDF5 data types.
static DataSpaceSharedPtr Null()
static PListSharedPtr DatasetXfer()
Properties for raw data transfer.
static PListSharedPtr FileCreate()
Properties for file creation.
void SetDxMpioCollective()
static ConvertedType Convert(const std::string &obj)
GroupSharedPtr CreateGroup(const std::string &name, PListSharedPtr createPL=PList::Default(), PListSharedPtr accessPL=PList::Default())
void SetAttribute(const std::string &name, const T &value)
static PListSharedPtr DatatypeAccess()
Properties for datatype access.
static DataSpaceSharedPtr Scalar()
LinkIterator & operator++()
Mixin for objects that contain groups and datasets (Group and File)
CanHaveAttributesSharedPtr operator[](hsize_t idx)
static herr_t helper(hid_t g_id, const char *name, const H5A_info_t *info, void *op_data)
void SetMpio(CommSharedPtr comm)
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
static T Deconvert(const ConvertedType &obj)
AttributeSharedPtr CreateAttribute(const std::string &name, DataTypeSharedPtr type, DataSpaceSharedPtr space)
virtual hsize_t GetNumElements()
void Read(std::vector< T > &data)
DataSpaceSharedPtr GetSpace() const
#define dest(otri, vertexptr)
boost::shared_ptr< Object > ObjectSharedPtr
virtual hsize_t GetNumElements()
CanHaveGroupsDataSetsSharedPtr m_grp
static PListSharedPtr StringCreate()
Properties for character encoding when encoding strings or object names.
DataTypeSharedPtr Copy() const
static DataTypeSharedPtr Native()
bool operator==(const LinkIterator &other) const
static PListSharedPtr LinkCreate()
Properties governing link creation.
boost::shared_ptr< CanHaveAttributes > CanHaveAttributesSharedPtr
static PListSharedPtr DatasetAccess()
Properties for dataset access.
static PListSharedPtr FileAccess()
Properties for file access.
std::string m_currentName
void Read(std::vector< T > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
std::string m_currentName
bool operator==(const AttrIterator &other) const
static PListSharedPtr AttributeCreate()
Properties for attribute creation.
static PListSharedPtr LinkAccess()
Properties governing link traversal when accessing objects.
AttributeSharedPtr OpenAttribute(const std::string &name)
void SetDeflate(const unsigned level=1)
static PListSharedPtr ObjectCopy()
Properties governing the object copying process.
void GetAttribute(const std::string &name, T &value)
static std::string Deconvert(const ConvertedType &obj)
Predefined HDF data types that must not be closed when done with.
static PListSharedPtr Default()
Default options.
static PListSharedPtr FileMount()
Properties for file mounting.
void Write(const std::vector< T > &data, DataSpaceSharedPtr filespace, PListSharedPtr dxpl=PList::Default())
GroupSharedPtr OpenGroup(const std::string &name, PListSharedPtr accessPL=PList::Default()) const
static const bool MustConvert
boost::shared_ptr< CanHaveGroupsDataSets > CanHaveGroupsDataSetsSharedPtr
static AttributeSharedPtr Open(hid_t parent, const std::string &name)