Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
FileServices Class Reference

A class to manage the files associated with each components of the simulation. More...

#include <fileservices.h>

+ Inheritance diagram for FileServices:
+ Collaboration diagram for FileServices:

Public Types

typedef std::list< FileHandler * >::const_iterator file_it
 

Public Member Functions

 FileServices ()
 
virtual ~FileServices ()
 
virtual bool init ()
 
virtual void notify ()
 
bool init (list< ParamSet * > &params)
 Checks if files with _basename already exist and save the simulation parameters in log files. More...
 
virtual Metapopget_pop_ptr ()
 Accessor to the pointer to the main population. More...
 
virtual void set_pop_ptr (Metapop *pop)
 Sets the Metapop reference. More...
 
void set_sampling_params (unsigned int size, age_t age)
 Set the population sampling params. More...
 
void setMode (unsigned int m)
 Mode setter, determines if file will get overwritten or not. More...
 
unsigned int getMode ()
 Writting mode getter. More...
 
void setBasename (string name)
 Sets the base file name of the simulation. More...
 
void setRootDir (string name)
 Sets the root directory of the simulation. More...
 
void log_simparams ()
 Saves the current simulation parameters to the default parameter logfile. More...
 
void log (string message)
 Write to the parameter logfile. More...
 
list< ParamSet * > & get_params ()
 Accessor to the list of the current parameters of the simulation. More...
 
file_it getFirstWriter ()
 Accessor to first element of the list of output FileHandlers. More...
 
file_it getLastWriter ()
 Accessor to last element of the list of output FileHandlers. More...
 
file_it getFirstReader ()
 Accessor to first element of the list of input FileHandlers. More...
 
file_it getLastReader ()
 Accessor to last element of the list of input FileHandlers. More...
 
FileHandlergetReader (string &type)
 Accessor to a specific file handler specified by its extension string. More...
 
string & getBaseFileName ()
 Accessor to the base file name of the simulation. More...
 
string & getRootDir ()
 Accessor to the name of the simulation's root output directory. More...
 
string getReplicateCounter ()
 Accessor to the current replicate counter string. More...
 
string & getFirstReplicateFileName ()
 Accessor to the first replicate file name. More...
 
string & getReplicateFileName ()
 Accessor to the current replicate file name. More...
 
string getGenerationCounter ()
 Accessor to the current generation counter string. More...
 
string getGenerationReplicateFileName ()
 Accessor to the current file name with generation and replicate counters added. More...
 
MetapopgetSampledPop ()
 Sets the down-sampled population and provides accessor to file handlers. More...
 
void subSamplePatch (sex_t SEX, age_idx AGE, Patch *source_patch, Patch *patch)
 
virtual void load (SimComponent *sc)
 Tells the SimComponent to load its file handlers. More...
 
virtual void attach (Handler *FH)
 Attaches the FileHandler to the current list (_writers) of the FileServices. More...
 
virtual void attach_reader (FileHandler *FH)
 Attaches the FileHandler to the current list (_readers) of the FileServices. More...
 
virtual void reset ()
 Clears the list of FileHandlers. More...
 
- Public Member Functions inherited from Service
 Service ()
 
virtual ~Service ()
 
virtual bool init ()=0
 Inits internals. More...
 
virtual void notify ()=0
 Notifies all observers to update their state. More...
 
virtual void load (SimComponent *sc)=0
 Interface used by a simulation component to load its obervers onto a service provider. More...
 
virtual void attach (Handler *h)=0
 Adds an observer to the list. More...
 
virtual void reset ()=0
 Clears the observers list. More...
 

Private Attributes

Metapop_popPtr
 a pointer to the current Metapop More...
 
FHLogWriter_logWriter
 a FileHandler used to save the simulation parameters on disk. More...
 
list< FileHandler * > _writers
 the list of the FileHandler's registered by the SimComponent in output mode More...
 
list< FileHandler * > _readers
 the list of the FileHandler's registered by the SimComponent in input mode More...
 
