casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TableCopy.h
Go to the documentation of this file.
1 //# TableCopy.h: Class with static functions for copying a table
2 //# Copyright (C) 2001,2002,2003
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_TABLECOPY_H
29 #define TABLES_TABLECOPY_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 // <summary>
42 // Class with static functions for copying a table.
43 // </summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
48 // </reviewed>
49 
50 // <prerequisite>
51 //# Classes you should understand before using this one.
52 // <li> Table
53 // </prerequisite>
54 
55 // <synopsis>
56 // TableCopy is a class for making a deep copy of a table.
57 // The table can be a PlainTable or a RefTable.
58 // It contains the following static functions:
59 // <ol>
60 // <li> <src>makeEmptyTable</src> creates a new table using the
61 // description and storage managers of the input table.
62 // By default TiledDataStMan (which is more or less obsolete) will
63 // be replaced by TiledShapeStMan.
64 // By default the new table contains the same number of rows as the
65 // existing table.
66 // <li> <src>copyRows</src> copies the data of one to another table.
67 // It is possible to specify where to start in the input and output.
68 // <li> <src>CopyInfo</src> copies the table info data.
69 // <li> <src>copySubTables</src> copies all the subtables in table and
70 // column keywords. It is done recursively.
71 // </ol>
72 // </synopsis>
73 
74 //# <todo asof="$DATE:$">
75 //# </todo>
76 
77 
78 class TableCopy
79 {
80 public:
81  // Make an (empty) table with the given description.
82  // If the description contains no columns, the description of the input
83  // table is used, so it has the same keywords and columns as the input one.
84  // The data managers can be given in the dataManagerInfo record.
85  // If it is empty, the info is taken from the input table.
86  // <br>Non-writable storage managers (like LofarStMan) are by default replaced
87  // by StandardStMan. If <src>replaceMSM</src> is set, MemoryStMan is also
88  // replaced by StandardStMan.
89  // <br>By default, the TiledDataStMan will be replaced by the TiledShapeStMan.
90  // <br>By default, the new table has the same nr of rows as the input table.
91  // If <src>noRows=True</src> is given, it does not contain any row.
92  static Table makeEmptyTable (const String& newName,
93  const Record& dataManagerInfo,
94  const Table& tab,
95  Table::TableOption option,
96  Table::EndianFormat endianFormat,
97  Bool replaceTSM = True,
98  Bool noRows = False,
99  const StorageOption& = StorageOption());
100 
101  // Make an (empty) memory table with the same layout as the input one.
102  // It has the same keywords and columns as the input one.
103  // By default, the new table has the same nr of rows as the input table.
104  // If <src>noRows=True</src> is given, it does not contain any row.
105  static Table makeEmptyMemoryTable (const String& newName,
106  const Table& tab,
107  Bool noRows = False);
108 
109  // Copy rows from the input to the output.
110  // By default all rows will be copied starting at row 0 of the output.
111  // Rows will be added to the output table as needed.
112  // The output table will by default be flushed after the rows are copied.
113  // <br> All columns in Table <src>out</src> will be filled from the
114  // column with the same name in table <src>in</src>. In principle only
115  // stored columns will be filled; however if the output table has only
116  // one column, it can also be a virtual one.
117  // <group>
118  static void copyRows (Table& out, const Table& in, Bool flush=True)
119  { copyRows (out, in, 0, 0, in.nrow(), flush); }
120  static void copyRows (Table& out, const Table& in,
121  uInt startout, uInt startin, uInt nrrow,
122  Bool flush=True);
123  // </group>
124 
125  // Copy the table info block from input to output table.
126  static void copyInfo (Table& out, const Table& in);
127 
128  // Copy all subtables (in table and column keywords) from input to
129  // output table.
130  // Subtables of which the keyword name matches an omit value are skipped.
131  // Optionally the row contents are not copied.
132  static void copySubTables (Table& out, const Table& in, Bool noRows=False,
133  const Block<String>& omit=Block<String>());
134 
135  // Copy the subtables in the given keywordset to the output keywordset
136  // in the table with the given name.
137  // Subtables of which the keyword name matches an omit value are skipped.
138  // Optionally the row contents are not copied.
139  static void copySubTables (TableRecord& outKeys,
140  const TableRecord& inKeys,
141  const String& outName,
142  Table::TableType outType,
143  const Table& in,
144  Bool noRows=False,
145  const Block<String>& omit=Block<String>());
146 
147  // Clone a column in the from table to a new column in the to table.
148  // The new column gets the same table description and data manager as the
149  // from column. It has to get a unique data manager name. If not given,
150  // it is the new column name.
151  static void cloneColumn (const Table& fromTable,
152  const String& fromColumn,
153  Table& toTable,
154  const String& newColumn,
155  const String& dataManagerName = String());
156  // Cloning as above, but the data type is set to the template parameter.
157  template<typename T>
158  static void cloneColumnTyped (const Table& fromTable,
159  const String& fromColumn,
160  Table& toTable,
161  const String& newColumn,
162  const String& dataManagerName = String());
163 
164  // Copy the data from one column to another.
165  // It can be used after function cloneColumn to populate the new column.
166  // Note that the data types of the column do not need to match; data type
167  // promotion is done if needed.
168  // <br>The <src>preserveTileShape</src> argument tells if the original
169  // tile shape is kept if a tiled data manager is used. If False, the
170  // default tile shape of the data manager is used.
171  // <note role=tip>
172  // Note that a TaQL command can be used to fill a column in any way.
173  // For example, fill toColumn with the real part of a complex fromColumn:
174  // <srcblock>
175  // Block<Table> tables(2);
176  // tables[0] = toTable;
177  // tables[1] = fromTable;
178  // tableCommand ("update $1 set toColumn=real(t2.fromColumn) from $2 t2",
179  // tables);
180  // </srcblock>
181  // When copying a column in a straightforward way, the TaQL way is about 25%
182  // slower than using the function <src>copyColumnData</src>.
183  // </note>
184  static void copyColumnData (const Table& fromTable,
185  const String& fromColumn,
186  Table& toTable,
187  const String& toColumn,
188  Bool preserveTileShape=True);
189 
190  // Fill the table column with the given array.
191  // The template type must match the column data type.
192  template<typename T>
193  static void fillArrayColumn (Table& table, const String& column,
194  const Array<T>& value);
195 
196  // Fill the table column with the given value.
197  // If the column contains arrays, the arrays are filled with the value.
198  // The template type must match the column data type.
199  template<typename T>
200  static void fillColumnData (Table& table, const String& column,
201  const T& value);
202  // Specialization to handle a C-string correctly.
203  static void fillColumnData (Table& table, const String& column,
204  const char* value)
205  { fillColumnData (table, column, String(value)); }
206 
207  // Fill the table column with the given value.
208  // The column must contain arrays. The arrays get the shape of the
209  // corresponding row in the fromColumn in the fromTable.
210  // It can be used after function cloneColumn to initialize the new column.
211  // The template type must match the column data type.
212  template<typename T>
213  static void fillColumnData (Table& table, const String& column,
214  const T& value,
215  const Table& fromTable, const String& fromColumn,
216  Bool preserveTileShape=True);
217  // Specialization to handle a C-string correctly.
218  static void fillColumnData (Table& table, const String& column,
219  const char* value,
220  const Table& fromTable, const String& fromColumn,
221  Bool preserveTileShape=True)
222  { fillColumnData (table, column, String(value), fromTable, fromColumn,
223  preserveTileShape); }
224 
225 
226  // Replace TiledDataStMan by TiledShapeStMan in the DataManagerInfo record.
227  // Since TiledShapeStMan does not support ID columns, they are
228  // adjusted as well in tabDesc and dminfo.
229  static void adjustTSM (TableDesc& tabDesc, Record& dminfo)
230  { DataManInfo::adjustTSM (tabDesc, dminfo); }
231 
232  // Replace non-writable storage managers by StandardStMan. This is needed
233  // for special storage managers like LofarStMan.
234  static Record adjustStMan (const Record& dminfo)
235  { return DataManInfo::adjustStMan (dminfo, "StandardStMan"); }
236 
237  // Set the data managers of the given column(s) to the given tiled storage
238  // manager (normally TiledShapeStMan or TiledColumnStMan).
239  // The columns are combined in a single storage manager, so the function
240  // has to be called multiple times if, say, one per column is needed.
241  // The columns already having a tiled storage manager are not changed.
242  static void setTiledStMan (Record& dminfo, const Vector<String>& columns,
243  const String& dmType, const String& dmName,
244  const IPosition& defaultTileShape)
245  { DataManInfo::setTiledStMan (dminfo, columns, dmType, dmName,
246  defaultTileShape); }
247 
248  // Remove the columns from the dminfo record and return a vector with the
249  // names of the columns actually removed.
250  // The columns having a data manager matching <src>keepType</src> are not
251  // removed. Matching means that the beginning of the data manager name
252  // have to match, so "Tiled" matches all tiled storagemanagers.
254  const Vector<String>& columns,
255  const String& keepType= String())
256  { return DataManInfo::removeDminfoColumns (dminfo, columns, keepType); }
257 
258  // Adjust the data manager types and groups and the
259  // hypercolumn definitions to the actual data manager info.
260  static void adjustDesc (TableDesc& tabDesc, const Record& dminfo)
261  { DataManInfo::adjustDesc (tabDesc, dminfo); }
262 
263 private:
264  static void doCloneColumn (const Table& fromTable, const String& fromColumn,
265  Table& toTable, const ColumnDesc& newColumn,
266  const String& dataManagerName);
267 };
268 
269 
270 
271 } //# NAMESPACE CASACORE - END
272 
273 #ifndef CASACORE_NO_AUTO_TEMPLATES
274 #include <casacore/tables/Tables/TableCopy.tcc>
275 #endif //# CASACORE_NO_AUTO_TEMPLATES
276 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
static void adjustDesc(TableDesc &tabDesc, const Record &dminfo)
Adjust the data manager types and groups and the hypercolumn definitions to the actual data manager i...
Definition: TableCopy.h:260
A 1-D Specialization of the Array class.
static Table makeEmptyTable(const String &newName, const Record &dataManagerInfo, const Table &tab, Table::TableOption option, Table::EndianFormat endianFormat, Bool replaceTSM=True, Bool noRows=False, const StorageOption &=StorageOption())
Make an (empty) table with the given description.
static void adjustDesc(TableDesc &tabDesc, const Record &dminfo)
Adjust the data manager types and groups and the hypercolumn definitions to the actual data manager i...
static void fillArrayColumn(Table &table, const String &column, const Array< T > &value)
Fill the table column with the given array.
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition: Table.h:192
static void copyRows(Table &out, const Table &in, Bool flush=True)
Copy rows from the input to the output.
Definition: TableCopy.h:118
Main interface class to a read/write table.
Definition: Table.h:153
Envelope class for the description of a table column.
Definition: ColumnDesc.h:131
static void doCloneColumn(const Table &fromTable, const String &fromColumn, Table &toTable, const ColumnDesc &newColumn, const String &dataManagerName)
static void copyInfo(Table &out, const Table &in)
Copy the table info block from input to output table.
static void cloneColumn(const Table &fromTable, const String &fromColumn, Table &toTable, const String &newColumn, const String &dataManagerName=String())
Clone a column in the from table to a new column in the to table.
static Table makeEmptyMemoryTable(const String &newName, const Table &tab, Bool noRows=False)
Make an (empty) memory table with the same layout as the input one.
static void cloneColumnTyped(const Table &fromTable, const String &fromColumn, Table &toTable, const String &newColumn, const String &dataManagerName=String())
Cloning as above, but the data type is set to the template parameter.
static Record adjustStMan(const Record &dminfo, const String &dmType, Bool replaceMSM=True)
Replace non-writable storage managers by the given storage manager (usually StandardStMan or Incremen...
Options defining how table files are organized.
Definition: StorageOption.h:76
static void setTiledStMan(Record &dminfo, const Vector< String > &columns, const String &dmType, const String &dmName, const IPosition &defaultTileShape)
Set the data managers of the given column(s) to the given tiled storage manager (normally TiledShapeS...
static Vector< String > removeDminfoColumns(Record &dminfo, const Vector< String > &columns, const String &keepType=String())
Remove the columns from the dminfo record and return a vector with the names of the columns actually ...
static void setTiledStMan(Record &dminfo, const Vector< String > &columns, const String &dmType, const String &dmName, const IPosition &defaultTileShape)
Set the data managers of the given column(s) to the given tiled storage manager (normally TiledShapeS...
Definition: TableCopy.h:242
static Vector< String > removeDminfoColumns(Record &dminfo, const Vector< String > &columns, const String &keepType=String())
Remove the columns from the dminfo record and return a vector with the names of the columns actually ...
Definition: TableCopy.h:253
Class with static functions for copying a table.
Definition: TableCopy.h:78
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
uInt nrow() const
Get the number of rows.
Definition: Table.h:1201
const Bool False
Definition: aipstype.h:44
static void fillColumnData(Table &table, const String &column, const char *value)
Specialization to handle a C-string correctly.
Definition: TableCopy.h:203
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
static void fillColumnData(Table &table, const String &column, const T &value)
Fill the table column with the given value.
simple 1-D array
static void adjustTSM(TableDesc &tabDesc, Record &dminfo)
Replace TiledDataStMan by TiledShapeStMan in the DataManagerInfo record.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static Record adjustStMan(const Record &dminfo)
Replace non-writable storage managers by StandardStMan.
Definition: TableCopy.h:234
Define the structure of a Casacore table.
Definition: TableDesc.h:187
static void copyColumnData(const Table &fromTable, const String &fromColumn, Table &toTable, const String &toColumn, Bool preserveTileShape=True)
Copy the data from one column to another.
TableType
Define the possible table types.
Definition: Table.h:184
static void adjustTSM(TableDesc &tabDesc, Record &dminfo)
Replace TiledDataStMan by TiledShapeStMan in the DataManagerInfo record.
Definition: TableCopy.h:229
const Bool True
Definition: aipstype.h:43
static void copySubTables(Table &out, const Table &in, Bool noRows=False, const Block< String > &omit=Block< String >())
Copy all subtables (in table and column keywords) from input to output table.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51
TableOption
Define the possible options how a table can be opened.
Definition: Table.h:168
static void fillColumnData(Table &table, const String &column, const char *value, const Table &fromTable, const String &fromColumn, Bool preserveTileShape=True)
Specialization to handle a C-string correctly.
Definition: TableCopy.h:218
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42