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

A class to handle simulation data saving in binary format. More...

#include <binarydatasaver.h>

+ Inheritance diagram for BinaryDataSaver:
+ Collaboration diagram for BinaryDataSaver:

Public Member Functions

 BinaryDataSaver ()
 
 ~BinaryDataSaver ()
 
void printData ()
 
virtual bool setParameters ()
 
virtual void execute ()
 
virtual BinaryDataSaverclone ()
 
virtual vector< string > ifExist ()
 
virtual void FHwrite ()
 
virtual void FHread (string &filename)
 
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...
 
- Public Member Functions inherited from FileHandler
 FileHandler (const char *ext)
 
virtual ~FileHandler ()
 
virtual void init ()
 Called by notifier during simulation setup, performs file checking. More...
 
virtual void set (bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path)
 Sets the hanlder parameters. More...
 
virtual void set_multi (bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path)
 
virtual void update ()
 Updates the inner replicate and generation counters and calls FHwrite if needed by the the periodicity of the file. More...
 
Metapopget_pop_ptr ()
 Returns the pointer to the current metapop through the FileServices interface. More...
 
void set_pop_ptr (Metapop *pop_ptr)
 
FileServicesget_service ()
 Returns pointer to the FileServices. More...
 
void set_service (FileServices *srv)
 
std::string & get_path ()
 
void set_path ()
 
std::string & get_extension ()
 
void set_extension (const char *ext)
 
std::string & get_filename ()
 Builds and returns the current file name depending on the periodicity of the file. More...
 
bool get_isInputHandler ()
 
void set_isInputHandler (bool val)
 
bool get_isReplicatePeriodic ()
 
void set_isReplicatePeriodic (bool val)
 
unsigned int get_ReplicateOccurrence ()
 
void set_ReplicateOccurrence (unsigned int val)
 
bool get_isGenerationPeriodic ()
 
void set_isGenerationPeriodic (bool val)
 
unsigned int get_GenerationOccurrence ()
 
void set_GenerationOccurrence (unsigned int val)
 
unsigned int get_ExecRank ()
 unused yet... More...
 
void set_ExecRank (int val)
 
TMatrixget_OccMatrix ()
 
void set_OccMatrix (TMatrix *occ)
 
bool get_isMasterExec ()
 
void set_isMasterExec (bool is)
 
- Public Member Functions inherited from Handler
virtual ~Handler ()
 

Static Public Attributes

static pid_t PID = 0
 

Private Member Functions

void setFileDescriptor ()
 
int getFileDescriptor ()
 
void printHeader ()
 
void storeData ()
 
void printOffsetTable ()
 
void finish ()
 

Private Attributes

BinaryStorageBuffer _buff
 
std::string _comp_cmd
 
std::string _comp_ext
 
std::string _uncomp_cmd
 
std::string _tar_cmd
 
std::string _tar_ext
 
std::string _dir
 
bool _isPeriodic
 
unsigned int _generation
 
off_t _offsetDataStart
 
vector< unsigned int > _occurrences
 
vector< unsigned int >::const_iterator _current_occurrence
 
int _fdesc
 

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...
 
- Protected Attributes inherited from FileHandler
Metapop_pop
 Pointer to the current metapop, set during initialization within the init function. More...
 

Detailed Description

A class to handle simulation data saving in binary format.

It is both an LCE and a FileHandler but the writing is executed through the LCE interface (i.e. LifeCycleEvent::execute()). Its inheritance from the FileHandler class is used to access the basic file services (i.e. basename and current replicate filename, etc.).

Constructor & Destructor Documentation

◆ BinaryDataSaver()

