libfaster API Documentation  Development Version
Super fast distributted computing
workerCreate.cpp
1 #include <iostream>
2 #include <fstream>
3 
4 #include "fastComm.h"
5 #include "workerFdd.h"
6 #include "worker.h"
7 
8 void faster::worker::createFDD (unsigned long int id, fddType type, size_t size){
9  //std::cerr << "createFDD ";
10  workerFddBase * newFdd;
11  newFdd = new workerFdd(id, type, size);
12  fddList.insert(fddList.end(), newFdd);
13 }
14 
15 
16 void faster::worker::readFDDFile(unsigned long int id, std::string &filename, size_t size, size_t offset){
17  std::string line;
18  char c;
19 
20  //workerFdd<std::string> * newFdd = new workerFdd<std::string>(id, String);
21  workerFdd * newFdd = new workerFdd(id, String);
22 
23  if (newFdd == NULL) { std::cerr << "\nERROR: Could not find FDD!"; exit(201); }
24 
25  fddList.insert(fddList.end(), newFdd);
26 
27  // TODO Treat other kinds of input files
28  std::ifstream inFile(filename, std::ifstream::in);
29 
30  if ( ! inFile.good() ){
31  std::cerr << "\nERROR: Could not read input File " << filename << "\n";
32  exit(202);
33  }
34 
35 
36  if( offset > 0){
37  inFile.seekg(offset-1, inFile.beg);
38  c = inFile.get();
39  // If the other process doesn't have this line, get it!
40  std::getline( inFile, line );
41  if ( c == '\n' ) {
42  //std::cerr << "(" << line << ")\n";
43  newFdd->insert(0, &line, 0);
44  }
45  }
46 
47  // Start reading lines
48  while( size_t(inFile.tellg()) < (offset + size) ){
49  std::getline( inFile, line );
50 
51  //std::cerr << line << "\n";
52  //std::cerr << "[" << line << "]\n";
53 
54  newFdd->insert(0, &line, 0);
55  }
56  inFile.close();
57 
58  newFdd->shrink();
59 
60  //std::cerr << " S:FDDInfo ";
61  comm->sendFDDInfo(newFdd->getSize());
62 
63 }
64 
65