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

Go to the SVN repository for this file.

1 /* $Id: dispatcher.cpp 71299 2016-02-24 19:31:13Z 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  * Author: Anton Butanaev, Eugene Vasilchenko
25  *
26  * File Description: Base data reader interface
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
37 #include <objtools/error_codes.hpp>
41 
42 
43 #define NCBI_USE_ERRCODE_X Objtools_Rd_Disp
44 
46 
48 
50 
51 NCBI_PARAM_DECL(bool, GENBANK, ALLOW_INCOMPLETE_COMMANDS);
52 NCBI_PARAM_DEF_EX(bool, GENBANK, ALLOW_INCOMPLETE_COMMANDS, false,
53  eParam_NoThread, GENBANK_ALLOW_INCOMPLETE_COMMANDS);
54 
55 static
57 {
59  return s_Value->Get();
60 }
61 
62 
63 /////////////////////////////////////////////////////////////////////////////
64 // CReadDispatcher
65 /////////////////////////////////////////////////////////////////////////////
66 
67 
69 {
70  CGBRequestStatistics("resolved", "string ids"),
71  CGBRequestStatistics("resolved", "seq-ids"),
72  CGBRequestStatistics("resolved", "gis"),
73  CGBRequestStatistics("resolved", "accs"),
74  CGBRequestStatistics("resolved", "labels"),
75  CGBRequestStatistics("resolved", "taxids"),
76  CGBRequestStatistics("resolved", "blob ids"),
77  CGBRequestStatistics("resolved", "blob state"),
78  CGBRequestStatistics("resolved", "blob versions"),
79  CGBRequestStatistics("loaded", "blob data"),
80  CGBRequestStatistics("loaded", "SNP data"),
81  CGBRequestStatistics("loaded", "split data"),
82  CGBRequestStatistics("loaded", "chunk data"),
83  CGBRequestStatistics("parsed", "blob data"),
84  CGBRequestStatistics("parsed", "SNP data"),
85  CGBRequestStatistics("parsed", "split data"),
86  CGBRequestStatistics("parsed", "chunk data"),
87  CGBRequestStatistics("loaded", "sequence hash"),
88  CGBRequestStatistics("loaded", "sequence length"),
89  CGBRequestStatistics("loaded", "sequence type")
90 };
91 
93  const char* entity)
94  : m_Action(action), m_Entity(entity),
95  m_Count(0), m_Time(0), m_Size(0)
96 {
97 }
98 
100 {
102  NCBI_THROW_FMT(CLoaderException, eOtherError,
103  "CGBRequestStatistics::GetStatistics: "
104  "invalid statistics type: "<<type);
105  }
106  return sx_Statistics[type];
107 }
108 
110 {
111  size_t count = GetCount();
112  if ( count > 0 ) {
113  double time = GetTime();
114  double size = GetSize();
115  if ( size <= 0 ) {
116  LOG_POST_X(5, "GBLoader: " << GetAction() << ' ' <<
117  count << ' ' << GetEntity() << " in " <<
118  setiosflags(ios::fixed) <<
119  setprecision(3) <<
120  (time) << " s (" <<
121  (time*1000/count) << " ms/one)");
122  }
123  else {
124  LOG_POST_X(6, "GBLoader: " << GetAction() << ' ' <<
125  count << ' ' << GetEntity() << " in " <<
126  setiosflags(ios::fixed) <<
127  setprecision(3) <<
128  (time) << " s (" <<
129  (time*1000/count) << " ms/one)" <<
130  setprecision(2) << " (" <<
131  (size/1024.0) << " kB " <<
132  (size/time/1024) << " kB/s)");
133  }
134  }
135 }
136 
137 
139 {
140  for ( int type = eStat_First; type <= eStat_Last; ++type ) {
141  sx_Statistics[type].PrintStat();
142  }
143 }
144 
145 inline
147 {
149  return s_Value->Get();
150 }
151 
152 
154 {
157 }
158 
159 
161 {
162  if ( CollectStatistics() > 0 ) {
164  }
165 }
166 
167 
169 {
170  if ( !reader ) {
171  return;
172  }
173 
174  m_Readers[level] = reader;
175  reader->m_Dispatcher = this;
176 }
177 
178 
180 {
181  if ( !writer ) {
182  return;
183  }
184 
185  m_Writers[level] = writer;
186 }
187 
188 
190 {
191  if ( !processor ) {
192  return;
193  }
194 
195  m_Processors[processor->GetType()] = processor;
196 }
197 
198 
200  CWriter::EType type) const
201 {
202  ITERATE ( TWriters, i, m_Writers ) {
203  if ( i->first >= result.GetLevel() ) {
204  break;
205  }
206  if ( i->second->CanWrite(type) ) {
207  return const_cast<CWriter*>(i->second.GetPointer());
208  }
209  }
210  return 0;
211 }
212 
213 
215 {
217  if ( iter == m_Processors.end() ) {
218  NCBI_THROW_FMT(CLoaderException, eLoaderFailed,
219  "CReadDispatcher::GetProcessor: "
220  "processor unknown: "<<type);
221  }
222  return *iter->second;
223 }
224 
225 
227 {
228  if ( m_Readers.empty() ) {
229  NCBI_THROW(CLoaderException, eLoaderFailed, "no reader loaded");
230  }
231 }
232 
233 
235 {
237  rd->second->ResetCache();
238  }
240  wr->second->ResetCache();
241  }
242 }
243 
244 
246  : m_Result(result)
247 {
248 }
249 
250 
252 {
253 }
254 
255 
257 {
258  return false;
259 }
260 
261 
262 namespace {
263  class CCommandLoadSeq_idSeq_ids : public CReadDispatcherCommand
264  {
265  public:
266  typedef CSeq_id_Handle TKey;
267  typedef CLoadLockSeqIds TLock;
268  CCommandLoadSeq_idSeq_ids(CReaderRequestResult& result,
269  const TKey& key)
270  : CReadDispatcherCommand(result),
271  m_Key(key), m_Lock(result, key)
272  {
273  }
274 
275  bool IsDone(void)
276  {
277  return m_Lock.IsLoaded();
278  }
279  bool Execute(CReader& reader)
280  {
281  return reader.LoadSeq_idSeq_ids(GetResult(), m_Key);
282  }
283  string GetErrMsg(void) const
284  {
285  return "LoadSeq_idSeq_ids("+m_Key.AsString()+"): "
286  "data not found";
287  }
289  {
291  }
292  string GetStatisticsDescription(void) const
293  {
294  return "Seq-ids("+m_Key.AsString()+")";
295  }
296 
297  private:
298  TKey m_Key;
299  TLock m_Lock;
300  };
301 
302  class CCommandLoadSeq_idGi : public CReadDispatcherCommand
303  {
304  public:
305  typedef CSeq_id_Handle TKey;
306  typedef CLoadLockGi TLock;
307  CCommandLoadSeq_idGi(CReaderRequestResult& result,
308  const TKey& key)
309  : CReadDispatcherCommand(result),
310  m_Key(key), m_Lock(result, key)
311  {
312  }
313 
314  bool IsDone(void)
315  {
316  return m_Lock.IsLoadedGi();
317  }
318  bool Execute(CReader& reader)
319  {
320  return reader.LoadSeq_idGi(GetResult(), m_Key);
321  }
322  string GetErrMsg(void) const
323  {
324  return "LoadSeq_idGi("+m_Key.AsString()+"): "
325  "data not found";
326  }
328  {
330  }
331  string GetStatisticsDescription(void) const
332  {
333  return "gi("+m_Key.AsString()+")";
334  }
335 
336  private:
337  TKey m_Key;
338  TLock m_Lock;
339  };
340 
341  class CCommandLoadSeq_idAccVer : public CReadDispatcherCommand
342  {
343  public:
344  typedef CSeq_id_Handle TKey;
345  typedef CLoadLockAcc TLock;
346  CCommandLoadSeq_idAccVer(CReaderRequestResult& result,
347  const TKey& key)
348  : CReadDispatcherCommand(result),
349  m_Key(key), m_Lock(result, key)
350  {
351  }
352 
353  bool IsDone(void)
354  {
355  return m_Lock.IsLoadedAccVer();
356  }
357  bool Execute(CReader& reader)
358  {
359  return reader.LoadSeq_idAccVer(GetResult(), m_Key);
360  }
361  string GetErrMsg(void) const
362  {
363  return "LoadSeq_idAccVer("+m_Key.AsString()+"): "
364  "data not found";
365  }
367  {
369  }
370  string GetStatisticsDescription(void) const
371  {
372  return "acc("+m_Key.AsString()+")";
373  }
374 
375  private:
376  TKey m_Key;
377  TLock m_Lock;
378  };
379 
380  class CCommandLoadSeq_idLabel : public CReadDispatcherCommand
381  {
382  public:
383  typedef CSeq_id_Handle TKey;
384  typedef CLoadLockLabel TLock;
385  CCommandLoadSeq_idLabel(CReaderRequestResult& result,
386  const TKey& key)
387  : CReadDispatcherCommand(result),
388  m_Key(key), m_Lock(result, key)
389  {
390  }
391 
392  bool IsDone(void)
393  {
394  return m_Lock.IsLoadedLabel();
395  }
396  bool Execute(CReader& reader)
397  {
398  return reader.LoadSeq_idLabel(GetResult(), m_Key);
399  }
400  string GetErrMsg(void) const
401  {
402  return "LoadSeq_idLabel("+m_Key.AsString()+"): "
403  "data not found";
404  }
406  {
408  }
409  string GetStatisticsDescription(void) const
410  {
411  return "label("+m_Key.AsString()+")";
412  }
413 
414  private:
415  TKey m_Key;
416  TLock m_Lock;
417  };
418 
419  class CCommandLoadSeq_idTaxId : public CReadDispatcherCommand
420  {
421  public:
422  typedef CSeq_id_Handle TKey;
423  typedef CLoadLockTaxId TLock;
424  CCommandLoadSeq_idTaxId(CReaderRequestResult& result,
425  const TKey& key)
426  : CReadDispatcherCommand(result),
427  m_Key(key), m_Lock(result, key)
428  {
429  }
430 
431  bool IsDone(void)
432  {
433  return m_Lock.IsLoadedTaxId();
434  }
435  bool Execute(CReader& reader)
436  {
437  return reader.LoadSeq_idTaxId(GetResult(), m_Key);
438  }
439  bool MayBeSkipped(void) const
440  {
441  return true;
442  }
443  string GetErrMsg(void) const
444  {
445  return "LoadSeq_idTaxId("+m_Key.AsString()+"): "
446  "data not found";
447  }
449  {
451  }
452  string GetStatisticsDescription(void) const
453  {
454  return "taxid("+m_Key.AsString()+")";
455  }
456 
457  private:
458  TKey m_Key;
459  TLock m_Lock;
460  };
461 
462  class CCommandLoadSequenceHash : public CReadDispatcherCommand
463  {
464  public:
465  typedef CSeq_id_Handle TKey;
466  typedef CLoadLockHash TLock;
467  CCommandLoadSequenceHash(CReaderRequestResult& result,
468  const TKey& key)
469  : CReadDispatcherCommand(result),
470  m_Key(key), m_Lock(result, key)
471  {
472  }
473 
474  bool IsDone(void)
475  {
476  return m_Lock.IsLoadedHash();
477  }
478  bool Execute(CReader& reader)
479  {
480  return reader.LoadSequenceHash(GetResult(), m_Key);
481  }
482  bool MayBeSkipped(void) const
483  {
484  return true;
485  }
486  string GetErrMsg(void) const
487  {
488  return "LoadSequenceHash("+m_Key.AsString()+"): "
489  "data not found";
490  }
492  {
494  }
495  string GetStatisticsDescription(void) const
496  {
497  return "hash("+m_Key.AsString()+")";
498  }
499 
500  private:
501  TKey m_Key;
502  TLock m_Lock;
503  };
504 
505  class CCommandLoadSequenceLength : public CReadDispatcherCommand
506  {
507  public:
508  typedef CSeq_id_Handle TKey;
509  typedef CLoadLockLength TLock;
510  CCommandLoadSequenceLength(CReaderRequestResult& result,
511  const TKey& key)
512  : CReadDispatcherCommand(result),
513  m_Key(key), m_Lock(result, key)
514  {
515  }
516 
517  bool IsDone(void)
518  {
519  return m_Lock.IsLoadedLength();
520  }
521  bool Execute(CReader& reader)
522  {
523  return reader.LoadSequenceLength(GetResult(), m_Key);
524  }
525  bool MayBeSkipped(void) const
526  {
527  return true;
528  }
529  string GetErrMsg(void) const
530  {
531  return "LoadSequenceLength("+m_Key.AsString()+"): "
532  "data not found";
533  }
535  {
537  }
538  string GetStatisticsDescription(void) const
539  {
540  return "length("+m_Key.AsString()+")";
541  }
542 
543  private:
544  TKey m_Key;
545  TLock m_Lock;
546  };
547 
548  class CCommandLoadSequenceType : public CReadDispatcherCommand
549  {
550  public:
551  typedef CSeq_id_Handle TKey;
552  typedef CLoadLockType TLock;
553  CCommandLoadSequenceType(CReaderRequestResult& result,
554  const TKey& key)
555  : CReadDispatcherCommand(result),
556  m_Key(key), m_Lock(result, key)
557  {
558  }
559 
560  bool IsDone(void)
561  {
562  return m_Lock.IsLoadedType();
563  }
564  bool Execute(CReader& reader)
565  {
566  return reader.LoadSequenceType(GetResult(), m_Key);
567  }
568  bool MayBeSkipped(void) const
569  {
570  return true;
571  }
572  string GetErrMsg(void) const
573  {
574  return "LoadSequenceType("+m_Key.AsString()+"): "
575  "data not found";
576  }
578  {
580  }
581  string GetStatisticsDescription(void) const
582  {
583  return "type("+m_Key.AsString()+")";
584  }
585 
586  private:
587  TKey m_Key;
588  TLock m_Lock;
589  };
590 
591  bool s_Blob_idsLoaded(CLoadLockBlobIds& ids,
592  CReaderRequestResult& result,
593  const CSeq_id_Handle& seq_id)
594  {
595  if ( ids.IsLoaded() ) {
596  return true;
597  }
598  // check if seq-id is known as absent
599  CLoadLockSeqIds seq_ids(result, seq_id, eAlreadyLoaded);
600  if ( seq_ids && !seq_ids.GetData().IsFound() ) {
601  // mark blob-ids as absent too
602  ids.SetNoBlob_ids(seq_ids.GetState());
603  return true;
604  }
605  return false;
606  }
607 
608  class CCommandLoadSeq_idBlob_ids : public CReadDispatcherCommand
609  {
610  public:
611  typedef CSeq_id_Handle TKey;
612  typedef CLoadLockBlobIds TLock;
613  CCommandLoadSeq_idBlob_ids(CReaderRequestResult& result,
614  const TKey& key,
615  const SAnnotSelector* sel)
616  : CReadDispatcherCommand(result),
617  m_Key(key), m_Selector(sel),
618  m_Lock(result, key, sel)
619  {
620  }
621 
622  bool IsDone(void)
623  {
624  return s_Blob_idsLoaded(m_Lock, GetResult(), m_Key);
625  }
626  bool Execute(CReader& reader)
627  {
628  return reader.LoadSeq_idBlob_ids(GetResult(),
629  m_Key, m_Selector);
630  }
631  string GetErrMsg(void) const
632  {
633  return "LoadSeq_idBlob_ids("+m_Key.AsString()+"): "
634  "data not found";
635  }
637  {
639  }
640  string GetStatisticsDescription(void) const
641  {
642  return "blob-ids("+m_Key.AsString()+")";
643  }
644 
645  private:
646  TKey m_Key;
647  const SAnnotSelector* m_Selector;
648  TLock m_Lock;
649  };
650 
651  template<class CLoadLock>
652  bool sx_IsLoaded(size_t i,
653  CReaderRequestResult& result,
654  const vector<CSeq_id_Handle>& ids,
655  const vector<bool>& loaded)
656  {
657  if ( loaded[i] || CReadDispatcher::CannotProcess(ids[i]) ) {
658  return true;
659  }
660  CLoadLock lock(result, ids[i]);
661  if ( lock.IsLoaded() && !lock.IsFound() ) {
662  return true;
663  }
664  return false;
665  }
666 
667  template<class CLoadLock>
668  bool sx_BulkIsDone(CReaderRequestResult& result,
669  const vector<CSeq_id_Handle>& ids,
670  const vector<bool>& loaded)
671  {
672  for ( size_t i = 0; i < ids.size(); ++i ) {
673  if ( sx_IsLoaded<CLoadLock>(i, result, ids, loaded) ) {
674  continue;
675  }
676  return false;
677  }
678  return true;
679  }
680 
681  template<class CLoadLock>
682  string sx_DescribeError(CReaderRequestResult& result,
683  const vector<CSeq_id_Handle>& ids,
684  const vector<bool>& loaded)
685  {
686  string ret;
687  for ( size_t i = 0; i < ids.size(); ++i ) {
688  if ( sx_IsLoaded<CLoadLock>(i, result, ids, loaded) ) {
689  continue;
690  }
691  if ( !ret.empty() ) {
692  ret += ", ";
693  }
694  ret += ids[i].AsString();
695  }
696  ret += " ["+NStr::SizetToString(ids.size())+"]";
697  return ret;
698  }
699 
700  class CCommandLoadAccVers : public CReadDispatcherCommand
701  {
702  public:
703  typedef vector<CSeq_id_Handle> TKey;
704  typedef vector<bool> TLoaded;
705  typedef vector<CSeq_id_Handle> TRet;
706  typedef CLoadLockAcc CLoadLock;
707  CCommandLoadAccVers(CReaderRequestResult& result,
708  const TKey& key, TLoaded& loaded, TRet& ret)
709  : CReadDispatcherCommand(result),
710  m_Key(key), m_Loaded(loaded), m_Ret(ret)
711  {
712  }
713 
714  bool Execute(CReader& reader)
715  {
716  return reader.LoadAccVers(GetResult(), m_Key, m_Loaded, m_Ret);
717  }
718  bool IsDone(void)
719  {
720  return sx_BulkIsDone<CLoadLock>(GetResult(), m_Key, m_Loaded);
721  }
722  string GetErrMsg(void) const
723  {
724  return "LoadAccVers("+
725  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
726  "): data not found";
727  }
728  string GetStatisticsDescription(void) const
729  {
730  return "accs("+
731  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
732  ")";
733  }
735  {
737  }
738 
739  private:
740  const TKey& m_Key;
741  TLoaded& m_Loaded;
742  TRet& m_Ret;
743  };
744 
745  class CCommandLoadGis : public CReadDispatcherCommand
746  {
747  public:
748  typedef vector<CSeq_id_Handle> TKey;
749  typedef vector<bool> TLoaded;
750  typedef vector<TGi> TRet;
751  typedef CLoadLockGi CLoadLock;
752  CCommandLoadGis(CReaderRequestResult& result,
753  const TKey& key, TLoaded& loaded, TRet& ret)
754  : CReadDispatcherCommand(result),
755  m_Key(key), m_Loaded(loaded), m_Ret(ret)
756  {
757  }
758 
759  bool Execute(CReader& reader)
760  {
761  return reader.LoadGis(GetResult(), m_Key, m_Loaded, m_Ret);
762  }
763  bool IsDone(void)
764  {
765  return sx_BulkIsDone<CLoadLock>(GetResult(), m_Key, m_Loaded);
766  }
767  string GetErrMsg(void) const
768  {
769  return "LoadGis("+
770  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
771  "): data not found";
772  }
773  string GetStatisticsDescription(void) const
774  {
775  return "gis("+
776  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
777  ")";
778  }
780  {
782  }
783 
784  private:
785  const TKey& m_Key;
786  TLoaded& m_Loaded;
787  TRet& m_Ret;
788  };
789 
790  class CCommandLoadLabels : public CReadDispatcherCommand
791  {
792  public:
793  typedef vector<CSeq_id_Handle> TKey;
794  typedef vector<bool> TLoaded;
795  typedef vector<string> TRet;
796  typedef CLoadLockLabel CLoadLock;
797  CCommandLoadLabels(CReaderRequestResult& result,
798  const TKey& key, TLoaded& loaded, TRet& ret)
799  : CReadDispatcherCommand(result),
800  m_Key(key), m_Loaded(loaded), m_Ret(ret)
801  {
802  }
803 
804  bool Execute(CReader& reader)
805  {
806  return reader.LoadLabels(GetResult(), m_Key, m_Loaded, m_Ret);
807  }
808  bool IsDone(void)
809  {
810  return sx_BulkIsDone<CLoadLock>(GetResult(), m_Key, m_Loaded);
811  }
812  string GetErrMsg(void) const
813  {
814  return "LoadLabels("+
815  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
816  "): data not found";
817  }
818  string GetStatisticsDescription(void) const
819  {
820  return "labels("+
821  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
822  ")";
823  }
825  {
827  }
828 
829  private:
830  const TKey& m_Key;
831  TLoaded& m_Loaded;
832  TRet& m_Ret;
833  };
834 
835  class CCommandLoadTaxIds : public CReadDispatcherCommand
836  {
837  public:
838  typedef vector<CSeq_id_Handle> TKey;
839  typedef vector<bool> TLoaded;
840  typedef vector<int> TRet;
841  typedef CLoadLockTaxId CLoadLock;
842  CCommandLoadTaxIds(CReaderRequestResult& result,
843  const TKey& key, TLoaded& loaded, TRet& ret)
844  : CReadDispatcherCommand(result),
845  m_Key(key), m_Loaded(loaded), m_Ret(ret)
846  {
847  }
848 
849  bool Execute(CReader& reader)
850  {
851  return reader.LoadTaxIds(GetResult(), m_Key, m_Loaded, m_Ret);
852  }
853  bool MayBeSkipped(void) const
854  {
855  return true;
856  }
857  bool IsDone(void)
858  {
859  return sx_BulkIsDone<CLoadLock>(GetResult(), m_Key, m_Loaded);
860  }
861  string GetErrMsg(void) const
862  {
863  return "LoadTaxIds("+
864  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
865  "): data not found";
866  }
867  string GetStatisticsDescription(void) const
868  {
869  return "taxids("+
870  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
871  ")";
872  }
874  {
876  }
877 
878  private:
879  const TKey& m_Key;
880  TLoaded& m_Loaded;
881  TRet& m_Ret;
882  };
883 
884  class CCommandLoadHashes : public CReadDispatcherCommand
885  {
886  public:
887  typedef vector<CSeq_id_Handle> TKey;
888  typedef vector<bool> TLoaded;
889  typedef vector<bool> TKnown;
890  typedef vector<int> TRet;
891  typedef CLoadLockHash CLoadLock;
892  CCommandLoadHashes(CReaderRequestResult& result,
893  const TKey& key, TLoaded& loaded,
894  TRet& ret, TKnown& known)
895  : CReadDispatcherCommand(result),
896  m_Key(key), m_Loaded(loaded), m_Ret(ret), m_Known(known)
897  {
898  }
899 
900  bool Execute(CReader& reader)
901  {
902  return reader.LoadHashes(GetResult(), m_Key, m_Loaded,
903  m_Ret, m_Known);
904  }
905  bool MayBeSkipped(void) const
906  {
907  return true;
908  }
909  bool IsDone(void)
910  {
911  return sx_BulkIsDone<CLoadLock>(GetResult(), m_Key, m_Loaded);
912  }
913  string GetErrMsg(void) const
914  {
915  return "LoadHashes("+
916  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
917  "): data not found";
918  }
919  string GetStatisticsDescription(void) const
920  {
921  return "hashes("+
922  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
923  ")";
924  }
926  {
928  }
929 
930  private:
931  const TKey& m_Key;
932  TLoaded& m_Loaded;
933  TRet& m_Ret;
934  TKnown& m_Known;
935  };
936 
937  class CCommandLoadLengths : public CReadDispatcherCommand
938  {
939  public:
940  typedef vector<CSeq_id_Handle> TKey;
941  typedef vector<bool> TLoaded;
942  typedef vector<TSeqPos> TRet;
943  typedef CLoadLockLength CLoadLock;
944  CCommandLoadLengths(CReaderRequestResult& result,
945  const TKey& key, TLoaded& loaded, TRet& ret)
946  : CReadDispatcherCommand(result),
947  m_Key(key), m_Loaded(loaded), m_Ret(ret)
948  {
949  }
950 
951  bool Execute(CReader& reader)
952  {
953  return reader.LoadLengths(GetResult(), m_Key, m_Loaded, m_Ret);
954  }
955  bool MayBeSkipped(void) const
956  {
957  return true;
958  }
959  bool IsDone(void)
960  {
961  return sx_BulkIsDone<CLoadLock>(GetResult(), m_Key, m_Loaded);
962  }
963  string GetErrMsg(void) const
964  {
965  return "LoadLengths("+
966  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
967  "): data not found";
968  }
969  string GetStatisticsDescription(void) const
970  {
971  return "lengths("+
972  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
973  ")";
974  }
976  {
978  }
979 
980  private:
981  const TKey& m_Key;
982  TLoaded& m_Loaded;
983  TRet& m_Ret;
984  };
985 
986  class CCommandLoadTypes : public CReadDispatcherCommand
987  {
988  public:
989  typedef vector<CSeq_id_Handle> TKey;
990  typedef vector<bool> TLoaded;
991  typedef vector<CSeq_inst::EMol> TRet;
992  typedef CLoadLockType CLoadLock;
993  CCommandLoadTypes(CReaderRequestResult& result,
994  const TKey& key, TLoaded& loaded, TRet& ret)
995  : CReadDispatcherCommand(result),
996  m_Key(key), m_Loaded(loaded), m_Ret(ret)
997  {
998  }
999 
1000  bool Execute(CReader& reader)
1001  {
1002  return reader.LoadTypes(GetResult(), m_Key, m_Loaded, m_Ret);
1003  }
1004  bool MayBeSkipped(void) const
1005  {
1006  return true;
1007  }
1008  bool IsDone(void)
1009  {
1010  return sx_BulkIsDone<CLoadLock>(GetResult(), m_Key, m_Loaded);
1011  }
1012  string GetErrMsg(void) const
1013  {
1014  return "LoadTypes("+
1015  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
1016  "): data not found";
1017  }
1018  string GetStatisticsDescription(void) const
1019  {
1020  return "types("+
1021  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
1022  ")";
1023  }
1025  {
1027  }
1028 
1029  private:
1030  const TKey& m_Key;
1031  TLoaded& m_Loaded;
1032  TRet& m_Ret;
1033  };
1034 
1035  class CCommandLoadStates : public CReadDispatcherCommand
1036  {
1037  public:
1038  typedef vector<CSeq_id_Handle> TKey;
1039  typedef vector<bool> TLoaded;
1040  typedef vector<int> TRet;
1041  typedef CLoadLockBlobIds CLoadLock;
1042  CCommandLoadStates(CReaderRequestResult& result,
1043  const TKey& key, TLoaded& loaded, TRet& ret)
1044  : CReadDispatcherCommand(result),
1045  m_Key(key), m_Loaded(loaded), m_Ret(ret)
1046  {
1047  }
1048 
1049  bool Execute(CReader& reader)
1050  {
1051  return reader.LoadStates(GetResult(), m_Key, m_Loaded, m_Ret);
1052  }
1053  bool IsDone(void)
1054  {
1055  return sx_BulkIsDone<CLoadLock>(GetResult(), m_Key, m_Loaded);
1056  }
1057  string GetErrMsg(void) const
1058  {
1059  return "LoadStates("+
1060  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
1061  "): data not found";
1062  }
1063  string GetStatisticsDescription(void) const
1064  {
1065  return "states("+
1066  sx_DescribeError<CLoadLock>(GetResult(), m_Key, m_Loaded)+
1067  ")";
1068  }
1070  {
1072  }
1073 
1074  private:
1075  const TKey& m_Key;
1076  TLoaded& m_Loaded;
1077  TRet& m_Ret;
1078  };
1079 
1080  class CCommandLoadBlobState : public CReadDispatcherCommand
1081  {
1082  public:
1083  typedef CBlob_id TKey;
1084  typedef CLoadLockBlobState TLock;
1085  CCommandLoadBlobState(CReaderRequestResult& result,
1086  const TKey& key)
1087  : CReadDispatcherCommand(result),
1088  m_Key(key), m_Lock(result, key)
1089  {
1090  }
1091 
1092  bool IsDone(void)
1093  {
1094  return m_Lock.IsLoadedBlobState();
1095  }
1096  bool Execute(CReader& reader)
1097  {
1098  return reader.LoadBlobState(GetResult(), m_Key);
1099  }
1100  string GetErrMsg(void) const
1101  {
1102  return "LoadBlobVersion("+m_Key.ToString()+"): "
1103  "data not found";
1104  }
1106  {
1108  }
1109  string GetStatisticsDescription(void) const
1110  {
1111  return "blob-version("+m_Key.ToString()+")";
1112  }
1113 
1114  private:
1115  TKey m_Key;
1116  TLock m_Lock;
1117  };
1118 
1119  class CCommandLoadBlobVersion : public CReadDispatcherCommand
1120  {
1121  public:
1122  typedef CBlob_id TKey;
1123  typedef CLoadLockBlobVersion TLock;
1124  CCommandLoadBlobVersion(CReaderRequestResult& result,
1125  const TKey& key)
1126  : CReadDispatcherCommand(result),
1127  m_Key(key), m_Lock(result, key)
1128  {
1129  }
1130 
1131  bool IsDone(void)
1132  {
1133  return m_Lock.IsLoadedBlobVersion();
1134  }
1135  bool Execute(CReader& reader)
1136  {
1137  return reader.LoadBlobVersion(GetResult(), m_Key);
1138  }
1139  string GetErrMsg(void) const
1140  {
1141  return "LoadBlobVersion("+m_Key.ToString()+"): "
1142  "data not found";
1143  }
1145  {
1147  }
1148  string GetStatisticsDescription(void) const
1149  {
1150  return "blob-version("+m_Key.ToString()+")";
1151  }
1152 
1153  private:
1154  TKey m_Key;
1155  TLock m_Lock;
1156  };
1157 
1158  bool s_AllBlobsAreLoaded(CReaderRequestResult& result,
1159  const CLoadLockBlobIds& blobs,
1161  const SAnnotSelector* sel)
1162  {
1163  _ASSERT(blobs.IsLoaded());
1164 
1165  CFixedBlob_ids blob_ids = blobs.GetBlob_ids();
1166  ITERATE ( CFixedBlob_ids, it, blob_ids ) {
1167  const CBlob_Info& info = *it;
1168  if ( !info.Matches(mask, sel) ) {
1169  continue;
1170  }
1171  CLoadLockBlob blob(result, *info.GetBlob_id());
1172  if ( !blob.IsLoadedBlob() ) {
1173  return false;
1174  }
1175  }
1176  return true;
1177  }
1178 
1179  class CCommandLoadBlobs : public CReadDispatcherCommand
1180  {
1181  public:
1182  typedef CLoadLockBlobIds TIds;
1183  typedef CReadDispatcher::TContentsMask TMask;
1184  CCommandLoadBlobs(CReaderRequestResult& result,
1185  TIds ids, TMask mask, const SAnnotSelector* sel)
1186  : CReadDispatcherCommand(result),
1187  m_Ids(ids), m_Mask(mask), m_Selector(sel)
1188  {
1189  }
1190 
1191  bool IsDone(void)
1192  {
1193  return s_AllBlobsAreLoaded(GetResult(),
1194  m_Ids, m_Mask, m_Selector);
1195  }
1196  bool Execute(CReader& reader)
1197  {
1198  return reader.LoadBlobs(GetResult(),
1199  m_Ids, m_Mask, m_Selector);
1200  }
1201  string GetErrMsg(void) const
1202  {
1203  return "LoadBlobs(CLoadInfoBlob_ids): "
1204  "data not found";
1205  }
1207  {
1209  }
1210  string GetStatisticsDescription(void) const
1211  {
1212  return "blobs(...)";
1213  }
1214 
1215  private:
1216  TIds m_Ids;
1217  TMask m_Mask;
1218  const SAnnotSelector* m_Selector;
1219  };
1220  class CCommandLoadSeq_idBlobs : public CReadDispatcherCommand
1221  {
1222  public:
1223  typedef CSeq_id_Handle TKey;
1224  typedef CLoadLockBlobIds TIds;
1225  typedef CReadDispatcher::TContentsMask TMask;
1226  CCommandLoadSeq_idBlobs(CReaderRequestResult& result,
1227  const TKey& key, TMask mask,
1228  const SAnnotSelector* sel)
1229  : CReadDispatcherCommand(result),
1230  m_Key(key), m_Ids(result, key, sel),
1231  m_Mask(mask), m_Selector(sel)
1232  {
1233  }
1234 
1235  bool IsDone(void)
1236  {
1237  return s_Blob_idsLoaded(m_Ids, GetResult(), m_Key) &&
1238  s_AllBlobsAreLoaded(GetResult(),
1239  m_Ids, m_Mask, m_Selector);
1240  }
1241  bool Execute(CReader& reader)
1242  {
1243  return reader.LoadBlobs(GetResult(),
1244  m_Key, m_Mask, m_Selector);
1245  }
1246  string GetErrMsg(void) const
1247  {
1248  return "LoadBlobs("+m_Key.AsString()+"): "
1249  "data not found";
1250  }
1252  {
1254  }
1255  string GetStatisticsDescription(void) const
1256  {
1257  return "blobs("+m_Key.AsString()+")";
1258  }
1259 
1260  private:
1261  TKey m_Key;
1262  TIds m_Ids;
1263  TMask m_Mask;
1264  const SAnnotSelector* m_Selector;
1265  };
1266 
1267  class CCommandLoadBlob : public CReadDispatcherCommand
1268  {
1269  public:
1270  typedef CBlob_id TKey;
1271  typedef CLoadLockBlob TLock;
1272  CCommandLoadBlob(CReaderRequestResult& result,
1273  const TKey& key,
1274  const CBlob_Info* blob_info = 0)
1275  : CReadDispatcherCommand(result),
1276  m_Key(key),
1277  m_Lock(result, key),
1278  m_BlobInfo(blob_info)
1279  {
1280  }
1281 
1282  bool IsDone(void)
1283  {
1284  return m_Lock.IsLoadedBlob();
1285  }
1286  bool Execute(CReader& reader)
1287  {
1288  if ( m_BlobInfo ) {
1289  return reader.LoadBlob(GetResult(), *m_BlobInfo);
1290  }
1291  else {
1292  return reader.LoadBlob(GetResult(), m_Key);
1293  }
1294  }
1295  string GetErrMsg(void) const
1296  {
1297  return "LoadBlob("+m_Key.ToString()+"): "
1298  "data not found";
1299  }
1301  {
1303  }
1304  string GetStatisticsDescription(void) const
1305  {
1306  return "blob("+m_Key.ToString()+")";
1307  }
1308 
1309  private:
1310  TKey m_Key;
1311  TLock m_Lock;
1312  const CBlob_Info* m_BlobInfo;
1313  };
1314 
1315  class CCommandLoadChunk : public CReadDispatcherCommand
1316  {
1317  public:
1318  typedef CBlob_id TKey;
1319  typedef CLoadLockBlob TLock;
1320  typedef int TChunkId;
1321  typedef CTSE_Chunk_Info TChunkInfo;
1322  CCommandLoadChunk(CReaderRequestResult& result,
1323  const TKey& key,
1324  TChunkId chunk_id)
1325  : CReadDispatcherCommand(result),
1326  m_Key(key), m_Lock(result, key, chunk_id),
1327  m_ChunkId(chunk_id)
1328  {
1329  }
1330 
1331  bool IsDone(void)
1332  {
1333  return m_Lock.IsLoadedChunk();
1334  }
1335  bool Execute(CReader& reader)
1336  {
1337  return reader.LoadChunk(GetResult(), m_Key, m_ChunkId);
1338  }
1339  string GetErrMsg(void) const
1340  {
1341  return "LoadChunk("+m_Key.ToString()+", "+
1342  NStr::IntToString(m_ChunkId)+"): "
1343  "data not found";
1344  }
1346  {
1348  }
1349  string GetStatisticsDescription(void) const
1350  {
1351  return "chunk("+m_Key.ToString()+"."+
1352  NStr::IntToString(m_ChunkId)+")";
1353  }
1354 
1355  private:
1356  TKey m_Key;
1357  TLock m_Lock;
1358  TChunkId m_ChunkId;
1359  };
1360 
1361  class CCommandLoadChunks : public CReadDispatcherCommand
1362  {
1363  public:
1364  typedef CBlob_id TKey;
1365  typedef CLoadLockBlob TLock;
1366  typedef int TChunkId;
1367  typedef vector<TChunkId> TChunkIds;
1368  typedef CTSE_Chunk_Info TChunkInfo;
1369  CCommandLoadChunks(CReaderRequestResult& result,
1370  const TKey& key,
1371  const TChunkIds chunk_ids)
1372  : CReadDispatcherCommand(result),
1373  m_Key(key), m_Lock(result, key),
1374  m_ChunkIds(chunk_ids)
1375  {
1376  }
1377 
1378  bool IsDone(void)
1379  {
1380  ITERATE ( TChunkIds, it, m_ChunkIds ) {
1381  if ( !m_Lock.IsLoadedChunk(*it) ) {
1382  return false;
1383  }
1384  }
1385  return true;
1386  }
1387  bool Execute(CReader& reader)
1388  {
1389  return reader.LoadChunks(GetResult(), m_Key, m_ChunkIds);
1390  }
1391  string GetErrMsg(void) const
1392  {
1394  str << "LoadChunks(" << m_Key.ToString() << ", {";
1395  int cnt = 0;
1396  ITERATE ( TChunkIds, it, m_ChunkIds ) {
1397  if ( !m_Lock.IsLoadedChunk(*it) ) {
1398  if ( cnt++ ) str << ',';
1399  str << ' ' << *it;
1400  }
1401  }
1402  str << " }): data not found";
1403  return CNcbiOstrstreamToString(str);
1404  }
1406  {
1408  }
1409  string GetStatisticsDescription(void) const
1410  {
1412  int cnt = 0;
1413  ITERATE ( TChunkIds, it, m_ChunkIds ) {
1414  int id = *it;
1415  if ( id >= 0 && id < kMax_Int ) {
1416  if ( !cnt ) {
1417  str << "chunk(" << m_Key.ToString() << '.';
1418  cnt = 1;
1419  }
1420  else {
1421  str << ',';
1422  }
1423  str << id;
1424  }
1425  }
1426  if ( !cnt ) {
1427  str << "blob(" << m_Key.ToString();
1428  }
1429  str << ')';
1430  return CNcbiOstrstreamToString(str);
1431  }
1432 
1433  private:
1434  TKey m_Key;
1435  TLock m_Lock;
1436  TChunkIds m_ChunkIds;
1437  };
1438 
1439  class CCommandLoadBlobSet : public CReadDispatcherCommand
1440  {
1441  public:
1442  typedef CReadDispatcher::TIds TIds;
1443  CCommandLoadBlobSet(CReaderRequestResult& result,
1444  const TIds& seq_ids)
1445  : CReadDispatcherCommand(result),
1446  m_Ids(seq_ids)
1447  {
1448  }
1449 
1450  bool IsDone(void)
1451  {
1452  CReaderRequestResult& result = GetResult();
1453  ITERATE(TIds, id, m_Ids) {
1454  CLoadLockBlobIds blob_ids(result, *id, 0);
1455  if ( !blob_ids ) {
1456  return false;
1457  }
1458  if ( !s_Blob_idsLoaded(blob_ids, result, *id) ) {
1459  return false;
1460  }
1461  CFixedBlob_ids ids = blob_ids.GetBlob_ids();
1462  ITERATE ( CFixedBlob_ids, it, ids ) {
1463  if ( !it->Matches(fBlobHasCore, 0) ) {
1464  continue;
1465  }
1466  CLoadLockBlob blob(result, *it->GetBlob_id());
1467  if ( !blob.IsLoadedBlob() ) {
1468  return false;
1469  }
1470  }
1471  }
1472  return true;
1473  }
1474  bool Execute(CReader& reader)
1475  {
1476  return reader.LoadBlobSet(GetResult(), m_Ids);
1477  }
1478  string GetErrMsg(void) const
1479  {
1480  return "LoadBlobSet(" +
1481  NStr::SizetToString(m_Ids.size()) + " ids): "
1482  "data not found";
1483  }
1485  {
1487  }
1488  string GetStatisticsDescription(void) const
1489  {
1490  return "blobs(" +
1491  NStr::SizetToString(m_Ids.size()) + " ids)";
1492  }
1493 
1494  private:
1495  TIds m_Ids;
1496  };
1497 }
1498 
1500 
1502 {
1504  : m_Command(command),
1505  m_SavedLevel(command.GetResult().GetLevel())
1506  {
1507  }
1508 
1510  {
1512  }
1513 
1516 };
1517 
1519 
1520 
1522  const CReader* asking_reader)
1523 {
1524  CheckReaders();
1525 
1526  if ( command.IsDone() ) {
1527  return;
1528  }
1529 
1530  SSaveResultLevel save_level(command);
1532  if ( asking_reader ) {
1533  // skip all readers before the asking one
1534  if ( rdr->second == asking_reader ) {
1535  // found the asking reader, start processing next readers
1536  asking_reader = 0;
1537  }
1538  continue;
1539  }
1540  CReader& reader = *rdr->second;
1541  command.GetResult().SetLevel(rdr->first);
1542  int retry_count = 0;
1543  int max_retry_count = reader.GetRetryCount();
1544  do {
1545  ++retry_count;
1546  try {
1548  if ( !command.Execute(reader) ) {
1549  retry_count = kMax_Int;
1550  }
1551  LogStat(command, r);
1552  }
1553  catch ( CLoaderException& exc ) {
1554  if ( exc.GetErrCode() == exc.eRepeatAgain ) {
1555  // no actual error, just restart
1556  --retry_count;
1557  LOG_POST_X(10, Info<<
1558  "CReadDispatcher: connection reopened "
1559  "due to inactivity timeout");
1560  }
1561  else if ( exc.GetErrCode() == exc.eNoConnection ) {
1562  LOG_POST_X(1, Warning<<
1563  "CReadDispatcher: Exception: "<<exc);
1564  retry_count = kMax_Int;
1565  }
1566  else {
1567  if ( retry_count >= max_retry_count &&
1568  !command.MayBeSkipped() &&
1569  !reader.MayBeSkippedOnErrors() ) {
1570  throw;
1571  }
1572  LOG_POST_X(2, Warning<<
1573  "CReadDispatcher: Exception: "<<exc);
1574  }
1575  }
1576  catch ( CException& exc ) {
1577  // error in the command
1578  if ( retry_count >= max_retry_count &&
1579  !command.MayBeSkipped() &&
1580  !reader.MayBeSkippedOnErrors() ) {
1581  throw;
1582  }
1583  LOG_POST_X(3, Warning <<
1584  "CReadDispatcher: Exception: "<<exc);
1585  }
1586  catch ( exception& exc ) {
1587  // error in the command
1588  if ( retry_count >= max_retry_count &&
1589  !command.MayBeSkipped() &&
1590  !reader.MayBeSkippedOnErrors() ) {
1591  throw;
1592  }
1593  LOG_POST_X(4, Warning <<
1594  "CReadDispatcher: Exception: "<<exc.what());
1595  }
1596  if ( command.IsDone() ) {
1597  return;
1598  }
1599  } while ( retry_count < max_retry_count );
1600  if ( !command.MayBeSkipped() &&
1601  !reader.MayBeSkippedOnErrors() &&
1603  NCBI_THROW(CLoaderException, eLoaderFailed, command.GetErrMsg());
1604  }
1605  }
1606 
1607  if ( !command.MayBeSkipped() &&
1609  NCBI_THROW(CLoaderException, eLoaderFailed, command.GetErrMsg());
1610  }
1611 }
1612 
1613 
1615  const CSeq_id_Handle& seq_id)
1616 {
1617  CCommandLoadSeq_idSeq_ids command(result, seq_id);
1618  Process(command);
1619 }
1620 
1621 
1623  const CSeq_id_Handle& seq_id)
1624 {
1625  CCommandLoadSeq_idGi command(result, seq_id);
1626  Process(command);
1627 }
1628 
1629 
1631  const CSeq_id_Handle& seq_id)
1632 {
1633  CCommandLoadSeq_idAccVer command(result, seq_id);
1634  Process(command);
1635 }
1636 
1637 
1639  const CSeq_id_Handle& seq_id)
1640 {
1641  CCommandLoadSeq_idLabel command(result, seq_id);
1642  Process(command);
1643 }
1644 
1645 
1647  const CSeq_id_Handle& seq_id)
1648 {
1649  CCommandLoadSeq_idTaxId command(result, seq_id);
1650  Process(command);
1651 }
1652 
1653 
1655  const CSeq_id_Handle& seq_id)
1656 {
1657  CCommandLoadSequenceHash command(result, seq_id);
1658  Process(command);
1659 }
1660 
1661 
1663  const CSeq_id_Handle& seq_id)
1664 {
1665  CCommandLoadSequenceLength command(result, seq_id);
1666  Process(command);
1667 }
1668 
1669 
1671  const CSeq_id_Handle& seq_id)
1672 {
1673  CCommandLoadSequenceType command(result, seq_id);
1674  Process(command);
1675 }
1676 
1677 
1679  const TIds& ids, TLoaded& loaded, TIds& ret)
1680 {
1681  CCommandLoadAccVers command(result, ids, loaded, ret);
1682  Process(command);
1683 }
1684 
1685 
1687  const TIds& ids, TLoaded& loaded, TGis& ret)
1688 {
1689  CCommandLoadGis command(result, ids, loaded, ret);
1690  Process(command);
1691 }
1692 
1693 
1695  const TIds& ids, TLoaded& loaded, TLabels& ret)
1696 {
1697  CCommandLoadLabels command(result, ids, loaded, ret);
1698  Process(command);
1699 }
1700 
1701 
1703  const TIds& ids, TLoaded& loaded, TTaxIds& ret)
1704 {
1705  CCommandLoadTaxIds command(result, ids, loaded, ret);
1706  Process(command);
1707 }
1708 
1709 
1711  const TIds& ids, TLoaded& loaded,
1712  THashes& ret, TKnown& known)
1713 {
1714  CCommandLoadHashes command(result, ids, loaded, ret, known);
1715  Process(command);
1716 }
1717 
1718 
1720  const TIds& ids, TLoaded& loaded, TLengths& ret)
1721 {
1722  CCommandLoadLengths command(result, ids, loaded, ret);
1723  Process(command);
1724 }
1725 
1726 
1728  const TIds& ids, TLoaded& loaded, TTypes& ret)
1729 {
1730  CCommandLoadTypes command(result, ids, loaded, ret);
1731  Process(command);
1732 }
1733 
1734 
1736  const TIds& ids, TLoaded& loaded, TStates& ret)
1737 {
1738  CCommandLoadStates command(result, ids, loaded, ret);
1739  Process(command);
1740 }
1741 
1742 
1744  const CSeq_id_Handle& seq_id,
1745  const SAnnotSelector* sel)
1746 {
1747  CCommandLoadSeq_idBlob_ids command(result, seq_id, sel);
1748  Process(command);
1749 }
1750 
1751 
1753  const TBlobId& blob_id)
1754 {
1755  CCommandLoadBlobState command(result, blob_id);
1756  Process(command);
1757 }
1758 
1760  const TBlobId& blob_id,
1761  const CReader* asking_reader)
1762 {
1763  CCommandLoadBlobVersion command(result, blob_id);
1764  Process(command, asking_reader);
1765 }
1766 
1768  const CSeq_id_Handle& seq_id,
1769  TContentsMask mask,
1770  const SAnnotSelector* sel)
1771 {
1772  CCommandLoadSeq_idBlobs command(result, seq_id, mask, sel);
1773  Process(command);
1774 }
1775 
1776 
1778  const CLoadLockBlobIds& blobs,
1779  TContentsMask mask,
1780  const SAnnotSelector* sel)
1781 {
1782  CCommandLoadBlobs command(result, blobs, mask, sel);
1783  Process(command);
1784 }
1785 
1786 
1788  const CBlob_id& blob_id)
1789 {
1790  CCommandLoadBlob command(result, blob_id);
1791  Process(command);
1792 }
1793 
1794 
1796  const CBlob_Info& blob_info)
1797 {
1798  CCommandLoadBlob command(result, *blob_info.GetBlob_id(), &blob_info);
1799  Process(command);
1800 }
1801 
1802 
1804  const TBlobId& blob_id, TChunkId chunk_id)
1805 {
1806  CCommandLoadChunk command(result, blob_id, chunk_id);
1807  Process(command);
1808 }
1809 
1810 
1812  const TBlobId& blob_id,
1813  const TChunkIds& chunk_ids)
1814 {
1815  CCommandLoadChunks command(result, blob_id, chunk_ids);
1816  Process(command);
1817 }
1818 
1819 
1821  const TIds& seq_ids)
1822 {
1823  CCommandLoadBlobSet command(result, seq_ids);
1824  Process(command);
1825 }
1826 
1827 
1829  CReaderRequestResult& result,
1830  const TIds& ids, TLoaded& loaded,
1831  TStates& ret)
1832 {
1833  if ( loaded[i] || CannotProcess(ids[i]) ) {
1834  return true;
1835  }
1836  CLoadLockBlobIds lock(result, ids[i]);
1837  if ( lock.IsLoaded() ) {
1838  CFixedBlob_ids blob_ids = lock.GetBlob_ids();
1839  if ( !blob_ids.IsFound() ) {
1840  ret[i] = lock.GetState();
1841  return true;
1842  }
1843  ITERATE ( CFixedBlob_ids, it, blob_ids ) {
1844  if ( it->Matches(fBlobHasCore, 0) ) {
1846  if ( state == CFixedBlob_ids::kUnknownState ) {
1847  CLoadLockBlobState state_lock(result, *it->GetBlob_id());
1848  if ( state_lock.IsLoadedBlobState() ) {
1849  state = state_lock.GetBlobState();
1850  }
1851  }
1852  if ( state != CFixedBlob_ids::kUnknownState ) {
1853  ret[i] = state;
1854  loaded[i] = true;
1855  return true;
1856  }
1857  return false;
1858  }
1859  }
1860  }
1861  else {
1862  CLoadLockSeqIds ids_lock(result, ids[i], eAlreadyLoaded);
1863  if ( ids_lock && !ids_lock.GetData().IsFound() ) {
1864  ret[i] = ids_lock.GetState();
1865  return true;
1866  }
1867  }
1868  return false;
1869 }
1870 
1871 
1873  CReaderRequestResultRecursion& recursion)
1874 {
1875  CReaderRequestResult& result = command.GetResult();
1876  double time = recursion.GetCurrentRequestTime();
1877  CGBRequestStatistics& stat = sx_Statistics[command.GetStatistics()];
1878  stat.AddTime(time);
1879  if ( CollectStatistics() >= 2 ) {
1880  string descr = command.GetStatisticsDescription();
1881  const CSeq_id_Handle& idh = result.GetRequestedId();
1882  if ( idh ) {
1883  descr = descr + " for " + idh.AsString();
1884  }
1885  LOG_POST_X(8, setw(recursion.GetRecursionLevel()) << "" <<
1886  "Dispatcher: read " <<
1887  descr << " in " <<
1888  setiosflags(ios::fixed) <<
1889  setprecision(3) << (time*1000) << " ms");
1890  }
1891 }
1892 
1893 
1895  CReaderRequestResultRecursion& recursion,
1896  double size)
1897 {
1898  CReaderRequestResult& result = command.GetResult();
1899  double time = recursion.GetCurrentRequestTime();
1900  CGBRequestStatistics& stat = sx_Statistics[command.GetStatistics()];
1901  stat.AddTimeSize(time, size);
1902  if ( CollectStatistics() >= 2 ) {
1903  string descr = command.GetStatisticsDescription();
1904  const CSeq_id_Handle& idh = result.GetRequestedId();
1905  if ( idh ) {
1906  descr = descr + " for " + idh.AsString();
1907  }
1908  LOG_POST_X(9, setw(recursion.GetRecursionLevel()) << "" <<
1909  descr << " in " <<
1910  setiosflags(ios::fixed) <<
1911  setprecision(3) <<
1912  (time*1000) << " ms (" <<
1913  setprecision(2) <<
1914  (size/1024.0) << " kB " <<
1915  setprecision(2) <<
1916  (size/time/1024) << " kB/s)");
1917  }
1918 }
1919 
1920 
void LoadTypes(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TTypes &ret)
#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:561
void LoadSeq_idTaxId(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
virtual string GetStatisticsDescription(void) const =0
virtual bool LoadStates(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TStates &ret)
Definition: reader.cpp:812
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:900
TReaders m_Readers
Definition: dispatcher.hpp:181
TWriters m_Writers
Definition: dispatcher.hpp:182
virtual bool LoadSeq_idAccVer(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:499
static void PrintStatistics(void)
Definition: dispatcher.cpp:138
CReadDispatcherCommand(CReaderRequestResult &result)
Definition: dispatcher.cpp:245
Definition: dbpivot.c:60
TProcessors m_Processors
Definition: dispatcher.hpp:183
CSafeStatic<>::
string AsString(void) const
CReader::TContentsMask TContentsMask
Definition: dispatcher.hpp:61
bool SetNoBlob_ids(const CFixedBlob_ids::TState &state, TExpirationTime expiration_time)
static string SizetToString(size_t value, TNumToStringFlags flags=0, int base=10)
Convert size_t to string.
Definition: ncbistr.cpp:2648
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:73
virtual EType GetType(void) const =0
virtual bool Execute(CReader &reader)=0
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:850
void LoadAccVers(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TIds &ret)
Data loader exceptions, used by GenBank loader.
bool IsFound(void) const
TData GetBlobState(void) const
SSaveResultLevel(CReadDispatcherCommand &command)
TData::TState GetState(void) const
vector< CSeq_id_Handle > TIds
Definition: dispatcher.hpp:68
virtual bool LoadSequenceType(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:618
virtual CGBRequestStatistics::EStatType GetStatistics(void) const =0
void LoadHashes(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, THashes &ret, TKnown &known)
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1008
CWriter * GetWriter(const CReaderRequestResult &result, CWriter::EType type) const
Definition: dispatcher.cpp:199
size_t GetCount(void) const
Definition: statistics.hpp:78
virtual int GetRetryCount(void) const
Definition: reader.cpp:468
TData::TState GetState(void) const
virtual bool LoadAccVers(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TIds &ret)
Definition: reader.cpp:651
TData GetBlob_ids(void) const
void InsertReader(TLevel level, CRef< CReader > reader)
Definition: dispatcher.cpp:168
void CheckReaders(void) const
Definition: dispatcher.cpp:226
bool Matches(TContentsMask mask, const SAnnotSelector *sel) const
void SetLevel(TLevel level)
void LoadSeq_idAccVer(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
void PrintStat(void) const
Definition: dispatcher.cpp:109
static const CGBRequestStatistics & GetStatistics(EStatType type)
Definition: dispatcher.cpp:99
double GetCurrentRequestTime(void) const
void LoadChunks(CReaderRequestResult &result, const TBlobId &blob_id, const TChunkIds &chunk_ids)
virtual bool LoadTaxIds(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TTaxIds &ret)
Definition: reader.cpp:720
SAnnotSelector –.
virtual bool LoadBlob(CReaderRequestResult &result, const CBlob_id &blob_id)=0
virtual bool LoadBlobSet(CReaderRequestResult &result, const TSeqIds &seq_ids)
Definition: reader.cpp:960
static bool CannotProcess(const CSeq_id_Handle &sih)
Definition: dispatcher.hpp:82
virtual bool LoadChunks(CReaderRequestResult &result, const TBlobId &blob_id, const TChunkIds &chunk_ids)
Definition: reader.cpp:948
void LoadBlobs(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TContentsMask mask, const SAnnotSelector *sel)
CReadDispatcherCommand & m_Command
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:893
virtual bool LoadSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)=0
int i
void LoadSequenceLength(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
static bool SetBlobState(size_t i, CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TStates &ret)
virtual bool LoadLabels(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TLabels &ret)
Definition: reader.cpp:699
void LoadSeq_idBlob_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, const SAnnotSelector *sel)
void LoadSequenceHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
BEGIN_LOCAL_NAMESPACE
virtual bool LoadLengths(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TLengths &ret)
Definition: reader.cpp:767
static void RegisterAllProcessors(CReadDispatcher &dispatcher)
Definition: processors.cpp:297
static int type
Definition: getdata.c:34
void LoadLengths(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TLengths &ret)
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5107
virtual bool LoadBlobVersion(CReaderRequestResult &result, const TBlobId &blob_id)=0
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
virtual bool LoadTypes(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TTypes &ret)
Definition: reader.cpp:788
const char * GetAction(void) const
Definition: statistics.hpp:72
const_iterator end() const
Definition: map.hpp:152
virtual bool LoadSequenceHash(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:569
const CProcessor & GetProcessor(CProcessor::EType type) const
Definition: dispatcher.cpp:214
void Process(CReadDispatcherCommand &command, const CReader *asking_reader=0)
END_LOCAL_NAMESPACE
vector< CSeq_inst::EMol > TTypes
Definition: dispatcher.hpp:114
virtual bool LoadSeq_idTaxId(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:537
void ResetCaches(void)
Definition: dispatcher.cpp:234
const_iterator find(const key_type &key) const
Definition: map.hpp:153
double GetSize(void) const
Definition: statistics.hpp:84
CReadDispatcher * m_Dispatcher
Definition: reader.hpp:284
Definition: type.c:8
virtual bool MayBeSkippedOnErrors(void) const
Definition: reader.cpp:474
void InsertWriter(TLevel level, CRef< CWriter > writer)
Definition: dispatcher.cpp:179
#define LOG_POST_X(err_subcode, message)
Definition: ncbidiag.hpp:547
void LoadBlobSet(CReaderRequestResult &result, const TIds &seq_ids)
bool empty() const
Definition: map.hpp:149
void AddTime(double time)
Definition: statistics.hpp:93
int size
NCBI_PARAM_DECL(bool, GENBANK, ALLOW_INCOMPLETE_COMMANDS)
static bool s_AllowIncompleteCommands(void)
Definition: dispatcher.cpp:56
virtual bool LoadHashes(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, THashes &ret, TKnown &known)
Definition: reader.cpp:741
virtual bool LoadSequenceLength(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:586
virtual bool LoadSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:480
void LoadGis(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TGis &ret)
void LoadSeq_idLabel(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
virtual bool LoadGis(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TGis &ret)
Definition: reader.cpp:675
void LoadBlobVersion(CReaderRequestResult &result, const TBlobId &blob_id, const CReader *asking_reader=0)
void LoadSeq_idSeq_ids(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
void LoadStates(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TStates &ret)
vector< TSeqPos > TLengths
Definition: dispatcher.hpp:113
const char * command
Definition: util.cpp:112
void LoadSequenceType(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
~CReadDispatcher(void)
Definition: dispatcher.cpp:160
CException –.
Definition: ncbiexpt.hpp:709
virtual bool LoadChunk(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id)
Definition: reader.cpp:940
void AddTimeSize(double time, double size)
Definition: statistics.hpp:98
virtual string GetErrMsg(void) const =0
vector< TGi > TGis
Definition: dispatcher.hpp:109
static const char * str(char *buf, int n)
Definition: stats.c:84
void InsertProcessor(CRef< CProcessor > processor)
Definition: dispatcher.cpp:189
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1002
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:435
void LoadSeq_idGi(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Do not use per-thread values.
Definition: ncbi_param.hpp:475
CReaderRequestResult & GetResult(void) const
Definition: dispatcher.hpp:202
virtual bool MayBeSkipped(void) const
Definition: dispatcher.cpp:256
void LoadLabels(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TLabels &ret)
IO_PREFIX::ostrstream CNcbiOstrstream
Portable alias for ostrstream.
Definition: ncbistre.hpp:163
#define _ASSERT
static int CollectStatistics(void)
Definition: dispatcher.cpp:146
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:70
virtual bool IsDone(void)=0
virtual bool LoadBlobState(CReaderRequestResult &result, const TBlobId &blob_id)=0
#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:546
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
void LoadBlobState(CReaderRequestResult &result, const TBlobId &blob_id)
int TChunkId
Definition: blob_id.hpp:124
CReadDispatcher::TLevel m_SavedLevel
void LoadBlob(CReaderRequestResult &result, const CBlob_id &blob_id)
virtual bool LoadBlobs(CReaderRequestResult &result, const CSeq_id_Handle &seq_id, TContentsMask mask, const SAnnotSelector *sel)
Definition: reader.cpp:869
NCBI_DEFINE_ERR_SUBCODE_X(10)
virtual ~CReadDispatcherCommand(void)
Definition: dispatcher.cpp:251
void LoadTaxIds(CReaderRequestResult &result, const TIds &ids, TLoaded &loaded, TTaxIds &ret)
vector< int > TTaxIds
Definition: dispatcher.hpp:111
TLevel GetLevel() const
vector< int > THashes
Definition: dispatcher.hpp:112
#define kMax_Int
Definition: ncbi_limits.h:184
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
vector< string > TLabels
Definition: dispatcher.hpp:110
static void LogStat(CReadDispatcherCommand &command, CReaderRequestResultRecursion &recursion)
const CSeq_id_Handle & GetRequestedId(void) const
double GetTime(void) const
Definition: statistics.hpp:81
NCBI_PARAM_DEF_EX(bool, GENBANK, ALLOW_INCOMPLETE_COMMANDS, false, eParam_NoThread, GENBANK_ALLOW_INCOMPLETE_COMMANDS)
T & Get(void)
Create the variable if not created yet, return the reference.
virtual bool LoadSeq_idLabel(CReaderRequestResult &result, const CSeq_id_Handle &seq_id)
Definition: reader.cpp:518
const CConstRef< CBlob_id > & GetBlob_id(void) const
const char * GetEntity(void) const
Definition: statistics.hpp:75
vector< TBlobState > TStates
Definition: dispatcher.hpp:115
CGBRequestStatistics(const char *action, const char *entity)
Definition: dispatcher.cpp:92
static bool IsFound(const TData &data)
void LoadChunk(CReaderRequestResult &result, const TBlobId &blob_id, TChunkId chunk_id)
Modified on Mon Aug 29 19:41:02 2016 by modify_doxy.py rev. 506947