BinaryDataSaver::BinaryDataSaver ( )
54 : LifeCycleEvent("store",""), FileHandler(".bin"), _isPeriodic(0)
55 {
58 
59  add_parameter("store_generation",INT,true,false,0,0,updater);
60  add_parameter("store_recursive",BOOL,false,false,0,0,updater);
61  add_parameter("store_dir",STR,false,false,0,0,updater);
62  add_parameter("store_nocompress",BOOL,false,false,0,0,updater);
63  add_parameter("store_noarchive",BOOL,false,false,0,0,updater);
64  add_parameter("store_compress_cmde",STR,false,false,0,0,updater);
65  add_parameter("store_compress_extension",STR,false,false,0,0,updater);
66  add_parameter("store_uncompress_cmde",STR,false,false,0,0,updater);
67  add_parameter("store_archive_cmde",STR,false,false,0,0,updater);
68  add_parameter("store_archive_extension",STR,false,false,0,0,updater);
69 }
bool _isPeriodic
Definition: binarydatasaver.h:50
virtual bool setParameters()
Definition: binarydatasaver.cc:73
FileHandler(const char *ext)
Definition: filehandler.h:106
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:97
Implementation of the ParamUpdaterBase interface.
Definition: param.h:362
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
@ BOOL
Definition: types.h:77
@ STR
Definition: types.h:77
@ INT
Definition: types.h:77

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

Referenced by clone().

+ Here is the caller graph for this function:

◆ ~BinaryDataSaver()

BinaryDataSaver::~BinaryDataSaver ( )
inline
74 {}

Member Function Documentation

◆ addAgeClass()

virtual age_t BinaryDataSaver::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

94 {return 0;}

◆ clone()

virtual BinaryDataSaver* BinaryDataSaver::clone ( )
inlinevirtual

Implements LifeCycleEvent.

84 {return new BinaryDataSaver();}
BinaryDataSaver()
Definition: binarydatasaver.cc:53

References BinaryDataSaver().

◆ execute()

void BinaryDataSaver::execute ( )
virtual

Implements LifeCycleEvent.

219 {
220  //set the buffer ready to be filled
221  if(_popPtr->getCurrentGeneration() == 1) {
223  }
224 
226 
227  _buff.set_buff(this);
228  printHeader();
229  storeData();
231  finish();
232 
234  }
235 
236 // //if the generation to store is > than the total nbr of generations,
237 // //correct this and store the last one
238 // if(!_isPeriodic && _generation == _popPtr->getCurrentGeneration()) {
239 // storeData();
240 // } else
241 // //if periodic, and generation match, store the data in the buffer
242 // if( _isPeriodic && !(_popPtr->getCurrentGeneration() % _generation)){
243 // storeData();
244 // }
245 //
246 // //if reached last generation, write data to file,
247 // //this empties the storage buffer with a call to printData() within FHwrite()
248 // //thus prevents further calls to FHwrite to rewrite data to disc
249 // if (_popPtr->getCurrentGeneration() == _popPtr->getGenerations()) {
250 // //make sure the last generation is always stored before writing data to disc:
251 // //catch if tot num gene is not a multiple of _generation
252 // if( _popPtr->getCurrentGeneration() % _generation ||
253 // //catch if tot num gen is a multiple but _generation < num gen and non periodic
254 // (!_isPeriodic && _generation != _popPtr->getGenerations() &&
255 // !(_popPtr->getCurrentGeneration() % _generation)))
256 // {
257 // storeData();
258 // }
259 // printData(); //this calls _buff.clear()
260 // finish(); //this should call printOffsetTable()
261 // }
262 }
void storeData()
Definition: binarydatasaver.cc:313
BinaryStorageBuffer _buff
Definition: binarydatasaver.h:47
void finish()
Definition: binarydatasaver.cc:443
void printOffsetTable()
Definition: binarydatasaver.cc:378
vector< unsigned int > _occurrences
Definition: binarydatasaver.h:57
void printHeader()
Definition: binarydatasaver.cc:289
vector< unsigned int >::const_iterator _current_occurrence
Definition: binarydatasaver.h:59
void set_buff(BinaryDataSaver *owner)
Definition: binarystoragebuffer.h:82
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:80
unsigned int getCurrentGeneration()
Definition: metapop.h:295

References _buff, _current_occurrence, _occurrences, LifeCycleEvent::_popPtr, finish(), Metapop::getCurrentGeneration(), printHeader(), printOffsetTable(), BinaryStorageBuffer::set_buff(), and storeData().

◆ FHread()

virtual void BinaryDataSaver::FHread ( string &  filename)
inlinevirtual

Implements FileHandler.

88 {}

◆ FHwrite()

void BinaryDataSaver::FHwrite ( )
virtual

Implements FileHandler.

