Nemo  2.4.2
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
283 : FileHandler(".log"){};
FileHandler(const char *ext)
Definition: filehandler.h:105

◆ ~FHLogWriter()

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

Member Function Documentation

◆ createInitFile()

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

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.

287 {}

◆ FHwrite()

virtual void FHLogWriter::FHwrite ( )
inlinevirtual

Implements FileHandler.

286 {}

◆ log_message()

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

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 
)
279 {
280  string file = get_filename();
281 
282  FH.open(file.c_str(), flag);
283 
284  if(!FH) {
285  error("FileServices::could not open simulation log file \"%s\"\n",file.c_str());
286  FH.close();
287  }
288 }
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:149
int error(const char *str,...)
Definition: output.cc:77

References error().

◆ save_simparams()

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

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

Catalogued on GSR