Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
fileservices.h
Go to the documentation of this file.
1 
32 #ifndef FILESERVICES_H
33 #define FILESERVICES_H
34 
35 #include <list>
36 #include <string>
37 #include <map>
38 #include "service.h"
39 #include "param.h"
40 
41 class Metapop;
42 class Patch;
43 
44 class FileHandler;
45 class FHLogWriter;
52 class FileServices : public Service {
53 
54 private:
59 
61  list< FileHandler* > _writers;
62 
64  list< FileHandler* > _readers;
65 
67  string _rep_filename;
68 
70  string _basename;
71 
73  string _root_dir;
74 
77  list< ParamSet* > _params;
78 
80  unsigned int _mode;
81 
83  TMatrix* _patch_sample_size; // num_patch x num_age
84 
85  TMatrix* _patch_sample_age; // num_patch x num_age
86 
87  TMatrix* _patch_sampled; // 1 x num_patch
88 
90 
92 
93 public:
94 
95  typedef std::list< FileHandler* >::const_iterator file_it;
96 
97  FileServices ( );
98 
99  virtual ~FileServices ( );
100 
101  virtual bool init ( ) {return false;}
102 
103  virtual void notify ();
109  bool init (list< ParamSet* >& params);
110 
113  virtual Metapop* get_pop_ptr ( ) {return _popPtr;}
114 
116  virtual void set_pop_ptr (Metapop* pop) {_popPtr = pop;}
117 
119  void setMode(unsigned int m) {_mode = m;}
120 
122  unsigned int getMode() {return _mode;}
123 
125  void setBasename (string name);
126 
128  void setRootDir (string name);
129 
131  void log_simparams();
132 
134  void log (string message);
135 
137  list< ParamSet* >& get_params() {return _params;};
138 
140  file_it getFirstWriter() {return _writers.begin();}
141 
143  file_it getLastWriter () {return _writers.end();}
144 
146  file_it getFirstReader() {return _readers.begin();}
147 
149  file_it getLastReader () {return _readers.end();}
150 
152  FileHandler* getReader (string& type);
153 
155  string& getBaseFileName ();
156 
158  string& getRootDir ();
159 
161  string getReplicateCounter ();
162 
164  string& getFirstReplicateFileName ();
165 
167  string& getReplicateFileName ();
168 
170  string getGenerationCounter ();
171 
174 
177 
178  void set_sampling_params(TMatrix* size, TMatrix* age, TMatrix* patches) {_patch_sample_size = size; _patch_sample_age = age; _patch_sampled = patches;}
179 
181  void empty_sampled_pop ();
182 
184  void reset_sampled_pop ();
185 
188 
190  void subSamplePatch(sex_t SEX, age_idx AGE, unsigned int num, Patch* source_patch, Patch* patch);
192 
195  virtual void load ( SimComponent* sc );
196 
199  virtual void attach ( Handler* FH );
200 
203  virtual void attach_reader ( FileHandler* FH );
204 
206  virtual void reset ( );
207 
208 };
209 #endif //FILESERVICES_H
210 
File Handler used to save the simulation parameters to a log file.
Definition: filehandler.h:283
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:53
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:52
string getGenerationCounter()
Accessor to the current generation counter string.
Definition: fileservices.cc:502
string & getReplicateFileName()
Accessor to the current replicate file name.
Definition: fileservices.cc:458
int _sampled_at_replicate
Definition: fileservices.h:89
void setBasename(string name)
Sets the base file name of the simulation.
Definition: fileservices.cc:515
Metapop * _sample_pop
Definition: fileservices.h:91
FileHandler * getReader(string &type)
Accessor to a specific file handler specified by its extension string.
Definition: fileservices.cc:533
virtual void notify()
Definition: fileservices.cc:189
string _basename
the base file name of the simulation, read from the init file (param "filename")
Definition: fileservices.h:70
unsigned int _mode
File mode, sets behavior when file must be overwritten or not.
Definition: fileservices.h:80
list< ParamSet * > _params
the list of the parameters of the current simulation.
Definition: fileservices.h:77
list< FileHandler * > _writers
the list of the FileHandler's registered by the SimComponent in output mode
Definition: fileservices.h:61
Metapop * getSampledPop()
Sets the down-sampled population and provides accessor to file handlers.
Definition: fileservices.cc:198
TMatrix * _patch_sampled
Definition: fileservices.h:87
file_it getFirstReader()
Accessor to first element of the list of input FileHandlers.
Definition: fileservices.h:146
void log(string message)
Write to the parameter logfile.
Definition: fileservices.cc:436
void setMode(unsigned int m)
Mode setter, determines if file will get overwritten or not.
Definition: fileservices.h:119
void reset_sampled_pop()
Remove the existing sampled metapop, if it has been allocated previously.
Definition: fileservices.cc:386
void set_sampling_params(TMatrix *size, TMatrix *age, TMatrix *patches)
Set the population sampling params.
Definition: fileservices.h:178
string getGenerationReplicateFileName()
Accessor to the current file name with generation and replicate counters added.
Definition: fileservices.cc:467
void empty_sampled_pop()
Empty the sampled pop without deleting the individuals since they are also in the main population.
Definition: fileservices.cc:365
string _rep_filename
the file name associated with the current simulation replicate
Definition: fileservices.h:67
string & getFirstReplicateFileName()
Accessor to the first replicate file name.
Definition: fileservices.cc:443
virtual Metapop * get_pop_ptr()
Accessor to the pointer to the main population.
Definition: fileservices.h:113
string getReplicateCounter()
Accessor to the current replicate counter string.
Definition: fileservices.cc:489
virtual void attach_reader(FileHandler *FH)
Attaches the FileHandler to the current list (_readers) of the FileServices.
Definition: fileservices.cc:74
file_it getFirstWriter()
Accessor to first element of the list of output FileHandlers.
Definition: fileservices.h:140
file_it getLastWriter()
Accessor to last element of the list of output FileHandlers.
Definition: fileservices.h:143
std::list< FileHandler * >::const_iterator file_it
Definition: fileservices.h:95
FHLogWriter * _logWriter
a FileHandler used to save the simulation parameters on disk.
Definition: fileservices.h:58
string & getRootDir()
Accessor to the name of the simulation's root output directory.
Definition: fileservices.cc:482
file_it getLastReader()
Accessor to last element of the list of input FileHandlers.
Definition: fileservices.h:149
list< ParamSet * > & get_params()
Accessor to the list of the current parameters of the simulation.
Definition: fileservices.h:137
void setRootDir(string name)
Sets the root directory of the simulation.
Definition: fileservices.cc:522
unsigned int getMode()
Writting mode getter.
Definition: fileservices.h:122
FileServices()
Definition: fileservices.cc:46
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:475
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:336
Metapop * _popPtr
a pointer to the current Metapop
Definition: fileservices.h:56
list< FileHandler * > _readers
the list of the FileHandler's registered by the SimComponent in input mode
Definition: fileservices.h:64
virtual void set_pop_ptr(Metapop *pop)
Sets the Metapop reference.
Definition: fileservices.h:116
virtual bool init()
Definition: fileservices.h:101
int _sampled_at_generation
Definition: fileservices.h:89
string _root_dir
the root directory for the simulation's results, read from the init file (param "root_dir")
Definition: fileservices.h:73
TMatrix * _patch_sample_size
Number of individuals to sample from each patch for the file handlers.
Definition: fileservices.h:83
virtual void load(SimComponent *sc)
Tells the SimComponent to load its file handlers.
Definition: fileservices.cc:82
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:61
TMatrix * _patch_sample_age
Definition: fileservices.h:85
void log_simparams()
Saves the current simulation parameters to the default parameter logfile.
Definition: fileservices.cc:426
virtual void reset()
Clears the list of FileHandlers.
Definition: fileservices.cc:403
virtual ~FileServices()
Definition: fileservices.cc:54
Service handler (an observer).
Definition: handler.h:36
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:80
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
Interface for the simulation services (files and stats).
Definition: service.h:43
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:45
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:50
void message(const char *message,...)
Definition: output.cc:40
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR