Nemo  2.4.0b
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
285 : FileHandler(".log"){};
FileHandler(const char *ext)
Definition: filehandler.h:107

◆ ~FHLogWriter()

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

Member Function Documentation

◆ createInitFile()

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

◆ FHread()

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

Implements FileHandler.

289 {}

◆ FHwrite()

virtual void FHLogWriter::FHwrite ( )
inlinevirtual

Implements FileHandler.

288 {}

◆ log_message()

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

Referenced by FileServices::log().

◆ open_logfile4writing()

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

References error().

◆ save_simparams()

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

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

Referenced by FileServices::log_simparams().


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

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR