Nemo  2.4.0
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 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 ~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
780 : FileHandler(".ped"), _patch_sample_size(0) {}
FileHandler(const char *ext)
Definition: filehandler.h:106
int _patch_sample_size
Definition: metapop.h:777

◆ ~MPFileHandler()

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

Member Function Documentation

◆ createAndPrintSample()

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

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.

787 {}

◆ FHwrite()

void MPFileHandler::FHwrite ( )
virtual

Implements FileHandler.

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

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 
)
1309 {
1310  Individual* ind;
1311  for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
1312 
1313  ind = patch->get(SEX, AGE, j);
1314 
1315  FH<< ind->getID() << " " << ind->getFatherID() << " " << ind->getMotherID()
1316  << " " << SEX << " " << AGE << " " << ind->getHome()+1
1317  << " " << patch->getID()+1 << endl;
1318  }
1319 }

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
784 {_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.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR