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

FileHandler of the LCE_StatServiceNotifier class, writes the recorded stats to txt files. More...

#include <servicenotifiers.h>

+ Inheritance diagram for LCE_StatFH:
+ Collaboration diagram for LCE_StatFH:

Public Member Functions

 LCE_StatFH ()
 
 ~LCE_StatFH ()
 
virtual vector< string > ifExist ()
 
void set_statService (StatServices *srv)
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
void PrintStat_byGen ()
 
- 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 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

StatServices_statService
 

Additional Inherited Members

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

Detailed Description

FileHandler of the LCE_StatServiceNotifier class, writes the recorded stats to txt files.

Constructor & Destructor Documentation

◆ LCE_StatFH()

LCE_StatFH::LCE_StatFH ( )
inline
159 : FileHandler(".txt"), _statService(0)
160 {
161  FileHandler::set(false,false,0,0,0,"");
162  set_isMasterExec(true);
163 }
void set_isMasterExec(bool is)
Definition: filehandler.h:185
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path)
Sets the hanlder parameters.
Definition: filehandler.h:196
FileHandler(const char *ext)
Definition: filehandler.h:106
StatServices * _statService
Definition: servicenotifiers.h:154

References FileHandler::set(), and FileHandler::set_isMasterExec().

◆ ~LCE_StatFH()

LCE_StatFH::~LCE_StatFH ( )
inline
165 { };

Member Function Documentation

◆ FHread()

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

Implements FileHandler.

172 {}

◆ FHwrite()

void LCE_StatFH::FHwrite ( )
virtual

Implements FileHandler.

1087 {
1088  ofstream FH;
1089 
1090  string filename = get_path() + get_service()->getBaseFileName() + get_extension();
1091 
1092 #ifdef _DEBUG_
1093  message("LCE_StatFH::FHwrite (%s)\n",filename.c_str());
1094 #endif
1095 
1096  if(SIMenv::getCurrentReplicate() == 1) {
1097 
1098  FH.open(filename.c_str(),ios::trunc);
1099 
1100  if(!FH) fatal("LCE_StatFH::FHwrite:: could not open stat output file \"%s\"\n",filename.c_str());
1101 
1102  } else {
1103 
1104  FH.open(filename.c_str(),ios::app);
1105 
1106  if(!FH) fatal("LCE_StatFH::FHwrite:: could not open stat output file \"%s\"\n",filename.c_str());
1107 
1108  }
1109 
1111 
1112  FH.close();
1113 
1114  //write the stat averages to the 'bygen.txt' file if at last replicate.
1116  && SIMenv::getReplicates() > 1
1118  PrintStat_byGen();
1119 }
std::string & get_path()
Definition: filehandler.h:142
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:138
std::string & get_extension()
Definition: filehandler.h:146
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:474
void PrintStat_byGen()
Definition: servicenotifiers.cc:1123
static unsigned int getReplicates()
Definition: simenv.h:62
static unsigned int getCurrentReplicate()
Definition: simenv.h:61
bool getPrintAveragesOpt()
Definition: statservices.h:143
void printStatValue(ofstream &FH, unsigned int repl_idx)
Prints the stat values to the '.txt' output file.
Definition: statservices.cc:288
void fatal(const char *str,...)
Definition: output.cc:99
void message(const char *message,...)
Definition: output.cc:39

References _statService, fatal(), FileHandler::get_extension(), FileHandler::get_path(), FileHandler::get_service(), FileServices::getBaseFileName(), SIMenv::getCurrentReplicate(), StatServices::getPrintAveragesOpt(), SIMenv::getReplicates(), message(), PrintStat_byGen(), and StatServices::printStatValue().

◆ ifExist()

vector< string > LCE_StatFH::ifExist ( )
virtual

Reimplemented from FileHandler.

1052 {
1053 // bool status = true;
1054  ifstream ifExist1, ifExist2;
1055  ifExist1.setstate(ios::failbit);
1056  ifExist2.setstate(ios::failbit);
1057 
1058  //check if the basefilename is already used on disk:
1059  string filename = get_path() + get_service()->getBaseFileName() + ".txt";
1060 
1061  vector< string > list;
1062 
1063  ifExist1.open(filename.c_str(),ios::in);
1064  if(ifExist1.is_open()) {
1065 // warning("filename \"%s\" used by \"%s\"\n",get_service()->getBaseFileName().c_str(),filename.c_str());
1066  list.push_back(filename);
1067 // status = false;
1068  }
1069  ifExist1.close();
1070 
1071  filename = get_path() + get_service()->getBaseFileName() + "_bygen.txt";
1072 
1073  ifExist2.open(filename.c_str(),ios::in);
1074  if(ifExist2.is_open()) {
1075 // warning("filename \"%s\" used by \"%s\"\n",get_service()->getBaseFileName().c_str(),filename.c_str());
1076  list.push_back(filename);
1077 // status = false;
1078  }
1079  ifExist2.close();
1080 
1081  return list;
1082 }

References FileHandler::get_path(), FileHandler::get_service(), and FileServices::getBaseFileName().

◆ PrintStat_byGen()

void LCE_StatFH::PrintStat_byGen ( )
1124 {
1125  ofstream FH;
1126 
1127  string filename = get_path() + get_service()->getBaseFileName() + "_bygen.txt";
1128 
1129  FH.open(filename.c_str(),ios::trunc);
1130 
1131  if(!FH) fatal("PrintStat:: could not open stat output file\n");
1132 
1134 
1135  FH.close();
1136 }
void printStatAverage(ofstream &FH)
Definition: statservices.cc:336

References _statService, fatal(), FileHandler::get_path(), FileHandler::get_service(), FileServices::getBaseFileName(), and StatServices::printStatAverage().

Referenced by FHwrite().

+ Here is the caller graph for this function:

◆ set_statService()

void LCE_StatFH::set_statService ( StatServices srv)
inline
169 {_statService = srv;}

References _statService.

Referenced by LCE_StatServiceNotifier::loadStatServices().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _statService

StatServices* LCE_StatFH::_statService
private

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

Generated for Nemo v2.4.1 by  doxygen 1.9.1

Catalogued on GSR