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 "hdf5serie/options.h"
28#include <vector>
29#include <boost/multi_array.hpp>
30
31namespace H5 {
32
33
34
64 template<class T>
65 class VectorSerie : public Dataset {
66 friend class Container<Object, GroupBase>;
67 private:
68 ScopedHID memDataTypeID;
69 ScopedHID memDataSpaceID;
70 ScopedHID memDataSpaceCacheID;
71 ScopedHID fileDataSpaceID;
72 hsize_t dims[2];
73 boost::multi_array<T, 2> cache;
74 boost::multi_array<char, 3> cacheFixedSizeStr;
75 std::vector<char> bufChar;
76 size_t cacheRow;
77 void writeToHDF5(size_t nrRows, size_t cacheSize, const std::conditional_t<std::is_same_v<T,std::string>,char,T>* data);
78 void openIDandFileDataSpaceID();
79 protected:
80 VectorSerie(int dummy, GroupBase *parent_, const std::string &name_);
81 VectorSerie(GroupBase *parent_, const std::string &name_, int cols, const Options &opts={});
82 ~VectorSerie() override;
83 void close() override;
84 void refresh() override;
85 void flush() override;
86 void enableSWMR() override;
87
88 public:
93 void setDescription(const std::string& description);
94
100 void append(const T data[], size_t size);
101
106 template<class DataType>
107 void append(const DataType &data){
108 append(&data[0], data.size());
109 }
110
112 inline int getRows();
113
115 inline unsigned int getColumns();
116
121 void getRow(int row, size_t size, T data[]);
122
127 template<class DataType>
128 void getRow(const int row, DataType &data) {
129 getRow(row, data.size(), &data[0]);
130 }
131
134 std::vector<T> getRow(const int row) {
135 std::vector<T> data(dims[1]);
136 getRow(row, dims[1], &data[0]);
137 return data;
138 }
139
144 void getColumn(int column, size_t size, T data[]);
145
150 template<class DataType>
151 void getColumn(const int column, DataType &data) {
152 getColumn(column, data.size(), &data[0]);
153 }
154
157 std::vector<T> getColumn(const int row) {
158 size_t rows=getRows();
159 std::vector<T> data(rows);
160 getColumn(row, rows, &data[0]);
161 return data;
162 }
163
168 std::string getDescription();
169
170 void setColumnLabel(const std::vector<std::string> &columnLabel);
171
177 std::vector<std::string> getColumnLabel();
178 };
179
180
181
182 // inline definitions
183
184 template<class T>
186 checkCall(H5Sget_simple_extent_dims(fileDataSpaceID, dims, nullptr));
187 return dims[0];
188 }
189
190 template<class T>
192 return dims[1];
193 }
194
195}
196
197#endif // _TIMESERIE_H_
Definition: interface.h:177
Definition: interface.h:331
Definition: group.h:31
Definition: interface.h:270
Definition: interface.h:78
Serie of vectors.
Definition: vectorserie.h:65
void setDescription(const std::string &description)
Sets a description for the dataset.
Definition: vectorserie.cc:171
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:216
void append(const DataType &data)
Definition: vectorserie.h:107
int getRows()
Returns the number of rows in the dataset.
Definition: vectorserie.h:185
void getColumn(int column, size_t size, T data[])
Returns the data vector at column column.
Definition: vectorserie.cc:236
std::string getDescription()
Return the description for the dataset.
Definition: vectorserie.cc:250
void append(const T data[], size_t size)
Append a data vector.
Definition: vectorserie.cc:198
std::vector< T > getColumn(const int row)
Definition: vectorserie.h:157
unsigned int getColumns()
Returns the number of columns(=number of data elements) in the dataset.
Definition: vectorserie.h:191
void getColumn(const int column, DataType &data)
Definition: vectorserie.h:151
std::vector< std::string > getColumnLabel()
Returns the column labels.
Definition: vectorserie.cc:264
void getRow(const int row, DataType &data)
Definition: vectorserie.h:128
std::vector< T > getRow(const int row)
Definition: vectorserie.h:134
Definition: options.h:29