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 hid_t memDataTypeID; // no need to useScopedHID since only a static hid_t is stored here
69 ScopedHID fixedStringTypeID;
70 ScopedHID memDataSpaceID;
71 ScopedHID memDataSpaceCacheID;
72 ScopedHID fileDataSpaceID;
73 hsize_t dims[2];
74 boost::multi_array<T, 2> cache;
75 boost::multi_array<char, 3> cacheFixedSizeStr;
76 std::vector<char> bufChar;
77 size_t cacheRow;
78 void writeToHDF5(size_t nrRows, size_t cacheSize, const std::conditional_t<std::is_same_v<T,std::string>,char,T>* data);
79 void openIDandFileDataSpaceID();
80 protected:
81 VectorSerie(int dummy, GroupBase *parent_, const std::string &name_);
82 VectorSerie(GroupBase *parent_, const std::string &name_, int cols, const Options &opts={});
83 ~VectorSerie() override;
84 void close() override;
85 void refresh() override;
86 void flush() override;
87 void enableSWMR() override;
88
89 public:
94 void setDescription(const std::string& description);
95
101 void append(const T data[], size_t size);
102
107 template<class DataType>
108 void append(const DataType &data){
109 append(&data[0], data.size());
110 }
111
113 inline int getRows();
114
116 inline unsigned int getColumns();
117
122 void getRow(int row, size_t size, T data[]);
123
128 template<class DataType>
129 void getRow(const int row, DataType &data) {
130 getRow(row, data.size(), &data[0]);
131 }
132
135 std::vector<T> getRow(const int row) {
136 std::vector<T> data(dims[1]);
137 getRow(row, dims[1], &data[0]);
138 return data;
139 }
140
145 void getColumn(int column, size_t size, T data[]);
146
151 template<class DataType>
152 void getColumn(const int column, DataType &data) {
153 getColumn(column, data.size(), &data[0]);
154 }
155
158 std::vector<T> getColumn(const int row) {
159 size_t rows=getRows();
160 std::vector<T> data(rows);
161 getColumn(row, rows, &data[0]);
162 return data;
163 }
164
169 std::string getDescription();
170
171 void setColumnLabel(const std::vector<std::string> &columnLabel);
172
178 std::vector<std::string> getColumnLabel();
179 };
180
181
182
183 // inline definitions
184
185 template<class T>
187 checkCall(H5Sget_simple_extent_dims(fileDataSpaceID, dims, nullptr));
188 return dims[0];
189 }
190
191 template<class T>
193 return dims[1];
194 }
195
196}
197
198#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:189
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:234
void append(const DataType &data)
Definition: vectorserie.h:108
int getRows()
Returns the number of rows in the dataset.
Definition: vectorserie.h:186
void getColumn(int column, size_t size, T data[])
Returns the data vector at column column.
Definition: vectorserie.cc:254
std::string getDescription()
Return the description for the dataset.
Definition: vectorserie.cc:268
void append(const T data[], size_t size)
Append a data vector.
Definition: vectorserie.cc:216
std::vector< T > getColumn(const int row)
Definition: vectorserie.h:158
unsigned int getColumns()
Returns the number of columns(=number of data elements) in the dataset.
Definition: vectorserie.h:192
void getColumn(const int column, DataType &data)
Definition: vectorserie.h:152
std::vector< std::string > getColumnLabel()
Returns the column labels.
Definition: vectorserie.cc:282
void getRow(const int row, DataType &data)
Definition: vectorserie.h:129
std::vector< T > getRow(const int row)
Definition: vectorserie.h:135
Definition: options.h:29