Nemo
2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
|
A class to manage the files associated with each components of the simulation. More...
#include <fileservices.h>
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 * > ¶ms) |
Checks if files with _basename already exist and save the simulation parameters in log files. More... | |
virtual Metapop * | get_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... | |
FileHandler * | getReader (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... | |
Metapop * | getSampledPop () |
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... | |
![]() | |
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 |
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.
typedef std::list<FileHandler*>::const_iterator FileServices::file_it |
FileServices::FileServices | ( | ) |
References _logWriter, and attach().
|
virtual |
References _logWriter.
|
virtual |
Attaches the FileHandler to the current list (_writers) of the FileServices.
FH | the FileHandler |
Implements Service.
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().
|
virtual |
Attaches the FileHandler to the current list (_readers) of the FileServices.
FH | the FileHandler |
References _readers, and FileHandler::set_service().
Referenced by attach(), LCE_Cross::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), and TProtoQuanti::loadFileServices().
|
inline |
Accessor to the list of the current parameters of the simulation.
References _params.
Referenced by BinaryDataSaver::printHeader().
|
inlinevirtual |
Accessor to the pointer to the main population.
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().
string & FileServices::getBaseFileName | ( | ) |
Accessor to the base file name of the simulation.
References _basename.
Referenced by FHLogWriter::createInitFile(), LCE_StatFH::FHwrite(), BinaryDataSaver::finish(), FileHandler::get_filename(), BinaryDataSaver::ifExist(), FileHandler::ifExist(), LCE_StatFH::ifExist(), SimRunner::printLog(), LCE_StatFH::PrintStat_byGen(), SimRunner::run(), and SimRunner::runPostExecReplicateWise().
|
inline |
Accessor to first element of the list of input FileHandlers.
References _readers.
Referenced by getReader().
string & FileServices::getFirstReplicateFileName | ( | ) |
Accessor to the first replicate file name.
References _basename, _myenv, _popPtr, _rep_filename, Metapop::getReplicates(), and MPIenv::workerRank().
|
inline |
Accessor to first element of the list of output FileHandlers.
References _writers.
Referenced by SimRunner::printLog().
string FileServices::getGenerationCounter | ( | ) |
Accessor to the current generation counter string.
References _popPtr, Metapop::getCurrentGeneration(), and Metapop::getGenerations().
Referenced by getGenerationReplicateFileName().
string FileServices::getGenerationReplicateFileName | ( | ) |
Accessor to the current file name with generation and replicate counters added.
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().
|
inline |
Accessor to last element of the list of input FileHandlers.
References _readers.
Referenced by getReader().
|
inline |
Accessor to last element of the list of output FileHandlers.
References _writers.
Referenced by SimRunner::printLog().
|
inline |
Writting mode getter.
References _mode.
Referenced by BinaryDataSaver::finish().
FileHandler * FileServices::getReader | ( | string & | type | ) |
Accessor to a specific file handler specified by its extension string.
References getFirstReader(), and getLastReader().
Referenced by Metapop::loadPopFromTraitFile().
string FileServices::getReplicateCounter | ( | ) |
Accessor to the current replicate counter string.
References _popPtr, Metapop::getCurrentReplicate(), and Metapop::getReplicates().
Referenced by getGenerationReplicateFileName(), and getReplicateFileName().
string & FileServices::getReplicateFileName | ( | ) |
Accessor to the current replicate file name.
References _basename, _rep_filename, and getReplicateCounter().
Referenced by TTQFreqExtractor::FHwrite(), and FileHandler::get_filename().
std::string & FileServices::getRootDir | ( | ) |
Accessor to the name of the simulation's root output directory.
References _root_dir.
Referenced by FileHandler::set_path().
Metapop * FileServices::getSampledPop | ( | ) |
Sets the down-sampled population and provides accessor to file handlers.
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().
|
inlinevirtual |
Implements Service.
Referenced by SimRunner::run().
bool FileServices::init | ( | list< ParamSet * > & | params | ) |
Checks if files with _basename already exist and save the simulation parameters in log files.
params | a ref to the list of the current parameters of the simulation |
References _basename, _logWriter, _mode, _myenv, _params, _root_dir, _writers, error(), fatal(), MPIenv::isMaster(), message(), FileHandler::set(), and warning().
|
virtual |
Tells the SimComponent to load its file handlers.
sc | the SimComponent |
Implements Service.
References SimComponent::loadFileServices().
Referenced by SimRunner::register_component().
void FileServices::log | ( | string | message | ) |
Write to the parameter logfile.
References _logWriter, FHLogWriter::log_message(), and message().
Referenced by Metapop::loadPopFromBinarySource(), SimRunner::run(), and LCE_Selection_base::set_std_rate_of_change().
void FileServices::log_simparams | ( | ) |
Saves the current simulation parameters to the default parameter logfile.
References _logWriter, _mode, _params, FHLogWriter::createInitFile(), and FHLogWriter::save_simparams().
Referenced by SimRunner::run().
|
virtual |
Implements Service.
References _writers.
Referenced by LCE_FileServicesNotifier::execute(), and SimRunner::Replicate_LOOP().
|
virtual |
Clears the list of FileHandlers.
Implements Service.
References _logWriter, _readers, and _writers.
Referenced by SimRunner::reset_services().
|
inlinevirtual |
Sets the Metapop reference.
References _popPtr.
Referenced by SimRunner::init_components().
Set the population sampling params.
References _patch_sample_age, and _patch_sample_size.
Referenced by LCE_FileServicesNotifier::loadFileServices().
void FileServices::setBasename | ( | string | name | ) |
Sets the base file name of the simulation.
References _basename.
Referenced by SimRunner::init().
|
inline |
Mode setter, determines if file will get overwritten or not.
References _mode.
Referenced by SimRunner::init().
void FileServices::setRootDir | ( | string | name | ) |
References _patch_sample_size, Patch::add(), fatal(), Patch::get(), RAND::Sample(), and Patch::size().
Referenced by getSampledPop().
|
private |
the base file name of the simulation, read from the init file (param "filename")
Referenced by getBaseFileName(), getFirstReplicateFileName(), getGenerationReplicateFileName(), getReplicateFileName(), init(), and setBasename().
|
private |
a FileHandler used to save the simulation parameters on disk.
Referenced by FileServices(), init(), log(), log_simparams(), reset(), and ~FileServices().
|
private |
File mode, sets behavior when file must be overwritten or not.
Referenced by getMode(), init(), log_simparams(), and setMode().
|
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().
|
private |
Referenced by getSampledPop(), and set_sampling_params().
|
private |
Number of individuals to sample from each patch for the file handlers.
Referenced by getSampledPop(), set_sampling_params(), and subSamplePatch().
|
private |
a pointer to the current Metapop
Referenced by get_pop_ptr(), getFirstReplicateFileName(), getGenerationCounter(), getReplicateCounter(), getSampledPop(), and set_pop_ptr().
|
private |
the list of the FileHandler's registered by the SimComponent in input mode
Referenced by attach_reader(), getFirstReader(), getLastReader(), and reset().
|
private |
the file name associated with the current simulation replicate
Referenced by getFirstReplicateFileName(), and getReplicateFileName().
|
private |
the root directory for the simulation's results, read from the init file (param "root_dir")
Referenced by getRootDir(), init(), and setRootDir().
|
private |
Referenced by getSampledPop().
|
private |
Referenced by getSampledPop().
|
private |
Referenced by getSampledPop().
|
private |
the list of the FileHandler's registered by the SimComponent in output mode
Referenced by attach(), getFirstWriter(), getLastWriter(), init(), notify(), and reset().