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 | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 13 | using namespace std; |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 14 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [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 | } |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 23 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 24 | void |
| 25 | SequencingManager::combineSequenceNo() |
| 26 | { |
| 27 | combinedSeqNo=0; |
| 28 | combinedSeqNo = combinedSeqNo | adjLsaSeq; |
| 29 | combinedSeqNo = combinedSeqNo | (corLsaSeq<<20); |
| 30 | combinedSeqNo = combinedSeqNo | (nameLsaSeq<<40); |
| 31 | } |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 32 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 33 | void |
| 34 | SequencingManager::writeSeqNoToFile() |
| 35 | { |
| 36 | std::ofstream outputFile(seqFileNameWithPath.c_str(),ios::binary); |
| 37 | outputFile<<combinedSeqNo; |
| 38 | outputFile.close(); |
| 39 | } |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 40 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 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() ) |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 47 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 48 | inputFile>>combinedSeqNo; |
| 49 | splittSequenceNo(combinedSeqNo); |
| 50 | adjLsaSeq+=10; |
| 51 | corLsaSeq+=10; |
| 52 | nameLsaSeq+=10; |
| 53 | combineSequenceNo(); |
| 54 | inputFile.close(); |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 55 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 56 | else |
| 57 | { |
| 58 | splittSequenceNo(0); |
| 59 | } |
| 60 | } |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 61 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 62 | void |
| 63 | SequencingManager::setSeqFileName(string filePath) |
| 64 | { |
| 65 | seqFileNameWithPath=filePath; |
| 66 | if( seqFileNameWithPath.empty() ) |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 67 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 68 | seqFileNameWithPath=getUserHomeDirectory(); |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 69 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 70 | seqFileNameWithPath=seqFileNameWithPath+"/nlsrSeqNo.txt"; |
| 71 | } |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 72 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 73 | string |
| 74 | SequencingManager::getUserHomeDirectory() |
| 75 | { |
| 76 | string homeDirPath(getpwuid(getuid())->pw_dir); |
| 77 | if( homeDirPath.empty() ) |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 78 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 79 | homeDirPath = getenv("HOME"); |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 80 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 81 | return homeDirPath; |
| 82 | } |
akmhoque | 2bb198e | 2014-02-28 11:46:27 -0600 | [diff] [blame] | 83 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame^] | 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 | |