SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { groupmap = NULL; countTable = NULL; //set up groupmap for later. if (m->groupMode == "group") { groupmap = new GroupMap(m->getGroupFile()); groupmap->readMap(); }else { countTable = new CountTable(); countTable->readTable(m->getCountTableFile(), true, false); } int hold; //are we at the beginning of the file?? if (m->saveNextLabel == "") { f >> label; //is this a shared file that has headers if (label == "label") { //gets "numOtus" f >> label; m->gobble(f); //eat rest of line label = m->getline(f); m->gobble(f); //parse labels to save istringstream iStringStream(label); m->listBinLabelsInFile.clear(); while(!iStringStream.eof()){ if (m->control_pressed) { break; } string temp; iStringStream >> temp; m->gobble(iStringStream); m->listBinLabelsInFile.push_back(temp); } f >> label >> hold; }else { //read in first row f >> hold; //make binlabels because we don't have any string snumBins = toString(hold); m->listBinLabelsInFile.clear(); for (int i = 0; i < hold; i++) { //if there is a bin label use it otherwise make one string binLabel = "Otu"; string sbinNumber = toString(i+1); if (sbinNumber.length() < snumBins.length()) { int diff = snumBins.length() - sbinNumber.length(); for (int h = 0; h < diff; h++) { binLabel += "0"; } } binLabel += sbinNumber; m->listBinLabelsInFile.push_back(binLabel); } } m->saveNextLabel = label; }else {
//reads a shared file SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { m->clearAllGroups(); vector<string> allGroups; int num, inputData, count; count = 0; string holdLabel, nextLabel, groupN; individual newguy; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } lookup.clear(); //are we at the beginning of the file?? if (m->saveNextLabel == "") { f >> label; //is this a shared file that has headers if (label == "label") { //gets "group" f >> label; m->gobble(f); //gets "numOtus" f >> label; m->gobble(f); //eat rest of line label = m->getline(f); m->gobble(f); //parse labels to save istringstream iStringStream(label); m->sharedBinLabelsInFile.clear(); while(!iStringStream.eof()){ if (m->control_pressed) { break; } string temp; iStringStream >> temp; m->gobble(iStringStream); m->sharedBinLabelsInFile.push_back(temp); } f >> label >> groupN >> num; }else { //read in first row since you know there is at least 1 group. f >> groupN >> num; //make binlabels because we don't have any string snumBins = toString(num); m->sharedBinLabelsInFile.clear(); for (int i = 0; i < num; i++) { //if there is a bin label use it otherwise make one string binLabel = "Otu"; string sbinNumber = toString(i+1); if (sbinNumber.length() < snumBins.length()) { int diff = snumBins.length() - sbinNumber.length(); for (int h = 0; h < diff; h++) { binLabel += "0"; } } binLabel += sbinNumber; m->sharedBinLabelsInFile.push_back(binLabel); } } }else {
//reads a shared file SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), maxRank(0.0), numBins(0), numSeqs(0.0) { try { m->clearAllGroups(); vector<string> allGroups; int num, count; float inputData; count = 0; string holdLabel, nextLabel, groupN; individualFloat newguy; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } lookup.clear(); //are we at the beginning of the file?? if (m->saveNextLabel == "") { f >> label; //is this a shared file that has headers if (label == "label") { //gets "group" f >> label; m->gobble(f); //gets "numOtus" f >> label; m->gobble(f); //eat rest of line label = m->getline(f); m->gobble(f); //parse labels to save istringstream iStringStream(label); m->binLabelsInFile.clear(); while(!iStringStream.eof()){ if (m->control_pressed) { break; } string temp; iStringStream >> temp; m->gobble(iStringStream); m->binLabelsInFile.push_back(temp); } f >> label; } }else { label = m->saveNextLabel; }
SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { //reads in a shared file try { maxRank = 0; numBins = 0; numSeqs = 0; groupmap = new GroupMap(); int num, inputData, count; count = 0; numSeqs = 0; string holdLabel, nextLabel, groupN; individual newguy; //read in first row since you know there is at least 1 group. //are we at the beginning of the file?? if (m->saveNextLabel == "") { f >> label; //is this a shared file that has headers if (label == "label") { //gets "group" f >> label; m->gobble(f); //gets "numOtus" f >> label; m->gobble(f); //eat rest of line label = m->getline(f); m->gobble(f); //parse labels to save istringstream iStringStream(label); m->sharedBinLabelsInFile.clear(); while(!iStringStream.eof()){ if (m->control_pressed) { break; } string temp; iStringStream >> temp; m->gobble(iStringStream); m->sharedBinLabelsInFile.push_back(temp); } f >> label; } }else { label = m->saveNextLabel; }
void NoeudThor::traitementDeLaTrame(Trame &t, Client<NoeudThor> *noeudSource) { if (noeudSource == noeudSecureNodeListProvider){ switch (t.getTTL()) { case -2: { cout << "On a recu la liste d'ip:portd'écoute des autres clients" << std::endl; list<pair <string, int> > ipPortEveryBody; std::istringstream iStringStream(t.getCommande()); boost::archive::text_iarchive iTextArchive(iStringStream); iTextArchive >> ipPortEveryBody; bool found; for(pair <string, int> trucl : ipPortEveryBody){ found=false; for (auto it = toutlemonde.begin(); it != toutlemonde.end() && found!=true; it++){ if ((*it)->getIpStr() == trucl.first && (*it)->getPort() == trucl.second){ cout << "nous somme déjà connectés à ce client (" << trucl.first << ":" << trucl.second << ")" << std::endl; found = true; } } if (found == false){ cout << "On était pas connecté donc on se connecte" << std::endl; auto cli = new Client<NoeudThor>(this, io_service); tcp::endpoint endpoint(boost::asio::ip::address::from_string(trucl.first), trucl.second); cli->getSocket().connect(endpoint); cli->startRead(); toutlemonde.push_front(cli); } cout << "IT : " << trucl.first << std::endl; cout << "Port : " << trucl.second << std::endl; } cout << "Enregistrement des différents noeuds effectué" << std::endl; break; } case -3: { cout << "On a recu le nombre de Noeuds du réseau" << std::endl; int nombre; sscanf(t.getCommande().c_str(), "%d", &nombre); cout << "Il y a " << nombre << "noeuds sur le réseau." << std::endl; break; } case -4: { cout << "On a recu nos voisins" << std::endl; list<pair <string, int> > ipPortVoisins; std::istringstream iStringStream(t.getCommande()); boost::archive::text_iarchive iTextArchive(iStringStream); iTextArchive >> ipPortVoisins; bool next=false; for(pair <string, int> trucl : ipPortVoisins){ for (auto it = toutlemonde.begin(); it != toutlemonde.end(); it++){ if ((*it)->getIpStr() == trucl.first && (*it)->getPort() == trucl.second){ if (next == false){ this->previous=(*it); next = true; } else { this->next=(*it); } } } } cout << "Enregistrement des voisins effectué" << std::endl; break; } default: { break; } } } else if(noeudSource == noeudServeurCentral){
SharedListVector::SharedListVector(ifstream& f, vector<string>& userGroups, string& previousLabel, string& labelTag) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { Utils util; groups = userGroups; fillGroups = true; if (groups.size() > 0) { fillGroups = false; } CurrentFile* current = CurrentFile::getInstance(); groupMode = current->getGroupMode(); groupmap = NULL; countTable = NULL; //set up groupmap for later. if (groupMode == "group") { groupmap = new GroupMap(current->getGroupFile()); groupmap->readMap(); if (fillGroups) { groups = groupmap->getNamesOfGroups(); m->mothurOut("[ERROR]: requesting groups not present in files, aborting.\n"); fillGroups = false; } else { if (!util.isSubset(groupmap->getNamesOfGroups(), groups)) { m->mothurOut("[ERROR]: requesting groups not present in files, aborting.\n"); m->setControl_pressed(true); } } }else { countTable = new CountTable(); countTable->readTable(current->getCountFile(), true, false); if (fillGroups) { groups = countTable->getNamesOfGroups(); fillGroups = false; } else { if (!util.isSubset(countTable->getNamesOfGroups(), groups)) { m->mothurOut("[ERROR]: requesting groups not present in files, aborting.\n"); m->setControl_pressed(true); } } } int hold; //are we at the beginning of the file?? If yes, read or create headers if (previousLabel == "") { f >> label; //is this a shared file that has headers if (label == "label") { //gets "numOtus" f >> label; util.gobble(f); //eat rest of line label = util.getline(f); util.gobble(f); //parse labels to save istringstream iStringStream(label); while(!iStringStream.eof()){ if (m->getControl_pressed()) { break; } string temp; iStringStream >> temp; util.gobble(iStringStream); binLabels.push_back(temp); } if (binLabels.size() != 0) { string binLabelTag = binLabels[0]; labelTag = ""; for (int i = 0; i < binLabelTag.length(); i++) { if (isalpha(binLabelTag[i])){ labelTag += binLabelTag[i]; } } } f >> label >> hold; }else { //read in first row f >> hold; //make binlabels because we don't have any string snumBins = toString(hold); if (labelTag == "") { labelTag = "Otu"; } for (int i = 0; i < hold; i++) { //if there is a bin label use it otherwise make one string binLabel = labelTag; string sbinNumber = toString(i+1); if (sbinNumber.length() < snumBins.length()) { int diff = snumBins.length() - sbinNumber.length(); for (int h = 0; h < diff; h++) { binLabel += "0"; } } binLabel += sbinNumber; binLabels.push_back(binLabel); } } }else { f >> label >> hold; }
void NoeudThor::traitementDeLaTrame(Trame &t, Client<NoeudThor> *noeudSource) { cout << "/********* Trame Recue" << std::endl << "TTL : " << t.getTTL() << std::endl << "Commande : " << t.getCommande() << std::endl << "*********/" << std::endl; if (noeudSource == noeudSecureNodeListProvider){ switch (t.getTTL()) { case -2: { cout << "On a recu la liste d'ip:portd'écoute des autres clients" << std::endl; list<pair <string, int> > ipPortEveryBody; std::istringstream iStringStream(t.getCommande()); boost::archive::text_iarchive iTextArchive(iStringStream); iTextArchive >> ipPortEveryBody; bool found; for(pair <string, int> trucl : ipPortEveryBody){ found=false; for (auto it = toutlemonde.begin(); it != toutlemonde.end() && found!=true; it++){ if ((*it)->getIpStr() == trucl.first && (*it)->getPort() == trucl.second){ cout << "Nous somme déjà connectés à ce client (" << trucl.first << ":" << trucl.second << ")" << std::endl; found = true; } } if (found == false){ cout << "Nous ne sommes pas connectés à un client, (" << trucl.first << ":" << trucl.second << ") on s'y connecte" << std::endl; auto cli = new Client<NoeudThor>(this, io_service); tcp::endpoint endpoint(boost::asio::ip::address::from_string(trucl.first), trucl.second); cli->getSocket().connect(endpoint); cli->startRead(); Trame t; t.setTTL(-1); t.setCommande(std::to_string(this->portecoute)); cli->send(t); cli->setPort(trucl.second); toutlemonde.push_front(cli); cout << "Client ajouté à la liste : " << cli->getIpStr() << ":" << cli->getPort() << endl; cout << "Taille de la liste : " << toutlemonde.size() << endl; } } cout << "Enregistrement des différents noeuds effectué" << std::endl << std::endl; askVoisins(); break; } case -3: { cout << "On a recu le nombre de Noeuds du réseau" << std::endl; int nombre; sscanf(t.getCommande().c_str(), "%d", &nombre); cout << "Il y a " << nombre << "noeuds sur le réseau." << std::endl; break; } case -4: { cout << "On a recu nos voisins (droite et gauche)" << std::endl; list<pair <string, int> > ipPortVoisins; std::istringstream iStringStream(t.getCommande()); boost::archive::text_iarchive iTextArchive(iStringStream); iTextArchive >> ipPortVoisins; const int SET_PREVIOUS=0; const int SET_NEXT=1; const int ALL_SET=2; char whatToDo=SET_PREVIOUS; for(pair <string, int> trucl : ipPortVoisins){ for (auto it = toutlemonde.begin(); it != toutlemonde.end(); it++){ if ((*it)->getIpStr() == trucl.first && (*it)->getPort() == trucl.second){ if (whatToDo == SET_PREVIOUS){ cout << "Previous pointe maintenant vers : " << (*it)->getIpStr() << ":" << (*it)->getPort() << endl; this->previous=(*it); whatToDo = SET_NEXT; } else { cout << "Next pointe maintenant vers : " << (*it)->getIpStr() << ":" << (*it)->getPort() << endl; this->next=(*it); whatToDo = ALL_SET; } } } } if (whatToDo != ALL_SET){ this->previous=NULL; this->next=NULL; } cout << "Enregistrement des voisins effectué" << std::endl << std::endl; break; } default: { break; } } } else if(noeudSource == noeudServeurCentral){