test_objmgr_data.cpp

来自「ncbi源码」· C++ 代码 · 共 506 行 · 第 1/2 页

CPP
506
字号
        to = m_gi_from;    }    int delta = (to > from) ? 1 : -1;    int pause = m_pause;    CPrefetchToken token;    if (m_prefetch) {        LOG_POST("Using prefetch");        // Initialize prefetch token;        CPrefetchToken::TIds ids;        for ( int i = from, end = to+delta; i != min(from+10, end); i += delta ) {            ids.push_back(CSeq_id_Handle::GetGiHandle(i));        }        token = CPrefetchToken(scope, ids);    }    bool ok = true;    const int kMaxErrorCount = 3;    int error_count = 0;    for ( int i = from, end = to+delta; i != end; i += delta ) {        if ( i != from && pause ) {            SleepSec(pause);        }        try {// load sequence            CSeq_id sid;            sid.SetGi(i);            CBioseq_Handle handle;            if (m_prefetch) {                if (!token) {                    LOG_POST("T" << idx << ": gi = " << i                             << ": INVALID PREFETCH TOKEN");                    continue;                }                handle = token.NextBioseqHandle(scope);                if ( !token ) {                    // Start next token                    CPrefetchToken::TIds ids;                    for ( int idx = i+1, end = to+delta; idx != min(i+10, end); idx += delta ) {                        ids.push_back(CSeq_id_Handle::GetGiHandle(idx));                    }                    token = CPrefetchToken(scope, ids);                }            }            else {                handle = scope.GetBioseqHandle(sid);            }            if (!handle) {                LOG_POST("T" << idx << ": gi = " << i << ": INVALID HANDLE");                continue;            }            int count = 0, count_prev;// check CSeqMap_CI            {{                /*                CSeqMap_CI it =                    handle.GetSeqMap().BeginResolved(&scope,                                                     kMax_Int,                                                     CSeqMap::fFindRef);                */                CSeqMap_CI it(ConstRef(&handle.GetSeqMap()),                              &scope,                              0,                              kMax_Int,                              CSeqMap::fFindRef);                while ( it ) {                    _ASSERT(it.GetType() == CSeqMap::eSeqRef);                    ++it;                }            }}// check seqvector            if ( 0 ) {{                string buff;                CSeqVector sv =                    handle.GetSeqVector(CBioseq_Handle::eCoding_Iupac,                                         CBioseq_Handle::eStrand_Plus);                int start = max(0, int(sv.size()-600000));                int stop  = sv.size();                sv.GetSeqData(start, stop, buff);                //cout << "POS: " << buff << endl;                sv = handle.GetSeqVector(CBioseq_Handle::eCoding_Iupac,                                          CBioseq_Handle::eStrand_Minus);                sv.GetSeqData(sv.size()-stop, sv.size()-start, buff);                //cout << "NEG: " << buff << endl;            }}// enumerate descriptions            // Seqdesc iterator            for (CSeqdesc_CI desc_it(handle); desc_it;  ++desc_it) {                count++;            }// verify result            {                CFastMutexGuard guard(s_GlobalLock);                if (m_mapGiToDesc.find(i) != m_mapGiToDesc.end()) {                    count_prev = m_mapGiToDesc[i];                    _ASSERT( m_mapGiToDesc[i] == count);                } else {                    m_mapGiToDesc[i] = count;                }            }// enumerate features            CSeq_loc loc;            loc.SetWhole(sid);            count = 0;            if ( idx%2 == 0 ) {                for (CFeat_CI feat_it(scope, loc,                                      CSeqFeatData::e_not_set,                                      SAnnotSelector::eOverlap_Intervals,                                      SAnnotSelector::eResolve_All);                     feat_it;  ++feat_it) {                    count++;                }// verify result                {                    CFastMutexGuard guard(s_GlobalLock);                    if (m_mapGiToFeat0.find(i) != m_mapGiToFeat0.end()) {                        count_prev = m_mapGiToFeat0[i];                        _ASSERT( m_mapGiToFeat0[i] == count);                    } else {                        m_mapGiToFeat0[i] = count;                    }                }            }            else {                for (CFeat_CI feat_it(handle, 0, 0, CSeqFeatData::e_not_set);                     feat_it;  ++feat_it) {                    count++;                }// verify result                {                    CFastMutexGuard guard(s_GlobalLock);                    if (m_mapGiToFeat1.find(i) != m_mapGiToFeat1.end()) {                        count_prev = m_mapGiToFeat1[i];                        _ASSERT( m_mapGiToFeat1[i] == count);                    } else {                        m_mapGiToFeat1[i] = count;                    }                }            }        }        catch (CLoaderException& e) {            LOG_POST("T" << idx << ": gi = " << i                 << ": EXCEPTION = " << e.what());            ok = false;            if ( e.GetErrCode() == CLoaderException::eNoConnection ) {                break;            }            if ( ++error_count > kMaxErrorCount ) {                break;            }        }        catch (exception& e) {            LOG_POST("T" << idx << ": gi = " << i                      << ": EXCEPTION = " << e.what());            ok = false;            if ( ++error_count > kMaxErrorCount ) {                break;            }        }        scope.ResetHistory();    }    if ( ok ) {        NcbiCout << " Passed" << NcbiEndl << NcbiEndl;    }    else {        NcbiCout << " Failed" << NcbiEndl << NcbiEndl;    }    return ok;}bool CTestOM::TestApp_Args( CArgDescriptions& args){    args.AddDefaultKey        ("fromgi", "FromGi",         "Process sequences in the interval FROM this Gi",         CArgDescriptions::eInteger, NStr::IntToString(g_gi_from));    args.AddDefaultKey        ("togi", "ToGi",         "Process sequences in the interval TO this Gi",         CArgDescriptions::eInteger, NStr::IntToString(g_gi_to));    args.AddDefaultKey        ("pause", "Pause",         "Pause between requests in seconds",         CArgDescriptions::eInteger, "0");    args.AddFlag("prefetch", "Use prefetching");    return true;}bool CTestOM::TestApp_Init(void){    CORE_SetLOCK(MT_LOCK_cxx2c());    CORE_SetLOG(LOG_cxx2c());    const CArgs& args = GetArgs();    m_gi_from  = args["fromgi"].AsInteger();    m_gi_to    = args["togi"].AsInteger();    m_pause    = args["pause"].AsInteger();    m_prefetch = args["prefetch"];    NcbiCout << "Testing ObjectManager ("        << "gi from "        << m_gi_from << " to " << m_gi_to << ")..." << NcbiEndl;    m_ObjMgr = new CObjectManager;    m_ObjMgr->RegisterDataLoader(*new CGBDataLoader("ID"),CObjectManager::eDefault);    // Scope shared by all threads/*    m_Scope = new CScope(*m_ObjMgr);    m_Scope->AddDefaults();*/    return true;}bool CTestOM::TestApp_Exit(void){/*    map<int, int>::iterator it;    for (it = m_mapGiToDesc.begin(); it != m_mapGiToDesc.end(); ++it) {        LOG_POST(            "gi = "         << it->first            << ": desc = "  << it->second            << ", feat0 = " << m_mapGiToFeat0[it->first]            << ", feat1 = " << m_mapGiToFeat1[it->first]            );    }*/    return true;}END_NCBI_SCOPE///////////////////////////////////////////////////////////////////////////////  MAINUSING_NCBI_SCOPE;int main(int argc, const char* argv[]){    return CTestOM().AppMain(argc, argv, 0, eDS_Default, 0);}

⌨️ 快捷键说明

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