static ::libmaus2::bambam::BamHeader::unique_ptr_type readSamHeader(libmaus2::util::LineBuffer & lb) { std::ostringstream istr; char const * pa = 0; char const * pe = 0; bool lineok = true; while ( (lineok = lb.getline(&pa,&pe)) ) { if ( pe-pa > 0 && pa[0] == '@' ) { istr.write(pa,pe-pa); istr.put('\n'); } else { break; } } if ( lineok ) lb.putback(pa); ::libmaus2::bambam::BamHeader::unique_ptr_type tptr(new ::libmaus2::bambam::BamHeader(istr.str())); return UNIQUE_PTR_MOVE(tptr); }
// // PPTokenTBuf::underflow // void PPTokenTBuf::underflow() { if(tptr() != tend()) return; switch((buf[0] = src.get()).tok) { case Core::TOK_Identi: if(IsKeyWrd(buf[0].str)) buf[0].tok = Core::TOK_KeyWrd; break; case Core::TOK_Number: if(IsNumInt(buf[0].str)) buf[0].tok = Core::TOK_NumInt; else if(IsNumFix(buf[0].str)) buf[0].tok = Core::TOK_NumFix; else if(IsNumFlt(buf[0].str)) buf[0].tok = Core::TOK_NumFlt; else { std::cerr << "ERROR: " << buf[0].pos << ": not valid number: '" << buf[0].str << "'\n"; throw EXIT_FAILURE; } break; default: break; } sett(buf, buf, buf + 1); }
std::ofstream & getFile(uint64_t const fileid) { if ( mapping[fileid] != lrusize ) { update(mapping[fileid]); return *(files[mapping[fileid]]); } std::pair < std::pair < uint64_t, uint64_t >, bool > P = add(); if ( ! P.second ) { uint64_t const kickedlruid = P.first.first; uint64_t const kickedfileid = rmapping[kickedlruid]; files [ kickedlruid ] -> flush (); files [ kickedlruid ] -> close (); files [ kickedlruid ] . reset ( ); mapping [ kickedfileid ] = lrusize; rmapping [ kickedlruid ] = 0; } mapping [ fileid ] = P.first.first; rmapping [ P.first.first ] = fileid; file_ptr_type tptr(new std::ofstream( filenames[fileid].c_str(), std::ios::binary | std::ios::app ) ); files [ mapping [ fileid] ] = UNIQUE_PTR_MOVE(tptr); return *(files[mapping[fileid]]); }
libmaus2::lz::BgzfDeflateOutputBufferBase::shared_ptr_type operator()() { libmaus2::lz::BgzfDeflateOutputBufferBase::shared_ptr_type tptr( new libmaus2::lz::BgzfDeflateOutputBufferBase(level) ); return tptr; }
package_type * getPackage() { libmaus::parallel::ScopePosixSpinLock llock(lock); if ( ! freelistFill ) { uint64_t const newlistsize = packages.size() ? 2*packages.size() : 1; libmaus::autoarray::AutoArray<package_ptr_type> newpackages(newlistsize); libmaus::autoarray::AutoArray<package_type *> newfreelist(newlistsize); for ( uint64_t i = 0; i < packages.size(); ++i ) { newpackages[i] = UNIQUE_PTR_MOVE(packages[i]); } for ( uint64_t i = packages.size(); i < newpackages.size(); ++i ) { package_ptr_type tptr(new package_type); newpackages[i] = UNIQUE_PTR_MOVE(tptr); newfreelist[freelistFill++] = newpackages[i].get(); } packages = newpackages; freelist = newfreelist; } return freelist[--freelistFill]; }
ReadEndsBlockDecoderBaseCollectionInfoLockedStream::unique_ptr_type getIndexStream() { ReadEndsBlockDecoderBaseCollectionInfoLockedStream::unique_ptr_type tptr( ReadEndsBlockDecoderBaseCollectionInfoLockedStream::construct(indexmutex,*indexstr) ); return UNIQUE_PTR_MOVE(tptr); }
ReadEndsBlockDecoderBaseCollectionInfoLockedStream::unique_ptr_type getDataStream() { ReadEndsBlockDecoderBaseCollectionInfoLockedStream::unique_ptr_type tptr( ReadEndsBlockDecoderBaseCollectionInfoLockedStream::construct(datamutex,*datastr) ); return UNIQUE_PTR_MOVE(tptr); }
static unique_ptr_type load(std::string const & filename) { libmaus2::aio::InputStream::unique_ptr_type PCIS( libmaus2::aio::InputStreamFactoryContainer::constructUnique(filename) ); unique_ptr_type tptr(new this_type(*PCIS)); return UNIQUE_PTR_MOVE(tptr); }
template<typename T> void dependent_edge_cases() { T a({0}); (void) T({0}); new T({0}); T *b({0}); typedef T *tptr; T *c = tptr({0}); }
static libmaus::bambam::BamCatHeader::unique_ptr_type constructHeader( std::vector<libmaus::bambam::BamAlignmentDecoderInfo> const & infos, wrapper_pointer_array_pointer_type & Pwrappers ) { if ( Pwrappers.get() ) { libmaus::autoarray::AutoArray<libmaus::bambam::BamAlignmentDecoder *> decs(Pwrappers->size()); for ( uint64_t i = 0; i < Pwrappers->size(); ++i ) decs[i] = &((*Pwrappers)[i]->getDecoder()); libmaus::bambam::BamCatHeader::unique_ptr_type tptr(new libmaus::bambam::BamCatHeader(decs)); return UNIQUE_PTR_MOVE(tptr); } else { libmaus::bambam::BamCatHeader::unique_ptr_type tptr(new libmaus::bambam::BamCatHeader(infos)); return UNIQUE_PTR_MOVE(tptr); } }
libmaus2::aio::InputStream::unique_ptr_type openStream() const { libmaus2::aio::InputStream::unique_ptr_type tptr(libmaus2::aio::InputStreamFactoryContainer::constructUnique(path)); if ( start != 0 ) { tptr->clear(); tptr->seekg(start,std::ios::beg); } return UNIQUE_PTR_MOVE(tptr); }
TempFileArray(std::string const & rprefix, uint64_t const n) : prefix(rprefix), Vfn(n), AOS(n) { for ( uint64_t i = 0; i < n; ++i ) { std::ostringstream ostr; ostr << prefix << libmaus2::util::ArgInfo::getDefaultTmpFileName(std::string()) << std::setw(6) << std::setfill('0') << i; Vfn[i] = ostr.str(); libmaus2::util::TempFileRemovalContainer::addTempFile(Vfn[i]); libmaus2::aio::OutputStreamInstance::unique_ptr_type tptr(new libmaus2::aio::OutputStreamInstance(Vfn[i])); AOS[i] = UNIQUE_PTR_MOVE(tptr); } }
BamCatHeader(std::vector<libmaus2::bambam::BamAlignmentDecoderInfo> const & V) : orderedCoordinates(true), orderedNames(true) { libmaus2::autoarray::AutoArray< libmaus2::bambam::BamAlignmentDecoderWrapper::unique_ptr_type > wraps(V.size()); libmaus2::autoarray::AutoArray< libmaus2::bambam::BamAlignmentDecoder * > decs(V.size()); for ( uint64_t i = 0; i < V.size(); ++i ) { libmaus2::bambam::BamAlignmentDecoderWrapper::unique_ptr_type tptr ( BamAlignmentDecoderFactory::construct(V[i]) ); wraps[i] = UNIQUE_PTR_MOVE(tptr); decs[i] = &(wraps[i]->getDecoder()); } init(decs.begin(),decs.size()); }
libmaus2::digest::DigestInterface::unique_ptr_type libmaus2::digest::DigestFactory_CRC32C_SSE42::constructStatic(std::string const & name) { #if defined(LIBMAUS2_USE_ASSEMBLY) && defined(LIBMAUS2_HAVE_x86_64) && defined(LIBMAUS2_HAVE_i386) && defined(LIBMAUS2_HAVE_SHA2_ASSEMBLY) if ( name == "crc32c" && libmaus2::util::I386CacheLineSize::hasSSE42() ) { libmaus2::digest::DigestInterface::unique_ptr_type tptr(new libmaus2::digest::CRC32C_sse42); return UNIQUE_PTR_MOVE(tptr); } else #endif { libmaus2::exception::LibMausException lme; lme.getStream() << "DigestFactory_CRC32C_SSE42: unsupported hash " << name << std::endl; lme.finish(); throw lme; } }
/** * input method * * @return bool if alignment input was successfull and a new alignment was stored **/ virtual bool readAlignmentInternal(bool const delayPutRank = false) { while ( true ) { if ( expect_false(! decoder) ) { if ( static_cast<uint64_t>(++fileid) == infos.size() ) { return false; } else { if ( Pwrappers.get() ) { decoder = &((*Pwrappers)[fileid]->getDecoder()); } else { libmaus::bambam::BamAlignmentDecoderWrapper::unique_ptr_type tptr ( libmaus::bambam::BamAlignmentDecoderFactory::construct(infos[fileid]) ); wrapper = UNIQUE_PTR_MOVE(tptr); decoder = &(wrapper->getDecoder()); } algnptr = &(decoder->getAlignment()); } } bool const ok = decoder->readAlignment(); if ( expect_true(ok) ) { alignment.swap(*algnptr); if ( ! delayPutRank ) putRank(); header.updateAlignment(fileid,alignment); return true; } else { wrapper.reset(); decoder = 0; algnptr = 0; } } }
static wrapper_pointer_array_pointer_type constructWrappers(std::vector<libmaus::bambam::BamAlignmentDecoderInfo> const & infos, bool const streaming) { wrapper_pointer_array_pointer_type Pwrappers; if ( streaming ) { wrapper_pointer_array_pointer_type Twrappers(new wrapper_pointer_array_type(infos.size())); Pwrappers = UNIQUE_PTR_MOVE(Twrappers); for ( uint64_t i = 0; i < infos.size(); ++i ) { wrapper_pointer_type tptr ( libmaus::bambam::BamAlignmentDecoderFactory::construct(infos[i]) ); (*Pwrappers)[i] = UNIQUE_PTR_MOVE(tptr); } } return UNIQUE_PTR_MOVE(Pwrappers); }
libmaus2::util::Histogram::unique_ptr_type getRunLengthHistogram(uint64_t const numthreads) const { uint64_t const nb = getNumBlocks(); libmaus2::util::HistogramSet HS(numthreads,256); #if defined(_OPENMP) #pragma omp parallel for num_threads(numthreads) #endif for ( int64_t b = 0; b < static_cast<int64_t>(nb); ++b ) #if defined(_OPENMP) getBlockRunLengthHistogram(b,HS[omp_get_thread_num()]); #else getBlockRunLengthHistogram(b,HS[0]); #endif libmaus2::util::Histogram::unique_ptr_type tptr(HS.merge()); return UNIQUE_PTR_MOVE(tptr); }
FragmentAlignmentBuffer::shared_ptr_type operator()() { FragmentAlignmentBuffer::shared_ptr_type tptr(new FragmentAlignmentBuffer(numbuffers,pointermult)); return tptr; }
static unique_ptr_type construct(libmaus2::parallel::PosixMutex & rmutex, std::istream & ristr) { unique_ptr_type tptr(new this_type(rmutex,ristr)); return UNIQUE_PTR_MOVE(tptr); }
static IRodsFileBase::unique_ptr_type openFile(std::string const & filename) { IRodsSystem::shared_ptr_type irodsSystem = getDefaultIRodsSystem(); IRodsFileBase::unique_ptr_type tptr(openFile(irodsSystem,filename)); return UNIQUE_PTR_MOVE(tptr); }
static IRodsCommProvider::shared_ptr_type getDefaultIRodsSystemCommProvider() { IRodsCommProvider::shared_ptr_type tptr(getDefaultIRodsSystem()); return tptr; }
static unique_ptr_type load(std::string const & s) { libmaus2::aio::InputStreamInstance ISI(s); unique_ptr_type tptr(new this_type(ISI)); return UNIQUE_PTR_MOVE(tptr); }
static unique_ptr_type load(std::istream & in) { unique_ptr_type tptr(new this_type(in)); return UNIQUE_PTR_MOVE(tptr); }
libmaus2::lz::BgzfInflateBase::shared_ptr_type operator()() { libmaus2::lz::BgzfInflateBase::shared_ptr_type tptr(new libmaus2::lz::BgzfInflateBase); return tptr; }
unique_ptr_type uclone() const { unique_ptr_type tptr(new this_type(*this)); return UNIQUE_PTR_MOVE(tptr); }
TInt CMessageQueue::SndMsg(const RMessage2& aMessage) { TInt msgSize = aMessage.GetDesLengthL(1); if ( iMq_ds.msg_cbytes + msgSize > iMq_ds.msg_qbytes ) {//if Queue is full if ( aMessage.Int2() & IPC_NOWAIT ) { aMessage.Complete(EAGAIN); return ETrue; } else { //put this request on the queue if ( iExternal ) { iWriteWaitQ.Append (aMessage); } return EFalse; } } else { iMq_ds.msg_lspid = IpcUtils::GetPid(aMessage); iMq_ds.msg_qnum++; iMq_ds.msg_stime = IpcUtils::CurrentTimeL(); iMq_ds.msg_cbytes += msgSize; //create message msg* tmsg = new msg; User::LeaveIfNull(tmsg); CleanupStack::PushL(tmsg); tmsg->msg_data = new char[msgSize]; User::LeaveIfNull(tmsg->msg_data); tmsg->msg_len = msgSize - sizeof(long int); tmsg->msg_next = NULL;//as this will be last message in the Q TPtr8 tptr((unsigned char*)tmsg->msg_data, msgSize, msgSize); aMessage.ReadL(1, tptr); CleanupStack::Pop(); tmsg->msg_type = *(long*)tmsg->msg_data; //move pointer to actual data. tmsg->msg_data = tmsg->msg_data + sizeof ( long int); aMessage.Complete(KErrNone); //add message in message link list //if message exist mean add after last one if ( iMq_ds.msg_last ) { iMq_ds.msg_last->msg_next = tmsg; iMq_ds.msg_last = tmsg; } else {//there is no message in the Q iMq_ds.msg_first = iMq_ds.msg_last = tmsg; } // try to satisfy existing request if any we can do. TInt max = iReadWaitQ.Count(); for (TInt i = 0; i < max; i++) { iExternal = EFalse; if ( RcvMsg(iReadWaitQ[i]) ) { iReadWaitQ.Remove(i); } } return ETrue; } }
SamInfo::shared_ptr_type operator()() { SamInfo::shared_ptr_type tptr(new SamInfo(*header)); return tptr; }
libmaus2::digest::DigestInterface::unique_ptr_type construct(std::string const & name) const { libmaus2::digest::DigestInterface::unique_ptr_type tptr(constructStatic(name)); return UNIQUE_PTR_MOVE(tptr); }
static unique_ptr_type load(std::string const & filename) { libmaus2::aio::InputStreamInstance CIS(filename); unique_ptr_type tptr(new this_type(CIS)); return UNIQUE_PTR_MOVE(tptr); }
TInt CMessageQueue::RcvMsg(const RMessage2& aMessage) { long msgType = 0; TPtr8 tptr((unsigned char*)&msgType, sizeof(long), sizeof(long)); aMessage.ReadL(1, tptr); TBool msgFound = EFalse; msg* tmsg = NULL; msg* tprevMsg = NULL; if ( !iMq_ds.msg_first ) { //if there is no message in the Q goto label1; } if ( !msgType ) {//return first message from Q; //there will be at least one msg as we have //checked for this in above if condition //set tmsg to first msg tmsg = iMq_ds.msg_first; msgFound = ETrue; } else if ( msgType > 0 ) {// first message of msg type tmsg = iMq_ds.msg_first; msg* prev = NULL; while (tmsg) { if ( tmsg->msg_type == msgType ) { msgFound = ETrue; tprevMsg = prev; break; } prev = tmsg; tmsg = tmsg->msg_next; } } else {//msgType is -ve //smallet message which is of type< = |msgType| msg* tmsg2 = iMq_ds.msg_first; msg* prev = NULL; // decrease it by one so that we can apply uniform // algo, to find smallest type message which is less then this no msgType--; msgType = -msgType; TInt lowestType = msgType; while (tmsg2) { if ( tmsg2->msg_type < lowestType) { tprevMsg = prev; tmsg = tmsg2; lowestType = tmsg2->msg_type; msgFound = ETrue; } prev = tmsg2; tmsg2 = tmsg2->msg_next; } } label1: if ( !msgFound ) { if ( aMessage.Int2 ()& IPC_NOWAIT) { aMessage.Complete (ENOMSG); return ETrue; } else { //put this request on the queue if ( iExternal ) { iReadWaitQ.Append (aMessage); } return EFalse; } } else { TInt msgSize = aMessage.GetDesLengthL(1); msgSize -= sizeof(long); TInt asize = tmsg->msg_len; if ( msgSize < tmsg->msg_len) { if ( aMessage.Int2() & MSG_NOERROR ) {//truncate to msgSize tmsg->msg_len = msgSize; } else { aMessage.Complete(E2BIG); return ETrue; } } //update data struct iMq_ds.msg_lrpid = IpcUtils::GetPid(aMessage); iMq_ds.msg_qnum--; iMq_ds.msg_rtime = IpcUtils::CurrentTimeL(); iMq_ds.msg_cbytes -= (asize + sizeof(long)); TPtr8 tptr( (unsigned char*)(tmsg->msg_data - sizeof(long)), tmsg->msg_len + sizeof(long), tmsg->msg_len + sizeof(long)); aMessage.WriteL (1, tptr); aMessage.Complete (KErrNone); if ( tprevMsg) { tprevMsg->msg_next = tmsg->msg_next; // if this is last msg if ( tmsg == iMq_ds.msg_last) { iMq_ds.msg_last = tprevMsg; } } else {//this is first msg iMq_ds.msg_first = iMq_ds.msg_first->msg_next; //if first is null them last must be null if ( !iMq_ds.msg_first) { iMq_ds.msg_last = NULL; } } delete tmsg; //check if something is there on write Q //complete requests as much as you can TInt max = iWriteWaitQ.Count(); //todo if sndmsg is also succesful and it calls //rcv again and that too successful then this for //loop would be called again and this can go to a forever loop //and we end up deleting a element many times for (TInt i = 0; i < max; i++) { iExternal = EFalse; if ( SndMsg(iWriteWaitQ[i]) ) { iWriteWaitQ.Remove(i); } } return ETrue; } }