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 ( )
735 : LifeCycleEvent("save_stats",""), _service(0), _occurrence(0)
736 {
738 
740 
741  add_parameter("stat",STR,true,false,0,0);
742 
743  add_parameter("stat_log_time",INT,true,false,0,0,updater);
744 
745  add_parameter("stat_dir",STR,false,false,0,0);
746 
747  add_parameter("stat_output_compact",BOOL,false,false,0,0);
748 
749  add_parameter("stat_output_CSV",BOOL,false,false,0,0);
750 
751  add_parameter("stat_output_width",INT,false,false,0,0);
752 
753  add_parameter("stat_output_precision",INT,false,false,0,0);
754 
755  add_parameter("stat_output_no_means",BOOL,false,false,0,0);
756 
758 }
unsigned int _occurrence
Definition: servicenotifiers.h:188
StatServices * _service
Definition: servicenotifiers.h:186
bool dummyUpdate()
Definition: servicenotifiers.h:202
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
198 { }

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_StatServiceNotifier::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

214 {return 0;}

◆ clone()

virtual LCE_StatServiceNotifier* LCE_StatServiceNotifier::clone ( )
inlinevirtual

Implements LifeCycleEvent.

207 {return new LCE_StatServiceNotifier();}
LCE_StatServiceNotifier()
Definition: servicenotifiers.cc:734

References LCE_StatServiceNotifier().

◆ dummyUpdate()

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

Referenced by LCE_StatServiceNotifier().

◆ execute()

void LCE_StatServiceNotifier::execute ( )
virtual

Implements LifeCycleEvent.

880 {
881 #ifdef _DEBUG_
882  message("LCE_StatServiceNotifier::execute (occurrence %i)\n",_service->getOccurrence());
883 #endif
884  _service->notify();
885 }
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
200 {return _fileHandler;}
LCE_StatFH _fileHandler
Definition: servicenotifiers.h:192

References _fileHandler.

◆ loadFileServices()

virtual void LCE_StatServiceNotifier::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

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

860 {
861 // _service = loader; //already set in cstor
862 
864 
865  if(!get_paramset()->isSet())
866  error("LCE_StatServiceNotifier::loadStatServices:stat params are not set!\n");
867 
868  loader->setStatOptions(_arg); //Occurrence has been set previously
869 
870  if ( _paramSet->isSet("stat_output_no_means") )
871  loader->cancelPrintAverages();
872  else
873  loader->doPrintAverages();
874 
875 }
void set_statService(StatServices *srv)
Definition: servicenotifiers.h:170
string _arg
Definition: servicenotifiers.h:190
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:79

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.

213 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_StatServiceNotifier::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

215 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

212 {return false;}

◆ setOccurence()

bool LCE_StatServiceNotifier::setOccurence ( )
807 {
808  map<unsigned int, unsigned int> atTimes;
809 
810  Param* logtime = _paramSet->get_param("stat_log_time");
811 
812 
813  if (!(logtime->isMatrix() || logtime->isTemporal())) {
814 
815  _occurrence = (unsigned int)logtime->getValue();
816 
817  atTimes[0] = _occurrence;
818 
819 
820  } else if (logtime->isMatrix()) {
821 
822 
823  //a matrix argument may be used to specify a set of generations
824  //where results will be saved, it is not recursive
825 
826  TMatrix tmp;
827  logtime->getMatrix(&tmp);
828 
829  if (tmp.nrows() > 1) {
830  fatal("parameter \"stat_log_time\" only accepts one-dimensional arrays.\n");
831  return false;
832  }
833 
834  for (unsigned int i = 0; i < tmp.ncols(); ++i)
835  atTimes[ tmp.get(0, i) ] = 0; //zero is used to indicate no recursivity
836 
837 
838  } else if (logtime->isTemporal()) {
839 
840 
841  //the occurence time changes during the course of a replicate
842  //get the temporal args:
843 
844  deque< unsigned int > tempoDates = logtime->getUpdatingDates();
845  deque< string > tempoArgs = logtime->getTemporalArgs();
846 
847  for (unsigned int i = 0; i < tempoDates.size(); i++)
848  atTimes[ tempoDates[i] ] = tstring::str2int( tempoArgs[i] );
849 
850  }
851 
852  _service->setOccurrences(atTimes);
853 
854  return true;
855 }
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:667
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:100

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.

763 {
764  _arg = _paramSet->getArg("stat");
765 
766  setOccurence();
767 
768  _dir = _paramSet->getArg("stat_dir");
769 
770  _fileHandler.set(true, false, 1,
771  SIMenv::getGenerations(), //this is when data is written
772  this->get_rank(),
773  _dir);
774 
775  //output format:
776  bool is_compact = false;
777  if (_paramSet->isSet("stat_output_compact")) {
778 
780  is_compact = true;
781 
782  } else if (_paramSet->isSet("stat_output_CSV")) {
783 
786  is_compact = true;
787 
788  } else {
789 
791 
792  }
793 
794  if (_paramSet->isSet("stat_output_width") && !is_compact) {
795  _service->setFieldWidth((unsigned int)_paramSet->getValue("stat_output_width"));
796  }
797 
798  if (_paramSet->isSet("stat_output_precision")) {
799  _service->setFieldPrecision((unsigned int)_paramSet->getValue("stat_output_precision"));
800  }
801  return true;
802 }
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:197
string _dir
Definition: servicenotifiers.h:190
bool setOccurence()
Definition: servicenotifiers.cc:806
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