gbloader.cpp

来自「ncbi源码」· C++ 代码 · 共 1,566 行 · 第 1/4 页

CPP
1,566
字号
/* * =========================================================================== * PRODUCTION $Log: gbloader.cpp,v $ * PRODUCTION Revision 1000.1  2004/06/01 19:41:37  gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.106 * PRODUCTION * =========================================================================== *//*  $Id: gbloader.cpp,v 1000.1 2004/06/01 19:41:37 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.** ===========================================================================**  Author: Michael Kimelman, Eugene Vasilchenko**  File Description: GenBank Data loader**/#include <ncbi_pch.hpp>#include <objtools/data_loaders/genbank/gbloader.hpp>#include <objtools/data_loaders/genbank/reader.hpp>// TODO: remove the following two includes# include <objtools/data_loaders/genbank/readers/id1/reader_id1.hpp>#if defined(HAVE_PUBSEQ_OS)# include <objtools/data_loaders/genbank/readers/pubseqos/reader_pubseq.hpp>#endif#include <objmgr/objmgr_exception.hpp>#include <objmgr/annot_selector.hpp>#include <objmgr/impl/tse_info.hpp>#include <objmgr/impl/tse_chunk_info.hpp>#include <objmgr/impl/handle_range_map.hpp>#include <objmgr/impl/data_source.hpp>#include <objmgr/impl/annot_object.hpp>#include <objects/seqloc/Seq_loc.hpp>#include <objects/seqloc/Seq_id.hpp>#include <objects/seqset/Seq_entry.hpp>#include <objects/seq/Seq_annot.hpp>#include <dbapi/driver/exception.hpp>#include <dbapi/driver/interfaces.hpp>BEGIN_NCBI_SCOPEBEGIN_SCOPE(objects)static int x_Request2SeqrefMask(CGBDataLoader::EChoice choice);//=======================================================================//   GBLoader sub classes ////=======================================================================// GBLoader Public interface // static const char* const DRV_ENV_VAR = "GENBANK_LOADER_METHOD";static const char* const DEFAULT_DRV_ORDER = "PUBSEQOS:ID1";static const char* const DRV_PUBSEQOS = "PUBSEQOS";static const char* const DRV_ID1 = "ID1";SSeqrefs::SSeqrefs(const CSeq_id_Handle& h)    : m_Handle(h){}SSeqrefs::~SSeqrefs(void){}CGBDataLoader::STSEinfo::STSEinfo()    : next(0), prev(0), locked(0), tseinfop(0), m_LoadState(eLoadStateNone){}CGBDataLoader::STSEinfo::~STSEinfo(){}#define TSE(stse) CSeqref::printTSE((stse).key)#define DUMP(stse) CSeqref::printTSE((stse).key) << \    " stse=" << &(stse) << \    " tsei=" << (stse).tseinfop << \    " tse=" << ((stse).tseinfop? (stse).tseinfop->GetSeq_entryCore().GetPointer(): 0)// Create driver specified in "env"/*CReader* s_CreateReader(string env){#if defined(HAVE_PUBSEQ_OS)    if (env == DRV_PUBSEQOS) {        try {            return new CPubseqReader;        }        catch ( exception& e ) {            GBLOG_POST("CPubseqReader is not available ::" << e.what());            return 0;        }        catch ( ... ) {            LOG_POST("CPubseqReader:: unable to init ");            return 0;        }    }#endif    if (env == DRV_ID1) {        return new CId1Reader;    }    return 0;}*/CGBDataLoader::CGBDataLoader(const string& loader_name, CReader *driver,                             int gc_threshold)  : CDataLoader(loader_name),    m_Driver(driver),    m_ReaderPluginManager(0),    m_UseListHead(0),    m_UseListTail(0){    GBLOG_POST( "CGBDataLoader");    if ( !m_Driver ) {        x_CreateDriver();// Commented out by kuznets Dec 03, 2003/*        const char* env = ::getenv(DRV_ENV_VAR);        if (!env) {            env = DEFAULT_DRV_ORDER; // default drivers' order        }        list<string> drivers;        NStr::Split(env, ":", drivers);        ITERATE ( list<string>, drv, drivers ) {            m_Driver = s_CreateReader(*drv);            if ( m_Driver )                break;        }        if(!m_Driver) {            NCBI_THROW(CLoaderException, eNoConnection,                       "Could not create driver: " + string(env));        }*/    }      size_t i = m_Driver->GetParallelLevel();    m_Locks.m_Pool.SetSize(i<=0?10:i);    m_Locks.m_SlowTraverseMode=0;      m_TseCount=0;    m_TseGC_Threshhold=gc_threshold;    m_InvokeGC=false;    //GBLOG_POST( "CGBDataLoader("<<loader_name<<"::" <<gc_threshold << ")" );}CGBDataLoader::CGBDataLoader(const string& loader_name,                             TReader_PluginManager *plugin_manager,                             EOwnership  take_plugin_manager,                             int gc_threshold)  : CDataLoader(loader_name),    m_Driver(0),    m_ReaderPluginManager(plugin_manager),    m_OwnReaderPluginManager(take_plugin_manager),    m_UseListHead(0),    m_UseListTail(0){    GBLOG_POST( "CGBDataLoader");    if (!m_ReaderPluginManager) {        x_CreateReaderPluginManager();    }    x_CreateDriver();    size_t i = m_Driver->GetParallelLevel();    m_Locks.m_Pool.SetSize(i<=0?10:i);    m_Locks.m_SlowTraverseMode=0;      m_TseCount=0;    m_TseGC_Threshhold=gc_threshold;    m_InvokeGC=false;}void CGBDataLoader::x_CreateReaderPluginManager(void){    if (m_OwnReaderPluginManager == eTakeOwnership) {        delete m_ReaderPluginManager;        m_ReaderPluginManager = 0;    }    m_ReaderPluginManager = new TReader_PluginManager;    m_OwnReaderPluginManager = eTakeOwnership;    TReader_PluginManager::FNCBI_EntryPoint ep1 = NCBI_EntryPoint_Id1Reader;    m_ReaderPluginManager->RegisterWithEntryPoint(ep1);#if defined(HAVE_PUBSEQ_OS)    TReader_PluginManager::FNCBI_EntryPoint ep2 = NCBI_EntryPoint_Reader_Pubseqos;    m_ReaderPluginManager->RegisterWithEntryPoint(ep2);#endif}void CGBDataLoader::x_CreateDriver(void){    if (!m_ReaderPluginManager) {        x_CreateReaderPluginManager();        _ASSERT(m_ReaderPluginManager);    }    const char* env = ::getenv(DRV_ENV_VAR);    if (!env) {        env = DEFAULT_DRV_ORDER; // default drivers' order    }    list<string> drivers;    NStr::Split(env, ":", drivers);    ITERATE ( list<string>, drv, drivers ) {        m_Driver = x_CreateReader(*drv);        if ( m_Driver )            break;    }    if (!m_Driver) {        NCBI_THROW(CLoaderException, eNoConnection,                   "Could not create driver: " + string(env));    }}CReader* CGBDataLoader::x_CreateReader(const string& env){    _ASSERT(m_ReaderPluginManager);#if defined(HAVE_PUBSEQ_OS)    if (env == DRV_PUBSEQOS) {        try {            return m_ReaderPluginManager->CreateInstance("pubseq_reader");        }        catch ( exception& e ) {            GBLOG_POST("CPubseqReader is not available ::" << e.what());            return 0;        }        catch ( ... ) {            LOG_POST("CPubseqReader:: unable to init ");            return 0;        }    }#endif    if (env == DRV_ID1) {        try {            return m_ReaderPluginManager->CreateInstance("id1_reader");        }        catch ( exception& e ) {            LOG_POST("CId1Reader is not available ::" << e.what());            return 0;        }        catch ( ... ) {            LOG_POST("CId1Reader:: unable to init ");            return 0;        }    }    return 0;}CGBDataLoader::~CGBDataLoader(void){    GBLOG_POST( "~CGBDataLoader");    CGBLGuard g(m_Locks,"~CGBDataLoader");    while ( m_UseListHead ) {        if ( m_UseListHead->tseinfop ) {            ERR_POST("CGBDataLoader::~CGBDataLoader: TSE not dropped: "<<                     TSE(*m_UseListHead));        }        x_DropTSEinfo(m_UseListHead);    }    m_Bs2Sr.clear();    if (m_OwnReaderPluginManager == eTakeOwnership) {        delete m_ReaderPluginManager;    }}static const char* const s_ChoiceName[] = {    "eBlob",    "eBioseq",    "eCore",    "eBioseqCore",    "eSequence",    "eFeatures",    "eGraph",    "eAlign",    "eAll",    "eAnnot",    "???"};staticconst size_t kChoiceNameCount = sizeof(s_ChoiceName)/sizeof(s_ChoiceName[0]);void CGBDataLoader::GetRecords(const CSeq_id_Handle& idh,                               const EChoice choice){    if ( choice == eAnnot && !idh.IsGi() ) {        // no external annots available on non-gi ids        return;    }    CMutexGuard guard(m_Locks.m_Lookup);    x_GetRecords(s_ChoiceName[min(size_t(choice), kChoiceNameCount-1)],                 idh, x_Request2SeqrefMask(choice));}void CGBDataLoader::GetChunk(CTSE_Chunk_Info& chunk_info){    CMutexGuard guard(m_Locks.m_Lookup);    x_GetChunk(GetTSEinfo(chunk_info.GetTSE_Info()), chunk_info);}CConstRef<CSeqref> CGBDataLoader::GetSatSatkey(const CSeq_id& id){    return GetSatSatkey(CSeq_id_Handle::GetHandle(id));}CConstRef<CSeqref> CGBDataLoader::GetSatSatkey(const CSeq_id_Handle& idh){    CConstRef<CSeqref> ret;    {{        CMutexGuard guard(m_Locks.m_Lookup);        CRef<SSeqrefs> srs = x_ResolveHandle(idh);        ITERATE ( SSeqrefs::TSeqrefs, it, srs->m_Sr ) {            const CSeqref& sr = **it;            if ( sr.GetFlags() & CSeqref::fHasCore ) {                ret = &sr;                break;            }        }    }}    return ret;}void CGBDataLoader::x_GetRecords(const char*#ifdef DEBUG_SYNC                                 type_name#endif                                 ,                                 const CSeq_id_Handle& idh,                                 TMask sr_mask){    GC();    char s[100];#ifdef DEBUG_SYNC    memset(s,0,sizeof(s));    {        strstream ss(s,sizeof(s));        ss << "GetRecords(" << type_name <<")";    }#else    s[0] = 0;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?