TableProxy.h

Go to the documentation of this file.
00001 //# TableProxy.h: High-level interface to tables
00002 //# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2005
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef TABLES_TABLEPROXY_H
00029 #define TABLES_TABLEPROXY_H
00030 
00031 
00032 //# Includes
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/tables/Tables/Table.h>
00035 #include <casacore/casa/Containers/Record.h>
00036 #include <casacore/casa/Arrays/Vector.h>
00037 #include <vector>
00038 
00039 
00040 //# Forward Declarations
00041 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00042   class ValueHolder;
00043   class RecordFieldId;
00044   class Table;
00045   class TableLock;
00046   class ColumnDesc;
00047   class TableExprNode;
00048   template<class T> class Vector;
00049   class Slicer;
00050 
00051 
00052 // <summary>
00053 // High-level interface to tables
00054 // </summary>
00055 
00056 // <use visibility=export>
00057 
00058 // <reviewed reviewer="Paul Shannon" date="1995/09/15" tests="ttable.py" demos="">
00059 // </reviewed>
00060 
00061 // <prerequisite>
00062 //# Classes you should understand before using this one.
00063 //   <li> class Table
00064 //   <li> python script table.py
00065 // </prerequisite>
00066 
00067 // <etymology>
00068 // TableProxy is a proxy for access to tables from any script.
00069 // </etymology>
00070 
00071 // <synopsis> 
00072 // TableProxy gives access to most of the functionality in the Table System.
00073 // It is primarily meant to be used in classes that wrap access to it
00074 // from scripting languages (like Glish and Python).
00075 // However, it can also be used directly from other C++ code.
00076 //
00077 // It has functions to open, create, read, write, and query tables.
00078 // Accompying proxy classes give access to other functionality. They are:
00079 // <ul>
00080 //  <li> <linkto class=TableIterProxy>TableIterProxy</linkto> for iteration
00081 //       through a table using class
00082 //       <linkto class=TableIterator>TableIterator</linkto>.
00083 //  <li> <linkto class=TableRowProxy>TableRowProxy</linkto> for access to
00084 //       table rows using class <linkto class=TableRow>TableRow</linkto>.
00085 //  <li> <linkto class=TableIndexProxy>TableIterProxy</linkto> for faster
00086 //       indexed access to using classes
00087 //       <linkto class=ColumnsIndex>ColumnsIndex</linkto> and
00088 //       <linkto class=ColumnsIndexArray>ColumnsIndexArray</linkto>.
00089 // </ul>
00090 //
00091 // TableProxy does not have the TableRecord type in its interface, because
00092 // such a type cannot be handled by e.g. Glish or Python. Instead it
00093 // converts TableRecords to/from Records. If a TableRecord contains a field
00094 // with a Table object, it is represented in the Record as a string
00095 // with the value "Table: NAME" where NAME is the table name.
00096 // </synopsis>
00097 
00098 // <motivation>
00099 // TableProxy is the Tasking-independent high-level table interface.
00100 // Different front-ends (e.g. GlishTableProxy) can be put on top of it.
00101 // </motivation>
00102 
00103 class TableProxy
00104 {
00105 public:
00106   // Default constructor initializes to not open.
00107   // This constructor is only needed for containers.
00108   TableProxy();
00109 
00110   // Create the object from an existing table (used by some methods).
00111   TableProxy (const Table& table)
00112     : table_p (table) {}
00113 
00114   // Open the table with a given name.
00115   TableProxy (const String& tableName,
00116               const Record& lockOptions,
00117               int option);
00118 
00119   // Create a table with given name and description, etc.
00120   TableProxy (const String& tableName,
00121               const Record& lockOptions,
00122               const String& endianFormat,
00123               const String& memType,
00124               int nrow,
00125               const Record& tableDesc,
00126               const Record& dmInfo);
00127 
00128   // Create a table object to concatenate a number of similar tables.
00129   // The keyword set of the first table is take as the keyword set of the
00130   // entire concatenation. However, it can be specified which subtables
00131   // have to be concatenated as well which means that for each subtable name
00132   // the subtable in the keywordsets are concatenated.
00133   // <note>For Boost-Python the constructors must have different nr of arguments.
00134   // Hence some dummy arguments are added.
00135   //</note>
00136   // <group>
00137   TableProxy (const Vector<String>& tableNames,
00138               const Vector<String>& concatenateSubTableNames, 
00139               const Record& lockOptions,
00140               int option);
00141   TableProxy (const std::vector<TableProxy>& tables,
00142               const Vector<String>& concatenateSubTableNames,
00143               int dummy1=0, int dummy2=0, int dummy3=0);
00144   // </group>
00145 
00146   // Create a table object from a table command (as defined in TableGram).
00147   // <br>If a CALC command was given, the resulting values are stored in
00148   // the a record and a null TableProxy object is returned.
00149   // The result can be obtained using getCalcResult.
00150   // <note>
00151   // If the command string contains no GIVING part, the resulting
00152   // table is temporary and its name is blank.
00153   // </note>
00154   TableProxy (const String& command,
00155               const std::vector<TableProxy>& tables);
00156 
00157   // Create a table from an Ascii file.
00158   // It fills a string containing the names and types
00159   // of the columns (in the form COL1=R, COL2=D, ...).
00160   // The string can be obtained using getAsciiFormat.
00161   TableProxy (const String& fileName,
00162               const String& headerName,
00163               const String& tableName,
00164               Bool autoHeader,
00165               const IPosition& autoShape,
00166               const String& separator,
00167               const String& commentMarker,
00168               Int firstLine,
00169               Int lastLine,
00170               const Vector<String>& columnNames = Vector<String>(),
00171               const Vector<String>& dataTypes = Vector<String>());
00172 
00173   // Copy constructor.
00174   TableProxy (const TableProxy&);
00175 
00176   // Close the table.
00177   ~TableProxy();
00178 
00179   // Assignment.
00180   TableProxy& operator= (const TableProxy&);
00181 
00182   // Select the given rows from the table and create a new (reference) table.
00183   // If outName is not empty, the new table is made persistent with that name.
00184   TableProxy selectRows (const Vector<Int>& rownrs,
00185                          const String& outName);
00186 
00187   // Reopen the table for read/write.
00188   void reopenRW();
00189 
00190   // Resync the table.
00191   void resync();
00192 
00193   // Flush the table and optionally all its subtables.
00194   void flush (Bool recursive);
00195 
00196   // Flush and close the table and all its subtables.
00197   void close();
00198 
00199   // Get the endian format of the table.
00200   // It fills the result with value "big" or "little".
00201   String endianFormat() const;
00202 
00203   // Acquire a (read or write) lock on the table.
00204   void lock (Bool mode, Int nattempts);
00205 
00206   // Release a lock on the table.
00207   void unlock();
00208 
00209   // Determine if data in the table has changed.
00210   Bool hasDataChanged();
00211 
00212   // Determine if the process has a read or write lock on the table.
00213   Bool hasLock (Bool mode);
00214 
00215   // Get the lock options of the table.
00216   // It fills the record with the fields option, interval and maxwait.
00217   Record lockOptions();
00218 
00219   // Determine if the table (and optionally its subtables) are in use
00220   // in another process.
00221   Bool isMultiUsed (Bool checkSubTables);
00222 
00223   // Write the table to an ASCII file
00224   // (approximately the inverse of the from-ASCII-contructor).
00225   // If <src>headerFile</src> is empty or equal to <src>asciiFile</src>, the
00226   // headers are written in the same file as the data, otherwise in a separate
00227   // file.
00228   // If no columns are given (or if the first column name is empty), all
00229   // table columns are written. Columns containing records are also printed
00230   // (enclosed in {}), but a warning message is returned.
00231   // <br>Argument <src>sep</src> is used as separator between columns and
00232   // array values. If it is empty, a blank is used.
00233   // <br>For each column the precision can be given. It is only used for
00234   // columns containing floating point numbers. A value <=0 means using the
00235   // default which is 9 for single and 18 for double precision.
00236   // <br>If <src>useBrackets=True</src>, arrays are enclosed in [] (for each
00237   // dimension), so variable shaped arrays can be read back unambiguously.
00238   // The type in the header will be something like D[4,64]. If the column is
00239   // variable shaped, the type is like D[].
00240   // If <src>useBracket=False</src>, arrays are written linearly where a
00241   // shape [4,64] is given in the header like D4,64. If the column is variable
00242   // shaped, the shape of the first cell is used and a warning message is
00243   // returned.
00244   String toAscii (const String& asciiFile, 
00245                   const String& headerFile, 
00246                   const Vector<String>& columns, 
00247                   const String& sep,
00248                   const Vector<Int>& precision,
00249                   Bool useBrackets);
00250 
00251   // Rename the table
00252   void rename (const String& newTableName);
00253 
00254   // Copy the table (possibly a deep copy).
00255   // If noRows=True, an empty table is created.
00256   TableProxy copy (const String& newTableName,
00257                    Bool toMemoryTable,
00258                    Bool deepCopy,
00259                    Bool valueCopy,
00260                    const String& endianFormat,
00261                    const Record& dminfo,
00262                    Bool noRows);
00263 
00264   // Copy rows from one table to another.
00265   // If startOut<0, it is set to the end of the output table.
00266   void copyRows (TableProxy& out,
00267                  Int startIn,
00268                  Int startOut,
00269                  Int nrow);
00270 
00271   // Close and delete the table.
00272   void deleteTable (Bool checkSubTables);
00273 
00274   // Get the table info of the table.
00275   Record tableInfo();
00276 
00277   // Put the table info of the table.
00278   void putTableInfo (const Record& value);
00279 
00280   // Add a line to the TableInfo readme.
00281   void addReadmeLine (const String& line);
00282 
00283   // Test if a table is readable.
00284   Bool isReadable() const;
00285 
00286   // Test if a table is writable.
00287   Bool isWritable() const;
00288 
00289   // Set the maximum cache size for the given column in the table.
00290   void setMaximumCacheSize (const String& columnName,
00291                             Int nbytes);
00292 
00293   // Add one or more columns to the table.
00294   void addColumns (const Record& tableDesc,
00295                    const Record& dminfo,
00296                    Bool addToParent);
00297 
00298   // Rename a column in the table.
00299   void renameColumn (const String& nameOld,
00300                      const String& nameNew);
00301 
00302   // Remove one or more columns from the table.
00303   void removeColumns (const Vector<String>& columnNames);
00304 
00305   // Add rows to the table.
00306   void addRow (Int nrow);
00307 
00308   // Remove rows from the table.
00309   void removeRow (const Vector<Int>& rownrs);
00310 
00311   // Get some or all values from a column in the table.
00312   // row is the starting row number (0-relative).
00313   // nrow=-1 means until the end of the table.
00314   // incr is the step in row number.
00315   // <group>
00316   ValueHolder getColumn (const String& columnName,
00317                          Int row,
00318                          Int nrow,
00319                          Int incr);
00320   void getColumnVH (const String& columnName,
00321                     Int row,
00322                     Int nrow,
00323                     Int incr,
00324                     const ValueHolder& vh);
00325   Record getVarColumn (const String& columnName,
00326                        Int row,
00327                        Int nrow,
00328                        Int incr);
00329   // </group>
00330 
00331   // Get some or all value slices from a column in the table.
00332   // If the inc vector is empty, it defaults to all 1.
00333   // <group>
00334   ValueHolder getColumnSlice (const String& columnName,
00335                               Int row,
00336                               Int nrow,
00337                               Int incr,
00338                               const Vector<Int>& blc,
00339                               const Vector<Int>& trc,
00340                               const Vector<Int>& inc);
00341   ValueHolder getColumnSliceIP (const String& columnName,
00342                                 const IPosition& blc,
00343                                 const IPosition& trc,
00344                                 const IPosition& inc,
00345                                 Int row,
00346                                 Int nrow,
00347                                 Int incr);
00348   void getColumnSliceVH (const String& columnName,
00349                          Int row,
00350                          Int nrow,
00351                          Int incr,
00352                          const Vector<Int>& blc,
00353                          const Vector<Int>& trc,
00354                          const Vector<Int>& inc,
00355                          const ValueHolder& vh);
00356   void getColumnSliceVHIP (const String& columnName,
00357                            const IPosition& blc,
00358                            const IPosition& trc,
00359                            const IPosition& inc,
00360                            Int row,
00361                            Int nrow,
00362                            Int incr,
00363                            const ValueHolder& vh);
00364   // </group>
00365 
00366   // Put some or all values into a column in the table.
00367   // row is the starting row number (0-relative).
00368   // nrow=-1 means until the end of the table.
00369   // incr is the step in row number.
00370   // <group>
00371   void putColumn (const String& columnName,
00372                   Int row,
00373                   Int nrow,
00374                   Int incr,
00375                   const ValueHolder&);
00376   void putVarColumn (const String& columnName,
00377                      Int row,
00378                      Int nrow,
00379                      Int incr,
00380                      const Record& values);
00381   // </group>
00382 
00383   // Put some or all value slices into a column in the table.
00384   // <group>
00385   void putColumnSlice (const String& columnName,
00386                        Int row,
00387                        Int nrow,
00388                        Int incr,
00389                        const Vector<Int>& blc,
00390                        const Vector<Int>& trc,
00391                        const Vector<Int>& inc,
00392                        const ValueHolder&);
00393   void putColumnSliceIP (const String& columnName,
00394                          const ValueHolder&,
00395                          const IPosition& blc,
00396                          const IPosition& trc,
00397                          const IPosition& inc,
00398                          Int row,
00399                          Int nrow,
00400                          Int incr);
00401   // </group>
00402 
00403   // Tests if the contents of a cell are defined.
00404   // Only a column with variable shaped arrays can have an empty cell.
00405   Bool cellContentsDefined (const String& columnName,
00406                             Int rownr);
00407 
00408   // Get a value from a column in the table.
00409   ValueHolder getCell (const String& columnName,
00410                        Int row);
00411   void getCellVH (const String& columnName,
00412                   Int row, const ValueHolder& vh);
00413 
00414   // Get a value slice from a column in the table.
00415   // If the inc vector is empty, it defaults to all 1.
00416   // <group>
00417   ValueHolder getCellSlice (const String& columnName,
00418                             Int row,
00419                             const Vector<Int>& blc,
00420                             const Vector<Int>& trc,
00421                             const Vector<Int>& inc);
00422   ValueHolder getCellSliceIP (const String& columnName,
00423                               Int row,
00424                               const IPosition& blc,
00425                               const IPosition& trc,
00426                               const IPosition& inc);
00427   void getCellSliceVH (const String& columnName,
00428                        Int row,
00429                        const Vector<Int>& blc,
00430                        const Vector<Int>& trc,
00431                        const Vector<Int>& inc,
00432                        const ValueHolder& vh);
00433   void getCellSliceVHIP (const String& columnName,
00434                          Int row,
00435                          const IPosition& blc,
00436                          const IPosition& trc,
00437                          const IPosition& inc,
00438                          const ValueHolder& vh);
00439   // </group>
00440 
00441   // Put a value into a column in the table.
00442   void putCell (const String& columnName,
00443                 const Vector<Int>& rownrs,
00444                 const ValueHolder&);
00445 
00446   // Put a value slice into a column in the table.
00447   // If the inc vector is empty, it defaults to all 1.
00448   // <group>
00449   void putCellSlice (const String& columnName,
00450                      Int row,
00451                      const Vector<Int>& blc,
00452                      const Vector<Int>& trc,
00453                      const Vector<Int>& inc,
00454                      const ValueHolder&);
00455   void putCellSliceIP (const String& columnName,
00456                        Int row,
00457                        const ValueHolder&,
00458                        const IPosition& blc,
00459                        const IPosition& trc,
00460                        const IPosition& inc);
00461   // </group>
00462 
00463   // Get the shape of one or more cells in a column as a vector of Strings
00464   // containing the shapes as [a,b,c].
00465   // If the shape is fixed, a single String is returned.
00466   Vector<String> getColumnShapeString (const String& columnName,
00467                                        Int rownr,
00468                                        Int nrow,
00469                                        Int incr,
00470                                        Bool cOrder = False);
00471 
00472   // Get a table or column keyword value in the table.
00473   // If the columnName is empty, a given keyword is a table keyword.
00474   // The keyword can be given as a name or a 0-based index.
00475   ValueHolder getKeyword (const String& columnName,
00476                           const String& keywordName,
00477                           Int keywordIndex);
00478 
00479   // Get the table or column keyword values in the table.
00480   // If the columnName is empty, the table keyword values are returned.
00481   Record getKeywordSet (const String& columnName);
00482 
00483   // Define a table or column keyword in the table.
00484   // If the column name is empty, a table keyword is defined.
00485   // The keyword can be given as a name or a 0-based number.
00486   // The value should be a record containing the value of the keyword.
00487   // The value can be any type (including a record).
00488   void putKeyword (const String& columnName,
00489                    const String& keywordName,
00490                    Int keywordIndex,
00491                    Bool makeSubRecord,
00492                    const ValueHolder&);
00493 
00494   // Define multiple table or column keywords in the table.
00495   // If the column name is empty, a table keywords are defined.
00496   // The value should be a record containing the values of the keywords.
00497   // The values can be any type (including a record).
00498   // The field names are the keyword names.
00499   void putKeywordSet (const String& columnName,
00500                       const Record& valueSet);
00501 
00502   // Remove a table or column keyword from the table.
00503   // If the column name is empty, a table keyword is removed.
00504   void removeKeyword (const String& columnName,
00505                       const String& keywordName,
00506                       Int keywordIndex);
00507 
00508   // Get the names of all field in a record in the table.
00509   // If the column name is empty, the table keywords are used.
00510   // If the keyword name is empty, the names of all keywords are returned.
00511   // Otherwise the names of all fields in the keyword value are returned.
00512   // In that case the value has to be a record.
00513   Vector<String> getFieldNames (const String& columnName,
00514                                 const String& keywordName,
00515                                 Int keywordIndex);
00516 
00517   // Get table name.
00518   String tableName();
00519 
00520   // Get the names of the parts the table consists of (e.g. for a ConcatTable).
00521   Vector<String> getPartNames (Bool recursive);
00522 
00523   // Get #columns of the table.
00524   Int ncolumns();
00525 
00526   // Get #rows of the table.
00527   Int nrows();
00528 
00529   // Get the shape (#columns, #rows) of the table.
00530   Vector<Int> shape();
00531 
00532   // Get the row numbers of the table.
00533   Vector<Int> rowNumbers (TableProxy& other);
00534 
00535   // Get all column names in the table.
00536   Vector<String> columnNames();
00537 
00538   // Return in result if the column contains scalars.
00539   Bool isScalarColumn (const String& columnName);
00540 
00541   // Return the data type of the column as:
00542   //  Bool, UChar, Short, UShort, Int, UInt, 
00543   //  Float, Double, Complex, DComplex, String, Table, or unknown.
00544   String columnDataType (const String& columnName);
00545 
00546   // Return the type of array in the column as:
00547   //    Direct
00548   //    Undefined
00549   //    FixedShape
00550   //    Direct,Undefined
00551   //    Direct,FixedShape
00552   //    Undefined,FixedShape
00553   //    Direct,Undefined,FixedShape
00554   // or Error -- unexpected column type
00555   String columnArrayType (const String& columnName);
00556 
00557   // Get the data manager info of the table.
00558   Record getDataManagerInfo();
00559 
00560   // Get the properties of a data manager given by column or data manager name.
00561   Record getProperties (const String& name, Bool byColumn);
00562 
00563   // Set the properties of a data manager given by column or data manager name.
00564   void setProperties (const String& name, Bool byColumn,
00565                       const Record& properties);
00566 
00567   // Get the table description of the table.
00568   // It returns a record containing the description.
00569   Record getTableDescription (Bool actual,         //# use actual description?
00570                               Bool cOrder=False);
00571 
00572   // Get the column description of a column in the table.
00573   // It returns a record containing the description.
00574   Record getColumnDescription (const String& columnName,
00575                                Bool actual,        //# use actual description?
00576                                Bool cOrder=False);
00577 
00578   // Get ascii format string.
00579   String getAsciiFormat() const;
00580 
00581   // Get result of possible CALC statement.
00582   Record getCalcResult() const;
00583 
00584   // Show the structure of a table.
00585   String showStructure (Bool showDataMan=True, Bool showColumns=True,
00586                         Bool showSubTables=False, Bool sortColumns=False) const;
00587 
00588   // Return the table object.
00589   // <group>
00590   Table& table()
00591     { return table_p; }
00592   const Table& table() const
00593     { return table_p; }
00594   // </group>
00595 
00596   // Get or put the values of all keywords.
00597   // Thus convert from TableRecord to/from Record.
00598   // Keywords containing a table are converted to a string containing
00599   // the table name preceeded by 'Table: '.
00600   // <group>
00601   static Record getKeyValues (const TableRecord& keySet);
00602   static void putKeyValues (TableRecord& keySet, const Record& valueSet);
00603   // </group>
00604 
00605 
00606 private:
00607   // Get the lock options from the fields in the record.
00608   // If the record or lockoption is invalid, an exception is thrown.
00609   static TableLock makeLockOptions (const Record& options);
00610 
00611   // Turn the string into the endian format option.
00612   // An exception is thrown if the string is invalid.
00613   static Table::EndianFormat makeEndianFormat (const String& endianFormat);
00614 
00615   // Make hypercolumn definitions for the given hypercolumns.
00616   static Bool makeHC (const Record& gdesc, TableDesc& tabdesc,
00617                       String& message);
00618 
00619   // Get the column info for toAscii.
00620   Bool getColInfo (const String& colName, Bool useBrackets,
00621                    String& type, String& message);
00622 
00623   // Print the data in a table cell for toAscii.
00624   // <group>
00625   void printValueHolder (const ValueHolder& vh, ostream& os,
00626                          const String& sep, Int prec, Bool useBrackets) const;
00627   template<typename T>
00628   void printArray (const Array<T>& arr, ostream& os,
00629                    const String& sep) const;
00630   void printArrayValue (ostream& os, Bool v, const String&) const
00631     {os << v;}
00632   void printArrayValue (ostream& os, Int v, const String&) const
00633     {os << v;}
00634   void printArrayValue (ostream& os, Int64 v, const String&) const
00635     {os << v;}
00636   void printArrayValue (ostream& os, Double v, const String&) const
00637     {os << v;}
00638   void printArrayValue (ostream& os, const DComplex& v, const String&) const
00639     {os << v;}
00640   void printArrayValue (ostream& os, const String& v, const String&) const
00641     {os << '"' << v << '"';}
00642   // </group>
00643 
00644   // Sync table to get correct nr of rows and check the row number.
00645   // It returns the nr of table rows.
00646   Int64 getRowsCheck (const String& columnName,
00647                       Int64 row, Int64 nrow, Int64 incr,
00648                       const String& caller);
00649 
00650   // Sync table to get correct nr of rows and check the row number.
00651   // Fill the slicer with the possibly expanded blc,trc,inc.
00652   // It returns the nr of table rows.
00653   Int64 getRowsSliceCheck (Slicer& slicer,
00654                            const String& columnName,
00655                            Int64 row, Int64 nrow, Int64 incr,
00656                            const IPosition& blc,
00657                            const IPosition& trc,
00658                            const IPosition& inc,
00659                            const String& caller);
00660 
00661   // Check if the column name and row numbers are valid.
00662   // Return the recalculated nrow so that it does not exceed #rows.
00663   Int checkRowColumn (Table& table,
00664                       const String& colName,
00665                       Int64 rownr, Int64 nrow, Int64 incr,
00666                       const String& caller);
00667 
00668   // Get values from the column.
00669   // Nrow<0 means till the end of the column.
00670   ValueHolder getValueFromTable (const String& colName, 
00671                                  Int rownr, Int nrow, Int incr,
00672                                  Bool isCell);
00673   void getValueFromTable (const String& colName,
00674                           Int rownr, Int nrow, Int incr,
00675                           Bool isCell, const ValueHolder& vh);
00676 
00677   // Get value slices from the column.
00678   // Nrow<0 means till the end of the column.
00679   ValueHolder getValueSliceFromTable(const String& colName, 
00680                                      const Slicer& slicer,
00681                                      Int rownr, Int nrow, Int incr,
00682                                      Bool isCell);
00683   void getValueSliceFromTable(const String& colName, 
00684                               const Slicer& slicer,
00685                               Int rownr, Int nrow, Int incr,
00686                               Bool isCell, const ValueHolder& vh);
00687 
00688   // Put values into the column.
00689   // Nrow<0 means till the end of the column.
00690   void putValueInTable (const String& colName,
00691                         Int rownr, Int nrow, Int incr,
00692                         Bool isCell, const ValueHolder&);
00693 
00694   // Put value slices into the column.
00695   // Nrow<0 means till the end of the column.
00696   void putValueSliceInTable (const String& colName,
00697                              const Slicer& slicer,
00698                              Int rownr, Int nrow, Int incr,
00699                              Bool isCell, const ValueHolder&);
00700 
00701   // Split the keyname into its separate parts (separator is .).
00702   // Check if each part exists and is a subrecord (except last part).
00703   // When putting, subrecords are created if undefined and if
00704   // makeSubRecord is set.
00705   // On return it fills in the fieldid with the latest keyword part.
00706   // KeySet is set to the last subrecord.
00707   // <group>
00708   void findKeyId (RecordFieldId& fieldid,
00709                   const TableRecord*& keySet,
00710                   const String& keyname,
00711                   const String& column);
00712   void findKeyId (RecordFieldId& fieldid,
00713                   TableRecord*& keySet,
00714                   const String& keyname,
00715                   const String& column,
00716                   Bool mustExist, Bool change, Bool makeSubRecord);
00717   // </group>
00718 
00719   // Get the value of a keyword.
00720   static ValueHolder getKeyValue (const TableRecord& keySet,
00721                                   const RecordFieldId& fieldId);
00722 
00723   // Put the value of a keyword.
00724   static void putKeyValue (TableRecord& keySet,
00725                            const RecordFieldId& fieldId,
00726                            const ValueHolder& value);
00727 
00728   // Make a real table description from a table description in a record.
00729   // An exception is thrown if the record table description is invalid.
00730   // A record table description is a Record object as returned by
00731   // getDesc.
00732   static Bool makeTableDesc (const Record& gdesc, TableDesc& tabdesc,
00733                              String& message);
00734 
00735   // Add an array column description to the table description.
00736   // It is used by the function makeDesc.
00737   static Bool addArrayColumnDesc (TableDesc& tableDesc,
00738                                   const String& valueType,
00739                                   const String& columnName,
00740                                   const String& comment,
00741                                   const String& dataManagerType,
00742                                   const String& dataManagerGroup,
00743                                   int options,
00744                                   Int ndim, const Vector<Int>& shape,
00745                                   Bool cOrder,
00746                                   String& message);
00747 
00748   // Make a record containing the column description.
00749   static Record recordColumnDesc (const ColumnDesc&, Bool cOrder);
00750 
00751   // Make a record containing the description of all hypercolumns.
00752   static Record recordHCDesc (const TableDesc& tableDesc);
00753 
00754   // Replace the user-given default value (<0) by the default value
00755   // used by Slicer (i.e. by Slicer::MimicSource).
00756   void setDefaultForSlicer (IPosition& vec) const;
00757 
00758   // Calculate the values of a CALC expression and store them in field
00759   // 'values' in rec.
00760   static void calcValues (Record& rec, const TableExprNode& expr);
00761 
00762   // Synchronize table if readlocking is in effect.
00763   // In this way the number of rows is up-to-date.
00764   void syncTable (Table& table);
00765 
00766   // Get the type string as used externally (in e.g. glish).
00767   static String getTypeStr (DataType);
00768 
00769   // Optionally reverse the axes.
00770   static IPosition fillAxes (const IPosition&, Bool cOrder);
00771 
00772   // Check if the new shape is still the same.
00773   // <br> same:   0=first time;   1=still the same;   2=different
00774   static void stillSameShape (Int& same, IPosition& shape,
00775                               const IPosition& newShape);
00776 
00777   // Copy the array contents of the record fields to a single array.
00778   // This can only be done if the shape is constant.
00779   template<typename T>
00780   static Array<T> record2Array (const Record& rec)
00781   {
00782     if (rec.empty()) {
00783       return Array<T>();
00784     }
00785     Array<T> tmp;
00786     rec.get (0, tmp);
00787     IPosition shp(tmp.shape());
00788     shp.append (IPosition(1, rec.size()));
00789     Array<T> arr(shp);
00790     ArrayIterator<T> iter(arr, tmp.ndim());
00791     for (uInt i=0; i<rec.size(); ++i, iter.next()) {
00792       rec.get (i, iter.array());
00793     }
00794     return arr;
00795   }
00796 
00797 
00798   //# The data members.
00799   Table  table_p;
00800   String asciiFormat_p;
00801   Record calcResult_p;
00802 };
00803 
00804 } //# NAMESPACE CASACORE - END
00805 
00806 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1