Пример #1
0
			void openNewFile()
			{
				if ( fileptr < idda.data.size() && blockptr < idda.data[fileptr].numentries )
				{
					/* open file */
					istr = UNIQUE_PTR_MOVE(
						::libmaus::aio::CheckedInputStream::unique_ptr_type(
							new ::libmaus::aio::CheckedInputStream(idda.data[fileptr].filename)
						)
					);

					/* seek to block */
					uint64_t const pos = idda.data[fileptr].getPos(blockptr);
					
					istr->seekg ( pos , std::ios::beg );
					
					if ( static_cast<int64_t>(istr->tellg()) != static_cast<int64_t>(pos) )
					{
						::libmaus::exception::LibMausException ex;
						ex.getStream() << "Failed to seek to position " << pos << " in file " << idda.data[fileptr].filename << std::endl;
						ex.finish();
						throw ex;
					}
					
					SGI = UNIQUE_PTR_MOVE(
						::libmaus::aio::SynchronousGenericInput<uint64_t>::unique_ptr_type(
							new ::libmaus::aio::SynchronousGenericInput<uint64_t>(
								*istr,64*1024,
								::std::numeric_limits<uint64_t>::max(),
								false /* do not check for multiples of entity size */
							)
						)
					);
					
					GD = UNIQUE_PTR_MOVE(
						::libmaus::gamma::GammaDecoder< ::libmaus::aio::SynchronousGenericInput<uint64_t> >::unique_ptr_type(
							new ::libmaus::gamma::GammaDecoder< ::libmaus::aio::SynchronousGenericInput<uint64_t> >(*SGI)
						)
					);
				}
			}
Пример #2
0
			static ::libmaus::aio::CheckedInputStream::unique_ptr_type openFileAtPosition(std::string const & filename, uint64_t const pos)
			{
				::libmaus::aio::CheckedInputStream::unique_ptr_type istr(new ::libmaus::aio::CheckedInputStream(filename));
				istr->seekg(pos,std::ios::beg);
				return UNIQUE_PTR_MOVE(istr);
			}
			bool readBlock(SimpleCompressedInputBlockConcatBlock & block)
			{
				block.compsize = 0;
				block.uncompsize = 0;
				block.currentInterval = currentInterval;
				block.eof = false;

				// check whether we need to open the next file
				if ( (!(Pcis.get())) )
				{
					// skip over empty intervals
					while ( intervalsIt != intervals.end() && intervalsIt->empty() )
						++intervalsIt;
					
					// check whether we are done
					if ( intervalsIt == intervals.end() )
					{
						block.eof = true;
						return true;
					}
					
					// get interval	
					currentInterval = &(*(intervalsIt++));
					block.currentInterval = currentInterval;
					// open file
					libmaus::aio::CheckedInputStream::unique_ptr_type Tcis(new libmaus::aio::CheckedInputStream(currentInterval->name));
					Pcis = UNIQUE_PTR_MOVE(Tcis);
					
					// seek
					Pcis->seekg(currentInterval->start.first);
					streampos = currentInterval->start.first;
				}
				
				block.blockstreampos = streampos;
			
				libmaus::util::CountPutObject CPO;
				block.uncompsize = libmaus::util::UTF8::decodeUTF8(*Pcis);
				::libmaus::util::UTF8::encodeUTF8(block.uncompsize,CPO);
				
				block.compsize = ::libmaus::util::NumberSerialisation::deserialiseNumber(*Pcis);
				::libmaus::util::NumberSerialisation::serialiseNumber(CPO,block.compsize);
				
				block.metasize = CPO.c;
				
				if ( block.compsize > block.I.size() )
					block.I = libmaus::autoarray::AutoArray<uint8_t>(block.compsize,false);
				
				Pcis->read(reinterpret_cast<char *>(block.I.begin()),block.compsize);
				
				streampos += (block.metasize+block.compsize);
				
				bool const gcountok = Pcis->gcount() == static_cast<int64_t>(block.compsize);
				
				if ( block.blockstreampos == currentInterval->end.first )
				{
					Pcis.reset();

					// skip over empty intervals
					while ( intervalsIt != intervals.end() && intervalsIt->empty() )
						++intervalsIt;
						
					if ( intervalsIt == intervals.end() )
						block.eof = true;
				}
					
				if ( gcountok )
					return true;
				else
					return false;
			}