string _rep_filename
 the file name associated with the current simulation replicate More...
 
string _basename
 the base file name of the simulation, read from the init file (param "filename") More...
 
string _root_dir
 the root directory for the simulation's results, read from the init file (param "root_dir") More...
 
list< ParamSet * > _params
 the list of the parameters of the current simulation. More...
 
unsigned int _mode
 File mode, sets behavior when file must be overwritten or not. More...
 
unsigned int _patch_sample_size
 Number of individuals to sample from each patch for the file handlers. More...
 
age_t _patch_sample_age
 
int _sampled_at_replicate
 
int _sampled_at_generation
 
Metapop_sample_pop
 

Detailed Description

A class to manage the files associated with each components of the simulation.

Implements the Observer design pattern (is the concrete subject), stores the base filename of the simulation and updates the replicate filenames. It also performs files checking and saves the simulation parameters on init.

Member Typedef Documentation

◆ file_it

typedef std::list<FileHandler*>::const_iterator FileServices::file_it

Constructor & Destructor Documentation

◆ FileServices()

FileServices::FileServices ( )
46 : _popPtr(0), _rep_filename(""), _basename(""), _root_dir(""),
49{
50 _logWriter = new FHLogWriter();
52}
File Handler used to save the simulation parameters to a log file.
Definition: filehandler.h:272
int _sampled_at_replicate
Definition: fileservices.h:87
Metapop * _sample_pop
Definition: fileservices.h:89
unsigned int _patch_sample_size
Number of individuals to sample from each patch for the file handlers.
Definition: fileservices.h:83
string _basename
the base file name of the simulation, read from the init file (param "filename")
Definition: fileservices.h:70
string _rep_filename
the file name associated with the current simulation replicate
Definition: fileservices.h:67
age_t _patch_sample_age
Definition: fileservices.h:85
FHLogWriter * _logWriter
a FileHandler used to save the simulation parameters on disk.
Definition: fileservices.h:58
Metapop * _popPtr
a pointer to the current Metapop
Definition: fileservices.h:56
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:73
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:60

References _logWriter, and attach().

◆ ~FileServices()

FileServices::~FileServices ( )
virtual
54 {
55 if(_logWriter) delete _logWriter;
56}

References _logWriter.

Member Function Documentation

◆ attach()

void FileServices::attach ( Handler FH)
virtual

Attaches the FileHandler to the current list (_writers) of the FileServices.

Parameters
FHthe FileHandler

Implements Service.

61{
62// Service::attach(FH);
63 FileHandler* FH = dynamic_cast<FileHandler*> (H);
64 _writers.push_back(FH);
65
67
68 FH->set_service(this);
69}
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:53
void set_service(FileServices *srv)
Definition: filehandler.h:137
bool get_isInputHandler()
Definition: filehandler.h:150
list< FileHandler * > _writers
the list of the FileHandler's registered by the SimComponent in output mode
Definition: fileservices.h:61
virtual void attach_reader(FileHandler *FH)
Attaches the FileHandler to the current list (_readers) of the FileServices.
Definition: fileservices.cc:73

References _writers, attach_reader(), FileHandler::get_isInputHandler(), and FileHandler::set_service().

Referenced by FileServices(), BinaryDataSaver::loadFileServices(), LCE_Selection_base::loadFileServices(), Metapop::loadFileServices(), LCE_FileServicesNotifier::loadFileServices(), LCE_StatServiceNotifier::loadFileServices(), TProtoBDMI::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), TProtoQuanti::loadFileServices(), and LCE_Breed_Wolbachia::loadFileServices().

+ Here is the caller graph for this function:

◆ attach_reader()

void FileServices::attach_reader ( FileHandler FH)
virtual

Attaches the FileHandler to the current list (_readers) of the FileServices.

Parameters
FHthe FileHandler
74{
75 _readers.push_back(FH);
76 FH->set_service(this);
77}
list< FileHandler * > _readers
the list of the FileHandler's registered by the SimComponent in input mode
Definition: fileservices.h:64

References _readers, and FileHandler::set_service().

Referenced by attach(), LCE_Cross::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), and TProtoQuanti::loadFileServices().

+ Here is the caller graph for this function:

◆ get_params()

list< ParamSet * > & FileServices::get_params ( )
inline

Accessor to the list of the current parameters of the simulation.

138{return _params;};
list< ParamSet * > _params
the list of the parameters of the current simulation.
Definition: fileservices.h:77

References _params.

Referenced by BinaryDataSaver::printHeader().

+ Here is the caller graph for this function:

◆ get_pop_ptr()

virtual Metapop * FileServices::get_pop_ptr ( )
inlinevirtual

Accessor to the pointer to the main population.

Returns
the pointer to the current Metapop as set during simulation setup.
111{return _popPtr;}

References _popPtr.

Referenced by TTNeutralGenesFH::FHread(), TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTNeutralGenesFH::FHwrite(), TTQuantiFH::FHwrite(), TTQFreqExtractor::FHwrite(), FileHandler::init(), TTNeutralGenesFH::write_Fst_i(), TTQuantiFH::write_TABLE(), and TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ getBaseFileName()

string & FileServices::getBaseFileName ( )

◆ getFirstReader()

file_it FileServices::getFirstReader ( )
inline

Accessor to first element of the list of input FileHandlers.

147{return _readers.begin();}

References _readers.

Referenced by getReader().

+ Here is the caller graph for this function:

◆ getFirstReplicateFileName()

string & FileServices::getFirstReplicateFileName ( )

Accessor to the first replicate file name.

367{
368 ostringstream rpl;
369
370 rpl.fill('0');
371 rpl.width( (int)log10((double)_popPtr->getReplicates()) + 1);
372 rpl<< max( (unsigned)1, _myenv->workerRank() );
373
374 _rep_filename = _basename + "_" + rpl.str();
375
376 return _rep_filename;
377}
MPIenv * _myenv
Definition: MPImanager.cc:36
unsigned int workerRank() const
Definition: MPImanager.h:129
unsigned int getReplicates()
Definition: metapop.h:275

References _basename, _myenv, _popPtr, _rep_filename, Metapop::getReplicates(), and MPIenv::workerRank().

◆ getFirstWriter()

file_it FileServices::getFirstWriter ( )
inline

Accessor to first element of the list of output FileHandlers.

141{return _writers.begin();}

References _writers.

Referenced by SimRunner::printLog().

+ Here is the caller graph for this function:

◆ getGenerationCounter()

string FileServices::getGenerationCounter ( )

Accessor to the current generation counter string.

426{
427 ostringstream gen;
428
429 gen.fill('0');
430 gen.width( (int)log10((double)_popPtr->getGenerations()) + 1);
432
433 return gen.str();
434}
unsigned int getGenerations()
Definition: metapop.h:273
unsigned int getCurrentGeneration()
Definition: metapop.h:294

References _popPtr, Metapop::getCurrentGeneration(), and Metapop::getGenerations().

Referenced by getGenerationReplicateFileName().

+ Here is the caller graph for this function:

◆ getGenerationReplicateFileName()

string FileServices::getGenerationReplicateFileName ( )

Accessor to the current file name with generation and replicate counters added.

391{
392 string name = _basename + "_" + getGenerationCounter() + "_" + getReplicateCounter();
393 return name;
394}
string getGenerationCounter()
Accessor to the current generation counter string.
Definition: fileservices.cc:425
string getReplicateCounter()
Accessor to the current replicate counter string.
Definition: fileservices.cc:412

References _basename, getGenerationCounter(), and getReplicateCounter().

