WSL/SLF GitLab Repository

Commit 40a68033 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Better error messages in IMISIO, better safety (regarding "undef") in Date and...

Better error messages in IMISIO, better safety (regarding "undef") in Date and some code cleanup/const/reserve business (all benchmarked) for the others. We also now avoid stacking two "/" at the end of the PLUGINPATH if one is already present.
parent 73a9d046
......@@ -58,7 +58,7 @@ void BufferedIOHandler::read2DGrid(Grid2DObject& in_grid2Dobj, const std::string
return;
}
Grid2DObject tmpgrid2D;
Grid2DObject tmpgrid2D; //HACK: why don't we read directly into in_grid2Dobj?
iohandler.read2DGrid(tmpgrid2D, in_filename);
bufferGrid(tmpgrid2D, in_filename);
in_grid2Dobj = tmpgrid2D;
......@@ -274,6 +274,7 @@ void BufferedIOHandler::readMeteoData(const Date& date_start, const Date& date_e
while (date_end > new_buffer_end){
//if the requested interval is bigger than a normal buffer, we have to increase the buffer anyway...
tmp_meteo_buffer.reserve(buffer_size);
iohandler.readMeteoData(new_buffer_end, new_buffer_end+chunk_size*chunks, tmp_meteo_buffer);
if (tmp_meteo_buffer.size() != buffer_size) {
......@@ -284,8 +285,8 @@ void BufferedIOHandler::readMeteoData(const Date& date_start, const Date& date_e
}
//Loop through stations and append data
for (size_t ii=0; ii<buffer_size; ii++){
size_t station_size = vec_buffer_meteo[ii].size();
for (size_t ii=0; ii<buffer_size; ii++){ //loop through stations
const size_t station_size = vec_buffer_meteo[ii].size();
if ((station_size > 0) && (tmp_meteo_buffer[ii].size() > 0)){
//check if the last element equals the first one
......@@ -293,6 +294,7 @@ void BufferedIOHandler::readMeteoData(const Date& date_start, const Date& date_e
vec_buffer_meteo[ii].pop_back(); //delete the element with the same date
}
vec_buffer_meteo[ii].reserve(vec_buffer_meteo[ii].size()+tmp_meteo_buffer[ii].size());
vec_buffer_meteo[ii].insert(vec_buffer_meteo[ii].end(), tmp_meteo_buffer[ii].begin(), tmp_meteo_buffer[ii].end());
}
new_buffer_end += chunk_size*chunks;
......@@ -301,7 +303,8 @@ void BufferedIOHandler::readMeteoData(const Date& date_start, const Date& date_e
}
//2. Copy appropriate data into vecMeteo
for (size_t ii=0; ii<buffer_size; ii++){
vecMeteo.reserve(buffer_size);
for (size_t ii=0; ii<buffer_size; ii++){ //loop through stations
vecMeteo.push_back(vector<MeteoData>()); //insert one empty vector of MeteoData
if (vec_buffer_meteo[ii].size() == 0) continue; //no data in buffer for this station
......@@ -310,14 +313,14 @@ void BufferedIOHandler::readMeteoData(const Date& date_start, const Date& date_e
if (pos_start == IOUtils::npos) pos_start = 0;
size_t pos_end = IOUtils::seek(date_end, vec_buffer_meteo[ii], false);//HACK:: edit IOUtils::seek to accept an offset
if (pos_end == IOUtils::npos) pos_end = vec_buffer_meteo[ii].size() - 1; //just copy until the end of the buffer
//cerr << "Station " << ii << ": pos_start=" << pos_start << " pos_end=" << pos_end << endl;
if (pos_end == IOUtils::npos) pos_end = vec_buffer_meteo[ii].size() - 1; //just copy until the end of the buffer
if (vec_buffer_meteo[ii][pos_end].date > date_end){
if (pos_end > pos_start) pos_end--;
if (pos_end > pos_start) pos_end--;
} else {
pos_end++;
}
//cerr << "Station " << ii << ": pos_start=" << pos_start << " pos_end=" << pos_end << endl;
vecMeteo[ii].reserve(pos_end-pos_start+1); //weird that the "insert" does not handle it internally...
vecMeteo[ii].insert(vecMeteo[ii].begin(), vec_buffer_meteo[ii].begin()+pos_start, vec_buffer_meteo[ii].begin()+pos_end);
}
}
......
......@@ -59,7 +59,7 @@ void Config::addCmdLine(const std::string& cmd_line)
void Config::addKey(const std::string& key, const std::string& value)
{
std::string section=defaultSection;
const std::string section=defaultSection;
addKey(key, section, value);
}
......@@ -98,8 +98,6 @@ void Config::parseCmdLine(const std::string& cmd_line)
void Config::parseFile(const std::string& filename)
{
std::ifstream fin; //Input file streams
unsigned int linenr = 0;
std::string line="", section=defaultSection;
if (!IOUtils::validFileName(filename)) {
throw InvalidFileNameException(filename,AT);
......@@ -116,7 +114,9 @@ void Config::parseFile(const std::string& filename)
throw FileAccessException(filename, AT);
}
char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
std::string line="", section=defaultSection;
const char eoln = IOUtils::getEoln(fin); //get the end of line character for the file
unsigned int linenr = 0;
try {
do {
......@@ -183,7 +183,7 @@ size_t Config::findKeys(std::vector<std::string>& vecResult, std::string keystar
map<string,string>::const_iterator it;
for (it=properties.begin(); it != properties.end(); it++){
const string tmp = (it->first).substr(0, tmp_keystart.length());
int matchcount = tmp_keystart.compare(tmp);
const int matchcount = tmp_keystart.compare(tmp);
if (matchcount == 0){ //perfect match
const string tmp2 = (it->first).substr(section.length() + 2);
......@@ -196,7 +196,7 @@ size_t Config::findKeys(std::vector<std::string>& vecResult, std::string keystar
std::string Config::extract_section(std::string& key)
{
string::size_type pos = key.find("::");
const string::size_type pos = key.find("::");
if (pos != string::npos){
string sectionname = key.substr(0, pos);
......
......@@ -160,7 +160,6 @@ void Date::setDate(const Date& in_date)
void Date::setDate(const int& i_year, const int& i_month, const int& i_day, const int& i_hour, const int& i_minute, const double& i_timezone, const bool& i_dst)
{
plausibilityCheck(i_year, i_month, i_day, i_hour, i_minute); //also checks leap years
undef = false;
setTimeZone(i_timezone, i_dst);
if(timezone==0 && dst==false) {
......@@ -175,6 +174,7 @@ void Date::setDate(const int& i_year, const int& i_month, const int& i_day, cons
}
//updating values to GMT, fixing potential 24:00 hour (ie: replaced by next day, 00:00)
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
undef = false;
}
void Date::setDate(const int& year, const unsigned int& month, const unsigned int& day, const unsigned int& hour, const unsigned int& minute, const double& in_timezone, const bool& in_dst)
......@@ -191,8 +191,8 @@ void Date::setDate(const int& year, const unsigned int& month, const unsigned in
void Date::setDate(const double& julian_in, const double& in_timezone, const bool& in_dst) {
setTimeZone(in_timezone, in_dst);
gmt_julian = localToGMT(julian_in);
undef = false;
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
undef = false;
}
/**
......
......@@ -164,11 +164,11 @@ void IOHandler::loadPlugin(const std::string& libname, const std::string& classn
try {
cfg.getValue("PLUGINPATH", pluginpath, Config::nothrow);
if (pluginpath != "")
if (pluginpath.length() > 0 && pluginpath.at( pluginpath.length() - 1 )!='/')
pluginpath += "/";
//Which dynamic library needs to be loaded
std::string filename = pluginpath + libname;
const std::string filename = pluginpath + libname;
dynLibrary = DynamicLoader::loadObjectFile(filename);
if(dynLibrary == NULL) {
......@@ -244,13 +244,14 @@ void IOHandler::readStationData(const Date& date, STATION_TIMESERIE& vecStation)
void IOHandler::readMeteoData(const Date& date, METEO_TIMESERIE& vecMeteo)
{
vecMeteo.clear();
std::vector< std::vector<MeteoData> > meteoTmpBuffer;
readMeteoData(date, date, meteoTmpBuffer);
unsigned int emptycounter = 0;
for (unsigned int ii=0; ii<meteoTmpBuffer.size(); ii++){//stations
vecMeteo.clear();
vecMeteo.reserve(meteoTmpBuffer.size());
size_t emptycounter = 0;
for (size_t ii=0; ii<meteoTmpBuffer.size(); ii++){//stations
if (meteoTmpBuffer[ii].size() > 0){
vecMeteo.push_back(meteoTmpBuffer[ii][0]);
} else {
......@@ -314,11 +315,11 @@ void IOHandler::parse_copy_config()
* duplicated (starting with 'COPY::')
*/
vector<string> copy_keys;
size_t nrOfMatches = cfg.findKeys(copy_keys, "COPY::", "Input");
const size_t nrOfMatches = cfg.findKeys(copy_keys, "COPY::", "Input");
for (size_t ii=0; ii<nrOfMatches; ii++) {
string initial_name = "";
string name_of_copy = copy_keys[ii].substr(6);
const string name_of_copy = copy_keys[ii].substr(6);
cfg.getValue(copy_keys[ii], "Input", initial_name);
if ((name_of_copy.length() > 0) && (initial_name.length() > 0)){
......@@ -352,7 +353,7 @@ void IOHandler::copy_parameters(const size_t& stationindex, std::vector< METEO_T
}
}
size_t nr_of_params = copy_parameter.size();
const size_t nr_of_params = copy_parameter.size();
vector<size_t> indices; //will hold the indices of the parameters to be copied
for (size_t ii=station_start; ii<station_end; ii++) { //for each station
......@@ -360,7 +361,7 @@ void IOHandler::copy_parameters(const size_t& stationindex, std::vector< METEO_T
if (jj==0) { //buffer the index numbers
for (size_t kk=0; kk<nr_of_params; kk++) {
size_t param_index = vecMeteo[ii][jj].getParameterIndex(copy_parameter[kk]);
const size_t param_index = vecMeteo[ii][jj].getParameterIndex(copy_parameter[kk]);
if (param_index == IOUtils::npos) {
std::stringstream ss;
ss << "At " << vecMeteo[ii][jj].date.toString(Date::ISO) << ", station " << vecMeteo[ii][jj].meta.stationID;
......@@ -373,8 +374,8 @@ void IOHandler::copy_parameters(const size_t& stationindex, std::vector< METEO_T
}
for (size_t kk=0; kk<nr_of_params; kk++) {
size_t newindex = vecMeteo[ii][jj].addParameter(copy_name[kk]);
vecMeteo[ii][jj](newindex) = vecMeteo[ii][jj](indices[kk]);
const size_t newparam = vecMeteo[ii][jj].addParameter(copy_name[kk]);
vecMeteo[ii][jj](newparam) = vecMeteo[ii][jj](indices[kk]);
}
}
indices.clear(); //may change for every station
......
......@@ -64,8 +64,12 @@ void IOManager::push_meteo_data(const ProcessingLevel& level, const Date& date_s
const std::vector< METEO_TIMESERIE >& vecMeteo)
{
//perform check on date_start and date_end
if (date_end < date_start)
throw InvalidArgumentException("date_start cannot be greater than date_end", AT);
if (date_end < date_start) {
std::stringstream ss;
ss << "Trying to push data set from " << date_start.toString(Date::ISO) << " to " << date_end.toString(Date::ISO) << ". ";
ss << " Obviously, date_start should be less than date_end!";
throw InvalidArgumentException(ss.str(), AT);
}
if (level == IOManager::filtered){
fcache_start = date_start;
......@@ -103,7 +107,7 @@ size_t IOManager::getMeteoData(const Date& dateStart, const Date& dateEnd, std::
if (processing_level == IOManager::raw){
rawio.readMeteoData(dateStart, dateEnd, vecMeteo);
} else {
bool success = read_filtered_cache(dateStart, dateEnd, vecMeteo);
const bool success = read_filtered_cache(dateStart, dateEnd, vecMeteo);
if (!success){
vector< vector<MeteoData> > tmp_meteo;
......@@ -245,7 +249,6 @@ size_t IOManager::getMeteoData(const Date& i_date, METEO_TIMESERIE& vecMeteo)
MeteoData md;
for (size_t ii=0; ii<(*data).size(); ii++) { //for every station
const bool success = meteoprocessor.resample(i_date, (*data)[ii], md);
if (success) vecMeteo.push_back(md);
}
}
......@@ -348,7 +351,7 @@ void IOManager::interpolate(const Date& date, const DEMObject& dem, const MeteoD
vector<Coords> vec_coords = in_coords;
for (size_t ii=0; ii<vec_coords.size(); ii++) {
bool gridify_success = dem.gridify(vec_coords[ii]);
const bool gridify_success = dem.gridify(vec_coords[ii]);
if (!gridify_success)
throw InvalidArgumentException("Coordinate given to interpolate is outside of dem", AT);
......
......@@ -294,7 +294,7 @@ void ImisIO::readStationData(const Date&, std::vector<StationData>& vecStation)
closeDBConnection(env, conn);
} catch (const exception& e){
closeDBConnection(env, conn);
throw IOException("Oracle Error: " + string(e.what()), AT); //Translation of OCCI exception to IOException
throw IOException("Oracle Error when reading stations' metedata: " + string(e.what()), AT); //Translation of OCCI exception to IOException
}
}
......@@ -493,7 +493,7 @@ void ImisIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
closeDBConnection(env, conn);
} catch (const exception& e){
closeDBConnection(env, conn);
throw IOException("Oracle Error: " + string(e.what()), AT); //Translation of OCCI exception to IOException
throw IOException("Oracle Error when reading stations' data: " + string(e.what()), AT); //Translation of OCCI exception to IOException
}
}
......@@ -797,7 +797,7 @@ void ImisIO::readSWE(const Date& dateStart, const Date& dateEnd, std::vector< st
stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
} catch (const exception& e){
throw IOException(string(e.what()), AT); //Translation of OCCI exception to IOException
throw IOException("Oracle Error when SWE data: " + string(e.what()), AT); //Translation of OCCI exception to IOException
}
}
......@@ -891,7 +891,7 @@ size_t ImisIO::getStationIDs(const std::string& station_code, const std::string&
conn->terminateStatement(stmt);
return cols.size();
} catch (const exception& e){
throw IOException(string(e.what()), AT); //Translation of OCCI exception to IOException
throw IOException("Oracle Error when reading stations' id: " + string(e.what()), AT); //Translation of OCCI exception to IOException
}
}
......@@ -929,7 +929,7 @@ size_t ImisIO::getSensorDepths(const std::string& stat_abk, const std::string& s
conn->terminateStatement(stmt);
return cols.size();
} catch (const exception& e){
throw IOException(string(e.what()), AT); //Translation of OCCI exception to IOException
throw IOException("Oracle Error when reading sensors' depths: " + string(e.what()), AT); //Translation of OCCI exception to IOException
}
}
......@@ -968,7 +968,7 @@ size_t ImisIO::getStationMetaData(const std::string& stat_abk, const std::string
conn->terminateStatement(stmt);
return cols.size();
} catch (const exception& e){
throw IOException(string(e.what()), AT); //Translation of OCCI exception to IOException
throw IOException("Oracle Error when reading stations' metadata: " + string(e.what()), AT); //Translation of OCCI exception to IOException
}
}
......@@ -1037,7 +1037,7 @@ bool ImisIO::getStationData(const std::string& stat_abk, const std::string& stao
conn->terminateStatement(stmt);
return fullStation;
} catch (const exception& e){
throw IOException(string(e.what()), AT); //Translation of OCCI exception to IOException
throw IOException("Oracle Error when reading stations' data: " + string(e.what()), AT); //Translation of OCCI exception to IOException
}
}
......
Supports Markdown
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