Nemo  2.4.2
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
779 : FileHandler(".ped"), _patch_sample_size(0) {}
FileHandler(const char *ext)
Definition: filehandler.h:105
int _patch_sample_size
Definition: metapop.h:776

◆ ~MPFileHandler()

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

Member Function Documentation

◆ createAndPrintSample()

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

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.

786 {}

◆ FHwrite()

void MPFileHandler::FHwrite ( )
virtual

Implements FileHandler.

1259 {
1260  if (!_pop->isAlive()) return; //don't write anything if pop is extinct
1261 
1262 
1263  std::string filename = get_filename();
1264 
1265  std::ofstream FILE (filename.c_str(), ios::out);
1266 
1267  if(!FILE) fatal("could not open \"%s\" output file!!\n",filename.c_str());
1268 
1269  FILE << "ID dad mum sex age home pop\n";
1270 
1271  Patch* patch;
1272 
1273  if(_patch_sample_size == 0) {
1274 
1275  for(unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
1276 
1277  patch = _pop->getPatch(i);
1278 
1279  for(unsigned int S = 0; S < 2; ++S){
1280 
1281  printNoSample((sex_t)S, OFFSx, patch, FILE);
1282 
1283  printNoSample((sex_t)S, ADLTx, patch, FILE);
1284 
1285  }
1286  }
1287 
1288  } else {
1289 
1290  for(unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
1291 
1292  patch = _pop->getPatch(i);
1293 
1294  createAndPrintSample(OFFSx, patch, FILE);
1295 
1296  createAndPrintSample(ADLTx, patch, FILE);
1297  }
1298  }
1299 
1300  FILE.close();
1301 
1302 }
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:149
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:101
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1323
void printNoSample(sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1307
unsigned int getPatchNbr()
Definition: metapop.h:274
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:255
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:98
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34
@ OFFSx
Definition: types.h:40
@ ADLTx
Definition: types.h:40

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

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
783 {_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.2 by  doxygen 1.9.1

Catalogued on GSR