Exemplo n.º 1
0
			::std::streampos seekpos(::std::streampos sp, ::std::ios_base::openmode which = ::std::ios_base::in | ::std::ios_base::out)
			{
				if ( which & ::std::ios_base::in )
				{
					int64_t const cur = symsread-(egptr()-gptr());
					int64_t const curlow = cur - static_cast<int64_t>(gptr()-eback());
					int64_t const curhigh = cur + static_cast<int64_t>(egptr()-gptr());
					
					// call relative seek, if target is in range
					if ( sp >= curlow && sp <= curhigh )
						return seekoff(static_cast<int64_t>(sp) - cur, ::std::ios_base::cur, which);

					// target is out of range, we really need to seek
					uint64_t tsymsread = (sp / buffersize)*buffersize;
					
					symsread = tsymsread;
					stream.clear();
					stream.seekg( (symsread * b) / 8 );
					setg(buffer.end(),buffer.end(),buffer.end());
					underflow();
					setg(eback(),gptr() + (static_cast<int64_t>(sp)-static_cast<int64_t>(tsymsread)), egptr());
				
					return sp;
				}
				
				return -1;
			}
Exemplo n.º 2
0
			void init(bool const repos)
			{
				// set empty buffer
				setgchecked(buffer.end(), buffer.end(), buffer.end());
				// seek
				if ( repos )
					fd->lseek(symsread,SEEK_SET);
			}
Exemplo n.º 3
0
			StreamWrapperBuffer(stream_type & rstream, ::std::size_t rbuffersize, std::size_t rpushbackspace)
			: stream(rstream), 
			  buffersize(rbuffersize),
			  pushbackspace(rpushbackspace),
			  buffer(buffersize+pushbackspace,false), streamreadpos(0)
			{
				setg(buffer.end(), buffer.end(), buffer.end());	
			}
Exemplo n.º 4
0
			void init(bool const repos)
			{
				// set empty buffer
				setgchecked(buffer.end(), buffer.end(), buffer.end());
				// seek
				if ( repos )
					stream.lseek(symsread);
			}
Exemplo n.º 5
0
			SocketInputStreamBuffer(::libmaus2::network::SocketInputInterface & rstream, uint64_t const rblocksize, uint64_t const rputbackspace = 0)
			: 
			  stream(rstream),
			  blocksize(rblocksize),
			  putbackspace(rputbackspace),
			  buffer(putbackspace + blocksize,false)
			{
				// set empty buffer
				setg(buffer.end(), buffer.end(), buffer.end());
			}
Exemplo n.º 6
0
 /**
  * constructor from input stream
  *
  * @param rstream input stream
  * @param offset start offset in file
  * @param rbuffersize size of streambuf buffer
  * @param rpushbackspace size of push back buffer
  **/
 CircularReverseBufferTemplate(std::basic_istream<char_type> & rstream, uint64_t const offset, ::std::size_t rbuffersize, std::size_t rpushbackspace)
     : Pstream(),
       stream(rstream),
       buffersize(rbuffersize),
       pushbackspace(rpushbackspace),
       buffer(buffersize+pushbackspace,false), streamreadpos(0),
       infilesize(::libmaus2::util::GetFileSize::getFileSize(stream))
 {
     stream.seekg(offset);
     base_type::setg(buffer.end(), buffer.end(), buffer.end());
 }
Exemplo n.º 7
0
			MdStringComputationContext()
			: T0(256,false), T1(256,false), nm(0)
			{
				std::fill(T0.begin(),T0.end(),4);
				std::fill(T1.begin(),T1.end(),5);
				T0['A'] = T0['a'] =  T1['A'] = T1['a'] = 0;
				T0['C'] = T0['c'] =  T1['C'] = T1['c'] = 1;
				T0['G'] = T0['g'] =  T1['G'] = T1['g'] = 2;
				T0['T'] = T0['t'] =  T1['T'] = T1['t'] = 3;
				auxvec.set("MD");
				auxvec.set("NM");
			}
			MemoryInputOutputStreamBuffer(std::string const & fn, std::ios_base::openmode const cxxmode, int64_t const rbuffersize)
			: 
			  fd(doOpen(fn,cxxmode)), 
			  buffersize(rbuffersize < 0 ? getDefaultBlockSize() : rbuffersize), 
			  buffer(buffersize,false),
			  readpos(0),
			  writepos(0)
			{
				// empty get buffer
				setg(buffer.end(),buffer.end(),buffer.end());
				// empty put buffer
				setp(buffer.begin(),buffer.end()-1);
			}