267 {
268  //need to make sure data is saved even though last generation has not been reached
269  //in case of population extinction, the file manager issues a notify() call after
270  //the simulation exited from the generations loop, we try to catch this call here
271 
272  //keep in mind that this function is always called at the last generation
273 
274  //if data is already written to disc, the data buffer is empty
275  //if the 'store' LCE is after the 'save_files' LCE in the life cycle, we don't write
276  //--> issues two calls to printData, this one would be before storing last generation
277  //if 'store' is before 'save_files', the data buffer should be empty by now
278 
280  printHeader();
281  printOffsetTable(); //this calls _buff.clear()
282  finish();
283  }
284 
285 }
off_t getBuffLength() const
Definition: binarystoragebuffer.h:59
virtual int get_rank()
Accessor to the LCE rank in the life cycle.
Definition: lifecycleevent.h:165
static int getCurrentRankInLifeCycle()
Definition: simenv.h:63

References _buff, finish(), LifeCycleEvent::get_rank(), BinaryStorageBuffer::getBuffLength(), SIMenv::getCurrentRankInLifeCycle(), printHeader(), and printOffsetTable().

◆ finish()

void BinaryDataSaver::finish ( )
private
444 {
445  bool doComp = (_comp_cmd.size() > 0),
446  doTar = (_tar_cmd.size() > 0),
447  first = (_popPtr->getCurrentReplicate() == max(1,_myenv->workerRank()));
448 
449  if (!(doComp || doTar)) return;
450 
451  stringstream sysCmd;
452 
453  if (doComp) {
454 
455  sysCmd << _comp_cmd << " ";
456 
457  if( get_service()->getMode() == 1 ) // overwrite
458  sysCmd<< "--force "; // overwrite existing compressed file
459 
460  sysCmd << get_filename() << ";";
461  }
462 
463  if (doTar) {
464 
465  sysCmd << _tar_cmd;
466 
467  if (first) sysCmd << " c"; //first replicate, create the tar archive:
468  else sysCmd << " r"; //next replicates, append files to it:
469 
470  sysCmd << "f " << get_path() << get_service()->getBaseFileName();
471 
472  if (!_myenv->isMaster()) sysCmd <<"_"<< _myenv->workerRank();
473 
474  sysCmd << _tar_ext << " --remove-files " << get_filename() << _comp_ext;
475  }
476 
477 
478  //wait for last child:
479 // if (!first) waitpid(PID,NULL,0);
480 //
481 // pid_t tPID = fork();
482 //
483 // if (tPID == 0) {
484 
485  if (system(sysCmd.str().c_str()) < 0)
486  error("BinaryDataSaver::finish system cmd \"%s\" failed: %s\n",
487  sysCmd.str().c_str(),strerror(errno));
488 
489 // _exit(EXIT_FAILURE);
490 
491 // } else if (tPID < 0) //fork failed :
492 // error("BinaryDataSaver::finish::could not fork new process: %s\n",
493 // strerror(errno));
494 //
495 // PID = tPID;
496 }
MPIenv * _myenv
Definition: MPImanager.cc:35
std::string _tar_cmd
Definition: binarydatasaver.h:49
std::string _comp_ext
Definition: binarydatasaver.h:49
std::string _tar_ext
Definition: binarydatasaver.h:49
std::string _comp_cmd
Definition: binarydatasaver.h:49
std::string & get_path()
Definition: filehandler.h:142
std::string & get_filename()
Builds and returns the current file name depending on the periodicity of the file.
Definition: filehandler.cc:150
FileServices * get_service()
Returns pointer to the FileServices.
Definition: filehandler.h:138
unsigned int getMode()
Writting mode getter.
Definition: fileservices.h:121
string & getBaseFileName()
Accessor to the base file name of the simulation.
Definition: fileservices.cc:474
bool isMaster() const
Definition: MPImanager.h:127
int workerRank() const
Definition: MPImanager.h:129
unsigned int getCurrentReplicate()
Definition: metapop.h:294
int error(const char *str,...)
Definition: output.cc:78

References _comp_cmd, _comp_ext, _myenv, LifeCycleEvent::_popPtr, _tar_cmd, _tar_ext, error(), FileHandler::get_filename(), FileHandler::get_path(), FileHandler::get_service(), FileServices::getBaseFileName(), Metapop::getCurrentReplicate(), FileServices::getMode(), MPIenv::isMaster(), and MPIenv::workerRank().

