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