StatHandlerBase Class Reference

Base class of the StatHandler class, implements the Handler interface. More...

#include <stathandler.h>

Inheritance diagram for StatHandlerBase:

Inheritance graph
[legend]
Collaboration diagram for StatHandlerBase:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 StatHandlerBase ()
virtual ~StatHandlerBase ()
virtual void reset ()
 Empties the _stats list and calls clear() (defined in the derived class).
Accessors
Metapopget_pop_ptr ()
void set_service (StatServices *srv)
StatServicesget_service ()
unsigned int getOccurrence ()
unsigned int getNbRecorders ()
unsigned int get_nrows ()
unsigned int get_ncols ()
std::list< StatRecBase * > & getStats ()
virtual void add (StatRecBase *rec)
Stat recorder interface
unsigned int getStatRecIndex (unsigned int i)
void setAverage ()
void print_headers (std::ofstream &FH, unsigned int order)
void print_value (std::ofstream &FH, unsigned int i, unsigned int j)
void print_average (std::ofstream &FH, unsigned int i)
Handler implementation
virtual void init ()
 Inits state.
virtual void update ()
 Updates the handler state.
StatHandler interface declaration
virtual void execute ()=0
virtual bool setStatRecorders (std::string &token)=0
virtual void clear ()=0

Protected Attributes

Metapop_pop
 Link to the current population, set through the link to the StatService.

Private Types

typedef std::list< StatRecBase * >
::iterator 
STAT_IT

Private Attributes

std::list< StatRecBase * > _stats
 Link to the StatRecorder list elements in the StatHandler derived class.
unsigned int _nrows
 Structure of the stats table in the stat recorders.
unsigned int _ncols
StatServices_service
 Link to the StatService.
unsigned int _GenerationOccurrence
 Occurence of the stats recording as set by the user (see parameter "stat_log_time").
unsigned int _current_replicate
 Replicate state of this Handler.
unsigned int _current_generation
 Generation state of this Handler.
age_t _current_age
 Age state of this Handler.


Detailed Description

Base class of the StatHandler class, implements the Handler interface.

This class stores the Handler state and the list of links to the StatRecBase. This list is duplicated in the StatHandler as a list of the StatRecorder templates. It allows the StatService to access the stat recorders without knowledge of the actual StatHandler and StatRecorder template type.

Definition at line 47 of file stathandler.h.


Member Typedef Documentation

typedef std::list< StatRecBase* >::iterator StatHandlerBase::STAT_IT [private]

Definition at line 65 of file stathandler.h.


Constructor & Destructor Documentation

StatHandlerBase::StatHandlerBase (  )  [inline]

Definition at line 73 of file stathandler.h.

virtual StatHandlerBase::~StatHandlerBase (  )  [inline, virtual]

Definition at line 78 of file stathandler.h.

00078 { }


Member Function Documentation

virtual void StatHandlerBase::add ( StatRecBase rec  )  [inline, virtual]

Definition at line 97 of file stathandler.h.

00097 {_stats.push_back(rec);}

virtual void StatHandlerBase::clear (  )  [pure virtual]

virtual void StatHandlerBase::execute (  )  [pure virtual]

unsigned int StatHandlerBase::get_ncols (  )  [inline]

Definition at line 93 of file stathandler.h.

Referenced by StatHandler< TTDeletMutBitstrSH >::add().

00093 {return _ncols;}

unsigned int StatHandlerBase::get_nrows (  )  [inline]

Definition at line 91 of file stathandler.h.

Referenced by StatHandler< TTDeletMutBitstrSH >::add().

00091 {return _nrows;}

Metapop* StatHandlerBase::get_pop_ptr (  )  [inline]

Definition at line 81 of file stathandler.h.

Referenced by init().

00081 {return _service->get_pop_ptr();}

StatServices* StatHandlerBase::get_service (  )  [inline]

Definition at line 85 of file stathandler.h.

00085 {return _service;}

unsigned int StatHandlerBase::getNbRecorders (  )  [inline]

Definition at line 89 of file stathandler.h.

00089 {return _stats.size();}

unsigned int StatHandlerBase::getOccurrence (  )  [inline]

Definition at line 87 of file stathandler.h.

Referenced by StatHandler< SH >::execute(), and init().

00087 {return _service->getOccurrence();}

unsigned int StatHandlerBase::getStatRecIndex ( unsigned int  i  ) 

Definition at line 90 of file stathandlerbase.cc.

00091 {
00092   STAT_IT el = _stats.begin();
00093   unsigned int index = 0;
00094 
00095   if(el != _stats.end()) {
00096     if(i > (*el)->getIndexSize())
00097       error("StatHandlerBase::getStatRecIndex: index vector overflow !!\n");
00098     //find the first statRecorder that has computed some stats
00099     for(; el != _stats.end(); el++)
00100       if((index = (*el)->getIndex(i)) != 0) break;
00101   }
00102 
00103   return index;
00104 }

std::list<StatRecBase*>& StatHandlerBase::getStats (  )  [inline]

Definition at line 95 of file stathandler.h.

00095 {return _stats;}

void StatHandlerBase::init (  )  [virtual]

Inits state.

Implements Handler.

Reimplemented in LCE_StatSH, TTDispersalSH, and TTNeutralGenesSH.

Definition at line 39 of file stathandlerbase.cc.

