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

File Handler used to save the simulation parameters to a log file. More...

#include <filehandler.h>

+ Inheritance diagram for FHLogWriter:
+ Collaboration diagram for FHLogWriter:

Public Member Functions

 FHLogWriter ()
 
virtual ~FHLogWriter ()
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
void createInitFile (list< ParamSet * > &params)
 
void save_simparams (list< ParamSet * > &params)
 
void log_message (string &logstr)
 
void open_logfile4writing (ofstream &FH, ios_base::openmode flag=ios_base::out)
 
- 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 ()
 

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

File Handler used to save the simulation parameters to a log file.

Constructor & Destructor Documentation

◆ FHLogWriter()

FHLogWriter::FHLogWriter ( )
inline
284 : FileHandler(".log"){};
FileHandler(const char *ext)
Definition: filehandler.h:106

◆ ~FHLogWriter()

virtual FHLogWriter::~FHLogWriter ( )
inlinevirtual
285 {}

Member Function Documentation

◆ createInitFile()

void FHLogWriter::createInitFile ( list< ParamSet * > &  params)
230 {
231  string file = get_service()->getBaseFileName() + ".ini"; // get_filename();
232  ofstream FH;
233 
234  FH.open(file.c_str(), ios_base::out);
235 
236  list< ParamSet* >::iterator Pit = params.begin();
237  char t_buff[20];
238  time_t t = time(NULL);
239  strftime(t_buff, 20, "%d-%m-%Y %H:%M:%S", localtime(&t));
240 
241  if(FH) {
242  FH<<"# Nemo v"<<MAIN_VERSION<<"."<<MINOR_VERSION<<"."<<REVISION<<RELEASE
243  <<" "<<VERSION_DATE<<endl<<"#"<<endl;
244  FH<<"# init file created on "<<t_buff<<endl<<endl;
245 
246  while(Pit != params.end()) {
247  FH<<endl;
248  // !!! we have to change the run mode in the init file !!!
249  if ((*Pit)->getName() == "simulation") {
250  (*Pit)->get_param("run_mode")->setArg("run");
251  }
252 
253  (*Pit)->print(FH);
254 
255  Pit++;
256  }
257 
258  FH<<endl;
259  FH.close();
260  }
261 }
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:138
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:474
#define VERSION_DATE
Definition: version.h:29
#define MINOR_VERSION
Definition: version.h:26
#define RELEASE
Definition: version.h:28
#define MAIN_VERSION
Definition: version.h:25
#define REVISION
Definition: version.h:27

References MAIN_VERSION, MINOR_VERSION, RELEASE, REVISION, and VERSION_DATE.

Referenced by FileServices::log_simparams().

+ Here is the caller graph for this function:

◆ FHread()

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

Implements FileHandler.

288 {}

◆ FHwrite()

virtual void FHLogWriter::FHwrite ( )
inlinevirtual

Implements FileHandler.

287 {}

◆ log_message()

void FHLogWriter::log_message ( string &  logstr)
266 {
267  ofstream FH;
268 
269  open_logfile4writing(FH, ios_base::app);
270 
271  if(FH) {
272  FH<<logstr<<endl;
273  FH.close();
274  }
275 }
void open_logfile4writing(ofstream &FH, ios_base::openmode flag=ios_base::out)
Definition: filehandler.cc:279

Referenced by FileServices::log().

+ Here is the caller graph for this function:

◆ open_logfile4writing()

void FHLogWriter::open_logfile4writing ( ofstream &  FH,
ios_base::openmode  flag = ios_base::out 
)
280 {
281  string file = get_filename();
282 
283  FH.open(file.c_str(), flag);
284 
285  if(!FH) {
286  error("FileServices::could not open simulation log file \"%s\"\n",file.c_str());
287  FH.close();
288  }
289 }
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:150
int error(const char *str,...)
Definition: output.cc:78

References error().

◆ save_simparams()

void FHLogWriter::save_simparams ( list< ParamSet * > &  params)
201 {
202  ofstream FH;
203 
205 
206  list< ParamSet* >::iterator Pit = params.begin();
207  char t_buff[20];
208  time_t t = time(NULL);
209  strftime(t_buff, 20, "%d-%m-%Y %H:%M:%S", localtime(&t));
210 
211  if(FH) {
212  FH<<"# Nemo v"<<MAIN_VERSION<<"."<<MINOR_VERSION<<"."<<REVISION<<RELEASE
213  <<" "<<VERSION_DATE<<endl<<"#"<<endl;
214  FH<<"# simulation started on "<<t_buff<<endl<<endl;
215 
216  while(Pit != params.end()) {
217  FH<<endl;
218  (*Pit)->print(FH);
219  Pit++;
220  }
221  FH<<endl;
222 
223  FH.close();
224  }
225 }

References MAIN_VERSION, MINOR_VERSION, RELEASE, REVISION, and VERSION_DATE.

Referenced by FileServices::log_simparams().

+ Here is the caller graph for this function:

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