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

◆ ~FHLogWriter()

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

Member Function Documentation

◆ createInitFile()

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

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.

285 {}

◆ FHwrite()

virtual void FHLogWriter::FHwrite ( )
inlinevirtual

Implements FileHandler.

284 {}

◆ log_message()

void FHLogWriter::log_message ( string &  logstr)
259 {
260  ofstream FH;
261 
262  open_logfile4writing(FH, ios_base::app);
263 
264  if(FH) {
265  FH<<logstr<<endl;
266  FH.close();
267  }
268 }
void open_logfile4writing(ofstream &FH, ios_base::openmode flag=ios_base::out)
Definition: filehandler.cc:272

Referenced by FileServices::log().

◆ open_logfile4writing()

void FHLogWriter::open_logfile4writing ( ofstream &  FH,
ios_base::openmode  flag = ios_base::out 
)
273 {
274  string file = get_filename();
275 
276  FH.open(file.c_str(), flag);
277 
278  if(!FH) {
279  error("FileServices::could not open simulation log file \"%s\"\n",file.c_str());
280  FH.close();
281  }
282 }
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:77

References error().

◆ save_simparams()

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

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