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

Go to the SVN repository for this file.

1 /* $Id: osg_resolve.cpp 99336 2023-03-13 14:22:34Z 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: Eugene Vasilchenko
27  *
28  * File Description: processor for data from OSG
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include "osg_resolve.hpp"
35 #include "osg_getblob_base.hpp"
36 #include "osg_fetch.hpp"
37 #include "osg_connection.hpp"
38 
40 #include <objects/id2/id2__.hpp>
42 
46 
47 
48 static const bool kAlwaysAskForBlobId = true;
49 
50 
52  const CRef<COSGConnectionPool>& pool,
53  const shared_ptr<CPSGS_Request>& request,
54  const shared_ptr<CPSGS_Reply>& reply,
55  TProcessorPriority priority)
56  : CPSGS_OSGProcessorBase(enabled_flags, pool, request, reply, priority)
57 {
58 }
59 
60 
62 {
64 }
65 
66 
68 {
69  return "OSG-resolve";
70 }
71 
72 
74 {
76 }
77 
78 
80  shared_ptr<CPSGS_Request>& request)
81 {
82  if ( !(enabled_flags & fEnabledWGS) ) {
83  return false;
84  }
85  auto& psg_req = request->GetRequest<SPSGS_ResolveRequest>();
86  return CanResolve(psg_req.m_SeqIdType, psg_req.m_SeqId);
87 }
88 
89 
91 {
92  auto& psg_req = GetRequest()->GetRequest<SPSGS_ResolveRequest>();
93  if ( psg_req.m_IncludeDataFlags &
94  (psg_req.fPSGS_SeqIds |
95  psg_req.fPSGS_CanonicalId |
96  psg_req.fPSGS_Gi) ) {
97  // actual sequence ids
98  CRef<CID2_Request> osg_req(new CID2_Request);
99  auto& req = osg_req->SetRequest().SetGet_seq_id();
100  SetSeqId(req.SetSeq_id().SetSeq_id(), psg_req.m_SeqIdType, psg_req.m_SeqId);
101  req.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all);
102  AddRequest(osg_req);
103  }
104  if ( psg_req.m_IncludeDataFlags &
105  (psg_req.fPSGS_MoleculeType |
106  psg_req.fPSGS_Length |
107  psg_req.fPSGS_TaxId |
108  psg_req.fPSGS_Hash) ) {
109  // artificial ids for special info requests
110  CRef<CID2_Request> osg_req(new CID2_Request);
111  auto& req = osg_req->SetRequest().SetGet_seq_id();
112  SetSeqId(req.SetSeq_id().SetSeq_id(), psg_req.m_SeqIdType, psg_req.m_SeqId);
113  req.SetSeq_id_type(0);
114  if ( psg_req.m_IncludeDataFlags & psg_req.fPSGS_MoleculeType ) {
115  req.SetSeq_id_type() |= CID2_Request_Get_Seq_id::eSeq_id_type_seq_mol;
116  }
117  if ( psg_req.m_IncludeDataFlags & psg_req.fPSGS_Length ) {
118  req.SetSeq_id_type() |= CID2_Request_Get_Seq_id::eSeq_id_type_seq_length;
119  }
120  if ( psg_req.m_IncludeDataFlags & psg_req.fPSGS_TaxId ) {
121  req.SetSeq_id_type() |= CID2_Request_Get_Seq_id::eSeq_id_type_taxid;
122  }
123  if ( psg_req.m_IncludeDataFlags & psg_req.fPSGS_Hash ) {
124  req.SetSeq_id_type() |= CID2_Request_Get_Seq_id::eSeq_id_type_hash;
125  }
126  AddRequest(osg_req);
127  }
128  /*
129  TODO
130  fPSGS_SeqState = (1 << 12),
131  */
132  if ( kAlwaysAskForBlobId ||
133  (psg_req.m_IncludeDataFlags &
134  (psg_req.fPSGS_BlobId |
135  psg_req.fPSGS_State |
136  psg_req.fPSGS_DateChanged)) ) {
137  // blob id or state
138  CRef<CID2_Request> osg_req(new CID2_Request);
139  auto& req = osg_req->SetRequest().SetGet_blob_id();
140  SetSeqId(req.SetSeq_id().SetSeq_id().SetSeq_id(), psg_req.m_SeqIdType, psg_req.m_SeqId);
141  AddRequest(osg_req);
142  }
143  if ( GetFetches().empty() ) {
144  // resolve only, no any other information to return
145  CRef<CID2_Request> osg_req(new CID2_Request);
146  auto& req = osg_req->SetRequest().SetGet_seq_id();
147  SetSeqId(req.SetSeq_id().SetSeq_id(), psg_req.m_SeqIdType, psg_req.m_SeqId);
148  req.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_any);
149  AddRequest(osg_req);
150  }
151 }
152 
153 
155 {
157 }
158 
159 
161 {
162  bool got_blob_id = false;
163  for ( auto& f : GetFetches() ) {
164  for ( auto& r : f->GetReplies() ) {
165  switch ( r->GetReply().Which() ) {
168  // do nothing
169  break;
172  break;
174  got_blob_id = true;
177  // resolved to OSG sequence
178  if ( SignalStartProcessing() == ePSGS_Cancel ) {
179  return;
180  }
181  }
182  break;
183  default:
184  PSG_ERROR(GetName()<<": "
185  "Unknown reply to "<<MSerial_AsnText<<*f->GetRequest()<<"\n"<<*r);
186  break;
187  }
188  }
189  }
190  if ( IsCanceled() ) {
191  SendTrace("OSG-resolve: canceled");
192  return;
193  }
194  if ( s_SimulateError() ) {
196  return;
197  }
198  SendTrace("OSG-resolve: sending reply");
199  if ( m_BioseqInfoFlags == 0 ) {
201  }
202  else if ( got_blob_id && !(m_BioseqInfoFlags & SPSGS_ResolveRequest::fPSGS_BlobId) ) {
203  // got non-OSG blob-id -> non-OSG sequence
205  }
206  else {
207  auto& psg_req = GetRequest()->GetRequest<SPSGS_ResolveRequest>();
208  if ( !psg_req.m_IncludeDataFlags ) {
209  // only resolution is requested
210  m_BioseqInfoFlags = 0;
211  }
212  if ( SignalStartProcessing() == ePSGS_Cancel ) {
214  return;
215  }
216  SendBioseqInfo(GetRequest()->GetRequest<SPSGS_ResolveRequest>().m_OutputFormat);
218  }
219 }
220 
221 
223  const CRef<COSGConnectionPool>& pool,
224  const shared_ptr<CPSGS_Request>& request,
225  const shared_ptr<CPSGS_Reply>& reply,
226  TProcessorPriority priority)
227  : CPSGS_OSGProcessorBase(enabled_flags, pool, request, reply, priority)
228 {
229 }
230 
231 
233 {
234  StopAsyncThread();
235 }
236 
237 
239 {
240  return "OSG-get";
241 }
242 
243 
245 {
246  return kOSGProcessorGroupName;
247 }
248 
249 
251  shared_ptr<CPSGS_Request>& request)
252 {
253  if ( !(enabled_flags & fEnabledWGS) ) {
254  return false;
255  }
256  auto& psg_req = request->GetRequest<SPSGS_BlobBySeqIdRequest>();
257  return CanResolve(psg_req.m_SeqIdType, psg_req.m_SeqId);
258 }
259 
260 
262 {
263  auto& psg_req = GetRequest()->GetRequest<SPSGS_BlobBySeqIdRequest>();
264  CRef<CID2_Request> osg_req(new CID2_Request);
265  auto& get_req = osg_req->SetRequest().SetGet_blob_info();
266  if ( psg_req.m_TSEOption != psg_req.ePSGS_NoneTSE ) {
267  get_req.SetGet_data();
268  }
269  auto& req = get_req.SetBlob_id().SetResolve();
270  SetSeqId(req.SetRequest().SetSeq_id().SetSeq_id().SetSeq_id(), psg_req.m_SeqIdType, psg_req.m_SeqId);
271  for ( auto& excl_id : psg_req.m_ExcludeBlobs ) {
272  if ( auto excl_blob_id = CPSGS_OSGGetBlobBase::ParsePSGBlobId(excl_id) ) {
273  req.SetExclude_blobs().push_back(excl_blob_id);
274  }
275  }
276  AddRequest(osg_req);
277 }
278 
279 
280 bool CPSGS_OSGGetBlobBySeqId::BlobIsExcluded(const string& psg_blob_id)
281 {
282  auto& psg_req = GetRequest()->GetRequest<SPSGS_BlobBySeqIdRequest>();
283  return find(psg_req.m_ExcludeBlobs.begin(), psg_req.m_ExcludeBlobs.end(), psg_blob_id) !=
284  psg_req.m_ExcludeBlobs.end();
285 }
286 
287 
289 {
291 }
292 
293 
295 {
296  for ( auto& f : GetFetches() ) {
297  for ( auto& r : f->GetReplies() ) {
298  switch ( r->GetReply().Which() ) {
301  // do nothing
302  break;
305  break;
309  // resolved to OSG sequence
310  if ( SignalStartProcessing() == ePSGS_Cancel ) {
312  return;
313  }
314  }
315  break;
318  break;
321  break;
322  default:
323  PSG_ERROR(GetName()<<": "
324  "Unknown reply to "<<MSerial_AsnText<<*f->GetRequest()<<"\n"<<*r);
325  break;
326  }
327  }
328  }
329  if ( IsCanceled() ) {
330  SendTrace("OSG-get: canceled");
331  return;
332  }
333  if ( s_SimulateError() ) {
335  return;
336  }
337  SendTrace("OSG-get: sending reply");
340  }
341  else if ( HasBlob() ) {
342  if ( SignalStartProcessing() == ePSGS_Cancel ) {
344  return;
345  }
347  SendBlob();
349  }
350  else if ( GetRequest()->GetRequest<SPSGS_BlobBySeqIdRequest>().m_TSEOption == SPSGS_BlobBySeqIdRequest::ePSGS_NoneTSE ) {
351  if ( SignalStartProcessing() == ePSGS_Cancel ) {
353  return;
354  }
357  }
358  else if ( BlobIsExcluded(m_BlobId) ) {
359  if ( SignalStartProcessing() == ePSGS_Cancel ) {
361  return;
362  }
366  }
367  else if ( Forbidden() ) {
368  if ( SignalStartProcessing() == ePSGS_Cancel ) {
370  return;
371  }
375  }
376  else {
377  PSG_ERROR(GetName()<<": Unexpected missing blob");
379  }
380 }
381 
382 
CID2_Request –.
Definition: ID2_Request.hpp:66
static CRef< CID2_Blob_Id > ParsePSGBlobId(const SPSGS_BlobId &blob_id)
void ProcessBlobReply(const CID2_Reply &reply)
void SendExcludedBlob(const string &psg_blob_id)
virtual void ProcessReplies() override
bool BlobIsExcluded(const string &psg_blob_id)
static bool CanProcess(TEnabledFlags enabled_flags, shared_ptr< CPSGS_Request > &request)
virtual void WaitForOtherProcessors() override
virtual string GetName() const override
Tells the processor name (used in logging and tracing)
virtual void CreateRequests() override
virtual string GetGroupName() const override
Tells the processor group name.
virtual ~CPSGS_OSGGetBlobBySeqId()
CPSGS_OSGGetBlobBySeqId(TEnabledFlags enabled_flags, const CRef< COSGConnectionPool > &pool, const shared_ptr< CPSGS_Request > &request, const shared_ptr< CPSGS_Reply > &reply, TProcessorPriority priority)
void AddRequest(const CRef< CID2_Request > &req)
void SendTrace(const string &str)
const TFetches & GetFetches() const
void SendBioseqInfo(EOutputFormat output_format)
TBioseqInfoFlags m_BioseqInfoFlags
static void SetSeqId(CSeq_id &id, int seq_id_type, const string &seq_id)
static bool CanResolve(int seq_id_type, const string &seq_id)
void ProcessResolveReply(const CID2_Reply &reply)
virtual void ProcessReplies() override
virtual void CreateRequests() override
Definition: osg_resolve.cpp:90
virtual void WaitForOtherProcessors() override
virtual string GetGroupName() const override
Tells the processor group name.
Definition: osg_resolve.cpp:73
CPSGS_OSGResolve(TEnabledFlags enabled_flags, const CRef< COSGConnectionPool > &pool, const shared_ptr< CPSGS_Request > &request, const shared_ptr< CPSGS_Reply > &reply, TProcessorPriority priority)
Definition: osg_resolve.cpp:51
virtual string GetName() const override
Tells the processor name (used in logging and tracing)
Definition: osg_resolve.cpp:67
virtual ~CPSGS_OSGResolve()
Definition: osg_resolve.cpp:61
static bool CanProcess(TEnabledFlags enabled_flags, shared_ptr< CPSGS_Request > &request)
Definition: osg_resolve.cpp:79
shared_ptr< CPSGS_Request > GetRequest(void) const
Provides the user request.
EPSGS_StartProcessing SignalStartProcessing(void)
A processor should call the method when it decides that it successfully started processing the reques...
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
void SetRequest(TRequest &value)
Assign a value to Request data member.
@ eSeq_id_type_hash
return a sequence hash as integer in general id with db "HASH"
@ eSeq_id_type_any
return any qualified Seq-id
@ eSeq_id_type_taxid
return a sequence taxonomy ID as integer in general id with db "TAXID"
@ eSeq_id_type_seq_length
return a sequence Seq-inst.length as int in general id with db "Seq-inst.length"
@ eSeq_id_type_seq_mol
return a sequence Seq-inst.mol as int in general id with db "Seq-inst.mol"
@ eSeq_id_type_all
return all qualified Seq-ids of the sequence
constexpr bool empty(list< Ts... >) noexcept
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
const string kOSGProcessorGroupName
END_NCBI_NAMESPACE
static const bool kAlwaysAskForBlobId
Definition: osg_resolve.cpp:48
BEGIN_NCBI_NAMESPACE
Definition: osg_resolve.cpp:43
BEGIN_NAMESPACE(psg)
END_NAMESPACE(osg)
#define PSG_ERROR(message)
int TProcessorPriority
vector< string > m_ExcludeBlobs
Modified on Fri Mar 01 10:07:29 2024 by modify_doxy.py rev. 669887