Referenced by TTDeletMutBitstrFH::FHwrite(), FileHandler::get_filename(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_PLINK(), TTQuantiFH::write_PLINK(), TTNeutralGenesFH::write_TAB(), and TTNeutralGenesFH::write_varcompWC().

+ Here is the caller graph for this function:

◆ getLastReader()

file_it FileServices::getLastReader ( )
inline

Accessor to last element of the list of input FileHandlers.

150{return _readers.end();}

References _readers.

Referenced by getReader().

+ Here is the caller graph for this function:

◆ getLastWriter()

file_it FileServices::getLastWriter ( )
inline

Accessor to last element of the list of output FileHandlers.

144{return _writers.end();}

References _writers.

Referenced by SimRunner::printLog().

+ Here is the caller graph for this function:

◆ getMode()

unsigned int FileServices::getMode ( )
inline

Writting mode getter.

123{return _mode;}
unsigned int _mode
File mode, sets behavior when file must be overwritten or not.
Definition: fileservices.h:80

References _mode.

Referenced by BinaryDataSaver::finish().

+ Here is the caller graph for this function:

◆ getReader()

FileHandler * FileServices::getReader ( string &  type)

Accessor to a specific file handler specified by its extension string.

457{
458 file_it file = getFirstReader(), last = getLastReader() ;
459
460 for(;file != last; file++) {
461 if( (*file)->get_extension().compare( type ) == 0) {
462 return (*file);
463 }
464 }
465 return 0;
466}
file_it getFirstReader()
Accessor to first element of the list of input FileHandlers.
Definition: fileservices.h:147
std::list< FileHandler * >::const_iterator file_it
Definition: fileservices.h:93
file_it getLastReader()
Accessor to last element of the list of input FileHandlers.
Definition: fileservices.h:150

References getFirstReader(), and getLastReader().

Referenced by Metapop::loadPopFromTraitFile().

+ Here is the caller graph for this function:

◆ getReplicateCounter()

string FileServices::getReplicateCounter ( )

Accessor to the current replicate counter string.

413{
414 ostringstream rpl;
415
416 rpl.fill('0');
417 rpl.width( (int)log10((double)_popPtr->getReplicates()) + 1);
419
420 return rpl.str();
421}
unsigned int getCurrentReplicate()
Definition: metapop.h:293

References _popPtr, Metapop::getCurrentReplicate(), and Metapop::getReplicates().

Referenced by getGenerationReplicateFileName(), and getReplicateFileName().

+ Here is the caller graph for this function:

◆ getReplicateFileName()

string & FileServices::getReplicateFileName ( )

Accessor to the current replicate file name.

382{
384
385 return _rep_filename;
386}

References _basename, _rep_filename, and getReplicateCounter().

Referenced by TTQFreqExtractor::FHwrite(), and FileHandler::get_filename().

+ Here is the caller graph for this function:

◆ getRootDir()

std::string & FileServices::getRootDir ( )

Accessor to the name of the simulation's root output directory.


406{
407 return _root_dir;
408}

References _root_dir.

Referenced by FileHandler::set_path().

+ Here is the caller graph for this function:

◆ getSampledPop()

Metapop * FileServices::getSampledPop ( )

Sets the down-sampled population and provides accessor to file handlers.

198{
199 // if the sampling parameters haven't been set, we return the main pop ptr
201 return _popPtr;
202
203 // if we already created a population sample, we return it:
206 {
207 return _sample_pop;
208 }
209
210#ifdef _DEBUG_
211 message("FileServices::setting sub-sampled pop (size = %i, age = %i): ", _patch_sample_size, _patch_sample_age);
212#endif
213
214 // else, population hasn't been sampled yet, create sample:
215
216 Patch *sample_patch, *src_patch;
217
218 //first time it is called, the pointer should be NULL upon instantiation of FileServices
219 if(!_sample_pop) {
220
221 _sample_pop = new Metapop();
222
223 } else {
224
225 // sampled pop already exists, we empty it (without deleting the individuals)
226
227 // remove the patches :
228 for(unsigned int i = 0; i < _sample_pop->getPatchArraySize(); ) {
229 // removePatch() resizes the array, i must stay = 0 to mimic pop_front() until array is empty
230 sample_patch = _sample_pop->removePatch(i);
231 sample_patch->clear(); // this resets all container's size to 0 without deleting content
232 delete sample_patch; // delete the patch, without deleting individuals because containers are seen as empty
233 }
234
235 }
236 // check the age flag:
237 if( _patch_sample_age != 0) {
238
239 // check if current pop age flag is compatible with user's choice:
240 // reset it to match with current age structure
243
244 } else { // the age flag wasn't set by the user
245
247
248 }
249
250 //need to set the age flag of the population
252
253 // stop here if age flag is null after checking:
254 if( _patch_sample_age == 0 )
255 fatal("The population cannot be sub-sampled for the age-class chosen (parameter \"files_sample_age\")\n Check your parameter file or contact the developers\n");
256
257#ifdef _DEBUG_
258 message("after check, sampling age is %i; ", _patch_sample_age);
259#endif
260
261 // add patches to match current parameters and patch sizes (discard empty patches)
262
263 for(unsigned int i = 0; i < _popPtr->getPatchNbr(); ++i) {
264
265 if( _popPtr->size(_patch_sample_age, i) == 0 ) continue; //skip empty patches
266
267 src_patch = _popPtr->getPatch(i);
268 // allocate new patches
269 sample_patch = new Patch();
270 sample_patch->setID(i);
271 sample_patch->set_K(src_patch->get_K());
272 sample_patch->set_KFem(src_patch->get_KFem());
273 sample_patch->set_KMal(src_patch->get_KMal());
274
275 // sub sample within patch, among offspring:
277
278 subSamplePatch(FEM, OFFSx, src_patch, sample_patch);
279 subSamplePatch(MAL, OFFSx, src_patch, sample_patch);
280 }
281
282 // sub sample within patch, among adults:
284
285 subSamplePatch(FEM, ADLTx, src_patch, sample_patch);
286 subSamplePatch(MAL, ADLTx, src_patch, sample_patch);
287 }
288
289 _sample_pop->addPatch( sample_patch );
290
291 }
292
295
296#ifdef _DEBUG_
297 message("sampled pop is: \n");
299#endif
300
301
304
305 return _sample_pop;
306}
void subSamplePatch(sex_t SEX, age_idx AGE, Patch *source_patch, Patch *patch)
Definition: fileservices.cc:310
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:80
void addPatch(Patch *patch)
Adds a patch to the population.
Definition: metapop.h:842
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:310
Patch * removePatch(unsigned int i)
Removes a patch from the patch array and returns it pointer.
Definition: metapop.h:825
unsigned int getPatchArraySize()
Definition: metapop.h:270
unsigned int getPatchNbr()
Definition: metapop.h:276
void setPatchNbr(unsigned int val)
Definition: metapop.h:287
age_t getCurrentAge()
Definition: metapop.h:297
void setPatchSizes(TMatrix &mat)
Definition: metapop.h:288
void show_up()
Definition: metapop.cc:1242
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
TMatrix * getPatchCapacities()
Definition: metapop.h:281
void setCurrentAge(age_t age)
Sets the age flag.
Definition: metapop.h:301
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
void setID(unsigned int i)
Definition: metapop.h:468
unsigned int get_K()
Definition: metapop.h:479
void set_KMal(unsigned int k)
Definition: metapop.h:471
void set_KFem(unsigned int k)
Definition: metapop.h:470
void set_K(unsigned int k)
Definition: metapop.h:469
unsigned int get_KFem()
Definition: metapop.h:481
unsigned int get_KMal()
Definition: metapop.h:482
void clear(sex_t SEX, age_idx AGE)
Sets the size of the appropriate container to zero.
Definition: metapop.h:632
void fatal(const char *str,...)
Definition: output.cc:96
void message(const char *message,...)
Definition: output.cc:40
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

