Nemo  2.2.0
Public Member Functions | Protected Attributes | Private Types | Private Attributes
StatHandlerBase Class Reference

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

#include <stathandler.h>

+ Inheritance diagram for StatHandlerBase:
+ Collaboration diagram for StatHandlerBase:

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.

{ }

Member Function Documentation

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

Definition at line 97 of file stathandler.h.

References _stats.

{_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.

References _ncols.

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

{return _ncols;}
unsigned int StatHandlerBase::get_nrows ( ) [inline]

Definition at line 91 of file stathandler.h.

References _nrows.

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

{return _nrows;}
Metapop* StatHandlerBase::get_pop_ptr ( ) [inline]

Definition at line 81 of file stathandler.h.

References _service, and StatServices::get_pop_ptr().

Referenced by init().

{return _service->get_pop_ptr();}
StatServices* StatHandlerBase::get_service ( ) [inline]

Definition at line 85 of file stathandler.h.

References _service.

{return _service;}
unsigned int StatHandlerBase::getNbRecorders ( ) [inline]

Definition at line 89 of file stathandler.h.

References _stats.

{return _stats.size();}
unsigned int StatHandlerBase::getOccurrence ( ) [inline]

Definition at line 87 of file stathandler.h.

References _service, and StatServices::getOccurrence().

Referenced by init().

{return _service->getOccurrence();}
unsigned int StatHandlerBase::getStatRecIndex ( unsigned int  i)

Definition at line 90 of file stathandlerbase.cc.

References _stats, and error().

{
  STAT_IT el = _stats.begin();
  unsigned int index = 0;

  if(el != _stats.end()) {
    if(i > (*el)->getIndexSize())
      error("StatHandlerBase::getStatRecIndex: index vector overflow !!\n");
    //find the first statRecorder that has computed some stats
    for(; el != _stats.end(); el++)
      if((index = (*el)->getIndex(i)) != 0) break;
  }

  return index;
}
std::list<StatRecBase*>& StatHandlerBase::getStats ( ) [inline]

Definition at line 95 of file stathandler.h.

References _stats.

{return _stats;}
void StatHandlerBase::init ( ) [virtual]

Inits state.

Implements Handler.

Reimplemented in TTNeutralGenesSH, TTQuantiSH, TTDispersalSH, and LCE_StatSH.

Definition at line 39 of file stathandlerbase.cc.

References _ncols, _nrows, _pop, fatal(), get_pop_ptr(), SimRunner::getGenerations(), getOccurrence(), SimRunner::getReplicates(), and SIMenv::MainSim.

{
  _pop = get_pop_ptr();
 
  unsigned int gen = SIMenv::MainSim->getGenerations(), log = getOccurrence();

  if(gen == 0) fatal("cannot initialize stat recorders, generation nbr is null\n");
  
  _nrows = ( log > gen || log == 0 ? 2 : gen/log); 

  if(log != 1) _nrows++; //automatically save first generation
  
  if(SIMenv::MainSim->getReplicates() == 0) fatal("cannot initialize stat recorders, replicate nbr is null\n");
  _ncols = SIMenv::MainSim->getReplicates();
}
void StatHandlerBase::print_average ( std::ofstream &  FH,
unsigned int  i 
)

Definition at line 154 of file stathandlerbase.cc.

References _stats, FLAT, and GEN.

{
  STAT_IT IT = _stats.begin();

  while(IT != _stats.end()) {
    FH<<"\t";
    FH.width(12);

    if((*IT)->getOrdering() == FLAT)
      FH<<(*IT)->getAverage(i);
    else if((*IT)->getOrdering() == GEN)
      FH<<(*IT)->getVal(i);
    IT++;
  }
}
void StatHandlerBase::print_headers ( std::ofstream &  FH,
unsigned int  order 
)

Definition at line 121 of file stathandlerbase.cc.

References _stats.

{
  STAT_IT IT = _stats.begin();

  while(IT != _stats.end()) {
    if( (*IT)->getOrdering() & order) {
      FH<<"\t";
      FH.width(12);
      FH<<(*IT)->getName();
    }
    IT++;

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

Definition at line 138 of file stathandlerbase.cc.

References _stats, and FLAT.

{
  STAT_IT IT = _stats.begin();

  while(IT != _stats.end()) {
    if((*IT)->getOrdering() == FLAT) {
      FH<<"\t";
      FH.width(12);
      FH<<(*IT)->getVal(i,j);
    }
    IT++;
  }
}
void StatHandlerBase::reset ( ) [virtual]

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

Definition at line 72 of file stathandlerbase.cc.

References _ncols, _nrows, _stats, and clear().

{
  STAT_IT IT = _stats.begin();

  while(IT != _stats.end()) {
    delete (*IT);
    IT++;
  }

  _stats.clear();

  _nrows = _ncols = 0;

  clear();
}
void StatHandlerBase::set_service ( StatServices srv) [inline]

Definition at line 83 of file stathandler.h.

References _service.

Referenced by StatServices::attach().

{_service = srv;}
void StatHandlerBase::setAverage ( )

Definition at line 108 of file stathandlerbase.cc.

References _stats, FLAT, and RPL.

{
  STAT_IT IT = _stats.begin();

  while(IT != _stats.end()) {
    if((*IT)->getOrdering() == FLAT)
      (*IT)->setAverage(0,0,0,RPL);
    IT++;
  }
}
virtual bool StatHandlerBase::setStatRecorders ( std::string &  token) [pure virtual]
void StatHandlerBase::update ( ) [virtual]

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.2.0 by  doxygen 1.7.5.1 -- Nemo is hosted by  SourceForge.net Logo