00040 {
00041   _pop = get_pop_ptr();
00042  
00043   unsigned int gen = SIMenv::MainSim->getGenerations(), log = getOccurrence();
00044 
00045   if(gen == 0) fatal("cannot initialize stat recorders, generation nbr is null\n");
00046   
00047   _nrows = ( log > gen || log == 0 ? 2 : gen/log); 
00048 
00049   if(log != 1) _nrows++; //automatically save first generation
00050   
00051   if(SIMenv::MainSim->getReplicates() == 0) fatal("cannot initialize stat recorders, replicate nbr is null\n");
00052   _ncols = SIMenv::MainSim->getReplicates();
00053 }

void StatHandlerBase::print_average ( std::ofstream &  FH,
unsigned int  i 
)

Definition at line 154 of file stathandlerbase.cc.

00155 {
00156   STAT_IT IT = _stats.begin();
00157 
00158   while(IT != _stats.end()) {
00159     FH<<"\t";
00160     FH.width(12);
00161 
00162     if((*IT)->getOrdering() == FLAT)
00163       FH<<(*IT)->getAverage(i);
00164     else if((*IT)->getOrdering() == GEN)
00165       FH<<(*IT)->getVal(i);
00166     IT++;
00167   }
00168 }

void StatHandlerBase::print_headers ( std::ofstream &  FH,
unsigned int  order 
)

Definition at line 121 of file stathandlerbase.cc.

00122 {
00123   STAT_IT IT = _stats.begin();
00124 
00125   while(IT != _stats.end()) {
00126     if( (*IT)->getOrdering() & order) {
00127       FH<<"\t";
00128       FH.width(12);
00129       FH<<(*IT)->getName();
00130     }
00131     IT++;
00132 
00133   }
00134 }

void StatHandlerBase::print_value ( std::ofstream &  FH,
unsigned int  i,
unsigned int  j 
)

Definition at line 138 of file stathandlerbase.cc.

00139 {
00140   STAT_IT IT = _stats.begin();
00141 
00142   while(IT != _stats.end()) {
00143     if((*IT)->getOrdering() == FLAT) {
00144       FH<<"\t";
00145       FH.width(12);
00146       FH<<(*IT)->getVal(i,j);
00147     }
00148     IT++;
00149   }
00150 }

void StatHandlerBase::reset (  )  [virtual]

Empties the _stats list and calls clear() (defined in the derived class).

Definition at line 72 of file stathandlerbase.cc.

00073 {
00074   STAT_IT IT = _stats.begin();
00075 
00076   while(IT != _stats.end()) {
00077     delete (*IT);
00078     IT++;
00079   }
00080 
00081   _stats.clear();
00082 
00083   _nrows = _ncols = 0;
00084 
00085   clear();
00086 }

void StatHandlerBase::set_service ( StatServices srv  )  [inline]

Definition at line 83 of file stathandler.h.

Referenced by StatServices::attach().

00083 {_service = srv;}

void StatHandlerBase::setAverage (  ) 

Definition at line 108 of file stathandlerbase.cc.

00109 {
00110   STAT_IT IT = _stats.begin();
00111 
00112   while(IT != _stats.end()) {
00113     if((*IT)->getOrdering() == FLAT)
00114       (*IT)->setAverage(0,0,0,RPL);
00115     IT++;
00116   }
00117 }

virtual bool StatHandlerBase::setStatRecorders ( std::string &  token  )  [pure virtual]

void StatHandlerBase::update (  )  [virtual]

Updates the handler state.

Implements Handler.

Definition at line 57 of file stathandlerbase.cc.

00058 {
00059   _current_replicate = _pop->getCurrentReplicate();
00060 
00061   _current_generation = _pop->getCurrentGeneration();
00062 
00063   _current_age = _pop->getCurrentAge();
00064 
00065   //if( !(_current_generation % _GenerationOccurrence) )
00066 
00067     execute();
00068 }


Member Data Documentation

Age state of this Handler.

Definition at line 63 of file stathandler.h.

Referenced by update().

unsigned int StatHandlerBase::_current_generation [private]

Generation state of this Handler.

Definition at line 61 of file stathandler.h.

Referenced by update().

unsigned int StatHandlerBase::_current_replicate [private]

Replicate state of this Handler.

Definition at line 59 of file stathandler.h.

Referenced by update().

Occurence of the stats recording as set by the user (see parameter "stat_log_time").

Definition at line 57 of file stathandler.h.

unsigned int StatHandlerBase::_ncols [private]

Definition at line 53 of file stathandler.h.

Referenced by get_ncols(), init(), and reset().

unsigned int StatHandlerBase::_nrows [private]

Structure of the stats table in the stat recorders.

Definition at line 53 of file stathandler.h.

Referenced by get_nrows(), init(), and reset().

Link to the StatService.

Definition at line 55 of file stathandler.h.

Referenced by get_pop_ptr(), get_service(), getOccurrence(), and set_service().

std::list<StatRecBase*> StatHandlerBase::_stats [private]

Link to the StatRecorder list elements in the StatHandler derived class.

Definition at line 51 of file stathandler.h.

Referenced by add(), getNbRecorders(), getStatRecIndex(), getStats(), print_average(), print_headers(), print_value(), reset(), and setAverage().


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

Generated for Nemo v2.1.2 by  doxygen 1.5.8 -- Nemo is hosted by  SourceForge.net Logo