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

Go to the SVN repository for this file.

1 #ifndef GBLOADER__HPP_INCLUDED
2 #define GBLOADER__HPP_INCLUDED
3 
4 /* $Id: gbloader.hpp 101259 2023-11-21 17:57:47Z 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 
55 
56 #include <util/cache/icache.hpp>
57 
58 #define GENBANK_NEW_READER_WRITER
59 
61 
63 
64 /////////////////////////////////////////////////////////////////////////////////
65 //
66 // GBDataLoader
67 //
68 
69 class CReader;
70 class CSeqref;
71 class CReadDispatcher;
72 class CGBInfoManager;
73 
74 // Parameter names used by loader factory
75 
77 {
78 public:
79  // possible parameters
80  typedef string TReaderName;
81  typedef CReader* TReaderPtr;
87  ePreopenByConfig
88  };
89 
90  // no options
91  CGBLoaderParams(void);
92  // one option
93  CGBLoaderParams(const string& reader_name);
97 
99  // copy
102 
103  void SetLoaderName(const string& loader_name)
104  {
105  m_LoaderName = loader_name;
106  }
107  const string& GetLoaderName(void) const
108  {
109  return m_LoaderName;
110  }
111 
112  void SetLoaderMethod(const string& loader_method)
113  {
114  m_LoaderMethod = loader_method;
115  }
116 
117  const string& GetLoaderMethod(void) const
118  {
119  return m_LoaderMethod;
120  }
121 
122  void SetReaderName(const string& reader_name)
123  {
124  m_ReaderName = reader_name;
125  }
126  const string& GetReaderName(void) const
127  {
128  return m_ReaderName;
129  }
130 
131  void SetWriterName(const string& writer_name)
132  {
133  m_WriterName = writer_name;
134  }
135  const string& GetWriterName(void) const
136  {
137  return m_WriterName;
138  }
139 
140  void SetReaderPtr(CReader* reader_ptr);
141  CReader* GetReaderPtr(void) const;
142 
143  void SetParamTree(const TParamTree* params);
144  const TParamTree* GetParamTree(void) const
145  {
146  return m_ParamTree;
147  }
148 
149  void SetPreopenConnection(EPreopenConnection preopen = ePreopenAlways)
150  {
151  m_Preopen = preopen;
152  }
154  {
155  return m_Preopen;
156  }
157  void SetHUPIncluded(bool include_hup = true,
158  const string& web_cookie = NcbiEmptyString)
159  {
160  m_HasHUPIncluded = include_hup;
161  m_WebCookie = web_cookie;
162  }
163  bool HasHUPIncluded(void) const
164  {
165  return m_HasHUPIncluded;
166  }
167 
168  const string& GetWebCookie(void) const
169  {
170  return m_WebCookie;
171  }
172 
173  const string& GetPSGServiceName(void) const
174  {
175  return m_PSGServiceName;
176  }
177 
178  void SetPSGServiceName(const string& service_name)
179  {
180  m_PSGServiceName = service_name;
181  }
182 
183  bool GetUsePSG() const;
184  void SetUsePSG(bool use_psg = true)
185  {
186  m_UsePSG = use_psg;
187  m_UsePSGInitialized = true;
188  }
189 
190  bool GetPSGNoSplit(void) const
191  {
192  return m_PSGNoSplit;
193  }
194 
195  void SetPSGNoSplit(bool no_split)
196  {
197  m_PSGNoSplit = no_split;
198  }
199 
200  bool IsSetEnableSNP(void) const;
201  bool GetEnableSNP(void) const;
202  void SetEnableSNP(bool enable);
203 
204  bool IsSetEnableWGS(void) const;
205  bool GetEnableWGS(void) const;
206  void SetEnableWGS(bool enable);
207 
208  bool IsSetEnableCDD(void) const;
209  bool GetEnableCDD(void) const;
210  void SetEnableCDD(bool enable);
211 
212 private:
213  string m_ReaderName;
214  string m_WriterName;
219  mutable bool m_UsePSGInitialized; // can be changed in GetUsePSG()
220  mutable bool m_UsePSG;
223  string m_WebCookie;
224  string m_LoaderName;
229 
230  friend class CGBDataLoader_Native;
231 };
232 
234 {
235 public:
236  // typedefs from CReader
237  typedef unsigned TConn;
240 
241  virtual ~CGBDataLoader(void);
242 
243  TBlobId GetBlobIdFromSatSatKey(int sat,
244  int sat_key,
245  int sub_sat = 0) const;
246 
247  // Create GB loader and register in the object manager if
248  // no loader with the same name is registered yet.
250  static TRegisterLoaderInfo RegisterInObjectManager(
252  CReader* reader = 0,
255  static string GetLoaderNameFromArgs(CReader* reader = 0);
256 
257  // enum to include HUP data
258  enum EIncludeHUP {
259  eIncludeHUP
260  };
261 
262  // Select reader by name. If failed, select default reader.
263  // Reader name may be the same as in environment: PUBSEQOS, ID1 etc.
264  // Several names may be separated with ":". Empty name or "*"
265  // included as one of the names allows to include reader names
266  // from environment and registry.
267  static TRegisterLoaderInfo RegisterInObjectManager(
269  const string& reader_name,
272  static string GetLoaderNameFromArgs(const string& reader_name);
273 
274  // GBLoader with HUP data included.
275  // The reader will be chosen from default configuration,
276  // either pubseqos or pubseqos2.
277  // The default loader priority will be slightly lower than for main data.
278  static TRegisterLoaderInfo RegisterInObjectManager(
280  EIncludeHUP include_hup,
283  static string GetLoaderNameFromArgs(EIncludeHUP include_hup);
284  static TRegisterLoaderInfo RegisterInObjectManager(
286  EIncludeHUP include_hup,
287  const string& web_cookie,
290  static string GetLoaderNameFromArgs(EIncludeHUP include_hup,
291  const string& web_cookie);
292 
293  // GBLoader with HUP data included.
294  // The reader can be either pubseqos or pubseqos2.
295  // The default loader priority will be slightly lower than for main data.
296  static TRegisterLoaderInfo RegisterInObjectManager(
298  const string& reader_name, // pubseqos or pubseqos2
299  EIncludeHUP include_hup,
302  static string GetLoaderNameFromArgs(const string& reader_name, // pubseqos or pubseqos2
303  EIncludeHUP include_hup);
304  static TRegisterLoaderInfo RegisterInObjectManager(
306  const string& reader_name, // pubseqos or pubseqos2
307  EIncludeHUP include_hup,
308  const string& web_cookie,
311  static string GetLoaderNameFromArgs(const string& reader_name, // pubseqos or pubseqos2
312  EIncludeHUP include_hup,
313  const string& web_cookie);
314 
315  // Setup loader using param tree. If tree is null or failed to find params,
316  // use environment or select default reader.
318  static TRegisterLoaderInfo RegisterInObjectManager(
320  const TParamTree& params,
323  static string GetLoaderNameFromArgs(const TParamTree& params);
324 
325  // Setup loader using param tree. If tree is null or failed to find params,
326  // use environment or select default reader.
327  static TRegisterLoaderInfo RegisterInObjectManager(
329  const CGBLoaderParams& params,
332  static string GetLoaderNameFromArgs(const CGBLoaderParams& params);
333 
336  const string& named_acc) = 0;
337 
338  CConstRef<CSeqref> GetSatSatkey(const CSeq_id_Handle& idh);
339  CConstRef<CSeqref> GetSatSatkey(const CSeq_id& id);
340 
341  TRealBlobId GetRealBlobId(const TBlobId& blob_id) const;
342  TRealBlobId GetRealBlobId(const CTSE_Info& tse_info) const;
343 
344  // params modifying access methods
345  // argument params should be not-null
346  // returned value is not null - subnode will be created if necessary
347  static TParamTree* GetParamsSubnode(TParamTree* params,
348  const string& subnode_name);
349  static TParamTree* GetLoaderParams(TParamTree* params);
350  static TParamTree* GetReaderParams(TParamTree* params,
351  const string& reader_name);
352  static void SetParam(TParamTree* params,
353  const string& param_name,
354  const string& param_value);
355  // params non-modifying access methods
356  // argument params may be null
357  // returned value may be null if params argument is null
358  // or if subnode is not found
359  static const TParamTree* GetParamsSubnode(const TParamTree* params,
360  const string& subnode_name);
361  static const TParamTree* GetLoaderParams(const TParamTree* params);
362  static const TParamTree* GetReaderParams(const TParamTree* params,
363  const string& reader_name);
364  static string GetParam(const TParamTree* params,
365  const string& param_name);
366 
367  enum ECacheType {
371  };
373  virtual bool HaveCache(TCacheType cache_type = fCache_Any) = 0;
374 
375  virtual void PurgeCache(TCacheType cache_type,
376  time_t access_timeout = 0) = 0;
377  virtual void CloseCache(void) = 0;
378 
379  // expiration timout in seconds, must be positive
382  {
383  return m_IdExpirationTimeout;
384  }
386 
387  bool GetAlwaysLoadExternal(void) const
388  {
389  return m_AlwaysLoadExternal;
390  }
391 
392  void SetAlwaysLoadExternal(bool flag)
393  {
394  m_AlwaysLoadExternal = flag;
395  }
396 
397  bool GetAlwaysLoadNamedAcc(void) const
398  {
399  return m_AlwaysLoadNamedAcc;
400  }
401 
402  void SetAlwaysLoadNamedAcc(bool flag)
403  {
404  m_AlwaysLoadNamedAcc = flag;
405  }
406 
407  bool GetAddWGSMasterDescr(void) const
408  {
409  return m_AddWGSMasterDescr;
410  }
411 
412  void SetAddWGSMasterDescr(bool flag)
413  {
414  m_AddWGSMasterDescr = flag;
415  }
416 
417  bool HasHUPIncluded(void) const
418  {
419  return m_HasHUPIncluded;
420  }
421 
422 
424  {
425  return m_PTISErrorAction;
426  }
427 
429  {
430  m_PTISErrorAction = action;
431  }
432 
433  virtual CObjectManager::TPriority GetDefaultPriority(void) const override;
434  virtual bool GetTrackSplitSeq() const override;
435 
436 protected:
437  template <class TDataLoader>
439  {
440  public:
442  : m_Params(params)
443  {
444  m_Name = CGBDataLoader::GetLoaderNameFromArgs(params);
445  }
446 
447  virtual ~CGBLoaderMaker(void) {}
448 
449  virtual CDataLoader* CreateLoader(void) const
450  {
451  return new TDataLoader(m_Name, m_Params);
452  }
455  {
457  info.Set(m_RegisterInfo.GetLoader(), m_RegisterInfo.IsCreated());
458  return info;
459  }
460  protected:
462  };
463  CGBDataLoader(const string& loader_name,
464  const CGBLoaderParams& params);
465 
466  static string x_GetLoaderMethod(const TParamTree* params);
467 
469 
475  string m_WebCookie;
476 
477 private:
480 
481  virtual TRealBlobId x_GetRealBlobId(const TBlobId& blob_id) const = 0;
482 public:
483  static bool IsUsingPSGLoader(void);
484 };
485 
486 
487 NCBI_PARAM_DECL(string, GENBANK, LOADER_METHOD);
488 
490 
491 
492 extern "C"
493 {
494 
499 
504 
505 } // extern C
506 
507 
509 
510 #endif
CConstRef –.
Definition: ncbiobj.hpp:1266
TRegisterInfo GetRegisterInfo(void)
Definition: gbloader.hpp:454
virtual CDataLoader * CreateLoader(void) const
Definition: gbloader.hpp:449
SRegisterLoaderInfo< CGBDataLoader > TRegisterInfo
Definition: gbloader.hpp:453
CGBLoaderMaker(const CGBLoaderParams &params)
Definition: gbloader.hpp:441
virtual TRealBlobId x_GetRealBlobId(const TBlobId &blob_id) const =0
Uint4 TExpirationTimeout
Definition: gbloader.hpp:380
unsigned TConn
Definition: gbloader.hpp:237
bool m_AddWGSMasterDescr
Definition: gbloader.hpp:472
bool m_HasHUPIncluded
Definition: gbloader.hpp:473
void SetAlwaysLoadExternal(bool flag)
Definition: gbloader.hpp:392
static string GetLoaderNameFromArgs(CReader *reader=0)
Definition: gbloader.cpp:377
virtual void CloseCache(void)=0
virtual void PurgeCache(TCacheType cache_type, time_t access_timeout=0)=0
void SetAddWGSMasterDescr(bool flag)
Definition: gbloader.hpp:412
TExpirationTimeout m_IdExpirationTimeout
Definition: gbloader.hpp:468
virtual TNamedAnnotNames GetNamedAnnotAccessions(const CSeq_id_Handle &idh)=0
void SetIdExpirationTimeout(TExpirationTimeout timeout)
bool GetAlwaysLoadExternal(void) const
Definition: gbloader.hpp:387
bool GetAddWGSMasterDescr(void) const
Definition: gbloader.hpp:407
bool m_AlwaysLoadExternal
Definition: gbloader.hpp:470
EGBErrorAction GetPTISErrorAction(void) const
Definition: gbloader.hpp:423
CGBDataLoader(const CGBDataLoader &)
string m_WebCookie
Definition: gbloader.hpp:475
bool HasHUPIncluded(void) const
Definition: gbloader.hpp:417
void SetAlwaysLoadNamedAcc(bool flag)
Definition: gbloader.hpp:402
TExpirationTimeout GetIdExpirationTimeout(void) const
Definition: gbloader.hpp:381
EGBErrorAction m_PTISErrorAction
Definition: gbloader.hpp:474
void SetPTISErrorAction(EGBErrorAction action)
Definition: gbloader.hpp:428
CBlob_id TRealBlobId
Definition: gbloader.hpp:238
virtual TNamedAnnotNames GetNamedAnnotAccessions(const CSeq_id_Handle &idh, const string &named_acc)=0
set< string > TNamedAnnotNames
Definition: gbloader.hpp:239
TPluginManagerParamTree TParamTree
Definition: gbloader.hpp:317
bool GetAlwaysLoadNamedAcc(void) const
Definition: gbloader.hpp:397
bool m_AlwaysLoadNamedAcc
Definition: gbloader.hpp:471
CGBDataLoader & operator=(const CGBDataLoader &)
virtual bool HaveCache(TCacheType cache_type=fCache_Any)=0
CReaderCacheManager::TCacheType TCacheType
Definition: gbloader.hpp:372
SRegisterLoaderInfo< CGBDataLoader > TRegisterLoaderInfo
Definition: gbloader.hpp:249
bool GetPSGNoSplit(void) const
Definition: gbloader.hpp:190
const string & GetPSGServiceName(void) const
Definition: gbloader.hpp:173
const string & GetLoaderMethod(void) const
Definition: gbloader.hpp:117
EPreopenConnection m_Preopen
Definition: gbloader.hpp:218
const string & GetLoaderName(void) const
Definition: gbloader.hpp:107
TPluginManagerParamTree TParamTree
Definition: gbloader.hpp:82
string m_WriterName
Definition: gbloader.hpp:214
void SetPSGNoSplit(bool no_split)
Definition: gbloader.hpp:195
EPreopenConnection GetPreopenConnection(void) const
Definition: gbloader.hpp:153
const TParamTree * m_ParamTree
Definition: gbloader.hpp:217
void SetReaderName(const string &reader_name)
Definition: gbloader.hpp:122
string m_WebCookie
Definition: gbloader.hpp:223
void SetPSGServiceName(const string &service_name)
Definition: gbloader.hpp:178
const TParamTree * GetParamTree(void) const
Definition: gbloader.hpp:144
void SetPreopenConnection(EPreopenConnection preopen=ePreopenAlways)
Definition: gbloader.hpp:149
CRef< CReader > m_ReaderPtr
Definition: gbloader.hpp:216
void SetLoaderMethod(const string &loader_method)
Definition: gbloader.hpp:112
CNullable< bool > m_EnableCDD
Definition: gbloader.hpp:228
void SetWriterName(const string &writer_name)
Definition: gbloader.hpp:131
string m_LoaderMethod
Definition: gbloader.hpp:215
CNullable< bool > m_EnableSNP
Definition: gbloader.hpp:226
void SetUsePSG(bool use_psg=true)
Definition: gbloader.hpp:184
string m_PSGServiceName
Definition: gbloader.hpp:225
string TReaderName
Definition: gbloader.hpp:80
const string & GetWebCookie(void) const
Definition: gbloader.hpp:168
CReader * TReaderPtr
Definition: gbloader.hpp:81
bool m_UsePSGInitialized
Definition: gbloader.hpp:219
string m_LoaderName
Definition: gbloader.hpp:224
const string & GetWriterName(void) const
Definition: gbloader.hpp:135
CNullable< bool > m_EnableWGS
Definition: gbloader.hpp:227
bool HasHUPIncluded(void) const
Definition: gbloader.hpp:163
CGBLoaderParams & operator=(const CGBLoaderParams &)
const string & GetReaderName(void) const
Definition: gbloader.hpp:126
void SetHUPIncluded(bool include_hup=true, const string &web_cookie=NcbiEmptyString)
Definition: gbloader.hpp:157
bool m_HasHUPIncluded
Definition: gbloader.hpp:222
CGBLoaderParams(TParamTreePtr param_tree)
string m_ReaderName
Definition: gbloader.hpp:213
CGBLoaderParams(const CGBLoaderParams &)
CGBLoaderParams(TReaderPtr reader_ptr)
~CGBLoaderParams(void)
const TPluginManagerParamTree * TParamTreePtr
Definition: gbloader.hpp:83
void SetLoaderName(const string &loader_name)
Definition: gbloader.hpp:103
CObjectManager –.
definition of a Culling tree
Definition: ncbi_tree.hpp:100
Include a standard set of the NCBI C++ Toolkit most basic headers.
NCBI_PARAM_DECL(string, GENBANK, LOADER_METHOD)
void NCBI_EntryPoint_xloader_genbank(CPluginManager< objects::CDataLoader >::TDriverInfoList &info_list, CPluginManager< objects::CDataLoader >::EEntryPointRequest method)
Definition: gbloader.cpp:799
void NCBI_EntryPoint_DataLoader_GB(CPluginManager< objects::CDataLoader >::TDriverInfoList &info_list, CPluginManager< objects::CDataLoader >::EEntryPointRequest method)
EIsDefault
Flag defining if the data loader is included in the "default" group.
@ kPriority_NotSet
Deprecated: use kPriority_Default instead.
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#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 NcbiEmptyString
Definition: ncbistr.hpp:122
#define NCBI_XLOADER_GENBANK_EXPORT
Definition: ncbi_export.h:1179
Interfaces for a local cache of versioned binary large objects (BLOBS).
static MDB_envinfo info
Definition: mdb_load.c:37
Multi-threading – mutexes; rw-locks; semaphore.
Multi-threading – classes, functions, and features.
EGBErrorAction
Definition: blob_id.hpp:191
Plugin manager (using class factory paradigm).
CRef< objects::CObjectManager > om
SRegisterLoaderInfo –.
Modified on Wed Feb 21 09:54:59 2024 by modify_doxy.py rev. 669887