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

Go to the SVN repository for this file.

1 /* $Id: reader_id2_base.cpp 101124 2023-11-01 22:46:50Z vasilche $
2  * ===========================================================================
3  * PUBLIC DOMAIN NOTICE
4  * National Center for Biotechnology Information
5  *
6  * This software/database is a "United States Government Work" under the
7  * terms of the United States Copyright Act. It was written as part of
8  * the author's official duties as a United States Government employee and
9  * thus cannot be copyrighted. This software/database is freely available
10  * to the public for use. The National Library of Medicine and the U.S.
11  * Government have not placed any restriction on its use or reproduction.
12  *
13  * Although all reasonable efforts have been taken to ensure the accuracy
14  * and reliability of the software and data, the NLM and the U.S.
15  * Government do not and cannot warrant the performance or results that
16  * may be obtained by using this software or data. The NLM and the U.S.
17  * Government disclaim all warranties, express or implied, including
18  * warranties of performance, merchantability or fitness for any particular
19  * purpose.
20  *
21  * Please cite the author in any work or product based on this material.
22  *
23  * ===========================================================================
24  *
25  * Author: Eugene Vasilchenko
26  *
27  * File Description: Data reader from ID2
28  *
29  */
30 
31 #include <ncbi_pch.hpp>
32 #include <corelib/ncbi_param.hpp>
33 #include <corelib/request_ctx.hpp>
34 
38 
41 #include <objmgr/impl/tse_info.hpp>
44 
46 #include <objtools/error_codes.hpp>
47 
48 #include <corelib/ncbimtx.hpp>
49 
51 
56 #include <objects/id2/id2__.hpp>
60 
61 #include <serial/iterator.hpp>
62 #include <serial/serial.hpp>
63 #include <serial/objistr.hpp>
64 
67 
68 #include <iomanip>
69 
70 
71 #define NCBI_USE_ERRCODE_X Objtools_Rd_Id2Base
72 
74 
76 
77 
78 NCBI_PARAM_ENUM_ARRAY(objects::CSeq_id::ESNPScaleLimit, GENBANK, ID2SNP_SCALE_LIMIT) {
79  {"", objects::CSeq_id::eSNPScaleLimit_Default},
80  {"Unit", objects::CSeq_id::eSNPScaleLimit_Unit},
81  {"Contig", objects::CSeq_id::eSNPScaleLimit_Contig},
82  {"Supercontig", objects::CSeq_id::eSNPScaleLimit_Supercontig},
83  {"Chromosome", objects::CSeq_id::eSNPScaleLimit_Chromosome},
84 };
85 NCBI_PARAM_ENUM_DECL(objects::CSeq_id::ESNPScaleLimit, GENBANK, ID2SNP_SCALE_LIMIT);
86 NCBI_PARAM_ENUM_DEF_EX(objects::CSeq_id::ESNPScaleLimit, GENBANK, ID2SNP_SCALE_LIMIT,
87  objects::CSeq_id::eSNPScaleLimit_Default,
88  eParam_NoThread, GENBANK_ID2SNP_SCALE_LIMIT);
89 typedef NCBI_PARAM_TYPE(GENBANK, ID2SNP_SCALE_LIMIT) TID2SNP_Scale_Limit;
90 
91 
93 
94 NCBI_PARAM_DECL(int, GENBANK, ID2_DEBUG);
95 NCBI_PARAM_DECL(int, GENBANK, ID2_MAX_CHUNKS_REQUEST_SIZE);
96 NCBI_PARAM_DECL(int, GENBANK, ID2_MAX_IDS_REQUEST_SIZE);
97 NCBI_PARAM_DECL(string, GENBANK, ID2_PROCESSOR);
98 NCBI_PARAM_DECL(bool, GENBANK, VDB_WGS);
99 NCBI_PARAM_DECL(bool, GENBANK, VDB_SNP);
100 NCBI_PARAM_DECL(bool, GENBANK, VDB_CDD);
101 
102 #ifdef _DEBUG
103 # define DEFAULT_DEBUG_LEVEL CId2ReaderBase::eTraceError
104 #else
105 # define DEFAULT_DEBUG_LEVEL 0
106 #endif
107 
108 NCBI_PARAM_DEF_EX(int, GENBANK, ID2_DEBUG, DEFAULT_DEBUG_LEVEL,
109  eParam_NoThread, GENBANK_ID2_DEBUG);
110 NCBI_PARAM_DEF_EX(int, GENBANK, ID2_MAX_CHUNKS_REQUEST_SIZE, 100,
111  eParam_NoThread, GENBANK_ID2_MAX_CHUNKS_REQUEST_SIZE);
112 NCBI_PARAM_DEF_EX(int, GENBANK, ID2_MAX_IDS_REQUEST_SIZE, 100,
113  eParam_NoThread, GENBANK_ID2_MAX_IDS_REQUEST_SIZE);
114 NCBI_PARAM_DEF_EX(string, GENBANK, ID2_PROCESSOR, "",
115  eParam_NoThread, GENBANK_ID2_PROCESSOR);
116 NCBI_PARAM_DEF_EX(bool, GENBANK, VDB_WGS, true,
117  eParam_NoThread, GENBANK_VDB_WGS);
118 NCBI_PARAM_DEF_EX(bool, GENBANK, VDB_SNP, true,
119  eParam_NoThread, GENBANK_VDB_SNP);
120 NCBI_PARAM_DEF_EX(bool, GENBANK, VDB_CDD, true,
121  eParam_NoThread, GENBANK_VDB_CDD);
122 
123 typedef NCBI_PARAM_TYPE(GENBANK, VDB_WGS) TGenbankVdbWgsParam;
124 typedef NCBI_PARAM_TYPE(GENBANK, VDB_SNP) TGenbankVdbSnpParam;
125 typedef NCBI_PARAM_TYPE(GENBANK, VDB_CDD) TGenbankVdbCddParam;
126 
128 {
129  static CSafeStatic<NCBI_PARAM_TYPE(GENBANK, ID2_DEBUG)> s_Value;
130  return s_Value->Get();
131 }
132 
133 
135 {
136  return TGenbankVdbSnpParam::GetDefault();
137 }
138 
139 
141 {
142  return TGenbankVdbSnpParam::SetDefault(enabled);
143 }
144 
145 
147 {
148  return TGenbankVdbWgsParam::GetDefault();
149 }
150 
151 
153 {
154  return TGenbankVdbWgsParam::SetDefault(enabled);
155 }
156 
157 
159 {
160  return TGenbankVdbCddParam::GetDefault();
161 }
162 
163 
165 {
166  return TGenbankVdbCddParam::SetDefault(enabled);
167 }
168 
169 
171 {
172  return TID2SNP_Scale_Limit::GetDefault();
173 }
174 
175 
177 {
178  TID2SNP_Scale_Limit::SetDefault(value);
179 }
180 
181 
182 static const char kSpecialId_label[] = "LABEL";
183 static const char kSpecialId_taxid[] = "TAXID";
184 static const char kSpecialId_hash[] = "HASH";
185 static const char kSpecialId_length[] = "Seq-inst.length";
186 static const char kSpecialId_type[] = "Seq-inst.mol";
187 
188 
189 // Number of chunks allowed in a single request
190 // 0 = unlimited request size
191 // 1 = do not use packets or get-chunks requests
192 static size_t GetMaxChunksRequestSize(void)
193 {
194  static CSafeStatic<NCBI_PARAM_TYPE(GENBANK, ID2_MAX_CHUNKS_REQUEST_SIZE)> s_Value;
195  return (size_t)s_Value->Get();
196 }
197 
198 
199 static size_t GetMaxIdsRequestSize(void)
200 {
201  static CSafeStatic<NCBI_PARAM_TYPE(GENBANK, ID2_MAX_IDS_REQUEST_SIZE)> s_Value;
202  return (size_t)s_Value->Get();
203 }
204 
205 
206 static inline
207 bool
209 {
210  return max_request_size == 1;
211 }
212 
213 
214 static inline
215 bool
216 LimitChunksRequests(size_t max_request_size = GetMaxChunksRequestSize())
217 {
218  return max_request_size > 0;
219 }
220 
221 
223 {
225  typedef list< CRef<CID2S_Seq_annot_Info> > TAnnotInfo;
227 };
228 
229 
231 {
232  typedef pair<int, CReader::TSeqIds> TSeq_idsInfo; // state & ids
236  typedef pair<int, TBlob_ids> TBlob_idsInfo; // state & blob-info
240 
245 };
246 
247 
249  : m_RequestSerialNumber(1),
250  m_AvoidRequest(0)
251 {
252  vector<string> proc_list;
253  string proc_param = NCBI_PARAM_TYPE(GENBANK, ID2_PROCESSOR)::GetDefault();
254  NStr::Split(proc_param, ";", proc_list);
255  ITERATE ( vector<string>, it, proc_list ) {
256  const string& proc_name = *it;
258  try {
260  CreateInstance(proc_name);
261  }
262  catch ( CException& exc ) {
263  ERR_POST_X(15, "CId2ReaderBase: "
264  "cannot load ID2 processor "<<proc_name<<": "<<exc);
265  }
266  if ( info.processor ) {
267  info.context = info.processor->CreateContext();
268  // send init request
269  CID2_Request req;
270  req.SetRequest().SetInit();
271  x_SetContextData(req);
272  CID2_Request_Packet packet;
273  packet.Set().push_back(Ref(&req));
274  CID2Processor::TReplies replies;
275  info.processor->ProcessPacket(info.context, packet, replies);
276  m_Processors.push_back(info);
277  }
278  }
279 }
280 
281 
283 {
284 }
285 
286 
288 {
289  m_Processors.clear();
290 }
291 
292 
293 #define MConnFormat MSerial_AsnBinary
294 
295 
297  const CSeq_id& seq_id)
298 {
299  //get_blob_id.SetSeq_id().SetSeq_id().SetSeq_id(const_cast<CSeq_id&>(seq_id));
300  get_blob_id.SetSeq_id().SetSeq_id().SetSeq_id().Assign(seq_id);
301  get_blob_id.SetExternal();
303 }
304 
305 
307  TContentsMask /*mask*/)
308 {
309 }
310 
311 
313  const CSeq_id_Handle& idh,
315 {
316  if ( SeparateChunksRequests() ) {
317  // Minimize size of request rather than response
318  return;
319  }
321  result.GetLoadedBlob_ids(idh, loaded_blob_ids);
322  if ( loaded_blob_ids.empty() ) {
323  return;
324  }
325  CID2_Request_Get_Blob_Info::C_Blob_id::C_Resolve::TExclude_blobs&
326  exclude_blobs =
327  get_blob_info.SetBlob_id().SetResolve().SetExclude_blobs();
328  ITERATE(CReaderRequestResult::TLoadedBlob_ids, id, loaded_blob_ids) {
329  CRef<CID2_Blob_Id> blob_id(new CID2_Blob_Id);
330  x_SetResolve(*blob_id, *id);
331  exclude_blobs.push_back(blob_id);
332  }
333 }
334 
335 
337 {
338  CBlob_id ret;
339  ret.SetSat(blob_id.GetSat());
340  ret.SetSubSat(blob_id.GetSub_sat());
341  ret.SetSatKey(blob_id.GetSat_key());
342  //ret.SetVersion(blob_id.GetVersion());
343  return ret;
344 }
345 
346 
348 {
349  blob_id.SetSat(src.GetSat());
350  blob_id.SetSub_sat(src.GetSubSat());
351  blob_id.SetSat_key(src.GetSatKey());
352  //blob_id.SetVersion(src.GetVersion());
353 }
354 
355 
357  const CSeq_id_Handle& seq_id)
358 {
359  CLoadLockSeqIds ids(result, seq_id);
360  if ( ids.IsLoaded() ) {
361  return true;
362  }
363 
364  CID2_Request req;
366  req.SetRequest().SetGet_seq_id();
367  get_id.SetSeq_id().SetSeq_id().Assign(*seq_id.GetSeqId());
368  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all);
369  x_ProcessRequest(result, req, 0);
370  return true;
371 }
372 
373 
375  const CSeq_id_Handle& seq_id)
376 {
377  CLoadLockGi lock(result, seq_id);
378  if ( lock.IsLoadedGi() ) {
379  return true;
380  }
381  CID2_Request req;
383  req.SetRequest().SetGet_seq_id();
384  get_id.SetSeq_id().SetSeq_id().Assign(*seq_id.GetSeqId());
385  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all);
386  x_ProcessRequest(result, req, 0);
387 
388  if ( !lock.IsLoadedGi() ) {
389  return CReader::LoadSeq_idGi(result, seq_id);
390  }
391 
392  return true;
393 }
394 
395 
397  const CSeq_id_Handle& seq_id)
398 {
399  CLoadLockAcc lock(result, seq_id);
400  if ( lock.IsLoadedAccVer() ) {
401  return true;
402  }
403  CID2_Request req;
405  req.SetRequest().SetGet_seq_id();
406  get_id.SetSeq_id().SetSeq_id().Assign(*seq_id.GetSeqId());
407  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all);
408  x_ProcessRequest(result, req, 0);
409 
410  if ( lock.IsLoadedAccVer() ) {
411  return true;
412  }
413  // load via full Seq-ids list
414  return CReader::LoadSeq_idAccVer(result, seq_id);
415 }
416 
417 
419  const CSeq_id_Handle& seq_id)
420 {
422  return CReader::LoadSeq_idLabel(result, seq_id);
423  }
424 
425  CLoadLockLabel ids(result, seq_id);
426  if ( ids.IsLoadedLabel() ) {
427  return true;
428  }
429  CID2_Request req;
431  req.SetRequest().SetGet_seq_id();
432  get_id.SetSeq_id().SetSeq_id().Assign(*seq_id.GetSeqId());
433  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_label);
434  x_ProcessRequest(result, req, 0);
435 
436  if ( ids.IsLoadedLabel() ) {
437  return true;
438  }
440  // load via full Seq-ids list
441  return CReader::LoadSeq_idLabel(result, seq_id);
442 }
443 
444 
446  const CSeq_id_Handle& seq_id)
447 {
449  return CReader::LoadSeq_idTaxId(result, seq_id);
450  }
451 
452  CLoadLockTaxId lock(result, seq_id);
453  if ( lock.IsLoadedTaxId() ) {
454  return true;
455  }
456  CID2_Request req;
458  req.SetRequest().SetGet_seq_id();
459  get_id.SetSeq_id().SetSeq_id().Assign(*seq_id.GetSeqId());
460  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_taxid);
461  x_ProcessRequest(result, req, 0);
462 
463  if ( !lock.IsLoadedTaxId() ) {
465  return true; // repeat
466  }
467 
468  return true;
469 }
470 
471 
473  const CSeq_id_Handle& seq_id)
474 {
476  return CReader::LoadSequenceHash(result, seq_id);
477  }
478 
479  CLoadLockHash lock(result, seq_id);
480  if ( lock.IsLoadedHash() ) {
481  return true;
482  }
483  CID2_Request req;
485  req.SetRequest().SetGet_seq_id();
486  get_id.SetSeq_id().SetSeq_id().Assign(*seq_id.GetSeqId());
487  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_hash);
488  x_ProcessRequest(result, req, 0);
489 
490  if ( !lock.IsLoadedHash() ) {
492  return true; // repeat
493  }
494 
495  return true;
496 }
497 
498 
500  const CSeq_id_Handle& seq_id)
501 {
503  return CReader::LoadSequenceLength(result, seq_id);
504  }
505 
506  CLoadLockLength lock(result, seq_id);
507  if ( lock.IsLoadedLength() ) {
508  return true;
509  }
510  CID2_Request req;
512  req.SetRequest().SetGet_seq_id();
513  get_id.SetSeq_id().SetSeq_id().Assign(*seq_id.GetSeqId());
514  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all |
516  x_ProcessRequest(result, req, 0);
517 
518  if ( !lock.IsLoadedLength() ) {
520  return true; // repeat
521  }
522 
523  return true;
524 }
525 
526 
528  const CSeq_id_Handle& seq_id)
529 {
531  return CReader::LoadSequenceType(result, seq_id);
532  }
533 
534  CLoadLockType lock(result, seq_id);
535  if ( lock.IsLoadedType() ) {
536  return true;
537  }
538  CID2_Request req;
540  req.SetRequest().SetGet_seq_id();
541  get_id.SetSeq_id().SetSeq_id().Assign(*seq_id.GetSeqId());
542  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all |
544  x_ProcessRequest(result, req, 0);
545 
546  if ( !lock.IsLoadedType() ) {
548  return true; // repeat
549  }
550 
551  return true;
552 }
553 
554 
556  const TIds& ids, TLoaded& loaded, TIds& ret)
557 {
558  size_t max_request_size = GetMaxIdsRequestSize();
559  if ( max_request_size <= 1 ) {
560  return CReader::LoadAccVers(result, ids, loaded, ret);
561  }
562 
563  size_t count = ids.size();
564  CID2_Request_Packet packet;
565  size_t packet_start = 0;
566 
567  for ( size_t i = 0; i < count; ++i ) {
568  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
569  continue;
570  }
571  CLoadLockAcc lock(result, ids[i]);
572  if ( lock.IsLoadedAccVer() ) {
573  TSequenceAcc data = lock.GetAccVer();
574  if ( lock.IsFound(data) ) {
575  ret[i] = lock.GetAcc(data);
576  loaded[i] = true;
577  }
578  continue;
579  }
580 
583  req->SetRequest().SetGet_seq_id();
584  get_id.SetSeq_id().SetSeq_id().Assign(*ids[i].GetSeqId());
585  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all);
586  if ( packet.Set().empty() ) {
587  packet_start = i;
588  }
589  packet.Set().push_back(req);
590  if ( packet.Set().size() == max_request_size ) {
591  x_ProcessPacket(result, packet, 0);
592  size_t count = i+1;
593  for ( size_t i = packet_start; i < count; ++i ) {
594  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
595  continue;
596  }
597  CLoadLockAcc lock(result, ids[i]);
598  if ( lock.IsLoadedAccVer() ) {
599  TSequenceAcc data = lock.GetAccVer();
600  if ( lock.IsFound(data) ) {
601  ret[i] = lock.GetAcc(data);
602  loaded[i] = true;
603  }
604  continue;
605  }
606  }
607  packet.Set().clear();
608  }
609  }
610 
611  if ( !packet.Set().empty() ) {
612  x_ProcessPacket(result, packet, 0);
613 
614  for ( size_t i = packet_start; i < count; ++i ) {
615  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
616  continue;
617  }
618  CLoadLockAcc lock(result, ids[i]);
619  if ( lock.IsLoadedAccVer() ) {
620  TSequenceAcc data = lock.GetAccVer();
621  if ( lock.IsFound(data) ) {
622  ret[i] = lock.GetAcc(data);
623  loaded[i] = true;
624  }
625  continue;
626  }
627  }
628  }
629 
630  return true;
631 }
632 
633 
635  const TIds& ids, TLoaded& loaded, TGis& ret)
636 {
637  size_t max_request_size = GetMaxIdsRequestSize();
638  if ( max_request_size <= 1 ) {
639  return CReader::LoadGis(result, ids, loaded, ret);
640  }
641 
642  size_t count = ids.size();
643  CID2_Request_Packet packet;
644  size_t packet_start = 0;
645 
646  for ( size_t i = 0; i < count; ++i ) {
647  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
648  continue;
649  }
650  CLoadLockGi lock(result, ids[i]);
651  if ( lock.IsLoadedGi() ) {
652  TSequenceGi data = lock.GetGi();
653  if ( lock.IsFound(data) ) {
654  ret[i] = lock.GetGi(data);
655  loaded[i] = true;
656  }
657  continue;
658  }
659 
662  req->SetRequest().SetGet_seq_id();
663  get_id.SetSeq_id().SetSeq_id().Assign(*ids[i].GetSeqId());
664  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all);
665  if ( packet.Set().empty() ) {
666  packet_start = i;
667  }
668  packet.Set().push_back(req);
669  if ( packet.Set().size() == max_request_size ) {
670  x_ProcessPacket(result, packet, 0);
671  size_t count = i+1;
672  for ( size_t i = packet_start; i < count; ++i ) {
673  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
674  continue;
675  }
676  CLoadLockGi lock(result, ids[i]);
677  if ( lock.IsLoadedGi() ) {
678  TSequenceGi data = lock.GetGi();
679  if ( lock.IsFound(data) ) {
680  ret[i] = lock.GetGi(data);
681  loaded[i] = true;
682  }
683  continue;
684  }
685  }
686  packet.Set().clear();
687  }
688  }
689 
690  if ( !packet.Set().empty() ) {
691  x_ProcessPacket(result, packet, 0);
692 
693  for ( size_t i = packet_start; i < count; ++i ) {
694  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
695  continue;
696  }
697  CLoadLockGi lock(result, ids[i]);
698  if ( lock.IsLoadedGi() ) {
699  TSequenceGi data = lock.GetGi();
700  if ( lock.IsFound(data) ) {
701  ret[i] = lock.GetGi(data);
702  loaded[i] = true;
703  }
704  continue;
705  }
706  }
707  }
708 
709  return true;
710 }
711 
712 
714  const TIds& ids, TLoaded& loaded, TLabels& ret)
715 {
716  size_t max_request_size = GetMaxIdsRequestSize();
717  if ( max_request_size <= 1 ) {
718  return CReader::LoadLabels(result, ids, loaded, ret);
719  }
720 
721  size_t count = ids.size();
722  CID2_Request_Packet packet;
723  size_t packet_start = 0;
724 
725  for ( size_t i = 0; i < count; ++i ) {
726  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
727  continue;
728  }
729  CLoadLockLabel lock(result, ids[i]);
730  if ( lock.IsLoadedLabel() ) {
731  ret[i] = lock.GetLabel();
732  loaded[i] = true;
733  continue;
734  }
735 
738  req->SetRequest().SetGet_seq_id();
739  get_id.SetSeq_id().SetSeq_id().Assign(*ids[i].GetSeqId());
741  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all);
742  }
743  else {
744  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_label);
745  }
746  if ( packet.Set().empty() ) {
747  packet_start = i;
748  }
749  packet.Set().push_back(req);
750  if ( packet.Set().size() == max_request_size ) {
751  x_ProcessPacket(result, packet, 0);
752  size_t count = i+1;
753  for ( size_t i = packet_start; i < count; ++i ) {
754  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
755  continue;
756  }
757  CLoadLockLabel lock(result, ids[i]);
758  if ( lock.IsLoadedLabel() ) {
759  ret[i] = lock.GetLabel();
760  loaded[i] = true;
761  continue;
762  }
763  else {
765  CLoadLockSeqIds ids_lock(result, ids[i]);
766  if ( ids_lock.IsLoaded() ) {
767  string label = ids_lock.GetSeq_ids().FindLabel();
768  lock.SetLoadedLabel(label,
769  ids_lock.GetExpirationTime());
770  ret[i] = label;
771  loaded[i] = true;
772  }
773  }
774  }
775  packet.Set().clear();
776  }
777  }
778 
779  if ( !packet.Set().empty() ) {
780  x_ProcessPacket(result, packet, 0);
781 
782  for ( size_t i = packet_start; i < count; ++i ) {
783  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
784  continue;
785  }
786  CLoadLockLabel lock(result, ids[i]);
787  if ( lock.IsLoadedLabel() ) {
788  ret[i] = lock.GetLabel();
789  loaded[i] = true;
790  continue;
791  }
792  else {
794  CLoadLockSeqIds ids_lock(result, ids[i]);
795  if ( ids_lock.IsLoaded() ) {
796  string label = ids_lock.GetSeq_ids().FindLabel();
797  lock.SetLoadedLabel(label,
798  ids_lock.GetExpirationTime());
799  ret[i] = label;
800  loaded[i] = true;
801  }
802  }
803  }
804  }
805 
806  return true;
807 }
808 
809 
811  const TIds& ids, TLoaded& loaded, TTaxIds& ret)
812 {
813  size_t max_request_size = GetMaxIdsRequestSize();
814  if ( max_request_size <= 1 ||
816  return CReader::LoadTaxIds(result, ids, loaded, ret);
817  }
818 
819  size_t count = ids.size();
820  CID2_Request_Packet packet;
821  size_t packet_start = 0;
822 
823  for ( size_t i = 0; i < count; ++i ) {
824  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
825  continue;
826  }
828  return CReader::LoadTaxIds(result, ids, loaded, ret);
829  }
830  CLoadLockTaxId lock(result, ids[i]);
831  if ( lock.IsLoadedTaxId() ) {
832  ret[i] = lock.GetTaxId();
833  loaded[i] = true;
834  continue;
835  }
836 
839  req->SetRequest().SetGet_seq_id();
840  get_id.SetSeq_id().SetSeq_id().Assign(*ids[i].GetSeqId());
841  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_taxid);
842  if ( packet.Set().empty() ) {
843  packet_start = i;
844  }
845  packet.Set().push_back(req);
846  if ( packet.Set().size() == max_request_size ) {
847  x_ProcessPacket(result, packet, 0);
848  size_t count = i+1;
849  for ( size_t i = packet_start; i < count; ++i ) {
850  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
851  continue;
852  }
853  CLoadLockTaxId lock(result, ids[i]);
854  if ( lock.IsLoadedTaxId() ) {
855  ret[i] = lock.GetTaxId();
856  loaded[i] = true;
857  continue;
858  }
859  else {
861  }
862  }
863  packet.Set().clear();
864  }
865  }
866 
867  if ( !packet.Set().empty() ) {
868  x_ProcessPacket(result, packet, 0);
869 
870  for ( size_t i = packet_start; i < count; ++i ) {
871  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
872  continue;
873  }
874  CLoadLockTaxId lock(result, ids[i]);
875  if ( lock.IsLoadedTaxId() ) {
876  ret[i] = lock.GetTaxId();
877  loaded[i] = true;
878  continue;
879  }
880  else {
882  }
883  }
884  }
885 
886  return true;
887 }
888 
889 
891  const TIds& ids, TLoaded& loaded,
892  THashes& ret, TKnown& known)
893 {
894  size_t max_request_size = GetMaxIdsRequestSize();
895  if ( max_request_size <= 1 ||
897  return CReader::LoadHashes(result, ids, loaded, ret, known);
898  }
899 
900  size_t count = ids.size();
901  CID2_Request_Packet packet;
902  size_t packet_start = 0;
903 
904  for ( size_t i = 0; i < count; ++i ) {
905  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
906  continue;
907  }
909  return CReader::LoadHashes(result, ids, loaded, ret, known);
910  }
911  CLoadLockHash lock(result, ids[i]);
912  if ( lock.IsLoadedHash() ) {
913  TSequenceHash hash = lock.GetHash();
914  if ( hash.hash_known ) {
915  ret[i] = hash.hash;
916  loaded[i] = true;
917  known[i] = true;
918  continue;
919  }
920  else if ( !hash.sequence_found ) {
921  // no sequence at all
922  continue;
923  }
924  }
925 
928  req->SetRequest().SetGet_seq_id();
929  get_id.SetSeq_id().SetSeq_id().Assign(*ids[i].GetSeqId());
930  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_hash);
931  if ( packet.Set().empty() ) {
932  packet_start = i;
933  }
934  packet.Set().push_back(req);
935  if ( packet.Set().size() == max_request_size ) {
936  x_ProcessPacket(result, packet, 0);
937  size_t count = i+1;
938  for ( size_t i = packet_start; i < count; ++i ) {
939  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
940  continue;
941  }
942  CLoadLockHash lock(result, ids[i]);
943  if ( lock.IsLoadedHash() ) {
944  TSequenceHash hash = lock.GetHash();
945  if ( hash.hash_known ) {
946  ret[i] = hash.hash;
947  loaded[i] = true;
948  known[i] = true;
949  continue;
950  }
951  else if ( !hash.sequence_found ) {
952  // no sequence at all
953  continue;
954  }
955  }
956  else {
958  }
959  }
960  packet.Set().clear();
961  }
962  }
963 
964  if ( !packet.Set().empty() ) {
965  x_ProcessPacket(result, packet, 0);
966 
967  for ( size_t i = packet_start; i < count; ++i ) {
968  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
969  continue;
970  }
971  CLoadLockHash lock(result, ids[i]);
972  TSequenceHash hash = lock.GetHash();
973  if ( hash.hash_known ) {
974  ret[i] = hash.hash;
975  loaded[i] = true;
976  known[i] = true;
977  continue;
978  }
979  else if ( !hash.sequence_found ) {
980  // no sequence at all
981  continue;
982  }
983  else {
985  }
986  }
987  }
988 
989  return true;
990 }
991 
992 
994  const TIds& ids, TLoaded& loaded, TLengths& ret)
995 {
996  size_t max_request_size = GetMaxIdsRequestSize();
997  if ( max_request_size <= 1 ||
999  return CReader::LoadLengths(result, ids, loaded, ret);
1000  }
1001 
1002  size_t count = ids.size();
1003  CID2_Request_Packet packet;
1004  size_t packet_start = 0;
1005 
1006  for ( size_t i = 0; i < count; ++i ) {
1007  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
1008  continue;
1009  }
1011  return CReader::LoadLengths(result, ids, loaded, ret);
1012  }
1013  CLoadLockLength lock(result, ids[i]);
1014  if ( lock.IsLoadedLength() ) {
1015  ret[i] = lock.GetLength();
1016  loaded[i] = true;
1017  continue;
1018  }
1019 
1022  req->SetRequest().SetGet_seq_id();
1023  get_id.SetSeq_id().SetSeq_id().Assign(*ids[i].GetSeqId());
1024  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all |
1026  if ( packet.Set().empty() ) {
1027  packet_start = i;
1028  }
1029  packet.Set().push_back(req);
1030  if ( packet.Set().size() == max_request_size ) {
1031  x_ProcessPacket(result, packet, 0);
1032  size_t count = i+1;
1033  for ( size_t i = packet_start; i < count; ++i ) {
1034  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
1035  continue;
1036  }
1037  CLoadLockLength lock(result, ids[i]);
1038  if ( lock.IsLoadedLength() ) {
1039  ret[i] = lock.GetLength();
1040  loaded[i] = true;
1041  continue;
1042  }
1043  else {
1045  }
1046  }
1047  packet.Set().clear();
1048  }
1049  }
1050 
1051  if ( !packet.Set().empty() ) {
1052  x_ProcessPacket(result, packet, 0);
1053 
1054  for ( size_t i = packet_start; i < count; ++i ) {
1055  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
1056  continue;
1057  }
1058  CLoadLockLength lock(result, ids[i]);
1059  if ( lock.IsLoadedLength() ) {
1060  ret[i] = lock.GetLength();
1061  loaded[i] = true;
1062  continue;
1063  }
1064  else {
1066  }
1067  }
1068  }
1069 
1070  return true;
1071 }
1072 
1073 
1075  const TIds& ids, TLoaded& loaded, TTypes& ret)
1076 {
1077  size_t max_request_size = GetMaxIdsRequestSize();
1078  if ( max_request_size <= 1 ||
1080  return CReader::LoadTypes(result, ids, loaded, ret);
1081  }
1082 
1083  size_t count = ids.size();
1084  CID2_Request_Packet packet;
1085  size_t packet_start = 0;
1086 
1087  for ( size_t i = 0; i < count; ++i ) {
1088  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
1089  continue;
1090  }
1092  return CReader::LoadTypes(result, ids, loaded, ret);
1093  }
1094  CLoadLockType lock(result, ids[i]);
1095  if ( lock.IsLoadedType() ) {
1096  TSequenceType data = lock.GetType();
1097  if ( lock.IsFound(data) ) {
1098  ret[i] = lock.GetType(data);
1099  loaded[i] = true;
1100  }
1101  continue;
1102  }
1103 
1106  req->SetRequest().SetGet_seq_id();
1107  get_id.SetSeq_id().SetSeq_id().Assign(*ids[i].GetSeqId());
1108  get_id.SetSeq_id_type(CID2_Request_Get_Seq_id::eSeq_id_type_all |
1110  if ( packet.Set().empty() ) {
1111  packet_start = i;
1112  }
1113  packet.Set().push_back(req);
1114  if ( packet.Set().size() == max_request_size ) {
1115  x_ProcessPacket(result, packet, 0);
1116  size_t count = i+1;
1117  for ( size_t i = packet_start; i < count; ++i ) {
1118  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
1119  continue;
1120  }
1121  CLoadLockType lock(result, ids[i]);
1122  if ( lock.IsLoadedType() ) {
1123  TSequenceType data = lock.GetType();
1124  if ( lock.IsFound(data) ) {
1125  ret[i] = lock.GetType(data);
1126  loaded[i] = true;
1127  }
1128  continue;
1129  }
1130  else {
1132  }
1133  }
1134  packet.Set().clear();
1135  }
1136  }
1137 
1138  if ( !packet.Set().empty() ) {
1139  x_ProcessPacket(result, packet, 0);
1140 
1141  for ( size_t i = packet_start; i < count; ++i ) {
1142  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
1143  continue;
1144  }
1145  CLoadLockType lock(result, ids[i]);
1146  if ( lock.IsLoadedType() ) {
1147  TSequenceType data = lock.GetType();
1148  if ( lock.IsFound(data) ) {
1149  ret[i] = lock.GetType(data);
1150  loaded[i] = true;
1151  }
1152  continue;
1153  }
1154  else {
1156  }
1157  }
1158  }
1159 
1160  return true;
1161 }
1162 
1163 
1165  const TIds& ids, TLoaded& loaded, TStates& ret)
1166 {
1167  size_t max_request_size = GetMaxIdsRequestSize();
1168  if ( max_request_size <= 1 ) {
1169  return CReader::LoadStates(result, ids, loaded, ret);
1170  }
1171 
1172  size_t count = ids.size();
1173  CID2_Request_Packet packet;
1174  size_t packet_start = 0;
1175 
1176  for ( size_t i = 0; i < count; ++i ) {
1177  if ( CReadDispatcher::SetBlobState(i, result, ids, loaded, ret) ) {
1178  continue;
1179  }
1180 
1182  x_SetResolve(req->SetRequest().SetGet_blob_id(), *ids[i].GetSeqId());
1183  if ( packet.Set().empty() ) {
1184  packet_start = i;
1185  }
1186  packet.Set().push_back(req);
1187  if ( packet.Set().size() == max_request_size ) {
1188  x_ProcessPacket(result, packet, 0);
1189  size_t count = i+1;
1190  for ( size_t i = packet_start; i < count; ++i ) {
1191  CReadDispatcher::SetBlobState(i, result, ids, loaded, ret);
1192  }
1193  packet.Set().clear();
1194  }
1195  }
1196 
1197  if ( !packet.Set().empty() ) {
1198  x_ProcessPacket(result, packet, 0);
1199 
1200  for ( size_t i = packet_start; i < count; ++i ) {
1201  CReadDispatcher::SetBlobState(i, result, ids, loaded, ret);
1202  }
1203  }
1204 
1205  return true;
1206 }
1207 
1208 
1210  const CSeq_id_Handle& seq_id,
1211  const SAnnotSelector* sel)
1212 {
1213  CLoadLockBlobIds ids(result, seq_id, sel);
1214  if ( ids.IsLoaded() ) {
1215  return true;
1216  }
1217 
1218  CID2_Request req;
1219  CID2_Request_Get_Blob_Id& get_blob_id = req.SetRequest().SetGet_blob_id();
1220  x_SetResolve(get_blob_id, *seq_id.GetSeqId());
1221  if ( sel && sel->IsIncludedAnyNamedAnnotAccession() ) {
1222  CID2_Request_Get_Blob_Id::TSources& srcs = get_blob_id.SetSources();
1224  srcs.push_back(it->first);
1225  if (it->first == "SNP") {
1227  if (snp_scale_limit == CSeq_id::eSNPScaleLimit_Default) {
1228  snp_scale_limit = GetSNP_Scale_Limit();
1229  }
1230  if (snp_scale_limit != CSeq_id::eSNPScaleLimit_Default) {
1231  CRef<CID2_Param> param(new CID2_Param);
1232  param->SetName("snp:scale-limit");
1233  param->SetValue().push_back(CSeq_id::GetSNPScaleLimit_Name(snp_scale_limit));
1234  req.SetParams().Set().push_back(param);
1235  }
1236  }
1237  }
1238  }
1239  x_ProcessRequest(result, req, sel);
1240  return true;
1241 }
1242 
1243 
1245  const CBlob_id& blob_id)
1246 {
1247  CLoadLockBlobState lock(result, blob_id);
1248  if ( lock.IsLoadedBlobState() ) {
1249  return true;
1250  }
1251  CID2_Request req;
1252  CID2_Request_Get_Blob_Info& req2 = req.SetRequest().SetGet_blob_info();
1253  x_SetResolve(req2.SetBlob_id().SetBlob_id(), blob_id);
1254  x_ProcessRequest(result, req, 0);
1255  if ( CProcessor_ExtAnnot::IsExtAnnot(blob_id) ) {
1256  // workaround for possible incorrect reply on request for non-existent
1257  // external annotations
1258  if ( !lock.IsLoadedBlobState() ) {
1259  ERR_POST_X(5, "ExtAnnot blob state is not loaded: "<<blob_id);
1260  result.SetLoadedBlobState(blob_id, 0);
1261  }
1262  }
1263  return true;
1264 }
1265 
1266 
1268  const CBlob_id& blob_id)
1269 {
1270  CLoadLockBlobVersion lock(result, blob_id);
1271  if ( lock.IsLoadedBlobVersion() ) {
1272  return true;
1273  }
1274  CID2_Request req;
1275  CID2_Request_Get_Blob_Info& req2 = req.SetRequest().SetGet_blob_info();
1276  x_SetResolve(req2.SetBlob_id().SetBlob_id(), blob_id);
1277  x_ProcessRequest(result, req, 0);
1278  if ( CProcessor_ExtAnnot::IsExtAnnot(blob_id) ) {
1279  // workaround for possible incorrect reply on request for non-existent
1280  // external annotations
1281  if ( !lock.IsLoadedBlobVersion() ) {
1282  ERR_POST_X(9, "ExtAnnot blob version is not loaded: "<<blob_id);
1283  result.SetLoadedBlobVersion(blob_id, 0);
1284  }
1285  }
1286  return true;
1287 }
1288 
1289 
1291  const CSeq_id_Handle& seq_id,
1293  const SAnnotSelector* sel)
1294 {
1295  CLoadLockBlobIds ids(result, seq_id, sel);
1296  if ( !ids.IsLoaded() ) {
1298  !(mask & fBlobHasAllLocal) ) {
1299  if ( !LoadSeq_idBlob_ids(result, seq_id, sel) ) {
1300  return false;
1301  }
1302  }
1303  }
1304  if ( ids.IsLoaded() ) {
1305  // shortcut - we know Seq-id -> Blob-id resolution
1306  return LoadBlobs(result, ids, mask, sel);
1307  }
1309  return CReader::LoadBlobs(result, seq_id, mask, sel);
1310  }
1311  else {
1312  CID2_Request req;
1313  CID2_Request_Get_Blob_Info& req2 = req.SetRequest().SetGet_blob_info();
1314  x_SetResolve(req2.SetBlob_id().SetResolve().SetRequest(),
1315  *seq_id.GetSeqId());
1316  x_SetDetails(req2.SetGet_data(), mask);
1317  x_SetExclude_blobs(req2, seq_id, result);
1318  x_ProcessRequest(result, req, sel);
1319  return ids.IsLoaded();
1320  }
1321 }
1322 
1323 
1325  const CLoadLockBlobIds& blobs,
1327  const SAnnotSelector* sel)
1328 {
1329  size_t max_request_size = GetMaxChunksRequestSize();
1330  CID2_Request_Packet packet;
1331  CFixedBlob_ids blob_ids = blobs.GetBlob_ids();
1332  ITERATE ( CFixedBlob_ids, it, blob_ids ) {
1333  const CBlob_Info& info = *it;
1334  const CBlob_id& blob_id = *info.GetBlob_id();
1335  if ( !info.Matches(mask, sel) ) {
1336  continue; // skip this blob
1337  }
1338  CLoadLockBlob blob(result, blob_id);
1339  if ( blob.IsLoadedBlob() ) {
1340  continue;
1341  }
1342 
1343  if ( info.IsSetAnnotInfo() ) {
1345  _ASSERT(blob.IsLoadedBlob());
1346  continue;
1347  }
1348 
1349  if ( CProcessor_ExtAnnot::IsExtAnnot(blob_id) ) {
1350  dynamic_cast<const CProcessor_ExtAnnot&>
1352  .Process(result, blob_id, kMain_ChunkId);
1353  _ASSERT(blob.IsLoadedBlob());
1354  continue;
1355  }
1356 
1358  packet.Set().push_back(req);
1360  req->SetRequest().SetGet_blob_info();
1361  x_SetResolve(req2.SetBlob_id().SetBlob_id(), blob_id);
1362  x_SetDetails(req2.SetGet_data(), mask);
1363  if ( LimitChunksRequests(max_request_size) &&
1364  packet.Get().size() >= max_request_size ) {
1365  x_ProcessPacket(result, packet, sel);
1366  packet.Set().clear();
1367  }
1368  }
1369  if ( !packet.Get().empty() ) {
1370  x_ProcessPacket(result, packet, sel);
1371  }
1372  return true;
1373 }
1374 
1375 
1377  const TBlobId& blob_id)
1378 {
1379  CLoadLockBlob blob(result, blob_id);
1380  if ( blob.IsLoadedBlob() ) {
1381  return true;
1382  }
1383 
1384  if ( CProcessor_ExtAnnot::IsExtAnnot(blob_id) ) {
1385  dynamic_cast<const CProcessor_ExtAnnot&>
1387  .Process(result, blob_id, kMain_ChunkId);
1388  _ASSERT(blob.IsLoadedBlob());
1389  return true;
1390  }
1391 
1392  CID2_Request req;
1393  CID2_Request_Get_Blob_Info& req2 = req.SetRequest().SetGet_blob_info();
1394  x_SetResolve(req2.SetBlob_id().SetBlob_id(), blob_id);
1395  req2.SetGet_data();
1396  x_ProcessRequest(result, req, 0);
1397  return true;
1398 }
1399 
1400 
1402  const CBlob_id& blob_id,
1403  TChunkId chunk_id)
1404 {
1405  CLoadLockBlob blob(result, blob_id, chunk_id);
1406  if ( blob.IsLoadedChunk() ) {
1407  return true;
1408  }
1409 
1410  CID2_Request req;
1411  if ( chunk_id == kDelayedMain_ChunkId ) {
1412  CID2_Request_Get_Blob_Info& req2 = req.SetRequest().SetGet_blob_info();
1413  x_SetResolve(req2.SetBlob_id().SetBlob_id(), blob_id);
1414  req2.SetGet_data();
1415  x_ProcessRequest(result, req, 0);
1416  if ( !blob.IsLoadedChunk() ) {
1417  CLoadLockSetter setter(blob);
1418  if ( !setter.IsLoaded() ) {
1419  ERR_POST_X(2, "ExtAnnot chunk is not loaded: "<<blob_id);
1420  setter.SetLoaded();
1421  }
1422  }
1423  }
1424  else {
1425  CID2S_Request_Get_Chunks& req2 = req.SetRequest().SetGet_chunks();
1426  x_SetResolve(req2.SetBlob_id(), blob_id);
1427 
1428  if ( blob.GetKnownBlobVersion() > 0 ) {
1429  req2.SetBlob_id().SetVersion(blob.GetKnownBlobVersion());
1430  }
1432  req2.SetChunks().push_back(CID2S_Chunk_Id(chunk_id));
1433  x_ProcessRequest(result, req, 0);
1434  }
1435  return true;
1436 }
1437 
1438 
1440  CID2_Request_Packet& packet,
1441  vector<TChunkId>& chunks,
1442  const CBlob_id& blob_id)
1443 {
1444  CLoadLockBlob blob(result, blob_id);
1445  NON_CONST_ITERATE(vector<TChunkId>, it, chunks) {
1446  blob.SelectChunk(*it);
1447  if ( !blob.IsLoadedChunk() ) {
1448  CLoadLockSetter setter(blob);
1449  if ( !setter.IsLoaded() ) {
1450  ERR_POST_X(3, "ExtAnnot chunk is not loaded: " << blob_id);
1451  setter.SetLoaded();
1452  }
1453  }
1454  }
1455  packet.Set().clear();
1456  chunks.clear();
1457 }
1458 
1459 
1461  const CBlob_id& blob_id,
1462  const TChunkIds& chunk_ids)
1463 {
1464  if ( chunk_ids.size() == 1 ) {
1465  return LoadChunk(result, blob_id, chunk_ids[0]);
1466  }
1467  size_t max_request_size = GetMaxChunksRequestSize();
1468  if ( SeparateChunksRequests(max_request_size) ) {
1469  return CReader::LoadChunks(result, blob_id, chunk_ids);
1470  }
1471  CLoadLockBlob blob(result, blob_id);
1472  _ASSERT(blob.IsLoadedBlob());
1473 
1474  CID2_Request_Packet packet;
1475 
1476  CRef<CID2_Request> chunks_req(new CID2_Request);
1477  CID2S_Request_Get_Chunks& get_chunks =
1478  chunks_req->SetRequest().SetGet_chunks();
1479 
1480  x_SetResolve(get_chunks.SetBlob_id(), blob_id);
1481  if ( blob.GetKnownBlobVersion() > 0 ) {
1482  get_chunks.SetBlob_id().SetVersion(blob.GetKnownBlobVersion());
1483  }
1484  get_chunks.SetSplit_version(blob.GetSplitInfo().GetSplitVersion());
1485  CID2S_Request_Get_Chunks::TChunks& chunks = get_chunks.SetChunks();
1486 
1487  vector<TChunkId> ext_chunks;
1488  ITERATE(TChunkIds, id, chunk_ids) {
1489  blob.SelectChunk(*id);
1490  if ( blob.IsLoadedChunk() ) {
1491  continue;
1492  }
1493  if ( *id == kDelayedMain_ChunkId ) {
1494  CRef<CID2_Request> ext_req(new CID2_Request);
1495  CID2_Request_Get_Blob_Info& ext_req_data =
1496  ext_req->SetRequest().SetGet_blob_info();
1497  x_SetResolve(ext_req_data.SetBlob_id().SetBlob_id(), blob_id);
1498  ext_req_data.SetGet_data();
1499  packet.Set().push_back(ext_req);
1500  ext_chunks.push_back(*id);
1501  if ( LimitChunksRequests(max_request_size) &&
1502  packet.Get().size() >= max_request_size ) {
1503  // Request collected chunks
1504  x_ProcessPacket(result, packet, 0);
1505  LoadedChunksPacket(result, packet, ext_chunks, blob_id);
1506  }
1507  }
1508  else {
1509  chunks.push_back(CID2S_Chunk_Id(*id));
1510  if ( LimitChunksRequests(max_request_size) &&
1511  chunks.size() >= max_request_size ) {
1512  // Process collected chunks
1513  x_ProcessRequest(result, *chunks_req, 0);
1514  chunks.clear();
1515  }
1516  }
1517  }
1518  if ( !chunks.empty() ) {
1519  if ( LimitChunksRequests(max_request_size) &&
1520  packet.Get().size() + chunks.size() > max_request_size ) {
1521  // process chunks separately from packet
1522  x_ProcessRequest(result, *chunks_req, 0);
1523  }
1524  else {
1525  // Use the same packet for chunks
1526  packet.Set().push_back(chunks_req);
1527  }
1528  }
1529  if ( !packet.Get().empty() ) {
1530  x_ProcessPacket(result, packet, 0);
1531  LoadedChunksPacket(result, packet, ext_chunks, blob_id);
1532  }
1533  return true;
1534 }
1535 
1536 
1538  const TSeqIds& seq_ids)
1539 {
1540  size_t max_request_size = GetMaxChunksRequestSize();
1541  if ( SeparateChunksRequests(max_request_size) ) {
1542  ITERATE(TSeqIds, id, seq_ids) {
1543  LoadSeq_idBlob_ids(result, *id, 0);
1544  }
1545  return true;
1546  }
1547  CID2_Request_Packet packet;
1548  ITERATE(TSeqIds, id, seq_ids) {
1549  CLoadLockBlobIds ids(result, *id, 0);
1550  if ( ids.IsLoaded() ) {
1551  continue;
1552  }
1553 
1555  x_SetResolve(req->SetRequest().SetGet_blob_id(), *id->GetSeqId());
1556  packet.Set().push_back(req);
1557  if ( LimitChunksRequests(max_request_size) &&
1558  packet.Get().size() >= max_request_size ) {
1559  // Request collected chunks
1560  x_ProcessPacket(result, packet, 0);
1561  packet.Set().clear();
1562  }
1563  }
1564  if ( !packet.Get().empty() ) {
1565  x_ProcessPacket(result, packet, 0);
1566  }
1567  return true;
1568 }
1569 
1570 
1572  const TSeqIds& seq_ids)
1573 {
1574  size_t max_request_size = GetMaxChunksRequestSize();
1575  if ( SeparateChunksRequests(max_request_size) ) {
1576  return CReader::LoadBlobSet(result, seq_ids);
1577  }
1578 
1579  bool loaded_blob_ids = false;
1580  size_t processed_requests = 0;
1582  if ( !x_LoadSeq_idBlob_idsSet(result, seq_ids) ) {
1583  return false;
1584  }
1585  loaded_blob_ids = true;
1586  }
1587 
1588  set<CBlob_id> load_blob_ids;
1589  CID2_Request_Packet packet;
1590  ITERATE(TSeqIds, id, seq_ids) {
1591  if ( !loaded_blob_ids &&
1593  if ( !x_LoadSeq_idBlob_idsSet(result, seq_ids) ) {
1594  return false;
1595  }
1596  loaded_blob_ids = true;
1597  }
1598  CLoadLockBlobIds ids(result, *id, 0);
1599  if ( ids && ids.IsLoaded() ) {
1600  // shortcut - we know Seq-id -> Blob-id resolution
1601  CFixedBlob_ids blob_ids = ids.GetBlob_ids();
1602  ITERATE ( CFixedBlob_ids, it, blob_ids ) {
1603  const CBlob_Info& info = *it;
1604  const CBlob_id& blob_id = *info.GetBlob_id();
1605  if ( (info.GetContentsMask() & fBlobHasCore) == 0 ) {
1606  continue; // skip this blob
1607  }
1608  CLoadLockBlob blob(result, blob_id);
1609  if ( blob.IsLoadedBlob() ) {
1610  continue;
1611  }
1612  if ( !load_blob_ids.insert(blob_id).second ) {
1613  continue;
1614  }
1617  req->SetRequest().SetGet_blob_info();
1618  x_SetResolve(req2.SetBlob_id().SetBlob_id(), blob_id);
1620  packet.Set().push_back(req);
1621  if ( LimitChunksRequests(max_request_size) &&
1622  packet.Get().size() >= max_request_size ) {
1623  processed_requests += packet.Set().size();
1624  x_ProcessPacket(result, packet, 0);
1625  packet.Set().clear();
1626  }
1627  }
1628  }
1629  else {
1632  req->SetRequest().SetGet_blob_info();
1633  x_SetResolve(req2.SetBlob_id().SetResolve().SetRequest(),
1634  *id->GetSeqId());
1636  x_SetExclude_blobs(req2, *id, result);
1637  packet.Set().push_back(req);
1638  if ( LimitChunksRequests(max_request_size) &&
1639  packet.Get().size() >= max_request_size ) {
1640  processed_requests += packet.Set().size();
1641  x_ProcessPacket(result, packet, 0);
1642  packet.Set().clear();
1643  }
1644  }
1645  }
1646  if ( !packet.Get().empty() ) {
1647  processed_requests += packet.Get().size();
1648  x_ProcessPacket(result, packet, 0);
1649  }
1650  if ( !processed_requests && !loaded_blob_ids ) {
1651  return false;
1652  }
1653  return true;
1654 }
1655 
1656 
1658  CID2_Request& req,
1659  const SAnnotSelector* sel)
1660 {
1661  CID2_Request_Packet packet;
1662  packet.Set().push_back(Ref(&req));
1663  x_ProcessPacket(result, packet, sel);
1664 }
1665 
1666 
1668 {
1671  vector<const CID2_Request*> requests;
1672 };
1673 
1674 
1676 {
1678  vector<TRequestReplies> replies;
1679 };
1680 
1681 
1683 {
1685  CID2Processor::TReplies replies; // in backward order to use pop_back()
1686 };
1687 
1688 
1690 {
1691  vector<SId2ProcessorStage> stages;
1692  unique_ptr<CReaderAllocatedConnection> conn;
1693 
1695  return conn? *conn: 0;
1696  }
1697 };
1698 
1699 
1701 {
1702  if (params.IsSetEnableSNP()) {
1703  SetVDB_SNP_Enabled(params.GetEnableSNP());
1704  }
1705  if (params.IsSetEnableWGS()) {
1706  SetVDB_WGS_Enabled(params.GetEnableWGS());
1707  }
1708  if (params.IsSetEnableCDD()) {
1709  SetVDB_CDD_Enabled(params.GetEnableCDD());
1710  }
1711 }
1712 
1713 
1715 {
1716  if ( request.GetRequest().IsInit() ) {
1717  CRef<CID2_Param> param(new CID2_Param);
1718  param->SetName("log:client_name");
1719  param->SetValue().push_back(GetDiagContext().GetAppName());
1720  request.SetParams().Set().push_back(param);
1721  if ( 1 ) {
1722  CRef<CID2_Param> param(new CID2_Param);
1723  param->SetName("id2:allow");
1724  // allow new blob-state field in several ID2 replies
1725  param->SetValue().push_back("*.blob-state");
1726  if ( GetVDB_WGS_Enabled() ) {
1727  // enable VDB-based WGS sequences
1728  param->SetValue().push_back("vdb-wgs");
1729  }
1730  if ( GetVDB_SNP_Enabled() ) {
1731  // enable VDB-based SNP sequences
1732  param->SetValue().push_back("vdb-snp");
1733  }
1734  if ( GetVDB_CDD_Enabled() ) {
1735  // enable VDB-based CDD sequences
1736  param->SetValue().push_back("vdb-cdd");
1737  }
1738  request.SetParams().Set().push_back(param);
1739  }
1740  auto scale_limit = GetSNP_Scale_Limit();
1741  if (scale_limit != CSeq_id::eSNPScaleLimit_Default) {
1742  CRef<CID2_Param> param(new CID2_Param);
1743  param->SetName("snp:scale-limit");
1744  param->SetValue().push_back(CSeq_id::GetSNPScaleLimit_Name(scale_limit));
1745  request.SetParams().Set().push_back(param);
1746  }
1747  }
1749  if ( rctx.IsSetSessionID() ) {
1750  CRef<CID2_Param> param(new CID2_Param);
1751  param->SetName("session_id");
1752  param->SetValue().push_back(rctx.GetSessionID());
1753  request.SetParams().Set().push_back(param);
1754  }
1755  if ( rctx.IsSetHitID() ) {
1756  CRef<CID2_Param> param(new CID2_Param);
1757  param->SetName("log:ncbi_phid");
1758  param->SetValue().push_back(rctx.GetNextSubHitID());
1759  request.SetParams().Set().push_back(param);
1760  }
1761  if ( rctx.IsSetClientIP() ) {
1762  CRef<CID2_Param> param(new CID2_Param);
1763  param->SetName("log:client_ip");
1764  param->SetValue().push_back(rctx.GetClientIP());
1765  request.SetParams().Set().push_back(param);
1766  }
1767 }
1768 
1769 
1770 #define x_GetReaderName(conn) \
1771  (x_ConnDescription((conn)).empty()? "CPubseq2Reader": "CId2Reader")
1772 
1773 
1775  const CID2_Request_Packet& packet,
1776  const char* msg)
1777 {
1778  if ( GetDebugLevel() >= eTraceConn ) {
1780  s << msg;
1781  if ( GetDebugLevel() >= eTraceASN ) {
1782  s << ": " << MSerial_AsnText << packet;
1783  }
1784  else {
1785  s << " ID2-Request-Packet";
1786  }
1787  s << "...";
1788  }
1789 }
1790 
1791 
1793  CID2_Reply& reply,
1794  const char* msg)
1795 {
1796  if ( GetDebugLevel() >= eTraceConn ) {
1798  s << msg;
1799  if ( GetDebugLevel() >= eTraceASN ) {
1800  if ( GetDebugLevel() >= eTraceBlobData ) {
1801  s << ": " << MSerial_AsnText << reply;
1802  }
1803  else {
1804  CTypeIterator<CID2_Reply_Data> iter = Begin(reply);
1805  if ( iter && iter->IsSetData() ) {
1807  save.swap(iter->SetData());
1808  size_t size = 0, count = 0, max_chunk = 0;
1809  ITERATE ( CID2_Reply_Data::TData, i, save ) {
1810  ++count;
1811  size_t chunk = (*i)->size();
1812  size += chunk;
1813  max_chunk = max(max_chunk, chunk);
1814  }
1815  s << ": " << MSerial_AsnText << reply <<
1816  "Data: " << size << " bytes in " <<
1817  count << " chunks with " <<
1818  max_chunk << " bytes in chunk max";
1819  save.swap(iter->SetData());
1820  }
1821  else {
1822  s << ": " << MSerial_AsnText << reply;
1823  }
1824  }
1825  }
1826  else {
1827  s << " ID2-Reply.";
1828  }
1829  }
1830  if ( GetDebugLevel() >= eTraceBlob ) {
1831  for ( CTypeConstIterator<CID2_Reply_Data> it(Begin(reply));
1832  it; ++it ) {
1833  if ( it->IsSetData() ) {
1834  try {
1836  }
1837  catch ( CException& exc ) {
1838  ERR_POST_X(1, "Exception while dumping data: "
1839  <<exc);
1840  }
1841  }
1842  }
1843  }
1844 }
1845 
1846 
1848  CID2_Request_Packet& packet)
1849 {
1851  x_DumpPacket(conn, packet);
1852  try {
1853  x_SendPacket(conn, packet);
1854  }
1855  catch ( CException& exc ) {
1856  NCBI_RETHROW(exc, CLoaderException, eConnectionFailed,
1857  "failed to send request: "+
1859  }
1860  if ( GetDebugLevel() >= eTraceConn ) {
1862  s << "Sent ID2-Request-Packet.";
1863  }
1864 }
1865 
1866 
1868 {
1869  if ( GetDebugLevel() >= eTraceConn ) {
1871  s << "Receiving ID2-Reply...";
1872  }
1873  CRef<CID2_Reply> reply(new CID2_Reply);
1874  try {
1875  x_ReceiveReply(conn, *reply);
1876  }
1877  catch ( CException& exc ) {
1878  NCBI_RETHROW(exc, CLoaderException, eConnectionFailed,
1879  "reply deserialization failed: "+
1881  }
1882  x_DumpReply(conn, *reply);
1884  return reply;
1885 }
1886 
1887 
1890  CID2_Request_Packet& packet)
1891 {
1893  x_DumpPacket(0, packet, "Processing");
1894  size_t proc_count = m_Processors.size();
1895  state.stages.reserve(proc_count);
1896  for ( size_t i = 0; i < proc_count; ++i ) {
1897  if ( packet.Get().empty() ) {
1898  return;
1899  }
1900  state.stages.resize(i+1);
1902  SId2ProcessorStage& stage = state.stages[i];
1903  stage.packet_context = info.processor->ProcessPacket(info.context, packet, stage.replies);
1904  if ( GetDebugLevel() >= eTraceConn &&
1905  !stage.replies.empty() ) {
1906  x_DumpPacket(0, packet, "Filtered");
1907  for ( auto& it : stage.replies ) {
1908  x_DumpReply(0, *it, "Got from processor");
1909  }
1910  }
1911  reverse(stage.replies.begin(), stage.replies.end());
1912  }
1913  if ( packet.Get().empty() ) {
1914  return;
1915  }
1916  state.conn.reset(new CConn(result, this));
1917  TConn conn = state.GetConn();
1918  try {
1919  if ( GetDebugLevel() >= eTraceConn ) {
1921  s << "Sending ID2-Request-Packet...";
1922  }
1923  x_SendPacket(conn, packet);
1924  if ( GetDebugLevel() >= eTraceConn ) {
1926  s << "Sent ID2-Request-Packet.";
1927  }
1928  }
1929  catch ( CException& exc ) {
1930  NCBI_RETHROW(exc, CLoaderException, eConnectionFailed,
1931  "failed to send request: "+
1933  }
1934 }
1935 
1936 
1938 {
1939  if ( pos < state.stages.size() ) {
1940  SId2ProcessorStage& stage = state.stages[pos];
1942  while ( stage.replies.empty() ) {
1944  info.processor->ProcessReply(info.context, stage.packet_context, *reply, stage.replies);
1945  if ( GetDebugLevel() >= eTraceConn &&
1946  (stage.replies.size() != 1 || stage.replies[0] != reply) ) {
1947  x_DumpReply(0, *reply, "Filtered by processor");
1948  for ( auto& it : stage.replies ) {
1949  x_DumpReply(0, *it, "New from processor");
1950  }
1951  }
1952  reverse(stage.replies.begin(), stage.replies.end());
1953  }
1954  CRef<CID2_Reply> reply = stage.replies.back();
1955  stage.replies.pop_back();
1956  return reply;
1957  }
1958  else {
1959  _ASSERT(state.conn);
1960  TConn conn = state.GetConn();
1961  for (;;) {
1962  if ( GetDebugLevel() >= eTraceConn ) {
1964  s << "Receiving ID2-Reply...";
1965  }
1966  CRef<CID2_Reply> reply(new CID2_Reply);
1967  try {
1968  x_ReceiveReply(conn, *reply);
1969  }
1970  catch ( CException& exc ) {
1971  NCBI_RETHROW(exc, CLoaderException, eConnectionFailed,
1972  "reply deserialization failed: "+
1974  }
1975  x_DumpReply(conn, *reply);
1976  if ( reply->IsSetDiscard() ) {
1977  continue;
1978  }
1979  return reply;
1980  }
1981  }
1982 }
1983 
1984 
1986 {
1989  return reply;
1990 }
1991 
1992 
1994  CID2_Request_Packet& packet)
1995 {
1996  // Fill request context information
1997  if ( !packet.Get().empty() ) {
1998  x_SetContextData(*packet.Set().front());
1999  }
2000 
2001  // prepare serial nums and result state
2002  for ( auto& i : packet.Get() ) {
2003  info.requests.push_back(i.GetPointer());
2004  }
2005  info.request_count = static_cast<int>(info.requests.size());
2006  info.remaining_count = info.request_count;
2007  int end_serial_num =
2008  static_cast<int>(m_RequestSerialNumber.Add(info.request_count));
2009  while ( end_serial_num <= info.request_count ) {
2010  // int overflow, adjust to 1
2011  {{
2012  DEFINE_STATIC_FAST_MUTEX(sx_Mutex);
2013  CFastMutexGuard guard(sx_Mutex);
2014  int num = static_cast<int>(m_RequestSerialNumber.Get());
2015  if ( num <= info.request_count ) {
2017  }
2018  }}
2019  end_serial_num =
2020  static_cast<int>(m_RequestSerialNumber.Add(info.request_count));
2021  }
2022  info.start_serial_num = end_serial_num - info.request_count;
2023  {{
2024  int cur_serial_num = info.start_serial_num;
2026  (*it)->SetSerial_number(cur_serial_num++);
2027  }
2028  }}
2029 }
2030 
2031 
2033  CConn* conn,
2034  SId2PacketInfo& packet,
2035  const CID2_Reply& reply)
2036 {
2037  int num = reply.IsSetSerial_number()? reply.GetSerial_number() - packet.start_serial_num: -1;
2038  if ( reply.IsSetDiscard() ) {
2039  // discard whole reply for now
2040  return -1;
2041  }
2042  if ( num < 0 || num >= packet.request_count || !packet.requests[num] ) {
2043  // unknown serial num - bad reply
2044  string descr;
2045  if ( conn ) {
2046  descr = x_ConnDescription(*conn);
2047  }
2048  else {
2049  descr = " (processor)";
2050  }
2051  if ( TErrorFlags error = x_GetError(result, reply) ) {
2052  if ( error & fError_inactivity_timeout ) {
2053  if ( conn ) {
2054  conn->Restart();
2055  }
2056  NCBI_THROW_FMT(CLoaderException, eRepeatAgain,
2057  "CId2ReaderBase: connection timed out"<<descr);
2058  }
2059  if ( error & fError_bad_connection ) {
2060  NCBI_THROW_FMT(CLoaderException, eConnectionFailed,
2061  "CId2ReaderBase: connection failed"<<descr);
2062  }
2063  if ( error & fError_failed_command ) {
2064  NCBI_THROW_FMT(CLoaderException, eOtherError,
2065  "CId2ReaderBase: failed command"<<descr);
2066  }
2067  }
2068  else if ( reply.GetReply().IsEmpty() ) {
2069  ERR_POST_X(8, "CId2ReaderBase: bad reply serial number: "<<descr);
2070  return num;
2071  }
2072  NCBI_THROW_FMT(CLoaderException, eOtherError,
2073  "CId2ReaderBase: bad reply serial number: "<<descr);
2074  }
2075  return num;
2076 }
2077 
2078 
2080  int num,
2081  const CID2_Reply& reply)
2082 {
2083  if ( reply.IsSetEnd_of_reply() ) {
2084  info.requests[num] = 0;
2085  --info.remaining_count;
2086  return true;
2087  }
2088  return false;
2089 }
2090 
2091 
2093  CID2_Request_Packet& packet,
2094  const SAnnotSelector* sel)
2095 {
2096  SId2PacketInfo packet_info;
2097  x_AssignSerialNumbers(packet_info, packet);
2098 
2099  vector<SId2LoadedSet> loaded_sets(packet_info.request_count);
2100 
2102  CRef<CID2_Reply> reply;
2103  try {
2104  // send request
2105  x_SendID2Packet(result, state, packet);
2106 
2107  // process replies
2108  while ( packet_info.remaining_count > 0 ) {
2109  reply = x_ReceiveID2Reply(state);
2110  int num = x_GetReplyIndex(result, state.conn.get(), packet_info, *reply);
2111  if ( num >= 0 ) {
2112  try {
2113  x_ProcessReply(result, loaded_sets[num], *reply, *packet_info.requests[num]);
2114  }
2115  catch ( CLoaderException& /*rethrown*/ ) {
2116  throw;
2117  }
2118  catch ( CException& exc ) {
2119  NCBI_RETHROW(exc, CLoaderException, eOtherError,
2120  "CId2ReaderBase: failed to process reply: "+
2121  x_ConnDescription(state.GetConn()));
2122  }
2123  if ( x_DoneReply(packet_info, num, *reply) ) {
2124  x_UpdateLoadedSet(result, loaded_sets[num], sel);
2125  }
2126  }
2127  reply.Reset();
2128  }
2129  if ( state.conn ) {
2130  x_EndOfPacket(*state.conn);
2131  }
2132  }
2133  catch ( exception& /*rethrown*/ ) {
2134  if ( GetDebugLevel() >= eTraceError ) {
2135  CDebugPrinter s(state.GetConn(), x_GetReaderName(state.GetConn()));
2136  s << "Error processing request: " << MSerial_AsnText << packet;
2137  if ( reply &&
2138  (reply->IsSetSerial_number() ||
2139  reply->IsSetParams() ||
2140  reply->IsSetError() ||
2141  reply->IsSetEnd_of_reply() ||
2142  reply->IsSetReply()) ) {
2143  try {
2144  s << "Last reply: " << MSerial_AsnText << *reply;
2145  }
2146  catch ( exception& /*ignored*/ ) {
2147  }
2148  }
2149  }
2150  throw;
2151  }
2152  if ( state.conn ) {
2153  state.conn->Release();
2154  }
2155 }
2156 
2157 
2159  TConn /*conn*/,
2160  CID2_Reply& reply)
2161 {
2162  stream >> reply;
2163 }
2164 
2165 
2167 {
2168  // do nothing by default
2169 }
2170 
2171 
2173  SId2LoadedSet& data,
2174  const SAnnotSelector* sel)
2175 {
2177  data.m_Seq_ids ) {
2178  SetAndSaveSeq_idSeq_ids(result, it->first,
2180  it->second.second,
2181  it->second.first));
2182  }
2183  data.m_Seq_ids.clear();
2185  CLoadLockBlobIds ids(result, it->first, sel);
2186  if ( ids.IsLoaded() ) {
2187  continue;
2188  }
2189  int state = it->second.first;
2190  TBlobIds blob_ids;
2191  ITERATE ( SId2LoadedSet::TBlob_ids, it2, it->second.second ) {
2192  CConstRef<CBlob_id> blob_id(new CBlob_id(it2->first));
2193  CBlob_Info blob_info(blob_id, it2->second.m_ContentMask);
2194  const SId2BlobInfo::TAnnotInfo& ainfos = it2->second.m_AnnotInfo;
2195  CRef<CBlob_Annot_Info> blob_annot_info;
2196  ITERATE ( SId2BlobInfo::TAnnotInfo, it3, ainfos ) {
2197  CID2S_Seq_annot_Info& annot_info = it3->GetNCObject();
2198  if ( !blob_annot_info ) {
2199  blob_annot_info = new CBlob_Annot_Info;
2200  }
2201  if ( (it2->second.m_ContentMask & fBlobHasNamedAnnot) &&
2202  annot_info.IsSetName() ) {
2203  blob_annot_info->AddNamedAnnotName(annot_info.GetName());
2204  // Heuristics to determine incorrect annot info records.
2205  if ( (annot_info.IsSetAlign() || annot_info.IsSetFeat()) &&
2206  annot_info.IsSetGraph() && ainfos.size() == 1 &&
2207  !ExtractZoomLevel(annot_info.GetName(), 0, 0) ) {
2208  // graphs are suppozed to be zoom tracks
2209  if ( GetDebugLevel() >= eTraceASN ) {
2210  CDebugPrinter s(0, x_GetReaderName(0));
2211  s << "Adding zoom tracks for "
2212  << MSerial_AsnText << annot_info;
2213  }
2214  for ( int zoom = 10; zoom < 1000000; zoom *= 10 ) {
2215  CRef<CID2S_Seq_annot_Info> zoom_info;
2216  zoom_info = SerialClone(annot_info);
2217  zoom_info->ResetFeat();
2218  zoom_info->ResetAlign();
2219  zoom_info->SetName(CombineWithZoomLevel(annot_info.GetName(), zoom));
2220  blob_annot_info->AddAnnotInfo(*zoom_info);
2221  }
2222  annot_info.ResetGraph();
2223  }
2224  }
2225 
2226  if ( annot_info.IsSetName() &&
2227  annot_info.IsSetSeq_loc() &&
2228  (annot_info.IsSetAlign() ||
2229  annot_info.IsSetGraph() ||
2230  annot_info.IsSetFeat()) ) {
2231  // complete annot info
2232  blob_annot_info->AddAnnotInfo(annot_info);
2233  }
2234  }
2235  if ( blob_annot_info &&
2236  !(blob_annot_info->GetAnnotInfo().empty() &&
2237  blob_annot_info->GetNamedAnnotNames().empty()) ) {
2238  blob_info.SetAnnotInfo(blob_annot_info);
2239  }
2240  blob_ids.push_back(blob_info);
2241  }
2242  SetAndSaveSeq_idBlob_ids(result, it->first, sel, ids,
2243  CFixedBlob_ids(eTakeOwnership, blob_ids,
2244  state));
2245  }
2246 }
2247 
2248 
2250  TErrorFlags& error_flags,
2251  EErrorFlags test_flag,
2252  const char* marker1,
2253  const char* marker2)
2254 {
2255  if ( !error.IsSetMessage() ) {
2256  // no message to parse
2257  return;
2258  }
2259  if ( error_flags & test_flag ) {
2260  // already set
2261  return;
2262  }
2263  SIZE_TYPE pos = NStr::FindNoCase(error.GetMessage(), marker1);
2264  if ( pos == NPOS) {
2265  // no marker
2266  return;
2267  }
2268  if ( marker2 &&
2269  NStr::FindNoCase(error.GetMessage(), marker2, pos) == NPOS ) {
2270  // no second marker
2271  return;
2272  }
2273  error_flags |= test_flag;
2274 }
2275 
2276 
2279  const CID2_Error& error)
2280 {
2281  TErrorFlags error_flags = 0;
2282  switch ( error.GetSeverity() ) {
2284  error_flags |= fError_warning;
2285  if ( error.IsSetMessage() ) {
2286  const string& msg = error.GetMessage();
2287  if ( msg.find("PTIS_FAILURE") != NPOS ) {
2288  EGBErrorAction action = result.GetPTISErrorAction();
2289  if ( action == eGBErrorAction_throw ) {
2290  NCBI_THROW_FMT(CLoaderException, eConnectionFailed, msg);
2291  }
2292  if ( action == eGBErrorAction_report ) {
2293  ERR_POST_X(16, Warning<<msg);
2294  }
2295  }
2296  }
2297  break;
2299  error_flags |= fError_failed_command;
2300  break;
2302  error_flags |= fError_bad_connection;
2303  if ( error.IsSetMessage() ) {
2304  sx_CheckErrorFlag(error, error_flags,
2305  fError_inactivity_timeout, "timed", "out");
2306  }
2307  break;
2309  error_flags |= fError_bad_connection;
2310  break;
2312  error_flags |= fError_no_data;
2313  break;
2315  error_flags |= fError_restricted | fError_no_data;
2316  break;
2319  error_flags |= fError_bad_command;
2320  break;
2322  error_flags |= fError_bad_command;
2323  break;
2324  }
2325  if ( error.IsSetRetry_delay() ) {
2326  result.AddRetryDelay(error.GetRetry_delay());
2327  }
2328  return error_flags;
2329 }
2330 
2331 
2334 {
2335  TErrorFlags error_flags = 0;
2336  switch ( error.GetSeverity() ) {
2338  error_flags |= fError_warning;
2339  if ( error.IsSetMessage() ) {
2340  sx_CheckErrorFlag(error, error_flags,
2341  fError_warning_dead, "obsolete");
2342  sx_CheckErrorFlag(error, error_flags,
2343  fError_suppressed_perm, "removed");
2344  sx_CheckErrorFlag(error, error_flags,
2345  fError_suppressed_perm, "suppressed");
2346  sx_CheckErrorFlag(error, error_flags,
2347  fError_suppressed_perm, "superceded"); // temp?
2348  sx_CheckErrorFlag(error, error_flags,
2349  fError_suppressed_temp, "superseded"); // perm?
2350  sx_CheckErrorFlag(error, error_flags,
2352  "Unknown satellite number 20 for bioseq info");
2353  if ( error_flags & fError_restricted ) {
2354  error_flags |= fError_no_data;
2355  }
2356  }
2357  break;
2359  error_flags |= fError_failed_command;
2360  break;
2362  error_flags |= fError_bad_connection;
2363  break;
2365  error_flags |= fError_bad_connection;
2366  break;
2368  error_flags |= fError_no_data;
2369  break;
2371  error_flags |= fError_no_data;
2372  if ( error.IsSetMessage() ) {
2373  sx_CheckErrorFlag(error, error_flags,
2374  fError_withdrawn, "withdrawn");
2375  sx_CheckErrorFlag(error, error_flags,
2376  fError_withdrawn, "removed");
2377  }
2378  if ( !(error_flags & fError_withdrawn) ) {
2379  error_flags |= fError_restricted;
2380  }
2381  break;
2384  error_flags |= fError_bad_command;
2385  break;
2387  error_flags |= fError_bad_command;
2388  break;
2389  }
2390  return error_flags;
2391 }
2392 
2393 
2396  const CID2_Reply& reply)
2397 {
2398  TErrorFlags errors = 0;
2399  if ( reply.IsSetError() ) {
2400  ITERATE ( CID2_Reply::TError, it, reply.GetError() ) {
2401  errors |= x_GetError(result, **it);
2402  }
2403  }
2404  return errors;
2405 }
2406 
2407 
2410 {
2411  TErrorFlags errors = 0;
2412  if ( reply.IsSetError() ) {
2413  ITERATE ( CID2_Reply::TError, it, reply.GetError() ) {
2414  errors |= x_GetMessageError(**it);
2415  }
2416  }
2417  return errors;
2418 }
2419 
2420 
2423  SId2LoadedSet& loaded_set,
2424  int id2_state)
2425 {
2426  TBlobState blob_state = 0;
2427  if ( id2_state & (1<<eID2_Blob_State_suppressed_temp) ) {
2429  }
2430  if ( id2_state & (1<<eID2_Blob_State_suppressed) ) {
2432  }
2433  if ( id2_state & (1<<eID2_Blob_State_dead) ) {
2434  blob_state |= CBioseq_Handle::fState_dead;
2435  }
2436  if ( id2_state & (1<<eID2_Blob_State_protected) ) {
2438  blob_state |= CBioseq_Handle::fState_no_data;
2439  }
2440  if ( id2_state & (1<<eID2_Blob_State_withdrawn) ) {
2441  blob_state |= CBioseq_Handle::fState_withdrawn;
2442  blob_state |= CBioseq_Handle::fState_no_data;
2443  }
2444  if ( blob_state ) {
2445  loaded_set.m_BlobStates[blob_id] |= blob_state;
2446  }
2447  return blob_state;
2448 }
2449 
2450 
2451 
2454  SId2LoadedSet& loaded_set,
2455  const CID2_Reply& reply,
2456  TErrorFlags* errors_ptr)
2457 {
2459  loaded_set.m_BlobStates.find(blob_id);
2460  if ( it != loaded_set.m_BlobStates.end() ) {
2461  return it->second;
2462  }
2463 
2464  TBlobState blob_state = 0;
2465  TErrorFlags errors = x_GetMessageError(reply);
2466  if ( errors_ptr ) {
2467  *errors_ptr = errors;
2468  }
2469  if ( errors & fError_no_data ) {
2470  blob_state |= CBioseq_Handle::fState_no_data;
2471  if ( errors & fError_restricted ) {
2473  }
2474  if ( errors & fError_withdrawn ) {
2475  blob_state |= CBioseq_Handle::fState_withdrawn;
2476  }
2477  }
2478  if ( errors & fError_warning_dead ) {
2479  blob_state |= CBioseq_Handle::fState_dead;
2480  }
2481  if ( errors & fError_suppressed_perm ) {
2483  }
2484  else if ( errors & fError_suppressed_temp ) {
2486  }
2487  return blob_state;
2488 }
2489 
2490 
2492  SId2LoadedSet& loaded_set,
2493  const CID2_Reply& main_reply,
2494  const CID2_Request& request)
2495 {
2496  if ( auto error = x_GetError(result, main_reply) ) {
2497  if ( error & fError_bad_connection ) {
2498  NCBI_THROW(CLoaderException, eConnectionFailed,
2499  "CId2ReaderBase: connection failed");
2500  }
2501  if ( error & fError_failed_command ) {
2502  ERR_POST_X(17, "CId2ReaderBase: failed command reply: "<<
2503  MSerial_AsnText<<main_reply<<
2504  MSerial_AsnText<<request);
2505  NCBI_THROW(CLoaderException, eOtherError,
2506  "CId2ReaderBase: failed command");
2507  }
2508  }
2509  auto& reply = main_reply.GetReply();
2510  switch ( reply.Which() ) {
2512  x_ProcessGetSeqId(result, loaded_set, main_reply,
2513  reply.GetGet_seq_id().GetRequest(),
2514  &reply.GetGet_seq_id());
2515  break;
2517  x_ProcessGetBlobId(result, loaded_set, main_reply,
2518  reply.GetGet_blob_id());
2519  break;
2521  x_ProcessGetBlobSeqIds(result, loaded_set, main_reply,
2522  reply.GetGet_blob_seq_ids());
2523  break;
2525  x_ProcessGetBlob(result, loaded_set, main_reply,
2526  reply.GetGet_blob());
2527  break;
2529  x_ProcessGetSplitInfo(result, loaded_set, main_reply,
2530  reply.GetGet_split_info());
2531  break;
2533  x_ProcessGetChunk(result, loaded_set, main_reply,
2534  reply.GetGet_chunk());
2535  break;
2537  x_ProcessEmptyReply(result, loaded_set, main_reply, request);
2538  break;
2539  default:
2540  break;
2541  }
2542 }
2543 
2544 
2546  SId2LoadedSet& loaded_set,
2547  const CID2_Reply& main_reply,
2548  const CID2_Request& main_request)
2549 {
2550  TErrorFlags errors = x_GetMessageError(main_reply);
2551  if ( errors & fError_no_data ) {
2552  auto& request = main_request.GetRequest();
2553  switch ( request.Which() ) {
2555  x_ProcessGetSeqId(result, loaded_set, main_reply, request.GetGet_seq_id(), 0);
2556  break;
2558  if ( request.GetGet_blob_id().IsSetSeq_id() ) {
2559  auto& req_id = request.GetGet_blob_id().GetSeq_id().GetSeq_id();
2560  if ( req_id.IsSeq_id() ) {
2562  return;
2563  }
2564  }
2565  break;
2567  if ( request.GetGet_blob_info().GetBlob_id().IsResolve() ) {
2568  auto& req_id = request.GetGet_blob_info().GetBlob_id().GetResolve().GetRequest().GetSeq_id().GetSeq_id();
2569  if ( req_id.IsSeq_id() ) {
2571  return;
2572  }
2573  }
2574  break;
2575  default:
2576  break;
2577  }
2578  }
2579 }
2580 
2581 
2583  SId2LoadedSet& loaded_set,
2584  const CID2_Reply& main_reply,
2585  const CID2_Request_Get_Seq_id& request,
2586  const CID2_Reply_Get_Seq_id* reply)
2587 {
2588  // we can save this data in cache
2589  const CID2_Seq_id& req_id = request.GetSeq_id();
2590  switch ( req_id.Which() ) {
2591  case CID2_Seq_id::e_Seq_id:
2592  x_ProcessGetSeqIdSeqId(result, loaded_set, main_reply,
2594  request, reply);
2595  break;
2596 
2597  default:
2598  break;
2599  }
2600 }
2601 
2602 
2603 static bool sx_IsSpecialId(const CSeq_id& id)
2604 {
2605  if ( !id.IsGeneral() ) {
2606  return false;
2607  }
2608  const string& db = id.GetGeneral().GetDb();
2609  return db == kSpecialId_length || db == kSpecialId_type;
2610 }
2611 
2612 
2615  SId2LoadedSet& loaded_set,
2616  const CID2_Reply& main_reply,
2617  const CSeq_id_Handle& seq_id,
2618  const CID2_Request_Get_Seq_id& req,
2619  const CID2_Reply_Get_Seq_id* reply)
2620 {
2621  int state = 0;
2622  TErrorFlags errors = x_GetMessageError(main_reply);
2623  if ( (errors & fError_no_data) &&
2624  (req.GetSeq_id_type() == req.eSeq_id_type_any ||
2625  (req.GetSeq_id_type()&req.eSeq_id_type_all)==req.eSeq_id_type_all) ) {
2627  // no Seq-ids
2628  if ( errors & fError_restricted ) {
2630  }
2631  if ( errors & fError_withdrawn ) {
2633  }
2635 
2636  if ( req.GetSeq_id_type() & req.eSeq_id_type_gi ) {
2638  }
2639  if ( req.GetSeq_id_type() & req.eSeq_id_type_text ) {
2641  }
2642  if ( req.GetSeq_id_type() & req.eSeq_id_type_label ) {
2643  SetAndSaveSeq_idLabel(result, seq_id, "");
2644  }
2645  if ( req.GetSeq_id_type() & req.eSeq_id_type_taxid ) {
2647  }
2648  if ( req.GetSeq_id_type() & req.eSeq_id_type_hash ) {
2650  }
2651  if ( req.GetSeq_id_type() & req.eSeq_id_type_seq_length ) {
2653  }
2654  if ( req.GetSeq_id_type() & req.eSeq_id_type_seq_mol ) {
2656  }
2657  return;
2658  }
2659  bool got_no_ids = false;
2660  if ( (req.GetSeq_id_type()&req.eSeq_id_type_all)==req.eSeq_id_type_all ) {
2661  CReader::TSeqIds seq_ids;
2662  if ( reply ) ITERATE ( CID2_Reply_Get_Seq_id::TSeq_id, it, reply->GetSeq_id() ) {
2663  if ( req.GetSeq_id_type() != req.eSeq_id_type_all &&
2664  sx_IsSpecialId(**it) ) {
2665  continue;
2666  }
2667  seq_ids.push_back(CSeq_id_Handle::GetHandle(**it));
2668  }
2669  if ( !reply || reply->IsSetEnd_of_reply() ) {
2670  got_no_ids = seq_ids.empty();
2673  seq_ids,
2674  state));
2675  }
2676  else {
2677  loaded_set.m_Seq_ids[seq_id].first = state;
2678  loaded_set.m_Seq_ids[seq_id].second.swap(seq_ids);
2679  }
2680  }
2681  if ( req.GetSeq_id_type() & req.eSeq_id_type_gi ) {
2682  TSequenceGi ret;
2683  if ( reply ) ITERATE ( CID2_Reply_Get_Seq_id::TSeq_id, it, reply->GetSeq_id() ) {
2684  if ( (**it).IsGi() ) {
2685  ret.gi = (**it).GetGi();
2686  break;
2687  }
2688  }
2689  ret.sequence_found = !got_no_ids;
2690  SetAndSaveSeq_idGi(result, seq_id, ret);
2691  }
2692  if ( req.GetSeq_id_type() & req.eSeq_id_type_text ) {
2693  TSequenceAcc ret;
2694  if ( reply ) ITERATE ( CID2_Reply_Get_Seq_id::TSeq_id, it, reply->GetSeq_id() ) {
2695  if ( (**it).GetTextseq_Id() ) {
2696  ret.acc_ver = CSeq_id_Handle::GetHandle(**it);
2697  break;
2698  }
2699  }
2700  ret.sequence_found = !got_no_ids;
2701  SetAndSaveSeq_idAccVer(result, seq_id, ret);
2702  }
2703  if ( req.GetSeq_id_type() & req.eSeq_id_type_label ) {
2704  if ( reply ) ITERATE ( CID2_Reply_Get_Seq_id::TSeq_id, it, reply->GetSeq_id() ) {
2705  const CSeq_id& id = **it;
2706  if ( id.IsGeneral() ) {
2707  const CDbtag& dbtag = id.GetGeneral();
2708  const CObject_id& obj_id = dbtag.GetTag();
2709  if ( obj_id.IsStr() && dbtag.GetDb() == kSpecialId_label ) {
2710  SetAndSaveSeq_idLabel(result, seq_id, obj_id.GetStr());
2711  break;
2712  }
2713  }
2714  }
2715  }
2716  if ( req.GetSeq_id_type() & req.eSeq_id_type_taxid ) {
2717  TTaxId taxid = INVALID_TAX_ID;
2718  if ( reply ) ITERATE ( CID2_Reply_Get_Seq_id::TSeq_id, it, reply->GetSeq_id() ) {
2719  const CSeq_id& id = **it;
2720  if ( id.IsGeneral() ) {
2721  const CDbtag& dbtag = id.GetGeneral();
2722  const CObject_id& obj_id = dbtag.GetTag();
2723  if ( obj_id.IsId() && dbtag.GetDb() == kSpecialId_taxid ) {
2724  taxid = TAX_ID_FROM(CObject_id::TId, obj_id.GetId());
2725  break;
2726  }
2727  }
2728  }
2729  if ( taxid != INVALID_TAX_ID ) {
2730  SetAndSaveSeq_idTaxId(result, seq_id, taxid);
2731  }
2732  }
2733  if ( req.GetSeq_id_type() & req.eSeq_id_type_hash ) {
2735  if ( reply ) ITERATE ( CID2_Reply_Get_Seq_id::TSeq_id, it, reply->GetSeq_id() ) {
2736  const CSeq_id& id = **it;
2737  if ( id.IsGeneral() ) {
2738  const CDbtag& dbtag = id.GetGeneral();
2739  const CObject_id& obj_id = dbtag.GetTag();
2740  if ( obj_id.IsId() && dbtag.GetDb() == kSpecialId_hash ) {
2741  hash.hash = obj_id.GetId();
2742  hash.sequence_found = true;
2743  hash.hash_known = true;
2744  break;
2745  }
2746  }
2747  }
2749  }
2750  if ( req.GetSeq_id_type() & req.eSeq_id_type_seq_length ) {
2751  TSeqPos length = kInvalidSeqPos;
2752  if ( reply ) ITERATE ( CID2_Reply_Get_Seq_id::TSeq_id, it, reply->GetSeq_id() ) {
2753  const CSeq_id& id = **it;
2754  if ( id.IsGeneral() ) {
2755  const CDbtag& dbtag = id.GetGeneral();
2756  const CObject_id& obj_id = dbtag.GetTag();
2757  if ( obj_id.IsId() && dbtag.GetDb() == kSpecialId_length ) {
2758  length = TSeqPos(obj_id.GetId());
2759  break;
2760  }
2761  }
2762  }
2763  if ( length != kInvalidSeqPos || got_no_ids ) {
2764  SetAndSaveSequenceLength(result, seq_id, length);
2765  }
2766  }
2767  if ( req.GetSeq_id_type() & req.eSeq_id_type_seq_mol ) {
2769  if ( reply ) ITERATE ( CID2_Reply_Get_Seq_id::TSeq_id, it, reply->GetSeq_id() ) {
2770  const CSeq_id& id = **it;
2771  if ( id.IsGeneral() ) {
2772  const CDbtag& dbtag = id.GetGeneral();
2773  const CObject_id& obj_id = dbtag.GetTag();
2774  if ( obj_id.IsId() && dbtag.GetDb() == kSpecialId_type ) {
2775  type.type = CSeq_inst::EMol(obj_id.GetId());
2776  type.sequence_found = true;
2777  break;
2778  }
2779  }
2780  }
2781  if ( type.sequence_found || got_no_ids ) {
2783  }
2784  }
2785 }
2786 
2787 
2790  SId2LoadedSet& loaded_set,
2791  const CID2_Reply& main_reply,
2792  const CID2_Reply_Get_Blob_Id& reply)
2793 {
2794  const CSeq_id& seq_id = reply.GetSeq_id();
2796  const CID2_Blob_Id& src_blob_id = reply.GetBlob_id();
2797  CBlob_id blob_id = GetBlobId(src_blob_id);
2798  TErrorFlags errors = 0;
2799  TBlobState blob_state;
2800  if ( reply.IsSetBlob_state() ) {
2801  blob_state = x_GetBlobStateFromID2(blob_id, loaded_set,
2802  reply.GetBlob_state());
2803  }
2804  else {
2805  blob_state = x_GetBlobState(blob_id, loaded_set, main_reply, &errors);
2806  }
2807  if ( blob_state & CBioseq_Handle::fState_no_data ) {
2808  SetAndSaveNoSeq_idBlob_ids(result, idh, 0, blob_state);
2809  return;
2810  }
2811  if ( (blob_state == 0) && (errors & fError_warning) ) {
2812  blob_state |= CBioseq_Handle::fState_other_error;
2813  }
2814 
2815  SId2LoadedSet::TBlob_idsInfo& ids = loaded_set.m_Blob_ids[idh];
2816  ids.first |= blob_state;
2817  if ( blob_state ) {
2818  loaded_set.m_BlobStates[blob_id] |= blob_state;
2819  }
2820  TContentsMask mask = 0;
2821  {{ // TODO: temporary logic, this info should be returned by server
2822  if ( (blob_id.GetSubSat() == CID2_Blob_Id::eSub_sat_main && !reply.IsSetAnnot_info()) ||
2826  }
2827  else {
2828  if ( seq_id.IsGeneral() ) {
2829  const CObject_id& obj_id = seq_id.GetGeneral().GetTag();
2830  if ( obj_id.IsId() &&
2831  obj_id.GetId8() == Uint4(blob_id.GetSatKey()) ) {
2833  }
2834  else {
2836  }
2837  }
2838  else {
2840  }
2841  }
2842  }}
2843  SId2BlobInfo& blob_info = ids.second[blob_id];
2844  if ( reply.IsSetAnnot_info() && mask == fBlobHasExtAnnot ) {
2845  blob_info.m_AnnotInfo = reply.GetAnnot_info();
2846  ITERATE ( SId2BlobInfo::TAnnotInfo, it, blob_info.m_AnnotInfo ) {
2847  const CID2S_Seq_annot_Info& info = **it;
2848  if ( info.IsSetName() && NStr::StartsWith(info.GetName(), "NA") ) {
2850  if ( info.IsSetFeat() ) {
2852  }
2853  if ( info.IsSetGraph() ) {
2855  }
2856  if ( info.IsSetAlign() ) {
2858  }
2859  }
2860  }
2861  }
2862  blob_info.m_ContentMask = mask;
2863  if ( src_blob_id.IsSetVersion() && src_blob_id.GetVersion() > 0 ) {
2864  SetAndSaveBlobVersion(result, blob_id, src_blob_id.GetVersion());
2865  }
2866 }
2867 
2868 
2870  CReaderRequestResult& /* result */,
2871  SId2LoadedSet& /*loaded_set*/,
2872  const CID2_Reply& /*main_reply*/,
2873  const CID2_Reply_Get_Blob_Seq_ids&/*reply*/)
2874 {
2875 /*
2876  if ( reply.IsSetIds() ) {
2877  CID2_Blob_Seq_ids ids;
2878  x_ReadData(reply.GetIds(), Begin(ids));
2879  ITERATE ( CID2_Blob_Seq_ids::Tdata, it, ids.Get() ) {
2880  if ( !(*it)->IsSetReplaced() ) {
2881  result.AddBlob_id((*it)->GetSeq_id(),
2882  GetBlobId(reply.GetBlob_id()), "");
2883  }
2884  }
2885  }
2886 */
2887 }
2888 
2889 
2892  SId2LoadedSet& loaded_set,
2893  const CID2_Reply& main_reply,
2894  const CID2_Reply_Get_Blob& reply)
2895 {
2896  TChunkId chunk_id = kMain_ChunkId;
2897  const CID2_Blob_Id& src_blob_id = reply.GetBlob_id();
2898  TBlobId blob_id = GetBlobId(src_blob_id);
2899 
2900  TBlobVersion blob_version = 0;
2901  if ( src_blob_id.IsSetVersion() && src_blob_id.GetVersion() > 0 ) {
2902  blob_version = src_blob_id.GetVersion();
2903  SetAndSaveBlobVersion(result, blob_id, blob_version);
2904  }
2905 
2906  TBlobState blob_state;
2907  if ( reply.IsSetBlob_state() ) {
2908  blob_state = x_GetBlobStateFromID2(blob_id, loaded_set,
2909  reply.GetBlob_state());
2910  }
2911  else {
2912  blob_state = x_GetBlobState(blob_id, loaded_set, main_reply);
2913  }
2914  if ( blob_state & CBioseq_Handle::fState_no_data ) {
2915  SetAndSaveNoBlob(result, blob_id, chunk_id, blob_state);
2916  return;
2917  }
2918 
2919  if ( !blob_version ) {
2920  CLoadLockBlobVersion lock(result, blob_id);
2921  if ( !lock.IsLoadedBlobVersion() ) {
2922  // need some reference blob version to work with
2923  // but not save it into cache
2924  SetAndSaveBlobVersion(result, blob_id, 0);
2925  //state.SetLoadedBlobVersion(0);
2926  }
2927  }
2928 
2929  if ( !reply.IsSetData() ) {
2930  // assume only blob info reply
2931  if ( blob_state ) {
2932  loaded_set.m_BlobStates[blob_id] |= blob_state;
2933  }
2934  return;
2935  }
2936 
2937  const CID2_Reply_Data& data = reply.GetData();
2938  if ( data.GetData().empty() ) {
2939  if ( reply.GetSplit_version() != 0 &&
2940  data.GetData_type() == data.eData_type_seq_entry ) {
2941  // Skeleton Seq-entry could be attached to the split-info
2942  ERR_POST_X(6, Warning << "CId2ReaderBase: ID2-Reply-Get-Blob: "
2943  "no data in reply: "<<blob_id);
2944  return;
2945  }
2946  ERR_POST_X(7, "CId2ReaderBase: ID2-Reply-Get-Blob: "
2947  "no data in reply: "<<blob_id);
2948  SetAndSaveNoBlob(result, blob_id, chunk_id, blob_state);
2949  return;
2950  }
2951 
2952  if ( reply.GetSplit_version() != 0 ) {
2953  // split info will follow
2954  // postpone parsing this blob
2955  loaded_set.m_Skeletons[blob_id] = &data;
2956  return;
2957  }
2958 
2959  CLoadLockBlob blob(result, blob_id);
2960  if ( blob.IsLoadedBlob() ) {
2961  if ( blob.NeedsDelayedMainChunk() ) {
2962  chunk_id = kDelayedMain_ChunkId;
2963  blob.SelectChunk(chunk_id);
2964  }
2965  if ( blob.IsLoadedChunk() ) {
2967  ERR_POST_X(4, Info << "CId2ReaderBase: ID2-Reply-Get-Blob: "
2968  "blob already loaded: "<<blob_id);
2969  return;
2970  }
2971  }
2972 
2973  if ( blob_state ) {
2974  result.SetAndSaveBlobState(blob_id, blob_state);
2975  }
2976 
2977  if ( reply.GetBlob_id().GetSub_sat() == CID2_Blob_Id::eSub_sat_snp ) {
2979  .ProcessBlobFromID2Data(result, blob_id, chunk_id, data);
2980  }
2981  else {
2982  dynamic_cast<const CProcessor_ID2&>
2984  .ProcessData(result, blob_id, blob_state, chunk_id, data);
2985  }
2986  _ASSERT(blob.IsLoadedChunk());
2987 }
2988 
2989 
2992  SId2LoadedSet& loaded_set,
2993  const CID2_Reply& main_reply,
2994  const CID2S_Reply_Get_Split_Info& reply)
2995 {
2996  TChunkId chunk_id = kMain_ChunkId;
2997  const CID2_Blob_Id& src_blob_id = reply.GetBlob_id();
2998  TBlobId blob_id = GetBlobId(src_blob_id);
2999  TBlobVersion blob_version = 0;
3000  if ( src_blob_id.IsSetVersion() && src_blob_id.GetVersion() > 0 ) {
3001  blob_version = src_blob_id.GetVersion();
3002  SetAndSaveBlobVersion(result, blob_id, blob_version);
3003  }
3004  if ( !reply.IsSetData() ) {
3005  ERR_POST_X(11, "CId2ReaderBase: ID2S-Reply-Get-Split-Info: "
3006  "no data in reply: "<<blob_id);
3007  return;
3008  }
3009 
3010  if ( !blob_version ) {
3011  CLoadLockBlobVersion lock(result, blob_id);
3012  if ( !lock.IsLoadedBlobVersion() ) {
3013  // need some reference blob version to work with
3014  // but not save it into cache
3015  SetAndSaveBlobVersion(result, blob_id, 0);
3016  //state.SetLoadedBlobVersion(0);
3017  }
3018  }
3019 
3020  CLoadLockBlob blob(result, blob_id);
3021  if ( blob.IsLoadedBlob() ) {
3022  if ( blob.NeedsDelayedMainChunk() ) {
3023  chunk_id = kDelayedMain_ChunkId;
3024  blob.SelectChunk(chunk_id);
3025  }
3026  if ( blob.IsLoadedChunk() ) {
3028  ERR_POST_X(10, Info<<"CId2ReaderBase: ID2S-Reply-Get-Split-Info: "
3029  "blob already loaded: " << blob_id);
3030  return;
3031  }
3032  }
3033 
3034  TBlobState blob_state;
3035  if ( reply.IsSetBlob_state() ) {
3036  blob_state = x_GetBlobStateFromID2(blob_id, loaded_set,
3037  reply.GetBlob_state());
3038  }
3039  else {
3040  blob_state = x_GetBlobState(blob_id, loaded_set, main_reply);
3041  }
3042  if ( blob_state & CBioseq_Handle::fState_no_data ) {
3043  SetAndSaveNoBlob(result, blob_id, chunk_id, blob_state);
3044  return;
3045  }
3046 
3048  {{
3050  loaded_set.m_Skeletons.find(blob_id);
3051  if ( iter != loaded_set.m_Skeletons.end() ) {
3052  skel = iter->second;
3053  }
3054  }}
3055 
3056  if ( blob_state ) {
3057  result.SetAndSaveBlobState(blob_id, blob_state);
3058  }
3059 
3060  dynamic_cast<const CProcessor_ID2&>
3062  .ProcessData(result, blob_id, blob_state, chunk_id,
3063  reply.GetData(), reply.GetSplit_version(), skel);
3064 
3065  _ASSERT(blob.IsLoadedChunk());
3066  loaded_set.m_Skeletons.erase(blob_id);
3067 }
3068 
3069 
3072  SId2LoadedSet& /*loaded_set*/,
3073  const CID2_Reply& /*main_reply*/,
3074  const CID2S_Reply_Get_Chunk& reply)
3075 {
3076  TBlobId blob_id = GetBlobId(reply.GetBlob_id());
3077  if ( !reply.IsSetData() ) {
3078  ERR_POST_X(14, "CId2ReaderBase: ID2S-Reply-Get-Chunk: "
3079  "no data in reply: "<<blob_id);
3080  return;
3081  }
3082 
3083  if ( !CLoadLockBlob(result, blob_id).IsLoadedBlob() ) {
3084  ERR_POST_X(13, "CId2ReaderBase: ID2S-Reply-Get-Chunk: "
3085  "blob is not loaded yet: " << blob_id);
3086  return;
3087  }
3088 
3089  dynamic_cast<const CProcessor_ID2&>
3091  .ProcessData(result, blob_id, 0, reply.GetChunk_id(), reply.GetData());
3092 }
3093 
3094 
3095 /////////////////////////////////////////////////////////////////////////////
3096 /////////////////////////////////////////////////////////////////////////////
3097 /////////////////////////////////////////////////////////////////////////////
3098 
3099 
ncbi::TMaskedQueryRegions mask
void SetAnnotInfo(CRef< CBlob_Annot_Info > &annot_info)
void SetSubSat(TSubSat v)
Definition: blob_id.hpp:109
TSat GetSat() const
Definition: blob_id.hpp:56
TSatKey GetSatKey() const
Definition: blob_id.hpp:64
void SetSatKey(TSatKey v)
Definition: blob_id.hpp:113
TSubSat GetSubSat() const
Definition: blob_id.hpp:60
void SetSat(TSat v)
Definition: blob_id.hpp:105
Definition: Dbtag.hpp:53
vector< CRef< CID2_Reply > > TReplies
CID2S_Chunk_Id –.
CID2S_Reply_Get_Chunk –.
CID2S_Reply_Get_Split_Info –.
CID2S_Request_Get_Chunks –.
CID2S_Seq_annot_Info –.
CID2_Blob_Id –.
Definition: ID2_Blob_Id.hpp:66
CID2_Error –.
Definition: ID2_Error.hpp:66
CID2_Get_Blob_Details –.
CID2_Param –.
Definition: ID2_Param.hpp:66
CID2_Reply_Get_Blob_Id –.
CID2_Reply_Get_Blob_Seq_ids –.
CID2_Reply_Get_Blob –.
CID2_Reply_Get_Seq_id –.
CID2_Reply –.
Definition: ID2_Reply.hpp:66
CID2_Request_Get_Blob_Id –.
CID2_Request_Get_Blob_Info –.
CID2_Request_Get_Seq_id –.
CID2_Request_Packet –.
CID2_Request –.
Definition: ID2_Request.hpp:66
CID2_Seq_id –.
Definition: ID2_Seq_id.hpp:66
virtual void x_ReceiveReply(TConn conn, CID2_Reply &reply)=0
TBlobState x_GetBlobStateFromID2(const CBlob_id &blob_id, SId2LoadedSet &loaded_set, int id2_state)
bool LoadLabels(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TLabels &ret)
void x_SetResolve(CID2_Request_Get_Blob_Id &get_blob_id, const CSeq_id &seq_id)
void x_SendID2Packet(CReaderRequestResult &result, SId2ProcessingState &state, CID2_Request_Packet &packet)
static void SetVDB_CDD_Enabled(bool enabled=true)
bool LoadHashes(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, THashes &ret, TKnown &known)
bool LoadSeq_idLabel(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
static bool GetVDB_SNP_Enabled()
bool LoadSeq_idTaxId(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
bool LoadChunk(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id)
void x_AssignSerialNumbers(SId2PacketInfo &info, CID2_Request_Packet &packet)
TProcessors m_Processors
bool LoadTaxIds(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TTaxIds &ret)
bool LoadChunks(CReaderRequestResult &result, const TBlobId &blob_id, const TChunkIds &chunk_ids)
bool x_LoadSeq_idBlob_idsSet(CReaderRequestResult &result, const TSeqIds &seq_ids)
static TBlobId GetBlobId(const CID2_Blob_Id &blob_id)
bool LoadSequenceHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
bool LoadLengths(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TLengths &ret)
void x_ProcessGetBlobSeqIds(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CID2_Reply_Get_Blob_Seq_ids &reply)
virtual void x_SendPacket(TConn conn, const CID2_Request_Packet &packet)=0
TErrorFlags x_GetMessageError(const CID2_Error &error)
void x_SetContextData(CID2_Request &request)
TErrorFlags x_GetError(CReaderRequestResult &result, const CID2_Error &error)
void x_ProcessGetChunk(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CID2S_Reply_Get_Chunk &reply)
bool LoadAccVers(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TIds &ret)
bool LoadTypes(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TTypes &ret)
bool LoadBlobs(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TContentsMask mask, const SAnnotSelector *sel)
bool x_DoneReply(SId2PacketInfo &info, int num, const CID2_Reply &reply)
atomic< TAvoidRequests > m_AvoidRequest
void x_ProcessGetSplitInfo(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CID2S_Reply_Get_Split_Info &reply)
static bool GetVDB_CDD_Enabled()
bool LoadBlobVersion(CReaderRequestResult &result, const TBlobId &blob_id)
static int GetDebugLevel(void)
TBlobState x_GetBlobState(const CBlob_id &blob_id, SId2LoadedSet &loaded_set, const CID2_Reply &reply, TErrorFlags *errors_ptr=0)
void x_DumpPacket(TConn conn, const CID2_Request_Packet &packet, const char *msg="Sending")
void x_ProcessGetBlob(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CID2_Reply_Get_Blob &reply)
static void SetSNP_Scale_Limit(CSeq_id::ESNPScaleLimit value)
void x_ProcessGetSeqId(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CID2_Request_Get_Seq_id &request, const CID2_Reply_Get_Seq_id *reply)
static void SetVDB_SNP_Enabled(bool enabled=true)
void x_SetExclude_blobs(CID2_Request_Get_Blob_Info &get_blob_info, const CSeq_id_Handle &idh, CReaderRequestResult &result)
void x_UpdateLoadedSet(CReaderRequestResult &result, SId2LoadedSet &data, const SAnnotSelector *sel)
void x_SetDetails(CID2_Get_Blob_Details &details, TContentsMask mask)
bool LoadBlobSet(CReaderRequestResult &result, const TSeqIds &seq_ids)
CRef< CID2_Reply > x_ReceiveID2ReplyStage(SId2ProcessingState &state, size_t pos)
void x_ProcessRequest(CReaderRequestResult &result, CID2_Request &req, const SAnnotSelector *sel)
virtual void SetParams(const CReaderParams &params)
void x_ProcessEmptyReply(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CID2_Request &main_request)
void x_DumpReply(TConn conn, CID2_Reply &reply, const char *msg="Received")
bool LoadBlobState(CReaderRequestResult &result, const TBlobId &blob_id)
virtual string x_ConnDescription(TConn conn) const =0
bool LoadSequenceType(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
bool LoadSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
CRef< CID2_Reply > x_ReceiveFromConnection(TConn conn)
virtual void x_EndOfPacket(TConn conn)
static void sx_CheckErrorFlag(const CID2_Error &error, TErrorFlags &error_flags, EErrorFlags test_flag, const char *marker1, const char *marker2=0)
CRef< CID2_Reply > x_ReceiveID2Reply(SId2ProcessingState &state)
CAtomicCounter_WithAutoInit m_RequestSerialNumber
static void SetVDB_WGS_Enabled(bool enabled=true)
bool LoadSequenceLength(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
static bool GetVDB_WGS_Enabled()
void x_ProcessGetBlobId(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CID2_Reply_Get_Blob_Id &reply)
void x_ProcessReply(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CID2_Request &main_request)
bool LoadGis(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TGis &ret)
void x_ProcessPacket(CReaderRequestResult &result, CID2_Request_Packet &packet, const SAnnotSelector *sel)
void x_ProcessGetSeqIdSeqId(CReaderRequestResult &result, SId2LoadedSet &loaded_set, const CID2_Reply &main_reply, const CSeq_id_Handle &seq_id, const CID2_Request_Get_Seq_id &request, const CID2_Reply_Get_Seq_id *reply)
int x_GetReplyIndex(CReaderRequestResult &result, CConn *conn, SId2PacketInfo &packet, const CID2_Reply &reply)
bool LoadSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel)
All LoadXxx() methods should return false if there is no requested data in the reader.
bool LoadStates(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TStates &ret)
bool LoadSeq_idAccVer(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
bool LoadSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
static CSeq_id::ESNPScaleLimit GetSNP_Scale_Limit(void)
bool LoadBlob(CReaderRequestResult &result, const TBlobId &blob_id)
void x_SendToConnection(TConn conn, CID2_Request_Packet &packet)
static bool IsFound(const TData &data)
TData GetAccVer(void) const
static const CSeq_id_Handle & GetAcc(const TData &data)
bool IsLoadedAccVer(void) const
TData GetBlob_ids(void) const
bool IsLoadedBlobState(void) const
bool IsLoadedBlobVersion(void) const
void SelectChunk(TChunkId chunk_id)
bool NeedsDelayedMainChunk(void) const
bool IsLoadedChunk(void) const
const CTSE_Split_Info & GetSplitInfo(void) const
bool IsLoadedBlob(void) const
TBlobVersion GetKnownBlobVersion(void) const
bool IsLoadedGi(void) const
static bool IsFound(const TData &data)
static TGi GetGi(const TData &data)
bool IsLoadedHash(void) const
static int GetHash(const TData &data)
bool IsLoadedLabel(void) const
bool SetLoadedLabel(const TData &data)
TData GetLabel(void) const
TData GetLength(void) const
bool IsLoadedLength(void) const
TData GetSeq_ids(void) const
void SetLoaded(void)
bool IsLoaded(void) const
bool IsLoadedTaxId(void) const
TData GetTaxId(void) const
static bool IsFound(const TData &data)
static CSeq_inst::TMol GetType(const TData &data)
bool IsLoadedType(void) const
Data loader exceptions, used by GenBank loader.
CObjectIStream –.
Definition: objistr.hpp:93
TId8 GetId8(void) const
Definition: Object_id.cpp:164
static TPluginManager * Get(void)
static void LoadBlob(CReaderRequestResult &result, const CBlob_Info &blob_info)
static bool IsExtAnnot(const TBlobId &blob_id)
static void DumpDataAsText(const CID2_Reply_Data &data, CNcbiOstream &out)
static void OffsetAllGisToOM(CBeginInfo obj, CTSE_SetObjectInfo *set_info=0)
Definition: processors.cpp:590
@ eType_ExtAnnot
Definition: processor.hpp:81
@ eType_Seq_entry_SNP
Definition: processor.hpp:72
void ProcessBlobFromID2Data(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id, const CID2_Reply_Data &data) const
Definition: processors.cpp:262
static void OffsetAllGisFromOM(CBeginInfo obj)
Definition: processors.cpp:584
const CProcessor & GetProcessor(CProcessor::EType type) const
Definition: dispatcher.cpp:219
static bool SetBlobState(size_t i, CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TStates &ret)
CWriter * GetWriter(const CReaderRequestResult &result, CWriter::EType type) const
Definition: dispatcher.cpp:204
static bool CannotProcess(const CSeq_id_Handle &sih)
Definition: dispatcher.cpp:261
bool GetEnableSNP(void) const
Definition: reader.hpp:57
bool GetEnableCDD(void) const
Definition: reader.hpp:67
bool GetEnableWGS(void) const
Definition: reader.hpp:62
bool IsSetEnableCDD(void) const
Definition: reader.hpp:66
bool IsSetEnableSNP(void) const
Definition: reader.hpp:56
bool IsSetEnableWGS(void) const
Definition: reader.hpp:61
vector< CBlob_id > TLoadedBlob_ids
CDataLoader::STypeFound TSequenceType
Definition: reader.hpp:185
vector< CSeq_id_Handle > TSeqIds
Definition: reader.hpp:96
virtual bool LoadBlobSet(CReaderRequestResult &result, const TSeqIds &seq_ids)
Definition: reader.cpp:981
virtual bool LoadHashes(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, THashes &ret, TKnown &known)
Definition: reader.cpp:751
CReadDispatcher * m_Dispatcher
Definition: reader.hpp:344
void SetAndSaveSeq_idAccVer(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const TSequenceAcc &acc_id) const
Definition: reader.cpp:1173
virtual bool LoadStates(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TStates &ret)
Definition: reader.cpp:822
virtual bool LoadSequenceHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:579
virtual bool LoadSeq_idTaxId(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:547
CReaderAllocatedConnection CConn
Definition: reader.hpp:346
void SetAndSaveNoSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel, const CLoadLockGi &gi_lock) const
Definition: reader.cpp:1133
virtual bool LoadLabels(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TLabels &ret)
Definition: reader.cpp:709
void SetAndSaveSequenceType(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const TSequenceType &type) const
Definition: reader.cpp:1238
virtual bool LoadTypes(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TTypes &ret)
Definition: reader.cpp:798
void SetAndSaveSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const TSequenceGi &gi) const
Definition: reader.cpp:1160
void SetAndSaveBlobVersion(CReaderRequestResult &result, const TBlobId &blob_id, TBlobVersion version) const
Definition: reader.cpp:1037
int TBlobVersion
Definition: reader.hpp:91
vector< CBlob_Info > TBlobIds
Definition: reader.hpp:97
vector< int > TStates
Definition: reader.hpp:128
virtual bool LoadTaxIds(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TTaxIds &ret)
Definition: reader.cpp:730
void SetAndSaveNoBlob(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id, TBlobState blob_state)
Definition: reader.cpp:992
virtual bool LoadSequenceType(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:628
vector< string > TLabels
Definition: reader.hpp:126
void SetAndSaveSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const CFixedSeq_ids &seq_ids) const
Definition: reader.cpp:1050
vector< TGi > TGis
Definition: reader.hpp:125
unsigned TConn
Definition: reader.hpp:87
virtual bool LoadSequenceLength(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:596
virtual bool LoadChunks(CReaderRequestResult &result, const TBlobId &blob_id, const TChunkIds &chunk_ids)
Definition: reader.cpp:969
void SetAndSaveSequenceLength(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TSeqPos length) const
Definition: reader.cpp:1225
void SetAndSaveSeq_idTaxId(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TTaxId taxid) const
Definition: reader.cpp:1199
vector< TSeqPos > TLengths
Definition: reader.hpp:131
virtual bool LoadGis(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TGis &ret)
Definition: reader.cpp:685
void SetAndSaveSeq_idLabel(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const string &label) const
Definition: reader.cpp:1186
virtual bool LoadAccVers(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TIds &ret)
Definition: reader.cpp:661
vector< CSeq_inst::EMol > TTypes
Definition: reader.hpp:132
vector< int > THashes
Definition: reader.hpp:129
virtual bool LoadSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:490
vector< CSeq_id_Handle > TIds
Definition: reader.hpp:123
CDataLoader::SAccVerFound TSequenceAcc
Definition: reader.hpp:183
virtual bool LoadSeq_idAccVer(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:509
CDataLoader::SHashFound TSequenceHash
Definition: reader.hpp:186
void SetAndSaveSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel, CLoadLockBlobIds &lock, const CLoadLockBlobIds &blob_ids) const
Definition: reader.cpp:1268
int TChunkId
Definition: reader.hpp:93
void SetAndSaveSequenceHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const TSequenceHash &hash) const
Definition: reader.cpp:1212
vector< TChunkId > TChunkIds
Definition: reader.hpp:95
vector< bool > TLoaded
Definition: reader.hpp:124
virtual bool LoadLengths(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TLengths &ret)
Definition: reader.cpp:777
int TContentsMask
Definition: reader.hpp:94
int TBlobState
Definition: reader.hpp:90
vector< TTaxId > TTaxIds
Definition: reader.hpp:127
virtual bool LoadBlobs(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TContentsMask mask, const SAnnotSelector *sel)
Definition: reader.cpp:879
void SetAndSaveNoSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TState state) const
Definition: reader.cpp:1149
virtual bool LoadSeq_idLabel(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:528
CDataLoader::SGiFound TSequenceGi
Definition: reader.hpp:184
vector< bool > TKnown
Definition: reader.hpp:130
CSafeStatic<>::
TSplitVersion GetSplitVersion(void) const
Template class for iteration on objects of class C (non-medifiable version)
Definition: iterator.hpp:767
Template class for iteration on objects of class C.
Definition: iterator.hpp:673
@ eBlobWriter
Definition: writer.hpp:65
void erase(iterator pos)
Definition: map.hpp:167
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
void swap(this_type &m)
Definition: map.hpp:118
Definition: map.hpp:338
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
char value[7]
Definition: config.c:431
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
static int type
Definition: getdata.c:31
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define INVALID_TAX_ID
Definition: ncbimisc.hpp:1116
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
SStrictId_Tax::TId TTaxId
Taxon id type.
Definition: ncbimisc.hpp:1048
const TSeqPos kInvalidSeqPos
Define special value for invalid sequence position.
Definition: ncbimisc.hpp:878
#define TAX_ID_FROM(T, value)
Definition: ncbimisc.hpp:1111
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
void Set(TValue new_value) THROWS_NONE
Set atomic counter value.
Definition: ncbicntr.hpp:185
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
Definition: ncbicntr.hpp:278
TValue Get(void) const THROWS_NONE
Get atomic counter value.
Definition: ncbicntr.hpp:168
CDiagContext & GetDiagContext(void)
Get diag context instance.
Definition: logging.cpp:818
string GetSessionID(void) const
Session ID.
const string & GetNextSubHitID(CTempString prefix=CTempString())
Get current hit id appended with auto-incremented sub-hit id.
bool IsSetSessionID(void) const
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
Definition: ncbidiag.cpp:1901
string GetClientIP(void) const
Client IP/hostname.
bool IsSetHitID(EHitIDSource src=eHitID_Any) const
Check if there's an explicit hit id or the default one.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
bool IsSetClientIP(void) const
#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:704
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
#define NCBI_RETHROW(prev_exception, exception_class, err_code, message)
Generic macro to re-throw an exception.
Definition: ncbiexpt.hpp:737
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
C * SerialClone(const C &src)
Create on heap a clone of the source object.
Definition: serialbase.hpp:512
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
CConstRef< CSeq_id > GetSeqId(void) const
static const char * GetSNPScaleLimit_Name(ESNPScaleLimit value)
Definition: Seq_id.cpp:3545
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
ESNPScaleLimit
SNP annotation scale limits.
Definition: Seq_id.hpp:815
@ eSNPScaleLimit_Default
Definition: Seq_id.hpp:816
CBeginInfo Begin(C &obj)
Get starting point of object hierarchy.
Definition: iterator.hpp:1004
bool IsIncludedAnyNamedAnnotAccession(void) const
check if any named annot accession is included in the search
string CombineWithZoomLevel(const string &acc, int zoom_level)
Combine accession string and zoom level into a string with separator.
TSNPScaleLimit GetSNPScaleLimit(void) const
bool ExtractZoomLevel(const string &full_name, string *acc_ptr, int *zoom_level_ptr)
Extract optional zoom level suffix from named annotation string.
const TNamedAnnotAccessions & GetNamedAnnotAccessions(void) const
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
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 NcbiCout
Definition: ncbistre.hpp:543
NCBI_NS_STD::string::size_type SIZE_TYPE
Definition: ncbistr.hpp:132
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3457
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
Definition: ncbistr.cpp:2989
#define NPOS
Definition: ncbistr.hpp:133
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5411
virtual void Process(SOCK sock)=0
Runs asynchronously (from a separate thread) for each request.
#define DEFINE_STATIC_FAST_MUTEX(id)
Define static fast mutex and initialize it.
Definition: ncbimtx.hpp:496
static const char label[]
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
const TTag & GetTag(void) const
Get the Tag member data.
Definition: Dbtag_.hpp:267
bool IsId(void) const
Check if variant Id is selected.
Definition: Object_id_.hpp:264
const TDb & GetDb(void) const
Get the Db member data.
Definition: Dbtag_.hpp:220
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
TId GetId(void) const
Get the variant data.
Definition: Object_id_.hpp:270
bool IsSetAnnot_info(void) const
annotation types in this blob annotation are unknown if this field is omitted Check if a value has be...
TVersion GetVersion(void) const
Get the Version member data.
TSat_key GetSat_key(void) const
Get the Sat_key member data.
const TError & GetError(void) const
Get the Error member data.
Definition: ID2_Reply_.hpp:891
void SetBlob_id(TBlob_id &value)
Assign a value to Blob_id data member.
bool IsSetBlob_state(void) const
state bits of the blob, 0 or missing means regular live data Check if a value has been assigned to Bl...
const TData & GetData(void) const
Get the Data member data.
void SetSplit_version(TSplit_version value)
Assign a value to Split_version data member.
bool IsSetBlob_state(void) const
state bits of the blob, 0 or missing means regular live data Check if a value has been assigned to Bl...
TSeq_id_type GetSeq_id_type(void) const
Get the Seq_id_type member data.
TChunks & SetChunks(void)
Assign a value to Chunks data member.
const TSeq_id & GetSeq_id(void) const
Get the Seq_id member data.
const TSeq_id & GetSeq_id(void) const
Get the Seq_id member data.
list< CRef< CID2_Error > > TError
Definition: ID2_Reply_.hpp:461
const TBlob_id & GetBlob_id(void) const
Get the Blob_id member data.
void SetGet_data(TGet_data &value)
Assign a value to Get_data data member.
bool IsSetDiscard(void) const
Check if a value has been assigned to Discard data member.
Definition: ID2_Reply_.hpp:958
bool IsSetBlob_state(void) const
state bits of the blob, 0 or missing means regular live data Check if a value has been assigned to Bl...
TSources & SetSources(void)
Assign a value to Sources data member.
bool IsEmpty(void) const
Check if variant Empty is selected.
Definition: ID2_Reply_.hpp:751
bool IsSetVersion(void) const
version of blob, optional in some requests Check if a value has been assigned to Version data member.
const TAnnot_info & GetAnnot_info(void) const
Get the Annot_info member data.
void SetParams(TParams &value)
Assign a value to Params data member.
TBlob_state GetBlob_state(void) const
Get the Blob_state member data.
const TBlob_id & GetBlob_id(void) const
Get the Blob_id member data.
const TSeq_id & GetSeq_id(void) const
Get the variant data.
bool IsSetData(void) const
chunk data not set if error occurred Check if a value has been assigned to Data data member.
const TChunk_id & GetChunk_id(void) const
Get the Chunk_id member data.
void SetSat_key(TSat_key value)
Assign a value to Sat_key data member.
TBlob_state GetBlob_state(void) const
Get the Blob_state member data.
list< vector< char > * > TData
TBlob_state GetBlob_state(void) const
Get the Blob_state member data.
const TReply & GetReply(void) const
Get the Reply member data.
Definition: ID2_Reply_.hpp:940
E_Choice Which(void) const
Which variant is currently selected.
const TBlob_id & GetBlob_id(void) const
Get the Blob_id member data.
TSplit_version GetSplit_version(void) const
Get the Split_version member data.
const TSeq_id & GetSeq_id(void) const
Get the Seq_id member data.
CID2_Request_Get_Seq_id TGet_seq_id
Tdata & Set(void)
Assign a value to data member.
TSub_sat GetSub_sat(void) const
Get the Sub_sat member data.
TData_type GetData_type(void) const
Get the Data_type member data.
TSerial_number GetSerial_number(void) const
Get the Serial_number member data.
Definition: ID2_Reply_.hpp:830
bool IsSetEnd_of_reply(void) const
this Seq-id is the last one in the request Check if a value has been assigned to End_of_reply data me...
const TSeq_id & GetSeq_id(void) const
Get the Seq_id member data.
const TData & GetData(void) const
Get the Data member data.
list< CRef< CID2_Request > > Tdata
bool IsSetSerial_number(void) const
request's serial number, copy from request Check if a value has been assigned to Serial_number data m...
Definition: ID2_Reply_.hpp:811
bool IsSetError(void) const
Check if a value has been assigned to Error data member.
Definition: ID2_Reply_.hpp:879
void SetSat(TSat value)
Assign a value to Sat data member.
const TRequest & GetRequest(void) const
Get the Request member data.
const TData & GetData(void) const
Get the Data member data.
bool IsInit(void) const
Check if variant Init is selected.
void SetRequest(TRequest &value)
Assign a value to Request data member.
bool IsSetData(void) const
blob split info not set if error occurred Check if a value has been assigned to Data data member.
void SetBlob_id(TBlob_id &value)
Assign a value to Blob_id data member.
TSat GetSat(void) const
Get the Sat member data.
void SetSub_sat(TSub_sat value)
Assign a value to Sub_sat data member.
const TBlob_id & GetBlob_id(void) const
Get the Blob_id member data.
list< CRef< CSeq_id > > TSeq_id
bool IsSetEnd_of_reply(void) const
true if this reply is the last one for the request false if more replies will follow Check if a value...
Definition: ID2_Reply_.hpp:904
void SetSeq_id(TSeq_id &value)
Assign a value to Seq_id data member.
void SetExternal(void)
Set NULL data member (assign 'NULL' value to External data member).
TSplit_version GetSplit_version(void) const
Get the Split_version member data.
bool IsSetData(void) const
whole blob or blob skeleton not set if error occurred Check if a value has been assigned to Data data...
const TData & GetData(void) const
Get the Data member data.
const Tdata & Get(void) const
Get the member data.
@ 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_text
text Seq-id (accession etc) is preferred
@ eSeq_id_type_label
return a sequence string label as string in general id with db "LABEL"
@ eSeq_id_type_all
return all qualified Seq-ids of the sequence
@ eSeverity_no_data
resolve request gives no data probably temporarily (see retry-delay field)
Definition: ID2_Error_.hpp:89
@ eSeverity_restricted_data
data exists but client doesn't have permission to get it
Definition: ID2_Error_.hpp:90
@ eSeverity_failed_command
command cannot be completed this time
Definition: ID2_Error_.hpp:86
@ eSeverity_failed_server
server cannot be used for a while
Definition: ID2_Error_.hpp:88
@ eSeverity_warning
nothing harmful happened
Definition: ID2_Error_.hpp:85
@ eSeverity_unsupported_command
this request type is not supported by server
Definition: ID2_Error_.hpp:91
@ eSeverity_invalid_arguments
error in request packet, cannot retry
Definition: ID2_Error_.hpp:92
@ eSeverity_failed_connection
connection cannot be reused, reconnect is required
Definition: ID2_Error_.hpp:87
@ eID2_Blob_State_dead
@ eID2_Blob_State_suppressed
@ eID2_Blob_State_protected
@ eID2_Blob_State_suppressed_temp
@ eID2_Blob_State_withdrawn
bool IsSetSeq_loc(void) const
Check if a value has been assigned to Seq_loc data member.
bool IsSetName(void) const
name is set if this is named annot name may be empty which differ from unnamed annot Check if a value...
bool IsSetGraph(void) const
Check if a value has been assigned to Graph data member.
bool IsSetAlign(void) const
Check if a value has been assigned to Align data member.
const TName & GetName(void) const
Get the Name member data.
bool IsSetFeat(void) const
Check if a value has been assigned to Feat data member.
void ResetGraph(void)
Reset Graph data member.
bool IsGeneral(void) const
Check if variant General is selected.
Definition: Seq_id_.hpp:877
E_Choice Which(void) const
Which variant is currently selected.
Definition: Seq_id_.hpp:746
const TGeneral & GetGeneral(void) const
Get the variant data.
Definition: Seq_id_.cpp:369
@ e_not_set
No variant selected.
Definition: Seq_id_.hpp:94
EMol
molecule class in living organism
Definition: Seq_inst_.hpp:108
Definition of all error codes used in objtools libraries.
int i
static MDB_envinfo info
Definition: mdb_load.c:37
const struct ncbi::grid::netcache::search::fields::SIZE size
string s_Value(TValue value)
Static variables safety - create on demand, destroy on application termination.
Multi-threading – mutexes; rw-locks; semaphore.
T max(T x_, T y_)
@ kMain_ChunkId
Definition: blob_id.hpp:133
@ kDelayedMain_ChunkId
Definition: blob_id.hpp:135
EGBErrorAction
Definition: blob_id.hpp:191
@ eGBErrorAction_report
Definition: blob_id.hpp:193
@ eGBErrorAction_throw
Definition: blob_id.hpp:194
@ fBlobHasNamedFeat
Definition: blob_id.hpp:154
@ fBlobHasNamedAnnot
Definition: blob_id.hpp:164
@ fBlobHasCore
Definition: blob_id.hpp:141
@ fBlobHasExtAnnot
Definition: blob_id.hpp:161
@ fBlobHasAllLocal
Definition: blob_id.hpp:182
@ fBlobHasNamedAlign
Definition: blob_id.hpp:155
@ fBlobHasNamedGraph
Definition: blob_id.hpp:156
Helper classes and templates to implement plugins.
#define DEFAULT_DEBUG_LEVEL
static const char kSpecialId_type[]
static void LoadedChunksPacket(CReaderRequestResult &result, CID2_Request_Packet &packet, vector< TChunkId > &chunks, const CBlob_id &blob_id)
NCBI_PARAM_ENUM_DEF_EX(objects::CSeq_id::ESNPScaleLimit, GENBANK, ID2SNP_SCALE_LIMIT, objects::CSeq_id::eSNPScaleLimit_Default, eParam_NoThread, GENBANK_ID2SNP_SCALE_LIMIT)
static const char kSpecialId_taxid[]
#define x_GetReaderName(conn)
static size_t GetMaxIdsRequestSize(void)
static size_t GetMaxChunksRequestSize(void)
typedef NCBI_PARAM_TYPE(GENBANK, ID2SNP_SCALE_LIMIT) TID2SNP_Scale_Limit
static const char kSpecialId_length[]
static const char kSpecialId_label[]
NCBI_PARAM_DECL(int, GENBANK, ID2_DEBUG)
static bool sx_IsSpecialId(const CSeq_id &id)
static bool LimitChunksRequests(size_t max_request_size=GetMaxChunksRequestSize())
NCBI_PARAM_ENUM_DECL(objects::CSeq_id::ESNPScaleLimit, GENBANK, ID2SNP_SCALE_LIMIT)
NCBI_DEFINE_ERR_SUBCODE_X(17)
NCBI_PARAM_ENUM_ARRAY(objects::CSeq_id::ESNPScaleLimit, GENBANK, ID2SNP_SCALE_LIMIT)
static bool SeparateChunksRequests(size_t max_request_size=GetMaxChunksRequestSize())
static const char kSpecialId_hash[]
NCBI_PARAM_DEF_EX(int, GENBANK, ID2_DEBUG, CId2ReaderBase::eTraceError, eParam_NoThread, GENBANK_ID2_DEBUG)
static bool GetSeqId(const T &d, set< string > &labels, const string name="", bool detect=false, bool found=false)
Defines CRequestContext class for NCBI C++ diagnostic API.
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 –.
TAnnotInfo m_AnnotInfo
CId2ReaderBase::TContentsMask m_ContentMask
list< CRef< CID2S_Seq_annot_Info > > TAnnotInfo
TSkeletons m_Skeletons
map< CSeq_id_Handle, TSeq_idsInfo > TSeq_idSeq_idsSet
pair< int, CReader::TSeqIds > TSeq_idsInfo
TBlob_idSet m_Blob_ids
map< CBlob_id, CConstRef< CID2_Reply_Data > > TSkeletons
TSeq_idSeq_idsSet m_Seq_ids
map< string, TSeq_idsInfo > TStringSeq_idsSet
pair< int, TBlob_ids > TBlob_idsInfo
map< CSeq_id_Handle, TBlob_idsInfo > TBlob_idSet
map< CBlob_id, SId2BlobInfo > TBlob_ids
TBlobStates m_BlobStates
map< CBlob_id, int > TBlobStates
vector< const CID2_Request * > requests
CID2Processor::TReplies TRequestReplies
vector< TRequestReplies > replies
CReader::TConn GetConn() const
vector< SId2ProcessorStage > stages
unique_ptr< CReaderAllocatedConnection > conn
CRef< CID2ProcessorPacketContext > packet_context
CID2Processor::TReplies replies
Definition: _hash_fun.h:40
Definition: type.c:6
SQLSMALLINT type
Definition: type.c:7
#define _ASSERT
else result
Definition: token2.c:20
Modified on Thu Dec 07 10:08:43 2023 by modify_doxy.py rev. 669887