casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef TABLES_TABLECOPY_H
27#define TABLES_TABLECOPY_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/DataMan/DataManInfo.h>
33#include <casacore/tables/Tables/Table.h>
34#include <casacore/casa/Arrays/Vector.h>
35#include <casacore/casa/Containers/Record.h>
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39// <summary>
40// Class with static functions for copying a table.
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
46// </reviewed>
47
48// <prerequisite>
49//# Classes you should understand before using this one.
50// <li> Table
51// </prerequisite>
52
53// <synopsis>
54// TableCopy is a class for making a deep copy of a table.
55// The table can be a PlainTable or a RefTable.
56// It contains the following static functions:
57// <ol>
58// <li> <src>makeEmptyTable</src> creates a new table using the
59// description and storage managers of the input table.
60// By default TiledDataStMan (which is more or less obsolete) will
61// be replaced by TiledShapeStMan.
62// By default the new table contains the same number of rows as the
63// existing table.
64// <li> <src>copyRows</src> copies the data of one to another table.
65// It is possible to specify where to start in the input and output.
66// <li> <src>CopyInfo</src> copies the table info data.
67// <li> <src>copySubTables</src> copies all the subtables in table and
68// column keywords. It is done recursively.
69// </ol>
70// </synopsis>
71
72//# <todo asof="$DATE:$">
73//# </todo>
74
75
77{
78public:
79 // Make an (empty) table with the given description.
80 // If the description contains no columns, the description of the input
81 // table is used, so it has the same keywords and columns as the input one.
82 // The data managers can be given in the dataManagerInfo record.
83 // If it is empty, the info is taken from the input table.
84 // <br>Non-writable storage managers (like LofarStMan) are by default replaced
85 // by StandardStMan. If <src>replaceMSM</src> is set, MemoryStMan is also
86 // replaced by StandardStMan.
87 // <br>By default, the TiledDataStMan will be replaced by the TiledShapeStMan.
88 // <br>By default, the new table has the same nr of rows as the input table.
89 // If <src>noRows=True</src> is given, it does not contain any row.
90 static Table makeEmptyTable (const String& newName,
91 const Record& dataManagerInfo,
92 const Table& tab,
93 Table::TableOption option,
94 Table::EndianFormat endianFormat,
95 Bool replaceTSM = True,
96 Bool noRows = False,
97 const StorageOption& = StorageOption());
98
99 // Make an (empty) memory table with the same layout as the input one.
100 // It has the same keywords and columns as the input one.
101 // By default, the new table has the same nr of rows as the input table.
102 // If <src>noRows=True</src> is given, it does not contain any row.
103 static Table makeEmptyMemoryTable (const String& newName,
104 const Table& tab,
105 Bool noRows = False);
106
107 // Copy rows from the input to the output.
108 // By default all rows will be copied starting at row 0 of the output.
109 // Rows will be added to the output table as needed.
110 // The output table will by default be flushed after the rows are copied.
111 // <br> All columns in Table <src>out</src> will be filled from the
112 // column with the same name in table <src>in</src>. In principle only
113 // stored columns will be filled; however if the output table has only
114 // one column, it can also be a virtual one.
115 // <group>
116 static void copyRows (Table& out, const Table& in, Bool flush=True)
117 { copyRows (out, in, 0, 0, in.nrow(), flush); }
118 static void copyRows (Table& out, const Table& in,
119 rownr_t startout, rownr_t startin, rownr_t nrrow,
120 Bool flush=True);
121 // </group>
122
123 // Copy the table info block from input to output table.
124 static void copyInfo (Table& out, const Table& in);
125
126 // Copy all subtables (in table and column keywords) from input to
127 // output table.
128 // Subtables of which the keyword name matches an omit value are skipped.
129 // Optionally the row contents are not copied.
130 static void copySubTables (Table& out, const Table& in, Bool noRows=False,
131 const Block<String>& omit=Block<String>());
132
133 // Copy the subtables in the given keywordset to the output keywordset
134 // in the table with the given name.
135 // Subtables of which the keyword name matches an omit value are skipped.
136 // Optionally the row contents are not copied.
137 static void copySubTables (TableRecord& outKeys,
138 const TableRecord& inKeys,
139 const String& outName,
140 Table::TableType outType,
141 const Table& in,
142 Bool noRows=False,
143 const Block<String>& omit=Block<String>());
144
145 // Clone a column in the from table to a new column in the to table.
146 // The new column gets the same table description as the source column.
147 // If newdmInfo is empty, the same data manager type as the source column is used.
148 // It has to have a unique data manager name. If not given, it is the new column name.
149 static void cloneColumn (const Table& fromTable,
150 const String& fromColumn,
151 Table& toTable,
152 const String& newColumn,
153 const String& dataManagerName = String(),
154 const Record& newdmInfo = Record());
155
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 const Record& newdmInfo = Record());
164
165 // Copy the data from one column to another.
166 // It can be used after function cloneColumn to populate the new column.
167 // Note that the data types of the column do not need to match; data type
168 // promotion is done if needed.
169 // <br>The <src>preserveTileShape</src> argument tells if the original
170 // tile shape is kept if a tiled data manager is used. If False, the
171 // default tile shape of the data manager is used.
172 // <note role=tip>
173 // Note that a TaQL command can be used to fill a column in any way.
174 // For example, fill toColumn with the real part of a complex fromColumn:
175 // <srcblock>
176 // Block<Table> tables(2);
177 // tables[0] = toTable;
178 // tables[1] = fromTable;
179 // tableCommand ("update $1 set toColumn=real(t2.fromColumn) from $2 t2",
180 // tables);
181 // </srcblock>
182 // When copying a column in a straightforward way, the TaQL way is about 25%
183 // slower than using the function <src>copyColumnData</src>.
184 // </note>
185 static void copyColumnData (const Table& fromTable,
186 const String& fromColumn,
187 Table& toTable,
188 const String& toColumn,
189 Bool preserveTileShape=True);
190
191 // Fill the table column with the given array.
192 // The template type must match the column data type.
193 template<typename T>
194 static void fillArrayColumn (Table& table, const String& column,
195 const Array<T>& value);
196
197 // Fill the table column with the given value.
198 // If the column contains arrays, the arrays are filled with the value.
199 // The template type must match the column data type.
200 template<typename T>
201 static void fillColumnData (Table& table, const String& column,
202 const T& value);
203 // Specialization to handle a C-string correctly.
204 static void fillColumnData (Table& table, const String& column,
205 const char* value)
206 { fillColumnData (table, column, String(value)); }
207
208 // Fill the table column with the given value.
209 // The column must contain arrays. The arrays get the shape of the
210 // corresponding row in the fromColumn in the fromTable.
211 // It can be used after function cloneColumn to initialize the new column.
212 // The template type must match the column data type.
213 template<typename T>
214 static void fillColumnData (Table& table, const String& column,
215 const T& value,
216 const Table& fromTable, const String& fromColumn,
217 Bool preserveTileShape=True);
218 // Specialization to handle a C-string correctly.
219 static void fillColumnData (Table& table, const String& column,
220 const char* value,
221 const Table& fromTable, const String& fromColumn,
222 Bool preserveTileShape=True)
223 { fillColumnData (table, column, String(value), fromTable, fromColumn,
224 preserveTileShape); }
225
226private:
227 static void doCloneColumn (const Table& fromTable, const String& fromColumn,
228 Table& toTable, const ColumnDesc& newColumn,
229 const String& dataManagerName,
230 const Record& newdmInfo);
231};
232
233
234
235} //# NAMESPACE CASACORE - END
236
237#ifndef CASACORE_NO_AUTO_TEMPLATES
238#include <casacore/tables/Tables/TableCopy.tcc>
239#endif //# CASACORE_NO_AUTO_TEMPLATES
240#endif
simple 1-D array
Definition Block.h:198
String: the storage and methods of handling collections of characters.
Definition String.h:223
static void fillColumnData(Table &table, const String &column, const T &value, const Table &fromTable, const String &fromColumn, Bool preserveTileShape=True)
Fill the table column with the given value.
static void fillArrayColumn(Table &table, const String &column, const Array< T > &value)
Fill the table column with the given array.
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.
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 cloneColumn(const Table &fromTable, const String &fromColumn, Table &toTable, const String &newColumn, const String &dataManagerName=String(), const Record &newdmInfo=Record())
Clone a column in the from table to a new column in the to table.
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 cloneColumnTyped(const Table &fromTable, const String &fromColumn, Table &toTable, const String &newColumn, const String &dataManagerName=String(), const Record &newdmInfo=Record())
Cloning as above, but the data type is set to the template parameter.
static void copySubTables(TableRecord &outKeys, const TableRecord &inKeys, const String &outName, Table::TableType outType, const Table &in, Bool noRows=False, const Block< String > &omit=Block< String >())
Copy the subtables in the given keywordset to the output keywordset in the table with the given name.
static void copyInfo(Table &out, const Table &in)
Copy the table info block from input to output table.
static void fillColumnData(Table &table, const String &column, const T &value)
Fill the table column with the given value.
static void copyRows(Table &out, const Table &in, rownr_t startout, rownr_t startin, rownr_t nrrow, Bool flush=True)
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.
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:219
static void fillColumnData(Table &table, const String &column, const char *value)
Specialization to handle a C-string correctly.
Definition TableCopy.h:204
static void doCloneColumn(const Table &fromTable, const String &fromColumn, Table &toTable, const ColumnDesc &newColumn, const String &dataManagerName, const Record &newdmInfo)
static void copyRows(Table &out, const Table &in, Bool flush=True)
Copy rows from the input to the output.
Definition TableCopy.h:116
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition Table.h:195
TableOption
Define the possible options how a table can be opened.
Definition Table.h:171
rownr_t nrow() const
Get the number of rows.
Definition Table.h:1176
TableType
Define the possible table types.
Definition Table.h:187
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
const Bool True
Definition aipstype.h:41
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44