casacore
Loading...
Searching...
No Matches
RowCopier.h
Go to the documentation of this file.
1// # RowCopier.h: RowCopier copies part or all of a row from one table to another.
2// # Copyright (C) 1995,2000
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_ROWCOPIER_H
27#define TABLES_ROWCOPIER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <memory>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37class Table;
38class String;
39class ColumnHolder; // # Only in the .cc file
40
41// <summary>
42// RowCopier copies all or part of a row from one table to another.
43// </summary>
44
45// <use visibility=export>
46
47// <reviewed reviewer="Mark Wieringa" date="21Nov94" tests="tRowCopier">
48// </reviewed>
49
50// <prerequisite>
51// <li> Table
52// </prerequisite>
53
54// <etymology>
55// RowCopier is a class that copies rows from one table to another, hence
56// the name.
57// </etymology>
58
59// <synopsis>
60// The primary organization in a Table is the TableColumn. However, data
61// is often organized primarily by rows, at least initially (e.g. for an
62// on-line system, the data will arrive in chunks that are likely to be
63// individual rows rather than individual columns). RowCopier is used
64// to copy values in a row from all or some of the columns of one table to
65// another table.
66//
67// Some things to keep in mind:
68// <ol>
69// <li> For each column to be copied, the data types and dimensionality
70// must match.
71// <li> The input row number need not be the same as the output row number.
72// <li> The output row number must already exist (i.e. no new rows are created).
73// <li> The output column name need not be the same as the input column name.
74// <li> The output column name and input column name, when specified, must
75// already exist.
76// <li> The output table and each output column must be writable.
77// </ol>
78// </synopsis>
79
80// <example>
81// In the FITS Binary Table extension to Table conversion class, BinTable,
82// the input FITS file is a stream that must be read sequentially, so the
83// input arrives row-by-row. Internally, there is a single row table that
84// is used to hold the values for the current row. To fill a Casacore table
85// with the data from each row, one creates the output table using the
86// table descriptor from the input, single-row table and uses RowCopier to
87// copy the single-row table to the appropriate row of the full table,
88// refilling the single-row table at each step. This is how that looks
89// (leaving out some details not important to this example):
90//
91// Background:
92// singleRowTab is a table constisting of a single row. It is filled
93// from the input FITS classes using the fillRow() member function.
94// The nrows() member function returns the total number of FITS binary
95// table rows and currrow() returns the current row number.
96//
97// <srcblock>
98// // Create an empty Table able to hold all remaining FITS rows, including
99// // the current one and having the same descriptor as singleRowTab
100// SetupNewTable newTab("FullTable", singleRowTab.getDescriptor(),
101// Table:New);
102// Table full(newTab, (nrows() - currrow() + 1));
103// // create the copier to copy all columns
104// RowCopier copier(full, singleRowTab);
105// // loop over all remaining rows
106// // since full was just created, we start filling it at row 0.
107// for (rownr_t outRow = 0, fitsRow = currrow(); fitsRow < nrows();
108// outRow++, fitsRow++) {
109// // copy the only row from currRowTab (row 0) to the outRow of full
110// copier.copy(outRow, 0);
111// // fill the next row of currRowTab
112// fillRow();
113// }
114// </srcblock>
115//
116// This example shows how to copy some of the values from one table to
117// another. This is a contrived example. The input table
118// has columns named "HSource" and "VSource" along with other columns.
119// This example places the values from these columns to columns named
120// "RA (1950)" and "DEC (1950)" in the output table (which also has other
121// columns). Note that each input column must have the same type and
122// dimensionality as the corresponding output column.
123//
124// <srcblock>
125// // construct a vector of the input column names to copy and the
126// // associated output column names
127// Vector<String> inColNames(2), outColNames(2);
128// inColNames(0) = "HSource"; outColNames(0) = "RA (1950)"
129// inColNames(1) = "VSource"; outColNames(1) = "DEC (1950)"
130//
131// // construct the copier
132// RowCopier copier(inTable, outTable, inColNames, outColNames);
133//
134// // Copy a row from in to out, obviously a typical use would do
135// // more than just one row.
136// copier.copy(outRownr, outRownr-1);
137// </srcblock>
138// </example>
139
140// <motivation>
141// See the comments in the synopsis.
142// </motivation>
143
144// <todo asof=$DATE:$">
145// <li> resize should probably happen in powers of 2
146// <li> is throwing exceptions really what we want to happen?
147// </todo>
148
150 public:
151 // This constructs a copier which will copy all columns which have the
152 // same name in both tables from in to out.
153 // An exception is thrown if the columns having the same name in both
154 // tables are not conformant (not the same type and not both scalar of both
155 // array columns)
156 // <thrown>
157 // <li> TableError
158 // </thrown>
159 RowCopier(Table &out, const Table &in);
160
161 // This constructs a copier which will copy innames columns to outnames
162 // columns, outnames and innames must be conformant. Columns are
163 // matched up element-by-element in innames and outnames.
164 // An exception is thrown if an element of innames or outnames is not
165 // present in the corresponding table, if innames and outnames are
166 // not conformant and if the corresponding columns are not conformant
167 // (not the same type and not both scalar or both array columns)
168 // <thrown>
169 // <li> TableError
170 // </thrown>
171 RowCopier(Table &out, const Table &in, const Vector<String> &outNames,
172 const Vector<String> &inNames);
173
175
176 // # The following constructors and operator don't seem to be useful
177 // <group>
178 RowCopier(const RowCopier &other) = delete;
179 RowCopier &operator=(const RowCopier &other) = delete;
180 // </group>
181
182 // The things that actually do the copying when requested.
183 // <group>
184 // Copy different row numbers.
185 Bool copy(rownr_t toRow, rownr_t fromRow);
186 // Copy to and from the same row number
187 Bool copy(rownr_t rownr);
188 // </group>
189
190 private:
191 // The ColumnHolder class exists only in the .cc file, it is what
192 // ultimately does the work.
193 std::shared_ptr<ColumnHolder> columns_p;
194};
195
196inline Bool RowCopier::copy(rownr_t rownr) { return copy(rownr, rownr); }
197
198} // namespace casacore
199
200#endif
RowCopier(Table &out, const Table &in, const Vector< String > &outNames, const Vector< String > &inNames)
This constructs a copier which will copy innames columns to outnames columns, outnames and innames mu...
Bool copy(rownr_t toRow, rownr_t fromRow)
The things that actually do the copying when requested.
RowCopier & operator=(const RowCopier &other)=delete
RowCopier(Table &out, const Table &in)
This constructs a copier which will copy all columns which have the same name in both tables from in ...
std::shared_ptr< ColumnHolder > columns_p
The ColumnHolder class exists only in the.cc file, it is what ultimately does the work.
Definition RowCopier.h:193
RowCopier(const RowCopier &other)=delete
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44