Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCE_StatServiceNotifier Class Reference

Initiates the StatServices' parameters (log time) when registering, calls StatServices::notify() when executing. More...

#include <servicenotifiers.h>

+ Inheritance diagram for LCE_StatServiceNotifier:
+ Collaboration diagram for LCE_StatServiceNotifier:

Public Member Functions

 LCE_StatServiceNotifier ()
 
virtual ~LCE_StatServiceNotifier ()
 
FileHandlergetFH ()
 
bool setOccurence ()
 
bool dummyUpdate ()
 
virtual bool setParameters ()
 
virtual void execute ()
 
virtual LCE_StatServiceNotifierclone ()
 
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
virtual age_t removeAgeClass ()
 
virtual age_t addAgeClass ()
 
virtual age_t requiredAgeClass ()
 
- Public Member Functions inherited from LifeCycleEvent
 LifeCycleEvent (const char *name, const char *trait_link)
 Cstor. More...
 
virtual ~LifeCycleEvent ()
 
virtual void init (Metapop *popPtr)
 Sets the pointer to the current Metapop and the trait link if applicable. More...
 
virtual bool attach_trait (string trait)
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 
virtual void set_event_name (std::string &name)
 Set the name of the event (name of the ParamSet) and add the corresponding parameter to the set. More...
 
virtual void set_event_name (const char *name)
 
virtual string & get_event_name ()
 Accessor to the LCE's name. More...
 
virtual int get_rank ()
 Accessor to the LCE rank in the life cycle. More...
 
virtual void set_pop_ptr (Metapop *popPtr)
 Accessors for the population pointer. More...
 
virtual Metapopget_pop_ptr ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 
virtual bool has_parameter (std::string name)
 Param getter. More...
 

Private Attributes

StatServices_service
 
unsigned int _occurrence
 
string _arg
 
string _dir
 
LCE_StatFH _fileHandler
 

Additional Inherited Members

- Protected Attributes inherited from LifeCycleEvent
std::string _event_name
 The param name to be read in the init file. More...
 
Metapop_popPtr
 The ptr to the current Metapop. More...
 
std::string _LCELinkedTraitType
 The name of the linked trait. More...
 
int _LCELinkedTraitIndex
 The index in the individual's trait table of the linked trait. More...
 
- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 

Detailed Description

Initiates the StatServices' parameters (log time) when registering, calls StatServices::notify() when executing.

Registers the file handler used to save the stats to the '.txt' and '_bygen.txt' files.

Constructor & Destructor Documentation

◆ LCE_StatServiceNotifier()

LCE_StatServiceNotifier::LCE_StatServiceNotifier ( )
211 : LifeCycleEvent("save_stats",""), _service(0), _occurrence(0)
212 {
214 
216 
217  add_parameter("stat",STR,true,false,0,0);
218 
219  add_parameter("stat_log_time",INT,true,false,0,0,updater);
220 
221  add_parameter("stat_dir",STR,false,false,0,0);
222 
223  add_parameter("stat_output_compact",BOOL,false,false,0,0);
224 
225  add_parameter("stat_output_CSV",BOOL,false,false,0,0);
226 
227  add_parameter("stat_output_width",INT,false,false,0,0);
228 
229  add_parameter("stat_output_precision",INT,false,false,0,0);
230 
231  add_parameter("stat_output_no_means",BOOL,false,false,0,0);
232 
234 }
unsigned int _occurrence
Definition: servicenotifiers.h:167
StatServices * _service
Definition: servicenotifiers.h:165
bool dummyUpdate()
Definition: servicenotifiers.h:181
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
Implementation of the ParamUpdaterBase interface.
Definition: param.h:363
static SimRunner * MainSim
Definition: simenv.h:42
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
StatServices * get_StatServices()
Returns the StatServices.
Definition: simulation.h:150
@ BOOL
Definition: types.h:78
@ STR
Definition: types.h:78
@ INT
Definition: types.h:78

References _service, SimComponent::add_parameter(), BOOL, dummyUpdate(), SimRunner::get_StatServices(), INT, SIMenv::MainSim, and STR.

Referenced by clone().

◆ ~LCE_StatServiceNotifier()

virtual LCE_StatServiceNotifier::~LCE_StatServiceNotifier ( )
inlinevirtual
177 { }

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_StatServiceNotifier::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

193 {return 0;}

◆ clone()

virtual LCE_StatServiceNotifier* LCE_StatServiceNotifier::clone ( )
inlinevirtual

