164 off_t gen_offset=0, last_offset, byte_length;
165 string cmd, magic_name, old_name;
166 bool do_compress = 0;
185 if((FD = open(
_filename.c_str(),O_RDONLY)) == -1){
187 int open_errno = errno;
191 if((FD = open(alt_name.c_str(),O_RDONLY)) == -1){
195 if((FD = open(alt_name.c_str(),O_RDONLY)) == -1){
198 fatal(
"BinaryDataLoader::extractPop::open failed on %s: %s\n",
_filename.c_str(),strerror(open_errno));
202 cmd =
"gzip -cd " + alt_name +
" > " + magic_name;
210 cmd =
"bunzip2 -ck " + alt_name +
" > " + magic_name;
212 status = system(cmd.c_str());
214 fatal(
"BinaryDataLoader::extractPop::bunzip2 failed (status %i) on %s\n",status, alt_name.c_str());
217 if((FD = open(magic_name.c_str(),O_RDONLY)) == -1) {
220 fatal(
"BinaryDataLoader::extractPop::open failed on %s: %s\n",
_filename.c_str(), strerror(errno));
236 error(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop::could not set parameters from binary file\n");
259 message(
"\nBinaryDataLoader::extractPop::generation offset is: %li\n last offset is: %li ",gen_offset,last_offset);
262 byte_length = last_offset - gen_offset;
264 assert(byte_length > 0);
270 message(
"--> nb bytes to read are: %li\n",byte_length);
275 if(current_pos == -1)
276 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop::lseek failed on %s\n",strerror(errno));
278 off_t rout = -1, rcount = 0;
279 off_t rest = byte_length;
284 while(rest != 0 && rout != 0) {
285 if( (rout = read(FD,&data[rcount],rest)) == -1)
286 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop::read data %s (reading in %li bytes, read %li so far)\n",strerror(errno), rest, rout);
290 message(
"BinaryDataLoader::extractPop:read %i bytes from file\n",rout);
302 unsigned char separator[2];
308 if( separator[0] !=
'@' || separator[1] !=
'G')
309 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop:: wrong generation separator\n");
319 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop:: wrong generation in file\n");
327 cmd =
"rm -f " + magic_name;
328 if( system(cmd.c_str()) == 1)
329 warning(
"BinaryDataLoader::extractPop:: deleting duplicated source file failed on %s\n",
_filename.c_str());
338 if( !status )
return NULL;
off_t extractOffsetTable(int FD)
Definition: binarydataloader.cc:61
char * getBuffer() const
Definition: binarystoragebuffer.h:57
void set_buff(BinaryDataSaver *owner)
Definition: binarystoragebuffer.h:81
void BSBread(void *out, unsigned int nb_bytes)
Definition: binarystoragebuffer.h:236
void makePrototype(map< trait_t, TraitPrototype * > TTlist)
Creates the individuals prototype from the selected trait prototypes.
Definition: indfactory.cc:48
void add_paramset(ParamSet *paramset)
Adds a ParamSet to the list of the parameter sets of the simulation.
Definition: basicsimulation.h:93
void setName(const char *name)
Definition: paramsparser.h:60
map< string, string > & getParameters(const char *stream_name)
Definition: paramsparser.cc:83
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:125
Provides methods to build the user's selected set of life cycle events and traits from the parameters...
Definition: basicsimulation.h:166
bool build_currentParams(map< string, string > &simparams)
Builds the list of parameters from user's defined input parameters.
Definition: basicsimulation.cc:888
map< trait_t, TraitPrototype * > & build_currentTraits()
Selects the trait prototypes that have their parameters set.
Definition: basicsimulation.cc:914
virtual ParamSet * get_paramset()
ParamSet accessor.
Definition: simcomponent.h:106
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:93
int error(const char *str,...)
Definition: output.cc:77
void warning(const char *str,...)
Definition: output.cc:56