Nemo  2.4.2
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 ( )
53 : LifeCycleEvent("store",""), FileHandler(".bin"), _isPeriodic(0)
54 {
57 
58  add_parameter("store_generation",INT,true,false,0,0,updater);
59  add_parameter("store_recursive",BOOL,false,false,0,0,updater);
60  add_parameter("store_dir",STR,false,false,0,0,updater);
61  add_parameter("store_nocompress",BOOL,false,false,0,0,updater);
62  add_parameter("store_noarchive",BOOL,false,false,0,0,updater);
63  add_parameter("store_compress_cmde",STR,false,false,0,0,updater);
64  add_parameter("store_compress_extension",STR,false,false,0,0,updater);
65  add_parameter("store_uncompress_cmde",STR,false,false,0,0,updater);
66  add_parameter("store_archive_cmde",STR,false,false,0,0,updater);
67  add_parameter("store_archive_extension",STR,false,false,0,0,updater);
68 }
bool _isPeriodic
Definition: binarydatasaver.h:49
virtual bool setParameters()
Definition: binarydatasaver.cc:72
FileHandler(const char *ext)
Definition: filehandler.h:105
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:96
Implementation of the ParamUpdaterBase interface.
Definition: param.h:371
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:110
@ BOOL
Definition: types.h:76
@ STR
Definition: types.h:76
@ INT
Definition: types.h:76

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

Referenced by clone().

+ Here is the caller graph for this function:

◆ ~BinaryDataSaver()

BinaryDataSaver::~BinaryDataSaver ( )
inline
73 {}

Member Function Documentation

◆ addAgeClass()

virtual age_t BinaryDataSaver::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

93 {return 0;}

◆ clone()

virtual BinaryDataSaver* BinaryDataSaver::clone ( )
inlinevirtual

Implements LifeCycleEvent.

83 {return new BinaryDataSaver();}
BinaryDataSaver()
Definition: binarydatasaver.cc:52

References BinaryDataSaver().

◆ execute()

void BinaryDataSaver::execute ( )
virtual

Implements LifeCycleEvent.

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

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.

87 {}

◆ FHwrite()

void BinaryDataSaver::FHwrite ( )
virtual

Implements FileHandler.

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

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

◆ finish()

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

+ Here is the caller graph for this function:

◆ getFileDescriptor()

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

References _fdesc.

◆ ifExist()

vector< string > BinaryDataSaver::ifExist ( )
virtual

Reimplemented from FileHandler.

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

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.

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

References FileServices::attach().

◆ loadStatServices()

virtual void BinaryDataSaver::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

90 {}

◆ printData()

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

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
289 {
290  //first, record the parameters in text mode:
291  ofstream FILE (get_filename().c_str(), ios::out);
292 
293  if(!FILE) fatal("could not open Binary output file!!\n");
294 
295  list< ParamSet* > current_params = get_service()->get_params();
296  list< ParamSet* >::iterator Pit = current_params.begin();
297 
298  FILE<<"#NEMO "<<MAIN_VERSION<<" "<<MINOR_VERSION<<" "<<REVISION<<" "<<RELEASE<<" "<<VERSION_DATE<<endl;
299 
300 #ifdef _DEBUG_
301  message("BinaryDataSaver::printHeader:storing parameters\n");
302 #endif
303  while(Pit != current_params.end()) {
304  (*Pit)->print(FILE);
305  Pit++;
306  }
307  FILE.close();
308 }
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:38
#define VERSION_DATE
Definition: version.h:28
#define MINOR_VERSION
Definition: version.h:25
#define RELEASE
Definition: version.h:27
#define MAIN_VERSION
Definition: version.h:24
#define REVISION
Definition: version.h:26

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

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.

92 {return 0;}

◆ requiredAgeClass()

virtual age_t BinaryDataSaver::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

94 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

91 {return false;}

◆ setFileDescriptor()

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

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.

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

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

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.2 by  doxygen 1.9.1

Catalogued on GSR