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
30namespace 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 void openIDandFileDataSpaceID();
76 protected:
77 VectorSerie(int dummy, GroupBase *parent_, const std::string &name_);
78 VectorSerie(GroupBase *parent_, const std::string &name_, int cols,
79 int compression=File::getDefaultCompression(), int chunkSize=File::getDefaultChunkSize(), int cacheSize=File::getDefaultCacheSize());
80 ~VectorSerie() override;
81 void close() override;
82 void refresh() override;
83 void flush() override;
84 void enableSWMR() override;
85
86 public:
91 void setDescription(const std::string& description);
92
98 void append(const T data[], size_t size);
99
104 template<class DataType>
105 void append(const DataType &data){
106 append(&data[0], data.size());
107 }
108
110 inline int getRows();
111
113 inline unsigned int getColumns();
114
119 void getRow(int row, size_t size, T data[]);
120
125 template<class DataType>
126 void getRow(const int row, DataType &data) {
127 getRow(row, data.size(), &data[0]);
128 }
129
132 std::vector<T> getRow(const int row) {
133 std::vector<T> data(dims[1]);
134 getRow(row, dims[1], &data[0]);
135 return data;
136 }
137
142 void getColumn(int column, size_t size, T data[]);
143
148 template<class DataType>
149 void getColumn(const int column, DataType &data) {
150 getColumn(column, data.size(), &data[0]);
151 }
152
155 std::vector<T> getColumn(const int row) {
156 size_t rows=getRows();
157 std::vector<T> data(rows);
158 getColumn(row, rows, &data[0]);
159 return data;
160 }
161
166 std::string getDescription();
167
168 void setColumnLabel(const std::vector<std::string> &columnLabel);
169
175 std::vector<std::string> getColumnLabel();
176 };
177
178
179
180 // inline definitions
181
182 template<class T>
184 checkCall(H5Sget_simple_extent_dims(fileDataSpaceID, dims, nullptr));
185 return dims[0];
186 }
187
188 template<class T>
190 return dims[1];
191 }
192
193}
194
195#endif // _TIMESERIE_H_
Definition: interface.h:138
Definition: interface.h:292
Definition: group.h:31
Definition: interface.h:231
Definition: interface.h:55
Serie of vectors.
Definition: vectorserie.h:64
void setDescription(const std::string &description)
Sets a description for the dataset.
Definition: vectorserie.cc:137
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:182
void append(const DataType &data)
Definition: vectorserie.h:105
int getRows()
Returns the number of rows in the dataset.
Definition: vectorserie.h:183
void getColumn(int column, size_t size, T data[])
Returns the data vector at column column.
Definition: vectorserie.cc:202
std::string getDescription()
Return the description for the dataset.
Definition: vectorserie.cc:216
void append(const T data[], size_t size)
Append a data vector.
Definition: vectorserie.cc:164
std::vector< T > getColumn(const int row)
Definition: vectorserie.h:155
unsigned int getColumns()
Returns the number of columns(=number of data elements) in the dataset.
Definition: vectorserie.h:189
void getColumn(const int column, DataType &data)
Definition: vectorserie.h:149
std::vector< std::string > getColumnLabel()
Returns the column labels.
Definition: vectorserie.cc:230
void getRow(const int row, DataType &data)
Definition: vectorserie.h:126
std::vector< T > getRow(const int row)
Definition: vectorserie.h:132