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

Go to the SVN repository for this file.

1 /* $Id: reader_id1.cpp 100611 2023-08-16 18:57:07Z 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: Anton Butanaev, Eugene Vasilchenko
26  *
27  * File Description: Data reader from ID1
28  *
29  */
30 
31 #include <ncbi_pch.hpp>
32 #include <corelib/ncbi_param.hpp>
33 
37 #include <objtools/data_loaders/genbank/readers.hpp> // for entry point
40 #include <objtools/error_codes.hpp>
41 
43 #include <objmgr/impl/tse_info.hpp>
46 
47 #include <corelib/ncbimtx.hpp>
48 
50 
54 #include <objects/id1/id1__.hpp>
55 
56 #include <serial/objistrasnb.hpp>
57 #include <serial/objostrasnb.hpp>
58 #include <serial/serial.hpp>
59 #include <serial/iterator.hpp>
60 
62 #include <util/static_map.hpp>
63 
65 
66 #include <iomanip>
67 
68 
69 #define NCBI_USE_ERRCODE_X Objtools_Reader_Id1
70 
73 
74 #define DEFAULT_SERVICE "ID1"
75 #define DEFAULT_NUM_CONN 3
76 #define MAX_MT_CONN 5
77 
78 //#define GENBANK_ID1_RANDOM_FAILS 1
79 #define GENBANK_ID1_RANDOM_FAILS_FREQUENCY 20
80 #define GENBANK_ID1_RANDOM_FAILS_RECOVER 0 // new + write + read
81 
82 #ifdef GENBANK_ID1_RANDOM_FAILS
83 static void SetRandomFail(CConn_IOStream& stream)
84 {
85  static int fail_recover = 0;
86  if ( fail_recover > 0 ) {
87  --fail_recover;
88  return;
89  }
90  if ( random() % GENBANK_ID1_RANDOM_FAILS_FREQUENCY == 0 ) {
91  fail_recover = GENBANK_ID1_RANDOM_FAILS_RECOVER;
92  stream.setstate(ios::badbit);
93  }
94 }
95 #else
96 # define SetRandomFail(stream)
97 #endif
98 
99 
100 NCBI_PARAM_DECL(int, GENBANK, ID1_DEBUG);
101 NCBI_PARAM_DECL(string, GENBANK, ID1_SERVICE_NAME);
102 NCBI_PARAM_DECL(string, NCBI, SERVICE_NAME_ID1);
103 
104 NCBI_PARAM_DEF_EX(int, GENBANK, ID1_DEBUG, 0,
105  eParam_NoThread, GENBANK_ID1_DEBUG);
106 NCBI_PARAM_DEF_EX(string, GENBANK, ID1_SERVICE_NAME, "",
107  eParam_NoThread, GENBANK_ID1_SERVICE_NAME);
108 NCBI_PARAM_DEF_EX(string, NCBI, SERVICE_NAME_ID1, DEFAULT_SERVICE,
109  eParam_NoThread, GENBANK_SERVICE_NAME_ID1);
110 
111 
112 static int GetDebugLevel(void)
113 {
114  static CSafeStatic<NCBI_PARAM_TYPE(GENBANK, ID1_DEBUG)> s_Value;
115  return s_Value->Get();
116 }
117 
118 
120 {
125  eTraceASNData = 8
126 };
127 
128 
129 CId1Reader::CId1Reader(int max_connections)
130  : m_Connector(DEFAULT_SERVICE)
131 {
132  ERR_POST_X_ONCE(2, "This app is using OM++ ID1 reader which is being phased out. Please switch to using ID2 or PSG.");
133  SetMaximumConnections(max_connections, DEFAULT_NUM_CONN);
134 }
135 
136 
138  const string& driver_name)
139 {
140  ERR_POST_X_ONCE(2, "This app is using OM++ ID1 reader which is being phased out. Please switch to using ID2 or PSG.");
141  CConfig conf(params);
142  string service_name = conf.GetString(
143  driver_name,
146  kEmptyStr);
147  if ( service_name.empty() ) {
148  service_name = NCBI_PARAM_TYPE(GENBANK,ID1_SERVICE_NAME)::GetDefault();
149  }
150  if ( service_name.empty() ) {
151  service_name = NCBI_PARAM_TYPE(NCBI, SERVICE_NAME_ID1)::GetDefault();
152  }
153  m_Connector.SetServiceName(service_name);
154  m_Connector.InitTimeouts(conf, driver_name);
155  CReader::InitParams(conf, driver_name, DEFAULT_NUM_CONN);
156 }
157 
158 
160 {
161 }
162 
163 
165 {
166 #ifdef NCBI_THREADS
167  return MAX_MT_CONN;
168 #else
169  return 1;
170 #endif
171 }
172 
173 
175 {
176  _ASSERT(!m_Connections.count(conn));
178 }
179 
180 
182 {
184 }
185 
186 
188 {
189  _ASSERT(m_Connections.count(conn));
191  m_Connector.RememberIfBad(conn_info);
192  if ( conn_info.m_Stream ) {
193  x_ReportDisconnect("CId1Reader", "ID1", conn, failed);
194  conn_info.m_Stream.reset();
195  }
196 }
197 
198 
200 {
201  _VERIFY(m_Connections.count(conn));
203  if ( conn_info.m_Stream.get() ) {
204  return conn_info.m_Stream.get();
205  }
207  return m_Connections[conn].m_Stream.get();
208 }
209 
210 
212 {
213  return m_Connector.GetConnDescription(stream);
214 }
215 
216 
218 {
220 
221  CConn_IOStream& stream = *conn_info.m_Stream;
222 #ifdef GENBANK_ID1_RANDOM_FAILS
223  SetRandomFail(stream);
224 #endif
225 
226  if ( stream.bad() ) {
227  NCBI_THROW(CLoaderException, eConnectionFailed,
228  "cannot open connection: "+x_ConnDescription(stream));
229  }
230 
231  if ( GetDebugLevel() >= eTraceOpen ) {
232  CDebugPrinter s(conn, "CId1Reader");
233  s << "New connection: " << x_ConnDescription(stream);
234  }
235 
236  STimeout tmout;
237  m_Connector.SetTimeoutTo(&tmout);
238  CONN_SetTimeout(stream.GetCONN(), eIO_ReadWrite, &tmout);
239  tmout.sec = 0; tmout.usec = 1; // no wait on close
240  CONN_SetTimeout(stream.GetCONN(), eIO_Close, &tmout);
241 
242  m_Connections[conn] = conn_info;
243 }
244 
245 
249 static const TSI sc_SatIndex[] = {
250  { "ANNOT:CDD", { TRDR::eSat_ANNOT_CDD, TRDR::eSubSat_CDD } },
251  { "ANNOT:EXON", { TRDR::eSat_ANNOT, TRDR::eSubSat_Exon } },
252  { "ANNOT:HPRD", { TRDR::eSat_ANNOT, TRDR::eSubSat_HPRD } },
253  { "ANNOT:MGC", { TRDR::eSat_ANNOT, TRDR::eSubSat_MGC } },
254  { "ANNOT:microRNA", { TRDR::eSat_ANNOT, TRDR::eSubSat_microRNA } },
255  { "ANNOT:SNP", { TRDR::eSat_ANNOT, TRDR::eSubSat_SNP } },
256  { "ANNOT:SNP GRAPH",{ TRDR::eSat_ANNOT, TRDR::eSubSat_SNP_graph } },
257  { "ANNOT:STS", { TRDR::eSat_ANNOT, TRDR::eSubSat_STS } },
258  { "ANNOT:TRNA", { TRDR::eSat_ANNOT, TRDR::eSubSat_tRNA } },
259  { "ti", { TRDR::eSat_TRACE, TRDR::eSubSat_main } },
260  { "TR_ASSM_CH", { TRDR::eSat_TR_ASSM_CH, TRDR::eSubSat_main } },
261  { "TRACE_ASSM", { TRDR::eSat_TRACE_ASSM, TRDR::eSubSat_main } },
262  { "TRACE_CHGR", { TRDR::eSat_TRACE_CHGR, TRDR::eSubSat_main } }
263 };
266 
267 
269  const CSeq_id_Handle& seq_id)
270 {
271  CLoadLockGi lock(result, seq_id);
272  if ( lock.IsLoadedGi() ) {
273  return true;
274  }
275 
276  CID1server_request id1_request;
277  id1_request.SetGetgi(const_cast<CSeq_id&>(*seq_id.GetSeqId()));
278 
279  CID1server_back id1_reply;
280  x_ResolveId(result, id1_reply, id1_request);
281 
282  TSequenceGi gi;
283  if ( id1_reply.IsGotgi() ) {
284  gi.gi = id1_reply.GetGotgi();
285  gi.sequence_found = gi.gi != ZERO_GI;
286  }
287  SetAndSaveSeq_idGi(result, seq_id, gi);
288  return true;
289 }
290 
291 
293  const CSeq_id_Handle& seq_id)
294 {
295  CLoadLockSeqIds ids_lock(result, seq_id);
296  if ( ids_lock.IsLoaded() ) {
297  return true;
298  }
299 
300  if ( seq_id.Which() == CSeq_id::e_Gi ) {
301  return LoadGiSeq_ids(result, seq_id);
302  }
303 
304  if ( seq_id.Which() == CSeq_id::e_General ) {
305  // accept some general Seq-ids
306  CConstRef<CSeq_id> id_ref = seq_id.GetSeqId();
307  const CDbtag& dbtag = id_ref->GetGeneral();
308  Int8 id;
309  if ( dbtag.GetTag().GetId8(id) && id > 0 &&
310  sc_SatMap.find(dbtag.GetDb().c_str()) != sc_SatMap.end() ) {
311  // only one source Seq-id and no synonyms
312  TSeqIds seq_ids;
313  seq_ids.push_back(seq_id);
314  ids_lock.SetLoadedSeq_ids(CFixedSeq_ids(eTakeOwnership, seq_ids));
315  return true;
316  }
317  }
318 
319  CLoadLockGi gi_lock(result, seq_id);
320  if ( !gi_lock.IsLoaded() ) {
321  m_Dispatcher->LoadSeq_idGi(result, seq_id);
322  }
323  TSequenceGi data = gi_lock.GetGi();
324  if ( !gi_lock.IsFound(data) ) {
325  // no gi -> no Seq-ids
326  SetAndSaveNoSeq_idSeq_ids(result, seq_id, gi_lock);
327  return true;
328  }
329 
330  CSeq_id_Handle gi_handle =
332  CLoadLockSeqIds gi_ids_lock(result, gi_handle);
333  if ( !gi_ids_lock.IsLoaded() ) {
335  }
336  SetAndSaveSeq_idSeq_ids(result, seq_id, gi_ids_lock);
337  return true;
338 }
339 
340 
342  const CSeq_id_Handle& seq_id)
343 {
344  CLoadLockSeqIds ids(result, seq_id);
345  if ( ids.IsLoaded() ) {
346  return true;
347  }
348 
349  _ASSERT(seq_id.Which() == CSeq_id::e_Gi);
350  TGi gi;
351  if ( seq_id.IsGi() ) {
352  gi = seq_id.GetGi();
353  }
354  else {
355  gi = seq_id.GetSeqId()->GetGi();
356  }
357  if ( gi == ZERO_GI ) {
358  SetAndSaveNoSeq_idSeq_ids(result, seq_id, 0);
359  return true;
360  }
361 
362  CID1server_request id1_request;
363  {{
364  id1_request.SetGetseqidsfromgi(gi);
365  }}
366 
367  CID1server_back id1_reply;
368  x_ResolveId(result, id1_reply, id1_request);
369 
370  if ( !id1_reply.IsIds() ) {
371  SetAndSaveNoSeq_idSeq_ids(result, seq_id, 0);
372  return true;
373  }
374 
375  TSeqIds seq_ids;
376  const CID1server_back::TIds& reply_ids = id1_reply.GetIds();
377  ITERATE(CID1server_back::TIds, it, reply_ids) {
378  seq_ids.push_back(CSeq_id_Handle::GetHandle(**it));
379  }
381  CFixedSeq_ids(eTakeOwnership, seq_ids));
382  return true;
383 }
384 
385 
387 {
388  for ( auto& s : accs ) {
389  if ( s.first != "SNP" ) {
390  return false;
391  }
392  }
393  return true;
394 }
395 
396 
398  const CSeq_id_Handle& seq_id,
399  const SAnnotSelector* sel)
400 {
401  CLoadLockBlobIds ids(result, seq_id, sel);
402  if ( ids.IsLoaded() ) {
403  return true;
404  }
405  if ( sel && sel->IsIncludedAnyNamedAnnotAccession() &&
407  return CReader::LoadSeq_idBlob_ids(result, seq_id, sel);
408  }
409 
410  if ( seq_id.Which() == CSeq_id::e_Gi ) {
411  return LoadGiBlob_ids(result, seq_id, sel);
412  }
413 
414  if ( seq_id.Which() == CSeq_id::e_General ) {
415  CConstRef<CSeq_id> id_ref = seq_id.GetSeqId();
416  const CSeq_id& id = *id_ref;
417  Int8 num;
418  if ( id.GetGeneral().GetTag().GetId8(num) && num != 0 ) {
419  const CDbtag& dbtag = id.GetGeneral();
420  const string& db = dbtag.GetDb();
421  TSatMap::const_iterator iter = sc_SatMap.find(db.c_str());
422  if ( iter != sc_SatMap.end() ) {
423  TBlobIds blob_ids;
424  CRef<CBlob_id> blob_id(new CBlob_id);
425  ESat sat = iter->second.first;
426  Int4 sat_key = Int4(num);
427  Int4 sub_sat = iter->second.second;
428  if ( sat == eSat_ANNOT_CDD || sat == eSat_ANNOT ) {
430  // pack gi into sat_key and sub_sat
431  sat_key = Int4(num);
432  sub_sat |= Int4((num>>32)<<16);
433  }
434  blob_id->SetSat(sat);
435  blob_id->SetSatKey(sat_key);
436  blob_id->SetSubSat(sub_sat);
437  blob_ids.push_back(CBlob_Info(blob_id, fBlobHasAllLocal));
439  return true;
440  }
441  }
442  }
443 
444  CLoadLockGi gi_lock(result, seq_id);
445  if ( !gi_lock.IsLoaded() ) {
446  m_Dispatcher->LoadSeq_idGi(result, seq_id);
447  }
448  TSequenceGi data = gi_lock.GetGi();
449  TGi gi = gi_lock.GetGi(data);
450  if ( gi == ZERO_GI ) {
451  // no gi -> no Seq-ids
452  SetAndSaveNoSeq_idBlob_ids(result, seq_id, sel, gi_lock);
453  return true;
454  }
455 
457  CLoadLockBlobIds gi_ids_lock(result, gi_handle, sel);
458  if ( !gi_ids_lock.IsLoaded() ) {
459  m_Dispatcher->LoadSeq_idBlob_ids(result, gi_handle, sel);
460  }
461  SetAndSaveSeq_idBlob_ids(result, seq_id, sel, ids, gi_ids_lock);
462  return true;
463 }
464 
465 
467  const CSeq_id_Handle& seq_id,
468  const SAnnotSelector* sel)
469 {
470  CLoadLockBlobIds ids(result, seq_id, sel);
471  if ( ids.IsLoaded() ) {
472  return true;
473  }
474  _ASSERT(seq_id.Which() == CSeq_id::e_Gi);
475  TGi gi;
476  if ( seq_id.IsGi() ) {
477  gi = seq_id.GetGi();
478  }
479  else {
480  gi = seq_id.GetSeqId()->GetGi();
481  }
482  if ( gi == ZERO_GI ) {
483  ids.SetNoBlob_ids(0);
484  return true;
485  }
486 
487  CID1server_request id1_request;
488  {{
489  CID1server_maxcomplex& blob = id1_request.SetGetblobinfo();
491  blob.SetGi(gi);
492  }}
493 
494  CID1server_back id1_reply;
495  TBlobState state = x_ResolveId(result, id1_reply, id1_request);
496 
497  if ( !id1_reply.IsGotblobinfo() ) {
498  if ( !state ) {
500  }
501  SetAndSaveNoSeq_idBlob_ids(result, seq_id, sel, ids, state);
502  return true;
503  }
504 
505  const CID1blob_info& info = id1_reply.GetGotblobinfo();
506  if ( info.GetBlob_state() < 0 ) {
508  }
509  if ( info.GetSuppress() & 5 ) { // suppressed(=1) & temporary(=4)
510  state |=
511  (info.GetSuppress() == 4)
514  }
515  if (info.GetWithdrawn() > 0) {
517  SetAndSaveNoSeq_idBlob_ids(result, seq_id, sel, ids, state);
518  return true;
519  }
520  if (info.GetConfidential() > 0) {
522  SetAndSaveNoSeq_idBlob_ids(result, seq_id, sel, ids, state);
523  return true;
524  }
525  if ( info.GetSat() < 0 || info.GetSat_key() < 0 ) {
526  LOG_POST_X(3, Warning<<"CId1Reader: gi "<<gi<<" negative sat/satkey");
527  if ( !state ) {
529  }
530  SetAndSaveNoSeq_idBlob_ids(result, seq_id, sel, ids, state);
531  return true;
532  }
533  TBlobIds blob_ids;
534  if ( CProcessor::TrySNPSplit() ) {
535  {{
536  // add main blob
537  CRef<CBlob_id> blob_id(new CBlob_id);
538  blob_id->SetSat(info.GetSat());
539  blob_id->SetSatKey(info.GetSat_key());
540  blob_ids.push_back(CBlob_Info(blob_id, fBlobHasAllLocal));
541  }}
542  if ( info.IsSetExtfeatmask() ) {
543  CreateExtAnnotBlob_ids(blob_ids, GI_TO(TIntId, CProcessor::ConvertGiFromOM(gi)), info.GetExtfeatmask());
544  }
545  }
546  else {
547  // whole blob
548  CRef<CBlob_id> blob_id(new CBlob_id);
549  blob_id->SetSat(info.GetSat());
550  blob_id->SetSatKey(info.GetSat_key());
551  if ( info.IsSetExtfeatmask() ) {
552  blob_id->SetSubSat(info.GetExtfeatmask());
553  }
554  blob_ids.push_back(CBlob_Info(blob_id, fBlobHasAllLocal));
555  }
556  SetAndSaveSeq_idBlob_ids(result, seq_id, sel, ids,
557  CFixedBlob_ids(eTakeOwnership, blob_ids, state));
558  return true;
559 }
560 
561 
563  const CBlob_id& blob_id)
564 {
565  GetBlobVersion(result, blob_id);
566 }
567 
568 
570  const CBlob_id& blob_id)
571 {
572  CID1server_request id1_request;
573  x_SetParams(id1_request.SetGetblobinfo(), blob_id);
574 
575  CID1server_back reply;
576  TBlobState state = x_ResolveId(result, reply, id1_request);
577 
578  TBlobVersion version = -1;
579  switch ( reply.Which() ) {
581  if ( reply.GetGotblobinfo().GetBlob_state() < 0 ) {
583  }
585  break;
587  if ( reply.GetGotblobinfo().GetBlob_state() < 0 ) {
589  }
591  break;
593  version = 0;
594  break;
595  default:
596  ERR_POST_X(5, "CId1Reader::GetBlobVersion: "
597  "invalid ID1server-back.");
598  NCBI_THROW(CLoaderException, eLoaderFailed,
599  "CId1Reader::GetBlobVersion: "
600  "invalid ID1server-back");
601  }
602 
603  if ( version >= 0 ) {
605  }
606  SetAndSaveBlobState(result, blob_id, state);
607 }
608 
609 
612  CID1server_back& reply,
613  CID1server_request& request)
614 {
615  CConn conn(result, this);
616  x_SendRequest(conn, request);
617  x_ReceiveReply(conn, reply);
618  if ( !reply.IsError() ) {
619  conn.Release();
620  return 0;
621  }
622  TBlobState state = 0;
623  int error = reply.GetError();
624  switch ( error ) {
625  case 1:
626  state =
629  break;
630  case 2:
631  state =
634  break;
635  case 10:
636  state =
639  break;
640  case 100:
641  NCBI_THROW_FMT(CLoaderException, eConnectionFailed,
642  "ID1server-back.error "<<error);
643  default:
644  NCBI_THROW_FMT(CLoaderException, eLoaderFailed,
645  "unknown ID1server-back.error "<<error);
646  }
647  conn.Release();
648  return state;
649 }
650 
651 
653  const TBlobId& blob_id,
654  TChunkId chunk_id)
655 {
656  CLoadLockBlob blob(result, blob_id, chunk_id);
657  if ( blob.IsLoadedChunk() ) {
658  return;
659  }
660  CConn conn(result, this);
661  {{
662  CID1server_request request;
663  x_SetBlobRequest(request, blob_id);
664  x_SendRequest(conn, request);
665  }}
666  CProcessor::EType processor_type;
667  if ( blob_id.GetSubSat() == eSubSat_SNP ) {
668  processor_type = CProcessor::eType_ID1_SNP;
669  }
670  else {
671  processor_type = CProcessor::eType_ID1;
672  }
674  try {
675  m_Dispatcher->GetProcessor(processor_type)
676  .ProcessStream(result, blob_id, chunk_id, *stream);
677  }
678  catch ( CException& exc ) {
679  NCBI_RETHROW(exc, CLoaderException, eConnectionFailed,
680  "failed to receive reply: "+
681  x_ConnDescription(*stream));
682  }
683  conn.Release();
684 }
685 
686 
688  const CBlob_id& blob_id)
689 {
690  x_SetParams(request.SetGetsewithinfo(), blob_id);
691 }
692 
693 
695  const CBlob_id& blob_id)
696 {
697  if ( IsAnnotSat(blob_id.GetSat()) ) {
699  params.SetSat("ANNOT:"+NStr::NumericToString(GetExtAnnotSubSat(blob_id)));
700  params.SetGi(GI_FROM(TIntId, GetExtAnnotGi(blob_id)));
701  }
702  else {
703  params.SetMaxplex(eEntry_complexities_entry | 0xffff0); // exclude ext annots
704  params.SetSat(NStr::NumericToString(blob_id.GetSat()));
705  params.SetEnt(blob_id.GetSatKey());
706  params.SetGi(ZERO_GI);
707  }
708 }
709 
710 
712 {
713  CID1server_request id1_request;
714  x_SetParams(id1_request.SetGetsefromgi(), blob_id);
715  x_SendRequest(conn, id1_request);
716 }
717 
718 
720  CID1server_request& request)
721 {
724 
725 #ifdef GENBANK_ID1_RANDOM_FAILS
726  SetRandomFail(*stream);
727 #endif
728  if ( GetDebugLevel() >= eTraceConn ) {
729  CDebugPrinter s(conn, "CId1Reader");
730  s << "Sending";
731  if ( GetDebugLevel() >= eTraceASN ) {
732  s << ": " << MSerial_AsnText << request;
733  }
734  else {
735  s << " ID1server-request";
736  }
737  s << "...";
738  }
739  try {
740  CObjectOStreamAsnBinary out(*stream);
741  out << request;
742  out.Flush();
743  }
744  catch ( CException& exc ) {
745  NCBI_RETHROW(exc, CLoaderException, eConnectionFailed,
746  "failed to send request: "+
747  x_ConnDescription(*stream));
748  }
749  if ( GetDebugLevel() >= eTraceConn ) {
750  CDebugPrinter s(conn, "CId1Reader");
751  s << "Sent ID1server-request.";
752  }
753 }
754 
755 
757  CID1server_back& reply)
758 {
760 
761 #ifdef GENBANK_ID1_RANDOM_FAILS
762  SetRandomFail(*stream);
763 #endif
764  if ( GetDebugLevel() >= eTraceConn ) {
765  CDebugPrinter s(conn, "CId1Reader");
766  s << "Receiving ID1server-back...";
767  }
768  try {
769  CObjectIStreamAsnBinary in(*stream);
770  in >> reply;
771  }
772  catch ( CException& exc ) {
773  NCBI_RETHROW(exc, CLoaderException, eConnectionFailed,
774  "failed to receive reply: "+
775  x_ConnDescription(*stream));
776  }
777  if ( GetDebugLevel() >= eTraceConn ) {
778  CDebugPrinter s(conn, "CId1Reader");
779  s << "Received";
780  if ( GetDebugLevel() >= eTraceASN ) {
781  s << ": " << MSerial_AsnText << reply;
782  }
783  else {
784  s << " ID1server-back.";
785  }
786  }
788 }
789 
791 
793 {
794  RegisterEntryPoint<objects::CReader>(NCBI_EntryPoint_Id1Reader);
795 }
796 
797 
798 /// Class factory for ID1 reader
799 ///
800 /// @internal
801 ///
802 class CId1ReaderCF :
803  public CSimpleClassFactoryImpl<objects::CReader, objects::CId1Reader>
804 {
805 public:
806  typedef CSimpleClassFactoryImpl<objects::CReader,
807  objects::CId1Reader> TParent;
808 public:
812 
813  objects::CReader*
814  CreateInstance(const string& driver = kEmptyStr,
816  NCBI_INTERFACE_VERSION(objects::CReader),
817  const TPluginManagerParamTree* params = 0) const
818  {
819  objects::CReader* drv = 0;
820  if ( !driver.empty() && driver != m_DriverName ) {
821  return 0;
822  }
823  if (version.Match(NCBI_INTERFACE_VERSION(objects::CReader))
825  drv = new objects::CId1Reader(params, driver);
826  }
827  return drv;
828  }
829 };
830 
831 
835 {
837 }
838 
839 
843 {
844  NCBI_EntryPoint_Id1Reader(info_list, method);
845 }
846 
847 
TSat GetSat() const
Definition: blob_id.hpp:56
TSatKey GetSatKey() const
Definition: blob_id.hpp:64
TSubSat GetSubSat() const
Definition: blob_id.hpp:60
Base class, inherited from "std::iostream", does both input and output, using the specified CONNECTOR...
Definition: Dbtag.hpp:53
CID1blob_info –.
@ID1server_back.hpp User-defined methods of the data storage class.
CID1server_maxcomplex –.
CID1server_request –.
static TIntId GetExtAnnotGi(const CBlob_id &blob_id)
static void CreateExtAnnotBlob_ids(TBlobIds &blob_ids, TIntId gi, int ext_feat)
static bool IsAnnotSat(int sat)
static int GetExtAnnotSubSat(const CBlob_id &blob_id)
Class factory for ID1 reader.
Definition: reader_id1.cpp:804
CSimpleClassFactoryImpl< objects::CReader, objects::CId1Reader > TParent
Definition: reader_id1.cpp:807
objects::CReader * CreateInstance(const string &driver=kEmptyStr, CVersionInfo version=NCBI_INTERFACE_VERSION(objects::CReader), const TPluginManagerParamTree *params=0) const
Create instance of TDriver.
Definition: reader_id1.cpp:814
void GetBlobVersion(CReaderRequestResult &result, const CBlob_id &blob_id)
Definition: reader_id1.cpp:569
CReaderServiceConnector m_Connector
Definition: reader_id1.hpp:110
void GetBlobState(CReaderRequestResult &result, const CBlob_id &blob_id)
Definition: reader_id1.cpp:562
virtual void x_AddConnectionSlot(TConn conn)
Definition: reader_id1.cpp:174
void x_SetParams(CID1server_maxcomplex &params, const CBlob_id &blob_id)
Definition: reader_id1.cpp:694
TBlobState x_ResolveId(CReaderRequestResult &result, CID1server_back &id1_reply, CID1server_request &id1_request)
Definition: reader_id1.cpp:611
void x_ReceiveReply(TConn conn, CID1server_back &reply)
Definition: reader_id1.cpp:756
bool LoadSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &id)
Definition: reader_id1.cpp:292
bool LoadSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &id, const SAnnotSelector *sel)
All LoadXxx() methods should return false if there is no requested data in the reader.
Definition: reader_id1.cpp:397
void x_SendRequest(TConn conn, CID1server_request &request)
Definition: reader_id1.cpp:719
CId1Reader(int max_connections=0)
Definition: reader_id1.cpp:129
virtual void x_RemoveConnectionSlot(TConn conn)
Definition: reader_id1.cpp:181
void x_SetBlobRequest(CID1server_request &request, const CBlob_id &blob_id)
Definition: reader_id1.cpp:687
void GetBlob(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id)
Definition: reader_id1.cpp:652
CConn_IOStream * x_GetConnection(TConn conn)
Definition: reader_id1.cpp:199
bool LoadSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader_id1.cpp:268
string x_ConnDescription(CConn_IOStream &stream) const
Definition: reader_id1.cpp:211
virtual void x_ConnectAtSlot(TConn conn)
Definition: reader_id1.cpp:217
virtual void x_DisconnectAtSlot(TConn conn, bool failed)
Definition: reader_id1.cpp:187
TConnections m_Connections
Definition: reader_id1.hpp:113
bool LoadGiBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel)
Definition: reader_id1.cpp:466
bool LoadGiSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader_id1.cpp:341
int GetMaximumConnectionsLimit(void) const
Definition: reader_id1.cpp:164
bool SetNoBlob_ids(const CFixedBlob_ids::TState &state, TExpirationTime expiration_time)
bool SetLoadedBlob_ids(const TData &data, TExpirationTime expiration_time)
bool IsLoadedChunk(void) const
bool IsLoadedGi(void) const
static bool IsFound(const TData &data)
static TGi GetGi(const TData &data)
bool SetLoadedSeq_ids(const TData &data)
Data loader exceptions, used by GenBank loader.
CObjectIStreamAsnBinary –.
Definition: objistrasnb.hpp:59
CObjectOStreamAsnBinary –.
Definition: objostrasnb.hpp:58
TId8 GetId8(void) const
Definition: Object_id.cpp:164
static TGi ConvertGiFromOM(TGi gi)
Definition: processor.hpp:139
static void OffsetAllGisToOM(CBeginInfo obj, CTSE_SetObjectInfo *set_info=0)
Definition: processors.cpp:590
virtual void ProcessStream(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id, CNcbiIstream &stream) const
Definition: processors.cpp:237
static bool TrySNPSplit(void)
Definition: processors.cpp:328
static void OffsetAllGisFromOM(CBeginInfo obj)
Definition: processors.cpp:584
const CProcessor & GetProcessor(CProcessor::EType type) const
Definition: dispatcher.cpp:219
void LoadSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
void LoadSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
void LoadSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel)
void RememberIfBad(SConnInfo &conn_info)
void SetTimeoutTo(STimeout *tmout) const
void InitTimeouts(CConfig &conf, const string &driver_name)
SConnInfo Connect(int error_count=0)
string GetConnDescription(CConn_IOStream &stream) const
void SetServiceName(const string &service_name)
vector< CSeq_id_Handle > TSeqIds
Definition: reader.hpp:96
CReadDispatcher * m_Dispatcher
Definition: reader.hpp:353
void SetAndSaveNoSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel, const CLoadLockGi &gi_lock) const
Definition: reader.cpp:1206
void SetAndSaveSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const TSequenceGi &gi) const
Definition: reader.cpp:1233
void SetAndSaveBlobVersion(CReaderRequestResult &result, const TBlobId &blob_id, TBlobVersion version) const
Definition: reader.cpp:1110
int TBlobVersion
Definition: reader.hpp:91
vector< CBlob_Info > TBlobIds
Definition: reader.hpp:97
void SetAndSaveBlobState(CReaderRequestResult &result, const TBlobId &blob_id, TBlobState blob_state) const
Definition: reader.cpp:1097
void SetAndSaveSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const CFixedSeq_ids &seq_ids) const
Definition: reader.cpp:1123
unsigned TConn
Definition: reader.hpp:87
void x_ReportDisconnect(const char *reader, const char *server, TConn conn, bool failed) const
Definition: reader.cpp:444
virtual void OpenConnection(TConn conn)
Definition: reader.cpp:326
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:1341
int TChunkId
Definition: reader.hpp:93
void InitParams(CConfig &conf, const string &driver_name, int default_max_conn)
Definition: reader.cpp:131
int SetMaximumConnections(int max)
Definition: reader.cpp:228
virtual 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.
Definition: reader.cpp:884
int TBlobState
Definition: reader.hpp:90
void SetAndSaveNoSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TState state) const
Definition: reader.cpp:1222
CRef –.
Definition: ncbiobj.hpp:618
CSafeStatic<>::
Template class helps to implement one driver class factory.
class CStaticArrayMap<> is an array adaptor that provides an STLish interface to statically-defined a...
Definition: static_map.hpp:105
TBase::const_iterator const_iterator
Definition: static_map.hpp:109
definition of a Culling tree
Definition: ncbi_tree.hpp:100
CVersionInfo –.
void erase(iterator pos)
Definition: map.hpp:167
std::ofstream out("events_result.xml")
main entry point for tests
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
int failed
Definition: dbmorecmds.c:10
char data[12]
Definition: iconv.c:80
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
Definition: ncbimisc.hpp:480
#define GI_FROM(T, value)
Definition: ncbimisc.hpp:1086
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:469
Int8 TIntId
Definition: ncbimisc.hpp:999
#define ZERO_GI
Definition: ncbimisc.hpp:1088
#define GI_TO(T, gi)
Definition: ncbimisc.hpp:1085
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
CONN GetCONN(void) const
EIO_Status CONN_SetTimeout(CONN conn, EIO_Event event, const STimeout *timeout)
Specify timeout for the connection I/O, including "Connect" (aka "Open") and "Close".
#define _VERIFY(expr)
Definition: ncbidbg.hpp:161
#define LOG_POST_X(err_subcode, message)
Definition: ncbidiag.hpp:553
#define ERR_POST_X_ONCE(err_subcode, message)
Error posting only once during program execution with default error code and given error subcode.
Definition: ncbidiag.hpp:621
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#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
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
string GetString(const string &driver_name, const string &param_name, EErrAction on_error, const string &default_value, const list< string > *synonyms=NULL)
Utility function to get an element of parameter tree Throws an exception when mandatory parameter is ...
@ eErr_NoThrow
Return default value on error.
CConstRef< CSeq_id > GetSeqId(void) const
static CSeq_id_Handle GetGiHandle(TGi gi)
Faster way to create a handle for a gi.
bool IsGi(void) const
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
CSeq_id::E_Choice Which(void) const
TGi GetGi(void) const
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
const TNamedAnnotAccessions & GetNamedAnnotAccessions(void) const
#define NCBI_PARAM_TYPE(section, name)
Generate typename for a parameter from its {section, name} attributes.
Definition: ncbi_param.hpp:149
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
static void NCBI_EntryPointImpl(TDriverInfoList &info_list, EEntryPointRequest method)
Entry point implementation.
#define NCBI_INTERFACE_VERSION(iface)
Macro to construct CVersionInfo class using interface name (relies on CInterfaceVersion class)
list< SDriverInfo > TDriverInfoList
List of driver information.
EEntryPointRequest
Actions performed by the entry point.
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#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 kEmptyStr
Definition: ncbistr.hpp:123
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
unsigned int usec
microseconds (modulo 1,000,000)
Definition: ncbi_types.h:78
unsigned int sec
seconds
Definition: ncbi_types.h:77
@ eIO_ReadWrite
eIO_Read | eIO_Write (also, eCONN_OnFlush)
Definition: ncbi_core.h:122
@ eIO_Close
also serves as an error indicator in SOCK_Poll
Definition: ncbi_core.h:123
@ eNonCompatible
major, minor does not match
const TTag & GetTag(void) const
Get the Tag member data.
Definition: Dbtag_.hpp:267
const TDb & GetDb(void) const
Get the Db member data.
Definition: Dbtag_.hpp:220
void SetEnt(TEnt value)
Assign a value to Ent data member.
const TGotblobinfo & GetGotblobinfo(void) const
Get the variant data.
void SetGi(TGi value)
Assign a value to Gi data member.
bool IsIds(void) const
Check if variant Ids is selected.
TBlob_state GetBlob_state(void) const
Get the Blob_state member data.
TGetsefromgi & SetGetsefromgi(void)
Select the variant.
E_Choice Which(void) const
Which variant is currently selected.
TError GetError(void) const
Get the variant data.
bool IsError(void) const
Check if variant Error is selected.
bool IsGotgi(void) const
Check if variant Gotgi is selected.
const TGotsewithinfo & GetGotsewithinfo(void) const
Get the variant data.
void SetSat(const TSat &value)
Assign a value to Sat data member.
TGotgi GetGotgi(void) const
Get the variant data.
const TIds & GetIds(void) const
Get the variant data.
TGetblobinfo & SetGetblobinfo(void)
Select the variant.
void SetMaxplex(TMaxplex value)
Assign a value to Maxplex data member.
TGetseqidsfromgi & SetGetseqidsfromgi(void)
Select the variant.
TGetsewithinfo & SetGetsewithinfo(void)
Select the variant.
TGetgi & SetGetgi(void)
Select the variant.
list< CRef< CSeq_id > > TIds
bool IsGotblobinfo(void) const
Check if variant Gotblobinfo is selected.
const TBlob_info & GetBlob_info(void) const
Get the Blob_info member data.
@ eEntry_complexities_entry
the "natural" entry for this (nuc-prot)
TGi GetGi(void) const
Get the variant data.
Definition: Seq_id_.hpp:889
const TGeneral & GetGeneral(void) const
Get the variant data.
Definition: Seq_id_.cpp:369
@ e_General
for other databases
Definition: Seq_id_.hpp:105
@ e_Gi
GenInfo Integrated Database.
Definition: Seq_id_.hpp:106
Definition of all error codes used in objtools libraries.
static MDB_envinfo info
Definition: mdb_load.c:37
static int version
Definition: mdb_load.c:29
string s_Value(TValue value)
#define abs(a)
Definition: ncbi_heapmgr.c:130
Multi-threading – mutexes; rw-locks; semaphore.
std::istream & in(std::istream &in_, double &x_)
@ fBlobHasAllLocal
Definition: blob_id.hpp:196
Helper classes and templates to implement plugins.
#define MAX_MT_CONN
Definition: reader_id1.cpp:76
static const TSI sc_SatIndex[]
Definition: reader_id1.cpp:249
#define DEFAULT_NUM_CONN
Definition: reader_id1.cpp:75
static bool sx_IsSNPOnly(const SAnnotSelector::TNamedAnnotAccessions &accs)
Definition: reader_id1.cpp:386
#define GENBANK_ID1_RANDOM_FAILS_RECOVER
Definition: reader_id1.cpp:80
EDebugLevel
Definition: reader_id1.cpp:120
@ eTraceOpen
Definition: reader_id1.cpp:122
@ eTraceASN
Definition: reader_id1.cpp:124
@ eTraceError
Definition: reader_id1.cpp:121
@ eTraceASNData
Definition: reader_id1.cpp:125
@ eTraceConn
Definition: reader_id1.cpp:123
void NCBI_EntryPoint_xreader_id1(CPluginManager< objects::CReader >::TDriverInfoList &info_list, CPluginManager< objects::CReader >::EEntryPointRequest method)
Definition: reader_id1.cpp:840
CId1ReaderBase TRDR
Definition: reader_id1.cpp:246
DEFINE_STATIC_ARRAY_MAP(TSatMap, sc_SatMap, sc_SatIndex)
void GenBankReaders_Register_Id1(void)
Definition: reader_id1.cpp:792
NCBI_PARAM_DECL(int, GENBANK, ID1_DEBUG)
SStaticPair< TRDR::ESat, TRDR::ESubSat > TSK
Definition: reader_id1.cpp:247
#define DEFAULT_SERVICE
Definition: reader_id1.cpp:74
static int GetDebugLevel(void)
Definition: reader_id1.cpp:112
void NCBI_EntryPoint_Id1Reader(CPluginManager< objects::CReader >::TDriverInfoList &info_list, CPluginManager< objects::CReader >::EEntryPointRequest method)
Definition: reader_id1.cpp:832
#define GENBANK_ID1_RANDOM_FAILS_FREQUENCY
Definition: reader_id1.cpp:79
SStaticPair< const char *, TSK > TSI
Definition: reader_id1.cpp:248
#define SetRandomFail(stream)
Definition: reader_id1.cpp:96
NCBI_PARAM_DEF_EX(int, GENBANK, ID1_DEBUG, 0, eParam_NoThread, GENBANK_ID1_DEBUG)
CStaticPairArrayMap< const char *, TSK, PNocase_CStr > TSatMap
Definition: reader_id1.cpp:264
#define NCBI_GBLOADER_READER_ID1_PARAM_SERVICE_NAME
#define NCBI_GBLOADER_READER_ID1_DRIVER_NAME
NCBI
Definition: static_set.hpp:72
Better replacement of GetGi(), this method should be defined in data loaders, GetGi() is left for com...
AutoPtr< CConn_IOStream > m_Stream
SAnnotSelector –.
Template structure SStaticPair is simlified replacement of STL pair<> Main reason of introducing this...
Definition: static_set.hpp:60
Timeout structure.
Definition: ncbi_types.h:76
#define _ASSERT
else result
Definition: token2.c:20
Modified on Fri Apr 26 16:26:44 2024 by modify_doxy.py rev. 669887