Nemo  2.2.0
Public Member Functions | Protected Types | Protected Attributes
StatHandler< SH > Class Template Reference

A class to compute and store the summary statistics associated with a SimComponent. More...

#include <stathandler.h>

+ Inheritance diagram for StatHandler< SH >:
+ Collaboration diagram for StatHandler< SH >:

List of all members.

Public Member Functions

 StatHandler ()
virtual ~StatHandler ()
virtual void clear ()
 Empties the _recorders list, they are destroyed in StatHandlerBase::reset().
virtual void execute ()
 Computes the stats by executing the function variables stored in the StatRecorder's.
virtual StatRecorder< SH > * add (std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(SH::*getStatNoArg)(void), double(SH::*getStatOneArg)(unsigned int), double(SH::*getStatTwoArg)(unsigned int, unsigned int), void(SH::*setStat)(void))
 Adds a StatRecorder to the list, it is also added to the StatHandlerBase::_stats list.

Protected Types

typedef std::list
< StatRecorder< SH >
* >::iterator 
REC_IT

Protected Attributes

std::list< StatRecorder< SH > * > _recorders
 The list of stat recorders.

Detailed Description

template<class SH>
class StatHandler< SH >

A class to compute and store the summary statistics associated with a SimComponent.

The template type must be the type of the class that declares the methods linked into the StatRecorder elements.

Definition at line 132 of file stathandler.h.


Member Typedef Documentation

template<class SH>
typedef std::list< StatRecorder<SH>* >::iterator StatHandler< SH >::REC_IT [protected]

Definition at line 138 of file stathandler.h.


Constructor & Destructor Documentation

template<class SH>
StatHandler< SH >::StatHandler ( ) [inline]

Definition at line 142 of file stathandler.h.

{ }
template<class SH>
virtual StatHandler< SH >::~StatHandler ( ) [inline, virtual]

Definition at line 144 of file stathandler.h.

{ }

Member Function Documentation

template<class SH>
virtual StatRecorder<SH>* StatHandler< SH >::add ( std::string  Title,
std::string  Name,
age_t  AGE,
unsigned int  ARG1,
unsigned int  ARG2,
double(SH::*)(void)  getStatNoArg,
double(SH::*)(unsigned int)  getStatOneArg,
double(SH::*)(unsigned int, unsigned int)  getStatTwoArg,
void(SH::*)(void)  setStat 
) [inline, virtual]

Adds a StatRecorder to the list, it is also added to the StatHandlerBase::_stats list.

Two types of function variables are passed to this function. The "getter" and "setter". A "getter" returns a double value that will be stored in the StatRecorder structure. It may or may not take an argument. Only one getter should be passed to the stat recorder. The setter is used to set variables in the SH class which are then read by the getter. A setter and a getter may be given together but a setter alone will issue an error at runtime as no getter is present in the stat recorder.

Parameters:
Titlethe stat title (as shown in the R frontend fro eg.)
Namethe stat name (headers in the stat output file)
AGEthe age class for which the stat will be recorded
ARG1the first argument to pass to the SH function
ARG2the second argument to pass to the SH function
getStatNoArgfunction ptr to a SH getter that takes no argument
getStatOneArgfunction ptr to a SH getter with a single integer argument
getStatTwoArgfunction ptr to a SH getter with two integer arguments
setStatfunction ptr to a SH setter

Definition at line 166 of file stathandler.h.

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

  {
    StatRecorder<SH>* new_rec = new StatRecorder<SH>(this->get_nrows(),this->get_ncols());
    
    new_rec->set(Title,Name,AGE,ARG1,ARG2,getStatNoArg,getStatOneArg,getStatTwoArg,setStat);
    
    _recorders.push_back(new_rec);
    
    StatHandlerBase::add(new_rec);
    
    return new_rec;
  }
template<class SH>
virtual void StatHandler< SH >::clear ( ) [inline, virtual]

Empties the _recorders list, they are destroyed in StatHandlerBase::reset().

Implements StatHandlerBase.

Definition at line 146 of file stathandler.h.

{_recorders.clear();}
template<class SH >
void StatHandler< SH >::execute ( ) [virtual]

Computes the stats by executing the function variables stored in the StatRecorder's.

Implements StatHandlerBase.

Definition at line 38 of file stathandler.cc.

References error(), and MPIenv::isMaster().

                                                    {
    REC_IT rec;
    rec = _recorders.begin();
    unsigned int repl = 1;
    if ( _myenv->isMaster() ) repl = _pop->getCurrentReplicate();
  while(rec != _recorders.end()) {
      if( !((*rec)->setVal(_pop->getCurrentAge(),getOccurrence(),_pop->getCurrentGeneration(),
                           repl,dynamic_cast<SH*>(this))) ) {
        error("StatRecorder::setVal returns false\n");
        return;
      }
      rec++;
  }
  }

Member Data Documentation

template<class SH>
std::list<StatRecorder<SH>*> StatHandler< SH >::_recorders [protected]

The list of stat recorders.

Definition at line 136 of file stathandler.h.

Referenced by StatHandler< LCE_SelectionSH >::add(), and StatHandler< LCE_SelectionSH >::clear().


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