casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TableCopy.h
Go to the documentation of this file.
00001 //# TableCopy.h: Class with static functions for copying a table
00002 //# Copyright (C) 2001,2002,2003
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: TableCopy.h 21285 2012-11-14 15:36:59Z gervandiepen $
00027 
00028 #ifndef TABLES_TABLECOPY_H
00029 #define TABLES_TABLECOPY_H
00030 
00031 
00032 //# Includes
00033 #include <tables/Tables/DataManInfo.h>
00034 #include <tables/Tables/Table.h>
00035 #include <casa/Arrays/Vector.h>
00036 #include <casa/Containers/Record.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 // <summary>
00041 // Class with static functions for copying a table.
00042 // </summary>
00043 
00044 // <use visibility=export>
00045 
00046 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //# Classes you should understand before using this one.
00051 //   <li> Table
00052 // </prerequisite>
00053 
00054 // <synopsis> 
00055 // TableCopy is a class for making a deep copy of a table.
00056 // The table can be a PlainTable or a RefTable.
00057 // It contains the following static functions:
00058 // <ol>
00059 //  <li> <src>makeEmptyTable</src> creates a new table using the
00060 //       description and storage managers of the input table.
00061 //       By default TiledDataStMan (which is more or less obsolete) will
00062 //       be replaced by TiledShapeStMan.
00063 //       By default the new table contains the same number of rows as the
00064 //       existing table.
00065 //  <li> <src>copyRows</src> copies the data of one to another table.
00066 //       It is possible to specify where to start in the input and output.
00067 //  <li> <src>CopyInfo</src> copies the table info data.
00068 //  <li> <src>copySubTables</src> copies all the subtables in table and
00069 //       column keywords. It is done recursively.
00070 // </ol>
00071 // </synopsis> 
00072 
00073 //# <todo asof="$DATE:$">
00074 //# </todo>
00075 
00076 
00077 class TableCopy
00078 {
00079 public:
00080   // Make an (empty) table with the given description.
00081   // If the description contains no columns, the description of the input
00082   // table is used, so it has the same keywords and columns as the input one.
00083   // The data managers can be given in the dataManagerInfo record.
00084   // If it is empty, the info is taken from the input table.
00085   // <br>Non-writable storage managers (like LofarStMan) are by default replaced
00086   // by StandardStMan. If <src>replaceMSM</src> is set, MemoryStMan is also
00087   // replaced by StandardStMan.
00088   // <br>By default, the TiledDataStMan will be replaced by the TiledShapeStMan.
00089   // <br>By default, the new table has the same nr of rows as the input table.
00090   // If <src>noRows=True</src> is given, it does not contain any row.
00091   static Table makeEmptyTable (const String& newName,
00092                                const Record& dataManagerInfo,
00093                                const Table& tab,
00094                                Table::TableOption option,
00095                                Table::EndianFormat endianFormat,
00096                                Bool replaceTSM = True,
00097                                Bool noRows = False);
00098 
00099   // Make an (empty) memory table with the same layout as the input one.
00100   // It has the same keywords and columns as the input one.
00101   // By default, the new table has the same nr of rows as the input table.
00102   // If <src>noRows=True</src> is given, it does not contain any row.
00103   static Table makeEmptyMemoryTable (const String& newName,
00104                                      const Table& tab,
00105                                      Bool noRows = False);
00106 
00107   // Copy rows from the input to the output.
00108   // By default all rows will be copied starting at row 0 of the output.
00109   // Rows will be added to the output table as needed.
00110   // The output table will by default be flushed after the rows are copied.
00111   // <br> All columns in Table <src>out</src> will be filled from the
00112   // column with the same name in table <src>in</src>. In principle only
00113   // stored columns will be filled; however if the output table has only
00114   // one column, it can also be a virtual one.
00115   // <group>
00116   static void copyRows (Table& out, const Table& in, Bool flush=True)
00117     { copyRows (out, in, 0, 0, in.nrow(), flush); }
00118   static void copyRows (Table& out, const Table& in,
00119                         uInt startout, uInt startin, uInt nrrow,
00120                         Bool flush=True);
00121   // </group>
00122 
00123   // Copy the table info block from input to output table.
00124   static void copyInfo (Table& out, const Table& in);
00125 
00126   // Copy all subtables (in table and column keywords) from input to
00127   // output table.
00128   // Subtables of which the keyword name matches an omit value are skipped.
00129   // Optionally the row contents are not copied.
00130   static void copySubTables (Table& out, const Table& in, Bool noRows=False,
00131                              const Block<String>& omit=Block<String>());
00132 
00133   // Copy the subtables in the given keywordset to the output keywordset
00134   // in the table with the given name.
00135   // Subtables of which the keyword name matches an omit value are skipped.
00136   // Optionally the row contents are not copied.
00137   static void copySubTables (TableRecord& outKeys,
00138                              const TableRecord& inKeys,
00139                              const String& outName,
00140                              Table::TableType outType,
00141                              const Table& in,
00142                              Bool noRows=False,
00143                              const Block<String>& omit=Block<String>());
00144 
00145   // Replace TiledDataStMan by TiledShapeStMan in the DataManagerInfo record.
00146   // Since TiledShapeStMan does not support ID columns, they are
00147   // adjusted as well in tabDesc and dminfo.
00148   static void adjustTSM (TableDesc& tabDesc, Record& dminfo)
00149     { DataManInfo::adjustTSM (tabDesc, dminfo); }
00150 
00151   // Replace non-writable storage managers by StandardStMan. This is needed
00152   // for special storage managers like LofarStMan.
00153   static Record adjustStMan (const Record& dminfo)
00154     { return DataManInfo::adjustStMan (dminfo, "StandardStMan"); }
00155 
00156   // Set the data managers of the given column(s) to the given tiled storage
00157   // manager (normally TiledShapeStMan or TiledColumnStMan).
00158   // The columns are combined in a single storage manager, so the function
00159   // has to be called multiple times if, say, one per column is needed.
00160   // The columns already having a tiled storage manager are not changed.
00161   static void setTiledStMan (Record& dminfo, const Vector<String>& columns,
00162                              const String& dmType, const String& dmName,
00163                              const IPosition& defaultTileShape)
00164     { DataManInfo::setTiledStMan (dminfo, columns, dmType, dmName,
00165                                   defaultTileShape); }
00166 
00167   // Remove the columns from the dminfo record and return a vector with the
00168   // names of the columns actually removed.
00169   // The columns having a data manager matching <src>keepType</src> are not
00170   // removed. Matching means that the beginning of the data manager name
00171   // have to match, so "Tiled" matches all tiled storagemanagers.
00172   static Vector<String> removeDminfoColumns (Record& dminfo,
00173                                              const Vector<String>& columns,
00174                                              const String& keepType= String())
00175     { return DataManInfo::removeDminfoColumns (dminfo, columns, keepType); }
00176 
00177   // Adjust the data manager types and groups and the
00178   // hypercolumn definitions to the actual data manager info.
00179   static void adjustDesc (TableDesc& tabDesc, const Record& dminfo)
00180     { DataManInfo::adjustDesc (tabDesc, dminfo); }
00181 };
00182 
00183 
00184 
00185 } //# NAMESPACE CASA - END
00186 
00187 #endif