Nemo  2.4.1
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 ( )
892 : LifeCycleEvent("save_stats",""), _service(0), _occurrence(0)
893 {
895 
897 
898  add_parameter("stat",STR,true,false,0,0);
899 
900  add_parameter("stat_log_time",INT,true,false,0,0,updater);
901 
902  add_parameter("stat_dir",STR,false,false,0,0);
903 
904  add_parameter("stat_output_compact",BOOL,false,false,0,0);
905 
906  add_parameter("stat_output_CSV",BOOL,false,false,0,0);
907 
908  add_parameter("stat_output_width",INT,false,false,0,0);
909 
910  add_parameter("stat_output_precision",INT,false,false,0,0);
911 
912  add_parameter("stat_output_no_means",BOOL,false,false,0,0);
913 
915 }
unsigned int _occurrence
Definition: servicenotifiers.h:187
StatServices * _service
Definition: servicenotifiers.h:185
bool dummyUpdate()
Definition: servicenotifiers.h:201
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:97
Implementation of the ParamUpdaterBase interface.
Definition: param.h:372
static SimRunner * MainSim
Definition: simenv.h:41
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
StatServices * get_StatServices()
Returns the StatServices.
Definition: simulation.h:155
@ BOOL
Definition: types.h:77
@ STR
Definition: types.h:77
@ INT
Definition: types.h:77

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
197 { }

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_StatServiceNotifier::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

213 {return 0;}

◆ clone()

virtual LCE_StatServiceNotifier* LCE_StatServiceNotifier::clone ( )
inlinevirtual

Implements LifeCycleEvent.

206 {return new LCE_StatServiceNotifier();}
LCE_StatServiceNotifier()
Definition: servicenotifiers.cc:891

References LCE_StatServiceNotifier().

◆ dummyUpdate()

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

Referenced by LCE_StatServiceNotifier().

+ Here is the caller graph for this function:

◆ execute()

void LCE_StatServiceNotifier::execute ( )
virtual

Implements LifeCycleEvent.

1037 {
1038 #ifdef _DEBUG_
1039  message("LCE_StatServiceNotifier::execute (occurrence %i)\n",_service->getOccurrence());
1040 #endif
1041  _service->notify();
1042 }
virtual void notify()
Definition: statservices.cc:187
unsigned int getOccurrence()
Definition: statservices.h:117
void message(const char *message,...)
Definition: output.cc:39

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

◆ getFH()

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

References _fileHandler.

◆ loadFileServices()

virtual void LCE_StatServiceNotifier::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

209 {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.

1017 {
1018 // _service = loader; //already set in cstor
1019 
1020  _fileHandler.set_statService(loader);
1021 
1022  if(!get_paramset()->isSet())
1023  error("LCE_StatServiceNotifier::loadStatServices:stat params are not set!\n");
1024 
1025  loader->setStatOptions(_arg); //Occurrence has been set previously
1026 
1027  if ( _paramSet->isSet("stat_output_no_means") )
1028  loader->cancelPrintAverages();
1029  else
1030  loader->doPrintAverages();
1031 
1032 }
void set_statService(StatServices *srv)
Definition: servicenotifiers.h:169
string _arg
Definition: servicenotifiers.h:189
bool isSet()
Accessor to the status flag.
Definition: param.h:297
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:107
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:47
void cancelPrintAverages()
Definition: statservices.h:142
void doPrintAverages()
Definition: statservices.h:141
void setStatOptions(string &str)
Definition: statservices.h:112
int error(const char *str,...)
Definition: output.cc:78

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.

212 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_StatServiceNotifier::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

214 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

211 {return false;}

◆ setOccurence()

bool LCE_StatServiceNotifier::setOccurence ( )
964 {
965  map<unsigned int, unsigned int> atTimes;
966 
967  Param* logtime = _paramSet->get_param("stat_log_time");
968 
969 
970  if (!(logtime->isMatrix() || logtime->isTemporal())) {
971 
972  _occurrence = (unsigned int)logtime->getValue();
973 
974  atTimes[0] = _occurrence;
975 
976 
977  } else if (logtime->isMatrix()) {
978 
979 
980  //a matrix argument may be used to specify a set of generations
981  //where results will be saved, it is not recursive
982 
983  TMatrix tmp;
984  logtime->getMatrix(&tmp);
985 
986  if (tmp.nrows() > 1) {
987  fatal("parameter \"stat_log_time\" only accepts one-dimensional arrays.\n");
988  return false;
989  }
990 
991  for (unsigned int i = 0; i < tmp.ncols(); ++i)
992  atTimes[ tmp.get(0, i) ] = 0; //zero is used to indicate no recursivity
993 
994 
995  } else if (logtime->isTemporal()) {
996 
997 
998  //the occurence time changes during the course of a replicate
999  //get the temporal args:
1000 
1001  deque< unsigned int > tempoDates = logtime->getUpdatingDates();
1002  deque< string > tempoArgs = logtime->getTemporalArgs();
1003 
1004  for (unsigned int i = 0; i < tempoDates.size(); i++)
1005  atTimes[ tempoDates[i] ] = tstring::str2int( tempoArgs[i] );
1006 
1007  }
1008 
1009  _service->setOccurrences(atTimes);
1010 
1011  return true;
1012 }
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:692
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
double getValue()
Returns the argument value according to its type.
Definition: param.cc:387
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:181
bool isTemporal()
Definition: param.h:150
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:397
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:120
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
unsigned int ncols() const
Definition: tmatrix.h:215
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:192
unsigned int nrows() const
Definition: tmatrix.h:212
static int str2int(const string &str)
Converts a string into an integer.
Definition: tstring.h:72
void fatal(const char *str,...)
Definition: output.cc:99

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.

920 {
921  _arg = _paramSet->getArg("stat");
922 
923  setOccurence();
924 
925  _dir = _paramSet->getArg("stat_dir");
926 
927  _fileHandler.set(true, false, 1,
928  SIMenv::getGenerations(), //this is when data is written
929  this->get_rank(),
930  _dir);
931 
932  //output format:
933  bool is_compact = false;
934  if (_paramSet->isSet("stat_output_compact")) {
935 
937  is_compact = true;
938 
939  } else if (_paramSet->isSet("stat_output_CSV")) {
940 
943  is_compact = true;
944 
945  } else {
946 
948 
949  }
950 
951  if (_paramSet->isSet("stat_output_width") && !is_compact) {
952  _service->setFieldWidth((unsigned int)_paramSet->getValue("stat_output_width"));
953  }
954 
955  if (_paramSet->isSet("stat_output_precision")) {
956  _service->setFieldPrecision((unsigned int)_paramSet->getValue("stat_output_precision"));
957  }
958  return true;
959 }
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:196
string _dir
Definition: servicenotifiers.h:189
bool setOccurence()
Definition: servicenotifiers.cc:963
virtual int get_rank()
Accessor to the LCE rank in the life cycle.
Definition: lifecycleevent.h:165
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:309
double getValue(string name)
Accessor the parameters value.
Definition: param.h:311
static unsigned int getGenerations()
Definition: simenv.h:60
void setFieldPrecision(unsigned int val)
Definition: statservices.h:156
void setDefaultOutputFormat()
Definition: statservices.h:160
void setFieldSeparator(unsigned char c)
Definition: statservices.h:158
void setFieldWidth(unsigned int val)
Definition: statservices.h:154
void setCompactOutputFormat()
Definition: statservices.h:152

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.1 by  doxygen 1.9.1

Catalogued on GSR