CNORXZ
Container with Native Operation Routines and Expressions
Loading...
Searching...
No Matches
src
opt
hdf5
lib
h5_dataset.cc
Go to the documentation of this file.
1
// -*- C++ -*-
12
#include "
h5_dataset.h
"
13
14
namespace
CNORXZ
15
{
16
namespace
hdf5
17
{
18
Dataset::Dataset
(
const
String
& name,
const
ContentBase
*
_parent
) :
19
ContentBase
(name,
_parent
)
20
{
21
if
(
exists
()){
22
open
();
23
}
24
}
25
26
Dataset::~Dataset
()
27
{
28
this->
close
();
29
}
30
31
ContentType
Dataset::type
()
const
32
{
33
return
ContentType::DSET
;
34
}
35
36
bool
Dataset::ro
()
const
37
{
38
return
mParent
->
ro
();
39
}
40
41
Dataset
&
Dataset::open
()
42
{
43
if
(
mId
== 0
and
exists
()){
44
mId
=
H5Dopen
(
mParent
->
id
(),
mName
.c_str(),
H5P_DEFAULT
);
45
mType
=
H5Dget_type
(
mId
);
46
47
mFilespace
=
H5Dget_space
(
mId
);
48
SizeT
ndims
=
H5Sget_simple_extent_ndims
(
mFilespace
);
49
Vector<hsize_t>
dims
(
ndims
);
50
H5Sget_simple_extent_dims
(
mFilespace
,
dims
.data(),
nullptr
);
51
52
Vector<RangePtr>
rs
(
ndims
);
53
for
(
SizeT
i
= 0;
i
!=
ndims
; ++
i
){
54
rs
[
i
] =
CRangeFactory
(
dims
[
i
]).
create
();
55
}
56
mDataRange
=
yrange
(
rs
);
57
}
58
return
*
this
;
59
}
60
61
Dataset
&
Dataset::close
()
62
{
63
if
(
mId
!= 0){
64
H5Sclose
(
mFilespace
);
65
H5Tclose
(
mType
);
66
H5Dclose
(
mId
);
67
mId
= 0;
68
}
69
return
*
this
;
70
}
71
72
String
Dataset::path
()
const
73
{
74
return
mParent
->
path
() +
"/"
+
mName
;
75
}
76
77
String
Dataset::filename
()
const
78
{
79
return
mParent
->
filename
();
80
}
81
82
bool
Dataset::exists
()
const
83
{
84
return
H5Lexists
(
mParent
->
id
(),
mName
.c_str(),
H5P_DEFAULT
) > 0;
85
}
86
87
Dataset
&
Dataset::init
(
const
RangePtr
& dataRange,
hid_t
type)
88
{
89
CXZ_ASSERT
(
not
isOpen
(),
"tried to initialize dataset that is already extisting"
);
90
mDataRange
=
dataRange
;
91
const
H5T_class_t
tc
=
H5Tget_class
(
type
);
92
CXZ_ASSERT
(
tc
!=
H5T_NO_CLASS
,
"id does not correspond to a data type"
);
// (did not found anythng better to check if type id is valid)...
93
const
hid_t
dcpl_id
=
H5Pcreate
(
H5P_DATASET_CREATE
);
94
// TODO: all sub-ranges explicity!!!:
95
const
SizeT
ndim
=
dataRange
->dim();
96
Vector<hsize_t>
exts
(
ndim
);
97
for
(
SizeT
i
= 0;
i
!=
ndim
; ++
i
){
98
exts
[
i
] =
static_cast<
hsize_t
>
(
dataRange
->sub(
i
)->size() );
99
}
100
mFilespace
=
H5Screate_simple
(
ndim
,
exts
.data(),
NULL
);
101
mType
=
type
;
102
mId
=
H5Dcreate
(
mParent
->
id
(),
mName
.c_str(),
mType
,
mFilespace
,
103
H5P_DEFAULT
,
dcpl_id
,
H5P_DEFAULT
);
104
H5Pclose
(
dcpl_id
);
105
return
*
this
;
106
}
107
108
const
RangePtr
&
Dataset::dataRange
()
const
109
{
110
return
mDataRange
;
111
}
112
113
}
114
}
CXZ_ASSERT
#define CXZ_ASSERT(statement, errmsg)
Definition
assert.h:40
CNORXZ::CRangeFactory
Definition
crange.h:137
CNORXZ::RangeFactoryBase::create
RangePtr create()
Definition
range_base.cc:24
CNORXZ::hdf5::ContentBase
Definition
h5_content_base.h:41
CNORXZ::hdf5::ContentBase::mName
String mName
Definition
h5_content_base.h:140
CNORXZ::hdf5::ContentBase::ro
virtual bool ro() const =0
CNORXZ::hdf5::ContentBase::path
virtual String path() const =0
CNORXZ::hdf5::ContentBase::mParent
const ContentBase * mParent
Definition
h5_content_base.h:141
CNORXZ::hdf5::ContentBase::filename
virtual String filename() const =0
CNORXZ::hdf5::ContentBase::mId
hid_t mId
Definition
h5_content_base.h:142
CNORXZ::hdf5::ContentBase::isOpen
bool isOpen() const
Definition
h5_content_base.cc:39
CNORXZ::hdf5::ContentBase::id
hid_t id() const
Definition
h5_content_base.cc:34
CNORXZ::hdf5::Dataset
Definition
h5_dataset.h:26
CNORXZ::hdf5::Dataset::filename
virtual String filename() const override final
Definition
h5_dataset.cc:77
CNORXZ::hdf5::Dataset::close
virtual Dataset & close() override final
Definition
h5_dataset.cc:61
CNORXZ::hdf5::Dataset::exists
virtual bool exists() const override final
Definition
h5_dataset.cc:82
CNORXZ::hdf5::Dataset::Dataset
Dataset(const String &name, const ContentBase *_parent)
Definition
h5_dataset.cc:18
CNORXZ::hdf5::Dataset::init
Dataset & init(const RangePtr &dataRange, hid_t type)
Definition
h5_dataset.cc:87
CNORXZ::hdf5::Dataset::mDataRange
RangePtr mDataRange
Definition
h5_dataset.h:65
CNORXZ::hdf5::Dataset::mFilespace
hid_t mFilespace
Definition
h5_dataset.h:67
CNORXZ::hdf5::Dataset::path
virtual String path() const override final
Definition
h5_dataset.cc:72
CNORXZ::hdf5::Dataset::dataRange
const RangePtr & dataRange() const
Definition
h5_dataset.cc:108
CNORXZ::hdf5::Dataset::type
virtual ContentType type() const override final
Definition
h5_dataset.cc:31
CNORXZ::hdf5::Dataset::~Dataset
~Dataset()
Definition
h5_dataset.cc:26
CNORXZ::hdf5::Dataset::ro
virtual bool ro() const override final
Definition
h5_dataset.cc:36
CNORXZ::hdf5::Dataset::mType
hid_t mType
Definition
h5_dataset.h:66
CNORXZ::hdf5::Dataset::open
virtual Dataset & open() override final
Definition
h5_dataset.cc:41
h5_dataset.h
Dataset declaration.
CNORXZ::hdf5::ContentType
ContentType
Definition
h5_content_base.h:29
CNORXZ::hdf5::ContentType::DSET
@ DSET
CNORXZ
Definition
aindex.cc.h:18
CNORXZ::String
std::string String
Definition
types.h:42
CNORXZ::SizeT
uint64_t SizeT
Definition
types.h:38
CNORXZ::yrange
RangePtr yrange(const Vector< RangePtr > &rs)
Definition
yrange.cc:666
CNORXZ::RangePtr
Sptr< RangeBase > RangePtr
Definition
types.h:157
CNORXZ::Vector
std::vector< T, Allocator< T > > Vector
Definition
types.h:310
CNORXZ::rangeCast
Sptr< Range > rangeCast(const RangePtr r)
Definition
range_base.cc.h:53
Generated by
1.10.0