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); |
| 45 | if (inputFile.good()) |
| 46 | { |
| 47 | inputFile >> m_combinedSeqNo; |
| 48 | splittSequenceNo(m_combinedSeqNo); |
| 49 | m_adjLsaSeq += 10; |
| 50 | m_corLsaSeq += 10; |
| 51 | m_nameLsaSeq += 10; |
| 52 | combineSequenceNo(); |
| 53 | inputFile.close(); |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | splittSequenceNo(0); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void |
| 62 | SequencingManager::setSeqFileName(string filePath) |
| 63 | { |
| 64 | m_seqFileNameWithPath = filePath; |
| 65 | if (m_seqFileNameWithPath.empty()) |
| 66 | { |
| 67 | m_seqFileNameWithPath = getUserHomeDirectory(); |
| 68 | } |
| 69 | m_seqFileNameWithPath = m_seqFileNameWithPath + "/nlsrSeqNo.txt"; |
| 70 | } |
| 71 | |
| 72 | string |
| 73 | SequencingManager::getUserHomeDirectory() |
| 74 | { |
| 75 | string homeDirPath(getpwuid(getuid())->pw_dir); |
| 76 | if (homeDirPath.empty()) |
| 77 | { |
| 78 | homeDirPath = getenv("HOME"); |
| 79 | } |
| 80 | return homeDirPath; |
| 81 | } |
| 82 | |
| 83 | ostream& |
| 84 | operator<<(ostream& os, const SequencingManager& sm) |
| 85 | { |
| 86 | std::cout << "----SequencingManager----" << std::endl; |
| 87 | std::cout << "Adj LSA seq no: " << sm.getAdjLsaSeq() << endl; |
| 88 | std::cout << "Cor LSA Seq no: " << sm.getCorLsaSeq() << endl; |
| 89 | std::cout << "Name LSA Seq no: " << sm.getNameLsaSeq() << endl; |
| 90 | std::cout << "Combined LSDB Seq no: " << sm.getCombinedSeqNo() << endl; |
| 91 | return os; |
| 92 | } |
| 93 | |
| 94 | }//namespace nlsr |
| 95 | |
| 96 | |