blob: 9a5ec895befcc11d450fcb18cba004f9c4dcc42f [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#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
10namespace nlsr {
11
12using namespace std;
13
14void
15SequencingManager::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
23void
24SequencingManager::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
32void
33SequencingManager::writeSeqNoToFile()
34{
35 std::ofstream outputFile(m_seqFileNameWithPath.c_str(), ios::binary);
36 outputFile << m_combinedSeqNo;
37 outputFile.close();
38}
39
40void
41SequencingManager::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
61void
62SequencingManager::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
72string
73SequencingManager::getUserHomeDirectory()
74{
75 string homeDirPath(getpwuid(getuid())->pw_dir);
76 if (homeDirPath.empty())
77 {
78 homeDirPath = getenv("HOME");
79 }
80 return homeDirPath;
81}
82
83ostream&
84operator<<(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