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