NCBI C++ ToolKit
gbnative.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GBNATIVE__HPP_INCLUDED
2 #define GBNATIVE__HPP_INCLUDED
3 
4 /* $Id: gbnative.hpp 102228 2024-04-09 17:35:06Z vasilche $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Aleksey Grichenko, Michael Kimelman, Eugene Vasilchenko,
30 * Anton Butanayev
31 *
32 * File Description:
33 * Data loader base class for object manager
34 *
35 * ===========================================================================
36 */
37 
38 #include <corelib/ncbistd.hpp>
39 #include <corelib/ncbimtx.hpp>
41 #include <corelib/ncbi_param.hpp>
42 
43 #if !defined(NDEBUG) && defined(DEBUG_SYNC)
44 // for GBLOG_POST()
45 # include <corelib/ncbithr.hpp>
46 #endif
47 
48 #include <objmgr/data_loader.hpp>
49 
50 #include <util/mutex_pool.hpp>
51 
56 
57 #include <util/cache/icache.hpp>
58 
60 
62 
63 class CReadDispatcher;
64 class CReader;
65 class CWriter;
66 class CSeqref;
67 class CBlob_id;
68 class CHandleRange;
69 class CSeq_entry;
70 class CLoadInfoBlob;
71 
72 #if !defined(NDEBUG) && defined(DEBUG_SYNC)
73 # if defined(NCBI_THREADS)
74 # define GBLOG_POST(x) LOG_POST(setw(3) << CThread::GetSelf() << ":: " << x)
75 # define GBLOG_POST_X(err_subcode, x) \
76  LOG_POST_X(err_subcode, setw(3) << CThread::GetSelf() << ":: " << x)
77 # else
78 # define GBLOG_POST(x) LOG_POST("0:: " << x)
79 # define GBLOG_POST_X(err_subcode, x) LOG_POST_X(err_subcode, "0:: " << x)
80 # endif
81 #else
82 # ifdef DEBUG_SYNC
83 # undef DEBUG_SYNC
84 # endif
85 # define GBLOG_POST(x)
86 # define GBLOG_POST_X(err_subcode, x)
87 #endif
88 
89 /////////////////////////////////////////////////////////////////////////////////
90 //
91 // GBDataLoader_Native
92 //
93 
95 class CGBInfoManager;
96 
97 
99 {
100 public:
102 
103  virtual void RegisterCache(ICache& cache, ECacheType cache_type);
104  virtual TCaches& GetCaches(void) { return m_Caches; }
105  virtual ICache* FindCache(ECacheType cache_type,
106  const TCacheParams* params);
107 private:
109 };
110 
111 
113 {
114 public:
115  // typedefs from CReader
116  typedef unsigned TConn;
119 
120  virtual ~CGBDataLoader_Native(void);
121 
122  virtual void DropTSE(CRef<CTSE_Info> tse_info) override;
123 
124  virtual void GetIds(const CSeq_id_Handle& idh, TIds& ids) override;
125  virtual SAccVerFound GetAccVerFound(const CSeq_id_Handle& idh) override;
126  virtual SGiFound GetGiFound(const CSeq_id_Handle& idh) override;
127  virtual string GetLabel(const CSeq_id_Handle& idh) override;
128  virtual TTaxId GetTaxId(const CSeq_id_Handle& idh) override;
129  virtual int GetSequenceState(const CSeq_id_Handle& idh) override;
130  virtual SHashFound GetSequenceHashFound(const CSeq_id_Handle& idh) override;
131  virtual TSeqPos GetSequenceLength(const CSeq_id_Handle& sih) override;
132  virtual STypeFound GetSequenceTypeFound(const CSeq_id_Handle& sih) override;
133 
134  virtual void GetBulkIds(const TIds& ids, TLoaded& loader, TBulkIds& ret) override;
135  virtual void GetAccVers(const TIds& ids, TLoaded& loader, TIds& ret) override;
136  virtual void GetGis(const TIds& ids, TLoaded& loader, TGis& ret) override;
137  virtual void GetLabels(const TIds& ids, TLoaded& loader, TLabels& ret) override;
138  virtual void GetTaxIds(const TIds& ids, TLoaded& loader, TTaxIds& ret) override;
139  virtual void GetSequenceStates(const TIds& ids, TLoaded& loader,
140  TSequenceStates& ret) override;
141  virtual void GetSequenceHashes(const TIds& ids, TLoaded& loader,
142  TSequenceHashes& ret, THashKnown& known) override;
143  virtual void GetSequenceLengths(const TIds& ids, TLoaded& loader,
144  TSequenceLengths& ret) override;
145  virtual void GetSequenceTypes(const TIds& ids, TLoaded& loader,
146  TSequenceTypes& ret) override;
147 
148  virtual TTSE_LockSet GetRecords(const CSeq_id_Handle& idh,
149  EChoice choice) override;
150  virtual TTSE_LockSet GetDetailedRecords(const CSeq_id_Handle& idh,
151  const SRequestDetails& details) override;
152  virtual TTSE_LockSet GetExternalRecords(const CBioseq_Info& bioseq) override;
153  virtual TTSE_LockSet GetExternalAnnotRecordsNA(const CSeq_id_Handle& idh,
154  const SAnnotSelector* sel,
155  TProcessedNAs* processed_nas) override;
156  virtual TTSE_LockSet GetExternalAnnotRecordsNA(const CBioseq_Info& bioseq,
157  const SAnnotSelector* sel,
158  TProcessedNAs* processed_nas) override;
159  virtual TTSE_LockSet GetOrphanAnnotRecordsNA(const CSeq_id_Handle& idh,
160  const SAnnotSelector* sel,
161  TProcessedNAs* processed_nas) override;
162 
163  virtual void GetChunk(TChunk chunk) override;
164  virtual void GetChunks(const TChunkSet& chunks) override;
165 
166  virtual void GetBlobs(TTSE_LockSets& tse_sets) override;
167 
168  virtual void GetCDDAnnots(const TSeqIdSets& id_sets, TLoaded& loaded, TCDD_Locks& ret) override;
169 
170  virtual TBlobId GetBlobId(const CSeq_id_Handle& idh) override;
171  virtual TBlobId GetBlobIdFromString(const string& str) const override;
172 
173  virtual TBlobVersion GetBlobVersion(const TBlobId& id) override;
174  virtual bool CanGetBlobById(void) const override;
175  virtual TTSE_Lock GetBlobById(const TBlobId& id) override;
176 
177  // Setup loader using param tree. If tree is null or failed to find params,
178  // use environment or select default reader.
179  static TRegisterLoaderInfo RegisterInObjectManager(
181  const CGBLoaderParams& params,
184 
185  //bool LessBlobId(const TBlobId& id1, const TBlobId& id2) const;
186  //string BlobIdToString(const TBlobId& id) const;
187 
188  virtual TTSE_Lock ResolveConflict(const CSeq_id_Handle& handle,
189  const TTSE_LockSet& tse_set) override;
190 
191  virtual void GC(void) override;
192 
193  virtual TNamedAnnotNames GetNamedAnnotAccessions(const CSeq_id_Handle& idh) override;
194  virtual TNamedAnnotNames GetNamedAnnotAccessions(const CSeq_id_Handle& idh,
195  const string& named_acc) override;
196 
198  {
199  return *m_Dispatcher;
200  }
202  {
203  return *m_InfoManager;
204  }
205 
206  enum ECacheType {
210  };
212  bool HaveCache(TCacheType cache_type = fCache_Any) override;
213 
214  void PurgeCache(TCacheType cache_type,
215  time_t access_timeout = 0) override;
216  void CloseCache(void) override;
217 
218 protected:
220 
221  TBlobContentsMask x_MakeContentMask(EChoice choice) const;
222  TBlobContentsMask x_MakeContentMask(const SRequestDetails& details) const;
223 
224  TTSE_LockSet x_GetRecords(const CSeq_id_Handle& idh,
225  TBlobContentsMask sr_mask,
226  const SAnnotSelector* sel,
227  TProcessedNAs* processed_nas = 0);
228 
229 private:
230  friend class CGBDataLoader;
231  friend class CGBLoaderMaker<CGBDataLoader_Native>;
232 
233  TRealBlobId x_GetRealBlobId(const TBlobId& blob_id) const override;
234 
235  CGBDataLoader_Native(const string& loader_name,
236  const CGBLoaderParams& params);
237 
239 
242 
243  // Information about all available caches
245 
246  //
247  // private code
248  //
249 
250  void x_CreateDriver(const CGBLoaderParams& params);
251 
252  pair<string, string> GetReaderWriterName(const TParamTree* params, const CGBLoaderParams& loader_params) const;
253  bool x_CreateReaders(const string& str,
254  const TParamTree* params,
255  const CGBLoaderParams& gb_params,
257  void x_CreateWriters(const string& str, const TParamTree* params);
258  CReader* x_CreateReader(const string& names, const CGBLoaderParams& gb_params, const TParamTree* params = 0);
259  CWriter* x_CreateWriter(const string& names, const TParamTree* params = 0);
260 
263 
264  static CRef<TReaderManager> x_GetReaderManager(void);
265  static CRef<TWriterManager> x_GetWriterManager(void);
266 
267 private:
270 };
271 
272 
274 
276 
277 #endif
CGBReaderCacheManager::TCacheType TCacheType
Definition: gbnative.hpp:211
CRef< CGBInfoManager > m_InfoManager
Definition: gbnative.hpp:241
CPluginManager< CWriter > TWriterManager
Definition: gbnative.hpp:262
CInitMutexPool m_MutexPool
Definition: gbnative.hpp:238
CGBReaderCacheManager m_CacheManager
Definition: gbnative.hpp:244
CRef< CReadDispatcher > m_Dispatcher
Definition: gbnative.hpp:240
CGBDataLoader_Native & operator=(const CGBDataLoader_Native &)
CPluginManager< CReader > TReaderManager
Definition: gbnative.hpp:261
set< string > TNamedAnnotNames
Definition: gbnative.hpp:118
CGBDataLoader_Native(const CGBDataLoader_Native &)
CGBInfoManager & GetInfoManager(void)
Definition: gbnative.hpp:201
CReadDispatcher & GetDispatcher(void)
Definition: gbnative.hpp:197
CReaderCacheManager::TCacheType TCacheType
Definition: gbloader.hpp:372
virtual TCaches & GetCaches(void)
Definition: gbnative.hpp:104
CObjectManager –.
CPluginManager<> –.
virtual ICache * FindCache(ECacheType cache_type, const TCacheParams *params)=0
vector< SReaderCacheInfo > TCaches
virtual void RegisterCache(ICache &cache, ECacheType cache_type)=0
Definition: Seq_entry.hpp:56
definition of a Culling tree
Definition: ncbi_tree.hpp:100
BLOB cache read/write/maintenance interface.
Definition: icache.hpp:64
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const struct name_t names[]
static const char * str(char *buf, int n)
Definition: stats.c:84
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
SStrictId_Tax::TId TTaxId
Taxon id type.
Definition: ncbimisc.hpp:1048
string GetLabel(const CSeq_id &id)
TTaxId GetTaxId(const CBioseq_Handle &handle)
return the tax-id associated with a given sequence.
Definition: sequence.cpp:274
vector< TSeqPos > TSequenceLengths
vector< CTSE_Lock > TCDD_Locks
vector< CSeq_id_Handle > TIds
vector< bool > THashKnown
vector< TGi > TGis
EChoice
main blob is blob with sequence all other blobs are external and contain external annotations
vector< TIds > TBulkIds
vector< CSeq_inst::TMol > TSequenceTypes
vector< vector< CSeq_id_Handle > > TSeqIdSets
EIsDefault
Flag defining if the data loader is included in the "default" group.
vector< bool > TLoaded
Bulk loading interface for a small pieces of information per id.
vector< string > TLabels
vector< TTaxId > TTaxIds
vector< int > TSequenceStates
vector< int > TSequenceHashes
vector< TChunk > TChunkSet
@ kPriority_NotSet
Deprecated: use kPriority_Default instead.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_XLOADER_GENBANK_EXPORT
Definition: ncbi_export.h:1179
Interfaces for a local cache of versioned binary large objects (BLOBS).
Multi-threading – mutexes; rw-locks; semaphore.
Multi-threading – classes, functions, and features.
int TBlobContentsMask
Definition: blob_id.hpp:202
Plugin manager (using class factory paradigm).
static bool GetIds(const T &d, set< string > &labels, const string name="", bool detect=false, bool found=false)
CRef< objects::CObjectManager > om
Better replacement of GetAccVer(), this method should be defined in data loaders, GetAccVer() is left...
Better replacement of GetGi(), this method should be defined in data loaders, GetGi() is left for com...
Better replacement of GetSequenceHash(), this method should be defined in data loaders,...
Better replacement of GetSequenceType(), this method should be defined in data loaders,...
SAnnotSelector –.
SRegisterLoaderInfo –.
Modified on Wed Apr 24 14:16:36 2024 by modify_doxy.py rev. 669887