Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
fileservices.h
Go to the documentation of this file.
1 
31 #ifndef FILESERVICES_H
32 #define FILESERVICES_H
33 
34 #include <list>
35 #include <string>
36 #include <map>
37 #include "service.h"
38 #include "param.h"
39 
40 class Metapop;
41 class Patch;
42 
43 class FileHandler;
44 class FHLogWriter;
51 class FileServices : public Service {
52 
53 private:
58 
60  list< FileHandler* > _writers;
61 
63  list< FileHandler* > _readers;
64 
66  string _rep_filename;
67 
69  string _basename;
70 
72  string _root_dir;
73 
76  list< ParamSet* > _params;
77 
79  unsigned int _mode;
80 
82  TMatrix* _patch_sample_size; // num_patch x num_age
83 
84  TMatrix* _patch_sample_age; // num_patch x num_age
85 
86  TMatrix* _patch_sampled; // 1 x num_patch
87 
89 
91 
92 public:
93 
94  typedef std::list< FileHandler* >::const_iterator file_it;
95 
96  FileServices ( );
97 
98  virtual ~FileServices ( );
99 
100  virtual bool init ( ) {return false;}
101 
102  virtual void notify ();
108  bool init (list< ParamSet* >& params);
109 
112  virtual Metapop* get_pop_ptr ( ) {return _popPtr;}
113 
115  virtual void set_pop_ptr (Metapop* pop) {_popPtr = pop;}
116 
118  void setMode(unsigned int m) {_mode = m;}
119 
121  unsigned int getMode() {return _mode;}
122 
124  void setBasename (string name);
125 
127  void setRootDir (string name);
128 
130  void log_simparams();
131 
133  void log (string message);
134 
136  list< ParamSet* >& get_params() {return _params;};
137 
139  file_it getFirstWriter() {return _writers.begin();}
140 
142  file_it getLastWriter () {return _writers.end();}
143 
145  file_it getFirstReader() {return _readers.begin();}
146 
148  file_it getLastReader () {return _readers.end();}
149 
151  FileHandler* getReader (string& type);
152 
154  string& getBaseFileName ();
155 
157  string& getRootDir ();
158 
160  string getReplicateCounter ();
161 
163  string& getFirstReplicateFileName ();
164 
166  string& getReplicateFileName ();
167 
169  string getGenerationCounter ();
170 
173 
176 
177  void set_sampling_params(TMatrix* size, TMatrix* age, TMatrix* patches) {_patch_sample_size = size; _patch_sample_age = age; _patch_sampled = patches;}
178 
180  void empty_sampled_pop ();
181 
183  void reset_sampled_pop ();
184 
187 
189  void subSamplePatch(sex_t SEX, age_idx AGE, unsigned int num, Patch* source_patch, Patch* patch);
191 
194  virtual void load ( SimComponent* sc );
195 
198  virtual void attach ( Handler* FH );
199 
202  virtual void attach_reader ( FileHandler* FH );
203 
205  virtual void reset ( );
206 
207 };
208 #endif //FILESERVICES_H
209 
File Handler used to save the simulation parameters to a log file.
Definition: filehandler.h:282
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:52
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
string getGenerationCounter()
Accessor to the current generation counter string.
Definition: fileservices.cc:501
string & getReplicateFileName()
Accessor to the current replicate file name.
Definition: fileservices.cc:457
int _sampled_at_replicate
Definition: fileservices.h:88
void setBasename(string name)
Sets the base file name of the simulation.
Definition: fileservices.cc:514
Metapop * _sample_pop
Definition: fileservices.h:90
FileHandler * getReader(string &type)
Accessor to a specific file handler specified by its extension string.
Definition: fileservices.cc:532
virtual void notify()
Definition: fileservices.cc:188
string _basename
the base file name of the simulation, read from the init file (param "filename")
Definition: fileservices.h:69
unsigned int _mode
File mode, sets behavior when file must be overwritten or not.
Definition: fileservices.h:79
list< ParamSet * > _params
the list of the parameters of the current simulation.
Definition: fileservices.h:76
list< FileHandler * > _writers
the list of the FileHandler's registered by the SimComponent in output mode
Definition: fileservices.h:60
Metapop * getSampledPop()
Sets the down-sampled population and provides accessor to file handlers.
Definition: fileservices.cc:197
TMatrix * _patch_sampled
Definition: fileservices.h:86
file_it getFirstReader()
Accessor to first element of the list of input FileHandlers.
Definition: fileservices.h:145
void log(string message)
Write to the parameter logfile.
Definition: fileservices.cc:435
void setMode(unsigned int m)
Mode setter, determines if file will get overwritten or not.
Definition: fileservices.h:118
void reset_sampled_pop()
Remove the existing sampled metapop, if it has been allocated previously.
Definition: fileservices.cc:385
void set_sampling_params(TMatrix *size, TMatrix *age, TMatrix *patches)
Set the population sampling params.
Definition: fileservices.h:177
string getGenerationReplicateFileName()
Accessor to the current file name with generation and replicate counters added.
Definition: fileservices.cc:466
void empty_sampled_pop()
Empty the sampled pop without deleting the individuals since they are also in the main population.
Definition: fileservices.cc:364
string _rep_filename
the file name associated with the current simulation replicate
Definition: fileservices.h:66
string & getFirstReplicateFileName()
Accessor to the first replicate file name.
Definition: fileservices.cc:442
virtual Metapop * get_pop_ptr()
Accessor to the pointer to the main population.
Definition: fileservices.h:112
string getReplicateCounter()
Accessor to the current replicate counter string.
Definition: fileservices.cc:488
virtual void attach_reader(FileHandler *FH)
Attaches the FileHandler to the current list (_readers) of the FileServices.
Definition: fileservices.cc:73
file_it getFirstWriter()
Accessor to first element of the list of output FileHandlers.
Definition: fileservices.h:139
file_it getLastWriter()
Accessor to last element of the list of output FileHandlers.
Definition: fileservices.h:142
std::list< FileHandler * >::const_iterator file_it
Definition: fileservices.h:94
FHLogWriter * _logWriter
a FileHandler used to save the simulation parameters on disk.
Definition: fileservices.h:57
string & getRootDir()
Accessor to the name of the simulation's root output directory.
Definition: fileservices.cc:481
file_it getLastReader()
Accessor to last element of the list of input FileHandlers.
Definition: fileservices.h:148
list< ParamSet * > & get_params()
Accessor to the list of the current parameters of the simulation.
Definition: fileservices.h:136
void setRootDir(string name)
Sets the root directory of the simulation.
Definition: fileservices.cc:521
unsigned int getMode()
Writting mode getter.
Definition: fileservices.h:121
FileServices()
Definition: fileservices.cc:45
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:474
void subSamplePatch(sex_t SEX, age_idx AGE, unsigned int num, Patch *source_patch, Patch *patch)
Create a patch from a sample of the corresponding patch in the main metapopulation.
Definition: fileservices.cc:335
Metapop * _popPtr
a pointer to the current Metapop
Definition: fileservices.h:55
list< FileHandler * > _readers
the list of the FileHandler's registered by the SimComponent in input mode
Definition: fileservices.h:63
virtual void set_pop_ptr(Metapop *pop)
Sets the Metapop reference.
Definition: fileservices.h:115
virtual bool init()
Definition: fileservices.h:100
int _sampled_at_generation
Definition: fileservices.h:88
string _root_dir
the root directory for the simulation's results, read from the init file (param "root_dir")
Definition: fileservices.h:72
TMatrix * _patch_sample_size
Number of individuals to sample from each patch for the file handlers.
Definition: fileservices.h:82
virtual void load(SimComponent *sc)
Tells the SimComponent to load its file handlers.
Definition: fileservices.cc:81
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:60
TMatrix * _patch_sample_age
Definition: fileservices.h:84
void log_simparams()
Saves the current simulation parameters to the default parameter logfile.
Definition: fileservices.cc:425
virtual void reset()
Clears the list of FileHandlers.
Definition: fileservices.cc:402
virtual ~FileServices()
Definition: fileservices.cc:53
Service handler (an observer).
Definition: handler.h:35
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
Interface for the simulation services (files and stats).
Definition: service.h:42
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:44
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
void message(const char *message,...)
Definition: output.cc:39
Nemo2.
Nemo2.
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:35
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:40

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