Referenced by execute(), and FHwrite().

+ Here is the caller graph for this function:

◆ getFileDescriptor()

int BinaryDataSaver::getFileDescriptor ( )
inlineprivate
64 { return _fdesc;}
int _fdesc
Definition: binarydatasaver.h:61

References _fdesc.

◆ ifExist()

vector< string > BinaryDataSaver::ifExist ( )
virtual

Reimplemented from FileHandler.

153 {
154  ifstream ifExist;
155  ifExist.setstate(ios::failbit);
156  vector< string > list;
157  string filename = get_path() + get_service()->getBaseFileName();
158  string testname;
159 
160  ostringstream rpl, gen;
161 
162  gen.fill('0');
163  gen.width( (int)log10((double)_pop->getGenerations()) + 1);
165 
166  rpl.fill('0');
167  rpl.width( (int)log10((double)_pop->getReplicates()) + 1);
169 
170  if(!_isPeriodic)
171  filename += "_" + rpl.str() + get_extension();
172  else
173  filename += "_" + gen.str() + "_" + rpl.str() + get_extension();
174 
175  //check if the basefilename is already used on disk:
176  ifExist.open(filename.c_str(),ios::in);
177  if(ifExist.is_open()) {
178  list.push_back(filename);
179  }
180  ifExist.close();
181  ifExist.setstate(ios::failbit);
182 
183 
184  //check if compressed files are present:
185  if( _comp_cmd != "" ) {
186 
187  testname = filename + _comp_ext;
188 
189  ifExist.open(testname.c_str(),ios::in);
190 
191  if(ifExist.is_open()) {
192  list.push_back(testname);
193  }
194 
195  ifExist.close();
196  ifExist.setstate(ios::failbit);
197  }
198 
199  if( _tar_cmd != "" ) {
200 
201  testname = filename + _tar_ext;
202 
203  ifExist.open(testname.c_str(),ios::in);
204 
205  if(ifExist.is_open()) {
206  list.push_back(testname);
207  }
208 
209  ifExist.close();
210  ifExist.setstate(ios::failbit);
211  }
212 
213  return list;
214 }
virtual vector< string > ifExist()
Definition: binarydatasaver.cc:152
Metapop * _pop
Pointer to the current metapop, set during initialization within the init function.
Definition: filehandler.h:102
unsigned int get_ReplicateOccurrence()
Definition: filehandler.h:159
unsigned int get_GenerationOccurrence()
Definition: filehandler.h:165
std::string & get_extension()
Definition: filehandler.h:146
unsigned int getGenerations()
Definition: metapop.h:272
unsigned int getReplicates()
Definition: metapop.h:274

References _comp_cmd, _comp_ext, _isPeriodic, FileHandler::_pop, _tar_cmd, _tar_ext, FileHandler::get_extension(), FileHandler::get_GenerationOccurrence(), FileHandler::get_path(), FileHandler::get_ReplicateOccurrence(), FileHandler::get_service(), FileServices::getBaseFileName(), Metapop::getGenerations(), and Metapop::getReplicates().

◆ loadFileServices()

virtual void BinaryDataSaver::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

90 {loader->attach(this);}
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:60

References FileServices::attach().

◆ loadStatServices()

virtual void BinaryDataSaver::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

91 {}

◆ printData()

void BinaryDataSaver::printData ( )
368 {
369  //we print what is in the buffer and empty it for the next bucket
370  if((write(_fdesc,_buff.getBuffer(),_buff.getBuffLength())) == -1)
371  fatal("BinaryDataSaver::printData::write %s\n",strerror(errno));
372 
373  _buff.emptyBuffer();
374 }
char * getBuffer() const
Definition: binarystoragebuffer.h:58
void emptyBuffer()
Definition: binarystoragebuffer.h:70
void fatal(const char *str,...)
Definition: output.cc:99

References _buff, _fdesc, BinaryStorageBuffer::emptyBuffer(), fatal(), BinaryStorageBuffer::getBuffer(), and BinaryStorageBuffer::getBuffLength().

Referenced by BinaryStorageBuffer::store().

+ Here is the caller graph for this function:

◆ printHeader()