Implements LifeCycleEvent.

186 {return new LCE_StatServiceNotifier();}
LCE_StatServiceNotifier()
Definition: servicenotifiers.cc:210

References LCE_StatServiceNotifier().

◆ dummyUpdate()

bool LCE_StatServiceNotifier::dummyUpdate ( )
inline
181 {return true;}

Referenced by LCE_StatServiceNotifier().

◆ execute()

void LCE_StatServiceNotifier::execute ( )
virtual

Implements LifeCycleEvent.

356 {
357 #ifdef _DEBUG_
358  message("LCE_StatServiceNotifier::execute (occurrence %i)\n",_service->getOccurrence());
359 #endif
360  _service->notify();
361 }
virtual void notify()
Definition: statservices.cc:188
unsigned int getOccurrence()
Definition: statservices.h:118
void message(const char *message,...)
Definition: output.cc:40

References _service, StatServices::getOccurrence(), message(), and StatServices::notify().

◆ getFH()

FileHandler& LCE_StatServiceNotifier::getFH ( )
inline
179 {return _fileHandler;}
LCE_StatFH _fileHandler
Definition: servicenotifiers.h:171

References _fileHandler.

◆ loadFileServices()

virtual void LCE_StatServiceNotifier::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

189 {loader->attach(&_fileHandler);}
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:61

References _fileHandler, and FileServices::attach().

◆ loadStatServices()

void LCE_StatServiceNotifier::loadStatServices ( StatServices loader)
virtual

Implements SimComponent.

336 {
337 // _service = loader; //already set in cstor
338 
340 
341  if(!get_paramset()->isSet())
342  error("LCE_StatServiceNotifier::loadStatServices:stat params are not set!\n");
343 
344  loader->setStatOptions(_arg); //Occurrence has been set previously
345 
346  if ( _paramSet->isSet("stat_output_no_means") )
347  loader->cancelPrintAverages();
348  else
349  loader->doPrintAverages();
350 
351 }
void set_statService(StatServices *srv)
Definition: servicenotifiers.h:149
string _arg
Definition: servicenotifiers.h:169
bool isSet()
Accessor to the status flag.
Definition: param.h:288
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:108
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
void cancelPrintAverages()
Definition: statservices.h:143
void doPrintAverages()
Definition: statservices.h:142
void setStatOptions(string &str)
Definition: statservices.h:113
int error(const char *str,...)
Definition: output.cc:77

References _arg, _fileHandler, SimComponent::_paramSet, StatServices::cancelPrintAverages(), StatServices::doPrintAverages(), error(), SimComponent::get_paramset(), ParamSet::isSet(), LCE_StatFH::set_statService(), and StatServices::setStatOptions().

◆ removeAgeClass()

virtual age_t LCE_StatServiceNotifier::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

192 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_StatServiceNotifier::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

194 {return 0;}

◆ resetParameterFromSource()

virtual bool LCE_StatServiceNotifier::resetParameterFromSource ( std::string  param,
SimComponent cmpt 
)
inlinevirtual

Implements SimComponent.

191 {return false;}

◆ setOccurence()

bool LCE_StatServiceNotifier::setOccurence ( )
283 {
284  map<unsigned int, unsigned int> atTimes;
285 
286  Param* logtime = _paramSet->get_param("stat_log_time");
287 
288 
289  if (!(logtime->isMatrix() || logtime->isTemporal())) {
290 
291  _occurrence = (unsigned int)logtime->getValue();
292 
293  atTimes[0] = _occurrence;
294 
295 
296  } else if (logtime->isMatrix()) {
297 
298 
299  //a matrix argument may be used to specify a set of generations
300  //where results will be saved, it is not recursive
301 
302  TMatrix tmp;
303  logtime->getMatrix(&tmp);
304 
305  if (tmp.nrows() > 1) {
306  fatal("parameter \"stat_log_time\" only accepts one-dimensional arrays.\n");
307  return false;
308  }
309 
310  for (unsigned int i = 0; i < tmp.ncols(); ++i)
311  atTimes[ tmp.get(0, i) ] = 0; //zero is used to indicate no recursivity
312 
313 
314  } else if (logtime->isTemporal()) {
315 
316 
317  //the occurence time changes during the course of a replicate
318  //get the temporal args:
319 
320  deque< unsigned int > tempoDates = logtime->getUpdatingDates();
321  deque< string > tempoArgs = logtime->getTemporalArgs();
322 
323  for (unsigned int i = 0; i < tempoDates.size(); i++)
324  atTimes[ tempoDates[i] ] = tstring::str2int( tempoArgs[i] );
325 
326  }
327 
328  _service->setOccurrences(atTimes);
329 
330  return true;
331 }
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:658
This structure stores one parameter, its definition and its string argument.
Definition: param.h:54
double getValue()
Returns the argument value according to its type.
Definition: param.cc:368
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:172
bool isTemporal()
Definition: param.h:143
deque< unsigned int > getUpdatingDates()
Definition: param.cc:94
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:378
deque< string > getTemporalArgs()
Definition: param.cc:107
void setOccurrences(map< unsigned int, unsigned int > timeTable)
Sets the list of generation for which statistics must be recorded during a run.
Definition: statservices.cc:121
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:50
unsigned int ncols() const
Definition: tmatrix.h:216
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:193
unsigned int nrows() const
Definition: tmatrix.h:213
static int str2int(const string &str)
Converts a string into an integer.
Definition: tstring.h:73
void fatal(const char *str,...)
Definition: output.cc:96

