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

Go to the SVN repository for this file.

1 /* $Id: cdd_loader.cpp 99348 2023-03-14 14:56:18Z 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  * Author: Aleksey Grichenko
27  *
28  * File Description: CDD file data loader
29  *
30  * ===========================================================================
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
37 #include <serial/serial.hpp>
39 #include <objects/id2/id2__.hpp>
46 
47 
49 
50 class CObject;
51 
53 
54 class CDataLoader;
55 
57 
59 public:
60  bool IsDataLoaderMatches(CDataLoader& loader) const {
61  return dynamic_cast<CCDDDataLoader*>(&loader) != 0;
62  }
63 };
64 
65 
66 class CRevoker {
67 public:
69  CLoaderFilter filter;
71  }
72 };
76 
78 
79 
80 /////////////////////////////////////////////////////////////////////////////
81 // CCDDDataLoader
82 /////////////////////////////////////////////////////////////////////////////
83 
84 
86  : m_Compress(false),
87  m_PoolSoftLimit(DEFAULT_CDD_POOL_SOFT_LIMIT),
88  m_PoolAgeLimit(DEFAULT_CDD_POOL_AGE_LIMIT),
89  m_ExcludeNucleotides(DEFAULT_CDD_EXCLUDE_NUCLEOTIDES)
90 {
91 }
92 
93 
94 static const char* kCDDLoaderName = "CDDDataLoader";
95 static const char* kCDDLoaderParamName = "CDD_Loader";
96 
97 
99 {
100  const TParamTree* node = params.FindSubNode(kCDDLoaderParamName);
101 
102  CConfig conf(node);
103 
104  m_ServiceName = conf.GetString(kCDDLoaderParamName,
108 
109  m_Compress = conf.GetBool(kCDDLoaderParamName,
112  false);
113 
114  m_PoolSoftLimit = conf.GetInt(kCDDLoaderParamName,
117 
118  m_PoolAgeLimit = conf.GetInt(kCDDLoaderParamName,
121 
122  m_ExcludeNucleotides = conf.GetBool(kCDDLoaderParamName,
125 
126 }
127 
128 
130 {
131 }
132 
133 
136  CObjectManager::EIsDefault is_default,
137  CObjectManager::TPriority priority)
138 {
139  SLoaderParams params;
140  TMaker maker(params);
141  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
142  return maker.GetRegisterInfo();
143 }
144 
145 
148  const TParamTree& param_tree,
149  CObjectManager::EIsDefault is_default,
150  CObjectManager::TPriority priority)
151 {
152  SLoaderParams params(param_tree);
153  TMaker maker(params);
154  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
155  return maker.GetRegisterInfo();
156 }
157 
158 
161  const SLoaderParams& params,
162  CObjectManager::EIsDefault is_default,
163  CObjectManager::TPriority priority)
164 {
165  TMaker maker(params);
166  CDataLoader::RegisterInObjectManager(om, maker, is_default, priority);
167  return maker.GetRegisterInfo();
168 }
169 
170 
172 {
173  return kCDDLoaderName;
174 }
175 
176 
178 {
179  SLoaderParams params;
180  return GetLoaderNameFromArgs(params);
181 }
182 
183 
184 CCDDDataLoader::CCDDDataLoader(const string& loader_name,
185  const SLoaderParams& params)
186  : CDataLoader(loader_name)
187 {
188  m_Impl = new CCDDDataLoader_Impl(params);
189 }
190 
191 
193 {
194 }
195 
196 
199 {
200  TTSE_LockSet locks;
201  return locks;
202 }
203 
204 
207  const SAnnotSelector* sel,
208  TProcessedNAs* processed_nas)
209 {
210  TSeq_idSet ids;
211  ids.insert(idh);
212  return GetOrphanAnnotRecordsNA(ids, sel, processed_nas);
213 }
214 
215 
218  const SAnnotSelector* sel,
219  TProcessedNAs* processed_nas)
220 {
221  return m_Impl->GetBlobBySeq_ids(ids, *GetDataSource(), processed_nas);
222 }
223 
224 
226 {
228 }
229 
230 
231 /////////////////////////////////////////////////////////////////////////////
232 // CCDDBlobId
233 /////////////////////////////////////////////////////////////////////////////
234 
235 
237 {
238  try {
239  str_id >> Get();
240  }
241  catch (...) {
242  }
243 }
244 
245 
247 {
249  m_Id2BlobId->Assign(blob_id);
250 }
251 
252 
253 const CID2_Blob_Id& CCDDBlobId::Get(void) const
254 {
255  if (!m_Id2BlobId) {
257  }
258  return *m_Id2BlobId;
259 }
260 
261 
263 {
264  if (!m_Id2BlobId) {
266  }
267  return *m_Id2BlobId;
268 }
269 
270 
271 string CCDDBlobId::ToString(void) const
272 {
273  string ret;
274  if (!IsEmpty())
275  {
276  ret << *m_Id2BlobId;
277  }
278  return ret;
279 }
280 
281 
282 bool CCDDBlobId::operator<(const CBlobId& blob_id) const
283 {
284  const CCDDBlobId* cdd = dynamic_cast<const CCDDBlobId*>(&blob_id);
285  return cdd && *this < *cdd;
286 }
287 
288 
289 bool CCDDBlobId::operator==(const CBlobId& blob_id) const
290 {
291  const CCDDBlobId* cdd = dynamic_cast<const CCDDBlobId*>(&blob_id);
292  return cdd && *this == *cdd;
293 }
294 
295 
296 #define CMP_MEMBER(NAME) \
297  do { \
298  T##NAME v1 = Get##NAME(); \
299  T##NAME v2 = blob_id.Get##NAME(); \
300  if (v1 != v2) return v1 < v2; \
301  } while (0)
302 
303 
304 bool CCDDBlobId::operator<(const CCDDBlobId& blob_id) const
305 {
306  // NULL is less than any blob-id.
307  if (IsEmpty()) return !blob_id.IsEmpty();
308 
309  CMP_MEMBER(Sat);
310  CMP_MEMBER(SubSat);
311  CMP_MEMBER(SatKey);
312  CMP_MEMBER(Version);
313  return false;
314 }
315 
316 
317 bool CCDDBlobId::operator==(const CCDDBlobId& blob_id) const
318 {
319  if (IsEmpty()) return blob_id.IsEmpty();
320  return GetSat() == blob_id.GetSat()
321  && GetSubSat() == blob_id.GetSubSat()
322  && GetSatKey() == blob_id.GetSatKey()
323  && GetVersion() == blob_id.GetVersion();
324 }
325 
326 
327 /////////////////////////////////////////////////////////////////////////////
328 // CCDDDataLoader_Impl
329 /////////////////////////////////////////////////////////////////////////////
330 
331 
333  : m_ClientPool(
334  params.m_ServiceName,
335  params.m_PoolSoftLimit,
336  params.m_PoolAgeLimit,
337  params.m_ExcludeNucleotides)
338 {
339 }
340 
341 
343 {
344 }
345 
346 
349 {
351  TBlob blob = m_ClientPool.GetBlobBySeq_ids(ids);
352  if (!blob.data) return ret;
353 
354  CRef<CCDDBlobId> cdd_blob_id(new CCDDBlobId(blob.info->GetBlob_id()));
355  CDataLoader::TBlobId blob_id(cdd_blob_id);
356  CTSE_LoadLock load_lock = ds.GetTSE_LoadLock(blob_id);
357  if (!load_lock.IsLoaded()) {
358  CRef<CSeq_entry> entry(new CSeq_entry);
359  entry->SetSet().SetSeq_set();
360  entry->SetAnnot().push_back(blob.data);
361  load_lock->SetName("CDD");
362  load_lock->SetSeq_entry(*entry);
363  load_lock.SetLoaded();
364  }
365  ret.insert(load_lock);
366  CDataLoader::SetProcessedNA("CDD", processed_nas);
367  return ret;
368 }
369 
370 
372 
373 // ===========================================================================
374 
376 
378 {
379  RegisterEntryPoint<CDataLoader>(NCBI_EntryPoint_DataLoader_Cdd);
380 }
381 
382 
383 const string kDataLoader_Cdd_DriverName("cdd");
384 
386 {
387 public:
390  virtual ~CCDD_DataLoaderCF(void) {}
391 
392 protected:
395  const TPluginManagerParamTree* params) const;
396 };
397 
398 
401  const TPluginManagerParamTree* params) const
402 {
403  if ( !ValidParams(params) ) {
404  // Use constructor without arguments
406  }
407  if (params) {
409  om,
410  *params,
411  GetIsDefault(params),
412  GetPriority(params)).GetLoader();
413  }
414  // IsDefault and Priority arguments may be specified
416  om,
417  GetIsDefault(params),
418  GetPriority(params)).GetLoader();
419 }
420 
421 
425 {
427 }
428 
429 
433 {
434  NCBI_EntryPoint_DataLoader_Cdd(info_list, method);
435 }
436 
437 
#define DEFAULT_CDD_POOL_AGE_LIMIT
Definition: cdd_client.hpp:47
#define DEFAULT_CDD_POOL_SOFT_LIMIT
Definition: cdd_client.hpp:46
#define DEFAULT_CDD_SERVICE_NAME
Definition: cdd_client.hpp:45
#define DEFAULT_CDD_EXCLUDE_NUCLEOTIDES
Definition: cdd_client.hpp:48
USING_SCOPE(objects)
static const char * kCDDLoaderParamName
Definition: cdd_loader.cpp:95
static const char * kCDDLoaderName
Definition: cdd_loader.cpp:94
void DataLoaders_Register_CDD(void)
Definition: cdd_loader.cpp:377
void NCBI_EntryPoint_xloader_cdd(CPluginManager< objects::CDataLoader >::TDriverInfoList &info_list, CPluginManager< objects::CDataLoader >::EEntryPointRequest method)
Definition: cdd_loader.cpp:430
BEGIN_LOCAL_NAMESPACE
Definition: cdd_loader.cpp:54
#define CMP_MEMBER(NAME)
Definition: cdd_loader.cpp:296
void NCBI_EntryPoint_DataLoader_Cdd(CPluginManager< CDataLoader >::TDriverInfoList &info_list, CPluginManager< CDataLoader >::EEntryPointRequest method)
Definition: cdd_loader.cpp:422
END_LOCAL_NAMESPACE
Definition: cdd_loader.cpp:77
const string kDataLoader_Cdd_DriverName("cdd")
static CSafeStatic< CRevoker > s_Revoker(CSafeStaticLifeSpan(CSafeStaticLifeSpan::eLifeLevel_AppMain, CSafeStaticLifeSpan::eLifeSpan_Long))
CRef< CID2_Blob_Id > m_Id2BlobId
TSat GetSat(void) const
TSatKey GetSatKey(void) const
bool operator==(const CBlobId &blob_id) const
Definition: cdd_loader.cpp:289
bool IsEmpty(void) const
string ToString(void) const
Get string representation of blob id.
Definition: cdd_loader.cpp:271
bool operator<(const CBlobId &blob_id) const
Definition: cdd_loader.cpp:282
TSubSat GetSubSat(void) const
TVersion GetVersion(void) const
const CID2_Blob_Id & Get(void) const
Definition: cdd_loader.cpp:253
SCDDBlob GetBlobBySeq_ids(const TSeq_idSet &ids)
Definition: cdd_client.cpp:389
CCDDDataLoader_Impl(const CCDDDataLoader::SLoaderParams &params)
Definition: cdd_loader.cpp:332
CCDDClientPool m_ClientPool
TTSE_LockSet GetBlobBySeq_ids(const TSeq_idSet &ids, CDataSource &ds, TProcessedNAs *processed_nas)
Definition: cdd_loader.cpp:348
CCDDDataLoader(void)
TTSE_LockSet GetOrphanAnnotRecordsNA(const CSeq_id_Handle &idh, const SAnnotSelector *sel, TProcessedNAs *processed_nas) override
new Get*AnnotRecords() methods
Definition: cdd_loader.cpp:206
static string GetLoaderNameFromArgs(void)
Definition: cdd_loader.cpp:177
CObjectManager::TPriority GetDefaultPriority(void) const override
Definition: cdd_loader.cpp:225
CRef< CCDDDataLoader_Impl > m_Impl
Definition: cdd_loader.hpp:103
~CCDDDataLoader(void)
Definition: cdd_loader.cpp:192
TTSE_LockSet GetRecords(const CSeq_id_Handle &idh, EChoice choice) override
Request from a datasource using handles and ranges instead of seq-loc The TSEs loaded in this call wi...
Definition: cdd_loader.cpp:198
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CObjectManager::EIsDefault is_default=CObjectManager::eNonDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: cdd_loader.cpp:134
virtual CDataLoader * CreateAndRegister(CObjectManager &om, const TPluginManagerParamTree *params) const
Definition: cdd_loader.cpp:399
virtual ~CCDD_DataLoaderCF(void)
Definition: cdd_loader.cpp:390
CObjectManager::TPriority GetPriority(const TPluginManagerParamTree *params) const
CObjectManager::EIsDefault GetIsDefault(const TPluginManagerParamTree *params) const
bool ValidParams(const TPluginManagerParamTree *params) const
CTSE_LoadLock GetTSE_LoadLock(const TBlobId &blob_id)
CID2_Blob_Id –.
Definition: ID2_Blob_Id.hpp:66
bool IsDataLoaderMatches(CDataLoader &loader) const
Definition: cdd_loader.cpp:60
CObjectManager –.
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
CSafeStaticLifeSpan::
@ eLifeLevel_AppMain
Destroyed in CNcbiApplication::AppMain, if possible.
CSafeStatic<>::
Definition: Seq_entry.hpp:56
TAnnot & SetAnnot(void)
Definition: Seq_entry.cpp:195
void SetName(const CAnnotName &name)
Definition: tse_info.cpp:333
void SetSeq_entry(CSeq_entry &entry, CTSE_SetObjectInfo *set_info=0)
Definition: tse_info.cpp:351
bool IsLoaded(void) const
void SetLoaded(void)
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
definition of a Culling tree
Definition: ncbi_tree.hpp:100
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define false
Definition: bool.h:36
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
int GetInt(const string &driver_name, const string &param_name, EErrAction on_error, int default_value, const list< string > *synonyms=NULL)
Utility function to get an integer element of parameter tree Throws an exception when mandatory param...
string GetString(const string &driver_name, const string &param_name, EErrAction on_error, const string &default_value, const list< string > *synonyms=NULL)
Utility function to get an element of parameter tree Throws an exception when mandatory parameter is ...
bool GetBool(const string &driver_name, const string &param_name, EErrAction on_error, bool default_value, const list< string > *synonyms=NULL)
Utility function to get an integer element of parameter tree Throws an exception when mandatory param...
@ eErr_NoThrow
Return default value on error.
TLoader * GetLoader(void) const
Get pointer to the loader.
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void RevokeDataLoaders(IDataLoaderFilter &filter)
Revoke data loaders by filter, even if they were still used.
static void SetProcessedNA(const string &na, TProcessedNAs *processed_nas)
CDataSource * GetDataSource(void) const
Definition: data_loader.cpp:92
EChoice
main blob is blob with sequence all other blobs are external and contain external annotations
EIsDefault
Flag defining if the data loader is included in the "default" group.
TRegisterInfo GetRegisterInfo(void)
static void RegisterInObjectManager(CObjectManager &om, CLoaderMaker_Base &loader_maker, CObjectManager::EIsDefault is_default, CObjectManager::TPriority priority)
Register the loader only if the name is not yet registered in the object manager.
Definition: data_loader.cpp:53
@ kPriority_Replace
Default priority for replacement loaders.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
static void NCBI_EntryPointImpl(TDriverInfoList &info_list, EEntryPointRequest method)
Entry point implementation.
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
#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
const TTreeType * FindSubNode(const TKeyType &key) const
Non recursive linear scan of all subnodes, with key comparison.
Definition: ncbi_tree.hpp:940
const TBlob_id & GetBlob_id(void) const
Get the Blob_id member data.
TSet & SetSet(void)
Select the variant.
Definition: Seq_entry_.cpp:130
TSeq_set & SetSeq_set(void)
Assign a value to Seq_set data member.
#define NCBI_ID2PROC_CDD_PARAM_SERVICE_NAME
Definition: id2cdd_params.h:47
#define NCBI_ID2PROC_CDD_PARAM_POOL_AGE_LIMIT
Definition: id2cdd_params.h:56
#define NCBI_ID2PROC_CDD_PARAM_POOL_SOFT_LIMIT
Definition: id2cdd_params.h:53
#define NCBI_ID2PROC_CDD_PARAM_COMPRESS_DATA
Definition: id2cdd_params.h:50
#define NCBI_ID2PROC_CDD_PARAM_EXCLUDE_NUCLEOTIDES
Definition: id2cdd_params.h:63
Helper classes and templates to implement plugins.
CRef< objects::CObjectManager > om
SAnnotSelector –.
SRegisterLoaderInfo –.
Modified on Fri Apr 26 16:21:25 2024 by modify_doxy.py rev. 669887