void BinaryDataSaver::printHeader ( )
private
290 {
291  //first, record the parameters in text mode:
292  ofstream FILE (get_filename().c_str(), ios::out);
293 
294  if(!FILE) fatal("could not open Binary output file!!\n");
295 
296  list< ParamSet* > current_params = get_service()->get_params();
297  list< ParamSet* >::iterator Pit = current_params.begin();
298 
299  FILE<<"#NEMO "<<MAIN_VERSION<<" "<<MINOR_VERSION<<" "<<REVISION<<" "<<RELEASE<<" "<<VERSION_DATE<<endl;
300 
301 #ifdef _DEBUG_
302  message("BinaryDataSaver::printHeader:storing parameters\n");
303 #endif
304  while(Pit != current_params.end()) {
305  (*Pit)->print(FILE);
306  Pit++;
307  }
308  FILE.close();
309 }
list< ParamSet * > & get_params()
Accessor to the list of the current parameters of the simulation.
Definition: fileservices.h:136
void message(const char *message,...)
Definition: output.cc:39
#define VERSION_DATE
Definition: version.h:29
#define MINOR_VERSION
Definition: version.h:26
#define RELEASE
Definition: version.h:28
#define MAIN_VERSION
Definition: version.h:25
#define REVISION
Definition: version.h:27

References fatal(), FileHandler::get_filename(), FileServices::get_params(), FileHandler::get_service(), MAIN_VERSION, message(), MINOR_VERSION, RELEASE, REVISION, and VERSION_DATE.

Referenced by execute(), and FHwrite().

+ Here is the caller graph for this function:

◆ printOffsetTable()

void BinaryDataSaver::printOffsetTable ( )
private
379 {
380 
381  //get the offset position of the EOF, will be the nbr of bytes to add to the generation offsets
382  // (data has already been written, the header plus any previous data)
383  off_t pos = lseek(_fdesc,0,SEEK_END);
384 
385  if(pos == -1) fatal("BinaryDataSaver::printOffsetTable::lseek failed %s\n",strerror(errno));
386 
387 // cout<<"+++BinaryDataSaver::printOffsetTable::EOF at "<<pos;
388 
389  //offset of the offset table:
390 // off_t off_table = _buff.getBuffLength() + pos;
391 
392 // cout<<"; adding "<<_buff.getBuffLength()<<"B of in-buff data +";
393 
394  //add the offset info at the end of the _buff:
395  unsigned char separator[3] = {'@','O','T'};
396  _buff.store(&separator, 3);
397 
398 // std::map<unsigned int, unsigned int>::iterator IT = _offset_table.begin();
399 // while(IT != _offset_table.end()) {
400 // IT->second += pos;
401 // _buff.store((int*)&IT->first, sizeof(int));
402 // _buff.store((int*)&IT->second, sizeof(off_t));
403 // IT++;
404 // }
405 
406  //_offset_table = pos; //EOF of current file, position of the start of the generation record
407 
408  unsigned int dummy = _popPtr->getCurrentGeneration();
409 
410  _buff.store(&dummy, sizeof(int));
411 
412  _buff.store(&_offsetDataStart, sizeof(off_t)); //previously stored offset of the generation separator
413 
414  //finally, record the number of generations recorded and the offset of start of the offset table
415 // int nb_recgen = _offset_table.size();
416 // int nb_recgen = 1; //always store only one generation
417 // _buff.store(&nb_recgen, sizeof(int));
418 // _buff.store(&off_table, sizeof(off_t));
419 
420 // cout<<" "<<4*sizeof(int)+3<<"B for the offset table = "<<_buff.getBuffLength()<<"B\n";
421 
422  //now write the data to the file, that is, anything remaining in the buffer:
423 #ifdef _DEBUG_
424  message("BinaryDataSaver::printOffsetTable:writing %iB of data ",_buff.getBuffLength());
425 #endif
426 
427  if((write(_fdesc,_buff.getBuffer(),_buff.getBuffLength())) == -1)
428  fatal("BinaryDataSaver::printOffsetTable::write %s\n",strerror(errno));
429 
430  if((close(_fdesc)) == -1)
431  error("BinaryDataSaver::printOffsetTable::close %s\n",strerror(errno));
432 
433  //empty the buffer, get ready for next record
434  _buff.clear();
435 
436 #ifdef _DEBUG_
437  message(" [ok]\n");
438 #endif
439 }
off_t _offsetDataStart
Definition: binarydatasaver.h:55
void clear()
Definition: binarystoragebuffer.h:62
void store(void *stream, unsigned int nb_bytes)
Definition: binarystoragebuffer.cc:37

