Nemo
2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
|
Interface to handle file input/output for any SimComponent. More...
#include <filehandler.h>
Public Member Functions | |
FileHandler (const char *ext) | |
virtual | ~FileHandler () |
virtual void | init () |
Called by notifier during simulation setup, performs file checking. More... | |
virtual vector< string > | ifExist () |
Checks if any file associated with the current file name already exists on disk. More... | |
virtual void | set (bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path) |
Sets the hanlder parameters. More... | |
virtual void | set_multi (bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path) |
virtual void | FHwrite ()=0 |
Default behavior of the class, called by Handler::update(). More... | |
virtual void | FHread (string &filename)=0 |
Default input function. More... | |
virtual void | update () |
Updates the inner replicate and generation counters and calls FHwrite if needed by the the periodicity of the file. More... | |
Accessors | |
Metapop * | get_pop_ptr () |
Returns the pointer to the current metapop through the FileServices interface. More... | |
void | set_pop_ptr (Metapop *pop_ptr) |
FileServices * | get_service () |
Returns pointer to the FileServices. More... | |
void | set_service (FileServices *srv) |
std::string & | get_path () |
void | set_path () |
std::string & | get_extension () |
void | set_extension (const char *ext) |
std::string & | get_filename () |
Builds and returns the current file name depending on the periodicity of the file. More... | |
bool | get_isInputHandler () |
void | set_isInputHandler (bool val) |
bool | get_isReplicatePeriodic () |
void | set_isReplicatePeriodic (bool val) |
unsigned int | get_ReplicateOccurrence () |
void | set_ReplicateOccurrence (unsigned int val) |
bool | get_isGenerationPeriodic () |
void | set_isGenerationPeriodic (bool val) |
unsigned int | get_GenerationOccurrence () |
void | set_GenerationOccurrence (unsigned int val) |
unsigned int | get_ExecRank () |
unused yet... More... | |
void | set_ExecRank (int val) |
TMatrix * | get_OccMatrix () |
void | set_OccMatrix (TMatrix *occ) |
bool | get_isMasterExec () |
void | set_isMasterExec (bool is) |
![]() | |
virtual void | init ()=0 |
Inits state. More... | |
virtual void | update ()=0 |
Updates the handler state. More... | |
virtual | ~Handler () |
Protected Attributes | |
Metapop * | _pop |
Pointer to the current metapop, set during initialization within the init function. More... | |
Private Attributes | |
FileServices * | _service |
Link to the files manager. More... | |
bool | _isMasterExec |
Flag telling if the file must be written by the master or the worker node. More... | |
bool | _isInputHandler |
Writing mode flag. More... | |
bool | _isReplicatePeriodic |
Flag telling if the file should be written each replicate. More... | |
bool | _isGenerationPeriodic |
Flag setting the per generation periodicity behaviour of the file. More... | |
unsigned int | _ReplicateOccurrence |
Tells every what replicate the file should be written. More... | |
unsigned int | _GenerationOccurrence |
Tells every what generation the file should be written. More... | |
unsigned int | _current_replicate |
The current replicate number of the simulation. More... | |
unsigned int | _current_generation |
The current generation number of the simulation. More... | |
TMatrix | _multipleOccurences |
Multiple occurences. More... | |
list< int >::const_iterator | _genITER |
list< int > | _generations |
unsigned int | _ExecRank |
unused... yet More... | |
std::string | _path |
File path as set during initialization. More... | |
std::string | _extension |
File extension, should be specific to the implementation. More... | |
std::string | _current_filename |
The current filename as set by FileHandler::get_filename(). More... | |
Interface to handle file input/output for any SimComponent.
Stores the periodicity parameters and the file path and extension. The replicate file name is given by the FileServices. A file handler might be set to write output at a specific generation of a specific replicate or at some periodic time during the simulation. The default writing mode of a FileHandler is in output and is added as a 'writer' to the File Services as such using the FileServices::attach mode. The _isInputHandler flag is thus set to FALSE by default. To set a FileHandler as a reader instead of a writer, the method FileHandler::set_isInputHandler(TRUE) must be called prior to attaching it to the FileServices using the FileServices::attach_reader method. Furthermore, a single instance of a FileHandler can be attached as both a writer and a reader by setting the _isInputHandler flag to TRUE and then using the FileServices::attach method to add it to the list of both the reader and writers. Note on memory management: the FileServices class only deals with its lists of FileHandlers pointers and will never try to delete any one of those. All memory management must thus be taken care of by the user class (typically the TraitPrototype...).
|
inline |
|
inlinevirtual |
|
pure virtual |
Default input function.
Loads a pop from the genotypes read from the input file.
Implemented in BinaryDataSaver, FHLogWriter, FHPedigreeReader, LCE_SelectionFH, MPFileHandler, FileMergerFH, LCE_StatFH, TTBDMI_FH, TTDeletMutBitstrFH, TTNeutralGenesFH, TTQuantiFH, TTQFreqExtractor, TTWolbachiaFH, TraitFileHandler< TP >, and EventFileHandler< LCE >.
Referenced by Metapop::loadPopFromTraitFile().
|
pure virtual |
Default behavior of the class, called by Handler::update().
Implemented in BinaryDataSaver, FHLogWriter, FHPedigreeReader, LCE_SelectionFH, MPFileHandler, FileMergerFH, LCE_StatFH, TTBDMI_FH, TTDeletMutBitstrFH, TTNeutralGenesFH, TTQuantiFH, TTQFreqExtractor, TTWolbachiaFH, TraitFileHandler< TP >, TraitFileHandler< TProtoBDMI >, TraitFileHandler< TProtoDeletMutations_bitstring >, TraitFileHandler< TProtoNeutralGenes >, TraitFileHandler< TProtoQuanti >, EventFileHandler< LCE >, EventFileHandler< LCE_Cross >, EventFileHandler< LCE_FileServicesNotifier >, EventFileHandler< LCE_Selection_base >, and EventFileHandler< LCE_Breed_Wolbachia >.
Referenced by SimRunner::Replicate_LOOP(), and update().
|
inline |
|
inline |
References _extension.
Referenced by LCE_StatFH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTQFreqExtractor::FHwrite(), BinaryDataSaver::ifExist(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_TAB(), and TTNeutralGenesFH::write_varcompWC().
string & FileHandler::get_filename | ( | ) |
Builds and returns the current file name depending on the periodicity of the file.
References _current_filename, _extension, _isGenerationPeriodic, _isReplicatePeriodic, _path, _service, FileServices::getBaseFileName(), FileServices::getGenerationReplicateFileName(), and FileServices::getReplicateFileName().
Referenced by LCE_SelectionFH::FHwrite(), MPFileHandler::FHwrite(), TTBDMI_FH::FHwrite(), TTWolbachiaFH::FHwrite(), BinaryDataSaver::finish(), FHLogWriter::open_logfile4writing(), BinaryDataSaver::printHeader(), BinaryDataSaver::setFileDescriptor(), and TTQuantiFH::write_TABLE().
|
inline |
References _GenerationOccurrence.
Referenced by TTQFreqExtractor::FHwrite(), and BinaryDataSaver::ifExist().
|
inline |
References _isGenerationPeriodic.
|
inline |
References _isInputHandler.
Referenced by FileServices::attach().
|
inline |
References _isMasterExec.
|
inline |
References _isReplicatePeriodic.
|
inline |
References _multipleOccurences.
|
inline |
References _path.
Referenced by LCE_StatFH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTQFreqExtractor::FHwrite(), BinaryDataSaver::finish(), BinaryDataSaver::ifExist(), LCE_StatFH::ifExist(), LCE_StatFH::PrintStat_byGen(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_PLINK(), TTQuantiFH::write_PLINK(), TTNeutralGenesFH::write_TAB(), and TTNeutralGenesFH::write_varcompWC().
|
inline |
Returns the pointer to the current metapop through the FileServices interface.
References _pop.
Referenced by TTDeletMutBitstrFH::FHwrite().
|
inline |
References _ReplicateOccurrence.
Referenced by BinaryDataSaver::ifExist().
|
inline |
Returns pointer to the FileServices.
References _service.
Referenced by FHLogWriter::createInitFile(), TTNeutralGenesFH::FHread(), LCE_StatFH::FHwrite(), TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTNeutralGenesFH::FHwrite(), TTQuantiFH::FHwrite(), TTQFreqExtractor::FHwrite(), BinaryDataSaver::finish(), BinaryDataSaver::ifExist(), LCE_StatFH::ifExist(), BinaryDataSaver::printHeader(), LCE_StatFH::PrintStat_byGen(), TTNeutralGenesFH::write_Fst_i(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_PLINK(), TTQuantiFH::write_PLINK(), TTNeutralGenesFH::write_TAB(), TTQuantiFH::write_TABLE(), and TTNeutralGenesFH::write_varcompWC().
|
virtual |
Checks if any file associated with the current file name already exists on disk.
Only checks wether the first replicate file is present.
Reimplemented in BinaryDataSaver, and LCE_StatFH.
References _extension, _GenerationOccurrence, _isGenerationPeriodic, _isReplicatePeriodic, _path, _pop, _ReplicateOccurrence, _service, FileServices::getBaseFileName(), Metapop::getGenerations(), and Metapop::getReplicates().
|
virtual |
Called by notifier during simulation setup, performs file checking.
Implements Handler.
References _GenerationOccurrence, _pop, _ReplicateOccurrence, _service, FileServices::get_pop_ptr(), Metapop::getGenerations(), Metapop::getReplicates(), and set_path().
|
inlinevirtual |
Sets the hanlder parameters.
rpl_per | replicate periodicity |
gen_per | generation periodicity |
rpl_occ | replicate occurence |
gen_occ | generation occurence |
rank | the rank in the life cycle, actualy unused... |
path | the file path |
References _path, set_ExecRank(), set_GenerationOccurrence(), set_isGenerationPeriodic(), set_isReplicatePeriodic(), and set_ReplicateOccurrence().
Referenced by FileServices::init(), LCE_StatFH::LCE_StatFH(), Metapop::loadFileServices(), EventFileHandler< LCE >::set(), TraitFileHandler< TP >::set(), BinaryDataSaver::setParameters(), and LCE_StatServiceNotifier::setParameters().
|
inline |
|
inline |
References _extension.
Referenced by TProtoNeutralGenes::loadFileServices().
|
inline |
References _GenerationOccurrence.
Referenced by set(), and set_multi().
|
inline |
References _isGenerationPeriodic.
Referenced by set(), and set_multi().
|
inline |
References _isInputHandler.
Referenced by LCE_Cross::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), and TProtoQuanti::loadFileServices().
|
inline |
References _isMasterExec.
Referenced by LCE_StatFH::LCE_StatFH().
|
inline |
References _isReplicatePeriodic.
Referenced by set(), and set_multi().
|
inlinevirtual |
References _path, set_GenerationOccurrence(), set_isGenerationPeriodic(), set_isReplicatePeriodic(), set_OccMatrix(), and set_ReplicateOccurrence().
Referenced by LCE_Selection_base::loadFileServices(), Metapop::loadFileServices(), LCE_FileServicesNotifier::loadFileServices(), TProtoBDMI::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), and TProtoQuanti::loadFileServices().
|
inline |
References _generations, _genITER, _multipleOccurences, TMatrix::get(), TMatrix::getValArray(), TMatrix::ncols(), TMatrix::nrows(), and TMatrix::reset().
Referenced by set_multi().
void FileHandler::set_path | ( | ) |
References _path, _service, error(), FileServices::getRootDir(), and warning().
Referenced by init().
|
inline |
References _pop.
Referenced by Metapop::loadPopFromTraitFile().
|
inline |
References _ReplicateOccurrence.
Referenced by set(), and set_multi().
|
inline |
References _service.
Referenced by FileServices::attach(), and FileServices::attach_reader().
|
virtual |
Updates the inner replicate and generation counters and calls FHwrite if needed by the the periodicity of the file.
Implements Handler.
References _current_generation, _current_replicate, _GenerationOccurrence, _generations, _genITER, _isGenerationPeriodic, _isMasterExec, _isReplicatePeriodic, _myenv, _pop, _ReplicateOccurrence, FHwrite(), Metapop::getCurrentGeneration(), Metapop::getCurrentReplicate(), and MPIenv::isMaster().
|
private |
The current filename as set by FileHandler::get_filename().
Is composed by putting together the following strings: FileHandler::_path, FileServices::_basename (+ replicate and generation counters if needed), and FileHandler::_extension.
Referenced by get_filename().
|
private |
The current generation number of the simulation.
Set by FileHandler::update().
Referenced by update().
|
private |
The current replicate number of the simulation.
Set by FileHandler::update().
Referenced by update().
|
private |
unused... yet
Referenced by get_ExecRank(), and set_ExecRank().
|
private |
File extension, should be specific to the implementation.
Is set during construction.
Referenced by get_extension(), get_filename(), ifExist(), and set_extension().
|
private |
Tells every what generation the file should be written.
Set by the set() method below.
Referenced by get_GenerationOccurrence(), ifExist(), init(), set_GenerationOccurrence(), and update().
|
private |
Referenced by set_OccMatrix(), and update().
|
private |
Referenced by set_OccMatrix(), and update().
|
private |
Flag setting the per generation periodicity behaviour of the file.
Referenced by get_filename(), get_isGenerationPeriodic(), ifExist(), set_isGenerationPeriodic(), and update().
|
private |
|
private |
Flag telling if the file must be written by the master or the worker node.
An example of master-only file is the stats files (.txt and _bygen.txt) that aggregate the stats from each node. Binary files or FSTAT files are written by the worker nodes, each file beeing written for one replicate only. The default behaviour is to be TRUE in the non-MPI version and FALSE in the MPI version.
Referenced by get_isMasterExec(), set_isMasterExec(), and update().
|
private |
Flag telling if the file should be written each replicate.
Referenced by get_filename(), get_isReplicatePeriodic(), ifExist(), set_isReplicatePeriodic(), and update().
|
private |
Multiple occurences.
Referenced by get_OccMatrix(), and set_OccMatrix().
|
private |
File path as set during initialization.
Usually user-defined.
Referenced by get_filename(), get_path(), ifExist(), set(), set_multi(), and set_path().
|
protected |
Pointer to the current metapop, set during initialization within the init function.
Referenced by TTDeletMutBitstrFH::FHread(), TTQuantiFH::FHread(), LCE_SelectionFH::FHwrite(), MPFileHandler::FHwrite(), TTBDMI_FH::FHwrite(), TTDeletMutBitstrFH::FHwrite(), TTNeutralGenesFH::FHwrite(), TTQuantiFH::FHwrite(), get_pop_ptr(), BinaryDataSaver::ifExist(), ifExist(), init(), TTQuantiFH::print(), set_pop_ptr(), update(), TTNeutralGenesFH::write_FSTAT(), TTNeutralGenesFH::write_GENEPOP(), TTNeutralGenesFH::write_PLINK(), TTQuantiFH::write_PLINK(), TTNeutralGenesFH::write_PLINK_BED(), TTNeutralGenesFH::write_TAB(), and TTQuantiFH::write_TABLE().
|
private |
Tells every what replicate the file should be written.
Set by the set() method below.
Referenced by get_ReplicateOccurrence(), ifExist(), init(), set_ReplicateOccurrence(), and update().
|
private |
Link to the files manager.
Referenced by get_filename(), get_service(), ifExist(), init(), set_path(), and set_service().