References _patch_sample_age, _patch_sample_size, _popPtr, _sample_pop, _sampled_at_generation, _sampled_at_replicate, Metapop::addPatch(), ADLTx, ADULTS, Patch::clear(), fatal(), FEM, Patch::get_K(), Patch::get_KFem(), Patch::get_KMal(), Metapop::getCurrentAge(), Metapop::getCurrentGeneration(), Metapop::getCurrentReplicate(), Metapop::getPatch(), Metapop::getPatchArraySize(), Metapop::getPatchCapacities(), Metapop::getPatchNbr(), MAL, message(), OFFSPRG, OFFSx, Metapop::removePatch(), Patch::set_K(), Patch::set_KFem(), Patch::set_KMal(), Metapop::setCurrentAge(), Patch::setID(), Metapop::setPatchNbr(), Metapop::setPatchSizes(), Metapop::show_up(), Metapop::size(), and subSamplePatch().

Referenced by TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTNeutralGenesFH::FHwrite(), and TTQuantiFH::FHwrite().

+ Here is the caller graph for this function:

◆ init() [1/2]

virtual bool FileServices::init ( )
inlinevirtual

Implements Service.

99{return false;}

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ init() [2/2]

bool FileServices::init ( list< ParamSet * > &  params)

Checks if files with _basename already exist and save the simulation parameters in log files.

