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