166 off_t gen_offset=0, last_offset, byte_length;
167 string cmd, magic_name, old_name;
168 bool do_compress = 0;
188 if((FD = open(
_filename.c_str(),O_RDONLY)) == -1){
194 if((FD = open(alt_name.c_str(),O_RDONLY)) == -1){
198 if((FD = open(alt_name.c_str(),O_RDONLY)) == -1){
200 fatal(
"BinaryDataLoader::extractPop::open failed on %s: %s\n",
_filename.c_str(),strerror(errno));
203 cmd =
"gzip -cd " + alt_name +
" > " + magic_name;
209 cmd =
"bunzip2 -ck " + alt_name +
" > " + magic_name;
211 status = system(cmd.c_str());
213 fatal(
"BinaryDataLoader::extractPop::bunzip2 failed (status %i) on %s\n",status, alt_name.c_str());
215 if((FD = open(magic_name.c_str(),O_RDONLY)) == -1) {
217 fatal(
"BinaryDataLoader::extractPop::open failed on %s: %s\n",
_filename.c_str(), strerror(errno));
232 error(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop::could not set parameters from binary file\n");
272 message(
"\nBinaryDataLoader::extractPop::generation offset is: %li\n last offset is: %li ",gen_offset,last_offset);
277 byte_length = last_offset - gen_offset;
282 assert(byte_length > 0);
288 message(
"--> nb bytes to read are: %li\n",byte_length);
293 if(current_pos == -1)
294 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop::lseek failed on %s\n",strerror(errno));
296 off_t rout = -1, rcount = 0;
297 off_t rest = byte_length;
298 char *data =
new char [byte_length];
300 while(rest != 0 && rout != 0) {
301 if( (rout = read(FD,&data[rcount],rest)) == -1)
302 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop::read data %s (reading in %li bytes, read %li so far)\n",strerror(errno), rest, rout);
306 message(
"BinaryDataLoader::extractPop:read %i bytes from file\n",rout);
316 unsigned char separator[2];
322 if( separator[0] !=
'@' || separator[1] !=
'G')
323 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop:: wrong generation separator\n");
333 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop:: wrong generation in file\n");
339 cmd =
"rm -f " + magic_name;
340 if( system(cmd.c_str()) == 1)
341 warning(
"BinaryDataLoader::extractPop:: deleting duplicated source file failed on %s\n",
_filename.c_str());
344 if( !status )
return NULL;
off_t extractOffsetTable(int FD)
Definition: binarydataloader.cc:63
void set_buff(BinaryDataSaver *owner)
Definition: binarystoragebuffer.h:83
void BSBread(void *out, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:179
void makePrototype(map< trait_t, TraitPrototype * > TTlist)
Creates the individuals prototype from the selected trait prototypes.
Definition: indfactory.cc:50
void add_paramset(ParamSet *paramset)
Adds a ParamSet to the list of the parameter sets of the simulation.
Definition: basicsimulation.h:95
void setName(const char *name)
Definition: paramsparser.h:57
map< string, string > & getParameters(const char *stream_name)
Definition: paramsparser.cc:80
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:124
static void loadDefaultComponents(SimBuilder *sim)
Definition: simenv.cc:53
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:168
bool build_currentParams(map< string, string > &simparams)
Builds the list of parameters from user's defined input parameters.
Definition: basicsimulation.cc:720
map< trait_t, TraitPrototype * > & build_currentTraits()
Selects the trait prototypes that have their parameters set.
Definition: basicsimulation.cc:746
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:108
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:95
int error(const char *str,...)
Definition: output.cc:77
void warning(const char *str,...)
Definition: output.cc:58