Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
fileservices.h
Go to the documentation of this file.
1 
30 #ifndef FILESERVICES_H
31 #define FILESERVICES_H
32 
33 #include <list>
34 #include <string>
35 #include <map>
36 #include "service.h"
37 #include "param.h"
38 
39 class Metapop;
40 class Patch;
41 
42 class FileHandler;
43 class FHLogWriter;
50 class FileServices : public Service {
51 
52 private:
57 
59  list< FileHandler* > _writers;
60 
62  list< FileHandler* > _readers;
63 
65  string _rep_filename;
66 
68  string _basename;
69 
71  string _root_dir;
72 
75  list< ParamSet* > _params;
76 
78  unsigned int _mode;
79 
81  TMatrix* _patch_sample_size; // num_patch x num_age
82 
83  TMatrix* _patch_sample_age; // num_patch x num_age
84 
85  TMatrix* _patch_sampled; // 1 x num_patch
86 
88 
90 
91 public:
92 
93  typedef std::list< FileHandler* >::const_iterator file_it;
94 
95  FileServices ( );
96 
97  virtual ~FileServices ( );
98 
99  virtual bool init ( ) {return false;}
100 
101  virtual void notify ();
107  bool init (list< ParamSet* >& params);
108 
111  virtual Metapop* get_pop_ptr ( ) {return _popPtr;}
112 
114  virtual void set_pop_ptr (Metapop* pop) {_popPtr = pop;}
115 
117  void setMode(unsigned int m) {_mode = m;}
118 
120  unsigned int getMode() {return _mode;}
121 
123  void setBasename (string name);
124 
126  void setRootDir (string name);
127 
129  void log_simparams();
130 
132  void log (string message);
133 
135  list< ParamSet* >& get_params() {return _params;};
136 
138  file_it getFirstWriter() {return _writers.begin();}
139 
141  file_it getLastWriter () {return _writers.end();}
142 
144  file_it getFirstReader() {return _readers.begin();}
145 
147  file_it getLastReader () {return _readers.end();}
148 
150  FileHandler* getReader (string& type);
151 
153  string& getBaseFileName ();
154 
156  string& getRootDir ();
157 
159  string getReplicateCounter ();
160 
162  string& getFirstReplicateFileName ();
163 
165  string& getReplicateFileName ();
166 
168  string getGenerationCounter ();
169 
172 
175 
176  void set_sampling_params(TMatrix* size, TMatrix* age, TMatrix* patches) {_patch_sample_size = size; _patch_sample_age = age; _patch_sampled = patches;}
177 
179  void empty_sampled_pop ();
180 
182  void reset_sampled_pop ();
183 
186 
188  void subSamplePatch(sex_t SEX, age_idx AGE, unsigned int num, Patch* source_patch, Patch* patch);
190 
193  virtual void load ( SimComponent* sc );
194 
197  virtual void attach ( Handler* FH );
198 
201  virtual void attach_reader ( FileHandler* FH );
202 
204  virtual void reset ( );
205 
206 };
207 #endif //FILESERVICES_H
208 
File Handler used to save the simulation parameters to a log file.
Definition: filehandler.h:281
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:51
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:50
string getGenerationCounter()
Accessor to the current generation counter string.
Definition: fileservices.cc:500
string & getReplicateFileName()
Accessor to the current replicate file name.
Definition: fileservices.cc:456
int _sampled_at_replicate
Definition: fileservices.h:87
void setBasename(string name)
Sets the base file name of the simulation.
Definition: fileservices.cc:513
Metapop * _sample_pop
Definition: fileservices.h:89
FileHandler * getReader(string &type)
Accessor to a specific file handler specified by its extension string.
Definition: fileservices.cc:531
virtual void notify()
Definition: fileservices.cc:187
string _basename
the base file name of the simulation, read from the init file (param "filename")
Definition: fileservices.h:68
unsigned int _mode
File mode, sets behavior when file must be overwritten or not.
Definition: fileservices.h:78
list< ParamSet * > _params
the list of the parameters of the current simulation.
Definition: fileservices.h:75
list< FileHandler * > _writers
the list of the FileHandler's registered by the SimComponent in output mode
Definition: fileservices.h:59
Metapop * getSampledPop()
Sets the down-sampled population and provides accessor to file handlers.
Definition: fileservices.cc:196
TMatrix * _patch_sampled
Definition: fileservices.h:85
file_it getFirstReader()
Accessor to first element of the list of input FileHandlers.
Definition: fileservices.h:144
void log(string message)
Write to the parameter logfile.
Definition: fileservices.cc:434
void setMode(unsigned int m)
Mode setter, determines if file will get overwritten or not.
Definition: fileservices.h:117
void reset_sampled_pop()
Remove the existing sampled metapop, if it has been allocated previously.
Definition: fileservices.cc:384
void set_sampling_params(TMatrix *size, TMatrix *age, TMatrix *patches)
Set the population sampling params.
Definition: fileservices.h:176
string getGenerationReplicateFileName()
Accessor to the current file name with generation and replicate counters added.
Definition: fileservices.cc:465
void empty_sampled_pop()
Empty the sampled pop without deleting the individuals since they are also in the main population.
Definition: fileservices.cc:363
string _rep_filename
the file name associated with the current simulation replicate
Definition: fileservices.h:65
string & getFirstReplicateFileName()
Accessor to the first replicate file name.
Definition: fileservices.cc:441
virtual Metapop * get_pop_ptr()
Accessor to the pointer to the main population.
Definition: fileservices.h:111
string getReplicateCounter()
Accessor to the current replicate counter string.
Definition: fileservices.cc:487
virtual void attach_reader(FileHandler *FH)
Attaches the FileHandler to the current list (_readers) of the FileServices.
Definition: fileservices.cc:72
file_it getFirstWriter()
Accessor to first element of the list of output FileHandlers.
Definition: fileservices.h:138
file_it getLastWriter()
Accessor to last element of the list of output FileHandlers.
Definition: fileservices.h:141
std::list< FileHandler * >::const_iterator file_it
Definition: fileservices.h:93
FHLogWriter * _logWriter
a FileHandler used to save the simulation parameters on disk.
Definition: fileservices.h:56
string & getRootDir()
Accessor to the name of the simulation's root output directory.
Definition: fileservices.cc:480
file_it getLastReader()
Accessor to last element of the list of input FileHandlers.
Definition: fileservices.h:147
list< ParamSet * > & get_params()
Accessor to the list of the current parameters of the simulation.
Definition: fileservices.h:135
void setRootDir(string name)
Sets the root directory of the simulation.
Definition: fileservices.cc:520
unsigned int getMode()
Writting mode getter.
Definition: fileservices.h:120
FileServices()
Definition: fileservices.cc:44
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:473
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:334
Metapop * _popPtr
a pointer to the current Metapop
Definition: fileservices.h:54
list< FileHandler * > _readers
the list of the FileHandler's registered by the SimComponent in input mode
Definition: fileservices.h:62
virtual void set_pop_ptr(Metapop *pop)
Sets the Metapop reference.
Definition: fileservices.h:114
virtual bool init()
Definition: fileservices.h:99
int _sampled_at_generation
Definition: fileservices.h:87
string _root_dir
the root directory for the simulation's results, read from the init file (param "root_dir")
Definition: fileservices.h:71
TMatrix * _patch_sample_size
Number of individuals to sample from each patch for the file handlers.
Definition: fileservices.h:81
virtual void load(SimComponent *sc)
Tells the SimComponent to load its file handlers.
Definition: fileservices.cc:80
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:59
TMatrix * _patch_sample_age
Definition: fileservices.h:83
void log_simparams()
Saves the current simulation parameters to the default parameter logfile.
Definition: fileservices.cc:424
virtual void reset()
Clears the list of FileHandlers.
Definition: fileservices.cc:401
virtual ~FileServices()
Definition: fileservices.cc:52
Service handler (an observer).
Definition: handler.h:34
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:78
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
Interface for the simulation services (files and stats).
Definition: service.h:41
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:43
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:48
void message(const char *message,...)
Definition: output.cc:38
Nemo2.
Nemo2.
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:39

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR