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