Parameters
paramsa ref to the list of the current parameters of the simulation
Returns
true if the files check is ok
false if the user wants to skip this simulation
86{
87 char yn;
88 bool ok;
89 file_it HIT;
90
91 _params = params;
92
93 _logWriter->set(0, 0, 0, 0, 0, "");
94
95 //first, build path and filename for each file handler
96 HIT = _writers.begin();
97
98 if(_myenv->isMaster()) message(" outputs: %s{",_root_dir.c_str());
99
100 while(HIT != _writers.end()) {
101 if(_myenv->isMaster()) message("%s%s*%s",
102 (*HIT)->get_path().c_str(),
103 ((*HIT)->get_path().size() !=0? "/":""),
104 (*HIT)->get_extension().c_str());
105 (*HIT)->init();
106 HIT++;
107
108 if(HIT != _writers.end() && _myenv->isMaster()) message(", ");
109 }
110 if(_myenv->isMaster()) message("}\n");
111
112 //then check if any file already exists
113check:
114
115 ok = true;
116 HIT = _writers.begin();
117 vector<string> local_files, Xing_files;
118
119 //we have to skip the first writer, it is the log-writer (always overwritten)
120 while(++HIT != _writers.end()) {
121
122 Xing_files = (*HIT)->ifExist();
123
124 if( Xing_files.size() != 0 ) {
125 local_files.insert(local_files.end(), Xing_files.begin(), Xing_files.end() );
126 ok = false;
127 } else
128 ok &= true;
129 }
130
131 if(!ok) {
132
133// warning("simulation filename \"%s\" already used on disc!", getBaseFileName().c_str());
134
135 for(unsigned int i=0; i < local_files.size(); ++i)
136 warning("\"%s\" exists", local_files[i].c_str());
137
138 //file mode is set during simulation setup, in SimRunner::init()
139 if(_mode == 0) { //"run"
140
141#if defined(_R_OUTPUT_) || defined(LOW_VERBOSE) || defined(USE_MPI)
142 yn = 's';
143 message("\nPlease choose an other base filename or move the existing file(s)\n");
144#else
145
146 message("\nDo you want to overwrite all the files that use it ? (y/n/s(kip)): ");
147 cin>>yn;
148#endif
149
150 } else if( _mode == 1 ) { //"overwrite"
151
152 warning("Overwriting existing files.\n\n");
153 yn = 'y';
154
155 } else if( _mode == 2 ) { //"skip" & "silent_run"
156
157 error("Files with the same simulation name already exist on disk!\n");
158 error("Choose another base filename or move the existing file(s)\n");
159 yn = 's';
160
161 } else if( _mode == 3 || _mode == 4) { // "dryrun" & "create_init"
162 //dryrun, pretend overwriting, silently
163 yn = 'y';
164 } else {
165 fatal("Run mode not properly set, check simulation parameter \"run_mode\".\n");
166 }
167
168
169 switch(yn) {
170 case 'y':
171 break;
172 case 's':
173 error("Skipping this simulation\n");
174 return false;
175 default: {
176 message("Please give a new output filename : ");
177 cin>>_basename;
178 goto check;
179 }
180 }
181 }
182
183 return true;
184}
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
bool isMaster() const
Definition: MPImanager.h:127
int error(const char *str,...)
Definition: output.cc:77
void warning(const char *str,...)
Definition: output.cc:58

