Nemo  2.4.0
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 ( )
734 : LifeCycleEvent("save_stats",""), _service(0), _occurrence(0)
735 {
737 
739 
740  add_parameter("stat",STR,true,false,0,0);
741 
742  add_parameter("stat_log_time",INT,true,false,0,0,updater);
743 
744  add_parameter("stat_dir",STR,false,false,0,0);
745 
746  add_parameter("stat_output_compact",BOOL,false,false,0,0);
747 
748  add_parameter("stat_output_CSV",BOOL,false,false,0,0);
749 
750  add_parameter("stat_output_width",INT,false,false,0,0);
751 
752  add_parameter("stat_output_precision",INT,false,false,0,0);
753 
754  add_parameter("stat_output_no_means",BOOL,false,false,0,0);
755 
757 }
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:362
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:149
@ 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:733

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.

879 {
880 #ifdef _DEBUG_
881  message("LCE_StatServiceNotifier::execute (occurrence %i)\n",_service->getOccurrence());
882 #endif
883  _service->notify();
884 }
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.

859 {
860 // _service = loader; //already set in cstor
861 
863 
864  if(!get_paramset()->isSet())
865  error("LCE_StatServiceNotifier::loadStatServices:stat params are not set!\n");
866 
867  loader->setStatOptions(_arg); //Occurrence has been set previously
868 
869  if ( _paramSet->isSet("stat_output_no_means") )
870  loader->cancelPrintAverages();
871  else
872  loader->doPrintAverages();
873 
874 }
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:287
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 ( )
806 {
807  map<unsigned int, unsigned int> atTimes;
808 
809  Param* logtime = _paramSet->get_param("stat_log_time");
810 
811 
812  if (!(logtime->isMatrix() || logtime->isTemporal())) {
813 
814  _occurrence = (unsigned int)logtime->getValue();
815 
816  atTimes[0] = _occurrence;
817 
818 
819  } else if (logtime->isMatrix()) {
820 
821 
822  //a matrix argument may be used to specify a set of generations
823  //where results will be saved, it is not recursive
824 
825  TMatrix tmp;
826  logtime->getMatrix(&tmp);
827 
828  if (tmp.nrows() > 1) {
829  fatal("parameter \"stat_log_time\" only accepts one-dimensional arrays.\n");
830  return false;
831  }
832 
833  for (unsigned int i = 0; i < tmp.ncols(); ++i)
834  atTimes[ tmp.get(0, i) ] = 0; //zero is used to indicate no recursivity
835 
836 
837  } else if (logtime->isTemporal()) {
838 
839 
840  //the occurence time changes during the course of a replicate
841  //get the temporal args:
842 
843  deque< unsigned int > tempoDates = logtime->getUpdatingDates();
844  deque< string > tempoArgs = logtime->getTemporalArgs();
845 
846  for (unsigned int i = 0; i < tempoDates.size(); i++)
847  atTimes[ tempoDates[i] ] = tstring::str2int( tempoArgs[i] );
848 
849  }
850 
851  _service->setOccurrences(atTimes);
852 
853  return true;
854 }
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:666
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:367
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:171
bool isTemporal()
Definition: param.h:142
deque< unsigned int > getUpdatingDates()
Definition: param.cc:93
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:377
deque< string > getTemporalArgs()
Definition: param.cc:106
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.

762 {
763  _arg = _paramSet->getArg("stat");
764 
765  setOccurence();
766 
767  _dir = _paramSet->getArg("stat_dir");
768 
769  _fileHandler.set(true, false, 1,
770  SIMenv::getGenerations(), //this is when data is written
771  this->get_rank(),
772  _dir);
773 
774  //output format:
775  bool is_compact = false;
776  if (_paramSet->isSet("stat_output_compact")) {
777 
779  is_compact = true;
780 
781  } else if (_paramSet->isSet("stat_output_CSV")) {
782 
785  is_compact = true;
786 
787  } else {
788 
790 
791  }
792 
793  if (_paramSet->isSet("stat_output_width") && !is_compact) {
794  _service->setFieldWidth((unsigned int)_paramSet->getValue("stat_output_width"));
795  }
796 
797  if (_paramSet->isSet("stat_output_precision")) {
798  _service->setFieldPrecision((unsigned int)_paramSet->getValue("stat_output_precision"));
799  }
800  return true;
801 }
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:805
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:299
double getValue(string name)
Accessor the parameters value.
Definition: param.h:301
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.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR