hdf5serie 2.0.0 HDF5 Serie

vectorserie.h
1 /* Copyright (C) 2009 Markus Friedrich
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 *
17 * Contact:
18 * friedrich.at.gc@googlemail.com
19 *
20 */
21
22 #ifndef _HDF5SERIE_VECTORSERIE_H_
23 #define _HDF5SERIE_VECTORSERIE_H_
24
25 #include <hdf5serie/interface.h>
26 #include <hdf5serie/file.h>
27 #include <vector>
28 #include <boost/multi_array.hpp>
29
30 namespace H5 {
31
32
33
63 template<class T>
64 class VectorSerie : public Dataset {
65 friend class Container<Object, GroupBase>;
66 private:
67 hid_t memDataTypeID; // no need to useScopedHID since only a static hid_t is stored here
68 ScopedHID memDataSpaceID;
69 ScopedHID memDataSpaceCacheID;
70 ScopedHID fileDataSpaceID;
71 hsize_t dims[2];
72 boost::multi_array<T, 2> cache;
73 size_t cacheRow;
74 void writeToHDF5(size_t nrRows, size_t cacheSize, const T* data);
75 protected:
76 VectorSerie(int dummy, GroupBase *parent_, const std::string &name_);
77 VectorSerie(GroupBase *parent_, const std::string &name_, int cols,
78 int compression=File::getDefaultCompression(), int chunkSize=File::getDefaultChunkSize(), int cacheSize=File::getDefaultCacheSize());
79 ~VectorSerie() override;
80 void close() override;
81 void refresh() override;
82 void flush() override;
83
84 public:
89 void setDescription(const std::string& description);
90
96 void append(const T data[], size_t size);
97
102 template<class DataType>
103 void append(const DataType &data){
104 append(&data[0], data.size());
105 }
106
108 inline int getRows();
109
111 inline unsigned int getColumns();
112
117 void getRow(int row, size_t size, T data[]);
118
123 template<class DataType>
124 void getRow(const int row, DataType &data) {
125 getRow(row, data.size(), &data[0]);
126 }
127
130 std::vector<T> getRow(const int row) {
131 std::vector<T> data(dims[1]);
132 getRow(row, dims[1], &data[0]);
133 return data;
134 }
135
140 void getColumn(int column, size_t size, T data[]);
141
146 template<class DataType>
147 void getColumn(const int column, DataType &data) {
148 getColumn(column, data.size(), &data[0]);
149 }
150
153 std::vector<T> getColumn(const int row) {
154 size_t rows=getRows();
155 std::vector<T> data(rows);
156 getColumn(row, rows, &data[0]);
157 return data;
158 }
159
164 std::string getDescription();
165
166 void setColumnLabel(const std::vector<std::string> &columnLabel);
167
173 std::vector<std::string> getColumnLabel();
174 };
175
176
177
178 // inline definitions
179
180 template<class T>
181 int VectorSerie<T>::getRows() {
182 H5Sget_simple_extent_dims(fileDataSpaceID, dims, nullptr);
183 return dims[0];
184 }
185
186 template<class T>
187 unsigned int VectorSerie<T>::getColumns() {
188 return dims[1];
189 }
190
191 }
192
193 #endif // _TIMESERIE_H_
H5::VectorSerie::getColumn
void getColumn(int column, size_t size, T data[])
Returns the data vector at column column.
Definition: vectorserie.cc:197
H5::VectorSerie::getColumn
std::vector< T > getColumn(const int row)
Definition: vectorserie.h:153
H5::VectorSerie::getRow
std::vector< T > getRow(const int row)
Definition: vectorserie.h:130
H5::Object
Definition: interface.h:212
H5::VectorSerie::getColumns
unsigned int getColumns()
Returns the number of columns(=number of data elements) in the dataset.
Definition: vectorserie.h:187
H5::VectorSerie::getColumnLabel
std::vector< std::string > getColumnLabel()
Returns the column labels.
Definition: vectorserie.cc:225
H5::VectorSerie::getRow
void getRow(int row, size_t size, T data[])
Returns the data vector at row row The first row is 0. The last avaliable row ist getRows()-1....
Definition: vectorserie.cc:177
H5::ScopedHID
Definition: interface.h:47
H5::GroupBase
Definition: group.h:31
H5::Container
Definition: interface.h:87
H5::Dataset
Definition: interface.h:273
H5::VectorSerie::getRow
void getRow(const int row, DataType &data)
Definition: vectorserie.h:124
H5::VectorSerie
Serie of vectors.
Definition: vectorserie.h:64
H5::VectorSerie::getDescription
std::string getDescription()
Return the description for the dataset.
Definition: vectorserie.cc:211
H5::VectorSerie::append
void append(const T data[], size_t size)
Append a data vector.
Definition: vectorserie.cc:159
H5::VectorSerie::getRows
int getRows()
Returns the number of rows in the dataset.
Definition: vectorserie.h:181
H5::VectorSerie::append
void append(const DataType &data)
Definition: vectorserie.h:103
H5::VectorSerie::getColumn
void getColumn(const int column, DataType &data)
Definition: vectorserie.h:147
H5::VectorSerie::setDescription
void setDescription(const std::string &description)
Sets a description for the dataset.
Definition: vectorserie.cc:132