WSL/SLF GitLab Repository

Commit c035c2f0 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

A tricky bug was found (thanks Leonardo for giving me a test case showing the...

A tricky bug was found (thanks Leonardo for giving me a test case showing the bug!) when copying data from the buffer back into a vector: the "insert" call from the STL does the copy in the range [start, end[ so we were always missing the last element. Most of the time, this was not an issue since we had such a large buffer, but with small buffers, one could see that the last data point was missing... So now, the "end" iterator is always "last_required+1".
parent a09d1759
......@@ -445,7 +445,7 @@ void IOHandler::readMeteoData(const Date& dateStart, const Date& dateEnd,
IOInterface *plugin = getPlugin("METEO", "Input");
plugin->readMeteoData(dateStart, dateEnd, vecMeteo);
if (!move_ready) create_move_map();
......@@ -140,7 +140,7 @@ size_t TimeSeriesManager::getMeteoData(const Date& dateStart, const Date& dateEn
const bool success = filtered_cache.get(dateStart, dateEnd, vecVecMeteo);
if (!success) {
vector< vector<MeteoData> > tmp_meteo;
std::vector< std::vector<MeteoData> > tmp_meteo;
fillRawBuffer(dateStart, dateEnd);
raw_buffer.get(dateStart, dateEnd, tmp_meteo);
......@@ -59,9 +59,12 @@ bool MeteoBuffer::get(const Date& date_start, const Date& date_end, std::vector<
size_t pos_start = IOUtils::seek(date_start, ts_buffer[ii], false);
if (pos_start==IOUtils::npos) pos_start = 0;
size_t pos_end = IOUtils::seek(date_end, ts_buffer[ii], false);
if (pos_end==IOUtils::npos) pos_end = ts_buffer[ii].size() - 1;
if (pos_end==IOUtils::npos)
pos_end = ts_buffer[ii].size();
pos_end++; //because "insert" does not include the element pointed to by the last iterator
vecMeteo[ii].reserve(pos_end-pos_start+1); //weird that the "insert" does not handle it internally...
vecMeteo[ii].insert(vecMeteo[ii].begin(), ts_buffer[ii].begin()+pos_start, ts_buffer[ii].begin()+pos_end);
......@@ -138,7 +141,7 @@ void MeteoBuffer::push(const Date& date_start, const Date& date_end, const std::
//there is some overlap, only copy data that does NOT overlap
if (data_start<buffer_start) {
const size_t pos = IOUtils::seek(buffer_start, vecMeteo[ii], false); //returns the first date >=
ts_buffer[ii].insert(ts_buffer[ii].begin(), vecMeteo[ii].begin(), vecMeteo[ii].begin()+pos-1);
ts_buffer[ii].insert(ts_buffer[ii].begin(), vecMeteo[ii].begin(), vecMeteo[ii].begin()+pos);
if (data_end>buffer_end) {
size_t pos = IOUtils::seek(buffer_end, vecMeteo[ii], false); //returns the first date >=
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment