Nemo  2.3.56
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 ( )
201: LifeCycleEvent("save_stats",""), _service(0), _occurrence(0)
202{
204
206
207 add_parameter("stat",STR,true,false,0,0);
208
209 add_parameter("stat_log_time",INT,true,false,0,0,updater);
210
211 add_parameter("stat_dir",STR,false,false,0,0);
212
213 add_parameter("stat_output_compact",BOOL,false,false,0,0);
214
215 add_parameter("stat_output_CSV",BOOL,false,false,0,0);
216
217 add_parameter("stat_output_width",INT,false,false,0,0);
218
219 add_parameter("stat_output_precision",INT,false,false,0,0);
220
221 add_parameter("stat_output_no_means",BOOL,false,false,0,0);
222
224}
unsigned int _occurrence
Definition: servicenotifiers.h:165
StatServices * _service
Definition: servicenotifiers.h:163
bool dummyUpdate()
Definition: servicenotifiers.h:179
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
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().

+ Here is the caller graph for this function:

◆ ~LCE_StatServiceNotifier()

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_StatServiceNotifier::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

191{return 0;}

◆ clone()

virtual LCE_StatServiceNotifier * LCE_StatServiceNotifier::clone ( )
inlinevirtual

Implements LifeCycleEvent.

184{return new LCE_StatServiceNotifier();}
LCE_StatServiceNotifier()
Definition: servicenotifiers.cc:200

References LCE_StatServiceNotifier().

◆ dummyUpdate()

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

Referenced by LCE_StatServiceNotifier().

+ Here is the caller graph for this function:

◆ execute()

void LCE_StatServiceNotifier::execute ( )
virtual

Implements LifeCycleEvent.

346{
347#ifdef _DEBUG_
348 message("LCE_StatServiceNotifier::execute (occurrence %i)\n",_service->getOccurrence());
349#endif
350 _service->notify();
351}
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
177{return _fileHandler;}
LCE_StatFH _fileHandler
Definition: servicenotifiers.h:169

References _fileHandler.

◆ loadFileServices()

virtual void LCE_StatServiceNotifier::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

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

References _fileHandler, and FileServices::attach().

◆ loadStatServices()

void LCE_StatServiceNotifier::loadStatServices ( StatServices loader)
virtual

Implements SimComponent.

326{
327// _service = loader; //already set in cstor
328
330
331 if(!get_paramset()->isSet())
332 error("LCE_StatServiceNotifier::loadStatServices:stat params are not set!\n");
333
334 loader->setStatOptions(_arg); //Occurrence has been set previously
335
336 if ( _paramSet->isSet("stat_output_no_means") )
337 loader->cancelPrintAverages();
338 else
339 loader->doPrintAverages();
340
341}
void set_statService(StatServices *srv)
Definition: servicenotifiers.h:147
string _arg
Definition: servicenotifiers.h:167
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.

190{return 0;}

◆ requiredAgeClass()

virtual age_t LCE_StatServiceNotifier::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

192{return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

189{return false;}

◆ setOccurence()

bool LCE_StatServiceNotifier::setOccurence ( )
273{
274 map<unsigned int, unsigned int> atTimes;
275
276 Param* logtime = _paramSet->get_param("stat_log_time");
277
278
279 if (!(logtime->isMatrix() || logtime->isTemporal())) {
280
281 _occurrence = (unsigned int)logtime->getValue();
282
283 atTimes[0] = _occurrence;
284
285
286 } else if (logtime->isMatrix()) {
287
288
289 //a matrix argument may be used to specify a set of generations
290 //where results will be saved, it is not recursive
291
292 TMatrix tmp;
293 logtime->getMatrix(&tmp);
294
295 if (tmp.nrows() > 1) {
296 fatal("parameter \"stat_log_time\" only accepts one-dimensional arrays.\n");
297 return false;
298 }
299
300 for (unsigned int i = 0; i < tmp.ncols(); ++i)
301 atTimes[ tmp.get(0, i) ] = 0; //zero is used to indicate no recursivity
302
303
304 } else if (logtime->isTemporal()) {
305
306
307 //the occurence time changes during the course of a replicate
308 //get the temporal args:
309
310 deque< unsigned int > tempoDates = logtime->getUpdatingDates();
311 deque< string > tempoArgs = logtime->getTemporalArgs();
312
313 for (unsigned int i = 0; i < tempoDates.size(); i++)
314 atTimes[ tempoDates[i] ] = tstring::str2int( tempoArgs[i] );
315
316 }
317
318 _service->setOccurrences(atTimes);
319
320 return true;
321}
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:637
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:347
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:96
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:357
deque< string > getTemporalArgs()
Definition: param.cc:109
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:49
unsigned int ncols()
Definition: tmatrix.h:170
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:147
unsigned int nrows()
Definition: tmatrix.h:167
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().

+ Here is the caller graph for this function:

◆ setParameters()

bool LCE_StatServiceNotifier::setParameters ( )
virtual

Implements SimComponent.

229{
230 _arg = _paramSet->getArg("stat");
231
232 setOccurence();
233
234 _dir = _paramSet->getArg("stat_dir");
235
236 _fileHandler.set(true, false, 1,
237 SIMenv::getGenerations(), //this is when data is written
238 this->get_rank(),
239 _dir);
240
241 //output format:
242 bool is_compact = false;
243 if (_paramSet->isSet("stat_output_compact")) {
244
246 is_compact = true;
247
248 } else if (_paramSet->isSet("stat_output_CSV")) {
249
252 is_compact = true;
253
254 } else {
255
257
258 }
259
260 if (_paramSet->isSet("stat_output_width") && !is_compact) {
261 _service->setFieldWidth((unsigned int)_paramSet->getValue("stat_output_width"));
262 }
263
264 if (_paramSet->isSet("stat_output_precision")) {
265 _service->setFieldPrecision((unsigned int)_paramSet->getValue("stat_output_precision"));
266 }
267 return true;
268}
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:167
bool setOccurence()
Definition: servicenotifiers.cc:272
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.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR