akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 1 | #include <string> |
| 2 | #include <iostream> |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 3 | #include <fstream> |
| 4 | #include <pwd.h> |
| 5 | #include <cstdlib> |
| 6 | #include <unistd.h> |
| 7 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 8 | #include "nlsr_sm.hpp" |
| 9 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 10 | namespace nlsr |
| 11 | { |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 12 | |
akmhoque | 1fd8c1e | 2014-02-19 19:41:49 -0600 | [diff] [blame] | 13 | using namespace std; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 14 | |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 15 | void |
| 16 | SequencingManager::splittSequenceNo(uint64_t seqNo) |
| 17 | { |
| 18 | combinedSeqNo=seqNo; |
| 19 | adjLsaSeq = (combinedSeqNo & 0xFFFFF); |
| 20 | corLsaSeq = ((combinedSeqNo >> 20) & 0xFFFFF); |
| 21 | nameLsaSeq = ((combinedSeqNo >> 40) & 0xFFFFF); |
| 22 | } |
| 23 | |
| 24 | void |
| 25 | SequencingManager::combineSequenceNo() |
| 26 | { |
| 27 | combinedSeqNo=0; |
| 28 | combinedSeqNo = combinedSeqNo | adjLsaSeq; |
| 29 | combinedSeqNo = combinedSeqNo | (corLsaSeq<<20); |
| 30 | combinedSeqNo = combinedSeqNo | (nameLsaSeq<<40); |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | SequencingManager::writeSeqNoToFile() |
| 35 | { |
| 36 | std::ofstream outputFile(seqFileNameWithPath.c_str(),ios::binary); |
| 37 | outputFile<<combinedSeqNo; |
| 38 | outputFile.close(); |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | SequencingManager::initiateSeqNoFromFile() |
| 43 | { |
| 44 | cout<<"Seq File Name: "<< seqFileNameWithPath<<endl; |
| 45 | std::ifstream inputFile(seqFileNameWithPath.c_str(),ios::binary); |
| 46 | if ( inputFile.good() ) |
| 47 | { |
| 48 | inputFile>>combinedSeqNo; |
| 49 | splittSequenceNo(combinedSeqNo); |
| 50 | adjLsaSeq+=10; |
| 51 | corLsaSeq+=10; |
| 52 | nameLsaSeq+=10; |
| 53 | combineSequenceNo(); |
| 54 | inputFile.close(); |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | splittSequenceNo(0); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | SequencingManager::setSeqFileName(string filePath) |
| 64 | { |
| 65 | seqFileNameWithPath=filePath; |
| 66 | if( seqFileNameWithPath.empty() ) |
| 67 | { |
| 68 | seqFileNameWithPath=getUserHomeDirectory(); |
| 69 | } |
| 70 | seqFileNameWithPath=seqFileNameWithPath+"/nlsrSeqNo.txt"; |
| 71 | } |
| 72 | |
| 73 | string |
| 74 | SequencingManager::getUserHomeDirectory() |
| 75 | { |
| 76 | string homeDirPath(getpwuid(getuid())->pw_dir); |
| 77 | if( homeDirPath.empty() ) |
| 78 | { |
| 79 | homeDirPath = getenv("HOME"); |
| 80 | } |
| 81 | return homeDirPath; |
| 82 | } |
| 83 | |
| 84 | ostream& |
| 85 | operator <<(ostream& os, const SequencingManager& sm) |
| 86 | { |
| 87 | std::cout<<"----SequencingManager----"<<std::endl; |
| 88 | std::cout<<"Adj LSA seq no: "<<sm.getAdjLsaSeq()<<endl; |
| 89 | std::cout<<"Cor LSA Seq no: "<<sm.getCorLsaSeq()<<endl; |
| 90 | std::cout<<"Name LSA Seq no: "<<sm.getNameLsaSeq()<<endl; |
| 91 | std::cout<<"Combined LSDB Seq no: "<<sm.getCombinedSeqNo()<<endl; |
| 92 | return os; |
| 93 | } |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 94 | |
akmhoque | b1710aa | 2014-02-19 17:13:36 -0600 | [diff] [blame] | 95 | }//namespace nlsr |
| 96 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 97 | |