UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
seismic_qsql.hpp
1 /* seis.hpp */
2 /* $Id$ */
3 #ifndef __hds_db_seismic_qsql_hpp
4 #define __hds_db_seismic_qsql_hpp
5 
6 #include <QSqlDatabase>
7 #include <QSqlQuery>
8 
9 #include <map>
10 #include <hds_db/base/seismic.hpp>
11 #include <hds_db/qsql/qsql_impl.hpp>
12 #include <hds_db/qsql/tr_hdrs_cache_qsql.hpp>
13 #include <hds_db/qsql/tr_bodies_cache_qsql.hpp>
14 
16 namespace hds
17 {
19  namespace db
20  {
21  class ProjectQSql;
22 
24  class SeismicQSql : public Seismic, public QSqlImpl
25  {
27  friend class ProjectQSql;
28 
29  public:
30 
37  SeismicQSql(const ContextQSql &dbc,
38  const std::string &project_str,
39  const size_t hdrs_cache_size = 8192,
40  const size_t bodies_cache_size = 4096);
41 
43  virtual ~SeismicQSql();
44 
45  //--- Access to data storage ---------------------------------------------------------------
46 
49  virtual ErrCode open(const std::string &name, OpenMode mode);
50 
53  virtual ErrCode close();
54 
57  virtual ErrCode flush();
58 
61  virtual ErrCode setName(const std::string &name_str);
62 
65  virtual std::string name(ErrCode *rc = NULL) const;
66 
69  virtual ErrCode remove(const std::string &name);
70 
75  virtual ErrCode getList(Names &list) const;
76 
81  virtual size_t dataSize(const std::string &name,
82  ErrCode *prc = NULL) const;
83 
87  virtual time_t creationTime(const std::string &name,
88  ErrCode *prc = NULL) const;
89 
93  virtual time_t modificationTime(const std::string &name,
94  ErrCode *prc = NULL) const;
95 
98  virtual DbIndex rawDbIndex(size_t id, ErrCode *prc = NULL) const;
99 
100 
101  //--- Reading facilities -------------------------------------------------------------------
102 
105  virtual ErrCode getVolumeHeader(VolumeHeader &vol_header) const;
106 
108  virtual size_t tracesNum(ErrCode *rc = NULL) const;
109 
112  virtual const TrHeader& rawTrHeader(const DbIndex &id, ErrCode *rc = NULL) const;
113 
116  virtual const TrBody& rawTrBody(const DbIndex &id, ErrCode *rc = NULL) const;
117 
118  //--- Writing/editing facilities -----------------------------------------------------------
119 
122  virtual ErrCode setVolumeHeader(const VolumeHeader &vol_header);
123 
125  virtual ErrCode rawSetTrHeader(const DbIndex &id, const TrHeader &hdr);
126 
128  virtual ErrCode rawSetTrBody(const DbIndex &id, const TrBody &body);
129 
132  virtual ErrCode appendTr(const TrHeader &header, const TrBody &body);
133 
136  virtual ErrCode eraseTr(size_t id);
137 
138  //--- Selection facilities -----------------------------------------------------------------
139 
143  virtual ErrCode select(const TrSelector &selector = TrSelector());
144 
146  virtual const TrSelector& getSelector() const;
147 
148 
149  //--- Extra functionality -----------------------------------------------------------------
150 
152  const DbIndex& getCurrentSeismicId() const {return m_cur_seismic_id;}
153 
156  void setBufferAllHeadersFlag(bool flag = true);
157 
160 
161  protected:
162 
165 
168 
170  DbIndex m_db_lock_id;
171 
172  private:
173 
175  size_t m_cur_traces_num;
176 
178  std::vector<DbIndex> m_trace_id_vec;
179 
181  size_t m_hdrs_cache_size;
182 
184  size_t m_bodies_cache_size;
185 
187  bool m_buffer_all_hdrs_flag;
188 
190  mutable TrHdrsCacheQSql m_hdrs_cache;
191 
193  mutable TrBodiesCacheQSql m_bodies_cache;
194 
197  DbIndex db_get_trace_id(const size_t id) const;
198 
200  ErrCode db_select_tr_indexes(const TrSelector &selector,
201  const bool is_temporary,
202  std::vector<DbIndex> &ids);
203 
205  void matching_condition_rule(QString &match_str,
206  const QString &rule_str,
207  const TrSelBaseRule *ppr,
208  const TrSelBaseRule *pr);
209 
211  ErrCode db_get_volume_header(const DbIndex &seis_id,
212  const bool is_temporary,
213  VolumeHeader &hdr) const;
214 
216  ErrCode db_update_volume_header(const DbIndex &seis_id,
217  const VolumeHeader &hdr,
218  const bool is_temporary);
219 
222  ErrCode db_create_seismic(const std::string &name,
223  const DbIndex &project_id,
224  const bool is_temporary,
225  DbIndex &id);
226 
228  ErrCode db_remove_seismic(const DbIndex &project_id,
229  const DbIndex &seis_id);
230 
232  bool db_tmp_seismic_exists(const DbIndex &seis_id) const;
233 
235  ErrCode db_get_hdrs_bodies_tbl_names(const std::string &name,
236  QString &hdrs_str,
237  QString &bodies_str,
238  DbIndex &seis_id) const;
239 
242  static ErrCode db_create_seismic_table(QSqlDatabase &m_db,
243  const bool is_temporary);
244 
245 
246  // DB query strings generators
247  ErrCode qs_create_tr_headers_table(const DbIndex &id,
248  const bool is_temporary,
249  QString &qs) const;
250  ErrCode qs_create_tr_bodies_table(const DbIndex &id,
251  const bool is_temporary,
252  QString &qs) const;
253  QString qs_match_rule(const TrSelBaseRule *prule, const QString &op) const;
254  QString qs_sort_rule(const TrSelBaseRule *prule) const;
255  QString qs_range_rule(const TrSelBaseRule *prule) const;
256 
259  static ErrCode name2id(QSqlDatabase &db,
260  const std::string &name,
261  const DbIndex &project_id,
262  DbIndex &id);
263 
266  static ErrCode tmp_name2id(QSqlDatabase &db,
267  const std::string &name,
268  DbIndex &id);
269 
272  static ErrCode clear(QSqlDatabase &db, const DbIndex &project_id);
273  };
274  }; // db
275 }; // hds
276 
277 #endif /* __hds_db_seismic_qsql_hpp */
SeismicQSql(const ContextQSql &dbc, const std::string &project_str, const size_t hdrs_cache_size=8192, const size_t bodies_cache_size=4096)
Definition: tr_hdrs_cache_qsql.hpp:20
virtual DbIndex rawDbIndex(size_t id, ErrCode *prc=NULL) const
void setBufferAllHeadersFlag(bool flag=true)
virtual ErrCode rawSetTrHeader(const DbIndex &id, const TrHeader &hdr)
virtual ErrCode getVolumeHeader(VolumeHeader &vol_header) const
OpenMode
Definition: defines.hpp:32
virtual const TrHeader & rawTrHeader(const DbIndex &id, ErrCode *rc=NULL) const
Definition: dbcontext_qsql.hpp:15
Definition: seismic.hpp:19
Definition: tr_selector.hpp:52
uint64_t DbIndex
Definition: defines.hpp:26
Definition: volume_header.hpp:17
virtual ErrCode setName(const std::string &name_str)
virtual ErrCode getList(Names &list) const
const DbIndex & getCurrentSeismicId() const
Definition: seismic_qsql.hpp:152
Definition: project_qsql.hpp:20
virtual ErrCode appendTr(const TrHeader &header, const TrBody &body)
ErrCode
Definition: defines.hpp:46
Definition: tr_selector.hpp:183
virtual ErrCode close()
std::vector< AmplT > TrBody
Definition: defines.hpp:23
virtual const TrBody & rawTrBody(const DbIndex &id, ErrCode *rc=NULL) const
Definition: seismic_qsql.hpp:24
virtual size_t tracesNum(ErrCode *rc=NULL) const
virtual size_t dataSize(const std::string &name, ErrCode *prc=NULL) const
QSqlDatabase m_db
Definition: qsql_impl.hpp:81
virtual ErrCode open(const std::string &name, OpenMode mode)
virtual time_t creationTime(const std::string &name, ErrCode *prc=NULL) const
TrSelector m_tr_selector
Definition: seismic_qsql.hpp:167
virtual ErrCode flush()
bool getBufferAllHeadersFlag()
Definition: tr_bodies_cache_qsql.hpp:19
virtual time_t modificationTime(const std::string &name, ErrCode *prc=NULL) const
Definition: qsql_impl.hpp:19
virtual ErrCode select(const TrSelector &selector=TrSelector())
virtual std::string name(ErrCode *rc=NULL) const
Definition: tr_header.hpp:17
virtual ErrCode rawSetTrBody(const DbIndex &id, const TrBody &body)
virtual ErrCode setVolumeHeader(const VolumeHeader &vol_header)
virtual ErrCode eraseTr(size_t id)
DbIndex m_cur_seismic_id
Definition: seismic_qsql.hpp:164
virtual const TrSelector & getSelector() const
std::vector< std::string > Names
Definition: object.hpp:23