References _buff, _fdesc, _offsetDataStart, LifeCycleEvent::_popPtr, BinaryStorageBuffer::clear(), error(), fatal(), BinaryStorageBuffer::getBuffer(), BinaryStorageBuffer::getBuffLength(), Metapop::getCurrentGeneration(), message(), and BinaryStorageBuffer::store().

Referenced by execute(), and FHwrite().

+ Here is the caller graph for this function:

◆ removeAgeClass()

virtual age_t BinaryDataSaver::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

93 {return 0;}

◆ requiredAgeClass()

virtual age_t BinaryDataSaver::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

95 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

92 {return false;}

◆ setFileDescriptor()

void BinaryDataSaver::setFileDescriptor ( )
private
353 {
354  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
355  int flag = O_WRONLY | O_APPEND;
356 
357  //open in write and append mode with permission flag set to rw-r--r--
358  _fdesc = open(get_filename().c_str(), flag, mode);
359 
360  if(_fdesc == -1)
361  fatal("BinaryDataSaver::printData::open %s:%s\n",get_filename().c_str(),strerror(errno));
362 
363 }

References _fdesc, fatal(), and FileHandler::get_filename().

Referenced by storeData().

+ Here is the caller graph for this function:

◆ setParameters()

bool BinaryDataSaver::setParameters ( )
virtual

Implements SimComponent.

74 {
75  Param* param;
76 
77  _generation = (unsigned int)get_parameter_value("store_generation");
78 
79  //make sure we at least save the last generation:
81 
82  param = get_parameter("store_dir");
83  if(param->isSet())
84  _dir = param->getArg();
85  else
86  _dir = "";
87 
88  param = get_parameter("store_recursive");
89  if(param->isSet())
90  _isPeriodic = true;
91  else
92  _isPeriodic = false;
93 
94  param = get_parameter("store_compress_cmde");
95  if(param->isSet())
96  _comp_cmd = param->getArg();
97  else
98  _comp_cmd = "bzip2"; //default compressor used
99 
100  param = get_parameter("store_compress_extension");
101  if(param->isSet())
102  _comp_ext = param->getArg();
103  else
104  _comp_ext = ".bz2"; //default
105 
106  param = get_parameter("store_uncompress_cmde");
107  if(param->isSet())
108  _uncomp_cmd = param->getArg();
109  else
110  _uncomp_cmd = "unbzip2"; //default
111 
112  param = get_parameter("store_archive_cmde");
113  if(param->isSet())
114  _tar_cmd = param->getArg();
115  else
116  _tar_cmd = "tar"; //default
117 
118  param = get_parameter("store_archive_extension");
119  if(param->isSet())
120  _tar_ext = param->getArg();
121  else
122  _tar_ext = ".tar"; //default
123 
124  param = get_parameter("store_nocompress");
125  if(param->isSet()) {_comp_cmd = ""; _comp_ext ="";} //compression process disabled
126 
127  param = get_parameter("store_noarchive");
128  if(param->isSet()) {_tar_cmd = ""; _tar_ext = "";} //archiving processed disabled
129 
130  //set the file handler, will be called by FileServices, will output data at each gen
132 
133  _offsetDataStart = 0L; //this stores the offset of the stored data in the file, positioned after
134  // the simulation parameters stored in plain text.
135 
136  _occurrences.clear();
137 
138  if(_isPeriodic) {
139  unsigned int num_occurrences = _popPtr->getGenerations() / _generation;
140 
141  for(unsigned int i = 1; i <= num_occurrences; ++i)
142  _occurrences.push_back( i* _generation);
143  } else
144  _occurrences.push_back(_generation);
145 
147 
148 
149  return true;
150 }
std::string _dir
Definition: binarydatasaver.h:49
unsigned int _generation
Definition: binarydatasaver.h:51
std::string _uncomp_cmd
Definition: binarydatasaver.h:49
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path)
Sets the hanlder parameters.
Definition: filehandler.h:196
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
string getArg()
Definition: param.h:137
bool isSet()
Definition: param.h:139
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:142
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:138

