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

#include <metapop.h>

+ Inheritance diagram for MPFileHandler:
+ Collaboration diagram for MPFileHandler:

Public Member Functions

 MPFileHandler ()
 
virtual ~MPFileHandler ()
 
void setOption (int size)
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
void createAndPrintSample (age_idx AGE, Patch *patch, ofstream &FH)
 
void printNoSample (sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
 
- Public Member Functions inherited from FileHandler
 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...
 
Metapopget_pop_ptr ()
 Returns the pointer to the current metapop through the FileServices interface. More...
 
void set_pop_ptr (Metapop *pop_ptr)
 
FileServicesget_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)
 
TMatrixget_OccMatrix ()
 
void set_OccMatrix (TMatrix *occ)
 
bool get_isMasterExec ()
 
void set_isMasterExec (bool is)
 
- Public Member Functions inherited from Handler
virtual void init ()=0
 Inits state. More...
 
virtual void update ()=0
 Updates the handler state. More...
 
virtual ~Handler ()
 

Private Attributes

int _patch_sample_size
 

Additional Inherited Members

- Protected Attributes inherited from FileHandler
Metapop_pop
 Pointer to the current metapop, set during initialization within the init function. More...
 

Constructor & Destructor Documentation

◆ MPFileHandler()

MPFileHandler::MPFileHandler ( )
inline
737: FileHandler(".ped"), _patch_sample_size(0) {}
Interface to handle file input/output for any SimComponent.
Definition: filehandler.h:53
int _patch_sample_size
Definition: metapop.h:734

◆ ~MPFileHandler()

virtual MPFileHandler::~MPFileHandler ( )
inlinevirtual
739{}

Member Function Documentation

◆ createAndPrintSample()

void MPFileHandler::createAndPrintSample ( age_idx  AGE,
Patch patch,
ofstream &  FH 
)
1326{
1327 Individual* ind;
1328 unsigned int size_fem = patch->size(FEM, AGE);
1329 unsigned int size_mal = patch->size(MAL, AGE);
1330 unsigned int sample_size;
1331
1332 int* sample = NULL;
1333
1334 //Females -----------------------------------------------------------------------------
1335 sample_size = (_patch_sample_size < (int)size_fem ? _patch_sample_size : size_fem);
1336
1337 if( sample_size != 0) {
1338
1339 sample = new int[sample_size];
1340
1341 RAND::Sample(0, size_fem, sample_size, sample, false);
1342
1343 for(unsigned int j = 0; j < sample_size; ++j) {
1344
1345 ind = patch->get(FEM, AGE, sample[j]);
1346
1347 FH<< ind->getID() << " " << ind->getFatherID() << " " << ind->getMotherID()
1348 << " " << FEM << " " << AGE << " " << ind->getHome()+1
1349 << " " << patch->getID()+1 << endl;
1350 }
1351 }
1352
1353 //Males -------------------------------------------------------------------------------
1354 sample_size = (_patch_sample_size < (int)size_mal ? _patch_sample_size : size_mal);
1355
1356 if( sample_size != 0) {
1357
1358 if(sample) delete [] sample;
1359
1360 sample = new int[sample_size];
1361
1362 RAND::Sample(0, size_mal, sample_size, sample, false);
1363
1364 for(unsigned int j = 0; j < sample_size; ++j) {
1365
1366 ind = patch->get(MAL, AGE, sample[j]);
1367
1368 FH<< ind->getID() << " " << ind->getFatherID() << " " << ind->getMotherID()
1369 << " " << MAL << " " << AGE << " " << ind->getHome()+1
1370 << " " << patch->getID()+1 << endl;
1371 }
1372 }
1373
1374 if(sample) delete [] sample;
1375}
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
unsigned long getID()
Definition: individual.h:122
unsigned short getHome()
Definition: individual.h:128
unsigned long getMotherID()
Definition: individual.h:125
unsigned long getFatherID()
Definition: individual.h:124
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
unsigned int getID()
Definition: metapop.h:478
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
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

References _patch_sample_size, FEM, Patch::get(), Individual::getFatherID(), Individual::getHome(), Individual::getID(), Patch::getID(), Individual::getMotherID(), MAL, RAND::Sample(), and Patch::size().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ FHread()

virtual void MPFileHandler::FHread ( string &  filename)
inlinevirtual

Implements FileHandler.

744{}

◆ FHwrite()

void MPFileHandler::FHwrite ( )
virtual

Implements FileHandler.

1261{
1262 if (!_pop->isAlive()) return; //don't write anything if pop is extinct
1263
1264
1265 std::string filename = get_filename();
1266
1267 std::ofstream FILE (filename.c_str(), ios::out);
1268
1269 if(!FILE) fatal("could not open \"%s\" output file!!\n",filename.c_str());
1270
1271 FILE << "ID dad mum sex age home pop\n";
1272
1273 Patch* patch;
1274
1275 if(_patch_sample_size == 0) {
1276
1277 for(unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
1278
1279 patch = _pop->getPatch(i);
1280
1281 for(unsigned int S = 0; S < 2; ++S){
1282
1283 printNoSample((sex_t)S, OFFSx, patch, FILE);
1284
1285 printNoSample((sex_t)S, ADLTx, patch, FILE);
1286
1287 }
1288 }
1289
1290 } else {
1291
1292 for(unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
1293
1294 patch = _pop->getPatch(i);
1295
1296 createAndPrintSample(OFFSx, patch, FILE);
1297
1298 createAndPrintSample(ADLTx, patch, FILE);
1299 }
1300 }
1301
1302 FILE.close();
1303
1304}
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:151
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:103
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1325
void printNoSample(sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1309
unsigned int getPatchNbr()
Definition: metapop.h:276
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class.
Definition: metapop.h:307
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
void fatal(const char *str,...)
Definition: output.cc:96
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

References _patch_sample_size, FileHandler::_pop, ADLTx, createAndPrintSample(), fatal(), FileHandler::get_filename(), Metapop::getPatch(), Metapop::getPatchNbr(), Metapop::isAlive(), OFFSx, and printNoSample().

◆ printNoSample()

void MPFileHandler::printNoSample ( sex_t  SEX,
age_idx  AGE,
Patch patch,
ofstream &  FH 
)
1310{
1311 Individual* ind;
1312 for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
1313
1314 ind = patch->get(SEX, AGE, j);
1315
1316 FH<< ind->getID() << " " << ind->getFatherID() << " " << ind->getMotherID()
1317 << " " << SEX << " " << AGE << " " << ind->getHome()+1
1318 << " " << patch->getID()+1 << endl;
1319 }
1320}

References Patch::get(), Individual::getFatherID(), Individual::getHome(), Individual::getID(), Patch::getID(), Individual::getMotherID(), and Patch::size().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ setOption()

void MPFileHandler::setOption ( int  size)
inline
741{_patch_sample_size = size;}

References _patch_sample_size.

Referenced by Metapop::loadFileServices().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _patch_sample_size

int MPFileHandler::_patch_sample_size
private

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