164{
165 int FD;
166 off_t gen_offset=0, last_offset, byte_length;
167 string cmd, magic_name, old_name;
168 bool do_compress = 0;
172
176
177
182
183
185
187
188 if((FD = open(
_filename.c_str(),O_RDONLY)) == -1){
189 close(FD);
190
193 int status;
194 if((FD = open(alt_name.c_str(),O_RDONLY)) == -1){
195 close(FD);
196
198 if((FD = open(alt_name.c_str(),O_RDONLY)) == -1){
199 close(FD);
200 fatal(
"BinaryDataLoader::extractPop::open failed on %s: %s\n",
_filename.c_str(),strerror(errno));
201 } else {
202
203 cmd = "gzip -cd " + alt_name + " > " + magic_name;
204
205 }
206 }
207 close(FD);
208
209 cmd = "bunzip2 -ck " + alt_name + " > " + magic_name;
210
211 status = system(cmd.c_str());
212 if(status != 0)
213 fatal(
"BinaryDataLoader::extractPop::bunzip2 failed (status %i) on %s\n",status, alt_name.c_str());
214
215 if((FD = open(magic_name.c_str(),O_RDONLY)) == -1) {
216 close(FD);
217 fatal(
"BinaryDataLoader::extractPop::open failed on %s: %s\n",
_filename.c_str(), strerror(errno));
218 }
222 do_compress = 1;
223 }
224
225
227
228
229
230
232 error(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop::could not set parameters from binary file\n");
233 return NULL;
234 }
235
236
237
238
239
241
242
244
245
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
264
265
266
267
268
269
270
271#ifdef _DEBUG_
272 message(
"\nBinaryDataLoader::extractPop::generation offset is: %li\n last offset is: %li ",gen_offset,last_offset);
273#endif
274
275
276
277 byte_length = last_offset - gen_offset;
278
279
280
281
282 assert(byte_length > 0);
283
284
285 byte_length += 2;
286
287#ifdef _DEBUG_
288 message(
"--> nb bytes to read are: %li\n",byte_length);
289#endif
290
292
293 if(current_pos == -1)
294 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop::lseek failed on %s\n",strerror(errno));
295
296 off_t rout = -1, rcount = 0;
297 off_t rest = byte_length;
298 char *data = new char [byte_length];
299
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);
303 rcount += rout;
304 rest -= rout;
305#ifdef _DEBUG_
306 message(
"BinaryDataLoader::extractPop:read %i bytes from file\n",rout);
307#endif
308 }
309
310 close(FD);
311
313
314 delete [] data;
315
316 unsigned char separator[2];
317
319
320
321
322 if( separator[0] != '@' || separator[1] != 'G')
323 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop:: wrong generation separator\n");
324
325
326
327 unsigned int dummy;
329
330
331
333 fatal(
"Binary file appears corrupted:\n >>>> BinaryDataLoader::extractPop:: wrong generation in file\n");
334
336
337
338 if(do_compress){
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());
342 }
343
344 if( !status ) return NULL;
345
347
348}
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:78
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:125
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:715
map< trait_t, TraitPrototype * > & build_currentTraits()
Selects the trait prototypes that have their parameters set.
Definition: basicsimulation.cc:741
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