blast_rid_cache.cpp
来自「ncbi源码」· C++ 代码 · 共 189 行
CPP
189 行
/* * =========================================================================== * PRODUCTION $Log: blast_rid_cache.cpp,v $ * PRODUCTION Revision 1000.0 2004/06/01 21:26:10 gouriano * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3 * PRODUCTION * =========================================================================== *//* $Id: blast_rid_cache.cpp,v 1000.0 2004/06/01 21:26:10 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Authors: Mike DiCuccio * * File Description: * */#include <ncbi_pch.hpp>#include "blast_rid_cache.hpp"#include <corelib/ncbiapp.hpp>#include <corelib/ncbireg.hpp>#include <corelib/ncbi_process.hpp>#include <bdb/bdb_blobcache.hpp>#include <gui/utils/system_path.hpp>#include <connect/ncbi_conn_stream.hpp>#include <serial/serial.hpp>#include <serial/objostr.hpp>#include <serial/objistr.hpp>BEGIN_NCBI_SCOPEUSING_SCOPE(objects);CBlastRidCache::CBlastRidCache(){ CNcbiApplication* app = CNcbiApplication::Instance(); _ASSERT(app); const CNcbiRegistry& reg = app->GetConfig(); string cache_path = CSystemPath::ResolvePath("<home>", "cache.rid"); cache_path = reg.GetString("BLAST", "CachePath", cache_path, CNcbiRegistry::eErrPost); m_Cache.reset(new CBDB_Cache()); try { ICache::TTimeStampFlags flags = ICache::fTimeStampOnRead; m_Cache->SetTimeStampPolicy(flags, 0); m_Cache->Open(cache_path.c_str(), "blast-rid-cache", CBDB_Cache::ePidLock); } catch (CPIDGuardException& e) { switch (e.GetErrCode()) { case CPIDGuardException::eStillRunning: LOG_POST(Error << "BLAST RID Cache: Another process is accessing " "the cache, access is disabled."); break; default: LOG_POST(Error << "Error creating BLAST RID cache: " << e.GetMsg()); break; } m_Cache.reset(); } catch (CException& e) { LOG_POST(Error << "Error creating BLAST RID cache: " << e.GetMsg()); m_Cache.reset(); } catch (...) { LOG_POST(Error << "Unknown error creating BLAST RID cache"); m_Cache.reset(); }}void CBlastRidCache::AddRID(const string& rid, const CSeq_annot& annot){ if ( !m_Cache.get() ) { // caching disabled return; } CConn_MemoryStream mem_str; {{ auto_ptr<CObjectOStream> os (CObjectOStream::Open(eSerial_AsnBinary, mem_str)); *os << annot; }} size_t size = mem_str.tellp() - CT_POS_TYPE(0); string data; data.resize(size); mem_str.read(const_cast<char*>(data.data()), size); m_Cache->Store(rid, 0, "", static_cast<const void*>(data.data()), size); LOG_POST(Info << "Cached results for RID " << rid);}CSeq_annot* CBlastRidCache::GetRID(const string& rid){ if ( !m_Cache.get() ) { // caching disabled return NULL; } try { size_t size = m_Cache->GetSize(rid, 0, ""); if (size == 0) { return NULL; } string data; data.resize(size); m_Cache->Read(rid, 0, "", static_cast<void*>(const_cast<char*>(data.data())), size); CNcbiIstrstream istr(data.data(), size); auto_ptr<CObjectIStream> is (CObjectIStream::Open(eSerial_AsnBinary, istr)); CRef<CSeq_annot> annot(new CSeq_annot()); *is >> *annot; LOG_POST(Info << "Retrieved cached results for RID " << rid); return annot.Release(); } catch (CException& e) { LOG_POST(Error << "failed to retrieve RID " << rid << " from cache: " << e.GetMsg()); return NULL; } catch (...) { LOG_POST(Error << "failed to retrieve RID " << rid << " from cache: unknown error"); return NULL; }}END_NCBI_SCOPE/* * =========================================================================== * $Log: blast_rid_cache.cpp,v $ * Revision 1000.0 2004/06/01 21:26:10 gouriano * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3 * * Revision 1.3 2004/05/21 22:27:46 gorelenk * Added PCH ncbi_pch.hpp * * Revision 1.2 2004/04/23 21:37:23 ucko * Cope with strict definitions of CT_POS_TYPE. * * Revision 1.1 2004/04/22 12:22:36 dicuccio * Initial revision * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?