1 /* $Id: prelim_search_runner.hpp 514950 2016-09-27 14:52:47Z rackerst $ 2 * =========================================================================== 3 * 4 * PUBLIC DOMAIN NOTICE 5 * National Center for Biotechnology Information 6 * 7 * This software/database is a "United States Government Work" under the 8 * terms of the United States Copyright Act. It was written as part of 9 * the author's official duties as a United States Government employee and 10 * thus cannot be copyrighted. This software/database is freely available 11 * to the public for use. The National Library of Medicine and the U.S. 12 * Government have not placed any restriction on its use or reproduction. 13 * 14 * Although all reasonable efforts have been taken to ensure the accuracy 15 * and reliability of the software and data, the NLM and the U.S. 16 * Government do not and cannot warrant the performance or results that 17 * may be obtained by using this software or data. The NLM and the U.S. 18 * Government disclaim all warranties, express or implied, including 19 * warranties of performance, merchantability or fitness for any particular 20 * purpose. 21 * 22 * Please cite the author in any work or product based on this material. 23 * 24 * =========================================================================== 25 * 26 * Author: Christiam Camacho 27 * 28 */ 29 30 /** @file prelim_search_runner.hpp 31 * Defines internal auxiliary functor object to run the preliminary stage of 32 * the BLAST search. 33 */ 34 35 #ifndef ALGO_BLAST_API___PRELIM_SEARCH_RUNNER__HPP 36 #define ALGO_BLAST_API___PRELIM_SEARCH_RUNNER__HPP 37 38 /** @addtogroup AlgoBlast 39 * 40 * @{ 41 */ 42 43 #include <corelib/ncbithr.hpp> // for CThread 44 #include <algo/blast/api/setup_factory.hpp> 45 #include "blast_memento_priv.hpp" 46 47 // CORE BLAST includes 48 #include <algo/blast/core/blast_engine.h> 49 50 BEGIN_NCBI_SCOPE 51 BEGIN_SCOPE(blast) 52 53 /// Functor to run the preliminary stage of the BLAST search 54 class CPrelimSearchRunner : public CObject 55 { 56 public: CPrelimSearchRunner(SInternalData & internal_data,const CBlastOptionsMemento * opts_memento)57 CPrelimSearchRunner(SInternalData& internal_data, 58 const CBlastOptionsMemento* opts_memento) 59 : m_InternalData(internal_data), m_OptsMemento(opts_memento) 60 {} ~CPrelimSearchRunner()61 ~CPrelimSearchRunner() {} operator ()()62 int operator()() { 63 _ASSERT(m_OptsMemento); 64 _ASSERT(m_InternalData.m_Queries); 65 _ASSERT(m_InternalData.m_QueryInfo); 66 _ASSERT(m_InternalData.m_SeqSrc); 67 _ASSERT(m_InternalData.m_ScoreBlk); 68 _ASSERT(m_InternalData.m_LookupTable); 69 _ASSERT(m_InternalData.m_HspStream); 70 SBlastProgressReset(m_InternalData.m_ProgressMonitor->Get()); 71 Int2 retval = Blast_RunPreliminarySearchWithInterrupt(m_OptsMemento->m_ProgramType, 72 m_InternalData.m_Queries, 73 m_InternalData.m_QueryInfo, 74 m_InternalData.m_SeqSrc->GetPointer(), 75 m_OptsMemento->m_ScoringOpts, 76 m_InternalData.m_ScoreBlk->GetPointer(), 77 m_InternalData.m_LookupTable->GetPointer(), 78 m_OptsMemento->m_InitWordOpts, 79 m_OptsMemento->m_ExtnOpts, 80 m_OptsMemento->m_HitSaveOpts, 81 m_OptsMemento->m_EffLenOpts, 82 m_OptsMemento->m_PSIBlastOpts, 83 m_OptsMemento->m_DbOpts, 84 m_InternalData.m_HspStream->GetPointer(), 85 m_InternalData.m_Diagnostics->GetPointer(), 86 m_InternalData.m_FnInterrupt, 87 m_InternalData.m_ProgressMonitor->Get()); 88 89 return static_cast<int>(retval); 90 } 91 92 private: 93 /// Data structure containing all the needed C structures for the 94 /// preliminary stage of the BLAST search 95 SInternalData& m_InternalData; 96 97 /// Pointer to memento which this class doesn't own 98 const CBlastOptionsMemento* m_OptsMemento; 99 100 101 /// Prohibit copy constructor 102 CPrelimSearchRunner(const CPrelimSearchRunner& rhs); 103 /// Prohibit assignment operator 104 CPrelimSearchRunner& operator=(const CPrelimSearchRunner& rhs); 105 }; 106 107 /// Thread class to run the preliminary stage of the BLAST search 108 class CPrelimSearchThread : public CThread 109 { 110 public: CPrelimSearchThread(SInternalData & internal_data,const CBlastOptionsMemento * opts_memento)111 CPrelimSearchThread(SInternalData& internal_data, 112 const CBlastOptionsMemento* opts_memento) 113 : m_InternalData(internal_data), m_OptsMemento(opts_memento) 114 { 115 // The following fields need to be copied to ensure MT-safety 116 BlastSeqSrc* seqsrc = 117 BlastSeqSrcCopy(m_InternalData.m_SeqSrc->GetPointer()); 118 m_InternalData.m_SeqSrc.Reset(new TBlastSeqSrc(seqsrc, 119 BlastSeqSrcFree)); 120 // The progress field must be copied to ensure MT-safety 121 if (m_InternalData.m_ProgressMonitor->Get()) { 122 SBlastProgress* bp = 123 SBlastProgressNew(m_InternalData.m_ProgressMonitor->Get()->user_data); 124 m_InternalData.m_ProgressMonitor.Reset(new CSBlastProgress(bp)); 125 } 126 // The BlastQueryInfo field needs to be copied to silence Thread 127 // Sanitizer warnings, and probably to ensure MT-safety too. 128 BlastQueryInfo* queryInfo = 129 BlastQueryInfoDup(m_InternalData.m_QueryInfo); 130 m_InternalData.m_QueryInfo = queryInfo; 131 } 132 133 protected: ~CPrelimSearchThread(void)134 virtual ~CPrelimSearchThread(void) { 135 BlastQueryInfoFree(m_InternalData.m_QueryInfo); 136 } 137 Main(void)138 virtual void* Main(void) { 139 return (void*) 140 ((intptr_t) CPrelimSearchRunner(m_InternalData, m_OptsMemento)()); 141 } 142 143 private: 144 SInternalData m_InternalData; 145 const CBlastOptionsMemento* m_OptsMemento; 146 }; 147 148 END_SCOPE(blast) 149 END_NCBI_SCOPE 150 151 /* @} */ 152 153 #endif /* ALGO_BLAST_API___PRELIM_SEARCH_RUNNER__HPP */ 154