Nemo  2.3.46
LCE_StatFH Class Reference

FileHandler of the LCE_StatServiceNotifier class, writes the recorded stats to txt files. More...

#include <servicenotifiers.h>

+ Inheritance diagram for LCE_StatFH:
+ Collaboration diagram for LCE_StatFH:

Public Member Functions

 LCE_StatFH ()
 
 ~LCE_StatFH ()
 
virtual bool ifExist ()
 
void set_statService (StatServices *srv)
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
void PrintStat_byGen ()
 
- 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 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 ()
 

Private Attributes

StatServices_statService
 

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

FileHandler of the LCE_StatServiceNotifier class, writes the recorded stats to txt files.

Constructor & Destructor Documentation

LCE_StatFH::LCE_StatFH ( )
inline

References FileHandler::set(), and FileHandler::set_isMasterExec().

102  : FileHandler(".txt"), _statService(0)
103  {
104  FileHandler::set(false,false,0,0,0,"");
105  set_isMasterExec(true);
106  }
StatServices * _statService
Definition: servicenotifiers.h:97
void set_isMasterExec(bool is)
Definition: filehandler.h:182
FileHandler(const char *ext)
Definition: filehandler.h:107
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path)
Sets the hanlder parameters.
Definition: filehandler.h:193
LCE_StatFH::~LCE_StatFH ( )
inline
108 { };

Member Function Documentation

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

Implements FileHandler.

115 {}
void LCE_StatFH::FHwrite ( )
virtual

Implements FileHandler.

References _statService, fatal(), FileHandler::get_extension(), FileHandler::get_path(), FileHandler::get_service(), FileServices::getBaseFileName(), SIMenv::getCurrentReplicate(), StatServices::getPrintAveragesOpt(), SIMenv::getReplicates(), message(), PrintStat_byGen(), and StatServices::printStatValue().

271 {
272  ofstream FH;
273 
274  string filename = get_path() + get_service()->getBaseFileName() + get_extension();
275 
276 #ifdef _DEBUG_
277  message("LCE_StatFH::FHwrite (%s)\n",filename.c_str());
278 #endif
279 
280  if(SIMenv::getCurrentReplicate() == 1) {
281 
282  FH.open(filename.c_str(),ios::trunc);
283 
284  if(!FH) fatal("LCE_StatFH::FHwrite:: could not open stat output file \"%s\"\n",filename.c_str());
285 
286  } else {
287 
288  FH.open(filename.c_str(),ios::app);
289 
290  if(!FH) fatal("LCE_StatFH::FHwrite:: could not open stat output file \"%s\"\n",filename.c_str());
291 
292  }
293 
295 
296  FH.close();
297 
298  //write the stat averages to the 'bygen.txt' file if at last replicate.
300  && SIMenv::getReplicates() > 1
302  PrintStat_byGen();
303 }
void PrintStat_byGen()
Definition: servicenotifiers.cc:307
void message(const char *message,...)
Definition: output.cc:40
StatServices * _statService
Definition: servicenotifiers.h:97
static unsigned int getReplicates()
Definition: simenv.h:63
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:135
std::string & get_extension()
Definition: filehandler.h:143
void fatal(const char *str,...)
Definition: output.cc:90
static unsigned int getCurrentReplicate()
Definition: simenv.h:62
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:226
void printStatValue(ofstream &FH, unsigned int repl_idx)
Prints the stat values to the '.txt' output file.
Definition: statservices.cc:280
std::string & get_path()
Definition: filehandler.h:139
bool getPrintAveragesOpt()
Definition: statservices.h:144
bool LCE_StatFH::ifExist ( )
virtual

Reimplemented from FileHandler.

References FileHandler::get_path(), FileHandler::get_service(), FileServices::getBaseFileName(), and warning().

240 {
241  bool status = true;
242  ifstream ifExist1, ifExist2;
243  ifExist1.setstate(ios::failbit);
244  ifExist2.setstate(ios::failbit);
245 
246  //check if the basefilename is already used on disk:
247  string filename = get_path() + get_service()->getBaseFileName() + ".txt";
248 
249  ifExist1.open(filename.c_str(),ios::in);
250  if(ifExist1.is_open()) {
251  warning("filename \"%s\" used by \"%s\"\n",get_service()->getBaseFileName().c_str(),filename.c_str());
252  status = false;
253  }
254  ifExist1.close();
255 
256  filename = get_path() + get_service()->getBaseFileName() + "_bygen.txt";
257 
258  ifExist2.open(filename.c_str(),ios::in);
259  if(ifExist2.is_open()) {
260  warning("filename \"%s\" used by \"%s\"\n",get_service()->getBaseFileName().c_str(),filename.c_str());
261  status = false;
262  }
263  ifExist2.close();
264 
265  return status;
266 }
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:135
void warning(const char *str,...)
Definition: output.cc:56
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:226
std::string & get_path()
Definition: filehandler.h:139
void LCE_StatFH::PrintStat_byGen ( )

References _statService, fatal(), FileHandler::get_path(), FileHandler::get_service(), FileServices::getBaseFileName(), and StatServices::printStatAverage().

Referenced by FHwrite().

308 {
309  ofstream FH;
310 
311  string filename = get_path() + get_service()->getBaseFileName() + "_bygen.txt";
312 
313  FH.open(filename.c_str(),ios::trunc);
314 
315  if(!FH) fatal("PrintStat:: could not open stat output file\n");
316 
318 
319  FH.close();
320 }
StatServices * _statService
Definition: servicenotifiers.h:97
void printStatAverage(ofstream &FH)
Definition: statservices.cc:328
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:135
void fatal(const char *str,...)
Definition: output.cc:90
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:226
std::string & get_path()
Definition: filehandler.h:139
void LCE_StatFH::set_statService ( StatServices srv)
inline

Referenced by LCE_StatServiceNotifier::loadStatServices().

112 {_statService = srv;}
StatServices * _statService
Definition: servicenotifiers.h:97

Member Data Documentation

StatServices* LCE_StatFH::_statService
private

Referenced by FHwrite(), and PrintStat_byGen().


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