casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TableProxy.h
Go to the documentation of this file.
1 //# TableProxy.h: High-level interface to tables
2 //# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2005
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 
28 #ifndef TABLES_TABLEPROXY_H
29 #define TABLES_TABLEPROXY_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
37 #include <vector>
38 
39 
40 //# Forward Declarations
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42  class ValueHolder;
43  class RecordFieldId;
44  class Table;
45  class TableLock;
46  class ColumnDesc;
47  class TableExprNode;
48  template<class T> class Vector;
49  class Slicer;
50 
51 
52 // <summary>
53 // High-level interface to tables
54 // </summary>
55 
56 // <use visibility=export>
57 
58 // <reviewed reviewer="Paul Shannon" date="1995/09/15" tests="ttable.py" demos="">
59 // </reviewed>
60 
61 // <prerequisite>
62 //# Classes you should understand before using this one.
63 // <li> class Table
64 // <li> python script table.py
65 // </prerequisite>
66 
67 // <etymology>
68 // TableProxy is a proxy for access to tables from any script.
69 // </etymology>
70 
71 // <synopsis>
72 // TableProxy gives access to most of the functionality in the Table System.
73 // It is primarily meant to be used in classes that wrap access to it
74 // from scripting languages (like Glish and Python).
75 // However, it can also be used directly from other C++ code.
76 //
77 // It has functions to open, create, read, write, and query tables.
78 // Accompying proxy classes give access to other functionality. They are:
79 // <ul>
80 // <li> <linkto class=TableIterProxy>TableIterProxy</linkto> for iteration
81 // through a table using class
82 // <linkto class=TableIterator>TableIterator</linkto>.
83 // <li> <linkto class=TableRowProxy>TableRowProxy</linkto> for access to
84 // table rows using class <linkto class=TableRow>TableRow</linkto>.
85 // <li> <linkto class=TableIndexProxy>TableIterProxy</linkto> for faster
86 // indexed access to using classes
87 // <linkto class=ColumnsIndex>ColumnsIndex</linkto> and
88 // <linkto class=ColumnsIndexArray>ColumnsIndexArray</linkto>.
89 // </ul>
90 //
91 // TableProxy does not have the TableRecord type in its interface, because
92 // such a type cannot be handled by e.g. Glish or Python. Instead it
93 // converts TableRecords to/from Records. If a TableRecord contains a field
94 // with a Table object, it is represented in the Record as a string
95 // with the value "Table: NAME" where NAME is the table name.
96 // </synopsis>
97 
98 // <motivation>
99 // TableProxy is the Tasking-independent high-level table interface.
100 // Different front-ends (e.g. GlishTableProxy) can be put on top of it.
101 // </motivation>
102 
104 {
105 public:
106  // Default constructor initializes to not open.
107  // This constructor is only needed for containers.
108  TableProxy();
109 
110  // Create the object from an existing table (used by some methods).
112  : table_p (table) {}
113 
114  // Open the table with a given name.
115  TableProxy (const String& tableName,
116  const Record& lockOptions,
117  int option);
118 
119  // Create a table with given name and description, etc.
120  TableProxy (const String& tableName,
121  const Record& lockOptions,
122  const String& endianFormat,
123  const String& memType,
124  int nrow,
125  const Record& tableDesc,
126  const Record& dmInfo);
127 
128  // Create a table object to concatenate a number of similar tables.
129  // The keyword set of the first table is take as the keyword set of the
130  // entire concatenation. However, it can be specified which subtables
131  // have to be concatenated as well which means that for each subtable name
132  // the subtable in the keywordsets are concatenated.
133  // <note>For Boost-Python the constructors must have different nr of arguments.
134  // Hence some dummy arguments are added.
135  //</note>
136  // <group>
137  TableProxy (const Vector<String>& tableNames,
138  const Vector<String>& concatenateSubTableNames,
139  const Record& lockOptions,
140  int option);
141  TableProxy (const std::vector<TableProxy>& tables,
142  const Vector<String>& concatenateSubTableNames,
143  int dummy1=0, int dummy2=0, int dummy3=0);
144  // </group>
145 
146  // Create a table object from a table command (as defined in TableGram).
147  // <br>If a CALC command was given, the resulting values are stored in
148  // the a record and a null TableProxy object is returned.
149  // The result can be obtained using getCalcResult.
150  // <note>
151  // If the command string contains no GIVING part, the resulting
152  // table is temporary and its name is blank.
153  // </note>
154  TableProxy (const String& command,
155  const std::vector<TableProxy>& tables);
156 
157  // Create a table from an Ascii file.
158  // It fills a string containing the names and types
159  // of the columns (in the form COL1=R, COL2=D, ...).
160  // The string can be obtained using getAsciiFormat.
161  TableProxy (const String& fileName,
162  const String& headerName,
163  const String& tableName,
164  Bool autoHeader,
165  const IPosition& autoShape,
166  const String& separator,
167  const String& commentMarker,
168  Int firstLine,
169  Int lastLine,
171  const Vector<String>& dataTypes = Vector<String>());
172 
173  // Copy constructor.
174  TableProxy (const TableProxy&);
175 
176  // Close the table.
177  ~TableProxy();
178 
179  // Assignment.
181 
182  // Select the given rows from the table and create a new (reference) table.
183  // If outName is not empty, the new table is made persistent with that name.
184  TableProxy selectRows (const Vector<Int>& rownrs,
185  const String& outName);
186 
187  // Reopen the table for read/write.
188  void reopenRW();
189 
190  // Resync the table.
191  void resync();
192 
193  // Flush the table and optionally all its subtables.
194  void flush (Bool recursive);
195 
196  // Flush and close the table and all its subtables.
197  void close();
198 
199  // Get the endian format of the table.
200  // It fills the result with value "big" or "little".
201  String endianFormat() const;
202 
203  // Acquire a (read or write) lock on the table.
204  void lock (Bool mode, Int nattempts);
205 
206  // Release a lock on the table.
207  void unlock();
208 
209  // Determine if data in the table has changed.
211 
212  // Determine if the process has a read or write lock on the table.
213  Bool hasLock (Bool mode);
214 
215  // Get the lock options of the table.
216  // It fills the record with the fields option, interval and maxwait.
218 
219  // Determine if the table (and optionally its subtables) are in use
220  // in another process.
221  Bool isMultiUsed (Bool checkSubTables);
222 
223  // Write the table to an ASCII file
224  // (approximately the inverse of the from-ASCII-contructor).
225  // If <src>headerFile</src> is empty or equal to <src>asciiFile</src>, the
226  // headers are written in the same file as the data, otherwise in a separate
227  // file.
228  // If no columns are given (or if the first column name is empty), all
229  // table columns are written. Columns containing records are also printed
230  // (enclosed in {}), but a warning message is returned.
231  // <br>Argument <src>sep</src> is used as separator between columns and
232  // array values. If it is empty, a blank is used.
233  // <br>For each column the precision can be given. It is only used for
234  // columns containing floating point numbers. A value <=0 means using the
235  // default which is 9 for single and 18 for double precision.
236  // <br>If <src>useBrackets=True</src>, arrays are enclosed in [] (for each
237  // dimension), so variable shaped arrays can be read back unambiguously.
238  // The type in the header will be something like D[4,64]. If the column is
239  // variable shaped, the type is like D[].
240  // If <src>useBracket=False</src>, arrays are written linearly where a
241  // shape [4,64] is given in the header like D4,64. If the column is variable
242  // shaped, the shape of the first cell is used and a warning message is
243  // returned.
244  String toAscii (const String& asciiFile,
245  const String& headerFile,
246  const Vector<String>& columns,
247  const String& sep,
248  const Vector<Int>& precision,
249  Bool useBrackets);
250 
251  // Rename the table
252  void rename (const String& newTableName);
253 
254  // Copy the table (possibly a deep copy).
255  // If noRows=True, an empty table is created.
256  TableProxy copy (const String& newTableName,
257  Bool toMemoryTable,
258  Bool deepCopy,
259  Bool valueCopy,
260  const String& endianFormat,
261  const Record& dminfo,
262  Bool noRows);
263 
264  // Copy rows from one table to another.
265  // If startOut<0, it is set to the end of the output table.
266  void copyRows (TableProxy& out,
267  Int startIn,
268  Int startOut,
269  Int nrow);
270 
271  // Close and delete the table.
272  void deleteTable (Bool checkSubTables);
273 
274  // Get the table info of the table.
275  Record tableInfo();
276 
277  // Put the table info of the table.
278  void putTableInfo (const Record& value);
279 
280  // Add a line to the TableInfo readme.
281  void addReadmeLine (const String& line);
282 
283  // Test if a table is readable.
284  Bool isReadable() const;
285 
286  // Test if a table is writable.
287  Bool isWritable() const;
288 
289  // Set the maximum cache size for the given column in the table.
290  void setMaximumCacheSize (const String& columnName,
291  Int nbytes);
292 
293  // Add one or more columns to the table.
294  void addColumns (const Record& tableDesc,
295  const Record& dminfo,
296  Bool addToParent);
297 
298  // Rename a column in the table.
299  void renameColumn (const String& nameOld,
300  const String& nameNew);
301 
302  // Remove one or more columns from the table.
304 
305  // Add rows to the table.
306  void addRow (Int nrow);
307 
308  // Remove rows from the table.
309  void removeRow (const Vector<Int>& rownrs);
310 
311  // Get some or all values from a column in the table.
312  // row is the starting row number (0-relative).
313  // nrow=-1 means until the end of the table.
314  // incr is the step in row number.
315  // <group>
316  ValueHolder getColumn (const String& columnName,
317  Int row,
318  Int nrow,
319  Int incr);
320  void getColumnVH (const String& columnName,
321  Int row,
322  Int nrow,
323  Int incr,
324  const ValueHolder& vh);
325  Record getVarColumn (const String& columnName,
326  Int row,
327  Int nrow,
328  Int incr);
329  // </group>
330 
331  // Get some or all value slices from a column in the table.
332  // If the inc vector is empty, it defaults to all 1.
333  // <group>
334  ValueHolder getColumnSlice (const String& columnName,
335  Int row,
336  Int nrow,
337  Int incr,
338  const Vector<Int>& blc,
339  const Vector<Int>& trc,
340  const Vector<Int>& inc);
341  ValueHolder getColumnSliceIP (const String& columnName,
342  const IPosition& blc,
343  const IPosition& trc,
344  const IPosition& inc,
345  Int row,
346  Int nrow,
347  Int incr);
348  void getColumnSliceVH (const String& columnName,
349  Int row,
350  Int nrow,
351  Int incr,
352  const Vector<Int>& blc,
353  const Vector<Int>& trc,
354  const Vector<Int>& inc,
355  const ValueHolder& vh);
356  void getColumnSliceVHIP (const String& columnName,
357  const IPosition& blc,
358  const IPosition& trc,
359  const IPosition& inc,
360  Int row,
361  Int nrow,
362  Int incr,
363  const ValueHolder& vh);
364  // </group>
365 
366  // Put some or all values into a column in the table.
367  // row is the starting row number (0-relative).
368  // nrow=-1 means until the end of the table.
369  // incr is the step in row number.
370  // <group>
371  void putColumn (const String& columnName,
372  Int row,
373  Int nrow,
374  Int incr,
375  const ValueHolder&);
376  void putVarColumn (const String& columnName,
377  Int row,
378  Int nrow,
379  Int incr,
380  const Record& values);
381  // </group>
382 
383  // Put some or all value slices into a column in the table.
384  // <group>
385  void putColumnSlice (const String& columnName,
386  Int row,
387  Int nrow,
388  Int incr,
389  const Vector<Int>& blc,
390  const Vector<Int>& trc,
391  const Vector<Int>& inc,
392  const ValueHolder&);
393  void putColumnSliceIP (const String& columnName,
394  const ValueHolder&,
395  const IPosition& blc,
396  const IPosition& trc,
397  const IPosition& inc,
398  Int row,
399  Int nrow,
400  Int incr);
401  // </group>
402 
403  // Tests if the contents of a cell are defined.
404  // Only a column with variable shaped arrays can have an empty cell.
405  Bool cellContentsDefined (const String& columnName,
406  Int rownr);
407 
408  // Get a value from a column in the table.
409  ValueHolder getCell (const String& columnName,
410  Int row);
411  void getCellVH (const String& columnName,
412  Int row, const ValueHolder& vh);
413 
414  // Get a value slice from a column in the table.
415  // If the inc vector is empty, it defaults to all 1.
416  // <group>
417  ValueHolder getCellSlice (const String& columnName,
418  Int row,
419  const Vector<Int>& blc,
420  const Vector<Int>& trc,
421  const Vector<Int>& inc);
422  ValueHolder getCellSliceIP (const String& columnName,
423  Int row,
424  const IPosition& blc,
425  const IPosition& trc,
426  const IPosition& inc);
427  void getCellSliceVH (const String& columnName,
428  Int row,
429  const Vector<Int>& blc,
430  const Vector<Int>& trc,
431  const Vector<Int>& inc,
432  const ValueHolder& vh);
433  void getCellSliceVHIP (const String& columnName,
434  Int row,
435  const IPosition& blc,
436  const IPosition& trc,
437  const IPosition& inc,
438  const ValueHolder& vh);
439  // </group>
440 
441  // Put a value into a column in the table.
442  void putCell (const String& columnName,
443  const Vector<Int>& rownrs,
444  const ValueHolder&);
445 
446  // Put a value slice into a column in the table.
447  // If the inc vector is empty, it defaults to all 1.
448  // <group>
449  void putCellSlice (const String& columnName,
450  Int row,
451  const Vector<Int>& blc,
452  const Vector<Int>& trc,
453  const Vector<Int>& inc,
454  const ValueHolder&);
455  void putCellSliceIP (const String& columnName,
456  Int row,
457  const ValueHolder&,
458  const IPosition& blc,
459  const IPosition& trc,
460  const IPosition& inc);
461  // </group>
462 
463  // Get the shape of one or more cells in a column as a vector of Strings
464  // containing the shapes as [a,b,c].
465  // If the shape is fixed, a single String is returned.
466  Vector<String> getColumnShapeString (const String& columnName,
467  Int rownr,
468  Int nrow,
469  Int incr,
470  Bool cOrder = False);
471 
472  // Get a table or column keyword value in the table.
473  // If the columnName is empty, a given keyword is a table keyword.
474  // The keyword can be given as a name or a 0-based index.
475  ValueHolder getKeyword (const String& columnName,
476  const String& keywordName,
477  Int keywordIndex);
478 
479  // Get the table or column keyword values in the table.
480  // If the columnName is empty, the table keyword values are returned.
481  Record getKeywordSet (const String& columnName);
482 
483  // Define a table or column keyword in the table.
484  // If the column name is empty, a table keyword is defined.
485  // The keyword can be given as a name or a 0-based number.
486  // The value should be a record containing the value of the keyword.
487  // The value can be any type (including a record).
488  void putKeyword (const String& columnName,
489  const String& keywordName,
490  Int keywordIndex,
491  Bool makeSubRecord,
492  const ValueHolder&);
493 
494  // Define multiple table or column keywords in the table.
495  // If the column name is empty, a table keywords are defined.
496  // The value should be a record containing the values of the keywords.
497  // The values can be any type (including a record).
498  // The field names are the keyword names.
499  void putKeywordSet (const String& columnName,
500  const Record& valueSet);
501 
502  // Remove a table or column keyword from the table.
503  // If the column name is empty, a table keyword is removed.
504  void removeKeyword (const String& columnName,
505  const String& keywordName,
506  Int keywordIndex);
507 
508  // Get the names of all field in a record in the table.
509  // If the column name is empty, the table keywords are used.
510  // If the keyword name is empty, the names of all keywords are returned.
511  // Otherwise the names of all fields in the keyword value are returned.
512  // In that case the value has to be a record.
513  Vector<String> getFieldNames (const String& columnName,
514  const String& keywordName,
515  Int keywordIndex);
516 
517  // Get table name.
518  String tableName();
519 
520  // Get the names of the parts the table consists of (e.g. for a ConcatTable).
521  Vector<String> getPartNames (Bool recursive);
522 
523  // Get #columns of the table.
524  Int ncolumns();
525 
526  // Get #rows of the table.
527  Int nrows();
528 
529  // Get the shape (#columns, #rows) of the table.
530  Vector<Int> shape();
531 
532  // Get the row numbers of the table.
534 
535  // Get all column names in the table.
537 
538  // Return in result if the column contains scalars.
539  Bool isScalarColumn (const String& columnName);
540 
541  // Return the data type of the column as:
542  // Bool, UChar, Short, UShort, Int, UInt, Int64,
543  // Float, Double, Complex, DComplex, String, Table, or unknown.
544  String columnDataType (const String& columnName);
545 
546  // Return the type of array in the column as:
547  // Direct
548  // Undefined
549  // FixedShape
550  // Direct,Undefined
551  // Direct,FixedShape
552  // Undefined,FixedShape
553  // Direct,Undefined,FixedShape
554  // or Error -- unexpected column type
555  String columnArrayType (const String& columnName);
556 
557  // Get the data manager info of the table.
559 
560  // Get the properties of a data manager given by column or data manager name.
561  Record getProperties (const String& name, Bool byColumn);
562 
563  // Set the properties of a data manager given by column or data manager name.
564  void setProperties (const String& name, const Record& properties,
565  Bool byColumn);
566 
567  // Get the table description of the table.
568  // It returns a record containing the description.
569  Record getTableDescription (Bool actual, //# use actual description?
570  Bool cOrder=False);
571 
572  // Create a Record table description from a TableDesc object
573  static Record getTableDesc(const TableDesc & tabdesc, Bool cOrder=False);
574 
575  // Get the column description of a column in the table.
576  // It returns a record containing the description.
577  Record getColumnDescription (const String& columnName,
578  Bool actual, //# use actual description?
579  Bool cOrder=False);
580 
581  // Get ascii format string.
582  String getAsciiFormat() const;
583 
584  // Get result of possible CALC statement.
585  Record getCalcResult() const;
586 
587  // Show the structure of a table.
588  String showStructure (Bool showDataMan=True, Bool showColumns=True,
589  Bool showSubTables=False, Bool sortColumns=False) const;
590 
591  // Return the table object.
592  // <group>
594  { return table_p; }
595  const Table& table() const
596  { return table_p; }
597  // </group>
598 
599  // Get or put the values of all keywords.
600  // Thus convert from TableRecord to/from Record.
601  // Keywords containing a table are converted to a string containing
602  // the table name preceeded by 'Table: '.
603  // <group>
604  static Record getKeyValues (const TableRecord& keySet);
605  static void putKeyValues (TableRecord& keySet, const Record& valueSet);
606  // </group>
607 
608  // Get the lock options from the fields in the record.
609  // If the record or lockoption is invalid, an exception is thrown.
610  static TableLock makeLockOptions (const Record& options);
611 
612  // Turn the string into the endian format option.
613  // An exception is thrown if the string is invalid.
615 
616  // Make hypercolumn definitions for the given hypercolumns.
617  static Bool makeHC (const Record& gdesc, TableDesc& tabdesc,
618  String& message);
619 
620  // Get the value of a keyword.
621  static ValueHolder getKeyValue (const TableRecord& keySet,
622  const RecordFieldId& fieldId);
623 
624  // Put the value of a keyword.
625  static void putKeyValue (TableRecord& keySet,
626  const RecordFieldId& fieldId,
627  const ValueHolder& value);
628 
629  // Make a real table description from a table description in a record.
630  // An exception is thrown if the record table description is invalid.
631  // A record table description is a Record object as returned by
632  // getDesc.
633  static Bool makeTableDesc (const Record& gdesc, TableDesc& tabdesc,
634  String& message);
635 
636  // Add an array column description to the table description.
637  // It is used by the function makeDesc.
638  static Bool addArrayColumnDesc (TableDesc& tableDesc,
639  const String& valueType,
640  const String& columnName,
641  const String& comment,
642  const String& dataManagerType,
643  const String& dataManagerGroup,
644  int options,
645  Int ndim, const Vector<Int>& shape,
646  Bool cOrder,
647  String& message);
648 
649  // Make a record containing the column description.
650  static Record recordColumnDesc (const ColumnDesc&, Bool cOrder);
651 
652  // Make a record containing the description of all hypercolumns.
653  static Record recordHCDesc (const TableDesc& tableDesc);
654 
655  // Calculate the values of a CALC expression and store them in field
656  // 'values' in rec.
657  static void calcValues (Record& rec, const TableExprNode& expr);
658 
659  // Get the type string as used externally (in e.g. glish).
660  static String getTypeStr (DataType);
661 
662  // Optionally reverse the axes.
663  static IPosition fillAxes (const IPosition&, Bool cOrder);
664 
665  // Check if the new shape is still the same.
666  // <br> same: 0=first time; 1=still the same; 2=different
667  static void stillSameShape (Int& same, IPosition& shape,
668  const IPosition& newShape);
669 
670  // Copy the array contents of the record fields to a single array.
671  // This can only be done if the shape is constant.
672  template<typename T>
673  static Array<T> record2Array (const Record& rec)
674  {
675  if (rec.empty()) {
676  return Array<T>();
677  }
678  Array<T> tmp;
679  rec.get (0, tmp);
680  IPosition shp(tmp.shape());
681  shp.append (IPosition(1, rec.size()));
682  Array<T> arr(shp);
683  ArrayIterator<T> iter(arr, tmp.ndim());
684  for (uInt i=0; i<rec.size(); ++i, iter.next()) {
685  rec.get (i, iter.array());
686  }
687  return arr;
688  }
689 
690 private:
691 
692  // Get the column info for toAscii.
693  Bool getColInfo (const String& colName, Bool useBrackets,
694  String& type, String& message);
695 
696  // Print the data in a table cell for toAscii.
697  // <group>
698  void printValueHolder (const ValueHolder& vh, ostream& os,
699  const String& sep, Int prec, Bool useBrackets) const;
700  template<typename T>
701  void printArray (const Array<T>& arr, ostream& os,
702  const String& sep) const;
703  void printArrayValue (ostream& os, Bool v, const String&) const
704  {os << v;}
705  void printArrayValue (ostream& os, Int v, const String&) const
706  {os << v;}
707  void printArrayValue (ostream& os, Int64 v, const String&) const
708  {os << v;}
709  void printArrayValue (ostream& os, Double v, const String&) const
710  {os << v;}
711  void printArrayValue (ostream& os, const DComplex& v, const String&) const
712  {os << v;}
713  void printArrayValue (ostream& os, const String& v, const String&) const
714  {os << '"' << v << '"';}
715  // </group>
716 
717  // Sync table to get correct nr of rows and check the row number.
718  // It returns the nr of table rows.
719  Int64 getRowsCheck (const String& columnName,
720  Int64 row, Int64 nrow, Int64 incr,
721  const String& caller);
722 
723  // Sync table to get correct nr of rows and check the row number.
724  // Fill the slicer with the possibly expanded blc,trc,inc.
725  // It returns the nr of table rows.
726  Int64 getRowsSliceCheck (Slicer& slicer,
727  const String& columnName,
728  Int64 row, Int64 nrow, Int64 incr,
729  const IPosition& blc,
730  const IPosition& trc,
731  const IPosition& inc,
732  const String& caller);
733 
734  // Check if the column name and row numbers are valid.
735  // Return the recalculated nrow so that it does not exceed #rows.
737  const String& colName,
738  Int64 rownr, Int64 nrow, Int64 incr,
739  const String& caller);
740 
741  // Make an empty array (with 1 axis) of the correct datatype.
742  ValueHolder makeEmptyArray (DataType dtype);
743 
744  // Get values from the column.
745  // Nrow<0 means till the end of the column.
746  ValueHolder getValueFromTable (const String& colName,
747  Int rownr, Int nrow, Int incr,
748  Bool isCell);
749  void getValueFromTable (const String& colName,
750  Int rownr, Int nrow, Int incr,
751  Bool isCell, const ValueHolder& vh);
752 
753  // Get value slices from the column.
754  // Nrow<0 means till the end of the column.
755  ValueHolder getValueSliceFromTable(const String& colName,
756  const Slicer& slicer,
757  Int rownr, Int nrow, Int incr,
758  Bool isCell);
759  void getValueSliceFromTable(const String& colName,
760  const Slicer& slicer,
761  Int rownr, Int nrow, Int incr,
762  Bool isCell, const ValueHolder& vh);
763 
764  // Put values into the column.
765  // Nrow<0 means till the end of the column.
766  void putValueInTable (const String& colName,
767  Int rownr, Int nrow, Int incr,
768  Bool isCell, const ValueHolder&);
769 
770  // Put value slices into the column.
771  // Nrow<0 means till the end of the column.
772  void putValueSliceInTable (const String& colName,
773  const Slicer& slicer,
774  Int rownr, Int nrow, Int incr,
775  Bool isCell, const ValueHolder&);
776 
777  // Split the keyname into its separate parts (separator is .).
778  // Check if each part exists and is a subrecord (except last part).
779  // When putting, subrecords are created if undefined and if
780  // makeSubRecord is set.
781  // On return it fills in the fieldid with the latest keyword part.
782  // KeySet is set to the last subrecord.
783  // <group>
784  void findKeyId (RecordFieldId& fieldid,
785  const TableRecord*& keySet,
786  const String& keyname,
787  const String& column);
788  void findKeyId (RecordFieldId& fieldid,
789  TableRecord*& keySet,
790  const String& keyname,
791  const String& column,
792  Bool mustExist, Bool change, Bool makeSubRecord);
793  // </group>
794 
795  // Replace the user-given default value (<0) by the default value
796  // used by Slicer (i.e. by Slicer::MimicSource).
797  void setDefaultForSlicer (IPosition& vec) const;
798 
799  // Synchronize table if readlocking is in effect.
800  // In this way the number of rows is up-to-date.
801  void syncTable (Table& table);
802 
803  //# The data members.
807 };
808 
809 } //# NAMESPACE CASACORE - END
810 
811 #endif
Record tableInfo()
Get the table info of the table.
Bool hasLock(Bool mode)
Determine if the process has a read or write lock on the table.
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
void getCellVH(const String &columnName, Int row, const ValueHolder &vh)
TableProxy()
Default constructor initializes to not open.
A 1-D Specialization of the Array class.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
void putCellSliceIP(const String &columnName, Int row, const ValueHolder &, const IPosition &blc, const IPosition &trc, const IPosition &inc)
int Int
Definition: aipstype.h:50
Bool hasDataChanged()
Determine if data in the table has changed.
std::vector< double > Vector
Definition: ds9context.h:24
void syncTable(Table &table)
Synchronize table if readlocking is in effect.
ValueHolder getCellSlice(const String &columnName, Int row, const Vector< Int > &blc, const Vector< Int > &trc, const Vector< Int > &inc)
Get a value slice from a column in the table.
void printArrayValue(ostream &os, Int v, const String &) const
Definition: TableProxy.h:705
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition: Table.h:192
String getAsciiFormat() const
Get ascii format string.
void removeKeyword(const String &columnName, const String &keywordName, Int keywordIndex)
Remove a table or column keyword from the table.
Bool isScalarColumn(const String &columnName)
Return in result if the column contains scalars.
static TableLock makeLockOptions(const Record &options)
Get the lock options from the fields in the record.
void setProperties(const String &name, const Record &properties, Bool byColumn)
Set the properties of a data manager given by column or data manager name.
void removeRow(const Vector< Int > &rownrs)
Remove rows from the table.
Main interface class to a read/write table.
Definition: Table.h:153
Record getTableDescription(Bool actual, Bool cOrder=False)
Get the table description of the table.
void putColumnSliceIP(const String &columnName, const ValueHolder &, const IPosition &blc, const IPosition &trc, const IPosition &inc, Int row, Int nrow, Int incr)
~TableProxy()
Close the table.
Int checkRowColumn(Table &table, const String &colName, Int64 rownr, Int64 nrow, Int64 incr, const String &caller)
Check if the column name and row numbers are valid.
Table & table()
Return the table object.
Definition: TableProxy.h:593
String endianFormat() const
Get the endian format of the table.
Handle class for a table column expression tree.
Definition: ExprNode.h:155
const Table & table() const
Definition: TableProxy.h:595
Envelope class for the description of a table column.
Definition: ColumnDesc.h:131
void reopenRW()
Reopen the table for read/write.
ValueHolder getColumnSlice(const String &columnName, Int row, Int nrow, Int incr, const Vector< Int > &blc, const Vector< Int > &trc, const Vector< Int > &inc)
Get some or all value slices from a column in the table.
Vector< String > getColumnShapeString(const String &columnName, Int rownr, Int nrow, Int incr, Bool cOrder=False)
Get the shape of one or more cells in a column as a vector of Strings containing the shapes as [a...
void unlock()
Release a lock on the table.
void getCellSliceVH(const String &columnName, Int row, const Vector< Int > &blc, const Vector< Int > &trc, const Vector< Int > &inc, const ValueHolder &vh)
Bool getColInfo(const String &colName, Bool useBrackets, String &type, String &message)
Get the column info for toAscii.
void putColumn(const String &columnName, Int row, Int nrow, Int incr, const ValueHolder &)
Put some or all values into a column in the table.
ValueHolder getColumn(const String &columnName, Int row, Int nrow, Int incr)
Get some or all values from a column in the table.
String tableName()
Get table name.
void putValueSliceInTable(const String &colName, const Slicer &slicer, Int rownr, Int nrow, Int incr, Bool isCell, const ValueHolder &)
Put value slices into the column.
Record getColumnDescription(const String &columnName, Bool actual, Bool cOrder=False)
Get the column description of a column in the table.
void copyRows(TableProxy &out, Int startIn, Int startOut, Int nrow)
Copy rows from one table to another.
Record getCalcResult() const
Get result of possible CALC statement.
virtual casacore::String type() const
Implements RegionShape::type.
Definition: RegionShapes.h:548
bool empty() const
Is the record empty?
ValueHolder getCellSliceIP(const String &columnName, Int row, const IPosition &blc, const IPosition &trc, const IPosition &inc)
Int64 getRowsSliceCheck(Slicer &slicer, const String &columnName, Int64 row, Int64 nrow, Int64 incr, const IPosition &blc, const IPosition &trc, const IPosition &inc, const String &caller)
Sync table to get correct nr of rows and check the row number.
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
High-level interface to tables.
Definition: TableProxy.h:103
void putVarColumn(const String &columnName, Int row, Int nrow, Int incr, const Record &values)
void putValueInTable(const String &colName, Int rownr, Int nrow, Int incr, Bool isCell, const ValueHolder &)
Put values into the column.
Int64 getRowsCheck(const String &columnName, Int64 row, Int64 nrow, Int64 incr, const String &caller)
Sync table to get correct nr of rows and check the row number.
Vector< Int > shape()
Get the shape (#columns, #rows) of the table.
void setMaximumCacheSize(const String &columnName, Int nbytes)
Set the maximum cache size for the given column in the table.
Record getKeywordSet(const String &columnName)
Get the table or column keyword values in the table.
ValueHolder getValueFromTable(const String &colName, Int rownr, Int nrow, Int incr, Bool isCell)
Get values from the column.
Iterate an Array cursor through another Array.
Definition: Array.h:51
void append(const IPosition &other)
Append this IPosition with another one (causing a resize).
void findKeyId(RecordFieldId &fieldid, const TableRecord *&keySet, const String &keyname, const String &column)
Split the keyname into its separate parts (separator is.).
void getColumnSliceVH(const String &columnName, Int row, Int nrow, Int incr, const Vector< Int > &blc, const Vector< Int > &trc, const Vector< Int > &inc, const ValueHolder &vh)
static Bool makeHC(const Record &gdesc, TableDesc &tabdesc, String &message)
Make hypercolumn definitions for the given hypercolumns.
Options options
void resync()
Resync the table.
TableProxy copy(const String &newTableName, Bool toMemoryTable, Bool deepCopy, Bool valueCopy, const String &endianFormat, const Record &dminfo, Bool noRows)
Copy the table (possibly a deep copy).
Record getProperties(const String &name, Bool byColumn)
Get the properties of a data manager given by column or data manager name.
Record lockOptions()
Get the lock options of the table.
The identification of a record field.
Definition: RecordFieldId.h:91
String columnDataType(const String &columnName)
Return the data type of the column as: Bool, UChar, Short, UShort, Int, UInt, Int64, Float, Double, Complex, DComplex, String, Table, or unknown.
Record getDataManagerInfo()
Get the data manager info of the table.
Vector< String > getFieldNames(const String &columnName, const String &keywordName, Int keywordIndex)
Get the names of all field in a record in the table.
uInt ndim() const
The dimensionality of this array.
Definition: ArrayBase.h:94
Record getVarColumn(const String &columnName, Int row, Int nrow, Int incr)
static Bool makeTableDesc(const Record &gdesc, TableDesc &tabdesc, String &message)
Make a real table description from a table description in a record.
static IPosition fillAxes(const IPosition &, Bool cOrder)
Optionally reverse the axes.
void rename(const String &newTableName)
Rename the table.
void putCell(const String &columnName, const Vector< Int > &rownrs, const ValueHolder &)
Put a value into a column in the table.
double Double
Definition: aipstype.h:55
A holder for a value of any basic Casacore data type.
Definition: ValueHolder.h:67
static Record recordHCDesc(const TableDesc &tableDesc)
Make a record containing the description of all hypercolumns.
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
Vector< String > columnNames()
Get all column names in the table.
Bool isWritable() const
Test if a table is writable.
Vector< String > getPartNames(Bool recursive)
Get the names of the parts the table consists of (e.g.
static Array< T > record2Array(const Record &rec)
Copy the array contents of the record fields to a single array.
Definition: TableProxy.h:673
String toAscii(const String &asciiFile, const String &headerFile, const Vector< String > &columns, const String &sep, const Vector< Int > &precision, Bool useBrackets)
Write the table to an ASCII file (approximately the inverse of the from-ASCII-contructor).
void printArrayValue(ostream &os, Bool v, const String &) const
Definition: TableProxy.h:703
void lock(Bool mode, Int nattempts)
Acquire a (read or write) lock on the table.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
static void stillSameShape(Int &same, IPosition &shape, const IPosition &newShape)
Check if the new shape is still the same.
static Record getKeyValues(const TableRecord &keySet)
Get or put the values of all keywords.
void flush(Bool recursive)
Flush the table and optionally all its subtables.
const Bool False
Definition: aipstype.h:44
Class to hold table lock options.
Definition: TableLock.h:65
static ValueHolder getKeyValue(const TableRecord &keySet, const RecordFieldId &fieldId)
Get the value of a keyword.
static Record getTableDesc(const TableDesc &tabdesc, Bool cOrder=False)
Create a Record table description from a TableDesc object.
Int nrows()
Get #rows of the table.
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
static String getTypeStr(DataType)
Get the type string as used externally (in e.g.
Bool cellContentsDefined(const String &columnName, Int rownr)
Tests if the contents of a cell are defined.
void removeColumns(const Vector< String > &columnNames)
Remove one or more columns from the table.
void printArrayValue(ostream &os, const String &v, const String &) const
Definition: TableProxy.h:713
static Record recordColumnDesc(const ColumnDesc &, Bool cOrder)
Make a record containing the column description.
void deleteTable(Bool checkSubTables)
Close and delete the table.
void putCellSlice(const String &columnName, Int row, const Vector< Int > &blc, const Vector< Int > &trc, const Vector< Int > &inc, const ValueHolder &)
Put a value slice into a column in the table.
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:289
static void putKeyValues(TableRecord &keySet, const Record &valueSet)
static Table::EndianFormat makeEndianFormat(const String &endianFormat)
Turn the string into the endian format option.
TableProxy selectRows(const Vector< Int > &rownrs, const String &outName)
Select the given rows from the table and create a new (reference) table.
Bool isReadable() const
Test if a table is readable.
void getColumnSliceVHIP(const String &columnName, const IPosition &blc, const IPosition &trc, const IPosition &inc, Int row, Int nrow, Int incr, const ValueHolder &vh)
Int ncolumns()
Get #columns of the table.
void renameColumn(const String &nameOld, const String &nameNew)
Rename a column in the table.
void get(const RecordFieldId &, Bool &value) const
Get the value of the given field.
ValueHolder getValueSliceFromTable(const String &colName, const Slicer &slicer, Int rownr, Int nrow, Int incr, Bool isCell)
Get value slices from the column.
ValueHolder getCell(const String &columnName, Int row)
Get a value from a column in the table.
TableProxy(const Table &table)
Create the object from an existing table (used by some methods).
Definition: TableProxy.h:111
ValueHolder makeEmptyArray(DataType dtype)
Make an empty array (with 1 axis) of the correct datatype.
void printArrayValue(ostream &os, const DComplex &v, const String &) const
Definition: TableProxy.h:711
ValueHolder getColumnSliceIP(const String &columnName, const IPosition &blc, const IPosition &trc, const IPosition &inc, Int row, Int nrow, Int incr)
void close()
Flush and close the table and all its subtables.
String columnArrayType(const String &columnName)
Return the type of array in the column as: Direct Undefined FixedShape Direct,Undefined Direct...
void setDefaultForSlicer(IPosition &vec) const
Replace the user-given default value (&lt;0) by the default value used by Slicer (i.e.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void putTableInfo(const Record &value)
Put the table info of the table.
void getColumnVH(const String &columnName, Int row, Int nrow, Int incr, const ValueHolder &vh)
void getCellSliceVHIP(const String &columnName, Int row, const IPosition &blc, const IPosition &trc, const IPosition &inc, const ValueHolder &vh)
void printArrayValue(ostream &os, Int64 v, const String &) const
Definition: TableProxy.h:707
TableProxy & operator=(const TableProxy &)
Assignment.
Vector< Int > rowNumbers(TableProxy &other)
Get the row numbers of the table.
Define the structure of a Casacore table.
Definition: TableDesc.h:187
void printValueHolder(const ValueHolder &vh, ostream &os, const String &sep, Int prec, Bool useBrackets) const
Print the data in a table cell for toAscii.
static void putKeyValue(TableRecord &keySet, const RecordFieldId &fieldId, const ValueHolder &value)
Put the value of a keyword.
ValueHolder getKeyword(const String &columnName, const String &keywordName, Int keywordIndex)
Get a table or column keyword value in the table.
void printArray(const Array< T > &arr, ostream &os, const String &sep) const
void putKeyword(const String &columnName, const String &keywordName, Int keywordIndex, Bool makeSubRecord, const ValueHolder &)
Define a table or column keyword in the table.
const Bool True
Definition: aipstype.h:43
String showStructure(Bool showDataMan=True, Bool showColumns=True, Bool showSubTables=False, Bool sortColumns=False) const
Show the structure of a table.
void putColumnSlice(const String &columnName, Int row, Int nrow, Int incr, const Vector< Int > &blc, const Vector< Int > &trc, const Vector< Int > &inc, const ValueHolder &)
Put some or all value slices into a column in the table.
void addRow(Int nrow)
Add rows to the table.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
static void calcValues(Record &rec, const TableExprNode &expr)
Calculate the values of a CALC expression and store them in field &#39;values&#39; in rec.
void putKeywordSet(const String &columnName, const Record &valueSet)
Define multiple table or column keywords in the table.
void addColumns(const Record &tableDesc, const Record &dminfo, Bool addToParent)
Add one or more columns to the table.
unsigned int uInt
Definition: aipstype.h:51
Bool isMultiUsed(Bool checkSubTables)
Determine if the table (and optionally its subtables) are in use in another process.
void printArrayValue(ostream &os, Double v, const String &) const
Definition: TableProxy.h:709
const IPosition & shape() const
The length of each axis.
Definition: ArrayBase.h:121
static Bool addArrayColumnDesc(TableDesc &tableDesc, const String &valueType, const String &columnName, const String &comment, const String &dataManagerType, const String &dataManagerGroup, int options, Int ndim, const Vector< Int > &shape, Bool cOrder, String &message)
Add an array column description to the table description.
void addReadmeLine(const String &line)
Add a line to the TableInfo readme.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42