References _basename, _logWriter, _mode, _myenv, _params, _root_dir, _writers, error(), fatal(), MPIenv::isMaster(), message(), FileHandler::set(), and warning().

◆ load()

void FileServices::load ( SimComponent sc)
virtual

Tells the SimComponent to load its file handlers.

Parameters
scthe SimComponent

Implements Service.

81{sc->loadFileServices(this);}
virtual void loadFileServices(FileServices *loader)=0
Loads the component's FileHandler onto the FileServices.

References SimComponent::loadFileServices().

Referenced by SimRunner::register_component().

+ Here is the caller graph for this function:

◆ log()

void FileServices::log ( string  message)

Write to the parameter logfile.

360{
362}
void log_message(string &logstr)
Definition: filehandler.cc:258

References _logWriter, FHLogWriter::log_message(), and message().

Referenced by Metapop::loadPopFromBinarySource(), SimRunner::run(), and LCE_Selection_base::set_std_rate_of_change().

+ Here is the caller graph for this function:

◆ log_simparams()

void FileServices::log_simparams ( )

Saves the current simulation parameters to the default parameter logfile.

350{
351 if(_mode == 4)
353 else
355}
void save_simparams(list< ParamSet * > &params)
Definition: filehandler.cc:193
void createInitFile(list< ParamSet * > &params)
Definition: filehandler.cc:222

References _logWriter, _mode, _params, FHLogWriter::createInitFile(), and FHLogWriter::save_simparams().

Referenced by SimRunner::run().

+ Here is the caller graph for this function:

◆ notify()

void FileServices::notify ( )
virtual

Implements Service.

189{
190 for (file_it file = _writers.begin(); file != _writers.end(); ++file) {
191 (*file)->update();
192 }
193}

References _writers.

Referenced by LCE_FileServicesNotifier::execute(), and SimRunner::Replicate_LOOP().

+ Here is the caller graph for this function:

◆ reset()

void FileServices::reset ( )
virtual

Clears the list of FileHandlers.

Implements Service.

341{
342 //Service::reset();
343 _writers.clear(); _writers.push_back(_logWriter);
344 _readers.clear();
345}

References _logWriter, _readers, and _writers.

Referenced by SimRunner::reset_services().

+ Here is the caller graph for this function:

◆ set_pop_ptr()

virtual void FileServices::set_pop_ptr ( Metapop pop)
inlinevirtual

Sets the Metapop reference.

114{_popPtr = pop;}

References _popPtr.

Referenced by SimRunner::init_components().

+ Here is the caller graph for this function:

◆ set_sampling_params()

void FileServices::set_sampling_params ( unsigned int  size,
age_t  age 
)
inline

Set the population sampling params.

References _patch_sample_age, and _patch_sample_size.

Referenced by LCE_FileServicesNotifier::loadFileServices().

+ Here is the caller graph for this function:

◆ setBasename()

void FileServices::setBasename ( string  name)

Sets the base file name of the simulation.

439{
440 _basename = name;
441}

References _basename.

Referenced by SimRunner::init().

+ Here is the caller graph for this function:

◆ setMode()

void FileServices::setMode ( unsigned int  m)
inline

Mode setter, determines if file will get overwritten or not.

120{_mode = m;}

References _mode.

Referenced by SimRunner::init().

+ Here is the caller graph for this function:

◆ setRootDir()

void FileServices::setRootDir ( string  name)

Sets the root directory of the simulation.

446{
447 _root_dir = name;
448
449 if(_root_dir.size() != 0 && _root_dir[_root_dir.length()-1] != '/')
450 _root_dir += "/";
451
452}

