FFSM++  1.1.0
French Forest Sector Model ++
BaseClass Class Reference

Base class for the regmas application. More...

#include <BaseClass.h>

Inheritance diagram for BaseClass:
Collaboration diagram for BaseClass:

Public Member Functions

 BaseClass ()
 
 ~BaseClass ()
 
void msgOut (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const int &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
void msgOut (const int &msgCode_h, const double &msg_h, const bool &refreshGUI_h=true) const
 Overloaded function to print the output log. More...
 
int s2i (const string &string_h) const
 string to integer conversion More...
 
double s2d (const string &string_h) const
 string to double conversion More...
 
double s2d (const string &string_h, const bool &replaceComma) const
 string to double conversion More...
 
bool s2b (const string &string_h) const
 string to bool conversion More...
 
string i2s (const int &int_h) const
 integer to string conversion More...
 
string d2s (const double &double_h) const
 double to string conversion More...
 
string b2s (const bool &bool_h) const
 bool to string conversion More...
 
vector< int > s2i (const vector< string > &string_h) const
 string to integer conversion (vector) More...
 
vector< double > s2d (const vector< string > &string_h, const bool &replaceComma=false) const
 string to double conversion (vector) More...
 
vector< bool > s2b (const vector< string > &string_h) const
 string to bool conversion (vector) More...
 
vector< string > i2s (const vector< int > &int_h) const
 integer to string conversion (vector) More...
 
vector< string > d2s (const vector< double > &double_h) const
 double to string conversion (vector) More...
 
vector< string > b2s (const vector< bool > &bool_h) const
 bool to string conversion (vector) More...
 
int getType (const string &type_h) const
 Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2)) More...
 
void refreshGUI () const
 Ping to periodically return the control to the GUI. More...
 
template<typename T >
string toString (const T &x) const
 
template<typename T >
stringTo (const std::string &s) const
 
int vSum (const vector< int > &vector_h) const
 
double vSum (const vector< double > &vector_h) const
 
int vSum (const vector< vector< int > > &vector_h) const
 
double vSum (const vector< vector< double > > &vector_h) const
 
void tokenize (const string &str, vector< string > &tokens, const string &delimiter=" ") const
 Tokenize a string using a delimiter (default is space) More...
 
void untokenize (string &str, vector< string > &tokens, const string &delimiter=" ") const
 
template<typename K , typename V >
findMap (const map< K, V > &mymap, const K &key, const int &error_level=MSG_CRITICAL_ERROR, const V &notFoundValue=numeric_limits< V >::min()) const
 Lookup a map for a value. Return the value starting from the key. More...
 
template<typename K , typename V >
void changeMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Change the value stored in a map given the key and the new value. More...
 
template<typename K , typename V >
void incrMapValue (map< K, V > &mymap, const K &key, const V &value, const int &error_level=MSG_CRITICAL_ERROR)
 Increments a value stored in a map of the specified value, given the key. More...
 
template<typename K , typename V >
void incrOrAddMapValue (map< K, V > &mymap, const K &key, const V &value)
 Increments a value stored in a map of the specified value, given the key. More...
 
template<typename K , typename V >
void resetMapValues (map< K, V > &mymap, const V &value)
 Reset all values stored in a map to the specified one. More...
 
template<typename K , typename V >
map< K, V > vectorToMap (const vector< K > &keys, const V &value=0.0)
 Returns a map built using the given vector and the given (scalar) value as keys/values pairs. More...
 
template<typename T >
vector< T > positionsToContent (const vector< T > &vector_h, const vector< int > &positions)
 Return a vector of content from a vector and a vector of positions (int) More...
 
template<typename V >
void debugMap (const map< iisskey, V > &mymap)
 Debug a map. More...
 
template<typename K , typename V >
void debugMap (const map< K, V > &mymap, const K &key)
 
template<typename K >
int getMaxPos (const vector< K > &v)
 Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima) More...
 
template<typename K >
int getMinPos (const vector< K > &v)
 Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima) More...
 
template<typename K >
getMax (const vector< K > &v)
 Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima) More...
 
template<typename K >
getMin (const vector< K > &v)
 Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima) More...
 
template<typename K >
double getAvg (const vector< K > &v)
 Returns the average of the elements in the vector. More...
 
template<typename K >
double getSd (const vector< K > &v, bool sample=true)
 
template<typename K >
int getPos (const K &element, const vector< K > &v, const int &msgCode_h=MSG_CRITICAL_ERROR)
 
template<typename K >
bool inVector (const K &element, const vector< K > &v)
 
double normSample (const double &avg, const double &stdev, const double &minval=NULL, const double &maxval=NULL) const
 Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only after milion of loops). More...
 
template<typename K >
normSample (normal_distribution< K > &d, std::mt19937 &gen, const K &minval=NULL, const K &maxval=NULL) const
 Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once. More...
 
template<typename T >
std::string toString (const T &x) const
 

Protected Attributes

ThreadManagerMTHREAD
 Pointer to the Thread manager. More...
 

Private Member Functions

void msgOut2 (const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h) const
 Do the job of the overloaded functions. More...
 

Detailed Description

Base class for the regmas application.

This class is the base class for all classes in regmas. \ It provides common methods in all parts of the application for printing the output, converting strings vs. values or regularly "ping" the GUI. \

Author
Antonello Lobianco

Definition at line 239 of file BaseClass.h.

Constructor & Destructor Documentation

BaseClass ( )

