Loading...
Searching...
No Matches
Hi5Read.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32
33#include "Hi5.h" // to define H5_USE_*_API_DEFAULT
34
35
36#ifndef Hi5READ
37#define Hi5READ
38
39
40#include <hdf5.h>
41
42#include <string>
43#include <list>
44
45#include <drain/util/TreeOrdered.h>
46#include <drain/util/EnumFlags.h>
47#include <drain/image/Image.h>
48
49
50
51
52// using namespace std;
53
54namespace hi5 {
55
56//extern const int ATTRIBUTES;
57//extern const int DATASETS;
58
59
60//extern
61
62class Reader : public Hi5Base {
63
64public:
65
66 enum Mode {
67 ATTRIBUTES=1,
69 EXCLUSIVE=4
70 };
71
73
74
75 static
76 void readFile(const std::string &filename, Hi5Tree &tree, ModeFlagger::ivalue_t mode=(ATTRIBUTES | DATASETS)); //(ATTRIBUTES|DATASETS));
77
79
86 static void
87 h5FileToTree(hid_t file_id, const Hi5Tree::path_t &path, Hi5Tree &tree, ModeFlagger::ivalue_t mode = (ATTRIBUTES | DATASETS));
88
90
95 static inline
96 void h5FileToTree(hid_t fid, Hi5Tree &tree, ModeFlagger::ivalue_t mode=(ATTRIBUTES | DATASETS)){ //(ATTRIBUTES|DATASETS)){
97 Hi5Tree::path_t path;
98 path.append(Hi5Tree::key_t::ROOT);
99 // path.appendElem(Hi5Tree::key_t::ROOT);
100 h5FileToTree(fid, path, tree, mode);
101 };
102
103
104 template <class T>
105 static
106 void h5AttributeToData(hid_t aid, hid_t datatype, drain::Variable & attribute, size_t elements=1){
107
108 drain::Logger mout(getLogH5(), __FILE__, __FUNCTION__);
109
110 attribute.setType(typeid(T));
111 attribute.setSize(elements);
112
113 int status = H5Aread(aid, datatype, attribute.getPtr());
114 handleStatus<LOG_ERR>(mout, status, "H5Aread failed for attribute=", attribute, __LINE__);
115 /*
116 if (status < 0){
117 mout.error("h5AttributeToData: read failed ");
118 }
119 */
120 }
121
122
123
124 static
125 void h5DatasetToImage(hid_t id, const Hi5Tree::path_t &path, drain::image::Image &image);
126
127protected:
128
129 static
130 herr_t iterate_attribute(hid_t id, const char * attr_name, const H5A_info_t *ainfo, void *operator_data);
131
132 static
133 herr_t iterate(hid_t group_id, const char * member_name, void *operator_data);
134
135};
136
137} // ::hi5
138
139//const drain::SingleFlagger<Reader::Mode>::dict_t Reader::dict = {{"ATTRIBUTES", ATTRIBUTES}, {"DATASETS", DATASETS}};
140template <>
142
143
144#endif /* ImageH5_H_ */
145
146// Rack
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
Flagger accepting values of enum type E.
Definition EnumFlags.h:190
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
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:159
Definition Hi5Read.h:62
Mode
Definition Hi5Read.h:66
@ EXCLUSIVE
Definition Hi5Read.h:69
@ DATASETS
Definition Hi5Read.h:68
static void h5FileToTree(hid_t file_id, const Hi5Tree::path_t &path, Hi5Tree &tree, ModeFlagger::ivalue_t mode=(ATTRIBUTES|DATASETS))
Conversion from native HDF5 structure to Rack's hi5 tree structure.
Definition Hi5Read.cpp:84
static herr_t iterate(hid_t group_id, const char *member_name, void *operator_data)
Recursive traversal.
Definition Hi5Read.cpp:212
static void h5FileToTree(hid_t fid, Hi5Tree &tree, ModeFlagger::ivalue_t mode=(ATTRIBUTES|DATASETS))
Conversion from native HDF5 structure to Rack's hi5 tree structure.
Definition Hi5Read.h:96
static herr_t iterate_attribute(hid_t id, const char *attr_name, const H5A_info_t *ainfo, void *operator_data)
Definition Hi5Read.cpp:220
static void h5DatasetToImage(hid_t id, const Hi5Tree::path_t &path, drain::image::Image &image)
const Hi5Tree::path_t &path
Definition Hi5Read.cpp:382
DRAIN_VARIABLE Variable
Value container supporting dynamic type.
Definition Variable.h:63
Wrapper for unique (static) dictionary of enum values.
Definition EnumFlags.h:66