Nemo  2.4.0b
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 ( )
55 : LifeCycleEvent("store",""), FileHandler(".bin"), _isPeriodic(0)
56 {
59 
60  add_parameter("store_generation",INT,true,false,0,0,updater);
61  add_parameter("store_recursive",BOOL,false,false,0,0,updater);
62  add_parameter("store_dir",STR,false,false,0,0,updater);
63  add_parameter("store_nocompress",BOOL,false,false,0,0,updater);
64  add_parameter("store_noarchive",BOOL,false,false,0,0,updater);
65  add_parameter("store_compress_cmde",STR,false,false,0,0,updater);
66  add_parameter("store_compress_extension",STR,false,false,0,0,updater);
67  add_parameter("store_uncompress_cmde",STR,false,false,0,0,updater);
68  add_parameter("store_archive_cmde",STR,false,false,0,0,updater);
69  add_parameter("store_archive_extension",STR,false,false,0,0,updater);
70 }
bool _isPeriodic
Definition: binarydatasaver.h:51
virtual bool setParameters()
Definition: binarydatasaver.cc:74
FileHandler(const char *ext)
Definition: filehandler.h:107
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
Implementation of the ParamUpdaterBase interface.
Definition: param.h:363
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, setParameters(), and STR.

Referenced by clone().

◆ ~BinaryDataSaver()

BinaryDataSaver::~BinaryDataSaver ( )
inline
75 {}

Member Function Documentation

◆ addAgeClass()

virtual age_t BinaryDataSaver::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

95 {return 0;}

◆ clone()

virtual BinaryDataSaver* BinaryDataSaver::clone ( )
inlinevirtual

Implements LifeCycleEvent.

85 {return new BinaryDataSaver();}
BinaryDataSaver()
Definition: binarydatasaver.cc:54

References BinaryDataSaver().

◆ execute()

void BinaryDataSaver::execute ( )
virtual

Implements LifeCycleEvent.

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

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.

89 {}

◆ FHwrite()

void BinaryDataSaver::FHwrite ( )
virtual

Implements FileHandler.

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

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

◆ finish()

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

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().

◆ getFileDescriptor()

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

References _fdesc.

◆ ifExist()

vector< string > BinaryDataSaver::ifExist ( )
virtual

Reimplemented from FileHandler.

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

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.

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

References FileServices::attach().

◆ loadStatServices()

virtual void BinaryDataSaver::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

92 {}

◆ printData()

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

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

Referenced by BinaryStorageBuffer::store().

◆ printHeader()

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

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().

◆ printOffsetTable()

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

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().

◆ removeAgeClass()

virtual age_t BinaryDataSaver::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

94 {return 0;}

◆ requiredAgeClass()

virtual age_t BinaryDataSaver::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

96 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

93 {return false;}

◆ setFileDescriptor()

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

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

Referenced by storeData().

◆ setParameters()

bool BinaryDataSaver::setParameters ( )
virtual

Implements SimComponent.

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

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().

◆ storeData()

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

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

Referenced by execute().

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.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR