CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
h5_dataset.cc.h
Go to the documentation of this file.
1// -*- C++ -*-
12#ifndef __cxz_h5_dataset_cc_h__
13#define __cxz_h5_dataset_cc_h__
14
15#include "h5_dataset.h"
16
17namespace CNORXZ
18{
19 namespace hdf5
20 {
21 template <typename T>
23 {
24 const hid_t tid = getTypeId(*data.data());
25 VCHECK(tid);
26 init(data.range(), tid);
27 if(data.begin().formatIsTrivial()){
29 for(SizeT i = 0; i != dims.size(); ++i){
30 dims[i] = mDataRange->sub(i)->size();
31 }
32 const hid_t memspace = H5Screate_simple(dims.size(), dims.data(), NULL);
35 }
36 else {
37 CXZ_ERROR("Got array type with non-trivial format; non-contiguous data formats are not supported yet!");
38 }
39 return *this;
40 }
41
42 template <typename T>
44 Dataset(name, _parent)
45 {}
46
47 template <typename T>
49 {
50 Vector<hsize_t> dims(mDataRange->dim());
51 for(SizeT i = 0; i != dims.size(); ++i){
52 dims[i] = mDataRange->sub(i)->size();
53 }
54 const hid_t mem_space_id = H5Screate_simple(static_cast<hsize_t>(dims.size()),
55 dims.data(), nullptr);
57 MArray<T> out(mDataRange);
58 const herr_t err = H5Dread(mId, mType, mem_space_id, mFilespace, xfer_plist_id, out.data());
59 CXZ_ASSERT(err >= 0, "error while reading dataset '" << mName
60 << "', errorcode :" << err);
63 return out;
64 }
65
66 template <typename T>
67 template <class I, typename M>
69 {
70 CXZ_ASSERT(beg.dim() == mDataRange->dim(), "got index of inconsistent dimension, got"
71 << beg.dim() << ", expected " << mDataRange->dim());
72 const RangePtr outrange = beg.prange(end);
74 for(SizeT i = 0; i != dims.size(); ++i){
75 dims[i] = outrange->sub(i)->size();
76 }
77 const Vector<hsize_t> fpos = mkFPos(beg);
78 H5Sselect_hyperslab(mFilespace, H5S_SELECT_SET, fpos.data(), NULL, dims.data(), NULL);
79 const hid_t mem_space_id = H5Screate_simple(static_cast<hsize_t>(dims.size()),
80 dims.data(), nullptr);
83 const herr_t err = H5Dread(mId, mType, mem_space_id, mFilespace, xfer_plist_id, out.data());
84 CXZ_ASSERT(err >= 0, "error while reading dataset '" << mName
85 << "', errorcode :" << err);
88 return out;
89 }
90
91 template <typename T>
92 template <class I, typename M>
94 {
96 if constexpr(has_static_sub<I>::value){
97 iter<0,index_dim<I>::value> ( [&](auto i) { fpos[i] = beg.THIS().pack().get(i)->lex(); }, NoF{} );
98 }
99 else if constexpr(has_sub<I>::value){
100 for(SizeT i = 0; i != beg.dim(); ++i){
101 fpos[i] = beg.THIS().pack().get(i)->lex();
102 }
103 }
104 else {
105 fpos[0] = beg.lex();
106 }
107 return fpos;
108 }
109
110 }
111}
112
113#endif
#define CXZ_ERROR(errmsg)
Definition assert.h:26
#define CXZ_ASSERT(statement, errmsg)
Definition assert.h:40
virtual iterator begin()
virtual T * data()=0
virtual RangePtr range() const
bool formatIsTrivial() const
Definition yrange.cc:473
Dataset & init(const RangePtr &dataRange, hid_t type)
Definition h5_dataset.cc:87
MArray< T > read() const
SDataset(const String &name, const ContentBase *_parent)
Dataset declaration.
#define VCHECK(a)
Definition macros.h:24
hid_t getTypeId(T x)
std::string String
Definition types.h:42
uint64_t SizeT
Definition types.h:38
Sptr< RangeBase > RangePtr
Definition types.h:157
std::vector< T, Allocator< T > > Vector
Definition types.h:310
Sptr< Range > rangeCast(const RangePtr r)
static constexpr bool value