Exemplo n.º 9
0
			static libmaus2::autoarray::AutoArray<char> loadFile(std::istream & in)
			{
				libmaus2::autoarray::AutoArray<char> C(1);
				uint64_t p = 0;
				
				while ( in )
				{
					in.read(C.begin() + p, C.size()-p);
					
					if ( ! in.gcount() )
						break;

					p += in.gcount();
					
					if ( p == C.size() )
					{
						libmaus2::autoarray::AutoArray<char> Cn(2*C.size(),false);
						std::copy(C.begin(),C.end(),Cn.begin());
						C = Cn;
					}
				}
				
				libmaus2::autoarray::AutoArray<char> Cn(p,false);
				std::copy(C.begin(),C.begin()+p,Cn.begin());
				
				return Cn;
			}
			ExternalMemoryIndexGenerator(std::string const & filename)
			: Pstream(libmaus2::aio::InputOutputStreamFactoryContainer::constructUnique(filename,std::ios::in|std::ios::out|std::ios::trunc|std::ios::binary)), stream(*Pstream), 
			  ic(0), flushed(false), writeCache(1024),
			  wa(writeCache.begin()), wc(wa), we(writeCache.end())
			{
			
			}
Exemplo n.º 11
0
			int_type underflow()
			{
				if ( gptr() < egptr() )
					return static_cast<int_type>(*uptr());
					
				assert ( gptr() == egptr() );
					
				char * midptr = buffer.begin() + pushbackspace;
				uint64_t const copyavail = 
					std::min(
						// previously read
						static_cast<uint64_t>(gptr()-eback()),
						// space we have to copy into
						static_cast<uint64_t>(midptr-buffer.begin())
					);
				::std::memmove(midptr-copyavail,gptr()-copyavail,copyavail);

				stream.read(midptr, buffer.end()-midptr);
				size_t const n = stream.gcount();
				streamreadpos += n;

				setg(midptr-copyavail, midptr, midptr+n);

				if (!n)
					return traits_type::eof();
				
				return static_cast<int_type>(*uptr());
			}
Exemplo n.º 12
0
 /**
  * constructor from filename
  *
  * @param filename name of file to be read
  * @param offset start offset in file
  * @param rbuffersize size of streambuf buffer
  * @param rpushbackspace size of push back buffer
  **/
 CircularReverseBufferTemplate(
     std::string const & filename,
     uint64_t const offset,
     ::std::size_t rbuffersize,
     std::size_t rpushbackspace
 )
     : Pstream(new stream_type(filename)),
       stream(*Pstream),
       buffersize(rbuffersize),
       pushbackspace(rpushbackspace),
       buffer(buffersize+pushbackspace,false), streamreadpos(0),
       infilesize(::libmaus2::util::GetFileSize::getFileSize(stream))
 {
     stream.seekg(offset);
     base_type::setg(buffer.end(), buffer.end(), buffer.end());
 }
			LinuxStreamingPosixFdOutputStreamBuffer(std::string const & fn, int64_t const rbuffersize)
			: fd(doOpen(fn)), closefd(true), 
			  optblocksize((rbuffersize < 0) ? getOptimalIOBlockSize(fd,std::string()) : rbuffersize),
			  buffersize(optblocksize),
			  buffer(buffersize,false), prevwrite(0,0)
			{
				setp(buffer.begin(),buffer.end()-1);
			}
Exemplo n.º 14
0
			MemoryOutputStreamBuffer(std::string const & fn, int64_t const rbuffersize)
			: 
			  fd(doOpen(fn)), 
			  buffersize((rbuffersize < 0) ? getDefaultBlockSize() : rbuffersize), 
			  buffer(buffersize,false)
			{
				setp(buffer.begin(),buffer.end()-1);
			}
Exemplo n.º 15
0
			BgzfParallelRecodeDeflateBase()
			: B(getBgzfMaxBlockSize(),false), 
			  pa(B.begin()), 
			  pc(B.begin()), 
			  pe(B.end())
			{
			
			}
