Nemo  2.3.46
statservices.h
Go to the documentation of this file.
1 
30 #ifndef STATSERVICES_H
31 #define STATSERVICES_H
32 
33 #include <list>
34 #include <string>
35 #include <fstream>
36 #include <map>
37 #include <vector>
38 #include <assert.h>
39 #include <cstring> //for memcpy
40 #include "service.h"
41 #include "statrecorder.h"
42 
43 using namespace std;
44 
45 class Metapop;
46 
47 class StatHandlerBase;
48 
50 class StatServices : public Service {
51 
52 private:
53 
55 
57  list< StatHandlerBase* > _statHandlers;
58 
60  list< StatRecBase *> _statRecorders;
61 
63  unsigned int _numRecorders;
64 
66  vector< vector< double*> > _statValues;
67 
70 
72  string _statArg;
73 
75  unsigned int _occurrence;
76 
78  list< unsigned int > _occurrences;
79 
83  list< unsigned int >::const_iterator _current_occurrence;
84 
85  //output format:
86  unsigned int _width, _precision;
87 
88  unsigned char _separator;
89 
91 
92 public:
93 
94  typedef list< StatHandlerBase* >::const_iterator stat_it;
95 
96  typedef list< StatRecBase* >::const_iterator rec_it;
97 
98  StatServices ( ) : _popPtr(0), _occurrence(0), _currentStatValues(0),
99  _numRecorders(0), _width(12), _precision(6), _separator('\t'), _printAverages(1)
100  { }
101 
102  virtual ~StatServices ( ) { reset_stat_table(); }
103 
104  virtual bool init ( );
105 
106  Metapop* get_pop_ptr ( ) {return _popPtr;}
107 
108  void set_pop_ptr (Metapop* pop) {_popPtr=pop;}
109 
110  void set (string& str, unsigned int occ)
111  {_statArg = str; _occurrence = occ;}
112 
113  void setStatOptions (string& str) {_statArg = str;}
114 
115  string& getStatArg ( ) {return _statArg;}
116 
117  //OCURRENCE
118  unsigned int getOccurrence ( ) {return _occurrence;}
119 
120  void setOcccurrence (unsigned int value) {_occurrence = value;}
124  void setOccurrences (map<unsigned int, unsigned int> timeTable);
126  unsigned int getNumOccurrences( ) {return _occurrences.size();}
127 
131  unsigned int getNumOccurrences(unsigned int replicate)
132  {
133  return _statValues[replicate-1].size();
134  }
136  unsigned int getCurrentOccurrence () {return *_current_occurrence;}
138  void resetCurrentOccurrence () {_current_occurrence = _occurrences.begin();}
139 
140  //PRINT
141  void printStatHeaders (ofstream& FH);
142  void doPrintAverages ( ) {_printAverages = 1;}
143  void cancelPrintAverages ( ) {_printAverages = 0;}
144  bool getPrintAveragesOpt ( ) {return _printAverages;}
145 
149  void printStatValue (ofstream& FH, unsigned int repl_idx);
150 
151  void printStatAverage (ofstream& FH);
152 
153  void setCompactOutputFormat () {_width = 0; _separator = ' ';}
154 
155  void setFieldWidth (unsigned int val) {_width = val;}
156 
157  void setFieldPrecision (unsigned int val) {_precision = val;}
158 
159  void setFieldSeparator (unsigned char c) {_separator = c;}
160 
161  void setDefaultOutputFormat () {_width = 12; _precision = 6; _separator = '\t';}
162 
163  //STAT RECORDS
164  list<StatRecBase*> getAllStats ( );
165 
166  unsigned int getNumStats ( ) {return _statRecorders.size();}
167 
168  stat_it getFirst () {return _statHandlers.begin();}
169 
170  stat_it getLast () {return _statHandlers.end();}
171 
172  vector<double*>* getReplicateStatRecords (unsigned int replicate)
173  {
174  return &_statValues[ replicate-1 ];
175  }
176 
177  double* getGenerationStatValues (unsigned int replicate, unsigned int occurence) const
178  {
179  assert(occurence < _occurrences.size());
180  return _statValues[ replicate-1 ][ occurence ];
181  }
182 
183  void copyGenerationStatValues (unsigned int replicate, unsigned int occurence, double* values, unsigned int size)
184  {
185  assert( _statValues[ replicate-1 ].size() < _occurrences.size() );
186 
187  assert( size == _numRecorders+2);
188 
189  double* new_record = new double[size];
190 
191  memcpy(new_record, values, size*sizeof(double));
192 
193  _statValues[ replicate-1 ].push_back(new_record);
194  }
198  void recordStats (unsigned int gen);
199 
200  virtual void notify ();
205  virtual void load ( SimComponent* sc );
210  virtual void attach ( Handler* H);
214  virtual void reset ( );
215 
217  void reset_stat_table();
218 };
219 #endif //STATSERVICES_H
220 
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
void set(string &str, unsigned int occ)
Definition: statservices.h:110
list< StatRecBase * > _statRecorders
List of stat recorders.
Definition: statservices.h:60
void setStatOptions(string &str)
Definition: statservices.h:113
StatServices()
Definition: statservices.h:98
void doPrintAverages()
Definition: statservices.h:142
list< StatHandlerBase * > _statHandlers
List of stat handlers declared by currently active simulation components.
Definition: statservices.h:57
void setFieldSeparator(unsigned char c)
Definition: statservices.h:159
double * getGenerationStatValues(unsigned int replicate, unsigned int occurence) const
Definition: statservices.h:177
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
list< unsigned int > _occurrences
List of all generations to record.
Definition: statservices.h:78
stat_it getLast()
Definition: statservices.h:170
void setDefaultOutputFormat()
Definition: statservices.h:161
unsigned int _occurrence
Deprecated.
Definition: statservices.h:75
unsigned int getNumOccurrences(unsigned int replicate)
Returns the number of generation records present in the stat table for a replicate.
Definition: statservices.h:131
Base class of the StatHandler class, implements the Handler interface.
Definition: stathandler.h:48
void set_pop_ptr(Metapop *pop)
Definition: statservices.h:108
void setFieldWidth(unsigned int val)
Definition: statservices.h:155
vector< double * > * getReplicateStatRecords(unsigned int replicate)
Definition: statservices.h:172
vector< vector< double * > > _statValues
Table containing all recorded stats, replicate x generation x (num recorders + 2) ...
Definition: statservices.h:66
Metapop * _popPtr
Definition: statservices.h:54
unsigned int _width
Definition: statservices.h:86
void cancelPrintAverages()
Definition: statservices.h:143
Interface to all basic components of a simulation (traits, life cycle events, pop, etc. ).
Definition: simcomponent.h:45
bool _printAverages
Definition: statservices.h:90
Metapop * get_pop_ptr()
Definition: statservices.h:106
unsigned int getNumOccurrences()
Returns the maximum number of generation records per replicate.
Definition: statservices.h:126
Service handler (an observer).
Definition: handler.h:36
unsigned int _numRecorders
Number of stats to record.
Definition: statservices.h:63
void resetCurrentOccurrence()
Resets the occurrence iterator to the beginning of the list of generation occurrences.
Definition: statservices.h:138
void setCompactOutputFormat()
Definition: statservices.h:153
unsigned int getNumStats()
Definition: statservices.h:166
virtual ~StatServices()
Definition: statservices.h:102
stat_it getFirst()
Definition: statservices.h:168
list< unsigned int >::const_iterator _current_occurrence
Iterator pointing to the current generation to record.
Definition: statservices.h:83
string _statArg
The string argument of the 'stat' input option.
Definition: statservices.h:72
string & getStatArg()
Definition: statservices.h:115
void setOcccurrence(unsigned int value)
Definition: statservices.h:120
void setFieldPrecision(unsigned int val)
Definition: statservices.h:157
void copyGenerationStatValues(unsigned int replicate, unsigned int occurence, double *values, unsigned int size)
Definition: statservices.h:183
unsigned int getOccurrence()
Definition: statservices.h:118
unsigned char _separator
Definition: statservices.h:88
bool getPrintAveragesOpt()
Definition: statservices.h:144
list< StatRecBase * >::const_iterator rec_it
Definition: statservices.h:96
double * _currentStatValues
Pointer to the last recorded stats.
Definition: statservices.h:69
Interface for the simulation services (files and stats).
Definition: service.h:43
unsigned int getCurrentOccurrence()
Returns the last generation recorded for current replicate.
Definition: statservices.h:136
list< StatHandlerBase * >::const_iterator stat_it
Definition: statservices.h:94

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