Nemo  2.2.0
Public Types | Public Member Functions | Private Attributes
StatServices Class Reference

The Service class used to manage the StatHandler objects. More...

#include <statservices.h>

+ Inheritance diagram for StatServices:
+ Collaboration diagram for StatServices:

List of all members.

Public Types

typedef std::list
< StatHandlerBase * >
::const_iterator 
stat_it

Public Member Functions

 StatServices ()
virtual ~StatServices ()
virtual bool init ()
 Inits internals.
Metapopget_pop_ptr ()
void set_pop_ptr (Metapop *pop)
void set (std::string &str, unsigned int occ)
unsigned int getOccurrence ()
void setOcccurrence (unsigned int value)
std::string & getStatArg ()
void printStatHeaders (std::ofstream &FH, unsigned int order)
void printStatValue (std::ofstream &FH, unsigned int i, unsigned int j)
 Prints the stat values to the '.txt' output file.
void printStatAverage (std::ofstream &FH, unsigned int i)
void setStatAverage ()
std::list< StatRecBase * > getAllStats ()
stat_it getFirst ()
stat_it getLast ()
unsigned int getStatRecIndex (unsigned int i)
virtual void notify ()
 Notifies all observers to update their state.
virtual void load (SimComponent *sc)
 tell the SimComponent to load its stat handlers
virtual void attach (StatHandlerBase *SH)
 attach the StatHandler to the current list (_children) of the StatServices
virtual void reset ()
 clear the list of StatHandler

Private Attributes

Metapop_popPtr
std::list< StatHandlerBase * > _children
std::string _statArg
unsigned int _occurrence

Detailed Description

The Service class used to manage the StatHandler objects.

Definition at line 44 of file statservices.h.


Member Typedef Documentation

typedef std::list< StatHandlerBase* >::const_iterator StatServices::stat_it

Definition at line 58 of file statservices.h.


Constructor & Destructor Documentation

StatServices::StatServices ( ) [inline]

Definition at line 60 of file statservices.h.

: _popPtr(0), _occurrence(0) { }
virtual StatServices::~StatServices ( ) [inline, virtual]

Definition at line 62 of file statservices.h.

{ }

Member Function Documentation

void StatServices::attach ( StatHandlerBase SH) [virtual]
Metapop* StatServices::get_pop_ptr ( ) [inline]

Definition at line 66 of file statservices.h.

References _popPtr.

Referenced by StatHandlerBase::get_pop_ptr().

{return _popPtr;}
list< StatRecBase * > StatServices::getAllStats ( )

Definition at line 202 of file statservices.cc.

References _children.

Referenced by SimRunner::get_allRegisteredStats().

{
  list< StatHandlerBase* >::iterator HIT = _children.begin();
  
  list<StatRecBase*> allStats, stats;
  
  while(HIT != _children.end()) {
        stats = (*HIT)->getStats();
        allStats.insert(allStats.end(), stats.begin(), stats.end());
        HIT++;
  }
  
  return allStats;
}
stat_it StatServices::getFirst ( ) [inline]

Definition at line 92 of file statservices.h.

References _children.

{return _children.begin();}
stat_it StatServices::getLast ( ) [inline]

Definition at line 94 of file statservices.h.

References _children.

{return _children.end();}
unsigned int StatServices::getOccurrence ( ) [inline]
std::string& StatServices::getStatArg ( ) [inline]

Definition at line 76 of file statservices.h.

References _statArg.

{return _statArg;}
unsigned int StatServices::getStatRecIndex ( unsigned int  i)

Definition at line 189 of file statservices.cc.

References _children.

Referenced by LCE_StatFH::FHwrite(), and LCE_StatFH::PrintStat_byGen().

{
  list< StatHandlerBase* >::iterator el;
  unsigned int index = 0;
  //find the first statHandler that has registered statRecorders and has computed some stats:
  for(el = _children.begin(); el != _children.end(); el++)
    if((index = (*el)->getStatRecIndex(i)) != 0) break;

  return index;
}
bool StatServices::init ( ) [virtual]

Inits internals.

Implements Service.

Definition at line 44 of file statservices.cc.

References _children, _statArg, and error().

Referenced by SimRunner::init_components().

{
  list< StatHandlerBase* >::iterator HIT;
  
  HIT = _children.begin();

  //first init the stat handlers -> will define the dims of the stat tables
  while(HIT != _children.end()) {
        (*HIT)->init();
        HIT++;
  }
  
  istringstream stats(_statArg);
  std::string arg;
  std::list<std::string> args;
  
  //extract the stat options from the string read in the init file
  while(stats>>arg) args.push_back(arg);
        
  std::list<std::string>::iterator token = args.begin();
  
  bool is_set = false;
  
  while(token != args.end()) {
        
        HIT = _children.begin();
        
        is_set = false;
        
        while(HIT != _children.end() && !is_set) {
          is_set |= (*HIT)->setStatRecorders( (*token) );
          HIT++;
        }

        if(!is_set) {
          error("the string \"%s\" is not a valid stat option\n",(*token).c_str());
          return false;
        }
        
        token++;
  }
  
  
  return true;
}
void StatServices::load ( SimComponent sc) [virtual]

tell the SimComponent to load its stat handlers

Parameters:
scthe SimComponent

Implements Service.

Definition at line 92 of file statservices.cc.

References SimComponent::loadStatServices().

Referenced by SimRunner::register_component().

{
  sc->loadStatServices(this);
}
void StatServices::notify ( ) [virtual]

Notifies all observers to update their state.

Reimplemented from Service.

Definition at line 108 of file statservices.cc.

References _occurrence, SIMenv::MainSim, and message().

Referenced by LCE_StatServiceNotifier::execute().

{
#ifdef _DEBUG_
  message("StatServices::notify (%i): ",( !(SIMenv::MainSim->getCurrentGeneration() % _occurrence)  
                                         || SIMenv::MainSim->getCurrentGeneration() == 1 ));
  fflush(stdout);
#endif
  //we automatically save first and last generations
  if( !(SIMenv::MainSim->getCurrentGeneration() % _occurrence)  || SIMenv::MainSim->getCurrentGeneration() == 1 )
    Service::notify();
#ifdef _DEBUG_
  message("\n");
#endif
}
void StatServices::printStatAverage ( std::ofstream &  FH,
unsigned int  i 
)

Definition at line 165 of file statservices.cc.

References _children.

Referenced by LCE_StatFH::PrintStat_byGen().

{
  list< StatHandlerBase* >::iterator HIT = _children.begin();
  
  while(HIT != _children.end()) {
        (*HIT)->print_average(FH,i);
        HIT++;
  }
}
void StatServices::printStatHeaders ( std::ofstream &  FH,
unsigned int  order 
)

Definition at line 141 of file statservices.cc.

References _children.

Referenced by LCE_StatFH::FHwrite(), and LCE_StatFH::PrintStat_byGen().

{
  list< StatHandlerBase* >::iterator HIT = _children.begin();
  
  while(HIT != _children.end()) {
        (*HIT)->print_headers(FH,order);
        HIT++;
  }
}
void StatServices::printStatValue ( std::ofstream &  FH,
unsigned int  i,
unsigned int  j 
)

Prints the stat values to the '.txt' output file.

Parameters:
FHthe file output stream
ithe generation index in the stat tables (row)
jthe replicate indes in the stat tables (column)

Definition at line 153 of file statservices.cc.

References _children.

Referenced by LCE_StatFH::FHwrite().

{
  list< StatHandlerBase* >::iterator HIT = _children.begin();
  
  while(HIT != _children.end()) {
        (*HIT)->print_value(FH,i,j);
        HIT++;
  }
}
void StatServices::reset ( ) [virtual]

clear the list of StatHandler

Reimplemented from Service.

Definition at line 125 of file statservices.cc.

References _children.

Referenced by SimRunner::reset_services().

{
  Service::reset();
  
  list< StatHandlerBase* >::iterator HIT = _children.begin();
  
  while(HIT != _children.end()) {
        (*HIT)->reset();
        HIT++;
  }
  
  _children.clear();
}
void StatServices::set ( std::string &  str,
unsigned int  occ 
) [inline]

Definition at line 70 of file statservices.h.

References _occurrence, and _statArg.

Referenced by LCE_StatServiceNotifier::loadStatServices().

{_statArg = str; _occurrence = occ;}
void StatServices::set_pop_ptr ( Metapop pop) [inline]

Definition at line 68 of file statservices.h.

References _popPtr.

Referenced by SimRunner::init_components().

{_popPtr=pop;}
void StatServices::setOcccurrence ( unsigned int  value) [inline]

Definition at line 74 of file statservices.h.

References _occurrence.

{_occurrence = value;}
void StatServices::setStatAverage ( )

Definition at line 177 of file statservices.cc.

References _children.

Referenced by LCE_StatFH::PrintStat_byGen().

{
  list< StatHandlerBase* >::iterator HIT = _children.begin();
  
  while(HIT != _children.end()) {
        (*HIT)->setAverage();
        HIT++;
  }
}

Member Data Documentation

std::list< StatHandlerBase* > StatServices::_children [private]
unsigned int StatServices::_occurrence [private]

Definition at line 54 of file statservices.h.

Referenced by getOccurrence(), notify(), set(), and setOcccurrence().

Definition at line 48 of file statservices.h.

Referenced by get_pop_ptr(), and set_pop_ptr().

std::string StatServices::_statArg [private]

Definition at line 52 of file statservices.h.

Referenced by getStatArg(), init(), and set().


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