Definition at line 31 of file BaseClass.cpp.

32 {
33  MTHREAD=NULL;
34 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
~BaseClass ( )

Definition at line 36 of file BaseClass.cpp.

37 {
38 
39 }

Member Function Documentation

string b2s ( const bool &  bool_h) const

bool to string conversion

Definition at line 239 of file BaseClass.cpp.

239  {
240  if (bool_h) return "true";
241  else return "false";
242 }
vector< string > b2s ( const vector< bool > &  bool_h) const

bool to string conversion (vector)

Definition at line 299 of file BaseClass.cpp.

299  {
300  vector <string> valuesAsString;
301  for (uint i=0;i<bool_h.size();i++){
302  if(bool_h[i]) valuesAsString.push_back("true");
303  else valuesAsString.push_back("false");
304  }
305  return valuesAsString;
306 }
void changeMapValue ( map< K, V > &  mymap,
const K &  key,
const V &  value,
const int &  error_level = MSG_CRITICAL_ERROR 
)
inline

Change the value stored in a map given the key and the new value.

Definition at line 299 of file BaseClass.h.

299  {
300  typename map<K, V>::iterator p;
301  p=mymap.find(key);
302  if(p != mymap.end()) {
303  p->second = value;
304  return;
305  }
306  else {
307  msgOut(error_level, "Error in finding a value in a map (no value found)");
308  }
309  }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
string d2s ( const double &  double_h) const

double to string conversion

Definition at line 229 of file BaseClass.cpp.

Referenced by Layers::countMyPixels(), Layers::filterExogenousDataset(), Layers::print(), ModelCoreSpatial::runBiologicalModule(), ModelCoreSpatial::runManagementModule(), and ModelCoreSpatial::runMarketModule().

229  {
230  //ostringstream out;
231  //out<<double_h;
232  //return out.str();
233  char outChar[24];
234  snprintf ( outChar, sizeof(outChar), "%f", double_h );
235  return string(outChar);
236 }

Here is the caller graph for this function:

vector< string > d2s ( const vector< double > &  double_h) const

double to string conversion (vector)

Definition at line 290 of file BaseClass.cpp.

290  {
291  vector <string> valuesAsString;
292  for (uint i=0;i<double_h.size();i++){
293  valuesAsString.push_back(d2s(double_h[i]));
294  }
295  return valuesAsString;
296 }
string d2s(const double &double_h) const
double to string conversion
Definition: BaseClass.cpp:229
void debugMap ( const map< iisskey, V > &  mymap)
inline

Debug a map.

Definition at line 368 of file BaseClass.h.

368  {
369  iisskey mykey(NULL,NULL,"","");
370  debugMap(mymap, mykey);
371  }
Class to provide a simple integer-integer-string-string key in std maps.
Definition: BaseClass.h:213
void debugMap(const map< iisskey, V > &mymap)
Debug a map.
Definition: BaseClass.h:368
void debugMap ( const map< K, V > &  mymap,
const K &  key 
)
inline

Definition at line 372 of file BaseClass.h.

372  {
373  cout<<"Debugging a map" << endl;
374  for (auto const &themap: mymap) {
375  if(themap.first.filter(key)){
376  cout << themap.first.print() << '\t' << themap.second << endl;
377  }
378  }
379  }
V findMap ( const map< K, V > &  mymap,
const K &  key,
const int &  error_level = MSG_CRITICAL_ERROR,
const V &  notFoundValue = numeric_limits<V>::min() 
) const
inline

Lookup a map for a value. Return the value starting from the key.

Definition at line 286 of file BaseClass.h.

Referenced by ModelData::getAvailableDeathTimber(), Carbon::getCumSavedEmissions(), Carbon::getStock(), Carbon::HWP_eol2energy(), Output::printDetailedHV(), ModelCoreSpatial::runManagementModule(), ModelCoreSpatial::sumRegionalForData(), and ModelCoreSpatial::updateMapAreas().

286  {
287  typename map<K, V>::const_iterator p;
288  p=mymap.find(key);
289  if(p != mymap.end()) {
290  return p->second;
291  }
292  else {
293  msgOut(error_level, "Error in finding a value in a map (no value found)");
294  return notFoundValue;
295  }
296  }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50

Here is the caller graph for this function:

double getAvg ( const vector< K > &  v)
inline

Returns the average of the elements in the vector.

Definition at line 399 of file BaseClass.h.

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols().

399  {
400  return v.size()==0 ? 0.0 : vSum(v)/ ( (double) v.size() );
401  }
int vSum(const vector< int > &vector_h) const
Definition: BaseClass.h:276

Here is the caller graph for this function:

K getMax ( const vector< K > &  v)
inline

Returns the value of the maximum element in the vector (the last one in case of multiple equivalent maxima)

Definition at line 391 of file BaseClass.h.

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols(), and ModelCoreSpatial::sumRegionalForData().

391  {
392  return *minmax_element(v.begin(), v.end()).second;
393  }

Here is the caller graph for this function:

int getMaxPos ( const vector< K > &  v)
inline

Returns the position of the maximum element in the vector (the last one in case of multiple equivalent maxima)

Definition at line 383 of file BaseClass.h.

Referenced by ModelCoreSpatial::runManagementModule().

383  {
384  return (minmax_element(v.begin(), v.end()).second - v.begin());
385  }

Here is the caller graph for this function:

K getMin ( const vector< K > &  v)
inline

Returns the value of the minimum element in the vector (the first one in case of multiple equivalent minima)

Definition at line 395 of file BaseClass.h.

395  {
396  return *minmax_element(v.begin(), v.end()).first;
397  }
int getMinPos ( const vector< K > &  v)
inline

Returns the position of the minimum element in the vector (the first one in case of multiple equivalent minima)

Definition at line 387 of file BaseClass.h.

387  {
388  return (minmax_element(v.begin(), v.end()).first - v.begin());
389  }
int getPos ( const K &  element,
const vector< K > &  v,
const int &  msgCode_h = MSG_CRITICAL_ERROR 
)
inline

Definition at line 421 of file BaseClass.h.

Referenced by ModelCoreSpatial::runManagementModule().

421  {
422  for(unsigned int i=0; i<v.size(); i++){
423  if(v[i]== element) return i;
424  }
425  msgOut(msgCode_h, "Element not found in vector in getPos()");
426  return -1;
427  }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50

Here is the caller graph for this function:

double getSd ( const vector< K > &  v,
bool  sample = true 
)
inline

Returns the sd of the elements of a vector. Default to sample sd.

See http://stackoverflow.com/questions/7616511/calculate-mean-and-standard-deviation-from-a-vector-of-samples-in-c-using-boos where there is also an example for covariance

Definition at line 408 of file BaseClass.h.

Referenced by ModelCoreSpatial::assignSpMultiplierPropToVols().

408  {
409  if (v.size()==0) return 0.0;
410  int sampleCorrection = sample==true?1:0;
411  double sum = std::accumulate(std::begin(v), std::end(v), 0.0);
412  double m = sum / v.size();
413  double accum = 0.0;
414  std::for_each (std::begin(v), std::end(v), [&](const double d) {
415  accum += (d - m) * (d - m);
416  });
417  double stdev = sqrt(accum / ( (double) (v.size()-sampleCorrection)));
418  return stdev;
419  }

Here is the caller graph for this function:

int getType ( const string &  type_h) const

Return a type according to enum TYPE_* from a string (eg: "string" -> TYPE_STRING (2))

Definition at line 310 of file BaseClass.cpp.

Referenced by ModelData::setDefaultSettings(), and ModelData::setScenarioSettings().

310  {
311  int toReturn=0;
312  if (type_h == "int") toReturn = TYPE_INT;
313  else if (type_h == "double") toReturn = TYPE_DOUBLE;
314  else if (type_h == "string") toReturn = TYPE_STRING;
315  else if (type_h == "bool") toReturn = TYPE_BOOL;
316  else msgOut(MSG_CRITICAL_ERROR, "Unknow type "+type_h+".");
317  return toReturn;
318 }
The required data is a string.
Definition: BaseClass.h:68
The required data is a bool.
Definition: BaseClass.h:69
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
The required data is a double.
Definition: BaseClass.h:67
The required data is an integer.
Definition: BaseClass.h:66

Here is the caller graph for this function:

string i2s ( const int &  int_h) const

integer to string conversion

Definition at line 219 of file BaseClass.cpp.

Referenced by Layers::addLegendItems(), ModelData::applyOverrides(), ModelCoreSpatial::assignSpMultiplierPropToVols(), LLData::clean(), ModelCoreSpatial::computeEconomicBalances(), Layers::countMyPixels(), LLData::getData(), Pixel::getDoubleValue(), ModelData::getFilenamesByDir(), ModelData::getForData(), Pixel::getPastRegArea(), Pixel::getPathMortality(), ModelData::getProdData(), ModelData::getRegion(), Pixel::getSTData(), ModelCore::initMarketModule(), ModelCoreSpatial::initMarketModule(), Output::initOptimisationLog(), ModelCoreSpatial::loadExogenousForestLayers(), ModelData::loadInput(), Layers::print(), Layers::printBinMap(), Output::printDebugPixelValues(), Output::printDetailedHV(), Output::printOptLog(), Output::printProductData(), ModelCoreSpatial::registerCarbonEvents(), Scheduler::run(), ModelCoreSpatial::runInitPeriod(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), ModelData::setDefaultForData(), ModelData::setDefaultPathogenRules(), ModelData::setDefaultProdData(), ModelData::setDefaultSettings(), ModelData::setForData(), Init::setInitLevel1(), Init::setInitLevel6(), ModelData::setProdData(), ModelData::setScenarioForData(), ModelData::setScenarioPathogenRules(), ModelData::setScenarioProdData(), ModelData::setScenarioSettings(), ModelData::setTimedData(), InputNode::setWorkingFile(), and ModelCoreSpatial::sumRegionalForData().

219  {
220  //ostringstream out;
221  //out<<int_h;
222  //return out.str();
223  char outChar[24];
224  snprintf ( outChar, sizeof(outChar), "%d", int_h );
225  return string(outChar);
226 }

Here is the caller graph for this function:

vector< string > i2s ( const vector< int > &  int_h) const

integer to string conversion (vector)

Definition at line 281 of file BaseClass.cpp.

281  {
282  vector <string> valuesAsString;
283  for (uint i=0;i<int_h.size();i++){
284  valuesAsString.push_back(i2s(int_h[i]));
285  }
286  return valuesAsString;
287 }
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
void incrMapValue ( map< K, V > &  mymap,
const K &  key,
const V &  value,
const int &  error_level = MSG_CRITICAL_ERROR 
)
inline

Increments a value stored in a map of the specified value, given the key.

Definition at line 312 of file BaseClass.h.

Referenced by Carbon::addSavedEmissions(), and ModelCoreSpatial::runManagementModule().

312  {
313  typename map<K, V>::iterator p;
314  p=mymap.find(key);
315  if(p != mymap.end()) {
316  p->second = p->second + value;
317  return;
318  }
319  else {
320  msgOut(error_level, "Error in finding a value in a map (no value found)");
321  }
322  }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50

Here is the caller graph for this function:

void incrOrAddMapValue ( map< K, V > &  mymap,
const K &  key,
const V &  value 
)
inline

Increments a value stored in a map of the specified value, given the key.

Definition at line 325 of file BaseClass.h.

Referenced by Carbon::registerDeathBiomass(), Carbon::registerHarvesting(), and ModelCoreSpatial::sumRegionalForData().

325  {
326  typename map<K, V>::iterator p;
327  p=mymap.find(key);
328  if(p != mymap.end()) {
329  // We found the key, we gonna add the value..
330  p->second = p->second + value;
331  return;
332  }
333  else {
334  // We didn't find the key, we gonna add it together with the value
335  pair<K,V> myPair(key,value);
336  mymap.insert(myPair);
337  }
338  }

Here is the caller graph for this function:

bool inVector ( const K &  element,
const vector< K > &  v 
)
inline

Definition at line 429 of file BaseClass.h.

Referenced by ModelData::getForTypeParents().

429  {
430  for(unsigned int i=0; i<v.size(); i++){
431  if(v[i]== element) return true;
432  }
433  return false;
434  }

Here is the caller graph for this function:

void msgOut ( const int &  msgCode_h,
const string &  msg_h,
const bool &  refreshGUI_h = true 
) const

Overloaded function to print the output log.

Overloaded method for the output log:

Parameters
msgCode_hMSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR, MSG_CRITICAL_ERROR
msg_hmessage text (string)
refreshGUI_huse this call to "ping" the GUI (optional, default=true)

Definition at line 50 of file BaseClass.cpp.

Referenced by Layers::addLegendItem(), Layers::addLegendItems(), Carbon::addSavedEmissions(), ModelData::addSetting(), ModelData::applyOverrides(), ModelCoreSpatial::assignSpMultiplierPropToVols(), ModelCoreSpatial::cacheDynamicSettings(), ModelCoreSpatial::cachePixelExogenousData(), ModelCore::cacheSettings(), ModelCoreSpatial::cacheSettings(), Pixel::changeValue(), LLData::clean(), Output::cleanScenario(), ModelCore::computeCumulativeData(), ModelCoreSpatial::computeCumulativeData(), ModelCore::computeInventary(), ModelCoreSpatial::computeInventary(), Layers::countMyPixels(), ModelData::delDir(), Layers::filterExogenousDataset(), ModelRegion::getArea(), ModelData::getBaseData(), InputNode::getBoolContent(), Carbon::getCumSavedEmissions(), LLData::getData(), InputNode::getDoubleAttributeByName(), Pixel::getDoubleValue(), ModelData::getFilenamesByDir(), ModelData::getForData(), ModelData::getForType(), ModelData::getForTypeCounter(), ModelData::getForTypeParentId(), InputNode::getIntAttributeByName(), ModelData::getMaxYearUsableDeathTimber(), Pixel::getMyRegion(), InputNode::getNodeByName(), InputNode::getNodesByName(), Output::getOutputFieldDelimiter(), Pixel::getPastRegArea(), Pixel::getPixelsAtDistLevel(), ModelData::getProdData(), ModelData::getRegion(), ModelData::getScenarioIndex(), Pixel::getSpModifier(), Carbon::getStock(), InputNode::getStringAttributeByName(), ModelData::getTable(), ModelData::getTableFromFile(), ModelData::getTimedData(), ModelRegion::getValue(), ModelData::getVectorBaseData(), Output::initCarbonBalance(), Output::initDebugOutput(), Output::initDebugPixelValues(), Carbon::initialiseDeathBiomassStocks(), Carbon::initialiseProductsStocks(), ModelCoreSpatial::initializePixelArea(), ModelCoreSpatial::initializePixelVolumes(), ModelCore::initMarketModule(), ModelCoreSpatial::initMarketModule(), Output::initOptimisationLog(), Output::initOutputForestData(), Output::initOutputMaps(), Output::initOutputProductData(), ModelData::loadInput(), Layers::print(), Output::printCarbonBalance(), Output::printDebugOutput(), Output::printDebugPixelValues(), Output::printDetailedHV(), Output::printForestData(), Output::printOptLog(), Output::printProductData(), ModelData::regSName2RegId(), ModelCoreSpatial::resetPixelValues(), Scheduler::run(), ModelCore::runBiologicalModule(), ModelCoreSpatial::runBiologicalModule(), ModelCoreSpatial::runInitPeriod(), ModelCore::runManagementModule(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), ModelData::setDefaultForData(), ModelData::setDefaultPathogenRules(), ModelData::setDefaultProdData(), ModelData::setDefaultProductResourceMatrixLink(), ModelData::setDefaultSettings(), ModelData::setForData(), Init::setInitLevel(), Init::setInitLevel1(), Init::setInitLevel6(), Pixel::setPastRegArea(), ModelData::setProdData(), ModelData::setReclassificationRules(), ModelData::setScenarioData(), ModelData::setScenarioSettings(), ModelData::setTimedData(), InputNode::setWorkingFile(), ModelCoreSpatial::sumRegionalForData(), Pixel::swap(), ModelData::unpackKeyForData(), ModelData::unpackKeyProdData(), ModelCore::updateMapAreas(), and ModelCoreSpatial::updateMapAreas().

50  {
51 
52  msgOut2(msgCode_h, msg_h, refreshGUI_h);
53 
54 }
void msgOut2(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h) const
Do the job of the overloaded functions.
Definition: BaseClass.cpp:88
void msgOut ( const int &  msgCode_h,
const int &  msg_h,
const bool &  refreshGUI_h = true 
) const

Overloaded function to print the output log.

Overloaded method for the output log:

Parameters
msgCode_hMSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR, MSG_CRITICAL_ERROR
msg_hmessage text (int)
refreshGUI_huse this call to "ping" the GUI (optional, default=true)

Definition at line 65 of file BaseClass.cpp.

65  {
66  msgOut2(msgCode_h, i2s(msg_h), refreshGUI_h);
67 }
string i2s(const int &int_h) const
integer to string conversion
Definition: BaseClass.cpp:219
void msgOut2(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h) const
Do the job of the overloaded functions.
Definition: BaseClass.cpp:88
void msgOut ( const int &  msgCode_h,
const double &  msg_h,
const bool &  refreshGUI_h = true 
) const

Overloaded function to print the output log.

Overloaded method for the output log:

Parameters
msgCode_hMSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR, MSG_CRITICAL_ERROR
msg_hmessage text (double)
refreshGUI_huse this call to "ping" the GUI (optional, default=true)

Definition at line 78 of file BaseClass.cpp.

78  {
79  msgOut2(msgCode_h, d2s(msg_h), refreshGUI_h);
80 
81 }
string d2s(const double &double_h) const
double to string conversion
Definition: BaseClass.cpp:229
void msgOut2(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h) const
Do the job of the overloaded functions.
Definition: BaseClass.cpp:88
void msgOut2 ( const int &  msgCode_h,
const string &  msg_h,
const bool &  refreshGUI_h 
) const
private

Do the job of the overloaded functions.

Convenient (private) function to actually do the job of the overloaded functions

Definition at line 88 of file BaseClass.cpp.

88  {
89 
90  string prefix;
91  switch (msgCode_h){
92  case MSG_NO_MSG:
93  return;
94  case MSG_DEBUG:
95  prefix="*DEBUG: ";
96  break;
97  case MSG_INFO:
98  prefix="**INFO: ";
99  break;
100  case MSG_WARNING:
101  prefix="**WARNING: ";
102  break;
103  case MSG_ERROR:
104  prefix="***ERROR: ";
105  break;
106  case MSG_CRITICAL_ERROR:
107  prefix="****CRITICAL ERROR: ";
108  break;
109  default:
110  cerr<<"I got an unknow error code: "<<msgCode_h<<" ("<<msg_h<<")"<<endl;
111  exit(EXIT_FAILURE);
112  }
113 
114  string message = prefix+msg_h;
115  if (MTHREAD && MTHREAD->usingGUI()){
116  MTHREAD->msgOut(msgCode_h, message);
117  }
118  else {
119  string totalMsg = prefix+msg_h;
120  cout<< totalMsg <<endl;
121  }
122 
123  if(refreshGUI_h) {refreshGUI();}
124 
125  //if(msgCode_h==MSG_CRITICAL_ERROR){
126  // if (MTHREAD && MTHREAD->usingGUI()){
127  // throw(2);
128  // }
129  // else {
130  // throw(2);
131  // exit(EXIT_FAILURE);
132  // }
133  //}
134 
135  if(msgCode_h==MSG_CRITICAL_ERROR){ // I can't throw an exception for any case, as code would resume from where it has been caught, not from here..
136  throw(msgCode_h);
137  }
138 
139 }
Print an ERROR message, but don&#39;t stop the model.
Definition: BaseClass.h:61
Do not actually output any message.
Definition: BaseClass.h:57
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
Print an error message and stop the model.
Definition: BaseClass.h:62
Print a debug message, normally filtered out.
Definition: BaseClass.h:58
Print a WARNING message.
Definition: BaseClass.h:60
void refreshGUI() const
Ping to periodically return the control to the GUI.
Definition: BaseClass.cpp:142
Print an INFO message.
Definition: BaseClass.h:59
void msgOut(const int msgCode_h, const string message_h)
double normSample ( const double &  avg,
const double &  stdev,
const double &  minval = NULL,
const double &  maxval = NULL 
) const

Sample from a normal distribution with bounds. Slower (double time, but still you see the diff only after milion of loops).

It doesn't require the normal_distribution to be passed to it, but due to including MTHREAD its definition can't be placed in the header and hence it can not be templated, so it works only with doubles.

Definition at line 330 of file BaseClass.cpp.

330  {
331  if(minval != NULL && maxval != NULL){
332  if (maxval <= minval){
333  msgOut(MSG_CRITICAL_ERROR,"Error in normSample: the maxvalue is lower than the minvalue");
334  }
335  }
336  for(;;){
337  normal_distribution<double> d(avg,stdev);
338  double c = d(*MTHREAD->gen);
339  if( (minval == NULL || c >= minval) && (maxval == NULL || c <= maxval) ){
340  return c;
341  }
342  }
343  return minval;
344 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
std::mt19937 * gen
used in the sampling from normal distribution
Definition: ThreadManager.h:83
K normSample ( normal_distribution< K > &  d,
std::mt19937 &  gen,
const K &  minval = NULL,
const K &  maxval = NULL 
) const
inline

Sample from a normal distribution with bounds. Faster (half time) as the normal_distribution is made only once.

Definition at line 443 of file BaseClass.h.

443  {
444  if(minval != NULL && maxval != NULL){
445  if (maxval <= minval){
446  msgOut(MSG_CRITICAL_ERROR,"Error in normSample: the maxvalue is lower than the minvalue");
447  }
448  }
449  for(;;){
450  K c = d(gen);
451  if( (minval == NULL || c >= minval) && (maxval == NULL || c <= maxval) ){
452  return c;
453  }
454  }
455  return minval;
456  }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
vector<T> positionsToContent ( const vector< T > &  vector_h,
const vector< int > &  positions 
)
inline

Return a vector of content from a vector and a vector of positions (int)

Definition at line 359 of file BaseClass.h.

Referenced by ModelCoreSpatial::computeInventary().

359  {
360  vector <T> toReturn;
361  for(uint i=0; i<positions.size(); i++){
362  toReturn.push_back(vector_h.at(positions[i]));
363  }
364  return toReturn;
365  }

Here is the caller graph for this function:

void refreshGUI ( ) const

Ping to periodically return the control to the GUI.

Definition at line 142 of file BaseClass.cpp.

Referenced by MainProgram::run().

142  {
143  if (MTHREAD && MTHREAD->usingGUI()){
144  MTHREAD->refreshGUI();
145  }
146 }
ThreadManager * MTHREAD
Pointer to the Thread manager.
Definition: BaseClass.h:467

Here is the caller graph for this function:

void resetMapValues ( map< K, V > &  mymap,
const V &  value 
)
inline

Reset all values stored in a map to the specified one.

Definition at line 341 of file BaseClass.h.

Referenced by ModelCoreSpatial::runManagementModule().

341  {
342  typename map<K, V>::iterator p;
343  for(p=mymap.begin(); p!=mymap.end(); p++) {
344  p->second =value;
345  }
346  }

Here is the caller graph for this function:

bool s2b ( const string &  string_h) const

string to bool conversion

Includes conversion checks.

Definition at line 208 of file BaseClass.cpp.

Referenced by ModelData::createRegions(), ModelData::getBoolSetting(), and ModelData::getBoolVectorSetting().

208  {
209  if (string_h == "true" || string_h == "vero" || string_h == "TRUE" || string_h == "VRAI" || string_h == "1" || string_h == "True")
210  return true;
211  else if (string_h == "false" || string_h == "falso" || string_h == "FALSE" || string_h == "FAUX" || string_h == "0" || string_h == "" || string_h == "False")
212  return false;
213 
214  msgOut(MSG_CRITICAL_ERROR,"Conversion string to bool failed. Some problems with the data? (got\""+string_h+"\")");
215  return true;
216 }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62

Here is the caller graph for this function:

vector< bool > s2b ( const vector< string > &  string_h) const

string to bool conversion (vector)

Includes conversion checks.

Definition at line 272 of file BaseClass.cpp.

272  {
273  vector <bool> valuesAsBool;
274  for (uint i=0;i<string_h.size();i++){
275  valuesAsBool.push_back(s2b(string_h[i]));
276  }
277  return valuesAsBool;
278 }
bool s2b(const string &string_h) const
string to bool conversion
Definition: BaseClass.cpp:208
double s2d ( const string &  string_h) const

string to double conversion

Definition at line 171 of file BaseClass.cpp.

Referenced by ModelData::getDoubleSetting(), ModelData::getDoubleVectorSetting(), ModelData::setDefaultForData(), ModelData::setDefaultPathogenRules(), ModelData::setDefaultProdData(), ModelData::setReclassificationRules(), ModelData::setScenarioForData(), ModelData::setScenarioPathogenRules(), and ModelData::setScenarioProdData().

171  {
172  if (string_h == "") return 0.;
173  double valueAsDouble;
174  istringstream totalSString( string_h );
175  totalSString >> valueAsDouble;
176  return valueAsDouble;
177  /*
178  if (string_h == "") return 0.;
179  try {
180  return stod(string_h); // stod want dot as decimal separator in console mode and comma in gui mode. Further the decimal digits left are only 2 !!
181  } catch (...) {
182  if (string_h == "") return 0.;
183  else {
184  msgOut(MSG_CRITICAL_ERROR,"Conversion string to double failed. Some problems with the data? (got\""+string_h+"\")");
185  }
186  }
187  return 0.;
188  */
189 }

Here is the caller graph for this function:

double s2d ( const string &  string_h,
const bool &  replaceComma 
) const

string to double conversion

Includes comma to dot conversion if needed.

Definition at line 194 of file BaseClass.cpp.

194  {
195  if(replaceComma){
196  string valueAsString = string_h;
197  // replace commas with dots. This is not needed when directly reading the input nodes as double, as the Qt function to Double does the same.
198  replace(valueAsString.begin(), valueAsString.end(), ',', '.');
199  return s2d(valueAsString);
200  }
201  return s2d(string_h);
202  msgOut(MSG_CRITICAL_ERROR, "debug me please!");
203  return 0.;
204 }
void msgOut(const int &msgCode_h, const string &msg_h, const bool &refreshGUI_h=true) const
Overloaded function to print the output log.
Definition: BaseClass.cpp:50
Print an error message and stop the model.
Definition: BaseClass.h:62
double s2d(const string &string_h) const
string to double conversion
Definition: BaseClass.cpp:171
vector< double > s2d ( const vector< string > &  string_h,
const bool &  replaceComma = false 
) const

string to double conversion (vector)

Includes comma to dot conversion if needed.

Definition at line 255 of file BaseClass.cpp.

Referenced by s2d().

255  {
256  vector <double> valuesAsDouble;
257  for (uint i=0;i<string_h.size();i++){
258  if(replaceComma){
259  string valueAsString = string_h[i];
260  // replace commas with dots. This is not needed when directly reading the input nodes as double, as the Qt function to Double does the same.
261  replace(valueAsString.begin(), valueAsString.end(), ',', '.');
262  valuesAsDouble.push_back(s2d(valueAsString));
263  } else {
264  valuesAsDouble.push_back(s2d(string_h[i]));
265  }
266  }
267  return valuesAsDouble;
268 }
double s2d(const string &string_h) const
string to double conversion
Definition: BaseClass.cpp:171

Here is the call graph for this function:

Here is the caller graph for this function:

int s2i ( const string &  string_h) const

string to integer conversion

Definition at line 149 of file BaseClass.cpp.

Referenced by ModelData::createRegions(), ModelData::getIntSetting(), ModelData::getIntVectorSetting(), ModelData::setDefaultProductResourceMatrixLink(), ModelData::setDefaultSettings(), ModelData::setForestTypes(), ModelData::setReclassificationRules(), ModelData::setScenarioSettings(), ModelData::unpackKeyForData(), and ModelData::unpackKeyProdData().

149  {
150  if (string_h == "") return 0;
151  int valueAsInteger;
152  stringstream ss(string_h);
153  ss >> valueAsInteger;
154  return valueAsInteger;
155  /*
156  // I can't use stoi as of bug in MinGW
157  try {
158  return stoi(string_h);
159  } catch (...) {
160  if (string_h == "") return 0;
161  else {
162  msgOut(MSG_CRITICAL_ERROR,"Conversion string to integer failed. Some problems with the data? (got\""+string_h+"\")");
163  }
164  }
165  return 0;
166  */
167 
168 }

Here is the caller graph for this function:

vector< int > s2i ( const vector< string > &  string_h) const

string to integer conversion (vector)

Definition at line 245 of file BaseClass.cpp.

245  {
246  vector <int> valuesAsInteger;
247  for (uint i=0;i<string_h.size();i++){
248  valuesAsInteger.push_back(s2i(string_h[i]));
249  }
250  return valuesAsInteger;
251 }
int s2i(const string &string_h) const
string to integer conversion
Definition: BaseClass.cpp:149
T stringTo ( const std::string &  s) const

Definition at line 348 of file BaseClass.cpp.

348  {
349  std::istringstream iss(s);
350  T x;
351  iss >> x;
352  return x;
353 }
void tokenize ( const string &  str,
vector< string > &  tokens,
const string &  delimiter = " " 
) const

Tokenize a string using a delimiter (default is space)

Definition at line 374 of file BaseClass.cpp.

Referenced by Output::cleanScenario().

374  {
375  // Skip delimiters at beginning.
376  string::size_type lastPos = str.find_first_not_of(delimiter, 0);
377  // Find first "non-delimiter".
378  string::size_type pos = str.find_first_of(delimiter, lastPos);
379 
380  while (string::npos != pos || string::npos != lastPos)
381  {
382  // Found a token, add it to the vector.
383  tokens.push_back(str.substr(lastPos, pos - lastPos));
384  // Skip delimiters. Note the "not_of"
385  lastPos = str.find_first_not_of(delimiter, pos);
386  // Find next "non-delimiter"
387  pos = str.find_first_of(delimiter, lastPos);
388  }
389 }

Here is the caller graph for this function:

string toString ( const T &  x) const
std::string toString ( const T &  x) const

Definition at line 322 of file BaseClass.cpp.

322  {
323  std::ostringstream oss;
324  oss << x;
325  return oss.str();
326 }
void untokenize ( string &  str,
vector< string > &  tokens,
const string &  delimiter = " " 
) const

Definition at line 392 of file BaseClass.cpp.

392  {
393  // add initial loken in str is not empty
394  if(str != ""){
395  str += delimiter;
396  }
397  for(int i=0;i<tokens.size();i++){
398  str += tokens[i];
399  // don't add final delimiter
400  if(i != (tokens.size()-1)){
401  str += delimiter;
402  }
403  }
404 }
map<K, V> vectorToMap ( const vector< K > &  keys,
const V &  value = 0.0 
)
inline

Returns a map built using the given vector and the given (scalar) value as keys/values pairs.

Definition at line 349 of file BaseClass.h.

Referenced by ModelCoreSpatial::runManagementModule().

349  {
350  map<K,V> returnMap;
351  for(unsigned int i=0; i<keys.size();i++){
352  pair<K,V> apair(keys[i],value);
353  returnMap.insert(apair);
354  }
355  return returnMap;
356  }

Here is the caller graph for this function:

double vSum ( const vector< double > &  vector_h) const
inline

Definition at line 277 of file BaseClass.h.

277 {return accumulate(vector_h.begin(),vector_h.end(),0.);};
int vSum ( const vector< vector< int > > &  vector_h) const

Definition at line 356 of file BaseClass.cpp.

356  {
357  int toReturn = 0;
358  for(vector < vector<int> >::const_iterator j=vector_h.begin();j!=vector_h.end();++j){
359  toReturn += accumulate(j->begin(),j->end(),0);
360  }
361  return toReturn;
362 }
double vSum ( const vector< vector< double > > &  vector_h) const

Definition at line 365 of file BaseClass.cpp.

365  {
366  double toReturn = 0.0;
367  for(vector < vector<double> >::const_iterator j=vector_h.begin();j!=vector_h.end();++j){
368  toReturn += accumulate(j->begin(),j->end(),0.0);
369  }
370  return toReturn;
371 }

Member Data Documentation

ThreadManager* MTHREAD
protected

Pointer to the Thread manager.

Through this pointer each derived subclass (the vast maiority of those used on FFSM) can "ask" for sending signals to the GUI, like append the log or modify the map.

Definition at line 467 of file BaseClass.h.

Referenced by ModelCoreSpatial::allocateHarvesting(), ModelCoreSpatial::assignSpMultiplierPropToVols(), ModelCoreSpatial::cacheDynamicSettings(), ModelCoreSpatial::cachePixelExogenousData(), ModelCore::cacheSettings(), ModelCoreSpatial::cacheSettings(), Carbon::Carbon(), Pixel::changeValue(), Output::commonInit(), ModelCore::computeCumulativeData(), ModelCoreSpatial::computeCumulativeData(), ModelCoreSpatial::computeEconomicBalances(), ModelCore::computeInventary(), ModelCoreSpatial::computeInventary(), Layers::countMyPixels(), ModelData::createRegions(), ModelData::getAllocableProductIdsFromDeathTimber(), ModelRegion::getArea(), ModelData::getAvailableAliveTimber(), ModelData::getBaseData(), ModelData::getBoolSetting(), ModelData::getBoolVectorSetting(), Layers::getCategory(), Layers::getColor(), ModelData::getDoubleSetting(), Pixel::getDoubleValue(), ModelData::getDoubleVectorSetting(), ModelData::getIntSetting(), ModelData::getIntVectorSetting(), Pixel::getMultiplier(), Output::getOutputFieldDelimiter(), Pixel::getPathMortality(), Pixel::getPixelsAtDistLevel(), ModelData::getRegionIds(), ModelData::getScenarioIndex(), ModelRegion::getSiblings(), Pixel::getSpModifier(), Pixel::getSTData(), Carbon::getStock(), ModelData::getStringSetting(), ModelData::getStringVectorSetting(), ModelData::getTable(), ModelData::getTableFromFile(), ModelData::getTimedData(), ModelCoreSpatial::getVHaByYear(), ModelCore::gfd(), ModelCoreSpatial::gfd(), ModelCore::gpd(), ModelCoreSpatial::gpd(), Carbon::HWP_eol2energy(), Init::Init(), ModelCoreSpatial::initialiseCarbonModule(), Carbon::initialiseDeathBiomassStocks(), ModelCoreSpatial::initialiseDeathTimber(), Carbon::initialiseEmissionCounters(), Carbon::initialiseProductsStocks(), ModelCoreSpatial::initializePixelArea(), ModelCoreSpatial::initializePixelVolumes(), Output::initOutputForestData(), Layers::Layers(), LLData::LLData(), ModelCoreSpatial::loadExogenousForestLayers(), ModelData::loadInput(), MainProgram::MainProgram(), ModelCore::ModelCore(), ModelCoreSpatial::ModelCoreSpatial(), ModelData::ModelData(), ModelRegion::ModelRegion(), Output::Output(), Pixel::Pixel(), Output::print(), Layers::print(), Layers::printBinMap(), Output::printCarbonBalance(), Output::printDebugOutput(), Output::printDebugPixelValues(), Output::printDetailedHV(), Output::printFinalOutput(), Output::printForestData(), Output::printMaps(), Output::printOptLog(), Output::printProductData(), Layers::randomShuffle(), ModelData::regId2RegSName(), ModelCoreSpatial::registerCarbonEvents(), Carbon::registerDeathBiomass(), Carbon::registerHarvesting(), Carbon::registerProducts(), Carbon::registerTransports(), ModelData::regSName2RegId(), ModelCoreSpatial::resetPixelValues(), Scheduler::run(), MainProgram::run(), ModelCore::runBiologicalModule(), ModelCoreSpatial::runBiologicalModule(), ModelCore::runInitPeriod(), ModelCoreSpatial::runInitPeriod(), ModelCore::runManagementModule(), ModelCoreSpatial::runManagementModule(), ModelCore::runMarketModule(), ModelCoreSpatial::runMarketModule(), ModelCore::runSimulationYear(), ModelCoreSpatial::runSimulationYear(), Scheduler::Scheduler(), ModelData::setDefaultSettings(), Init::setInitLevel1(), Init::setInitLevel3(), Init::setInitLevel5(), Init::setInitLevel6(), ModelRegion::setMyPixels(), ModelData::setOutputDirectory(), ModelData::setScenarioData(), ModelData::setScenarioSettings(), ModelData::setTimedData(), ModelCore::sfd(), ModelCoreSpatial::sfd(), ModelCore::spd(), ModelCoreSpatial::spd(), ModelCoreSpatial::sumRegionalForData(), ModelCore::updateMapAreas(), ModelCoreSpatial::updateMapAreas(), and ModelCoreSpatial::updateOtherMapData().


The documentation for this class was generated from the following files: