MeteoIODoc  2.10.0
TimeSeriesManager.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 TIMESERIESMANAGER_H
20 #define TIMESERIESMANAGER_H
21 
22 #include <meteoio/DataGenerator.h>
23 #include <meteoio/MeteoProcessor.h>
26 #include <meteoio/IOHandler.h>
27 #include <meteoio/Config.h>
28 
29 namespace mio {
30 
32  public:
33  enum cache_types {
34  RAW,
37  ALL
38  };
39 
51  TimeSeriesManager(IOHandler& in_iohandler, const Config& in_cfg, const char& rank=1, const IOUtils::OperationMode &mode=IOUtils::STD);
52 
53  size_t getStationData(const Date& date, STATIONS_SET& vecStation);
54 
69  size_t getMeteoData(const Date& dateStart, const Date& dateEnd,
70  std::vector< METEO_SET >& vecVecMeteo);
71 
87  size_t getMeteoData(const Date& i_date, METEO_SET& vecMeteo);
88 
101  void push_meteo_data(const IOUtils::ProcessingLevel& level, const Date& date_start, const Date& date_end,
102  const std::vector< MeteoData >& vecMeteo, const bool& invalidate_cache=true);
103 
104  void push_meteo_data(const IOUtils::ProcessingLevel& level, const Date& date_start, const Date& date_end,
105  const std::vector< METEO_SET >& vecMeteo);
106 
119  void setProcessingLevel(const unsigned int& i_level);
120 
129  void setBufferProperties(const double& buffer_size, const double& buff_before);
130 
131  void setRawBufferProperties(const Date& raw_buffer_start, const Date& raw_buffer_end);
132 
138  void getBufferProperties(Duration &o_buffer_size, Duration &o_buff_before) const;
139 
149  double getAvgSamplingRate() const;
150 
151  void writeMeteoData(const std::vector< METEO_SET >& vecMeteo, const std::string& name="");
152 
153  const std::string toString() const;
154 
164  void add_to_points_cache(const Date& i_date, const METEO_SET& vecMeteo);
165 
170  void clear_cache(const cache_types& cache);
171 
177  const Config getConfig() const {return cfg;}
178 
184  IOHandler& getIOHandler() const {return iohandler;}
185 
193  Date getBufferStart(const cache_types& cache) const;
194 
202  Date getBufferEnd(const cache_types& cache) const;
203 
211  Date getDataStart(const cache_types& cache) const;
212 
220  Date getDataEnd(const cache_types& cache) const;
221 
222 
223  private:
224  static bool compare(std::pair<Date, METEO_SET> p1, std::pair<Date, METEO_SET> p2);
225  void setDfltBufferProperties();
226  void fill_filtered_cache();
227  void fillRawBuffer(const Date& date_start, const Date& date_end);
228 
229  const Config& cfg;
230  IOHandler& iohandler;
231  MeteoProcessor meteoprocessor;
232  DataGenerator dataGenerator;
233 
234  ProcessingProperties proc_properties;
235  std::map<Date, METEO_SET > point_cache;
236  MeteoBuffer raw_buffer;
237  MeteoBuffer filtered_cache;
238 
239  Date raw_requested_start, raw_requested_end;
240  Duration chunk_size;
241  Duration buff_before;
242  unsigned int processing_level;
243 };
244 } //end namespace
245 #endif
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:79
A class to generate meteo data from user-selected models or parametrizations. This class sits in betw...
Definition: DataGenerator.h:43
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
This class is the class to use for raw I/O operations. It is responsible for transparently loading th...
Definition: IOHandler.h:37
A class to buffer meteorological data. This class buffers MeteoData objects. It is currently NOT a pr...
Definition: Buffer.h:39
A facade class that invokes the processing of the filters and the resampling.
Definition: MeteoProcessor.h:39
Definition: ProcessingBlock.h:36
Definition: TimeSeriesManager.h:31
size_t getMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< METEO_SET > &vecVecMeteo)
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition: TimeSeriesManager.cc:227
Date getDataEnd(const cache_types &cache) const
Returns the real end of the raw data in buffer.
Definition: TimeSeriesManager.cc:159
void setBufferProperties(const double &buffer_size, const double &buff_before)
Set buffer window properties requirements as known to the application itself.
Definition: TimeSeriesManager.cc:75
void clear_cache(const cache_types &cache)
Clear the chosen cache.
Definition: TimeSeriesManager.cc:371
const std::string toString() const
Definition: TimeSeriesManager.cc:431
double getAvgSamplingRate() const
Returns the average sampling rate in the data.
Definition: TimeSeriesManager.cc:110
void writeMeteoData(const std::vector< METEO_SET > &vecMeteo, const std::string &name="")
Definition: TimeSeriesManager.cc:335
IOHandler & getIOHandler() const
Returns a copy of the internal IOHandler object. This is convenient to clone an iomanager.
Definition: TimeSeriesManager.h:184
cache_types
Definition: TimeSeriesManager.h:33
@ ALL
all caches
Definition: TimeSeriesManager.h:37
@ FILTERED
the filtered data cache
Definition: TimeSeriesManager.h:35
@ RAW
the raw data cache
Definition: TimeSeriesManager.h:34
@ POINTS
the (interpolated) points cache
Definition: TimeSeriesManager.h:36
void push_meteo_data(const IOUtils::ProcessingLevel &level, const Date &date_start, const Date &date_end, const std::vector< MeteoData > &vecMeteo, const bool &invalidate_cache=true)
Push a vector of time series of MeteoData objects into the TimeSeriesManager. This overwrites any int...
Definition: TimeSeriesManager.cc:196
void getBufferProperties(Duration &o_buffer_size, Duration &o_buff_before) const
Get the current buffer requirements (ie user defined buffer + filters/resampling requirements)
Definition: TimeSeriesManager.cc:96
Date getBufferStart(const cache_types &cache) const
Returns the beginning of the raw buffer.
Definition: TimeSeriesManager.cc:119
Date getDataStart(const cache_types &cache) const
Returns the real beginning of the raw data in buffer.
Definition: TimeSeriesManager.cc:143
void setProcessingLevel(const unsigned int &i_level)
Set the desired ProcessingLevel of the TimeSeriesManager instance The processing level affects the wa...
Definition: TimeSeriesManager.cc:102
size_t getStationData(const Date &date, STATIONS_SET &vecStation)
Definition: TimeSeriesManager.cc:218
TimeSeriesManager(IOHandler &in_iohandler, const Config &in_cfg, const char &rank=1, const IOUtils::OperationMode &mode=IOUtils::STD)
Default constructor.
Definition: TimeSeriesManager.cc:32
void add_to_points_cache(const Date &i_date, const METEO_SET &vecMeteo)
Add a METEO_SET for a specific instance to the point cache.
Definition: TimeSeriesManager.cc:361
const Config getConfig() const
Returns a copy of the internal Config object.
Definition: TimeSeriesManager.h:177
void setRawBufferProperties(const Date &raw_buffer_start, const Date &raw_buffer_end)
Definition: TimeSeriesManager.cc:90
Date getBufferEnd(const cache_types &cache) const
Returns the end of the raw buffer.
Definition: TimeSeriesManager.cc:131
OperationMode
Keywords for mode of operation. Please keep all the GRID_xxx last!
Definition: IOUtils.h:63
@ STD
default: extract timeseries from timeseries or grids from grids or spatially interpolate timeseries
Definition: IOUtils.h:64
ProcessingLevel
Definition: IOUtils.h:54
Definition: Config.cc:30
std::vector< MeteoData > METEO_SET
Definition: MeteoData.h:31
std::vector< StationData > STATIONS_SET
Definition: StationData.h:141