MeteoIODoc 20240503.aefd3c94
Buffer.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2014 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BUFFER_H
20#define BUFFER_H
21
26
27namespace mio {
28
40 public:
41 MeteoBuffer() : ts_buffer(), ts_start(), ts_end() {}
42
49 bool get(const Date& date, METEO_SET &vecMeteo) const;
50
58 bool get(const Date& date_start, const Date& date_end, std::vector< METEO_SET > &vecMeteo) const;
59
69 double getAvgSamplingRate() const;
70
77 Date getBufferStart() const;
78
85 Date getBufferEnd() const;
86
92 Date getDataStart() const;
93
99 Date getDataEnd() const;
100
105 bool empty() const;
106
111 size_t size() const { return ts_buffer.size();}
112
116 void clear();
117
124 void push(const Date& date_start, const Date& date_end, const std::vector< METEO_SET >& vecMeteo);
125
126
133 void push(const Date& date_start, const Date& date_end, const std::vector<MeteoData>& vecMeteo);
134
135 const std::string toString() const;
136
137 //HACK: these should be removed in order to hide the internals! But this requires a re-write of MeteoProcessor
138 std::vector< METEO_SET >& getBuffer();
139 void setBufferStart(const Date& date);
140 void setBufferEnd(const Date& date);
141 private:
142 std::vector< METEO_SET > ts_buffer;
143 Date ts_start, ts_end;
144};
145
156//TODO: make it a template so it can buffer dems, 2D, 3D grids
158 public:
159 GridBuffer(const size_t& in_max_grids);
160
161 bool empty() const {return IndexBufferedGrids.empty();}
162 void clear() {mapBufferedGrids.clear(); mapBufferedInfos.clear(); IndexBufferedGrids.clear();}
163 size_t size() const {return IndexBufferedGrids.size();}
164
165 void setMaxGrids(const size_t& in_max_grids) {max_grids=in_max_grids;}
166
167 bool get(DEMObject& grid, const std::string& grid_hash) const;
168 bool get(Grid2DObject& grid, const std::string& grid_hash) const;
169 bool get(Grid2DObject& grid, const std::string& grid_hash, std::string& grid_info) const;
170 bool get(Grid2DObject& grid, const MeteoGrids::Parameters& parameter, const Date& date) const;
171
172 bool has(const std::string& grid_hash) const;
173 bool has(const MeteoGrids::Parameters& parameter, const Date& date) const;
174
175 void push(const DEMObject& grid, const std::string& grid_hash);
176 void push(const Grid2DObject& grid, const std::string& grid_hash);
177 void push(const Grid2DObject& grid, const std::string& grid_hash, const std::string& grid_info);
178 void push(const Grid2DObject& grid, const MeteoGrids::Parameters& parameter, const Date& date);
179
180 const std::string toString() const;
181 private:
182 std::map<std::string, Grid2DObject> mapBufferedGrids;
183 std::map<std::string, DEMObject> mapBufferedDEMs;
184 std::map<std::string, std::string> mapBufferedInfos;
185 std::vector<std::string> IndexBufferedGrids; // this is required in order to know which grid is the oldest one
186 std::vector<std::string> IndexBufferedDEMs; // this is required in order to know which grid is the oldest one
187 size_t max_grids;
188};
189
190}
191#endif
A class to represent DEMs and automatically compute some properties. This class stores elevation grid...
Definition: DEMObject.h:40
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:42
A class to buffer gridded data. This class buffers Grid2D objects. It implements a proper ring buffer...
Definition: Buffer.h:157
const std::string toString() const
Definition: Buffer.cc:453
size_t size() const
Definition: Buffer.h:163
bool empty() const
Definition: Buffer.h:161
void clear()
Definition: Buffer.h:162
bool get(DEMObject &grid, const std::string &grid_hash) const
Definition: Buffer.cc:375
void push(const DEMObject &grid, const std::string &grid_hash)
Definition: Buffer.cc:406
GridBuffer(const size_t &in_max_grids)
Definition: Buffer.cc:322
void setMaxGrids(const size_t &in_max_grids)
Definition: Buffer.h:165
bool has(const std::string &grid_hash) const
Definition: Buffer.cc:362
A class to buffer meteorological data. This class buffers MeteoData objects. It is currently NOT a pr...
Definition: Buffer.h:39
MeteoBuffer()
Definition: Buffer.h:41
Date getDataStart() const
Returns the real beginning of the data contained in the buffer. This is the start date of the availab...
Definition: Buffer.cc:257
double getAvgSamplingRate() const
Returns the average sampling rate in the data. This computes the average sampling rate of the data th...
Definition: Buffer.cc:223
Date getBufferStart() const
Returns the beginning of the buffer. This is the start date of the request that was given to the IOHa...
Definition: Buffer.cc:247
Date getBufferEnd() const
Returns the end of the buffer. This is the end date of the request that was given to the IOHandler....
Definition: Buffer.cc:252
bool empty() const
Check if the buffer is empty.
Definition: Buffer.cc:74
void setBufferStart(const Date &date)
Definition: Buffer.cc:290
std::vector< METEO_SET > & getBuffer()
Definition: Buffer.cc:285
Date getDataEnd() const
Returns the real end of the data contained in the buffer. This is the end date of the available data ...
Definition: Buffer.cc:271
const std::string toString() const
Definition: Buffer.cc:298
size_t size() const
Returns the number of stations present in the buffer.
Definition: Buffer.h:111
void clear()
Clear the buffer; the data is deleted and the start and end dates reset to undef
Definition: Buffer.cc:80
void push(const Date &date_start, const Date &date_end, const std::vector< METEO_SET > &vecMeteo)
Add data representing the available data between two dates.
Definition: Buffer.cc:153
bool get(const Date &date, METEO_SET &vecMeteo) const
Get buffer data for a specific date.
Definition: Buffer.cc:29
void setBufferEnd(const Date &date)
Definition: Buffer.cc:294
Parameters
this enum provides names for possible meteogrids (from an ARPS file, etc)
Definition: MeteoData.h:46
Definition: Config.cc:31
std::vector< MeteoData > METEO_SET
Definition: MeteoData.h:32