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

Go to the SVN repository for this file.

1 /* $Id: kdbread.cpp 97456 2022-07-19 17:56:42Z vasilche $
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: Eugene Vasilchenko
27  *
28  * File Description:
29  * Access to SRA files
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
35 
37 #include <vdb/vdb-priv.h>
38 #include <klib/rc.h>
39 #include <klib/namelist.h>
40 #include <kdb/table.h>
41 #include <kdb/meta.h>
42 #include <kdb/namelist.h>
43 
46 
47 
48 class CSeq_entry;
49 
50 
51 DEFINE_SRA_REF_TRAITS(KTable, const);
52 DEFINE_SRA_REF_TRAITS(KMetadata, const);
53 DEFINE_SRA_REF_TRAITS(KMDataNode, const);
54 DEFINE_SRA_REF_TRAITS(KNamelist, );
55 
56 
58 {
59  if ( rc_t rc = VTableOpenKTableRead(table, x_InitPtr()) ) {
60  *x_InitPtr() = 0;
61  NCBI_THROW2(CSraException, eInitFailed,
62  "Cannot open KTable", rc);
63  }
64 }
65 
66 
68 {
69  x_Init(table);
70 }
71 
72 
73 CKMetadata::CKMetadata(const CVDB& db, const char* table_name)
74 {
76 }
77 
78 
80 {
81  if ( rc_t rc = KTableOpenMetadataRead(table, x_InitPtr()) ) {
82  *x_InitPtr() = 0;
83  NCBI_THROW2(CSraException, eInitFailed,
84  "Cannot open KMetadata", rc);
85  }
86 }
87 
88 
90  const char* node_name,
91  EMissing missing)
92 {
93  if ( rc_t rc = KMetadataOpenNodeRead(meta, x_InitPtr(), node_name) ) {
94  *x_InitPtr() = 0;
95  if ( GetRCObject(rc) == RCObject(rcPath) &&
96  GetRCState(rc) == rcNotFound ) {
97  if ( missing == eMissing_Throw ) {
99  "Cannot open KMDataNode", rc, node_name);
100  }
101  }
102  else {
103  NCBI_THROW3(CSraException, eInitFailed,
104  "Cannot open KMDataNode", rc, node_name);
105  }
106  }
107 }
108 
109 
111  const char* node_name,
112  EMissing missing)
113 {
114  if ( rc_t rc = KMDataNodeOpenNodeRead(parent, x_InitPtr(), node_name) ) {
115  *x_InitPtr() = 0;
116  if ( GetRCObject(rc) == RCObject(rcPath) &&
117  GetRCState(rc) == rcNotFound ) {
118  if ( missing == eMissing_Throw ) {
120  "Cannot open child KMDataNode", rc, node_name);
121  }
122  }
123  else {
124  NCBI_THROW3(CSraException, eInitFailed,
125  "Cannot open child KMDataNode", rc, node_name);
126  }
127  }
128 }
129 
130 
132 {
133  uint32_t value;
134  if ( rc_t rc = KMDataNodeReadAsU32(*this, &value) ) {
135  NCBI_THROW2(CSraException, eInitFailed,
136  "Cannot read metadata node value", rc);
137  }
138  return (Uint4)value;
139 }
140 
141 
143 {
144  uint64_t value;
145  if ( rc_t rc = KMDataNodeReadAsU64(*this, &value) ) {
146  NCBI_THROW2(CSraException, eInitFailed,
147  "Cannot read metadata node value", rc);
148  }
149  return (Uint8)value;
150 }
151 
152 
153 pair<size_t, size_t>
154 CKMDataNode::TryToGetData(char* buffer, size_t size, size_t offset) const
155 {
156  pair<size_t, size_t> ret;
157  if ( rc_t rc = KMDataNodeRead(*this, offset, buffer, size,
158  &ret.first, &ret.second) ) {
159  NCBI_THROW2(CSraException, eInitFailed,
160  "Cannot read metadata node data", rc);
161  }
162  return ret;
163 }
164 
165 
166 void CKMDataNode::GetData(char* buffer, size_t size, size_t offset) const
167 {
168  pair<size_t, size_t> ret = TryToGetData(buffer, size, offset);
169  if ( ret.first != size ) {
170  NCBI_THROW2(CSraException, eDataError,
171  "Cannot read all requested data from metadata node",
172  RC(rcApp, rcData, rcRetrieving, rcSize, rcTooBig));
173  }
174 }
175 
176 
178 {
179  if ( rc_t rc = KMDataNodeListChild(parent, x_InitPtr()) ) {
180  NCBI_THROW2(CSraException, eInitFailed,
181  "Cannot get metadata node child list", rc);
182  }
183  if ( rc_t rc = KNamelistCount(*this, &m_Size) ) {
184  NCBI_THROW2(CSraException, eInitFailed,
185  "Cannot get size of metadata node child list", rc);
186  }
187 }
188 
189 
190 const char* CKNameList::operator[](size_t index) const
191 {
192  if ( index >= size() ) {
193  NCBI_THROW3(CSraException, eInvalidIndex,
194  "Invalid index for a namelist",
195  RC(rcApp, rcData, rcRetrieving, rcOffset, rcTooBig),
196  index);
197  }
198  const char* ret = 0;
199  if ( rc_t rc = KNamelistGet(*this, uint32_t(index), &ret) ) {
200  NCBI_THROW3(CSraException, eInitFailed,
201  "Cannot get name from a namelist", rc, index);
202  }
203  return ret;
204 }
205 
206 
#define NCBI_THROW3(exc_cls, err_code, msg, extra1, extra2)
uint32_t rc_t
Uint4 GetUint4(void) const
Definition: kdbread.cpp:131
pair< size_t, size_t > TryToGetData(char *buffer, size_t size, size_t offset=0) const
Definition: kdbread.cpp:154
CKMDataNode(const CKMetadata &meta, const char *node_name, EMissing missing=eMissing_Throw)
Definition: kdbread.cpp:89
Uint8 GetUint8(void) const
Definition: kdbread.cpp:142
@ eMissing_Throw
Definition: kdbread.hpp:85
void GetData(char *buffer, size_t size, size_t offset=0) const
Definition: kdbread.cpp:166
void x_Init(const CKTable &table)
Definition: kdbread.cpp:79
CKMetadata(const CKTable &table)
Definition: kdbread.cpp:67
size_t size(void) const
Definition: kdbread.hpp:120
const char * operator[](size_t index) const
Definition: kdbread.cpp:190
uint32_t m_Size
Definition: kdbread.hpp:128
CKNameList(const CKMDataNode &parent)
Definition: kdbread.cpp:177
CKTable(const CVDBTable &table)
Definition: kdbread.cpp:57
Definition: Seq_entry.hpp:56
TObject ** x_InitPtr(void)
Definition: sdk.hpp:175
static const char table_name[]
Definition: bcp.c:249
int offset
Definition: replacements.h:160
Uint8 uint64_t
Uint4 uint32_t
#define NCBI_THROW2(exception_class, err_code, message, extra)
Throw exception with extra parameter.
Definition: ncbiexpt.hpp:1754
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#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
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
DEFINE_SRA_REF_TRAITS(KTable, const)
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
static pcre_uint8 * buffer
Definition: pcretest.c:1051
@ eNotFound
Not found.
#define uint32_t
Definition: config.h:42
Modified on Tue Jul 23 17:57:26 2024 by modify_doxy.py rev. 669887