References _comp_cmd, _comp_ext, _current_occurrence, _dir, _generation, _isPeriodic, _occurrences, _offsetDataStart, LifeCycleEvent::_popPtr, _tar_cmd, _tar_ext, _uncomp_cmd, SimComponent::get_parameter(), SimComponent::get_parameter_value(), LifeCycleEvent::get_rank(), Param::getArg(), Metapop::getGenerations(), Param::isSet(), and FileHandler::set().

Referenced by BinaryDataSaver().

+ Here is the caller graph for this function:

◆ storeData()

void BinaryDataSaver::storeData ( )
private
314 {
315 #ifdef _DEBUG_
316  message("BinaryDataSaver::storeData\n");
317  unsigned int byte_count = _buff.getBuffLength();
318 #endif
319 
320  unsigned int generation = _popPtr->getCurrentGeneration();
321  unsigned char separator[2] = {'@','G'}; //generation separator = '@G'
322 
323  //store the data, begin with generation separator and number:
324  _buff.store(&separator, 2 * sizeof(unsigned char));
325 
326  _buff.store(&generation, sizeof(unsigned int));
327 
328  //open the output file;
330 
331  //store the position of the generation separator in the buffer into the offset table:
332  //_offsetDataStart = _buff.getTotByteRecorded();
333 
334  _offsetDataStart = lseek(_fdesc,0,SEEK_END);
335 
336 // cout<<"BinaryDataSaver::storeData::offset of start of record: "<<_offsetDataStart
337 // <<"; data recorder so far: "<<_buff.getTotByteRecorded()<<"B\n";
338  //start storing information, the data buckets will automatically be written to file if >500MB
339 
340  //Metapop is a StorableComponent, call store_data:
341  //stores all individual info, including trait sequences
343 
344 #ifdef _DEBUG_
345  message("BinaryDataSaver::storeData::stored %iB\n",(_buff.getBuffLength()-byte_count));
346  byte_count = _buff.getBuffLength();
347 #endif
348 }
void setFileDescriptor()
Definition: binarydatasaver.cc:352
virtual void store_data(BinaryStorageBuffer *saver)
Definition: metapop.cc:452

References _buff, _fdesc, _offsetDataStart, LifeCycleEvent::_popPtr, BinaryStorageBuffer::getBuffLength(), Metapop::getCurrentGeneration(), message(), setFileDescriptor(), BinaryStorageBuffer::store(), and Metapop::store_data().

Referenced by execute().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _buff

BinaryStorageBuffer BinaryDataSaver::_buff
private

◆ _comp_cmd

std::string BinaryDataSaver::_comp_cmd
private

Referenced by finish(), ifExist(), and setParameters().

◆ _comp_ext

std::string BinaryDataSaver::_comp_ext
private

Referenced by finish(), ifExist(), and setParameters().

◆ _current_occurrence

vector< unsigned int >::const_iterator BinaryDataSaver::_current_occurrence
private

Referenced by execute(), and setParameters().

◆ _dir

std::string BinaryDataSaver::_dir
private

Referenced by setParameters().

◆ _fdesc

int BinaryDataSaver::_fdesc
private

◆ _generation

unsigned int BinaryDataSaver::_generation
private

Referenced by setParameters().

◆ _isPeriodic

bool BinaryDataSaver::_isPeriodic
private

Referenced by ifExist(), and setParameters().

◆ _occurrences

vector< unsigned int > BinaryDataSaver::_occurrences
private

Referenced by execute(), and setParameters().

◆ _offsetDataStart

off_t BinaryDataSaver::_offsetDataStart
private

◆ _tar_cmd

std::string BinaryDataSaver::_tar_cmd
private

Referenced by finish(), ifExist(), and setParameters().

◆ _tar_ext

std::string BinaryDataSaver::_tar_ext
private

Referenced by finish(), ifExist(), and setParameters().

◆ _uncomp_cmd

std::string BinaryDataSaver::_uncomp_cmd
private

Referenced by setParameters().

◆ PID

pid_t BinaryDataSaver::PID = 0
static

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

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

Locations of visitors to this page
Catalogued on GSR