Nemo  2.3.46
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 bool 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 ( )
inline
274 : FileHandler(".log"){};
FileHandler(const char *ext)
Definition: filehandler.h:107
virtual FHLogWriter::~FHLogWriter ( )
inlinevirtual
275 {}

Member Function Documentation

void FHLogWriter::createInitFile ( list< ParamSet * > &  params)

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

Referenced by FileServices::log_simparams().

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

Implements FileHandler.

278 {}
virtual void FHLogWriter::FHwrite ( )
inlinevirtual

Implements FileHandler.

277 {}//@TODO implement log writer procedures
void FHLogWriter::log_message ( string &  logstr)

Referenced by FileServices::log().

255 {
256  ofstream FH;
257 
258  open_logfile4writing(FH, ios_base::app);
259 
260  if(FH) {
261  FH<<logstr<<endl;
262  FH.close();
263  }
264 }
void open_logfile4writing(ofstream &FH, ios_base::openmode flag=ios_base::out)
Definition: filehandler.cc:268
void FHLogWriter::open_logfile4writing ( ofstream &  FH,
ios_base::openmode  flag = ios_base::out 
)

References error().

269 {
270  string file = get_filename();
271 
272  FH.open(file.c_str(), flag);
273 
274  if(!FH) {
275  error("FileServices::could not open simulation log file \"%s\"\n",file.c_str());
276  FH.close();
277  }
278 }
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:148
int error(const char *str,...)
Definition: output.cc:73
void FHLogWriter::save_simparams ( list< ParamSet * > &  params)

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

Referenced by FileServices::log_simparams().

190 {
191  ofstream FH;
192 
194 
195  list< ParamSet* >::iterator Pit = params.begin();
196  char t_buff[20];
197  time_t t = time(NULL);
198  strftime(t_buff, 20, "%d-%m-%Y %H:%M:%S", localtime(&t));
199 
200  if(FH) {
201  FH<<"# Nemo v"<<MAIN_VERSION<<"."<<MINOR_VERSION<<"."<<REVISION<<RELEASE
202  <<" "<<VERSION_DATE<<endl<<"#"<<endl;
203  FH<<"# simulation started on "<<t_buff<<endl<<endl;
204 
205  while(Pit != params.end()) {
206  FH<<endl;
207  (*Pit)->print(FH);
208  Pit++;
209  }
210  FH<<endl;
211 
212  FH.close();
213  }
214 }
#define REVISION
Definition: version.h:29
#define RELEASE
Definition: version.h:30
#define MINOR_VERSION
Definition: version.h:28
#define MAIN_VERSION
Definition: version.h:27
#define VERSION_DATE
Definition: version.h:31
void open_logfile4writing(ofstream &FH, ios_base::openmode flag=ios_base::out)
Definition: filehandler.cc:268

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

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR