Nemo  2.3.46
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 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...
 

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 ( )

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

Referenced by clone().

80 : LifeCycleEvent("save_stats",""), _service(0)
81 {
83 
85 
86  add_parameter("stat",STR,true,false,0,0);
87 
88  add_parameter("stat_log_time",INT,true,false,0,0,updater);
89 
90  add_parameter("stat_dir",STR,false,false,0,0);
91 
92  add_parameter("stat_output_compact",BOOL,false,false,0,0);
93 
94  add_parameter("stat_output_CSV",BOOL,false,false,0,0);
95 
96  add_parameter("stat_output_width",INT,false,false,0,0);
97 
98  add_parameter("stat_output_precision",INT,false,false,0,0);
99 
100  add_parameter("stat_output_no_means",BOOL,false,false,0,0);
101 
103 }
StatServices * _service
Definition: servicenotifiers.h:128
Implementation of the ParamUpdaterBase interface.
Definition: param.h:348
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
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:148
bool dummyUpdate()
Definition: servicenotifiers.h:144
Definition: types.h:78
Definition: types.h:78
Definition: types.h:78
virtual LCE_StatServiceNotifier::~LCE_StatServiceNotifier ( )
inlinevirtual
140 { }

Member Function Documentation

virtual age_t LCE_StatServiceNotifier::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

155 {return 0;}
virtual LCE_StatServiceNotifier* LCE_StatServiceNotifier::clone ( )
inlinevirtual

Implements LifeCycleEvent.

References LCE_StatServiceNotifier().

149 {return new LCE_StatServiceNotifier();}
LCE_StatServiceNotifier()
Definition: servicenotifiers.cc:79
bool LCE_StatServiceNotifier::dummyUpdate ( )
inline

Referenced by LCE_StatServiceNotifier().

144 {return true;}
void LCE_StatServiceNotifier::execute ( )
virtual

Implements LifeCycleEvent.

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

225 {
226 #ifdef _DEBUG_
227  message("LCE_StatServiceNotifier::execute (occurrence %i)\n",_service->getOccurrence());
228 #endif
229  _service->notify();
230 }
void message(const char *message,...)
Definition: output.cc:40
StatServices * _service
Definition: servicenotifiers.h:128
virtual void notify()
Definition: statservices.cc:188
unsigned int getOccurrence()
Definition: statservices.h:118
FileHandler& LCE_StatServiceNotifier::getFH ( )
inline

References _fileHandler.

142 {return _fileHandler;}
LCE_StatFH _fileHandler
Definition: servicenotifiers.h:134
virtual void LCE_StatServiceNotifier::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

References FileServices::attach().

152 {loader->attach(&_fileHandler);}
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:57
LCE_StatFH _fileHandler
Definition: servicenotifiers.h:134
void LCE_StatServiceNotifier::loadStatServices ( StatServices loader)
virtual

Implements SimComponent.

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

205 {
206 // _service = loader; //already set in cstor
207 
209 
210  if(!get_paramset()->isSet())
211  error("LCE_StatServiceNotifier::loadStatServices:stat params are not set!\n");
212 
213  loader->setStatOptions(_arg); //occurence has been set previously
214 
215  if ( _paramSet->isSet("stat_output_no_means") )
216  loader->cancelPrintAverages();
217  else
218  loader->doPrintAverages();
219 
220 }
void setStatOptions(string &str)
Definition: statservices.h:113
void doPrintAverages()
Definition: statservices.h:142
LCE_StatFH _fileHandler
Definition: servicenotifiers.h:134
int error(const char *str,...)
Definition: output.cc:73
void cancelPrintAverages()
Definition: statservices.h:143
void set_statService(StatServices *srv)
Definition: servicenotifiers.h:112
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
string _arg
Definition: servicenotifiers.h:132
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:108
bool isSet()
Accessor to the status flag.
Definition: param.h:273
virtual age_t LCE_StatServiceNotifier::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

154 {return 0;}
virtual age_t LCE_StatServiceNotifier::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

156 {return 0;}
bool LCE_StatServiceNotifier::setOccurence ( )

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().

152 {
153  map<unsigned int, unsigned int> atTimes;
154 
155  Param* logtime = _paramSet->get_param("stat_log_time");
156 
157 
158  if (!(logtime->isMatrix() || logtime->isTemporal())) {
159 
160  _occurrence = (unsigned int)logtime->getValue();
161 
162  atTimes[0] = _occurrence;
163 
164 
165  } else if (logtime->isMatrix()) {
166 
167 
168  //a matrix argument may be used to specify a set of generations
169  //where results will be saved, it is not recursive
170 
171  TMatrix tmp;
172  logtime->getMatrix(&tmp);
173 
174  if (tmp.nrows() > 1) {
175  fatal("parameter \"stat_log_time\" only accepts one-dimensional arrays.\n");
176  return false;
177  }
178 
179  for (unsigned int i = 0; i < tmp.ncols(); ++i)
180  atTimes[ tmp.get(0, i) ] = 0; //zero is used to indicate no recursivity
181 
182 
183  } else if (logtime->isTemporal()) {
184 
185 
186  //the occurence time changes during the course of a replicate
187  //get the temporal args:
188 
189  deque< unsigned int > tempoDates = logtime->getUpdatingDates();
190  deque< string > tempoArgs = logtime->getTemporalArgs();
191 
192  for (unsigned int i = 0; i < tempoDates.size(); i++)
193  atTimes[ tempoDates[i] ] = tstring::str2int( tempoArgs[i] );
194 
195  }
196 
197  _service->setOccurrences(atTimes);
198 
199  return true;
200 }
static int str2int(const string &str)
Converts a string into an integer.
Definition: tstring.h:73
StatServices * _service
Definition: servicenotifiers.h:128
unsigned int ncols()
Definition: tmatrix.h:143
double getValue()
Returns the argument value according to its type.
Definition: param.cc:319
deque< string > getTemporalArgs()
Definition: param.cc:97
deque< unsigned int > getUpdatingDates()
Definition: param.cc:84
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:329
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
unsigned int _occurrence
Definition: servicenotifiers.h:130
void fatal(const char *str,...)
Definition: output.cc:90
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:170
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
bool isTemporal()
Definition: param.h:141
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:597
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
unsigned int nrows()
Definition: tmatrix.h:140
bool LCE_StatServiceNotifier::setParameters ( )
virtual

Implements SimComponent.

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().

108 {
109  _arg = _paramSet->getArg("stat");
110 
111  setOccurence();
112 
113  _dir = _paramSet->getArg("stat_dir");
114 
115  _fileHandler.set(true, false, 1,
116  SIMenv::getGenerations(), //this is when data is written
117  this->get_rank(),
118  _dir);
119 
120  //output format:
121  bool is_compact = false;
122  if (_paramSet->isSet("stat_output_compact")) {
123 
125  is_compact = true;
126 
127  } else if (_paramSet->isSet("stat_output_CSV")) {
128 
131  is_compact = true;
132 
133  } else {
134 
136 
137  }
138 
139  if (_paramSet->isSet("stat_output_width") && !is_compact) {
140  _service->setFieldWidth((unsigned int)_paramSet->getValue("stat_output_width"));
141  }
142 
143  if (_paramSet->isSet("stat_output_precision")) {
144  _service->setFieldPrecision((unsigned int)_paramSet->getValue("stat_output_precision"));
145  }
146  return true;
147 }
StatServices * _service
Definition: servicenotifiers.h:128
string _dir
Definition: servicenotifiers.h:132
void setFieldSeparator(unsigned char c)
Definition: statservices.h:159
void setDefaultOutputFormat()
Definition: statservices.h:161
LCE_StatFH _fileHandler
Definition: servicenotifiers.h:134
void setFieldWidth(unsigned int val)
Definition: statservices.h:155
bool setOccurence()
Definition: servicenotifiers.cc:151
void setCompactOutputFormat()
Definition: statservices.h:153
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
string _arg
Definition: servicenotifiers.h:132
double getValue(string name)
Accessor the parameters value.
Definition: param.h:287
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 getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:285
void setFieldPrecision(unsigned int val)
Definition: statservices.h:157
bool isSet()
Accessor to the status flag.
Definition: param.h:273
static unsigned int getGenerations()
Definition: simenv.h:61
virtual int get_rank()
Accessor to the LCE rank in the life cycle.
Definition: lifecycleevent.h:166

Member Data Documentation

string LCE_StatServiceNotifier::_arg
private

Referenced by loadStatServices(), and setParameters().

string LCE_StatServiceNotifier::_dir
private

Referenced by setParameters().

LCE_StatFH LCE_StatServiceNotifier::_fileHandler
private
unsigned int LCE_StatServiceNotifier::_occurrence
private

Referenced by setOccurence().

StatServices* LCE_StatServiceNotifier::_service
private

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

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR