StatServices Class Reference

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

#include <statservices.h>

Inheritance diagram for StatServices:

Inheritance graph
[legend]
Collaboration diagram for StatServices:

Collaboration graph
[legend]

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.

00060 : _popPtr(0), _occurrence(0) { }

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

Definition at line 62 of file statservices.h.

00062 { }


Member Function Documentation

void StatServices::attach ( StatHandlerBase SH  )  [virtual]

Metapop* StatServices::get_pop_ptr (  )  [inline]

Definition at line 66 of file statservices.h.

Referenced by StatHandlerBase::get_pop_ptr().

00066 {return _popPtr;}

list< StatRecBase * > StatServices::getAllStats (  ) 

Definition at line 202 of file statservices.cc.

Referenced by SimRunner::get_allRegisteredStats().

00203 {
00204   list< StatHandlerBase* >::iterator HIT = _children.begin();
00205   
00206   list<StatRecBase*> allStats, stats;
00207   
00208   while(HIT != _children.end()) {
00209         stats = (*HIT)->getStats();
00210         allStats.insert(allStats.end(), stats.begin(), stats.end());
00211         HIT++;
00212   }
00213   
00214   return allStats;
00215 }

stat_it StatServices::getFirst (  )  [inline]

Definition at line 92 of file statservices.h.

00092 {return _children.begin();}

stat_it StatServices::getLast (  )  [inline]

Definition at line 94 of file statservices.h.

00094 {return _children.end();}

unsigned int StatServices::getOccurrence (  )  [inline]

std::string& StatServices::getStatArg (  )  [inline]

Definition at line 76 of file statservices.h.

00076 {return _statArg;}

unsigned int StatServices::getStatRecIndex ( unsigned int  i  ) 

Definition at line 189 of file statservices.cc.

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

00190 {
00191   list< StatHandlerBase* >::iterator el;
00192   unsigned int index = 0;
00193   //find the first statHandler that has registered statRecorders and has computed some stats:
00194   for(el = _children.begin(); el != _children.end(); el++)
00195     if((index = (*el)->getStatRecIndex(i)) != 0) break;
00196 
00197   return index;
00198 }

bool StatServices::init (  )  [virtual]

Inits internals.

Implements Service.

Definition at line 44 of file statservices.cc.

Referenced by SimRunner::init_components().

00045 {
00046   list< StatHandlerBase* >::iterator HIT;
00047   
00048   HIT = _children.begin();
00049 
00050   //first init the stat handlers -> will define the dims of the stat tables
00051   while(HIT != _children.end()) {
00052         (*HIT)->init();
00053         HIT++;
00054   }
00055   
00056   istringstream stats(_statArg);
00057   std::string arg;
00058   std::list<std::string> args;
00059   
00060   //extract the stat options from the string read in the init file
00061   while(stats>>arg) args.push_back(arg);
00062         
00063   std::list<std::string>::iterator token = args.begin();
00064   
00065   bool is_set = false;
00066   
00067   while(token != args.end()) {
00068         
00069         HIT = _children.begin();
00070         
00071         is_set = false;
00072         
00073         while(HIT != _children.end() && !is_set) {
00074           is_set |= (*HIT)->setStatRecorders( (*token) );
00075           HIT++;
00076         }
00077 
00078         if(!is_set) {
00079           error("the string \"%s\" is not a valid stat option\n",(*token).c_str());
00080           return false;
00081         }
00082         
00083         token++;
00084   }
00085   
00086   
00087   return true;
00088 }

void StatServices::load ( SimComponent sc  )  [virtual]

tell the SimComponent to load its stat handlers

Parameters:
sc the SimComponent

Implements Service.

Definition at line 92 of file statservices.cc.

Referenced by SimRunner::register_component().

00093 {
00094   sc->loadStatServices(this);
00095 }

void StatServices::notify (  )  [virtual]

Notifies all observers to update their state.

Reimplemented from Service.

Definition at line 108 of file statservices.cc.

Referenced by LCE_StatServiceNotifier::execute().

00109 {
00110 #ifdef _DEBUG_
00111   message("StatServices::notify (%i): ",( !(SIMenv::MainSim->getCurrentGeneration() % _occurrence)  
00112                                          || SIMenv::MainSim->getCurrentGeneration() == 1 ));
00113   fflush(stdout);
00114 #endif
00115   //we automatically save first and last generations
00116   if( !(SIMenv::MainSim->getCurrentGeneration() % _occurrence)  || SIMenv::MainSim->getCurrentGeneration() == 1 )
00117     Service::notify();
00118 #ifdef _DEBUG_
00119   message("\n");
00120 #endif
00121 }

void StatServices::printStatAverage ( std::ofstream &  FH,
unsigned int  i 
)

Definition at line 165 of file statservices.cc.

Referenced by LCE_StatFH::PrintStat_byGen().

00166 {
00167   list< StatHandlerBase* >::iterator HIT = _children.begin();
00168   
00169   while(HIT != _children.end()) {
00170         (*HIT)->print_average(FH,i);
00171         HIT++;
00172   }
00173 }

void StatServices::printStatHeaders ( std::ofstream &  FH,
unsigned int  order 
)

Definition at line 141 of file statservices.cc.

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

00142 {
00143   list< StatHandlerBase* >::iterator HIT = _children.begin();
00144   
00145   while(HIT != _children.end()) {
00146         (*HIT)->print_headers(FH,order);
00147         HIT++;
00148   }
00149 }

void StatServices::printStatValue ( std::ofstream &  FH,
unsigned int  i,
unsigned int  j 
)

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

Parameters:
FH the file output stream
i the generation index in the stat tables (row)
j the replicate indes in the stat tables (column)

Definition at line 153 of file statservices.cc.

Referenced by LCE_StatFH::FHwrite().

00154 {
00155   list< StatHandlerBase* >::iterator HIT = _children.begin();
00156   
00157   while(HIT != _children.end()) {
00158         (*HIT)->print_value(FH,i,j);
00159         HIT++;
00160   }
00161 }

void StatServices::reset (  )  [virtual]

clear the list of StatHandler

Reimplemented from Service.

Definition at line 125 of file statservices.cc.

Referenced by SimRunner::reset_services().

00126 {
00127   Service::reset();
00128   
00129   list< StatHandlerBase* >::iterator HIT = _children.begin();
00130   
00131   while(HIT != _children.end()) {
00132         (*HIT)->reset();
00133         HIT++;
00134   }
00135   
00136   _children.clear();
00137 }

void StatServices::set ( std::string &  str,
unsigned int  occ 
) [inline]

Definition at line 70 of file statservices.h.

Referenced by LCE_StatServiceNotifier::loadStatServices().

00070 {_statArg = str; _occurrence = occ;}

void StatServices::set_pop_ptr ( Metapop pop  )  [inline]

Definition at line 68 of file statservices.h.

Referenced by SimRunner::init_components().

00068 {_popPtr=pop;}

void StatServices::setOcccurrence ( unsigned int  value  )  [inline]

Definition at line 74 of file statservices.h.

00074 {_occurrence = value;}

void StatServices::setStatAverage (  ) 

Definition at line 177 of file statservices.cc.

Referenced by LCE_StatFH::PrintStat_byGen().

00178 {
00179   list< StatHandlerBase* >::iterator HIT = _children.begin();
00180   
00181   while(HIT != _children.end()) {
00182         (*HIT)->setAverage();
00183         HIT++;
00184   }
00185 }


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