Exemplo n.º 16
0
                        void exec()
                        {
                                pid = fork();
                                
                                if ( pid < 0 )
                                {
                                        ::libmaus2::exception::LibMausException ex;
                                        ex.getStream() << "failed to fork: " << strerror(errno);
                                        ex.finish();
                                        throw ex;
                                }
                                
                                if ( ! pid )
                                {
                                	signal(SIGCHLD,sigchildhandler);
                                
                                        while ( true )
                                        {        
                                                try
                                                {
	                                                ::libmaus2::network::SocketBase::unique_ptr_type recsock = seso->accept();
	                                                
                                                        pid_t childpid = fork();
                                                        
                                                        if ( childpid == 0 )
                                                        {
                                                        	try
                                                        	{
                                                        		char const * ptr = data.begin();
                                                        		char const * ptre = data.end();
                                                        		uint64_t const bs = 4096;
                                                        		
                                                        		while ( ptr != ptre )
                                                        		{
                                                        			uint64_t const rest = ptre-ptr;
                                                        			uint64_t const towrite = std::min(bs,rest); 
                                                        			recsock->write(ptr,towrite);
                                                        			ptr += towrite;
                                                        		}
								}
								catch(std::exception const & ex)
								{
									std::cerr << ex.what() << std::endl;
								}

                                                                _exit(0);
                                                        }
                                                }
                                                catch(std::exception const & ex)
                                                {
                                                        std::cerr << "Error in SingleFileServer: " << ex.what() << std::endl;
                                                }
                                        }
                                
                                        _exit(0);
                                }
                        }
Exemplo n.º 17
0
			GammaRLEncoder(std::string const & filename, unsigned int const ralbits, uint64_t const n, uint64_t const rblocksize, uint64_t const rbufsize = 64*1024)
			: 
			  blocksize(rblocksize),
			  COS(filename), SGO(COS,rbufsize), GE(SGO), 
			  A(blocksize), pa(A.begin()), pc(pa), pe(A.end()), 
			  cursym(0), curcnt(0), indexwritten(false), albits(ralbits)
			{
				SGO.put(n);
				SGO.put(albits);
			}
Exemplo n.º 18
0
			SymBitEncoderBaseTemplate(bit_writer_type & rwriter, uint64_t const bufsize = 64*1024ull)
			: writer(rwriter),
			  symcntruns(bufsize),
			  ra(symcntruns.begin()),
			  rc(symcntruns.begin()),
			  re(symcntruns.end()),
			  currun(std::numeric_limits<int64_t>::min(),false,0),
			  indexwritten(false)
			{
			}
Exemplo n.º 19
0
			PacDecoderBuffer(
				std::string const & filename, 
				::std::size_t rbuffersize,
				bool const raddterm = false
			)
			: stream(filename),
			  b(2),
			  n(getNumberOfSymbols(stream)),
			  // smallest multiple aligning to bitsperentity bits
			  alignmult(1ull << (loglog-::libmaus2::bitio::Ctz::ctz(b))),
			  // make buffersize multiple of alignmult
			  buffersize(((rbuffersize + alignmult-1)/alignmult)*alignmult),
			  C((buffersize*b+7)/8),
			  buffer(buffersize,false),
			  symsread(0),
			  addterm(raddterm)
			{
				setg(buffer.end(), buffer.end(), buffer.end());	
			}
Exemplo n.º 20
0
			GraphEdgeBlockBuffer(std::string const & filename, uint64_t const bufsize)
			: 
				COS(filename),
				B(bufsize,false),
				pa(B.begin()),
				pc(pa),
				pe(B.end())
			{
			
			}
			/**
			 * seek to absolute position
			 **/
			::std::streampos seekpos(::std::streampos sp, ::std::ios_base::openmode /* which */)
			{			
				// flush write buffer before seeking anywhere
				checkWriteBuffer();
				// seek
				off_t const off = doSeek(sp,SEEK_SET);
				
				if ( off == static_cast<off_t>(-1) )
					return -1;
				
				// empty get buffer
				setg(buffer.end(),buffer.end(),buffer.end());
				// empty put buffer
				setp(buffer.begin(),buffer.end()-1);
				// set positions
				readpos = off;
				writepos = off;
				
				return off;
			}
Exemplo n.º 22
0
			int_type underflow()
			{
				if ( gptr() < egptr() )
					return static_cast<int_type>(*uptr());
					
				assert ( gptr() == egptr() );
				
				char * midptr = buffer.begin() + pushbackspace;
				uint64_t const copyavail = 
					std::min(
						// previously read
						static_cast<uint64_t>(gptr()-eback()),
						// space we have to copy into
						static_cast<uint64_t>(midptr-buffer.begin())
					);
				::std::memmove(midptr-copyavail,gptr()-copyavail,copyavail);
				
				size_t n = 0;
				bool done = false;
				
				while ( ! done )
				{
					BgzfInflateInfo const info = stream.readAndInfo(midptr, buffer.end()-midptr);						
					n = info.uncompressed;
					
					// non eof block
					if ( n )
					{
						streamreadpos += n;
						done = true;			
					}
					else
					{
						// eof block at end of stream
						if ( info.streameof )
						{
							done = true;
						}
						// intermediate empty block, skip it
						else
						{
						
						}
					}
				}

				setg(midptr-copyavail, midptr, midptr+n);

				if (!n)
					return traits_type::eof();
									
				return static_cast<int_type>(*uptr());
			}
