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

Go to the SVN repository for this file.

1 /* $Id: flat_file_sequence_list_job.cpp 39645 2017-10-23 19:42:27Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 
39 
42 
44  objects::CSeq_entry_Handle& h,
45  const objects::CSubmit_block* submitBlock,
46  const objects::CSeq_loc* seq_loc,
47  objects::CFlatFileConfig::EStyle style)
48  : m_Config(CFlatFileConfig::eFormat_Lite, CFlatFileConfig::eMode_GBench, style, 0, CFlatFileConfig::fViewAll)
49 {
51 
52  m_Context->SetEntry(h);
53  if (submitBlock) {
54  m_Context->SetSubmit(*submitBlock);
55  }
56  m_Context->SetLocation(seq_loc);
57 }
58 
60 {
61 
62 }
63 
65 {
66  string jobName = x_GetJobName();
67  string err_msg, logMsg = jobName + " - exception in Run() ";
68 
69  IAppJob::EJobState jobState = eCompleted;
70 
71  try {
72  CLockerGuard guard = x_GetGuard();
73  if (IsCanceled()) return eCanceled;
74  jobState = x_Run();
75  }
76  catch (CException& e) {
77  err_msg = e.GetMsg();
78  LOG_POST(Error << logMsg << GetDescr() << ". " << err_msg);
79  //e.ReportAll();
80  }
81  catch (std::exception& e) {
82  err_msg = GetDescr() + ". " + e.what();
83  LOG_POST(Error << logMsg << GetDescr() << ". " << err_msg);
84  }
85  catch (const CCancelException&) {
86  }
87 
88  if (IsCanceled())
89  return eCanceled;
90 
91  if (!err_msg.empty()) {
92  string s = err_msg;
93  m_Error.Reset(new CAppJobError(s));
94  return eFailed;
95  }
96 
97  return jobState;
98 }
99 
101 {
103 }
104 
106 {
108 }
109 
111 {
113 }
114 
116 {
117  if (m_Canceled.IsCanceled())
118  throw CCancelException();
119 
120  const CLocusItem* locusItem = dynamic_cast<const CLocusItem*>(item.GetPointerOrNull());
121  if (locusItem) {
122  CBioseqContext* ctx = locusItem->GetContext();
123  if (ctx) {
124  CBioseq_Handle& handle(ctx->GetHandle());
125  if (handle)
126  m_Seqs.push_back(CFlatFileSeq(locusItem->GetFullName(), handle));
127  }
128  }
129 }
130 
132 {
134  formatter->SetContext(*m_Context);
135 
137 
138  CRef<CFlatGatherer> gatherer(CFlatGatherer::New(m_Config.GetFormat()));
139  gatherer->Gather(*m_Context, *builder);
140 
142 
143  return eCompleted;
144 }
145 
CAppJobError Default implementation for IAppJobError - encapsulates a text error message.
CBioseq_Handle –.
CConstRef –.
Definition: ncbiobj.hpp:1266
virtual void AddItem(CConstRef< objects::IFlatItem > item)
virtual EJobState Run()
Function that does all the useful work, called by the Engine.
CFlatFileSequenceListJob(objects::CSeq_entry_Handle &h, const objects::CSubmit_block *submitBlock, const objects::CSeq_loc *seq_loc, objects::CFlatFileConfig::EStyle style)
CRef< objects::CFlatFileContext > m_Context
virtual string GetDescr() const
Returns a human readable description of the Job (optional)
virtual CConstIRef< IAppJobError > GetError()
Returns IAppJobError object describing internal error that caused the Job to fail.
virtual CConstIRef< IAppJobProgress > GetProgress()
return progress object, the function shall be synchronized internally.
virtual CRef< CObject > GetResult()
Returns the Job Result.
CRef< CTextViewSequenceListResult > m_Result
static CFlatGatherer * New(CFlatFileConfig::TFormat format)
static CFlatItemFormatter * New(CFlatFileConfig::TFormat format)
CBioseqContext * GetContext(void)
Definition: item_base.hpp:113
const string & GetFullName(void) const
Definition: locus_item.hpp:120
CS_CONTEXT * ctx
Definition: t0006.c:12
USING_SCOPE(objects)
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
ICanceled * x_GetICanceled()
virtual bool IsCanceled() const override
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
CLockerGuard x_GetGuard()
@ eCanceled
Definition: app_job.hpp:91
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType * GetPointerOrNull(void) const THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:1672
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsCanceled(void) const =0
Modified on Thu Feb 22 17:08:48 2024 by modify_doxy.py rev. 669887