WSL/SLF GitLab Repository

Commit 97a68d0b authored by Mathias Bavay's avatar Mathias Bavay
Browse files

code cleanup and micro-optimizations

parent 18297fbe
......@@ -520,9 +520,9 @@ void IOHandler::checkTimestamps(const std::vector<METEO_SET>& vecVecMeteo)
Date previous_date( vecVecMeteo[stat_idx].front().date );
for (size_t ii=1; ii<nr_timestamps; ++ii) {
const Date& current_date = vecVecMeteo[stat_idx][ii].date;
const Date current_date( vecVecMeteo[stat_idx][ii].date );
if (current_date<=previous_date) {
const StationData& station = vecVecMeteo[stat_idx][ii].meta;
const StationData& station( vecVecMeteo[stat_idx][ii].meta );
if (current_date==previous_date)
throw IOException("Error for station \""+station.stationName+"\" ("+station.stationID+") at time "+current_date.toString(Date::ISO)+": timestamps must be unique!", AT);
else
......@@ -537,7 +537,7 @@ void IOHandler::create_merge_map()
{
merge_ready = true;
vector<string> merge_keys;
std::vector<std::string> merge_keys;
const size_t nrOfStations = cfg.findKeys(merge_keys, "::MERGE", "Input", true);
for (size_t ii=0; ii<nrOfStations; ++ii) {
const size_t found = merge_keys[ii].find_first_of(":");
......@@ -549,7 +549,7 @@ void IOHandler::create_merge_map()
if (vecString.empty()) throw InvalidArgumentException("Empty value for key \""+merge_keys[ii]+"\"", AT);
for (vector<string>::iterator it = vecString.begin(); it != vecString.end(); ++it) {
IOUtils::toUpper(*it);
IOUtils::toUpper( *it );
const std::vector<std::string>::const_iterator vec_it = find (merged_stations.begin(), merged_stations.end(), *it);
if (vec_it==merged_stations.end()) merged_stations.push_back( *it ); //this station will be merged into another one
}
......@@ -562,7 +562,7 @@ void IOHandler::create_merge_map()
//make sure there is no "chain merge": station A merging station B and station C merging station A
std::map< std::string, std::vector<std::string> >::iterator it_dest;
for(it_dest=merge_commands.begin(); it_dest!=merge_commands.end(); ++it_dest) {
const std::string &stationID = it_dest->first;
const std::string stationID( it_dest->first );
if (std::binary_search(merged_stations.begin(), merged_stations.end(), stationID))
throw InvalidArgumentException("\'chain merge\' detected for station \'"+stationID+"\', this is not supported (see documentation)", AT);
}
......@@ -581,7 +581,7 @@ void IOHandler::merge_stations(STATIONS_SET& vecStation) const
const std::map< string, vector<string> >::const_iterator it = merge_commands.find( toStationID );
if (it == merge_commands.end()) continue; //no merge commands for this station
const std::vector<std::string> &merge_from( it->second );
const std::vector<std::string> merge_from( it->second );
for (std::vector<std::string>::const_iterator it_set=merge_from.begin(); it_set != merge_from.end(); ++it_set) {
const std::string fromStationID( *it_set );
......@@ -624,7 +624,7 @@ void IOHandler::merge_stations(std::vector<METEO_SET>& vecVecMeteo) const
const std::map< std::string, std::vector<std::string> >::const_iterator it = merge_commands.find( toStationID );
if (it == merge_commands.end()) continue; //no merge commands for this station
const std::vector<std::string> &merge_from( it->second );
const std::vector<std::string> merge_from( it->second );
for (std::vector<std::string>::const_iterator it_set=merge_from.begin(); it_set != merge_from.end(); ++it_set) {
const std::string fromStationID( *it_set );
......@@ -709,7 +709,7 @@ void IOHandler::create_exclude_map()
cfg.getValue(exclude_keys[ii], "Input", vecString);
if (vecString.empty()) throw InvalidArgumentException("Empty value for key \""+exclude_keys[ii]+"\"", AT);
for (vector<string>::iterator it = vecString.begin(); it != vecString.end(); ++it) {
IOUtils::toUpper(*it);
IOUtils::toUpper( *it );
}
const std::set<std::string> tmpset(vecString.begin(), vecString.end());
......@@ -785,7 +785,7 @@ void IOHandler::create_keep_map()
cfg.getValue(keep_keys[ii], "Input", vecString);
if (vecString.empty()) throw InvalidArgumentException("Empty value for key \""+keep_keys[ii]+"\"", AT);
for (vector<string>::iterator it = vecString.begin(); it != vecString.end(); ++it) {
IOUtils::toUpper(*it);
IOUtils::toUpper( *it );
}
const std::set<std::string> tmpset(vecString.begin(), vecString.end());
......@@ -855,7 +855,7 @@ void IOHandler::keep_params(std::vector<METEO_SET>& vecVecMeteo) const
const std::set<std::string> kept( it->second );
for (size_t ii=0; ii<vecVecMeteo[station].size(); ++ii) {
MeteoData& md_ref = vecVecMeteo[station][ii];
MeteoData& md_ref( vecVecMeteo[station][ii] );
MeteoData md( md_ref );
md.reset(); //delete all meteo fields
......@@ -887,7 +887,7 @@ void IOHandler::create_move_map()
if (vecString.empty()) throw InvalidArgumentException("Empty value for key \""+move_keys[ii]+"\"", AT);
for (vector<string>::iterator it = vecString.begin(); it != vecString.end(); ++it) {
IOUtils::toUpper(*it);
IOUtils::toUpper( *it );
}
const std::set<std::string> tmpset(vecString.begin(), vecString.end());
......
......@@ -167,13 +167,13 @@ size_t TimeSeriesManager::getMeteoData(const Date& i_date, METEO_SET& vecMeteo)
//1. Check whether user wants raw data or processed data
//The first case: we are looking at raw data directly, only unresampled values are considered, exact date match
if (processing_level == IOUtils::raw) {
vector< vector<MeteoData> > vec_cache;
std::vector< std::vector<MeteoData> > vec_cache;
const Duration eps(1./(24.*3600.), 0.);
iohandler.readMeteoData(i_date-eps, i_date+eps, vec_cache);
for (size_t ii=0; ii<vec_cache.size(); ii++) { //for every station
const size_t index = IOUtils::seek(i_date, vec_cache[ii], true);
if (index != IOUtils::npos)
vecMeteo.push_back(vec_cache[ii][index]); //Insert station into vecMeteo
vecMeteo.push_back( vec_cache[ii][index] ); //Insert station into vecMeteo
}
return vecMeteo.size();
}
......@@ -187,7 +187,7 @@ size_t TimeSeriesManager::getMeteoData(const Date& i_date, METEO_SET& vecMeteo)
//Let's make sure we have the data we need, in the filtered_cache or in vec_cache
const Date buffer_start( i_date-proc_properties.time_before ), buffer_end( i_date+proc_properties.time_after );
vector< vector<MeteoData> >* data = NULL; //reference to either filtered_cache or raw_buffer
std::vector< vector<MeteoData> >* data = NULL; //reference to either filtered_cache or raw_buffer
if ((IOUtils::filtered & processing_level) == IOUtils::filtered) {
const bool cached = (!filtered_cache.empty()) && (filtered_cache.getBufferStart() <= buffer_start) && (filtered_cache.getBufferEnd() >= buffer_end);
if (!cached) {
......@@ -205,13 +205,13 @@ size_t TimeSeriesManager::getMeteoData(const Date& i_date, METEO_SET& vecMeteo)
for (size_t ii=0; ii<(*data).size(); ii++) { //for every station
MeteoData md;
const bool success = meteoprocessor.resample(i_date, (*data)[ii], md);
if (success) vecMeteo.push_back(md);
if (success) vecMeteo.push_back( md );
}
} else { //no resampling required
for (size_t ii=0; ii<(*data).size(); ii++) { //for every station
const size_t index = IOUtils::seek(i_date, (*data)[ii], true); //needs to be an exact match
if (index != IOUtils::npos)
vecMeteo.push_back((*data)[ii][index]); //Insert station into vecMeteo
vecMeteo.push_back( (*data)[ii][index] ); //Insert station into vecMeteo
}
}
......@@ -275,7 +275,7 @@ void TimeSeriesManager::fillRawBuffer(const Date& date_start, const Date& date_e
raw_buffer.clear(); //HACK until we have a proper ring buffer to avoid eating up all memory...
if (raw_buffer.empty()) {
vector< METEO_SET > vecMeteo;
std::vector< METEO_SET > vecMeteo;
iohandler.readMeteoData(new_start, new_end, vecMeteo);
raw_buffer.push(new_start, new_end, vecMeteo);
return;
......@@ -284,20 +284,20 @@ void TimeSeriesManager::fillRawBuffer(const Date& date_start, const Date& date_e
const Date buffer_start( raw_buffer.getBufferStart() );
const Date buffer_end( raw_buffer.getBufferEnd() );
if (new_start>buffer_end || new_end<buffer_start) { //easy: full rebuffer
vector< METEO_SET > vecMeteo;
std::vector< METEO_SET > vecMeteo;
iohandler.readMeteoData(new_start, new_end, vecMeteo);
raw_buffer.push(new_start, new_end, vecMeteo);
return;
}
if (new_start<buffer_start) { //some data must be inserted before
vector< METEO_SET > vecMeteo;
std::vector< METEO_SET > vecMeteo;
iohandler.readMeteoData(new_start, buffer_start, vecMeteo);
raw_buffer.push(new_start, buffer_start, vecMeteo);
}
if (new_end>buffer_end) { //some data must be inserted after. Keep in mind both before and after could happen simultaneously!
vector< METEO_SET > vecMeteo;
std::vector< METEO_SET > vecMeteo;
iohandler.readMeteoData(buffer_end, new_end, vecMeteo);
raw_buffer.push(buffer_end, new_end, vecMeteo);
}
......
......@@ -432,7 +432,7 @@ void ImisIO::assimilateAnetzData(const Date& dateStart, const AnetzData& ad,
getAnetzPSUM(ad, mapAnetzNames, vec_of_psums, current_station_psum);
size_t counter = 0;
Date current_slice_date = dateStart;
Date current_slice_date( dateStart );
current_slice_date.setTimeZone(in_tz);
for (size_t jj=0; jj<vecMeteo[stationindex].size(); jj++){
while (vecMeteo[stationindex][jj].date > (current_slice_date+0.2485)){
......@@ -458,7 +458,7 @@ void ImisIO::getAnetzPSUM(const AnetzData& ad, const std::map<std::string, size_
vector<size_t> vecIndex; //this vector will hold up to three indexes for the Anetz stations (position in vec_of_psums)
for (size_t ii=0; ii<ad.nrOfAnetzStations; ii++){
const map<string, size_t>::const_iterator it = mapAnetzNames.find(ad.anetzstations[ii]);
vecIndex.push_back(it->second);
vecIndex.push_back( it->second );
}
if (ad.nrOfAnetzStations == ad.nrOfCoefficients){
......@@ -496,7 +496,7 @@ void ImisIO::calculatePsum(const Date& dateStart, const Date& dateEnd,
for (size_t ii=0; ii<vecMeteoAnetz.size(); ii++){
double tmp_psum = 0.0;
Date current_date = dateStart;
Date current_date( dateStart );
current_date.setTimeZone(in_tz);
vector<double> vec_current_station;
......@@ -547,7 +547,7 @@ void ImisIO::findAnetzStations(const size_t& indexStart, const size_t& indexEnd,
std::map<std::string, size_t>& mapAnetzNames,
std::vector<StationData>& vecAnetzStation)
{
set<string> uniqueStations;
std::set<std::string> uniqueStations;
for (size_t ii=indexStart; ii<indexEnd; ii++){ //loop through stations
const map<string, AnetzData>::const_iterator it = mapAnetz.find(vecStationMetaData.at(ii).getStationID());
......@@ -585,7 +585,7 @@ void ImisIO::readData(const Date& dateStart, const Date& dateEnd, std::vector< s
{
vecMeteo.at(stationindex).clear();
string stat_abk, stao_nr;
std::string stat_abk, stao_nr;
vector< vector<string> > vecResult;
// Moving back to the IMIS timezone (UTC+1)
......@@ -648,7 +648,7 @@ void ImisIO::readSWE(const Date& dateStart, const Date& dateEnd, std::vector< st
dateE.setTimeZone(in_tz);
//build stat_abk and stao_nr from station name
string stat_abk, stao_nr;
std::string stat_abk, stao_nr;
parseStationID(vecStationIDs.at(stationindex).getStationID(), stat_abk, stao_nr);
const unsigned int max_row = static_cast<unsigned int>( Optim::ceil( (dateE.getJulian()-dateS.getJulian())*24.*2. ) ); //for prefetching
......@@ -670,7 +670,7 @@ void ImisIO::readSWE(const Date& dateStart, const Date& dateEnd, std::vector< st
stmt->setDate(4, enddate); // set 4th variable's value (end date)
ResultSet *rs = stmt->executeQuery(); // execute the statement stmt
const vector<MetaData> cols = rs->getColumnListMetaData();
const vector<MetaData> cols( rs->getColumnListMetaData() );
double prev_swe = IOUtils::nodata;
Date prev_date;
......
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