blob: cae7f6050eb9992b967cdabb7cfa13ae324b593f [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001#include <string>
2#include <iostream>
akmhoque2bb198e2014-02-28 11:46:27 -06003#include <fstream>
4#include <pwd.h>
5#include <cstdlib>
6#include <unistd.h>
7
akmhoque298385a2014-02-13 14:13:09 -06008#include "nlsr_sm.hpp"
9
akmhoque1fd8c1e2014-02-19 19:41:49 -060010namespace nlsr
11{
akmhoqueb1710aa2014-02-19 17:13:36 -060012
akmhoque1fd8c1e2014-02-19 19:41:49 -060013 using namespace std;
akmhoque298385a2014-02-13 14:13:09 -060014
akmhoque2bb198e2014-02-28 11:46:27 -060015 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 }
23
24 void
25 SequencingManager::combineSequenceNo()
26 {
27 combinedSeqNo=0;
28 combinedSeqNo = combinedSeqNo | adjLsaSeq;
29 combinedSeqNo = combinedSeqNo | (corLsaSeq<<20);
30 combinedSeqNo = combinedSeqNo | (nameLsaSeq<<40);
31 }
32
33 void
34 SequencingManager::writeSeqNoToFile()
35 {
36 std::ofstream outputFile(seqFileNameWithPath.c_str(),ios::binary);
37 outputFile<<combinedSeqNo;
38 outputFile.close();
39 }
40
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() )
47 {
48 inputFile>>combinedSeqNo;
49 splittSequenceNo(combinedSeqNo);
50 adjLsaSeq+=10;
51 corLsaSeq+=10;
52 nameLsaSeq+=10;
53 combineSequenceNo();
54 inputFile.close();
55 }
56 else
57 {
58 splittSequenceNo(0);
59 }
60 }
61
62 void
63 SequencingManager::setSeqFileName(string filePath)
64 {
65 seqFileNameWithPath=filePath;
66 if( seqFileNameWithPath.empty() )
67 {
68 seqFileNameWithPath=getUserHomeDirectory();
69 }
70 seqFileNameWithPath=seqFileNameWithPath+"/nlsrSeqNo.txt";
71 }
72
73 string
74 SequencingManager::getUserHomeDirectory()
75 {
76 string homeDirPath(getpwuid(getuid())->pw_dir);
77 if( homeDirPath.empty() )
78 {
79 homeDirPath = getenv("HOME");
80 }
81 return homeDirPath;
82 }
83
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 }
akmhoque298385a2014-02-13 14:13:09 -060094
akmhoqueb1710aa2014-02-19 17:13:36 -060095}//namespace nlsr
96
akmhoque298385a2014-02-13 14:13:09 -060097