blob: e44c433b149d27b651278cad317f8b8ce26d0f25 [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"
akmhoque05d5fcf2014-04-15 14:58:45 -05009#include "utility/nlsr_logger.hpp"
10
11#define THIS_FILE "nlsr_sm.cpp"
akmhoque298385a2014-02-13 14:13:09 -060012
akmhoque1fd8c1e2014-02-19 19:41:49 -060013namespace nlsr
14{
akmhoqueb1710aa2014-02-19 17:13:36 -060015
akmhoque5a44dd42014-03-12 18:11:32 -050016 using namespace std;
akmhoque298385a2014-02-13 14:13:09 -060017
akmhoque5a44dd42014-03-12 18:11:32 -050018 void
19 SequencingManager::splittSequenceNo(uint64_t seqNo)
20 {
akmhoque05d5fcf2014-04-15 14:58:45 -050021 m_combinedSeqNo=seqNo;
22 m_adjLsaSeq = (m_combinedSeqNo & 0xFFFFF);
23 m_corLsaSeq = ((m_combinedSeqNo >> 20) & 0xFFFFF);
24 m_nameLsaSeq = ((m_combinedSeqNo >> 40) & 0xFFFFF);
akmhoque5a44dd42014-03-12 18:11:32 -050025 }
akmhoque2bb198e2014-02-28 11:46:27 -060026
akmhoque5a44dd42014-03-12 18:11:32 -050027 void
28 SequencingManager::combineSequenceNo()
29 {
akmhoque05d5fcf2014-04-15 14:58:45 -050030 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);
akmhoque5a44dd42014-03-12 18:11:32 -050034 }
akmhoque2bb198e2014-02-28 11:46:27 -060035
akmhoque5a44dd42014-03-12 18:11:32 -050036 void
37 SequencingManager::writeSeqNoToFile()
38 {
akmhoque05d5fcf2014-04-15 14:58:45 -050039 std::ofstream outputFile(m_seqFileNameWithPath.c_str(),ios::binary);
40 outputFile<<m_combinedSeqNo;
akmhoque5a44dd42014-03-12 18:11:32 -050041 outputFile.close();
42 }
akmhoque2bb198e2014-02-28 11:46:27 -060043
akmhoque5a44dd42014-03-12 18:11:32 -050044 void
45 SequencingManager::initiateSeqNoFromFile()
46 {
akmhoque05d5fcf2014-04-15 14:58:45 -050047 cout<<"Seq File Name: "<< m_seqFileNameWithPath<<endl;
48 std::ifstream inputFile(m_seqFileNameWithPath.c_str(),ios::binary);
akmhoque5a44dd42014-03-12 18:11:32 -050049 if ( inputFile.good() )
akmhoque2bb198e2014-02-28 11:46:27 -060050 {
akmhoque05d5fcf2014-04-15 14:58:45 -050051 inputFile>>m_combinedSeqNo;
52 splittSequenceNo(m_combinedSeqNo);
53 m_adjLsaSeq+=10;
54 m_corLsaSeq+=10;
55 m_nameLsaSeq+=10;
akmhoque5a44dd42014-03-12 18:11:32 -050056 combineSequenceNo();
57 inputFile.close();
akmhoque2bb198e2014-02-28 11:46:27 -060058 }
akmhoque5a44dd42014-03-12 18:11:32 -050059 else
60 {
61 splittSequenceNo(0);
62 }
63 }
akmhoque2bb198e2014-02-28 11:46:27 -060064
akmhoque5a44dd42014-03-12 18:11:32 -050065 void
66 SequencingManager::setSeqFileName(string filePath)
67 {
akmhoque05d5fcf2014-04-15 14:58:45 -050068 m_seqFileNameWithPath=filePath;
69 if( m_seqFileNameWithPath.empty() )
akmhoque2bb198e2014-02-28 11:46:27 -060070 {
akmhoque05d5fcf2014-04-15 14:58:45 -050071 m_seqFileNameWithPath=getUserHomeDirectory();
akmhoque2bb198e2014-02-28 11:46:27 -060072 }
akmhoque05d5fcf2014-04-15 14:58:45 -050073 m_seqFileNameWithPath=m_seqFileNameWithPath+"/nlsrSeqNo.txt";
akmhoque5a44dd42014-03-12 18:11:32 -050074 }
akmhoque2bb198e2014-02-28 11:46:27 -060075
akmhoque5a44dd42014-03-12 18:11:32 -050076 string
77 SequencingManager::getUserHomeDirectory()
78 {
79 string homeDirPath(getpwuid(getuid())->pw_dir);
80 if( homeDirPath.empty() )
akmhoque2bb198e2014-02-28 11:46:27 -060081 {
akmhoque5a44dd42014-03-12 18:11:32 -050082 homeDirPath = getenv("HOME");
akmhoque2bb198e2014-02-28 11:46:27 -060083 }
akmhoque5a44dd42014-03-12 18:11:32 -050084 return homeDirPath;
85 }
akmhoque2bb198e2014-02-28 11:46:27 -060086
akmhoque5a44dd42014-03-12 18:11:32 -050087 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 }
akmhoque298385a2014-02-13 14:13:09 -060097
akmhoqueb1710aa2014-02-19 17:13:36 -060098}//namespace nlsr
99
akmhoque298385a2014-02-13 14:13:09 -0600100