References _root_dir.

Referenced by SimRunner::init().

+ Here is the caller graph for this function:

◆ subSamplePatch()

void FileServices::subSamplePatch ( sex_t  SEX,
age_idx  AGE,
Patch source_patch,
Patch patch 
)
311{
312
313 int* sample = NULL;
314 int size = (int)source_patch->size(SEX, AGE), sample_size;
315 Individual *ind = 0;
316
317 sample_size = (_patch_sample_size < size ? _patch_sample_size : size);
318
319 if( patch->size(SEX, AGE) != 0) fatal("FileServices::subSamplePatch::receiver patch container is not empty before sampling\n");
320
321 if( sample_size != 0) {
322
323 sample = new int[sample_size];
324
325 RAND::Sample(0, size, sample_size, sample, false);
326
327 for(unsigned int j = 0; j < sample_size; ++j) {
328
329 ind = source_patch->get(SEX, AGE, sample[j]);
330
331 patch->add(SEX, AGE, ind);
332 }
333
334 delete [] sample;
335 }
336}
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:496
void add(sex_t SEX, age_idx AGE, Individual *ind)
Adds an individual to the appropriate container, increments its size, eventually resizing it.
Definition: metapop.h:549
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:532
static void Sample(const int from, const int to, const unsigned int num, int *result, bool replace)
Creates a sample of integers within range [from, to), with or without replacement.
Definition: Uniform.h:714

References _patch_sample_size, Patch::add(), fatal(), Patch::get(), RAND::Sample(), and Patch::size().

Referenced by getSampledPop().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _basename

string FileServices::_basename
private

the base file name of the simulation, read from the init file (param "filename")

Referenced by getBaseFileName(), getFirstReplicateFileName(), getGenerationReplicateFileName(), getReplicateFileName(), init(), and setBasename().

◆ _logWriter

FHLogWriter* FileServices::_logWriter
private

a FileHandler used to save the simulation parameters on disk.

Referenced by FileServices(), init(), log(), log_simparams(), reset(), and ~FileServices().

◆ _mode

unsigned int FileServices::_mode
private

File mode, sets behavior when file must be overwritten or not.

Referenced by getMode(), init(), log_simparams(), and setMode().

◆ _params

list< ParamSet* > FileServices::_params
private

the list of the parameters of the current simulation.

The list is created when init() is called from SimRunner::run().

Referenced by get_params(), init(), and log_simparams().

◆ _patch_sample_age

age_t FileServices::_patch_sample_age
private

◆ _patch_sample_size

unsigned int FileServices::_patch_sample_size
private

Number of individuals to sample from each patch for the file handlers.

Referenced by getSampledPop(), set_sampling_params(), and subSamplePatch().

◆ _popPtr

Metapop* FileServices::_popPtr
private

◆ _readers

list< FileHandler* > FileServices::_readers
private

the list of the FileHandler's registered by the SimComponent in input mode

Referenced by attach_reader(), getFirstReader(), getLastReader(), and reset().

◆ _rep_filename

string FileServices::_rep_filename
private

the file name associated with the current simulation replicate

Referenced by getFirstReplicateFileName(), and getReplicateFileName().

◆ _root_dir

string FileServices::_root_dir
private

the root directory for the simulation's results, read from the init file (param "root_dir")

Referenced by getRootDir(), init(), and setRootDir().

◆ _sample_pop

Metapop* FileServices::_sample_pop
private

Referenced by getSampledPop().

◆ _sampled_at_generation

int FileServices::_sampled_at_generation
private

Referenced by getSampledPop().

◆ _sampled_at_replicate

int FileServices::_sampled_at_replicate
private

Referenced by getSampledPop().

◆ _writers

list< FileHandler* > FileServices::_writers
private

the list of the FileHandler's registered by the SimComponent in output mode

Referenced by attach(), getFirstWriter(), getLastWriter(), init(), notify(), and reset().


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

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR