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