References _occurrence, SimComponent::_paramSet, _service, fatal(), TMatrix::get(), ParamSet::get_param(), Param::getMatrix(), Param::getTemporalArgs(), Param::getUpdatingDates(), Param::getValue(), Param::isMatrix(), Param::isTemporal(), TMatrix::ncols(), TMatrix::nrows(), StatServices::setOccurrences(), and tstring::str2int().

Referenced by setParameters().

◆ setParameters()

bool LCE_StatServiceNotifier::setParameters ( )
virtual

Implements SimComponent.

239 {
240  _arg = _paramSet->getArg("stat");
241 
242  setOccurence();
243 
244  _dir = _paramSet->getArg("stat_dir");
245 
246  _fileHandler.set(true, false, 1,
247  SIMenv::getGenerations(), //this is when data is written
248  this->get_rank(),
249  _dir);
250 
251  //output format:
252  bool is_compact = false;
253  if (_paramSet->isSet("stat_output_compact")) {
254 
256  is_compact = true;
257 
258  } else if (_paramSet->isSet("stat_output_CSV")) {
259 
262  is_compact = true;
263 
264  } else {
265 
267 
268  }
269 
270  if (_paramSet->isSet("stat_output_width") && !is_compact) {
271  _service->setFieldWidth((unsigned int)_paramSet->getValue("stat_output_width"));
272  }
273 
274  if (_paramSet->isSet("stat_output_precision")) {
275  _service->setFieldPrecision((unsigned int)_paramSet->getValue("stat_output_precision"));
276  }
277  return true;
278 }
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path)
Sets the hanlder parameters.
Definition: filehandler.h:193
string _dir
Definition: servicenotifiers.h:169
bool setOccurence()
Definition: servicenotifiers.cc:282
virtual int get_rank()
Accessor to the LCE rank in the life cycle.
Definition: lifecycleevent.h:166
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:300
double getValue(string name)
Accessor the parameters value.
Definition: param.h:302
static unsigned int getGenerations()
Definition: simenv.h:61
void setFieldPrecision(unsigned int val)
Definition: statservices.h:157
void setDefaultOutputFormat()
Definition: statservices.h:161
void setFieldSeparator(unsigned char c)
Definition: statservices.h:159
void setFieldWidth(unsigned int val)
Definition: statservices.h:155
void setCompactOutputFormat()
Definition: statservices.h:153

References _arg, _dir, _fileHandler, SimComponent::_paramSet, _service, LifeCycleEvent::get_rank(), ParamSet::getArg(), SIMenv::getGenerations(), ParamSet::getValue(), ParamSet::isSet(), FileHandler::set(), StatServices::setCompactOutputFormat(), StatServices::setDefaultOutputFormat(), StatServices::setFieldPrecision(), StatServices::setFieldSeparator(), StatServices::setFieldWidth(), and setOccurence().

Member Data Documentation

◆ _arg

string LCE_StatServiceNotifier::_arg
private

Referenced by loadStatServices(), and setParameters().

◆ _dir

string LCE_StatServiceNotifier::_dir
private

Referenced by setParameters().

◆ _fileHandler

LCE_StatFH LCE_StatServiceNotifier::_fileHandler
private

◆ _occurrence

unsigned int LCE_StatServiceNotifier::_occurrence
private

Referenced by setOccurence().

◆ _service

StatServices* LCE_StatServiceNotifier::_service
private

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

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR