casacore
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>
34 #include <casacore/tables/Tables/Table.h>
35 #include <casacore/casa/Containers/Record.h>
36 #include <casacore/casa/Arrays/Vector.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,
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, Bool byColumn,
565  const Record& properties);
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  // Get the column description of a column in the table.
573  // It returns a record containing the description.
574  Record getColumnDescription (const String& columnName,
575  Bool actual, //# use actual description?
576  Bool cOrder=False);
577 
578  // Get ascii format string.
579  String getAsciiFormat() const;
580 
581  // Get result of possible CALC statement.
582  Record getCalcResult() const;
583 
584  // Show the structure of a table.
585  String showStructure (Bool showDataMan=True, Bool showColumns=True,
586  Bool showSubTables=False, Bool sortColumns=False) const;
587 
588  // Return the table object.
589  // <group>
591  { return table_p; }
592  const Table& table() const
593  { return table_p; }
594  // </group>
595 
596  // Get or put the values of all keywords.
597  // Thus convert from TableRecord to/from Record.
598  // Keywords containing a table are converted to a string containing
599  // the table name preceeded by 'Table: '.
600  // <group>
601  static Record getKeyValues (const TableRecord& keySet);
602  static void putKeyValues (TableRecord& keySet, const Record& valueSet);
603  // </group>
604 
605 
606 private:
607  // Get the lock options from the fields in the record.
608  // If the record or lockoption is invalid, an exception is thrown.
609  static TableLock makeLockOptions (const Record& options);
610 
611  // Turn the string into the endian format option.
612  // An exception is thrown if the string is invalid.
613  static Table::EndianFormat makeEndianFormat (const String& endianFormat);
614 
615  // Make hypercolumn definitions for the given hypercolumns.
616  static Bool makeHC (const Record& gdesc, TableDesc& tabdesc,
617  String& message);
618 
619  // Get the column info for toAscii.
620  Bool getColInfo (const String& colName, Bool useBrackets,
621  String& type, String& message);
622 
623  // Print the data in a table cell for toAscii.
624  // <group>
625  void printValueHolder (const ValueHolder& vh, ostream& os,
626  const String& sep, Int prec, Bool useBrackets) const;
627  template<typename T>
628  void printArray (const Array<T>& arr, ostream& os,
629  const String& sep) const;
630  void printArrayValue (ostream& os, Bool v, const String&) const
631  {os << v;}
632  void printArrayValue (ostream& os, Int v, const String&) const
633  {os << v;}
634  void printArrayValue (ostream& os, Int64 v, const String&) const
635  {os << v;}
636  void printArrayValue (ostream& os, Double v, const String&) const
637  {os << v;}
638  void printArrayValue (ostream& os, const DComplex& v, const String&) const
639  {os << v;}
640  void printArrayValue (ostream& os, const String& v, const String&) const
641  {os << '"' << v << '"';}
642  // </group>
643 
644  // Sync table to get correct nr of rows and check the row number.
645  // It returns the nr of table rows.
646  Int64 getRowsCheck (const String& columnName,
647  Int64 row, Int64 nrow, Int64 incr,
648  const String& caller);
649 
650  // Sync table to get correct nr of rows and check the row number.
651  // Fill the slicer with the possibly expanded blc,trc,inc.
652  // It returns the nr of table rows.
653  Int64 getRowsSliceCheck (Slicer& slicer,
654  const String& columnName,
655  Int64 row, Int64 nrow, Int64 incr,
656  const IPosition& blc,
657  const IPosition& trc,
658  const IPosition& inc,
659  const String& caller);
660 
661  // Check if the column name and row numbers are valid.
662  // Return the recalculated nrow so that it does not exceed #rows.
664  const String& colName,
665  Int64 rownr, Int64 nrow, Int64 incr,
666  const String& caller);
667 
668  // Get values from the column.
669  // Nrow<0 means till the end of the column.
670  ValueHolder getValueFromTable (const String& colName,
671  Int rownr, Int nrow, Int incr,
672  Bool isCell);
673  void getValueFromTable (const String& colName,
674  Int rownr, Int nrow, Int incr,
675  Bool isCell, const ValueHolder& vh);
676 
677  // Get value slices from the column.
678  // Nrow<0 means till the end of the column.
679  ValueHolder getValueSliceFromTable(const String& colName,
680  const Slicer& slicer,
681  Int rownr, Int nrow, Int incr,
682  Bool isCell);
683  void getValueSliceFromTable(const String& colName,
684  const Slicer& slicer,
685  Int rownr, Int nrow, Int incr,
686  Bool isCell, const ValueHolder& vh);
687 
688  // Put values into the column.
689  // Nrow<0 means till the end of the column.
690  void putValueInTable (const String& colName,
691  Int rownr, Int nrow, Int incr,
692  Bool isCell, const ValueHolder&);
693 
694  // Put value slices into the column.
695  // Nrow<0 means till the end of the column.
696  void putValueSliceInTable (const String& colName,
697  const Slicer& slicer,
698  Int rownr, Int nrow, Int incr,
699  Bool isCell, const ValueHolder&);
700 
701  // Split the keyname into its separate parts (separator is .).
702  // Check if each part exists and is a subrecord (except last part).
703  // When putting, subrecords are created if undefined and if
704  // makeSubRecord is set.
705  // On return it fills in the fieldid with the latest keyword part.
706  // KeySet is set to the last subrecord.
707  // <group>
708  void findKeyId (RecordFieldId& fieldid,
709  const TableRecord*& keySet,
710  const String& keyname,
711  const String& column);
712  void findKeyId (RecordFieldId& fieldid,
713  TableRecord*& keySet,
714  const String& keyname,
715  const String& column,
716  Bool mustExist, Bool change, Bool makeSubRecord);
717  // </group>
718 
719  // Get the value of a keyword.
720  static ValueHolder getKeyValue (const TableRecord& keySet,
721  const RecordFieldId& fieldId);
722 
723  // Put the value of a keyword.
724  static void putKeyValue (TableRecord& keySet,
725  const RecordFieldId& fieldId,
726  const ValueHolder& value);
727 
728  // Make a real table description from a table description in a record.
729  // An exception is thrown if the record table description is invalid.
730  // A record table description is a Record object as returned by
731  // getDesc.
732  static Bool makeTableDesc (const Record& gdesc, TableDesc& tabdesc,
733  String& message);
734 
735  // Add an array column description to the table description.
736  // It is used by the function makeDesc.
737  static Bool addArrayColumnDesc (TableDesc& tableDesc,
738  const String& valueType,
739  const String& columnName,
740  const String& comment,
741  const String& dataManagerType,
742  const String& dataManagerGroup,
743  int options,
744  Int ndim, const Vector<Int>& shape,
745  Bool cOrder,
746  String& message);
747 
748  // Make a record containing the column description.
749  static Record recordColumnDesc (const ColumnDesc&, Bool cOrder);
750 
751  // Make a record containing the description of all hypercolumns.
752  static Record recordHCDesc (const TableDesc& tableDesc);
753 
754  // Replace the user-given default value (<0) by the default value
755  // used by Slicer (i.e. by Slicer::MimicSource).
756  void setDefaultForSlicer (IPosition& vec) const;
757 
758  // Calculate the values of a CALC expression and store them in field
759  // 'values' in rec.
760  static void calcValues (Record& rec, const TableExprNode& expr);
761 
762  // Synchronize table if readlocking is in effect.
763  // In this way the number of rows is up-to-date.
764  void syncTable (Table& table);
765 
766  // Get the type string as used externally (in e.g. glish).
767  static String getTypeStr (DataType);
768 
769  // Optionally reverse the axes.
770  static IPosition fillAxes (const IPosition&, Bool cOrder);
771 
772  // Check if the new shape is still the same.
773  // <br> same: 0=first time; 1=still the same; 2=different
774  static void stillSameShape (Int& same, IPosition& shape,
775  const IPosition& newShape);
776 
777  // Copy the array contents of the record fields to a single array.
778  // This can only be done if the shape is constant.
779  template<typename T>
780  static Array<T> record2Array (const Record& rec)
781  {
782  if (rec.empty()) {
783  return Array<T>();
784  }
785  Array<T> tmp;
786  rec.get (0, tmp);
787  IPosition shp(tmp.shape());
788  shp.append (IPosition(1, rec.size()));
789  Array<T> arr(shp);
790  ArrayIterator<T> iter(arr, tmp.ndim());
791  for (uInt i=0; i<rec.size(); ++i, iter.next()) {
792  rec.get (i, iter.array());
793  }
794  return arr;
795  }
796 
797 
798  //# The data members.
802 };
803 
804 } //# NAMESPACE CASACORE - END
805 
806 #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<T> 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.
Definition: ArrayIO.h:45
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:47
Bool hasDataChanged()
Determine if data in the table has changed.
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:632
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition: Table.h:188
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 removeRow(const Vector< Int > &rownrs)
Remove rows from the table.
Main interface class to a read/write table.
Definition: Table.h:149
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:590
String endianFormat() const
Get the endian format of the table.
Handle class for a table column expression tree.
Definition: ExprNode.h:578
const Table & table() const
Definition: TableProxy.h:592
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.
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.
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:54
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.
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, 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:52
A holder for a value of any basic Casacore data type.
Definition: ValueHolder.h:67
void setProperties(const String &name, Bool byColumn, const Record &properties)
Set the properties of a data manager given by column or data manager name.
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:780
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:630
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:181
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
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:41
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.
Int nrows()
Get #rows of the table.
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
template <class T, class U> class vector;
Definition: Array.h:169
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:640
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:275
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
void printArrayValue(ostream &os, const DComplex &v, const String &) const
Definition: TableProxy.h:638
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 (<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:634
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:186
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:40
String showStructure(Bool showDataMan=True, Bool showColumns=True, Bool showSubTables=False, Bool sortColumns=False) const
Show the structure of a table.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
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:48
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:636
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.