casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBTable.h
Go to the documentation of this file.
1 //# Table.h: Primary interface for the rest of the browser to a table.
2 //# Copyright (C) 2007-2008
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef TBTABLE_H_
28 #define TBTABLE_H_
29 
32 
33 #include <casa/BasicSL/String.h>
34 
35 #include <vector>
36 
37 namespace casa {
38 
39 //# Forward Declarations
40 class TBField;
41 class TBKeyword;
42 class TBArray;
43 class ProgressHelper;
44 class XMLtoken;
45 class TBParser;
46 class TBTableDriver;
47 class TBData;
48 class TBArrayData;
49 class TBPlotData;
50 class TBFilterRuleSequence;
51 
52 // <summary>
53 // Parameters to indicate what driver should be used for the table backend.
54 // </summary>
55 //
56 // <synopsis>
57 // The DriverParams consist of two parameters: the driver type and (if
58 // applicable) the parser type. The parser type is only used for the XML
59 // driver.
60 // </synopsis>
61 
62 class DriverParams {
63 public:
64  // Default Constructor.
66  parser(p) { }
67 
68  // Copy Constructor.
70 
71 
72  // Driver type.
74 
75  // Parser type (for XML driver).
77 };
78 
79 // <summary>
80 // Parameters that define all table data and meta-deta.
81 // </summary>
82 //
83 // <synopsis>
84 // A TableParams contains references to all important table members. Since
85 // this information needs to be accessed and potentially changed by both the
86 // TBTable and the TBTableDriver, the references are shared by passing a
87 // TableParams object.
88 // </synopsis>
89 
90 class TableParams {
91 public:
92  TableParams(casacore::String& l, bool& ir, bool& rr,
93  std::vector<std::vector<TBData*>*>& d,
94  std::vector<TBField*>& f, std::vector<TBKeyword*>& k,
95  std::vector<int>& sr, int& tr, int& lr, std::vector<bool>& w, bool& t,
96  DriverParams* dp): location(l), insertRow(ir), removeRow(rr),
97  data(d), fields(f), keywords(k), subtableRows(sr),
98  totalRows(tr), loadedRows(lr), writable(w), taql(t),
99  dParams(dp) { }
100 
101 
102  // See TBTable::location.
104 
105  // See TBTable::insertRow.
106  bool& insertRow;
107 
108  // See TBTable::removeRow.
109  bool& removeRow;
110 
111  // See TBTable::data.
112  std::vector<std::vector<TBData*>*>& data;
113 
114  // See TBTable::fields.
115  std::vector<TBField*>& fields;
116 
117  // See TBTable::keywords.
118  std::vector<TBKeyword*>& keywords;
119 
120  // See TBTable::subtableRows.
121  std::vector<int>& subtableRows;
122 
123  // See TBTable::totalRows.
124  int& totalRows;
125 
126  // See TBTable::loadedRows.
128 
129  // See TBTable::writable.
130  std::vector<bool>& writable;
131 
132  // See TBTable::taql.
133  bool& taql;
134 
135  // See TBTable::dParams.
137 };
138 
139 // <summary>
140 // Primary interface for the rest of the browser to a table.
141 // </summary>
142 //
143 // <synopsis>
144 // Although TBTable is considered the table backend, it is actually more like
145 // an interface over a TBTableDriver. However, since there may be multiple
146 // implementations of the driver, the table provides a unified interface over
147 // the driver as well as other useful operations. Generally speaking, the
148 // driver handles dealing with the table on disk while the TBTable handles
149 // dealing with the data represented in memory.
150 // </synopsis>
151 
152 class TBTable {
153 public:
154  // Constructor that takes the filename and driver parameters. If taql is
155  // true, then this table is a table constructed from a TaQL command stored
156  // in filename; otherwise filename holds the location on disk of the table.
157  TBTable(casacore::String filename, DriverParams* dp, bool taql = false);
158 
159  ~TBTable();
160 
161 
162  // Returns the filename where this table is located.
164 
165  // Returns the name of this table (which the last the part of the
166  // filename). If this is a TaQL table, returns "TaQL casacore::Table".
168 
169  // Returns the driver parameters for this table.
171 
172  // Returns the fields for this table.
173  std::vector<TBField*>* getFields();
174 
175  // Returns the field at the given index, or NULL if there is none.
176  TBField* field(int i);
177 
178  // Returns the field with the given name, or NULL if there is none.
180 
181  // Returns the table keywords.
182  std::vector<TBKeyword*>* getTableKeywords();
183 
184  // Returns the keyword at the given index, or NULL if there is none.
185  TBKeyword* keyword(int i);
186 
187  // Returns the keyword with the given name, or NULL if there is none.
189 
190  // Indicates if the table is ready for access or not.
191  bool isReady();
192 
193  // Returns true if the underlying table allows for insertion of rows,
194  // false otherwise.
195  bool canInsertRows();
196 
197  // Returns true if the underlying table allows for deletion of rows,
198  // false otherwise.
199  bool canDeleteRows();
200 
201  // Returns the total number of rows in the table.
202  int getTotalRows();
203 
204  // Returns the number of rows loaded into the table.
205  int getLoadedRows();
206 
207  // Returns the number of selected rows. Note: this may be different than
208  // the number of loaded rows. For example, if you load rows [0 - 1000] but
209  // the table has only 20 rows, getSelectedRows() would return 1000 while
210  // getLoadedRows() would return 20.
211  int getSelectedRows();
212 
213  // Returns the number of pages in the table.
214  int getNumPages();
215 
216  // Return the currently loaded page.
217  int getPage();
218 
219  // Returns the first loaded row in the table.
220  int getRowIndex();
221 
222  // Returns the number of columns in the table.
223  int getNumFields();
224 
225  // Sets whether the table should print debug information or not.
226  void setPrintDebug(bool pdb);
227 
228  // Returns the data at the given indices, or NULL if they are invalid.
229  TBData* dataAt(unsigned int row, unsigned int col);
230 
231  // Returns the shape of the array for the given field, or an empty list
232  // if the field is not an array.
233  std::vector<int> dataDimensionsAt(unsigned int col);
234 
235  // Returns whether all the columns in this table are editable or not.
236  bool isEditable();
237 
238  // Returns whether any of the columns in this table are editable or not.
239  bool isAnyEditable();
240 
241  // Returns whether the column at the given index is editable or not.
242  bool isEditable(int index);
243 
244  // Returns whether this table is constructed from a TaQL query or not.
245  bool isTaQL();
246 
247  // See TBTableDriver::canRead().
248  bool canRead();
249 
250  // See TBTableDriver::canWrite().
251  bool canWrite();
252 
253  // See TBTableDriver::tryWriteLock().
254  bool tryWriteLock();
255 
256  // See TBTableDriver::releaseWriteLock().
257  bool releaseWriteLock();
258 
259 
260  // Loads the given rows into the table and returns a Result indicating the
261  // success of the loading. The rows loaded will be from start to start +
262  // number (inclusive). If full is true, array data will be included;
263  // otherwise only the shapes of the array will be included. If columns
264  // is a non-NULL, non-empty list, then only those fields will be loaded
265  // into the table. If parsedata is true, the table data will be loaded;
266  // otherwise only the meta-data will be loaded. If a ProgressHelper is
267  // provided, the label and progress meter will be periodically updated
268  // as progress is made.
269  Result loadRows(int start = 0,
270  int number = TBConstants::DEFAULT_SELECT_NUM,
271  bool full = false, std::vector<casacore::String>* columns = NULL,
272  bool parsedata = true,
273  ProgressHelper* progressPanel = NULL);
274 
275  // Returns the column headers (field names) for this table.
276  std::vector<casacore::String> getColumnHeaders();
277 
278  // Returns the row headers (row numbers) for the loaded rows in this table.
279  std::vector<casacore::String> getRowHeaders();
280 
281  // Loads and returns the array at the given indices.
282  TBArrayData* loadArray(unsigned int row, unsigned int col);
283 
284  // Release the array at the given indices and returns whether the release
285  // succeeded.
286  bool releaseArray(unsigned int row, unsigned int col);
287 
288  // Edits the data at the given indices to have the new value and returns
289  // whether the operation succeeded.
290  Result editData(unsigned int row, unsigned int col, TBData* newVal);
291 
292  // Updates the table on disk with the new value at the given coordinates
293  // in the array at the given row and column. oneDim must be true for a
294  // one-dimensional array, false otherwise. Returns a result indicating
295  // the success of the editing.
296  Result editArrayData(unsigned int row, unsigned int col,
297  std::vector<int> coords, TBData* newVal, bool oneDim);
298 
299  // Exports the entirety of this table to VOTable XML format to the given
300  // file. If a ProgressHelper is provided, progress information is updated
301  // periodically.
302  void exportVOTable(casacore::String file, ProgressHelper* progressPanel = NULL);
303 
304  // Returns data used for plotting, using the given plot parameters and row
305  // information. If a ProgressHelper is provided, progress information is
306  // updated periodically.
307  TBPlotData* plotRows(PlotParams& x, PlotParams& y, int rowFrom, int rowTo,
308  int rowInterval, TBFilterRuleSequence* rule = NULL,
309  ProgressHelper* ph = NULL);
310 
311  // Returns data used for plotting (an 1-D array and its indices),
312  // using the given plot parameters, slice axis, and row number.
313  // If a ProgressHelperis provided, progress information is updated
314  // periodically.
315  TBPlotData* plotIndices(PlotParams& dp, int axis, bool x, int row,
316  TBFilterRuleSequence* rule = NULL,
317  ProgressHelper* ph = NULL);
318 
319  // Returns the total number of rows for the table at the given location, or
320  // -1 for an invalid location or other problem. TBTable caches the total
321  // rows of all subtables (i.e., tables pointed to in the table keywords).
323 
324  // Returns a tooltip for the field at index i.
326 
327  // Returns a tooltip for this table.
329 
330  // Inserts the given number of rows at the end of the table. Returns a
331  // Result indicating the success of the operation.
332  Result insertRows(int n);
333 
334  // Deletes the given rows from the table. Each element in the vector
335  // should be a row number. Returns a Result indicating the success of the
336  // operation.
337  Result deleteRows(std::vector<int> r);
338 
339 private:
340  // Driver parameters.
342 
343  // Location of the table.
345 
346  // Indicates whether the table is ready for access or not.
347  bool ready;
348 
349  // Indicates whether this table allows for the insertion of rows or not.
350  bool insertRow;
351 
352  // Indicates whether this table allows for the deletion of rows or not.
353  bool removeRow;
354 
355  // Holds the table data.
356  std::vector< std::vector<TBData*>* > data;
357 
358  // The total number of rows in the table.
360 
361  // The number of rows currently loaded in the table.
363 
364  // The last number of rows selected for loading during the last load.
366 
367  // The index of the first row loaded in this table.
368  int rowIndex;
369 
370  // The table fields.
371  std::vector<TBField*> fields;
372 
373  // The table keywords.
374  std::vector<TBKeyword*> keywords;
375 
376  // Cache of total number of rows for subtables.
377  std::vector<int> subtableRows;
378 
379  // Indicates whether this table is writable or not.
380  std::vector<bool> writable;
381 
382  // Indates whether this table was constructed from a TaQL command or not.
383  bool taql;
384 
385  // casacore::Table driver.
387 
388 
389  // Helper method for plotRows().
390  double getDouble(TBData* d, std::vector<int>* slice, bool complex, bool amp);
391 
392  // Helper method for plotRows().
393  void filter(TBPlotData* data, TBTable& table, TBFilterRuleSequence* rules,
394  int rowFrom, int rowTo, int rowInterval);
395 };
396 
397 }
398 
399 #endif /* TBTABLE_H_ */
bool canRead()
See TBTableDriver::canRead().
static const unsigned int DEFAULT_SELECT_NUM
The default number of rows to load from the table at a time.
Definition: TBConstants.h:168
int loadedRows
The number of rows currently loaded in the table.
Definition: TBTable.h:362
std::vector< TBKeyword * > & keywords
See TBTable::keywords.
Definition: TBTable.h:118
DriverParams * dParams
See TBTable::dParams.
Definition: TBTable.h:136
std::vector< TBField * > fields
The table fields.
Definition: TBTable.h:371
bool isEditable()
Returns whether all the columns in this table are editable or not.
std::vector< TBField * > * getFields()
Returns the fields for this table.
int totalRows
The total number of rows in the table.
Definition: TBTable.h:359
TBField * field(int i)
Returns the field at the given index, or NULL if there is none.
bool canWrite()
See TBTableDriver::canWrite().
Convenience class for a casacore::String/bool tuple.
Definition: TBConstants.h:93
Result editArrayData(unsigned int row, unsigned int col, std::vector< int > coords, TBData *newVal, bool oneDim)
Updates the table on disk with the new value at the given coordinates in the array at the given row a...
bool removeRow
Indicates whether this table allows for the deletion of rows or not.
Definition: TBTable.h:353
double getDouble(TBData *d, std::vector< int > *slice, bool complex, bool amp)
Helper method for plotRows().
casacore::String tableToolTip()
Returns a tooltip for this table.
void exportVOTable(casacore::String file, ProgressHelper *progressPanel=NULL)
Exports the entirety of this table to VOTable XML format to the given file.
std::vector< TBField * > & fields
See TBTable::fields.
Definition: TBTable.h:115
bool & removeRow
See TBTable::removeRow.
Definition: TBTable.h:109
casacore::Data for plotting.
Definition: TBPlotter.qo.h:94
casacore::Data types used for loaded data.
Definition: TBData.h:51
std::vector< bool > writable
Indicates whether this table is writable or not.
Definition: TBTable.h:380
std::vector< std::vector< TBData * > * > data
Holds the table data.
Definition: TBTable.h:356
tb::Parser parser
Parser type (for XML driver).
Definition: TBTable.h:76
bool & insertRow
See TBTable::insertRow.
Definition: TBTable.h:106
bool canInsertRows()
Returns true if the underlying table allows for insertion of rows, false otherwise.
void setPrintDebug(bool pdb)
Sets whether the table should print debug information or not.
int totalRowsOf(casacore::String location)
Returns the total number of rows for the table at the given location, or -1 for an invalid location o...
bool canDeleteRows()
Returns true if the underlying table allows for deletion of rows, false otherwise.
TBData * dataAt(unsigned int row, unsigned int col)
Returns the data at the given indices, or NULL if they are invalid.
Result insertRows(int n)
Inserts the given number of rows at the end of the table.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
Parser
Enum to indicate the different parsers available for XML drivers.
Definition: TBConstants.h:77
void filter(TBPlotData *data, TBTable &table, TBFilterRuleSequence *rules, int rowFrom, int rowTo, int rowInterval)
Helper method for plotRows().
std::vector< int > subtableRows
Cache of total number of rows for subtables.
Definition: TBTable.h:377
Driver for interacting with the table on disk.
Definition: TBTableDriver.h:68
int rowIndex
The index of the first row loaded in this table.
Definition: TBTable.h:368
bool releaseArray(unsigned int row, unsigned int col)
Release the array at the given indices and returns whether the release succeeded. ...
int getRowIndex()
Returns the first loaded row in the table.
casacore::Data type that holds an array.
Definition: TBData.h:983
std::vector< int > & subtableRows
See TBTable::subtableRows.
Definition: TBTable.h:121
Wrapper around a QProgressPanel or other QLabel/QProgressBar pairing.
Result deleteRows(std::vector< int > r)
Deletes the given rows from the table.
Parameters that define all table data and meta-deta.
Definition: TBTable.h:90
int & totalRows
See TBTable::totalRows.
Definition: TBTable.h:124
std::vector< std::vector< TBData * > * > & data
See TBTable::data.
Definition: TBTable.h:112
bool isTaQL()
Returns whether this table is constructed from a TaQL query or not.
bool ready
Indicates whether the table is ready for access or not.
Definition: TBTable.h:347
tb::Driver type
Driver type.
Definition: TBTable.h:73
TBArrayData * loadArray(unsigned int row, unsigned int col)
Loads and returns the array at the given indices.
int & loadedRows
See TBTable::loadedRows.
Definition: TBTable.h:127
bool isAnyEditable()
Returns whether any of the columns in this table are editable or not.
bool isReady()
Indicates if the table is ready for access or not.
std::vector< casacore::String > getColumnHeaders()
Returns the column headers (field names) for this table.
casacore::String getName()
Returns the name of this table (which the last the part of the filename).
bool taql
Indates whether this table was constructed from a TaQL command or not.
Definition: TBTable.h:383
Primary interface for the rest of the browser to a table.
Definition: TBTable.h:152
LatticeExprNode amp(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds sqrt(left^2+right^2).
TBPlotData * plotRows(PlotParams &x, PlotParams &y, int rowFrom, int rowTo, int rowInterval, TBFilterRuleSequence *rule=NULL, ProgressHelper *ph=NULL)
Returns data used for plotting, using the given plot parameters and row information.
std::vector< casacore::String > getRowHeaders()
Returns the row headers (row numbers) for the loaded rows in this table.
TBTableDriver * driver
casacore::Table driver.
Definition: TBTable.h:386
Driver
Enum to indicate the different driver types.
Definition: TBConstants.h:72
bool releaseWriteLock()
See TBTableDriver::releaseWriteLock().
Result loadRows(int start=0, int number=TBConstants::DEFAULT_SELECT_NUM, bool full=false, std::vector< casacore::String > *columns=NULL, bool parsedata=true, ProgressHelper *progressPanel=NULL)
Loads the given rows into the table and returns a Result indicating the success of the loading...
std::vector< TBKeyword * > * getTableKeywords()
Returns the table keywords.
std::vector< int > dataDimensionsAt(unsigned int col)
Returns the shape of the array for the given field, or an empty list if the field is not an array...
std::vector< TBKeyword * > keywords
The table keywords.
Definition: TBTable.h:374
int getLoadedRows()
Returns the number of rows loaded into the table.
TBPlotData * plotIndices(PlotParams &dp, int axis, bool x, int row, TBFilterRuleSequence *rule=NULL, ProgressHelper *ph=NULL)
Returns data used for plotting (an 1-D array and its indices), using the given plot parameters...
TBTable(casacore::String filename, DriverParams *dp, bool taql=false)
Constructor that takes the filename and driver parameters.
int getSelectedRows()
Returns the number of selected rows.
A sequence of TBFilterRules that can be used to filter rows.
casacore::String fieldToolTip(int i)
Returns a tooltip for the field at index i.
bool & taql
See TBTable::taql.
Definition: TBTable.h:133
Representation of a table field.
Definition: TBField.h:48
TBKeyword * keyword(int i)
Returns the keyword at the given index, or NULL if there is none.
DriverParams(tb::Driver t=tb::DIRECT, tb::Parser p=tb::XERCES_SAX)
Default Constructor.
Definition: TBTable.h:65
Result editData(unsigned int row, unsigned int col, TBData *newVal)
Edits the data at the given indices to have the new value and returns whether the operation succeeded...
casacore::String getFile()
Returns the filename where this table is located.
int selectedRows
The last number of rows selected for loading during the last load.
Definition: TBTable.h:365
DriverParams * getDriverParams()
Returns the driver parameters for this table.
int getPage()
Return the currently loaded page.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
bool tryWriteLock()
See TBTableDriver::tryWriteLock().
casacore::String & location
See TBTable::location.
Definition: TBTable.h:103
Parameters for a single field for collecting plotting data.
Definition: TBPlotter.qo.h:61
int getNumPages()
Returns the number of pages in the table.
bool insertRow
Indicates whether this table allows for the insertion of rows or not.
Definition: TBTable.h:350
DriverParams(DriverParams *dp)
Copy Constructor.
Definition: TBTable.h:69
casacore::String location
Location of the table.
Definition: TBTable.h:344
Representation of a keyword attached to a table or field.
Definition: TBKeyword.h:45
Parameters to indicate what driver should be used for the table backend.
Definition: TBTable.h:62
DriverParams * dParams
Driver parameters.
Definition: TBTable.h:341
std::vector< bool > & writable
See TBTable::writable.
Definition: TBTable.h:130
int getNumFields()
Returns the number of columns in the table.
int getTotalRows()
Returns the total number of rows in the table.
TableParams(casacore::String &l, bool &ir, bool &rr, std::vector< std::vector< TBData * > * > &d, std::vector< TBField * > &f, std::vector< TBKeyword * > &k, std::vector< int > &sr, int &tr, int &lr, std::vector< bool > &w, bool &t, DriverParams *dp)
Definition: TBTable.h:92
Defines nreal time structures used by the VLA table filler.
Definition: nreal.h:100