casacore
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>
34 #include <casacore/tables/DataMan/DataManInfo.h>
35 #include <casacore/tables/Tables/Table.h>
36 #include <casacore/casa/Arrays/Vector.h>
37 #include <casacore/casa/Containers/Record.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 
100  // Make an (empty) memory table with the same layout as the input one.
101  // It has the same keywords and columns as the input one.
102  // By default, the new table has the same nr of rows as the input table.
103  // If <src>noRows=True</src> is given, it does not contain any row.
104  static Table makeEmptyMemoryTable (const String& newName,
105  const Table& tab,
106  Bool noRows = False);
107 
108  // Copy rows from the input to the output.
109  // By default all rows will be copied starting at row 0 of the output.
110  // Rows will be added to the output table as needed.
111  // The output table will by default be flushed after the rows are copied.
112  // <br> All columns in Table <src>out</src> will be filled from the
113  // column with the same name in table <src>in</src>. In principle only
114  // stored columns will be filled; however if the output table has only
115  // one column, it can also be a virtual one.
116  // <group>
117  static void copyRows (Table& out, const Table& in, Bool flush=True)
118  { copyRows (out, in, 0, 0, in.nrow(), flush); }
119  static void copyRows (Table& out, const Table& in,
120  uInt startout, uInt startin, uInt nrrow,
121  Bool flush=True);
122  // </group>
123 
124  // Copy the table info block from input to output table.
125  static void copyInfo (Table& out, const Table& in);
126 
127  // Copy all subtables (in table and column keywords) from input to
128  // output table.
129  // Subtables of which the keyword name matches an omit value are skipped.
130  // Optionally the row contents are not copied.
131  static void copySubTables (Table& out, const Table& in, Bool noRows=False,
132  const Block<String>& omit=Block<String>());
133 
134  // Copy the subtables in the given keywordset to the output keywordset
135  // in the table with the given name.
136  // Subtables of which the keyword name matches an omit value are skipped.
137  // Optionally the row contents are not copied.
138  static void copySubTables (TableRecord& outKeys,
139  const TableRecord& inKeys,
140  const String& outName,
141  Table::TableType outType,
142  const Table& in,
143  Bool noRows=False,
144  const Block<String>& omit=Block<String>());
145 
146  // Replace TiledDataStMan by TiledShapeStMan in the DataManagerInfo record.
147  // Since TiledShapeStMan does not support ID columns, they are
148  // adjusted as well in tabDesc and dminfo.
149  static void adjustTSM (TableDesc& tabDesc, Record& dminfo)
150  { DataManInfo::adjustTSM (tabDesc, dminfo); }
151 
152  // Replace non-writable storage managers by StandardStMan. This is needed
153  // for special storage managers like LofarStMan.
154  static Record adjustStMan (const Record& dminfo)
155  { return DataManInfo::adjustStMan (dminfo, "StandardStMan"); }
156 
157  // Set the data managers of the given column(s) to the given tiled storage
158  // manager (normally TiledShapeStMan or TiledColumnStMan).
159  // The columns are combined in a single storage manager, so the function
160  // has to be called multiple times if, say, one per column is needed.
161  // The columns already having a tiled storage manager are not changed.
162  static void setTiledStMan (Record& dminfo, const Vector<String>& columns,
163  const String& dmType, const String& dmName,
164  const IPosition& defaultTileShape)
165  { DataManInfo::setTiledStMan (dminfo, columns, dmType, dmName,
166  defaultTileShape); }
167 
168  // Remove the columns from the dminfo record and return a vector with the
169  // names of the columns actually removed.
170  // The columns having a data manager matching <src>keepType</src> are not
171  // removed. Matching means that the beginning of the data manager name
172  // have to match, so "Tiled" matches all tiled storagemanagers.
174  const Vector<String>& columns,
175  const String& keepType= String())
176  { return DataManInfo::removeDminfoColumns (dminfo, columns, keepType); }
177 
178  // Adjust the data manager types and groups and the
179  // hypercolumn definitions to the actual data manager info.
180  static void adjustDesc (TableDesc& tabDesc, const Record& dminfo)
181  { DataManInfo::adjustDesc (tabDesc, dminfo); }
182 };
183 
184 
185 
186 } //# NAMESPACE CASACORE - END
187 
188 #endif
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
static Table makeEmptyTable(const String &newName, const Record &dataManagerInfo, const Table &tab, Table::TableOption option, Table::EndianFormat endianFormat, Bool replaceTSM=True, Bool noRows=False)
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...
Definition: TableCopy.h:180
A 1-D Specialization of the Array class.
Definition: ArrayIO.h:45
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...
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition: Table.h:188
static void copyRows(Table &out, const Table &in, Bool flush=True)
Copy rows from the input to the output.
Definition: TableCopy.h:117
Main interface class to a read/write table.
Definition: Table.h:149
static void copyInfo(Table &out, const Table &in)
Copy the table info block from input to output 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 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...
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:162
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:173
Class with static functions for copying a table.
Definition: TableCopy.h:78
A hierarchical collection of named fields of various types.
Definition: Record.h:181
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
uInt nrow() const
Get the number of rows.
Definition: Table.h:1147
const Bool False
Definition: aipstype.h:41
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
simple 1-D array
Definition: ArrayIO.h:47
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:154
Define the structure of a Casacore table.
Definition: TableDesc.h:186
TableType
Define the possible table types.
Definition: Table.h:180
static void adjustTSM(TableDesc &tabDesc, Record &dminfo)
Replace TiledDataStMan by TiledShapeStMan in the DataManagerInfo record.
Definition: TableCopy.h:149
const Bool True
Definition: aipstype.h:40
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.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:48
TableOption
Define the possible options how a table can be opened.
Definition: Table.h:164