WSL/SLF GitLab Repository

BufferedIOHandler.h 5.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/***********************************************************************************/
/*  Copyright 2009 WSL Institute for Snow and Avalanche Research    SLF-DAVOS      */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BUFFEREDIOHANDLER_H__
#define __BUFFEREDIOHANDLER_H__

#include <meteoio/IOHandler.h>
22
#include <meteoio/Config.h>
23
24
25
26
27
28
29
30
31
32
33
34
#include <map>
#include <vector>
#include <string>

namespace mio {

/**
 * @class BufferedIOHandler
 * @brief This class is the class to use for buffered I/O operations. It is responsible for transparently loading the plugins
 * and transparently buffering the data. It follows the interface defined by the IOInterface class with the addition of
 * a few convenience methods.
 *
35
36
37
38
 * @section buffereiohandler_keywords Keywords
 * This module uses the following keywords to customize the buffering:
 * - BUFF_CHUNKS: how many chunks of data to buffer; [General] section (NOT YET USED)
 * - BUFF_CHUNK_SIZE: size in days of a chunk of data to read at once; [General] section
39
40
41
42
43
 * - BUFF_CENTERING: centering of the buffer. When rebuffering, the new date will be located BUFF_CENTERING % from the
 *                   begining of the buffer (therefore, it takes a value between 0 and 1); [General] section, optional
 *                   (10% by default)
 * - BUFF_BEFORE: alternate way of buffer centering: When rebuffering, the new date will be located BUFF_BEFORE days from the
 *                begining of the buffer (therefore, it takes a value in days); [General] section, optional. Only one of
44
45
 *                two centering option can be used.
 *
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 * @author Thomas Egger
 * @date   2009-07-25
 */

class MeteoFilter;

#ifdef _POPC_
class BufferedIOHandler {
#else
class BufferedIOHandler : public IOInterface {
#endif
	public:

		/**
		 * @brief The constructor accepts an already initialized child of IOInterface (e.g. A3DIO, BormaIO, ImisIO)
61
		 *        and a Config object
62
63
64
65
		 *
		 * Example Usage:
		 * @code
		 * IOHandler *io1;
66
		 * Config cfg("io.ini");
67
68
69
70
		 * io1 = new A3DIO(cfg);
		 * BufferedIOHandler bio(*io1, cfg);
		 * @endcode
		 */
71
		BufferedIOHandler(IOHandler& in_iohandler, const Config& in_cfg);
72
73
74
75
76
77
	#ifdef _POPC_
		virtual ~BufferedIOHandler();
	#else
		virtual ~BufferedIOHandler() throw();
	#endif

78
79
80
81
82
83
		///Keywords for slope computation algorithm
		typedef enum BUFFER_POLICY {
			KEEP_NODATA, ///< when a data point is nodata in the buffer, return the buffered value
			RECHECK_NODATA ///< when a data point is nodata in the buffer, refresh the buffer to see if a value could be found
		} buffer_policy;

84
		/**
85
		 * @brief Read the metadata for a given date.
86
87
		 * @param date date for which to read the metadata
		 * @param vecStation vector of metadata
88
		 */
89
		virtual void readStationData(const Date& date, STATION_TIMESERIE& vecStation);
90
91
92
93
94
95
96
97
98
99
100
101

		/**
		 * @brief Clear all buffers in BufferedIOHandler and hence force rebuffering
		 */
		void clearBuffer();

		virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
		virtual void readDEM(DEMObject& dem_out);
		virtual void readAssimilationData(const Date& date_in, Grid2DObject& da_out);
		virtual void readLanduse(Grid2DObject& landuse_out);
		virtual void readSpecialPoints(std::vector<Coords>& pts);
		virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
102
		                           std::vector< METEO_TIMESERIE >& vecMeteo,
103
		                           const unsigned int& stationindex=IOUtils::npos);
104
#ifdef _POPC_
105
		virtual void writeMeteoData(std::vector< METEO_TIMESERIE >& vecMeteo,
106
		                            const std::string& name="");
107
#else
108
		virtual void writeMeteoData(const std::vector< METEO_TIMESERIE >& vecMeteo,
109
		                            const std::string& name="");
110
111
112
#endif
		virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& options="");

113
114
		double getAvgSamplingRate();

115
116
		friend std::ostream& operator<<(std::ostream& os, const BufferedIOHandler& data);

117
		friend class IOManager;
118

119
	private:
120
		//private methods
121
		const std::vector<METEO_TIMESERIE>& get_complete_buffer(Date& start, Date& end);
122

123
124
		void push_meteo_data(const Date& date_start, const Date& date_end,
		                     const std::vector< METEO_TIMESERIE >& vecMeteo);
125

126
		void setDfltBufferProperties();
127
		void bufferData(const Date& date_start, const Date& date_end, std::vector< METEO_TIMESERIE >& vecvecMeteo);
128

129
		//private members
130
		IOHandler& iohandler;
131
		const Config& cfg;
132

133
134
135
		std::vector< METEO_TIMESERIE > vec_buffer_meteo;
		std::map<std::string, Grid2DObject> mapBufferedGrids;

136
		Date buffer_start, buffer_end;
137
138
		Duration chunk_size; ///< How much data to read at once
		Duration buff_before; ///< How much data to read before the requested date in buffer
139
		unsigned int chunks; ///< How many chuncks to buffer
140
141
142
};
} //end namespace
#endif