Exemplo n.º 23
0
    FastATwoBitTable()
        : T(static_cast<size_t>(std::numeric_limits<unsigned char>::max())+1,false)
    {
        assert ( 3 < T.size() );

        std::fill(T.begin(),T.end(),0);

        T['a'] = T['A'] = 0;
        T['c'] = T['C'] = 1;
        T['g'] = T['G'] = 2;
        T['t'] = T['T'] = 3;
    }
Exemplo n.º 24
0
			GammaPDDecoder(std::string const & rfn, uint64_t const blocksize = 4096)
			: fn(rfn), POSI(new libmaus2::aio::OutputStreamInstance(fn)),
			  PSGO(new libmaus2::aio::SynchronousGenericOutput<uint64_t>(*POSI,4096)),
			  metafn(fn + ".meta"),
			  PMETA(new libmaus2::aio::OutputStreamInstance(metafn)),
			  B(blocksize,false),
			  pa(B.begin()),
			  pc(B.begin()),
			  pe(B.end()),
			  headerlength(sizeof(uint64_t)),
			  valueswritten(0),
			  flushed(false)
			{
			}
Exemplo n.º 25
0
    /**
     * buffer underflow callback
     * @return next symbol
     **/
    typename base_type::int_type underflow()
    {
        if ( base_type::gptr() < base_type::egptr() )
            return static_cast<typename base_type::int_type>(*uptr());

        assert ( base_type::gptr() == base_type::egptr() );

        char_type * midptr = buffer.begin() + pushbackspace;
        uint64_t const copyavail =
            std::min(
                // previously read
                static_cast<uint64_t>(base_type::gptr()-base_type::eback()),
                // space we have to copy into
                static_cast<uint64_t>(midptr-buffer.begin())
            );
        ::std::memmove(midptr-copyavail,base_type::gptr()-copyavail,copyavail*sizeof(char_type));

        if ( static_cast<int64_t>(stream.tellg()) == static_cast<int64_t>(0) )
        {
            stream.seekg(infilesize);
            stream.clear();
        }

        uint64_t const rspace = stream.tellg();
        uint64_t const toread = std::min(rspace,static_cast<uint64_t>(buffer.end()-midptr));

        stream.seekg(-static_cast<int64_t>(toread),std::ios::cur);
        stream.clear();

        stream.read(midptr, toread);
        size_t const n = stream.gcount();
        assert ( n == toread );
        std::reverse(midptr,midptr+n);
        streamreadpos += n;

        stream.seekg(-static_cast<int64_t>(toread),std::ios::cur);
        stream.clear();

        base_type::setg(midptr-copyavail, midptr, midptr+n);

        if (!n)
            return base_type::traits_type::eof();

        return static_cast<typename base_type::int_type>(*uptr());
    }
Exemplo n.º 26
0
			void resize(uint64_t const tracelen)
			{
				trace = ::libmaus2::autoarray::AutoArray<step_type>(tracelen,false);
				te = trace.end();
				ta = te;
			}
Exemplo n.º 27
0
			Buffer(uint64_t const bufsize = 8*1024)
			: A(bufsize,false), pa(A.begin()), pc(pa), pe(A.end())
			{

			}
Exemplo n.º 28
0
			AlignmentTraceContainer(uint64_t const tracelen = 0)
			: trace(tracelen), te(trace.end()), ta(te)
			{
			
			}
Exemplo n.º 29
0
			BgzfOutputStreamBuffer(std::ostream & out, int const level = Z_DEFAULT_COMPRESSION)
			: BgzfDeflateWrapper<std::ostream>(out,level,true), buffer(BgzfConstants::getBgzfMaxBlockSize(),false) 
			{
				setp(buffer.begin(),buffer.end());
			}
			ExternalMemoryIndexGenerator(std::iostream & rstream)
			: Pstream(), stream(rstream), ic(0), flushed(false), writeCache(1024),
			  wa(writeCache.begin()), wc(wa), we(writeCache.end())
			{
			
			}