NCBI C++ ToolKit
scope_info.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: scope_info.cpp 77637 2017-04-27 17:21:02Z vasilche $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors:
27 * Eugene Vasilchenko
28 *
29 * File Description:
30 * Structures used by CScope
31 *
32 */
33 
34 #include <ncbi_pch.hpp>
37 #include <objmgr/scope.hpp>
38 
39 #include <objmgr/impl/synonyms.hpp>
41 
42 #include <objmgr/impl/tse_info.hpp>
43 #include <objmgr/tse_handle.hpp>
49 #include <objmgr/bioseq_handle.hpp>
52 
53 #include <corelib/ncbi_param.hpp>
54 #include <algorithm>
55 
58 
59 #if 0
60 # define _TRACE_TSE_LOCK(x) _TRACE(x)
61 #else
62 # define _TRACE_TSE_LOCK(x) ((void)0)
63 #endif
64 
65 
66 NCBI_PARAM_DECL(bool, OBJMGR, SCOPE_AUTORELEASE);
67 NCBI_PARAM_DEF_EX(bool, OBJMGR, SCOPE_AUTORELEASE, true,
68  eParam_NoThread, OBJMGR_SCOPE_AUTORELEASE);
69 
71 {
73  return sx_Value->Get();
74 }
75 
76 
77 NCBI_PARAM_DECL(unsigned, OBJMGR, SCOPE_AUTORELEASE_SIZE);
78 NCBI_PARAM_DEF_EX(unsigned, OBJMGR, SCOPE_AUTORELEASE_SIZE, 10,
79  eParam_NoThread, OBJMGR_SCOPE_AUTORELEASE_SIZE);
80 
81 static unsigned s_GetScopeAutoReleaseSize(void)
82 {
84  return sx_Value->Get();
85 }
86 
87 
88 NCBI_PARAM_DECL(int, OBJMGR, SCOPE_POSTPONE_DELETE);
89 NCBI_PARAM_DEF_EX(int, OBJMGR, SCOPE_POSTPONE_DELETE, 1,
90  eParam_NoThread, OBJMGR_SCOPE_POSTPONE_DELETE);
91 
92 static int s_GetScopePostponeDelete(void)
93 {
95  return sx_Value->Get();
96 }
97 
98 
99 DEFINE_STATIC_FAST_MUTEX(sx_UsedTSEMutex);
100 
101 
102 /////////////////////////////////////////////////////////////////////////////
103 // CDataSource_ScopeInfo
104 /////////////////////////////////////////////////////////////////////////////
105 
107  CDataSource& ds)
108  : m_Scope(&scope),
109  m_DataSource(&ds),
110  m_CanBeUnloaded(s_GetScopeAutoReleaseEnabled() &&
111  ds.GetDataLoader() &&
112  ds.GetDataLoader()->CanGetBlobById()),
113  m_CanBeEdited(ds.CanBeEdited()),
114  m_CanRemoveOnResetHistory(false),
115  m_NextTSEIndex(0),
116  m_TSE_UnlockQueue(s_GetScopeAutoReleaseSize())
117 {
118 }
119 
120 
122 {
123  _ASSERT(!m_Scope);
125 }
126 
127 
129 {
130  if ( !m_Scope ) {
131  NCBI_THROW(CCoreException, eNullPtr,
132  "CDataSource_ScopeInfo is not attached to CScope");
133  }
134  return *m_Scope;
135 }
136 
137 
139 {
140  return GetDataSource().GetDataLoader();
141 }
142 
143 
145 {
146  return !CanBeEdited() && GetDataSource().CanBeEdited();
147 }
148 
149 
151 {
152  _ASSERT(CanBeEdited());
154  m_CanBeEdited = false;
155  _ASSERT(IsConst());
156 }
157 
158 
160 {
161  _ASSERT(CanBeEdited());
165 }
166 
167 
169 {
170  if ( m_Scope ) {
172  ResetDS();
175  m_Scope = 0;
176  }
177 }
178 
179 
182 {
183  return m_TSE_InfoMap;
184 }
185 
186 
189 {
190  return m_TSE_LockSet;
191 }
192 
193 
194 static DECLARE_TLS_VAR(CUnlockedTSEsGuard*, st_Guard);
195 
196 
198 {
199  if ( !st_Guard ) {
200  st_Guard = this;
201  }
202 }
203 
204 
206 {
207  if ( st_Guard == this ) {
208  while ( !m_UnlockedTSEsInternal.empty() ) {
209  TUnlockedTSEsInternal locks;
211  }
212  st_Guard = 0;
213  }
214 }
215 
216 
218 {
219  if ( !s_GetScopePostponeDelete() ) {
220  return;
221  }
222  _ASSERT(st_Guard);
223  if ( CUnlockedTSEsGuard* guard = st_Guard ) {
224  guard->m_UnlockedTSEsLock.push_back(ConstRef(&*lock));
225  }
226 }
227 
228 
230 {
231  if ( !s_GetScopePostponeDelete() ) {
232  return;
233  }
234  _ASSERT(st_Guard);
235  if ( CUnlockedTSEsGuard* guard = st_Guard ) {
236  guard->m_UnlockedTSEsInternal.push_back(lock);
237  }
238 }
239 
240 
242 {
243  if ( !s_GetScopePostponeDelete() ) {
244  return;
245  }
246  _ASSERT(st_Guard);
247  if ( CUnlockedTSEsGuard* guard = st_Guard ) {
248  guard->m_UnlockedTSEsInternal.insert
249  (guard->m_UnlockedTSEsInternal.end(), locks.begin(), locks.end());
250  }
251 }
252 
253 
255 {
259 }
260 
261 
263 {
266 }
267 
268 
271 {
272  CTSE_ScopeUserLock ret;
273  _ASSERT(lock);
274  if ( m_EditDS && TSEIsReplaced(lock->GetBlobId()) ) {
275  return ret;
276  }
277  TTSE_ScopeInfo info;
278  {{
280  TTSE_ScopeInfo& slot = m_TSE_InfoMap[lock->GetBlobId()];
281  if ( !slot ) {
282  slot = info = new CTSE_ScopeInfo(*this, lock,
283  m_NextTSEIndex++,
285  if ( m_CanBeUnloaded ) {
286  // add this TSE into index by SeqId
287  x_IndexTSE(*info);
288  }
289  }
290  else {
291  info = slot;
292  }
293  _ASSERT(info->IsAttached() && &info->GetDSInfo() == this);
294  info->m_TSE_LockCounter.Add(1);
295  {{
296  // first remove the TSE from unlock queue
298  // TSE must be locked already by caller
299  _ASSERT(info->m_TSE_LockCounter.Get() > 0);
300  m_TSE_UnlockQueue.Erase(info);
301  // TSE must be still locked by caller even after removing it
302  // from unlock queue
303  _ASSERT(info->m_TSE_LockCounter.Get() > 0);
304  }}
305  info->SetTSE_Lock(lock);
306  ret.Reset(info);
307  _VERIFY(info->m_TSE_LockCounter.Add(-1) > 0);
308  _ASSERT(info->GetTSE_Lock() == lock);
309  }}
310  return ret;
311 }
312 
313 
315  const CTSE_Lock& lock)
316 {
318  _ASSERT(!info.m_DS_Info);
319  _ASSERT(!info.m_TSE_Lock);
320  _ASSERT(lock && &lock->GetDataSource() == &GetDataSource());
323  (lock->GetBlobId(),
324  //STSE_Key(*lock, m_CanBeUnloaded),
325  Ref(&info))).second);
326  if ( m_CanBeUnloaded ) {
327  // add this TSE into index by SeqId
328  x_IndexTSE(info);
329  }
330  info.m_DS_Info = this;
331  info.SetTSE_Lock(lock);
332 }
333 
334 
336 {
339  }
340 }
341 
342 
344 {
347  while ( tse_it != m_TSE_BySeqId.end() && tse_it->first == *it ) {
348  if ( tse_it->second == &tse ) {
349  m_TSE_BySeqId.erase(tse_it++);
350  }
351  else {
352  ++tse_it;
353  }
354  }
355  }
356 }
357 
358 
361 {
362  TTSE_ScopeInfo tse;
364  it != m_TSE_BySeqId.end() && it->first == idh; ++it ) {
365  if ( !tse || x_IsBetter(idh, *it->second, *tse) ) {
366  tse = it->second;
367  }
368  }
369  return tse;
370 }
371 
372 
374 {
375  {{
376  // first remove the TSE from unlock queue
378  // TSE must be locked already by caller
379  _ASSERT(tse.m_TSE_LockCounter.Get() > 0);
380  m_TSE_UnlockQueue.Erase(&tse);
381  // TSE must be still locked by caller even after removing it
382  // from unlock queue
383  _ASSERT(tse.m_TSE_LockCounter.Get() > 0);
384  }}
385  if ( !tse.GetTSE_Lock() ) {
386  // OK, we need to update the lock
387  if ( !lock ) { // obtain lock from CDataSource
388  lock = tse.m_UnloadedInfo->LockTSE();
389  _ASSERT(lock);
390  }
391  tse.SetTSE_Lock(lock);
392  _ASSERT(tse.GetTSE_Lock() == lock);
393  }
394  _ASSERT(tse.m_TSE_LockCounter.Get() > 0);
395  _ASSERT(tse.GetTSE_Lock());
396 }
397 
398 
399 // Called by destructor of CTSE_ScopeUserLock when lock counter goes to 0
401 {
402  CUnlockedTSEsGuard guard;
403  {{
404  CTSE_ScopeInternalLock unlocked;
406  if ( tse.m_TSE_LockCounter.Get() > 0 ) {
407  // relocked already
408  return;
409  }
410  if ( !tse.GetTSE_Lock() ) {
411  // already unlocked
412  return;
413  }
414  m_TSE_UnlockQueue.Put(&tse, CTSE_ScopeInternalLock(&tse), &unlocked);
415  if ( unlocked ) {
417  }
418  }}
419 }
420 
421 
422 // Called by destructor of CTSE_ScopeInternalLock when lock counter goes to 0
423 // CTSE_ScopeInternalLocks are stored in m_TSE_UnlockQueue
425 {
426  if ( tse.m_TSE_LockCounter.Get() > 0 ) {
427  // relocked already
428  return;
429  }
430  if ( !tse.GetTSE_Lock() ) {
431  // already unlocked
432  return;
433  }
434  CUnlockedTSEsGuard guard;
435  tse.ForgetTSE_Lock();
436 }
437 
438 
440 {
441  CUnlockedTSEsGuard guard;
443  {{
445  {{
447  m_TSE_UnlockQueue.Clear(&unlocked);
448  }}
449  if ( !unlocked.empty() ) {
451  }
452  }}
454  it->second->DropTSE_Lock();
455  it->second->x_DetachDS();
456  }
459  {{
462  }}
463  m_NextTSEIndex = 0;
464 }
465 
466 
467 void CDataSource_ScopeInfo::ResetHistory(int action_if_locked)
468 {
469  if ( action_if_locked == CScope::eRemoveIfLocked ) {
470  // no checks -> fast reset
471  ResetDS();
472  return;
473  }
474  typedef vector< CRef<CTSE_ScopeInfo> > TTSEs;
475  TTSEs tses;
476  {{
478  tses.reserve(m_TSE_InfoMap.size());
480  tses.push_back(it->second);
481  }
482  }}
483  CUnlockedTSEsGuard guard;
484  ITERATE ( TTSEs, it, tses ) {
485  it->GetNCObject().RemoveFromHistory(action_if_locked);
486  }
487 }
488 
489 
491  bool drop_from_ds)
492 {
493  tse.ReleaseUsedTSEs();
495  if ( tse.CanBeUnloaded() ) {
496  x_UnindexTSE(tse);
497  }
498  tse.RestoreReplacedTSE();
500  tse.m_TSE_LockCounter.Add(1); // to prevent storing into m_TSE_UnlockQueue
501  // remove TSE lock completely
502  {{
504  m_TSE_UnlockQueue.Erase(&tse);
505  }}
506  if ( CanRemoveOnResetHistory() ||
507  (drop_from_ds && GetDataSource().CanBeEdited()) ) {
508  // remove TSE from static blob set in DataSource
509  CConstRef<CTSE_Info> tse_info(&*tse.GetTSE_Lock());
510  tse.ResetTSE_Lock();
511  GetDataSource().DropStaticTSE(const_cast<CTSE_Info&>(*tse_info));
512  }
513  else {
514  tse.ResetTSE_Lock();
515  }
516  tse.x_DetachDS();
517  tse.m_TSE_LockCounter.Add(-1); // restore lock counter
518  _ASSERT(!tse.GetTSE_Lock());
519  _ASSERT(!tse.m_DS_Info);
520 }
521 
522 
525 {
527  {{
530  }}
531  if ( lock ) {
532  return GetTSE_Lock(lock);
533  }
534  return TTSE_Lock();
535 }
536 
537 
540 {
542  {{
544  lock = GetDataSource().GetSeq_entry_Lock(blob_id);
545  }}
546  if ( lock.first ) {
547  return TSeq_entry_Lock(lock.first, GetTSE_Lock(lock.second));
548  }
549  return TSeq_entry_Lock();
550 }
551 
552 
555 {
557  {{
560  }}
561  if ( lock.first ) {
562  return TSeq_entry_Lock(lock.first, GetTSE_Lock(lock.second));
563  }
564  return TSeq_entry_Lock();
565 }
566 
567 
570 {
572  {{
575  }}
576  if ( lock.first ) {
577  return TSeq_annot_Lock(lock.first, GetTSE_Lock(lock.second));
578  }
579  return TSeq_annot_Lock();
580 }
581 
582 
585 {
587  {{
590  }}
591  if ( lock.first ) {
592  return TBioseq_set_Lock(lock.first, GetTSE_Lock(lock.second));
593  }
594  return TBioseq_set_Lock();
595 }
596 
597 
600 {
602  {{
604  lock = GetDataSource().FindBioseq_Lock(bioseq, m_TSE_LockSet);
605  }}
606  if ( lock.first ) {
607  return GetTSE_Lock(lock.second)->GetBioseqLock(null, lock.first);
608  }
609  return TBioseq_Lock();
610 }
611 
612 
615  TSeqPos loc_pos,
616  const CSeq_feat& feat)
617 {
618  TSeq_feat_Lock ret;
620  {{
622  lock = GetDataSource().FindSeq_feat_Lock(loc_id, loc_pos, feat);
623  }}
624  if ( lock.first.first ) {
625  ret.first.first = lock.first.first;
626  ret.first.second = GetTSE_Lock(lock.first.second);
627  ret.second = lock.second;
628  }
629  return ret;
630 }
631 
632 
634  int get_flag)
635 {
636  SSeqMatch_Scope ret = x_GetSeqMatch(idh);
637  if ( !ret && get_flag == CScope::eGetBioseq_All ) {
638  // Try to load the sequence from the data source
639  SSeqMatch_DS ds_match = GetDataSource().BestResolve(idh);
640  if ( ds_match ) {
641  x_SetMatch(ret, ds_match);
642  }
643  }
644 #ifdef _DEBUG
645  if ( ret ) {
646  _ASSERT(ret.m_Seq_id);
647  _ASSERT(ret.m_Bioseq);
648  _ASSERT(ret.m_TSE_Lock);
650  }
651 #endif
652  return ret;
653 }
654 
655 
657  CTSE_ScopeInfo& tse)
658 {
659  SSeqMatch_Scope ret;
660  x_SetMatch(ret, tse, idh);
661  return ret;
662 }
663 
664 
666 {
667  SSeqMatch_Scope ret = x_FindBestTSE(idh);
668  if ( !ret && idh.HaveMatchingHandles() ) {
671  ITERATE ( CSeq_id_Handle::TMatches, it, ids ) {
672  if ( *it == idh ) // already checked
673  continue;
674  if ( ret && ret.m_Seq_id.IsBetter(*it) ) // worse hit
675  continue;
676  if ( SSeqMatch_Scope match = x_FindBestTSE(*it) ) {
677  ret = match;
678  }
679  }
680  }
681  return ret;
682 }
683 
684 
686 {
687  SSeqMatch_Scope ret;
688  if ( m_CanBeUnloaded ) {
689  // We have full index of static TSEs.
692  if ( tse ) {
693  x_SetMatch(ret, *tse, idh);
694  }
695  }
696  else {
697  // We have to ask data source about it.
698  CDataSource::TSeqMatches matches;
699  {{
701  CDataSource::TSeqMatches matches2 =
703  matches.swap(matches2);
704  }}
705  ITERATE ( CDataSource::TSeqMatches, it, matches ) {
706  SSeqMatch_Scope nxt;
707  x_SetMatch(nxt, *it);
708  if ( !nxt ) {
709  continue;
710  }
711  if ( !ret || x_IsBetter(idh, *nxt.m_TSE_Lock, *ret.m_TSE_Lock) ) {
712  ret = nxt;
713  }
714  }
715  }
716  return ret;
717 }
718 
719 
721  const CTSE_ScopeInfo& tse1,
722  const CTSE_ScopeInfo& tse2)
723 {
724  // First of all we check if we already resolve bioseq with this id.
725  bool resolved1 = tse1.HasResolvedBioseq(idh);
726  bool resolved2 = tse2.HasResolvedBioseq(idh);
727  if ( resolved1 != resolved2 ) {
728  return resolved1;
729  }
730  // Now check TSEs' orders.
733  if ( order1 != order2 ) {
734  return order1 < order2;
735  }
736 
737  // Now we have very similar TSE's so we'll prefer the first one added.
738  return tse1.GetLoadIndex() < tse2.GetLoadIndex();
739 }
740 
741 
743  CTSE_ScopeInfo& tse,
744  const CSeq_id_Handle& idh) const
745 {
746  match.m_Seq_id = idh;
747  match.m_TSE_Lock = CTSE_ScopeUserLock(&tse);
748  _ASSERT(match.m_Seq_id);
749  _ASSERT(match.m_TSE_Lock);
750  match.m_Bioseq = match.m_TSE_Lock->GetTSE_Lock()->FindBioseq(idh);
751  _ASSERT(match.m_Bioseq);
752  _ASSERT(match.m_Bioseq == match.m_TSE_Lock->m_TSE_Lock->FindBioseq(match.m_Seq_id));
753 }
754 
755 
757  const SSeqMatch_DS& ds_match)
758 {
759  match.m_TSE_Lock = GetTSE_Lock(ds_match.m_TSE_Lock);
760  if ( !match.m_TSE_Lock ) {
761  match.m_Seq_id.Reset();
762  match.m_Bioseq.Reset();
763  return;
764  }
765  match.m_Seq_id = ds_match.m_Seq_id;
766  match.m_Bioseq = ds_match.m_Bioseq;
767  _ASSERT(match.m_Seq_id);
768  _ASSERT(match.m_Bioseq);
769  _ASSERT(match.m_TSE_Lock);
770  _ASSERT(match.m_Bioseq == match.m_TSE_Lock->GetTSE_Lock()->FindBioseq(match.m_Seq_id));
771 }
772 
773 
775 {
776  CDataSource::TSeqMatchMap ds_match_map;
777  ITERATE(TSeqMatchMap, it, match_map) {
778  if ( it->second ) {
779  continue;
780  }
782  it->first, SSeqMatch_DS()));
783  }
784  if ( match_map.empty() ) {
785  return;
786  }
787  GetDataSource().GetBlobs(ds_match_map);
788  ITERATE(CDataSource::TSeqMatchMap, ds_match, ds_match_map) {
789  if ( !ds_match->second ) {
790  continue;
791  }
792  SSeqMatch_Scope& scope_match = match_map[ds_match->first];
793  scope_match = x_GetSeqMatch(ds_match->first);
794  x_SetMatch(scope_match, ds_match->second);
795  if ( !scope_match ) {
796  match_map.erase(ds_match->first);
797  }
798  }
799 }
800 
801 
803 {
805  return m_TSE_UnlockQueue.Contains(&tse);
806 }
807 
808 
810 {
811  if ( m_EditDS ) {
812  return m_EditDS->TSEIsReplaced(blob_id);
813  }
814  return m_ReplacedTSEs.find(blob_id) != m_ReplacedTSEs.end();
815 }
816 
817 
818 /////////////////////////////////////////////////////////////////////////////
819 // CTSE_ScopeInfo
820 /////////////////////////////////////////////////////////////////////////////
821 
822 
824  : m_Source(&tse_lock->GetDataSource()),
825  m_BlobId(tse_lock->GetBlobId()),
826  m_BlobOrder(tse_lock->GetBlobOrder())
827 {
828  _ASSERT(m_Source);
829  _ASSERT(m_BlobId);
830  // copy all bioseq ids
831  tse_lock->GetBioseqsIds(m_BioseqsIds);
832 }
833 
834 
836 {
837  _ASSERT(m_Source);
838  _ASSERT(m_BlobId);
839  return m_Source->GetDataLoader()->GetBlobById(m_BlobId);
840 }
841 
842 
844  const CTSE_Lock& lock,
845  int load_index,
846  bool can_be_unloaded)
847  : m_DS_Info(&ds_info),
848  m_LoadIndex(load_index),
849  m_UsedByTSE(0)
850 {
851  _ASSERT(lock);
852  if ( can_be_unloaded ) {
853  _ASSERT(lock->GetBlobId());
854  m_UnloadedInfo.reset(new SUnloadedInfo(lock));
855  }
856  else {
857  // permanent lock
858  _TRACE_TSE_LOCK("CTSE_ScopeInfo("<<this<<") perm lock");
860  x_SetTSE_Lock(lock);
861  _ASSERT(m_TSE_Lock == lock);
862  }
863 }
864 
865 
867 {
868  if ( !CanBeUnloaded() ) {
869  // remove permanent lock
870  _TRACE_TSE_LOCK("CTSE_ScopeInfo("<<this<<") perm unlock: "<<m_TSE_LockCounter.Get());
871  _VERIFY(m_TSE_LockCounter.Add(-1) == 0);
872  }
873  x_DetachDS();
874  _TRACE_TSE_LOCK("CTSE_ScopeInfo("<<this<<") final: "<<m_TSE_LockCounter.Get());
875  _ASSERT(m_TSE_LockCounter.Get() == 0);
879 }
880 
881 
883 {
884  if ( !m_TSE_Lock ) {
885  _ASSERT(m_UnloadedInfo.get());
886  return m_UnloadedInfo->m_BlobOrder;
887  }
888  else {
891  if ( m_UnloadedInfo && m_UnloadedInfo->m_BlobOrder != order ) {
892  m_UnloadedInfo->m_BlobOrder = order;
893  }
894  return order;
895  }
896 }
897 
898 
900 {
901  if ( CanBeUnloaded() ) {
902  _ASSERT(m_UnloadedInfo.get());
903  return m_UnloadedInfo->m_BlobId;
904  }
905  else {
907  return m_TSE_Lock->GetBlobId();
908  }
909 }
910 
911 
913 {
915  return m_UnloadedInfo->m_BioseqsIds;
916 }
917 
918 
920 {
921  CTSE_ScopeInfo* tse = static_cast<CTSE_ScopeInfo*>(this);
922  if ( !tse->m_TSE_Lock ) {
923  CDataSource_ScopeInfo* ds = tse->m_DS_Info;
924  if ( !ds ) {
925  tse->m_TSE_LockCounter.Add(-1);
926  NCBI_THROW(CCoreException, eNullPtr,
927  "CTSE_ScopeInfo is not attached to CScope");
928  }
929  ds->UpdateTSELock(*tse, CTSE_Lock());
930  }
931  _ASSERT(tse->m_TSE_Lock);
932 }
933 
934 
936 {
937  CTSE_ScopeInfo* tse = static_cast<CTSE_ScopeInfo*>(this);
938  _ASSERT(tse->CanBeUnloaded());
939  if ( tse->IsAttached() ) {
940  tse->GetDSInfo().ReleaseTSELock(*tse);
941  }
942 }
943 
944 
946 {
947  CTSE_ScopeInfo* tse = static_cast<CTSE_ScopeInfo*>(this);
948  _ASSERT(tse->CanBeUnloaded());
949  if ( tse->IsAttached() ) {
950  tse->GetDSInfo().ForgetTSELock(*tse);
951  }
952 }
953 
954 
955 bool CTSE_ScopeInfo::x_SameTSE(const CTSE_Info& tse) const
956 {
957  return m_TSE_LockCounter.Get() > 0 && m_TSE_Lock && &*m_TSE_Lock == &tse;
958 }
959 
960 
962 {
963  // release all used TSEs
964  TUsedTSE_LockSet used;
965  CFastMutexGuard guard(sx_UsedTSEMutex);
967  _ASSERT(it->second->m_UsedByTSE == this);
968  it->second->m_UsedByTSE = 0;
969  }
970  m_UsedTSE_Set.swap(used);
971 }
972 
973 
975 {
976  CTSE_ScopeInternalLock add_lock(used_tse.GetNCPointer());
977  CTSE_ScopeInfo& add_info = const_cast<CTSE_ScopeInfo&>(*used_tse);
978  if ( &add_info == this || // the same TSE
979  !add_info.CanBeUnloaded() || // added is permanentrly locked
980  m_TSE_LockCounter.Get() == 0 ) { // this one is unlocked
981  return false;
982  }
983  CFastMutexGuard guard(sx_UsedTSEMutex);
984  if ( add_info.m_UsedByTSE ) { // already used
985  return false;
986  }
987  for ( const CTSE_ScopeInfo* p = m_UsedByTSE; p; p = p->m_UsedByTSE ) {
988  if ( p == &add_info ) {
989  return false;
990  }
991  }
992  CTSE_ScopeInternalLock& add_slot = m_UsedTSE_Set[ConstRef(&*used_tse)];
993  _ASSERT(!add_slot);
994  add_info.m_UsedByTSE = this;
995  swap(add_slot, add_lock);
996  return true;
997 }
998 
999 
1001 {
1002  _ASSERT(lock);
1003  if ( !m_TSE_Lock ) {
1004  m_TSE_Lock = lock;
1005  GetDSInfo().AddTSE_Lock(lock);
1006  }
1007  _ASSERT(m_TSE_Lock == lock);
1008 }
1009 
1010 
1012 {
1013  if ( m_TSE_Lock ) {
1014  CTSE_Lock lock;
1015  lock.Swap(m_TSE_Lock);
1016  GetDSInfo().RemoveTSE_Lock(lock);
1017  }
1018  _ASSERT(!m_TSE_Lock);
1019 }
1020 
1021 
1023 {
1024  _ASSERT(lock);
1025  if ( !m_TSE_Lock ) {
1027  x_SetTSE_Lock(lock);
1028  }
1029  _ASSERT(m_TSE_Lock == lock);
1030 }
1031 
1032 
1034 {
1035  if ( m_TSE_Lock ) {
1037  x_ResetTSE_Lock();
1038  }
1039  _ASSERT(!m_TSE_Lock);
1040 }
1041 
1042 
1044 {
1045  if ( m_TSE_Lock ) {
1047  m_TSE_Lock.Reset();
1048  }
1049  _ASSERT(!m_TSE_Lock);
1050 }
1051 
1052 
1053 void CTSE_ScopeInfo::SetEditTSE(const CTSE_Lock& new_tse_lock,
1054  CDataSource_ScopeInfo& new_ds)
1055 {
1056  _ASSERT(!CanBeEdited());
1057  _ASSERT(new_ds.CanBeEdited());
1058  _ASSERT(&new_tse_lock->GetDataSource() == &new_ds.GetDataSource());
1059 
1060  CUnlockedTSEsGuard unlocked_guard;
1064  CTSE_Lock old_tse_lock = m_TSE_Lock;
1065 
1066  TScopeInfoMap old_map; // save old scope info map
1067  old_map.swap(m_ScopeInfoMap);
1068  TBioseqById old_bioseq_map; // save old bioseq info map
1069  old_bioseq_map.swap(m_BioseqById);
1070 
1071  GetDSInfo().RemoveFromHistory(*this); // remove tse from old ds
1072  _ASSERT(!m_TSE_Lock);
1073  _ASSERT(!m_DS_Info);
1074  if ( CanBeUnloaded() ) {
1075  m_UnloadedInfo.reset(); // edit tse cannot be unloaded
1077  }
1078 
1079  // convert scope info map
1080  const TEditInfoMap& edit_map = new_tse_lock->m_BaseTSE->m_ObjectCopyMap;
1081  NON_CONST_ITERATE ( TScopeInfoMap, it, old_map ) {
1082  CConstRef<CObject> old_obj(it->first);
1083  _ASSERT(old_obj);
1084  TEditInfoMap::const_iterator iter = edit_map.find(old_obj);
1085  TScopeInfoMapKey new_obj;
1086  if ( iter == edit_map.end() ) {
1087  _ASSERT(&*old_obj == &*old_tse_lock);
1088  new_obj.Reset(&*new_tse_lock);
1089  }
1090  else {
1091  new_obj.Reset(&dynamic_cast<const CTSE_Info_Object&>(*iter->second));
1092  }
1093  _ASSERT(new_obj);
1094  _ASSERT(&*new_obj != &*old_obj);
1095  TScopeInfoMapValue info = it->second;
1096  _ASSERT(info->m_ObjectInfo == old_obj);
1097  info->m_ObjectInfo = new_obj;
1099  (TScopeInfoMap::value_type(new_obj, info)).second);
1100  }
1101  // restore bioseq info map
1102  m_BioseqById.swap(old_bioseq_map);
1103 
1104  new_ds.AttachTSE(*this, new_tse_lock);
1105 
1106  _ASSERT(&GetDSInfo() == &new_ds);
1107  _ASSERT(m_TSE_Lock == new_tse_lock);
1108 
1109  const_cast<CTSE_Info&>(*new_tse_lock).m_BaseTSE->m_ObjectCopyMap.clear();
1110 }
1111 
1112 
1114 {
1115  if ( m_ReplacedTSE ) {
1116  _ASSERT(m_DS_Info);
1118  m_ReplacedTSE = TBlobId();
1119  }
1120 }
1121 
1122 
1124 {
1126  _ASSERT(m_DS_Info);
1127  m_ReplacedTSE = old_tse.GetBlobId();
1128  if ( !m_DS_Info->m_ReplacedTSEs.insert(m_ReplacedTSE).second ) {
1129  m_ReplacedTSE = TBlobId();
1130  ERR_POST("CTSE_ScopeInfo::ReplaceTSE("<<
1131  old_tse.GetDescription()<<"): already replaced");
1132  }
1133 }
1134 
1135 
1136 // Action A4.
1138 {
1139  if ( m_TSE_LockCounter.Get() > 0 ) {
1140  // relocked already
1141  return;
1142  }
1143  ReleaseUsedTSEs();
1144  if ( !m_TSE_Lock ) {
1145  return;
1146  }
1148  if ( m_TSE_LockCounter.Get() > 0 ) {
1149  // relocked already
1150  return;
1151  }
1152  if ( !m_TSE_Lock ) {
1153  return;
1154  }
1156  _ASSERT(!it->second->m_TSE_Handle.m_TSE);
1157  it->second->m_ObjectInfo.Reset();
1158  if ( it->second->IsTemporary() ) {
1159  it->second->x_DetachTSE(this);
1160  }
1161  }
1163  x_ResetTSE_Lock();
1164 }
1165 
1166 
1168 {
1169  if ( !m_DS_Info ) {
1170  return;
1171  }
1172  ReleaseUsedTSEs();
1175  it->second->m_TSE_Handle.Reset();
1176  it->second->m_ObjectInfo.Reset();
1177  it->second->x_DetachTSE(this);
1178  }
1180  m_TSE_Lock.Reset();
1181  while ( !m_BioseqById.empty() ) {
1182  CRef<CBioseq_ScopeInfo> bioseq = m_BioseqById.begin()->second;
1183  bioseq->x_DetachTSE(this);
1184  _ASSERT(m_BioseqById.empty()||m_BioseqById.begin()->second != bioseq);
1185  }
1186  m_DS_Info = 0;
1187 }
1188 
1189 
1191 {
1192  int max_locks = CanBeUnloaded() ? 0 : 1;
1193  if ( GetDSInfo().TSEIsInQueue(*this) ) {
1194  // Extra-lock from delete queue allowed
1195  ++max_locks;
1196  }
1197  return max_locks;
1198 }
1199 
1200 
1202 {
1204 }
1205 
1206 
1208 {
1209  return int(m_TSE_LockCounter.Get()) > x_GetDSLocksCount() + 1;
1210 }
1211 
1212 
1213 void CTSE_ScopeInfo::RemoveFromHistory(int action_if_locked, bool drop_from_ds)
1214 {
1215  if ( IsLocked() ) {
1216  switch ( action_if_locked ) {
1217  case CScope::eKeepIfLocked:
1218  return;
1220  NCBI_THROW(CObjMgrException, eLockedData,
1221  "Cannot remove TSE from scope's history "
1222  "because it's locked");
1223  default: // forced removal
1224  break;
1225  }
1226  }
1227  CUnlockedTSEsGuard guard;
1228  GetDSInfo().RemoveFromHistory(*this, drop_from_ds);
1229 }
1230 
1231 
1233 {
1234  return m_BioseqById.find(id) != m_BioseqById.end();
1235 }
1236 
1237 
1239 {
1240  if ( CanBeUnloaded() ) {
1241  return binary_search(m_UnloadedInfo->m_BioseqsIds.begin(),
1242  m_UnloadedInfo->m_BioseqsIds.end(),
1243  id);
1244  }
1245  else {
1246  return m_TSE_Lock->ContainsBioseq(id);
1247  }
1248 }
1249 
1250 
1253 {
1254  if ( CanBeUnloaded() ) {
1255  if ( ContainsBioseq(id) ) {
1256  return id;
1257  }
1258  if ( id.HaveMatchingHandles() ) {
1260  id.GetMatchingHandles(ids, eAllowWeakMatch);
1261  ITERATE ( CSeq_id_Handle::TMatches, it, ids ) {
1262  if ( *it != id ) {
1263  if ( ContainsBioseq(*it) ) {
1264  return *it;
1265  }
1266  }
1267  }
1268  }
1269  return null;
1270  }
1271  else {
1272  return m_TSE_Lock->ContainsMatchingBioseq(id);
1273  }
1274 }
1275 
1276 // Action A5.
1279  const CSeq_entry_Info& info)
1280 {
1283  CRef<CSeq_entry_ScopeInfo> scope_info;
1284  TScopeInfoMapKey key(&info);
1286  if ( iter == m_ScopeInfoMap.end() || iter->first != key ) {
1287  scope_info = new CSeq_entry_ScopeInfo(tse, info);
1288  TScopeInfoMapValue value(scope_info);
1289  m_ScopeInfoMap.insert(iter, TScopeInfoMap::value_type(key, value));
1290  value->m_ObjectInfo = &info;
1291  }
1292  else {
1293  _ASSERT(iter->second->HasObject());
1294  _ASSERT(&iter->second->GetObjectInfo_Base() == &info);
1295  scope_info = &dynamic_cast<CSeq_entry_ScopeInfo&>(*iter->second);
1296  }
1297  if ( !scope_info->m_TSE_Handle.m_TSE ) {
1298  scope_info->m_TSE_Handle = tse.m_TSE;
1299  }
1300  _ASSERT(scope_info->IsAttached());
1301  _ASSERT(scope_info->m_TSE_Handle.m_TSE);
1302  _ASSERT(scope_info->HasObject());
1303  return TSeq_entry_Lock(*scope_info);
1304 }
1305 
1306 // Action A5.
1309  const CSeq_annot_Info& info)
1310 {
1313  CRef<CSeq_annot_ScopeInfo> scope_info;
1314  TScopeInfoMapKey key(&info);
1316  if ( iter == m_ScopeInfoMap.end() || iter->first != key ) {
1317  scope_info = new CSeq_annot_ScopeInfo(tse, info);
1318  TScopeInfoMapValue value(scope_info);
1319  m_ScopeInfoMap.insert(iter, TScopeInfoMap::value_type(key, value));
1320  value->m_ObjectInfo = &info;
1321  }
1322  else {
1323  _ASSERT(iter->second->HasObject());
1324  _ASSERT(&iter->second->GetObjectInfo_Base() == &info);
1325  scope_info = &dynamic_cast<CSeq_annot_ScopeInfo&>(*iter->second);
1326  }
1327  if ( !scope_info->m_TSE_Handle.m_TSE ) {
1328  scope_info->m_TSE_Handle = tse.m_TSE;
1329  }
1330  _ASSERT(scope_info->IsAttached());
1331  _ASSERT(scope_info->m_TSE_Handle.m_TSE);
1332  _ASSERT(scope_info->HasObject());
1333  return TSeq_annot_Lock(*scope_info);
1334 }
1335 
1336 // Action A5.
1339  const CBioseq_set_Info& info)
1340 {
1343  CRef<CBioseq_set_ScopeInfo> scope_info;
1344  TScopeInfoMapKey key(&info);
1346  if ( iter == m_ScopeInfoMap.end() || iter->first != key ) {
1347  scope_info = new CBioseq_set_ScopeInfo(tse, info);
1348  TScopeInfoMapValue value(scope_info);
1349  m_ScopeInfoMap.insert(iter, TScopeInfoMap::value_type(key, value));
1350  value->m_ObjectInfo = &info;
1351  }
1352  else {
1353  _ASSERT(iter->second->HasObject());
1354  _ASSERT(&iter->second->GetObjectInfo_Base() == &info);
1355  scope_info = &dynamic_cast<CBioseq_set_ScopeInfo&>(*iter->second);
1356  }
1357  if ( !scope_info->m_TSE_Handle.m_TSE ) {
1358  scope_info->m_TSE_Handle = tse.m_TSE;
1359  }
1360  _ASSERT(scope_info->IsAttached());
1361  _ASSERT(scope_info->m_TSE_Handle.m_TSE);
1362  _ASSERT(scope_info->HasObject());
1363  return TBioseq_set_Lock(*scope_info);
1364 }
1365 
1366 // Action A5.
1369  CConstRef<CBioseq_Info> bioseq)
1370 {
1372  CTSE_ScopeUserLock tse(this);
1374  if ( !info ) {
1375  // find CBioseq_ScopeInfo
1376  _ASSERT(bioseq);
1378  const CBioseq_Info::TId& ids = bioseq->GetId();
1379  if ( !ids.empty() ) {
1380  // named bioseq, look in Seq-id index only
1381  info = x_FindBioseqInfo(ids);
1382  if ( !info ) {
1383  info = x_CreateBioseqInfo(ids);
1384  }
1385  }
1386  else {
1387  // unnamed bioseq, look in object map, create if necessary
1388  TScopeInfoMapKey key(bioseq);
1390  if ( iter == m_ScopeInfoMap.end() || iter->first != key ) {
1391  info = new CBioseq_ScopeInfo(*this);
1392  TScopeInfoMapValue value(info);
1393  iter = m_ScopeInfoMap
1394  .insert(iter, TScopeInfoMap::value_type(key, value));
1395  value->m_ObjectInfo = &*bioseq;
1396  }
1397  else {
1398  _ASSERT(iter->second->HasObject());
1399  _ASSERT(&iter->second->GetObjectInfo_Base() == &*bioseq);
1400  info.Reset(&dynamic_cast<CBioseq_ScopeInfo&>(*iter->second));
1401  }
1402  if ( !info->m_TSE_Handle.m_TSE ) {
1403  info->m_TSE_Handle = tse;
1404  }
1405  _ASSERT(info->IsAttached());
1406  _ASSERT(info->m_TSE_Handle.m_TSE);
1407  _ASSERT(info->HasObject());
1408  return TBioseq_Lock(*info);
1409  }
1410  }
1411  _ASSERT(info);
1412  _ASSERT(!info->IsDetached());
1413  // update CBioseq_ScopeInfo object
1414  if ( !info->HasObject() ) {
1415  if ( !bioseq ) {
1416  const CBioseq_ScopeInfo::TIds& ids = info->GetIds();
1417  if ( !ids.empty() ) {
1418  const CSeq_id_Handle& id = *ids.begin();
1419  bioseq = m_TSE_Lock->FindBioseq(id);
1420  _ASSERT(bioseq);
1421  }
1422  else {
1423  // unnamed bioseq without object - error,
1424  // this situation must be prevented by code.
1425  _ASSERT(0 && "CBioseq_ScopeInfo without ids and bioseq");
1426  }
1427  }
1428  _ASSERT(bioseq);
1429  _ASSERT(bioseq->GetId() == info->GetIds());
1430  TScopeInfoMapKey key(bioseq);
1431  TScopeInfoMapValue value(info);
1433  .insert(TScopeInfoMap::value_type(key, value)).second);
1434  info->m_ObjectInfo = &*bioseq;
1435  info->x_SetLock(tse, *bioseq);
1436  }
1437  if ( !info->m_TSE_Handle.m_TSE ) {
1438  info->m_TSE_Handle = tse;
1439  }
1440  _ASSERT(info->HasObject());
1442  _ASSERT(m_ScopeInfoMap.find(TScopeInfoMapKey(&info->GetObjectInfo()))->second == info);
1443  _ASSERT(info->IsAttached());
1444  _ASSERT(info->m_TSE_Handle.m_TSE);
1445  _ASSERT(info->HasObject());
1446  return TBioseq_Lock(*info);
1447 }
1448 
1449 
1450 // Action A1
1452 {
1453  if ( !info.m_TSE_Handle.m_TSE ) {
1454  // already unlocked
1455  return;
1456  }
1457  CRef<CScope_Impl> scope;
1458  CRef<CTSE_ScopeInfo> self;
1459  CUnlockedTSEsGuard guard;
1460  {{
1461  CMutexGuard guard_mtx(m_TSE_LockMutex);
1462  if ( info.m_LockCounter.Get() > 0 ) {
1463  // already locked again
1464  return;
1465  }
1466  scope = m_DS_Info->m_Scope; // to prevent premature deletion of scope
1467  self = this; // to prevent deletion of this while mutex is locked.
1468  info.m_TSE_Handle.Reset();
1469  }}
1470 }
1471 
1472 
1473 // Find scope bioseq info by match: CConstRef<CBioseq_Info> & CSeq_id_Handle
1474 // The problem is that CTSE_Info and CBioseq_Info may be unloaded and we
1475 // cannot store pointers to them.
1476 // However, we have to find the same CBioseq_ScopeInfo object.
1477 // It is stored in m_BioseqById map under one of Bioseq's ids.
1480 {
1481  _ASSERT(&*match.m_TSE_Lock == this);
1482  _ASSERT(match.m_Seq_id);
1483  _ASSERT(match.m_Bioseq);
1485  const CBioseq_Info::TId& ids = match.m_Bioseq->GetId();
1486  _ASSERT(find(ids.begin(), ids.end(), match.m_Seq_id) != ids.end());
1487 
1489 
1490  info = x_FindBioseqInfo(ids);
1491  if ( !info ) {
1492  info = x_CreateBioseqInfo(ids);
1493  }
1494  return info;
1495 }
1496 
1497 
1500 {
1501  if ( !ids.empty() ) {
1502  const CSeq_id_Handle& id = *ids.begin();
1504  it != m_BioseqById.end() && it->first == id; ++it ) {
1505  if ( it->second->GetIds() == ids ) {
1506  return it->second;
1507  }
1508  }
1509  }
1510  return null;
1511 }
1512 
1513 
1515 {
1516  return Ref(new CBioseq_ScopeInfo(*this, ids));
1517 }
1518 
1519 
1521  CBioseq_ScopeInfo* info)
1522 {
1524 }
1525 
1526 
1528  const CBioseq_ScopeInfo* info)
1529 {
1531  it != m_BioseqById.end() && it->first == id; ++it ) {
1532  if ( it->second == info ) {
1533  m_BioseqById.erase(it);
1534  return;
1535  }
1536  }
1537  _ASSERT(0 && "UnindexBioseq: CBioseq_ScopeInfo is not in index");
1538 }
1539 
1540 // Action A2.
1542 {
1544  _ASSERT(info.IsAttached());
1546  if ( info.GetObjectInfo().Which() == CSeq_entry::e_Set ) {
1547  child.Reset(&*GetScopeLock(info.m_TSE_Handle,
1548  info.GetObjectInfo().GetSet()));
1549  }
1550  else if ( info.GetObjectInfo().Which() == CSeq_entry::e_Seq ) {
1551  CConstRef<CBioseq_Info> bioseq(&info.GetObjectInfo().GetSeq());
1552  child.Reset(&GetBioseqLock(null, bioseq).GetNCObject());
1553  }
1554  else {
1555  // nothing to do
1556  return;
1557  }
1558  info.GetNCObjectInfo().Reset();
1559  x_SaveRemoved(*child);
1560  _ASSERT(child->IsDetached());
1561 }
1562 
1563 // Action A2.
1565 {
1567  _ASSERT(info.IsAttached());
1568  CSeq_entry_Info& entry = info.GetNCObjectInfo();
1569  entry.GetParentBioseq_set_Info().RemoveEntry(Ref(&entry));
1570  x_SaveRemoved(info);
1571  _ASSERT(info.IsDetached());
1572 }
1573 
1574 // Action A2.
1576 {
1578  _ASSERT(info.IsAttached());
1579  CSeq_annot_Info& annot = info.GetNCObjectInfo();
1580  annot.GetParentBioseq_Base_Info().RemoveAnnot(Ref(&annot));
1581  x_SaveRemoved(info);
1582  _ASSERT(info.IsDetached());
1583 }
1584 
1585 
1586 // Action A7.
1587 #ifdef _DEBUG
1589  CScopeInfo_Base& child)
1590 {
1591  _ASSERT(parent.IsAttached());
1592  _ASSERT(parent.HasObject());
1593  _ASSERT(parent.m_LockCounter.Get() > 0);
1594  _ASSERT(child.IsDetached());
1595  _ASSERT(child.m_DetachedInfo);
1596  _ASSERT(child.HasObject());
1598  _ASSERT(child.m_LockCounter.Get() > 0);
1600 }
1601 #else /* _DEBUG */
1603  CScopeInfo_Base& /*child*/)
1604 {}
1605 #endif
1606 
1607 
1608 // Action A7.
1610  CSeq_entry_ScopeInfo& child,
1611  int index)
1612 {
1614  x_CheckAdded(parent, child);
1615  parent.GetNCObjectInfo().AddEntry(Ref(&child.GetNCObjectInfo()), index, true);
1616  x_RestoreAdded(parent, child);
1617  _ASSERT(child.IsAttached());
1618 }
1619 
1620 
1621 // Action A7.
1623  CSeq_annot_ScopeInfo& child)
1624 {
1626  x_CheckAdded(parent, child);
1627  parent.GetNCObjectInfo().AddAnnot(Ref(&child.GetNCObjectInfo()));
1628  x_RestoreAdded(parent, child);
1629  _ASSERT(child.IsAttached());
1630 }
1631 
1632 
1633 // Action A7.
1635  CBioseq_set_ScopeInfo& child)
1636 {
1638  x_CheckAdded(parent, child);
1640  parent.GetNCObjectInfo().SelectSet(child.GetNCObjectInfo());
1641  x_RestoreAdded(parent, child);
1642  _ASSERT(child.IsAttached());
1643 }
1644 
1645 
1646 // Action A7.
1648  CBioseq_ScopeInfo& child)
1649 {
1651  x_CheckAdded(parent, child);
1653  parent.GetNCObjectInfo().SelectSeq(child.GetNCObjectInfo());
1654  x_RestoreAdded(parent, child);
1655  _ASSERT(child.IsAttached());
1656 }
1657 
1658 
1659 // Save and restore scope info objects.
1660 
1661 typedef pair<CConstRef<CTSE_Info_Object>,
1663 typedef vector<TDetachedInfoElement> TDetachedInfo;
1664 
1665 // Action A3.
1667 {
1668  _ASSERT(info.IsAttached()); // info is not yet detached
1669  _ASSERT(!info.m_DetachedInfo); // and doesn't contain m_DetachedInfo yet
1670  _ASSERT(info.HasObject()); // it contains pointer to removed object
1671  _ASSERT(!info.GetObjectInfo_Base().HasParent_Info()); //and is root of tree
1673  _ASSERT(!m_UnloadedInfo); // this TSE cannot be unloaded
1674  _ASSERT(m_TSE_Lock); // and TSE is locked
1675  _TRACE("x_SaveRemoved("<<&info<<") TSE: "<<this);
1677  it != m_ScopeInfoMap.end(); ) {
1678  if ( !it->first->BelongsToTSE_Info(*m_TSE_Lock) ) {
1679  _TRACE(" "<<it->second<<" " << it->first);
1680  it->second->m_TSE_Handle.Reset();
1681  it->second->x_DetachTSE(this);
1682  if ( &*it->second != &info ) {
1683  _ASSERT(it->first->HasParent_Info());
1684  save->GetData().push_back(TDetachedInfoElement(it->first,
1685  it->second));
1686  }
1687  m_ScopeInfoMap.erase(it++);
1688  }
1689  else {
1690  ++it;
1691  }
1692  }
1693  _ASSERT(info.IsDetached()); // info is already detached
1695  info.m_DetachedInfo.Reset(save); // save m_DetachedInfo
1696 #ifdef _DEBUG
1697  ITERATE ( TBioseqById, it, m_BioseqById ) {
1698  _ASSERT(!it->second->IsDetached());
1699  _ASSERT(&it->second->x_GetTSE_ScopeInfo() == this);
1700  _ASSERT(!it->second->HasObject() || it->second->GetObjectInfo_Base().BelongsToTSE_Info(*m_TSE_Lock));
1701  }
1702 #endif
1703  // post checks
1704  _ASSERT(info.IsDetached());
1705  _ASSERT(info.m_DetachedInfo);
1706  _ASSERT(info.HasObject()); // it contains pointer to removed object
1707  _ASSERT(!info.GetObjectInfo_Base().HasParent_Info());//and is root of tree
1708 }
1709 
1710 // Action A7
1712  CScopeInfo_Base& child)
1713 {
1714  _ASSERT(parent.IsAttached()); // parent is attached
1715  _ASSERT(parent.m_TSE_Handle); // and locked
1716  _ASSERT(parent.m_LockCounter.Get() > 0);
1717  _ASSERT(child.IsDetached()); // child is detached
1718  _ASSERT(child.m_DetachedInfo); // and contain m_DetachedInfo
1719  _ASSERT(child.HasObject()); // it contains pointer to removed object
1720  _ASSERT(child.GetObjectInfo_Base().HasParent_Info());//and is connected
1721  _ASSERT(child.m_LockCounter.Get() > 0);
1722 
1723  _TRACE("x_RestoreAdded("<<&child<<") TSE: "<<this);
1724 
1726  (&dynamic_cast<CObjectFor<TDetachedInfo>&>(*child.m_DetachedInfo));
1727  child.m_DetachedInfo.Reset();
1728  infos->GetData().push_back
1730  Ref(&child)));
1731 
1732  ITERATE ( TDetachedInfo, it, infos->GetData() ) {
1733  _TRACE(" "<<it->second<<" " << it->first);
1734  CScopeInfo_Base& info = it->second.GetNCObject();
1735  if ( info.m_LockCounter.Get() > 0 ) {
1736  info.x_AttachTSE(this);
1738  (TScopeInfoMap::value_type(it->first, it->second)).second);
1739  info.m_TSE_Handle = parent.m_TSE_Handle;
1740  }
1741  }
1742  _ASSERT(child.IsAttached());
1743  _ASSERT(child.m_TSE_Handle.m_TSE);
1744  _ASSERT(child.HasObject());
1745 }
1746 
1747 
1749 {
1750  return GetDSInfo().Resolve(id, *this);
1751 }
1752 
1753 
1754 /////////////////////////////////////////////////////////////////////////////
1755 // CBioseq_ScopeInfo
1756 /////////////////////////////////////////////////////////////////////////////
1757 
1758 // If this define will be uncomented then it must be changed to use ERR_POST_X
1759 //#define BIOSEQ_TRACE(x) ERR_POST(x)
1760 #ifndef BIOSEQ_TRACE
1761 # define BIOSEQ_TRACE(x)
1762 #endif
1763 
1765  : m_BlobState(flags | CBioseq_Handle::fState_no_data),
1766  m_UnresolvedTimestamp(timestamp)
1767 {
1768  BIOSEQ_TRACE("CBioseq_ScopeInfo: "<<this);
1769 }
1770 
1771 
1773  : m_BlobState(CBioseq_Handle::fState_none),
1774  m_UnresolvedTimestamp(0)
1775 {
1776  BIOSEQ_TRACE("CBioseq_ScopeInfo: "<<this);
1777  x_AttachTSE(&tse);
1778 }
1779 
1780 
1782  const TIds& ids)
1783  : m_Ids(ids),
1784  m_BlobState(CBioseq_Handle::fState_none),
1785  m_UnresolvedTimestamp(0)
1786 {
1787  BIOSEQ_TRACE("CBioseq_ScopeInfo: "<<this);
1788  x_AttachTSE(&tse);
1789 }
1790 
1791 
1793 {
1794  if ( IsAttached() ) {
1795  BIOSEQ_TRACE("~CBioseq_ScopeInfo: "<<this<<
1796  " TSE "<<&x_GetTSE_ScopeInfo());
1797  }
1798  else {
1799  BIOSEQ_TRACE("~CBioseq_ScopeInfo: "<<this);
1800  }
1801  _ASSERT(!IsAttached());
1802 }
1803 
1804 
1806 {
1807  _ASSERT(!HasBioseq());
1809  m_UnresolvedTimestamp = timestamp;
1810 }
1811 
1812 
1814  const TIds& ids)
1815 {
1816  _ASSERT(!HasBioseq());
1817  m_Ids = ids;
1820  x_AttachTSE(&tse);
1821 }
1822 
1823 
1825 {
1826  const TIds& ids = GetIds();
1827  return ids.empty()? 0: &ids;
1828 }
1829 
1830 
1832 {
1833  return (GetBlobState() & CBioseq_Handle::fState_no_data) == 0;
1834 }
1835 
1836 
1839 {
1840  return x_GetTSE_ScopeInfo().GetBioseqLock(Ref(this), bioseq);
1841 }
1842 
1843 
1845 {
1846  BIOSEQ_TRACE("CBioseq_ScopeInfo: "<<this<<" x_AttachTSE "<<tse);
1847  m_BlobState = tse->GetTSE_Lock()->GetBlobState();
1849  ITERATE ( TIds, it, GetIds() ) {
1850  tse->x_IndexBioseq(*it, this);
1851  }
1852 }
1853 
1855 {
1856  BIOSEQ_TRACE("CBioseq_ScopeInfo: "<<this<<" x_DetachTSE "<<tse);
1857  m_SynCache.Reset();
1858  m_BioseqAnnotRef_Info.Reset();
1859  ITERATE ( TIds, it, GetIds() ) {
1860  tse->x_UnindexBioseq(*it, this);
1861  }
1863  BIOSEQ_TRACE("CBioseq_ScopeInfo: "<<this<<" x_DetachTSE "<<tse<<" DONE");
1864 }
1865 
1866 
1868 {
1869  BIOSEQ_TRACE("CBioseq_ScopeInfo: "<<this<<" x_ForgetTSE "<<tse);
1870  m_SynCache.Reset();
1871  m_BioseqAnnotRef_Info.Reset();
1873  BIOSEQ_TRACE("CBioseq_ScopeInfo: "<<this<<" x_ForgetTSE "<<tse<<" DONE");
1874 }
1875 
1876 
1878 {
1879  CNcbiOstrstream os;
1880  const TIds& ids = GetIds();
1881  ITERATE ( TIds, it, ids ) {
1882  if ( it != ids.begin() )
1883  os << " | ";
1884  os << it->AsString();
1885  }
1886  return CNcbiOstrstreamToString(os);
1887 }
1888 
1889 
1891 {
1892  _ASSERT(HasObject());
1893  const_cast<CBioseq_Info&>(GetObjectInfo()).ResetId();
1895  ITERATE ( TIds, it, GetIds() ) {
1896  x_GetTSE_ScopeInfo().x_UnindexBioseq(*it, this);
1897  }
1898  m_Ids.clear();
1899 }
1900 
1901 
1903 {
1904  _ASSERT(HasObject());
1905  CBioseq_Info& info = const_cast<CBioseq_Info&>(GetObjectInfo());
1906  if ( !info.AddId(id) ) {
1907  return false;
1908  }
1909  m_Ids.push_back(id);
1910  x_GetTSE_ScopeInfo().x_IndexBioseq(id, this);
1912  return true;
1913 }
1914 
1915 
1917 {
1918  _ASSERT(HasObject());
1919  if ( !const_cast<CBioseq_Info&>(GetObjectInfo()).RemoveId(id) ) {
1920  return false;
1921  }
1922  TIds::iterator it = find(m_Ids.begin(), m_Ids.end(), id);
1923  _ASSERT(it != m_Ids.end());
1925  x_GetTSE_ScopeInfo().x_UnindexBioseq(id, this);
1926  m_Ids.erase(it);
1927  return true;
1928 }
1929 
1930 
1931 /////////////////////////////////////////////////////////////////////////////
1932 // SSeq_id_ScopeInfo
1933 /////////////////////////////////////////////////////////////////////////////
1934 
1936 {
1937 }
1938 
1940 {
1941 }
1942 
1943 /////////////////////////////////////////////////////////////////////////////
1944 // CSynonymsSet
1945 /////////////////////////////////////////////////////////////////////////////
1946 
1948 {
1949 }
1950 
1951 
1953 {
1954 }
1955 
1956 
1958 {
1959  return *iter;
1960 }
1961 
1962 
1964 {
1965  ITERATE ( TIdSet, iter, m_IdSet ) {
1966  if ( *iter == id ) {
1967  return true;
1968  }
1969  }
1970  return false;
1971 }
1972 
1973 
1975 {
1976  _ASSERT(!ContainsSynonym(id));
1977  m_IdSet.push_back(id);
1978 }
1979 
1980 
TTSE_InfoMapMutex m_TSE_InfoMapMutex
Definition: scope_info.hpp:314
void Reset(void)
Reset the handle (remove seq-id reference)
CBioseq_Handle –.
const TObjectInfo & GetObjectInfo(void) const
CRef< CObject > m_DetachedInfo
Definition: tse_handle.hpp:489
TScopeInfoMap m_ScopeInfoMap
Definition: scope_info.hpp:492
CSynonymsSet(void)
void x_UnindexBioseq(const CSeq_id_Handle &id, const CBioseq_ScopeInfo *info)
bool ContainsBioseq(const CSeq_id_Handle &id) const
const_iterator lower_bound(const key_type &key) const
Definition: map.hpp:154
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:783
void GetMatchingHandles(TMatches &matches) const
void SetEditTSE(const CTSE_Lock &new_tse_lock, CDataSource_ScopeInfo &new_ds)
CConstRef –.
Definition: ncbiobj.hpp:1192
size_type size() const
Definition: map.hpp:148
#define BIOSEQ_TRACE(x)
CScope_Impl & x_GetScopeImpl(void) const
Definition: tse_handle.cpp:417
CBioseq_Info & GetNCObjectInfo(void)
Definition: scope_info.hpp:528
Definition: dbpivot.c:60
bool AddId(const CSeq_id_Handle &id)
void AddEntry(CBioseq_set_ScopeInfo &seqset, CSeq_entry_ScopeInfo &info, int index)
CRef< CBioseq_ScopeInfo > x_FindBioseqInfo(const TSeqIds &ids) const
CSafeStatic<>::
bool LockedMoreThanOnce(void) const
TBlobOrder GetBlobOrder(void) const
Definition: tse_info.hpp:827
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:1849
const CBioseq_Info & GetObjectInfo(void) const
Definition: scope_info.hpp:524
void x_ForgetTSE(CTSE_ScopeInfo *tse)
virtual void x_DetachTSE(CTSE_ScopeInfo *tse)
Definition: tse_handle.cpp:510
bool empty() const
Definition: map.hpp:289
void ForgetTSELock(CTSE_ScopeInfo &tse)
Definition: scope_info.cpp:424
virtual void x_ForgetTSE(CTSE_ScopeInfo *tse)
Definition: tse_handle.cpp:522
void GetBlobs(TSeqMatchMap &match_map)
void AttachTSE(CTSE_ScopeInfo &tse, const CTSE_Lock &lock)
Definition: scope_info.cpp:314
void ReleaseTSELock(CTSE_ScopeInfo &tse)
Definition: scope_info.cpp:400
bool AddId(const CSeq_id_Handle &id)
static DECLARE_TLS_VAR(CUnlockedTSEsGuard *, st_Guard)
vector< CSeq_id_Handle > TSeqIds
Definition: scope_info.hpp:351
TSeq_feat_Lock FindSeq_feat_Lock(const CSeq_id_Handle &loc_id, TSeqPos loc_pos, const CSeq_feat &feat)
Definition: scope_info.cpp:614
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:73
auto_ptr< SBaseTSE > m_BaseTSE
Definition: tse_info.hpp:714
void swap(this_type &m)
Definition: map.hpp:118
bool RemoveId(const CSeq_id_Handle &id)
const struct ncbi::grid::netcache::search::fields::KEY key
pair< CConstRef< CSeq_annot_Info >, TTSE_Lock > TSeq_annot_Lock
Definition: scope_info.hpp:261
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:836
vector< SSeqMatch_DS > TSeqMatches
CScopeInfo_Ref< CBioseq_ScopeInfo > TBioseq_Lock
Definition: scope_info.hpp:402
void x_DetachDS(void)
bool TSEIsReplaced(const TBlobId &blob_id) const
Definition: scope_info.cpp:809
void clear()
Definition: map.hpp:169
CScopeInfo_Ref< CBioseq_ScopeInfo > TBioseq_Lock
Definition: scope_info.hpp:263
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1336
const TSet & GetSet(void) const
bool HasBioseq(void) const
friend class CTSE_ScopeInfo
Definition: scope_info.hpp:289
vector< TDetachedInfoElement > TDetachedInfo
const_iterator begin() const
Definition: map.hpp:291
const CTSE_Info_Object & GetObjectInfo_Base(void) const
Definition: tse_handle.hpp:348
TObjectType * GetNCPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1146
TSet & SelectSet(void)
pair< CConstRef< CSeq_entry_Info >, TTSE_Lock > TSeq_entry_Lock
Definition: scope_info.hpp:260
CMutex m_TSE_LockMutex
Definition: scope_info.hpp:484
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
Definition: ncbicntr.hpp:254
container_type::const_iterator const_iterator
Definition: map.hpp:53
bool ContainsSynonym(const CSeq_id_Handle &id) const
void RemoveTSE_Lock(const CTSE_Lock &lock)
Definition: scope_info.cpp:254
CScope_Impl & GetScopeImpl(void) const
Definition: scope_info.cpp:128
CSeq_id_Handle ContainsMatchingBioseq(const CSeq_id_Handle &id) const
Definition: tse_info.cpp:711
CAtomicCounter_WithAutoInit m_TSE_LockCounter
CTSE_ScopeInfo(CDataSource_ScopeInfo &ds_info, const CTSE_Lock &tse_lock, int load_index, bool can_be_unloaded)
Definition: scope_info.cpp:843
AutoPtr< SUnloadedInfo > m_UnloadedInfo
Definition: scope_info.hpp:481
void x_InternalUnlockTSE(void)
Definition: scope_info.cpp:945
TBioseq_Lock FindBioseq_Lock(const CBioseq &bioseq)
Definition: scope_info.cpp:599
CTSE_Lock m_TSE_Lock
static bool x_IsBetter(const CSeq_id_Handle &idh, const CTSE_ScopeInfo &tse1, const CTSE_ScopeInfo &tse2)
Definition: scope_info.cpp:720
static void SaveInternal(const CTSE_ScopeInternalLock &lock)
Definition: scope_info.cpp:229
bool IsConst(void) const
Definition: scope_info.cpp:144
pair< TSeq_annot_Lock, int > TSeq_feat_Lock
Definition: scope_info.hpp:264
set< TBlobId > m_ReplacedTSEs
Definition: scope_info.hpp:321
SSeqMatch_DS BestResolve(const CSeq_id_Handle &idh)
SSeqMatch_Scope Resolve(const CSeq_id_Handle &idh, CTSE_ScopeInfo &tse)
Definition: scope_info.cpp:656
void RemoveFromHistory(int action_if_locked, bool drop_from_ds=false)
void DropTSE_Lock(void)
void RemoveAnnot(CSeq_annot_ScopeInfo &info)
void Clear(TUnlockSet *unlock_set=0)
Definition: scope_info.hpp:180
void x_ClearCacheOnRemoveSeqId(const CSeq_id_Handle &id, CBioseq_ScopeInfo &seq)
TSeq_annot_Lock FindSeq_annot_Lock(const CSeq_annot &annot, const TTSE_LockSet &history) const
TTSE_Lock GetTSE_Lock(const CTSE_Lock &tse)
Definition: scope_info.cpp:270
CRef< CTSE_ScopeInfo, CTSE_ScopeInternalLocker > CTSE_ScopeInternalLock
const TSeq & GetSeq(void) const
vector< TIndexId > TIndexIds
Definition: tse_handle.hpp:317
CScope_Impl * m_Scope
Definition: scope_info.hpp:307
void RestoreReplacedTSE(void)
bool IsDetached(void) const
Definition: tse_handle.hpp:303
const_iterator end() const
Definition: map.hpp:292
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1343
void swap(this_type &m)
Definition: map.hpp:258
TBioseq_Lock FindBioseq_Lock(const CBioseq &bioseq, const TTSE_LockSet &history) const
bool IsAttached(void) const
Definition: scope_info.hpp:679
CInitMutex< SAnnotSetCache > m_BioseqAnnotRef_Info
Definition: scope_info.hpp:582
void RemoveEntry(CSeq_entry_ScopeInfo &info)
CConstRef< CBioseq_Info > m_Bioseq
Definition: tse_info.hpp:135
void RemoveAnnot(CRef< CSeq_annot_Info > annot)
TUnlockedTSEsInternal m_UnlockedTSEsInternal
Definition: scope_info.hpp:342
CCoreException –.
Definition: ncbiexpt.hpp:1292
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:776
#define _VERIFY(expr)
Definition: ncbidbg.hpp:159
const TIds & GetIds(void) const
Definition: scope_info.hpp:533
void UpdateTSELock(CTSE_ScopeInfo &tse, CTSE_Lock lock)
Definition: scope_info.cpp:373
TSeq_entry_Lock GetScopeLock(const CTSE_Handle &tse, const CSeq_entry_Info &info)
CRef< CDataSource_ScopeInfo > m_EditDS
Definition: scope_info.hpp:320
TTSE_BySeqId m_TSE_BySeqId
Definition: scope_info.hpp:315
Search bioseq, load if not loaded yet.
Definition: scope.hpp:127
void AddTSE_Lock(const CTSE_Lock &lock)
Definition: scope_info.cpp:262
TSeq_entry_Lock GetSeq_entry_Lock(const CBlobIdKey &blob_id)
Definition: scope_info.cpp:539
void clear()
Definition: map.hpp:309
void x_UnindexTSE(const CTSE_ScopeInfo &tse)
Definition: scope_info.cpp:343
TBlobOrder GetBlobOrder(void) const
Definition: scope_info.cpp:882
CTSE_Handle m_TSE_Handle
Definition: tse_handle.hpp:487
TTSE_InfoMap m_TSE_InfoMap
Definition: scope_info.hpp:313
const TSeqIds & GetBioseqsIds(void) const
Definition: scope_info.cpp:912
const TTSE_InfoMap & GetTSE_InfoMap(void) const
Definition: scope_info.cpp:181
TValue Get(void) const THROWS_NONE
Get atomic counter value.
Definition: ncbicntr.hpp:161
TSeqMatches GetMatches(const CSeq_id_Handle &idh, const TTSE_LockSet &locks)
void x_LockTSE(void)
Definition: scope_info.cpp:919
CDataSource_ScopeInfo * m_DS_Info
Definition: scope_info.hpp:469
void x_DetachTSE(CTSE_ScopeInfo *tse)
void GetBlobs(TSeqMatchMap &match_map)
Definition: scope_info.cpp:774
TBioseq_Lock GetBioseqLock(CRef< CBioseq_ScopeInfo > info, CConstRef< CBioseq_Info > bioseq)
void RemoveFromHistory(CTSE_ScopeInfo &tse, bool drop_from_ds=false)
Definition: scope_info.cpp:490
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
iterator insert(const value_type &val)
Definition: map.hpp:305
vector< CTSE_ScopeInternalLock > TUnlockedTSEsInternal
Definition: scope_info.hpp:332
TIdSet::const_iterator const_iterator
Definition: synonyms.hpp:59
const CTSE_Info & GetTSE_Info(void) const
void ResetId(void)
TBlobStateFlags m_BlobState
Definition: scope_info.hpp:574
const TBlobId & GetBlobId(void) const
Definition: tse_info.hpp:850
CDataSource & GetDataSource(void) const
Definition: tse_info.hpp:748
const_iterator end() const
Definition: map.hpp:152
void x_AttachTSE(CTSE_ScopeInfo *tse)
CScopeInfo_Ref< CSeq_entry_ScopeInfo > TSeq_entry_Lock
Definition: scope_info.hpp:399
pair< CConstRef< CSeq_annot_Info >, TTSE_Lock > TSeq_annot_Lock
void ResetTSE_Lock(void)
#define _TRACE_TSE_LOCK(x)
Definition: scope_info.cpp:62
CBioseq_ScopeInfo(TBlobStateFlags flag, int timestamp)
static CSeq_id_Handle GetSeq_id_Handle(const const_iterator &iter)
bool AddLock(const CTSE_Lock &lock)
TObjectInfo & GetNCObjectInfo(void)
void Reset(void)
Definition: tse_lock.hpp:108
const_iterator find(const key_type &key) const
Definition: map.hpp:153
TBioseq_set_Lock FindBioseq_set_Lock(const CBioseq_set &seqset, const TTSE_LockSet &history) const
TTSE_LockSet m_TSE_LockSet
Definition: scope_info.hpp:316
bool CanBeEdited(void) const
Definition: scope_info.hpp:701
void SetTSE_Lock(const CTSE_Lock &lock)
CTSE_ScopeUserLock m_TSE_Lock
Definition: scope_impl.hpp:124
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:185
CRef< CObjectManager > m_ObjMgr
Definition: scope_impl.hpp:605
CRef< CTSE_ScopeInfo, CTSE_ScopeUserLocker > CTSE_ScopeUserLock
CBlobIdKey TBlobId
Definition: scope_info.hpp:349
CConstRef< CBioseq_Info > FindBioseq(const CSeq_id_Handle &id) const
Definition: tse_info.cpp:731
CInitMutex< CSynonymsSet > m_SynCache
Definition: scope_info.hpp:580
CSeq_id_Handle m_Seq_id
Definition: tse_info.hpp:134
SSeqMatch_Scope Resolve(const CSeq_id_Handle &id)
TSeq_feat_Lock FindSeq_feat_Lock(const CSeq_id_Handle &loc_id, TSeqPos loc_pos, const CSeq_feat &feat) const
virtual void GetBioseqsIds(TSeqIds &ids) const
Definition: tse_info.cpp:662
bool HasParent_Info(void) const
void x_UserUnlockTSE(void)
Definition: scope_info.cpp:935
SSeqMatch_Scope x_FindBestTSE(const CSeq_id_Handle &idh)
Definition: scope_info.cpp:685
bool HaveMatchingHandles(void) const
volatile int m_UnresolvedTimestamp
Definition: scope_info.hpp:577
bool Contains(const key_type &key) const
Definition: scope_info.hpp:104
CScopeInfo_Ref< CSeq_annot_ScopeInfo > TSeq_annot_Lock
Definition: scope_info.hpp:400
friend class CBioseq_ScopeInfo
Definition: scope_info.hpp:463
void ResetEntry(CSeq_entry_ScopeInfo &info)
void SetResolved(CTSE_ScopeInfo &tse, const TIds &ids)
void ReleaseUsedTSEs(void)
Definition: scope_info.cpp:961
static int match(register const unsigned char *eptr, register const uschar *ecode, const unsigned char *mstart, int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, int flags, unsigned int rdepth)
Definition: pcre_exec.c:431
const TIndexIds * GetIndexIds(void) const
TBioseq_Lock GetLock(CConstRef< CBioseq_Info > bioseq)
bool empty() const
Definition: map.hpp:149
void Reset(void)
Definition: mutex_pool.hpp:144
const_iterator find(const key_type &key) const
Definition: map.hpp:293
const TTSE_LockSet & GetTSE_LockSet(void) const
Definition: scope_info.cpp:188
TBlobId GetBlobId(void) const
Definition: scope_info.cpp:899
static bool s_GetScopeAutoReleaseEnabled(void)
Definition: scope_info.cpp:70
CDataLoader * GetDataLoader(void) const
TTSE_ScopeInfo x_FindBestTSEInIndex(const CSeq_id_Handle &idh) const
Definition: scope_info.cpp:360
int GetLoadIndex(void) const
Definition: scope_info.hpp:672
TSeq & SelectSeq(TSeq &seq)
bool IsAttached(void) const
Definition: tse_handle.hpp:307
const CTSE_Handle & GetTSE_Handle(void) const
Definition: tse_handle.hpp:341
void SelectSeq(CSeq_entry_ScopeInfo &entry, CBioseq_ScopeInfo &info)
void x_RestoreAdded(CScopeInfo_Base &parent, CScopeInfo_Base &child)
bool TSEIsInQueue(const CTSE_ScopeInfo &tse) const
Definition: scope_info.cpp:802
int x_GetDSLocksCount(void) const
const_iterator lower_bound(const key_type &key) const
Definition: map.hpp:294
SSeqMatch_Scope BestResolve(const CSeq_id_Handle &idh, int get_flag)
Definition: scope_info.cpp:633
static unsigned s_GetScopeAutoReleaseSize(void)
Definition: scope_info.cpp:81
virtual void x_SetLock(const CTSE_ScopeUserLock &tse, const CTSE_Info_Object &info)
Definition: tse_handle.cpp:464
CAtomicCounter_WithAutoInit m_LockCounter
Definition: tse_handle.hpp:484
bool HasObject(void) const
Definition: tse_handle.hpp:311
pair< int, int > TBlobOrder
Definition: scope_info.hpp:352
TTSE_InfoMapMutex & GetTSE_InfoMapMutex(void) const
Definition: scope_info.hpp:639
char value[7]
Definition: config.c:428
Base class for all object manager exceptions.
void Reset(void)
void Swap(CTSE_Lock &lock)
NCBI_PARAM_DECL(bool, OBJMGR, SCOPE_AUTORELEASE)
const CTSE_Info & x_GetTSE_Info(void) const
Definition: tse_handle.cpp:115
void x_SaveRemoved(CScopeInfo_Base &info)
const CBioseq_set_Info & GetParentBioseq_set_Info(void) const
bool IsLocked(void) const
vector< value_type > TIdSet
Definition: synonyms.hpp:58
void ReleaseDataSource(TDataSourceLock &data_source)
TBioseqById m_BioseqById
Definition: scope_info.hpp:482
NCBI_PARAM_DEF_EX(bool, OBJMGR, SCOPE_AUTORELEASE, true, eParam_NoThread, OBJMGR_SCOPE_AUTORELEASE)
void SelectSet(CSeq_entry_ScopeInfo &entry, CBioseq_set_ScopeInfo &info)
TTSE_LockSetMutex m_TSE_UnlockQueueMutex
Definition: scope_info.hpp:319
CTSE_ScopeUserLock m_TSE
Definition: tse_handle.hpp:209
bool RemoveLock(const CTSE_Lock &lock)
~CSynonymsSet(void)
TUsedTSE_LockSet m_UsedTSE_Set
Definition: scope_info.hpp:488
void erase(iterator pos)
Definition: map.hpp:307
TTSE_Lock FindTSE_Lock(const CSeq_entry &entry, const TTSE_LockSet &history) const
TBlobState GetBlobState(void) const
Definition: tse_info.hpp:777
void ResetHistory(int action_if_locked)
Definition: scope_info.cpp:467
bool AddUsedTSE(const CTSE_ScopeUserLock &lock) const
Definition: scope_info.cpp:974
void Reset(void)
Reset to null state.
Definition: tse_handle.cpp:105
CRef –.
Definition: ncbiobj.hpp:616
DEFINE_STATIC_FAST_MUTEX(sx_UsedTSEMutex)
No variant selected.
Definition: Seq_entry_.hpp:88
CObjectFor –.
Definition: ncbiobj.hpp:2023
Definition: Seq_entry.hpp:55
void erase(iterator pos)
Definition: map.hpp:167
CSeq_id_Handle ContainsMatchingBioseq(const CSeq_id_Handle &id) const
pair< CConstRef< CTSE_Info_Object >, CRef< CScopeInfo_Base > > TDetachedInfoElement
void ReplaceTSE(const CTSE_Info &old_tse)
void AddAnnot(CSeq_entry_ScopeInfo &entry, CSeq_annot_ScopeInfo &info)
static CRef< CScope > m_Scope
virtual string GetDescription(void) const
Definition: tse_info.cpp:1968
void AddSynonym(const value_type &syn)
CDataSource & GetDataSource(void)
Definition: scope_info.hpp:624
pair< CConstRef< CSeq_entry_Info >, TTSE_Lock > TSeq_entry_Lock
bool ContainsBioseq(const CSeq_id_Handle &id) const
Definition: tse_info.cpp:695
void SetUnresolved(TBlobStateFlags flag, int timestamp)
TObjectInfo & GetNCObjectInfo(void)
CDataSource_ScopeInfo & GetDSInfo(void) const
Definition: scope_info.hpp:693
const CTSE_ScopeInfo * m_UsedByTSE
Definition: scope_info.hpp:487
CTSE_ScopeInfo & x_GetTSE_ScopeInfo(void) const
Definition: tse_handle.hpp:334
void x_IndexBioseq(const CSeq_id_Handle &id, CBioseq_ScopeInfo *info)
void x_SetTSE_Lock(const CTSE_Lock &lock)
Do not use per-thread values.
Definition: ncbi_param.hpp:475
static int s_GetScopePostponeDelete(void)
Definition: scope_info.cpp:92
void x_IndexTSE(CTSE_ScopeInfo &tse)
Definition: scope_info.cpp:335
TBioseq_set_Lock FindBioseq_set_Lock(const CBioseq_set &seqset)
Definition: scope_info.cpp:584
SUnloadedInfo(const CTSE_Lock &lock)
Definition: scope_info.cpp:823
bool CanBeEdited(void) const
CTSE_ScopeUserLock TTSE_Lock
Definition: scope_info.hpp:259
IO_PREFIX::ostrstream CNcbiOstrstream
Portable alias for ostrstream.
Definition: ncbistre.hpp:155
CRef< CBioseq_ScopeInfo > GetBioseqInfo(const SSeqMatch_Scope &match)
virtual void x_AttachTSE(CTSE_ScopeInfo *tse)
Definition: tse_handle.cpp:499
#define _ASSERT
bool DropStaticTSE(CTSE_Info &info)
const CBioseq_Base_Info & GetParentBioseq_Base_Info(void) const
pair< TSeq_annot_Lock, int > TSeq_feat_Lock
SSeqMatch_Scope x_GetSeqMatch(const CSeq_id_Handle &idh)
Definition: scope_info.cpp:665
void x_CheckAdded(CScopeInfo_Base &parent, CScopeInfo_Base &child)
vector< CSeq_id_Handle > TId
Definition: bioseq_info.hpp:91
namespace ncbi::objects::
Definition: Seq_feat.hpp:56
bool IsBetter(const CSeq_id_Handle &h) const
True if "this" is a better bioseq than "h".
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:70
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string...
Definition: ncbiexpt.hpp:546
void x_SetMatch(SSeqMatch_Scope &match, CTSE_ScopeInfo &tse, const CSeq_id_Handle &idh) const
Definition: scope_info.cpp:742
CRef< CSeq_entry_Info > AddEntry(CSeq_entry &entry, int index, bool set_uniqid=false)
void clear(void)
void x_ResetTSE_Lock(void)
bool BelongsToTSE_Info(const CTSE_Info &tse) const
void SetCanRemoveOnResetHistory(void)
Definition: scope_info.cpp:159
CConstRef< C > ConstRef(const C *object)
Template function for conversion of const object pointer to CConstRef.
Definition: ncbiobj.hpp:1858
TDataSourceLock m_DataSource
Definition: scope_info.hpp:308
void Reset(void)
Definition: tse_handle.hpp:553
CTSE_Lock m_TSE_Lock
Definition: scope_info.hpp:485
bool CanBeUnloaded(void) const
Definition: scope_info.hpp:686
pair< CConstRef< CBioseq_set_Info >, TTSE_Lock > TBioseq_set_Lock
static void SaveLock(const CTSE_Lock &lock)
Definition: scope_info.cpp:217
const_iterator begin() const
Definition: map.hpp:151
bool HasResolvedBioseq(const CSeq_id_Handle &id) const
~CTSE_ScopeInfo(void)
Definition: scope_info.cpp:866
pair< CConstRef< CBioseq_set_Info >, TTSE_Lock > TBioseq_set_Lock
Definition: scope_info.hpp:262
TSeq_entry_Lock FindSeq_entry_Lock(const CSeq_entry &entry)
Definition: scope_info.cpp:554
void Erase(const key_type &key)
Definition: scope_info.hpp:125
TTSE_UnlockQueue m_TSE_UnlockQueue
Definition: scope_info.hpp:318
E_Choice Which(void) const
CDataSource_ScopeInfo(CScope_Impl &scope, CDataSource &ds)
Definition: scope_info.cpp:106
bool x_SameTSE(const CTSE_Info &tse) const
Definition: scope_info.cpp:955
const CTSE_Lock & GetTSE_Lock(void) const
Definition: scope_info.hpp:715
const TId & GetId(void) const
CDataLoader * GetDataLoader(void)
Definition: scope_info.cpp:138
void RemoveEntry(CRef< CSeq_entry_Info > entry)
TSeq_entry_Lock GetSeq_entry_Lock(const CBlobIdKey &blob_id)
bool CanRemoveOnResetHistory(void) const
Definition: scope_info.hpp:660
#define _TRACE(message)
Definition: ncbidbg.hpp:120
TIdSet m_IdSet
Definition: synonyms.hpp:78
TTSE_LockSetMutex m_TSE_LockSetMutex
Definition: scope_info.hpp:317
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
void ForgetTSE_Lock(void)
string IdString(void) const
TBlobStateFlags GetBlobState(void) const
Definition: scope_info.hpp:547
CRef< CDataSource > m_Source
Definition: scope_info.hpp:475
bool CanBeEdited(void) const
Definition: scope_info.hpp:653
CRef< CSeq_annot_Info > AddAnnot(CSeq_annot &annot)
unsigned int
Definition: types.hpp:1153
TSeq_entry_Lock FindSeq_entry_Lock(const CSeq_entry &entry, const TTSE_LockSet &history) const
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:756
T & Get(void)
Create the variable if not created yet, return the reference.
TSeq_annot_Lock FindSeq_annot_Lock(const CSeq_annot &annot)
Definition: scope_info.cpp:569
CRef< CBioseq_ScopeInfo > x_CreateBioseqInfo(const TSeqIds &ids)
void RemoveLastInfoLock(CScopeInfo_Base &info)
void Put(const key_type &key, const value_type &value, value_type *unlock_ptr)
Definition: scope_info.hpp:135
void x_ClearCacheOnNewData(const TIds &seq_ids, const TIds &annot_ids)
Definition: scope_impl.cpp:936
TObjectInfo & GetNCObjectInfo(void)
CScopeInfo_Ref< CBioseq_set_ScopeInfo > TBioseq_set_Lock
Definition: scope_info.hpp:401
pair< CConstRef< CBioseq_Info >, TTSE_Lock > TBioseq_Lock
TTSE_Lock FindTSE_Lock(const CSeq_entry &tse)
Definition: scope_info.cpp:524
TBlobId m_ReplacedTSE
Definition: scope_info.hpp:490
Modified on Wed May 24 16:19:40 2017 by modify_doxy.py rev. 533848