Nemo  2.3.46
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 bool 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 ( )
inline
728 : FileHandler(".ped"), _patch_sample_size(0) {}
FileHandler(const char *ext)
Definition: filehandler.h:107
int _patch_sample_size
Definition: metapop.h:725
virtual MPFileHandler::~MPFileHandler ( )
inlinevirtual
730 {}

Member Function Documentation

void MPFileHandler::createAndPrintSample ( age_idx  AGE,
Patch patch,
ofstream &  FH 
)

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().

1135 {
1136  Individual* ind;
1137  unsigned int size_fem = patch->size(FEM, AGE);
1138  unsigned int size_mal = patch->size(MAL, AGE);
1139  unsigned int sample_size;
1140 
1141  int* sample = NULL;
1142 
1143  //Females -----------------------------------------------------------------------------
1144  sample_size = (_patch_sample_size < size_fem ? _patch_sample_size : size_fem);
1145 
1146  if( sample_size != 0) {
1147 
1148  sample = new int[sample_size];
1149 
1150  RAND::Sample(0, size_fem, sample_size, sample, false);
1151 
1152  for(unsigned int j = 0; j < sample_size; ++j) {
1153 
1154  ind = patch->get(FEM, AGE, sample[j]);
1155 
1156  FH<< ind->getID() << " " << ind->getFatherID() << " " << ind->getMotherID()
1157  << " " << FEM << " " << AGE << " " << ind->getHome()+1
1158  << " " << patch->getID()+1 << endl;
1159  }
1160  }
1161 
1162  //Males -------------------------------------------------------------------------------
1163  sample_size = (_patch_sample_size < size_mal ? _patch_sample_size : size_mal);
1164 
1165  if( sample_size != 0) {
1166 
1167  if(sample) delete [] sample;
1168 
1169  sample = new int[sample_size];
1170 
1171  RAND::Sample(0, size_mal, sample_size, sample, false);
1172 
1173  for(unsigned int j = 0; j < sample_size; ++j) {
1174 
1175  ind = patch->get(MAL, AGE, sample[j]);
1176 
1177  FH<< ind->getID() << " " << ind->getFatherID() << " " << ind->getMotherID()
1178  << " " << MAL << " " << AGE << " " << ind->getHome()+1
1179  << " " << patch->getID()+1 << endl;
1180  }
1181  }
1182 
1183  if(sample) delete [] sample;
1184 }
unsigned long getID()
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:487
unsigned long getMotherID()
Definition: individual.h:125
unsigned int getID()
Definition: metapop.h:469
unsigned long getFatherID()
Definition: individual.h:124
unsigned short getHome()
Definition: individual.h:128
Definition: types.h:37
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:523
static void Sample(int from, int to, unsigned int num, int *result, bool replace)
Definition: Uniform.h:512
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
Definition: types.h:37
int _patch_sample_size
Definition: metapop.h:725
virtual void MPFileHandler::FHread ( string &  filename)
inlinevirtual

Implements FileHandler.

735 {}
void MPFileHandler::FHwrite ( )
virtual

Implements FileHandler.

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

1076 {
1077  if (!_pop->isAlive()) return; //don't write anything if pop is extinct
1078 
1079 
1080  std::string filename = get_filename();
1081 
1082  std::ofstream FILE (filename.c_str(), ios::out);
1083 
1084  if(!FILE) fatal("could not open \"%s\" output file!!\n",filename.c_str());
1085 
1086  FILE << "ID dad mum sex age home pop\n";
1087 
1088  Patch* patch;
1089 
1090  if(_patch_sample_size == 0) {
1091 
1092  for(unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
1093 
1094  patch = _pop->getPatch(i);
1095 
1096  for(unsigned int S = 0; S < 2; ++S){
1097 
1098  printNoSample((sex_t)S, OFFSx, patch, FILE);
1099 
1100  printNoSample((sex_t)S, ADLTx, patch, FILE);
1101 
1102  }
1103  }
1104 
1105  } else {
1106 
1107  for(unsigned int i = 0; i < _pop->getPatchNbr(); ++i) {
1108 
1109  patch = _pop->getPatch(i);
1110 
1111  createAndPrintSample(OFFSx, patch, FILE);
1112 
1113  createAndPrintSample(ADLTx, patch, FILE);
1114  }
1115  }
1116 
1117  FILE.close();
1118 
1119 }
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:148
void fatal(const char *str,...)
Definition: output.cc:90
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
bool isAlive()
Checks if the population still contains at least one individual in any sex or age class...
Definition: metapop.h:299
unsigned int getPatchNbr()
Definition: metapop.h:270
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
Definition: types.h:42
void createAndPrintSample(age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1134
Definition: types.h:42
int _patch_sample_size
Definition: metapop.h:725
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:103
void printNoSample(sex_t SEX, age_idx AGE, Patch *patch, ofstream &FH)
Definition: metapop.cc:1121
void MPFileHandler::printNoSample ( sex_t  SEX,
age_idx  AGE,
Patch patch,
ofstream &  FH 
)

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

Referenced by FHwrite().

1122 {
1123  Individual* ind;
1124  for(unsigned int j = 0; j < patch->size(SEX, AGE); ++j) {
1125 
1126  ind = patch->get(SEX, AGE, j);
1127 
1128  FH<< ind->getID() << " " << ind->getFatherID() << " " << ind->getMotherID()
1129  << " " << SEX << " " << AGE << " " << ind->getHome()+1
1130  << " " << patch->getID()+1 << endl;
1131  }
1132 }
unsigned long getID()
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:487
unsigned long getMotherID()
Definition: individual.h:125
unsigned int getID()
Definition: metapop.h:469
unsigned long getFatherID()
Definition: individual.h:124
unsigned short getHome()
Definition: individual.h:128
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:523
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
void MPFileHandler::setOption ( int  size)
inline

Referenced by Metapop::loadFileServices().

732 {_patch_sample_size = size;}
int _patch_sample_size
Definition: metapop.h:725

Member Data Documentation

int MPFileHandler::_patch_sample_size
private

Referenced by createAndPrintSample(), and FHwrite().


The documentation for this class was generated from the following files:

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR