Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCE_FileServicesNotifier Class Reference

Event used to notify all file handlers to update their state through the FileServices::notify() interface. More...

#include <servicenotifiers.h>

+ Inheritance diagram for LCE_FileServicesNotifier:
+ Collaboration diagram for LCE_FileServicesNotifier:

Public Member Functions

 LCE_FileServicesNotifier ()
 
virtual ~LCE_FileServicesNotifier ()
 
virtual void execute ()
 
virtual bool setParameters ()
 
virtual LifeCycleEventclone ()
 
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
virtual age_t removeAgeClass ()
 
virtual age_t addAgeClass ()
 
virtual age_t requiredAgeClass ()
 
- Public Member Functions inherited from LifeCycleEvent
 LifeCycleEvent (const char *name, const char *trait_link)
 Cstor. More...
 
virtual ~LifeCycleEvent ()
 
virtual void init (Metapop *popPtr)
 Sets the pointer to the current Metapop and the trait link if applicable. More...
 
virtual bool attach_trait (string trait)
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 
virtual void set_event_name (std::string &name)
 Set the name of the event (name of the ParamSet) and add the corresponding parameter to the set. More...
 
virtual void set_event_name (const char *name)
 
virtual string & get_event_name ()
 Accessor to the LCE's name. More...
 
virtual int get_rank ()
 Accessor to the LCE rank in the life cycle. More...
 
virtual void set_pop_ptr (Metapop *popPtr)
 Accessors for the population pointer. More...
 
virtual Metapopget_pop_ptr ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 
virtual bool has_parameter (std::string name)
 Param getter. More...
 

Private Attributes

FileServices_service
 
unsigned int _sample_size
 
age_t _sample_age
 
GenotyperFH_genotyper
 

Additional Inherited Members

- Protected Attributes inherited from LifeCycleEvent
std::string _event_name
 The param name to be read in the init file. More...
 
Metapop_popPtr
 The ptr to the current Metapop. More...
 
std::string _LCELinkedTraitType
 The name of the linked trait. More...
 
int _LCELinkedTraitIndex
 The index in the individual's trait table of the linked trait. More...
 
- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 

Detailed Description

Event used to notify all file handlers to update their state through the FileServices::notify() interface.

Constructor & Destructor Documentation

◆ LCE_FileServicesNotifier()

LCE_FileServicesNotifier::LCE_FileServicesNotifier ( )
62  : LifeCycleEvent("save_files",""),
64 {
65 
66  add_parameter("files_sample_size", INT, false, false, 0, 0);
67  add_parameter("files_sample_age", INT, false, false, 0, 0);
68  add_parameter("files_genotyper_traits", STR, false, false, 0, 0);
69  add_parameter("files_genotyper_format", STR, false, false, 0, 0);
70  add_parameter("files_genotyper_logtime", INT, false, false, 0, 0);
71  add_parameter("files_genotyper_dir", STR, false, false, 0, 0);
72  add_parameter("files_genotyper_trim_fixed", BOOL, false, false, 0, 0);
73 
74 }
GenotyperFH * _genotyper
Definition: servicenotifiers.h:79
age_t _sample_age
Definition: servicenotifiers.h:77
FileServices * _service
Definition: servicenotifiers.h:75
unsigned int _sample_size
Definition: servicenotifiers.h:76
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
@ BOOL
Definition: types.h:78
@ STR
Definition: types.h:78
@ INT
Definition: types.h:78

References SimComponent::add_parameter(), BOOL, INT, and STR.

Referenced by clone().

◆ ~LCE_FileServicesNotifier()

LCE_FileServicesNotifier::~LCE_FileServicesNotifier ( )
virtual
77 {
78  if(_genotyper) delete _genotyper;
79 }

References _genotyper.

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_FileServicesNotifier::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

95 {return 0;}

◆ clone()

virtual LifeCycleEvent* LCE_FileServicesNotifier::clone ( )
inlinevirtual

Implements LifeCycleEvent.

88 {return new LCE_FileServicesNotifier();}
LCE_FileServicesNotifier()
Definition: servicenotifiers.cc:62

References LCE_FileServicesNotifier().

◆ execute()

void LCE_FileServicesNotifier::execute ( )
virtual

Implements LifeCycleEvent.

165 {
166 #ifdef _DEBUG_
167  message("LCE_FileServicesNotifier::execute (gen: %i rpl: %i)\n",
168  this->get_pop_ptr()->getCurrentGeneration(),
169  this->get_pop_ptr()->getCurrentReplicate());
170 #endif
171 
172  _service->notify();
173 }
virtual void notify()
Definition: fileservices.cc:189
virtual Metapop * get_pop_ptr()
Definition: lifecycleevent.h:174
void message(const char *message,...)
Definition: output.cc:40

References _service, LifeCycleEvent::get_pop_ptr(), message(), and FileServices::notify().

◆ loadFileServices()

void LCE_FileServicesNotifier::loadFileServices ( FileServices loader)
virtual

Implements SimComponent.

111 {
112  _service = loader;
113 
114  // tell the file services to reset the sampled metapop to avoid pbs between chained simulations
116 
118 
119  if(get_parameter("files_genotyper_traits")->isSet()) {
120 
121  // create FH for merged output
122  if( _genotyper) delete _genotyper;
123  _genotyper = new GenotyperFH(this);
124 
125  vector< string > traits = get_parameter("files_genotyper_traits")->getMultiArgs();
126 
127  int index;
128 
129  for(unsigned int i = 0; i < traits.size(); i++) {
130 
131  if( _popPtr->getTraitIndex(traits[i].c_str()) < 0) {
132 
133  fatal("Genotyper::cannot find trait \"%s\" among successfully initialized traits.\n", traits[i].c_str());
134 
135  }
136  }
137 
138  _genotyper->setTraits(traits);
139 
140  Param* param = get_parameter("files_genotyper_logtime");
141 
142  if(!param->isSet()) fatal("parameter \"files_genotyper_logtime\" is missing\n");
143 
144  if(param->isMatrix()) {
145 
146  TMatrix temp;
147 
148  param->getMatrix(&temp);
149 
150  _genotyper->set_multi(true, true, 1, &temp, get_parameter("files_genotyper_dir")->getArg());
151 
152  // rpl_per, gen_per, rpl_occ, gen_occ, rank, path, self-ref
153  } else
154  _genotyper->set(true, param->isSet(), 1, (param->isSet() ? (int)param->getValue() : 0),
155  0, get_parameter("files_genotyper_dir")->getArg(), this);
156 
157  loader->attach(_genotyper);
158  }
159 
160 }
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path, LCE *event)
Definition: filehandler.h:272
virtual void set_multi(bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path)
Definition: filehandler.h:197
void set_sampling_params(unsigned int size, age_t age)
Set the population sampling params.
Definition: fileservices.h:176
void reset_sampled_pop()
Remove the existing sampled metapop, if it has been allocated previously.
Definition: fileservices.cc:357
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:61
Definition: servicenotifiers.h:101
void setTraits(vector< trait_t > &traits)
Definition: servicenotifiers.cc:175
int getTraitIndex(trait_t type)
Gives the index of trait with type.
Definition: indfactory.cc:128
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This structure stores one parameter, its definition and its string argument.
Definition: param.h:54
double getValue()
Returns the argument value according to its type.
Definition: param.cc:368
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:172
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:378
vector< string > getMultiArgs()
Definition: param.cc:120
bool isSet()
Definition: param.h:140
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:50
void fatal(const char *str,...)
Definition: output.cc:96

References _genotyper, LifeCycleEvent::_popPtr, _sample_age, _sample_size, _service, FileServices::attach(), fatal(), SimComponent::get_parameter(), Param::getMatrix(), Param::getMultiArgs(), IndFactory::getTraitIndex(), Param::getValue(), Param::isMatrix(), Param::isSet(), FileServices::reset_sampled_pop(), EventFileHandler< LCE >::set(), FileHandler::set_multi(), FileServices::set_sampling_params(), and GenotyperFH::setTraits().

◆ loadStatServices()

virtual void LCE_FileServicesNotifier::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

92 {}

◆ removeAgeClass()

virtual age_t LCE_FileServicesNotifier::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

94 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_FileServicesNotifier::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

96 {return 0;}

◆ resetParameterFromSource()

virtual bool LCE_FileServicesNotifier::resetParameterFromSource ( std::string  param,
SimComponent cmpt 
)
inlinevirtual

Implements SimComponent.

93 {return false;}

◆ setParameters()

bool LCE_FileServicesNotifier::setParameters ( )
virtual

Implements SimComponent.

84 {
85  _sample_size = 0;
86  _sample_age = 0;
87 
88  if( get_parameter("files_sample_size")->isSet() ) {
89 
90  _sample_size = get_parameter_value("files_sample_size");
91 
92  if(get_parameter("files_sample_age")->isSet())
93  _sample_age = static_cast<age_t> (get_parameter_value("files_sample_age"));
94 
95  } else if(get_parameter("files_sample_age")->isSet()) {
96  return error("parameter \"files_sample_age\" but parameter \"files_sample_size\" is missing\n");
97  }
98 
99 
100  if(get_parameter("files_genotyper_traits")->isSet()){
101 
102  //read trait types, get genetic map
103  }
104 
105  return true;
106 }
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
int error(const char *str,...)
Definition: output.cc:77
unsigned int age_t
Age class flags.
Definition: types.h:46

References _sample_age, _sample_size, error(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), and Param::isSet().

Member Data Documentation

◆ _genotyper

GenotyperFH* LCE_FileServicesNotifier::_genotyper
private

◆ _sample_age

age_t LCE_FileServicesNotifier::_sample_age
private

Referenced by loadFileServices(), and setParameters().

◆ _sample_size

unsigned int LCE_FileServicesNotifier::_sample_size
private

Referenced by loadFileServices(), and setParameters().

◆ _service

FileServices* LCE_FileServicesNotifier::_service
private

Referenced by execute(), and loadFileServices().


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

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR