casacore
Loading...
Searching...
No Matches
ArrayQuantColumn.h
Go to the documentation of this file.
1// # ArrayQuantColumn.h: Access to an Array Quantum Column in a table.
2// # Copyright (C) 1997,1998,1999,2000,2001
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 MEASURES_ARRAYQUANTCOLUMN_H
27#define MEASURES_ARRAYQUANTCOLUMN_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/Vector.h>
32#include <casacore/casa/Quanta/Quantum.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37class Table;
38template <class T>
39class ArrayColumn;
40template <class T>
41class ScalarColumn;
42class String;
43
44// <summary>
45// Provides read/write access to Array Quantum columns in Tables.
46// </summary>
47
48// <use visibility=export>
49
50// <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableQuantum.cc">
51// </reviewed>
52
53// <prerequisite>
54// # Classes you should understand before using this one.
55// <li> <linkto class=TableQuantumDesc>TableQuantumDesc</linkto>
56// <li> <linkto class=Table>Table</linkto>
57// <li> <linkto class=ArrayColumn>ArrayColumn</linkto>
58// <li> <linkto class=Quantum>Quantum</linkto>
59// </prerequisite>
60
61// <synopsis>
62// The ArrayQuantColumn class provides read/write access to quanta
63// stored in a array Quantum Table column. The Quantum column should
64// already exist in the table and would have been defined by means of a
65// <linkto class=TableQuantumDesc>TableQuantumDesc object</linkto>.
66// In addition,
67// for a ArrayQuantColumn object to be useful the column should
68// contain Quanta.
69//
70// The ArrayQuantColumn class is the array version
71// of the <linkto class=ScalarQuantColumn>ScalarQuantColumn</linkto>
72// class.
73//
74// <h3>Quantum Units</h3></A>
75// Quanta retrieved from the column will normally have the Unit that was
76// specified when the Quantum column was defined.
77// However, it is possible to override the default column Unit by
78// supplying a Unit in the ArrayQuantColumn constructor.
79// When constructed in this fashion the retrieved Quanta will by
80// default be retrieved in this unit, i.e. they will by default be
81// converted to this unit.
82// <br>
83// By giving a unit (as a Unit or Quantum object) to a get function,
84// the data can be retrieved in another unit than the default.
85// </synopsis>
86
87// <example>
88// (See <linkto class=TableQuantumDesc>TableQuantumDesc</linkto> class
89// for an example of how to define a Quantum column).
90// <srcblock>
91// // Create the column object with default units "deg".
92// // It gets the quantum array from row 0 and prints it to stdout.
93// ArrayQuantColumn<Double> roaqCol(qtab, "ArrQuantDouble", "deg");
94// cout << roaqCol(0) << endl;
95// // This retrieves the same array with units converted to "m/s".
96// cout << roaqCol(0, "m/s") << endl;
97// </srcblock>
98// </example>
99
100// <motivation>
101// Add support for Quanta in the Tables system.
102// </motivation>
103
104// <thrown>
105// <li>TableInvOper if the Table column is null.
106// </thrown>
107
108// <todo asof="$DATE:$">
109// # A List of bugs, limitations, extensions or planned refinements.
110// <li> Support for fixed unit per array element (e.g. for positions)
111// In that case #units should match first array dimension.
112// <li> Functions like getColumn, getSlice.
113// <li> get as <src>Quantum<Array<T>></src>.
114// <li> optimize when converting when units are the same for entire array.
115// </todo>
116
117template <class T>
119 public:
120 // The default constructor creates a null object. It is useful for creating
121 // arrays of ArrayQuantColumn objects. Attempting to use a null object
122 // will produce a segmentation fault so care needs to be taken to
123 // initialize the objects by using the attach() member before any attempt
124 // is made to use the object. The isNull() member can be used to test
125 // if a ArrayQuantColumn object is null.
127
128 // Create the ArrayQuantColumn from the supplied table and column name.
129 // The default unit for data retrieved is the unit in which they were stored.
130 ArrayQuantColumn(const Table& tab, const String& columnName);
131
132 // Create the ArrayQuantColumn from the supplied table and column name.
133 // The default unit for data retrieved is the given unit (the data is
134 // converted as needed).
135 // <group>
136 ArrayQuantColumn(const Table& tab, const String& columnName, const Unit&);
137 ArrayQuantColumn(const Table& tab, const String& columnName, const Vector<Unit>&);
138 // </group>
139
140 // Copy constructor (copy semantics).
142
144
145 // Make this object reference the column in "that".
147
148 // Attach a column to the object. Optionally supply a default unit.
149 // which has the same meaning as the constructor unit argument.
150 // <group name="attach">
151 void attach(const Table& tab, const String& columnName);
152 void attach(const Table& tab, const String& columnName, const Unit&);
153 void attach(const Table& tab, const String& columnName, const Vector<Unit>&);
154 // </group>
155
156 // Get the quantum array in the specified row.
157 // If resize is True the resulting array is resized if its shape
158 // is not correct. Otherwise a "conformance exception" is thrown
159 // if the array is not empty and its shape mismatches.
160 // <group name="get">
161 void get(rownr_t rownr, Array<Quantum<T>>& q, Bool resize = False) const;
162 // Get the quantum array in the specified row. Each quantum is
163 // converted to the given unit.
164 void get(rownr_t rownr, Array<Quantum<T>>& q, const Unit&, Bool resize = False) const;
165 // Get the quantum array in the specified row. Each quantum is
166 // converted to the given units.
167 void get(rownr_t rownr, Array<Quantum<T>>& q, const Vector<Unit>&, Bool resize = False) const;
168 // Get the quantum array in the specified row. Each quantum is
169 // converted to the unit in other.
170 void get(rownr_t rownr, Array<Quantum<T>>& q, const Quantum<T>& other, Bool resize = False) const;
171 // </group>
172
173 // Return the quantum array stored in the specified row.
174 // <group>
176 // Return the quantum array stored in the specified row, converted
177 // to the given unit.
179 // Return the quantum array stored in the specified row, converted
180 // to the given units.
182 // Return the quantum array stored in the specified row, converted
183 // to the unit in other.
184 Array<Quantum<T>> operator()(rownr_t rownr, const Quantum<T>& other) const;
185 // </group>
186
187 // Put an array of quanta into the specified row of the table.
188 // If the column supports variable units, the units are stored as well.
189 // Otherwise the quanta are converted to the column's units.
190 void put(rownr_t rownr, const Array<Quantum<T>>& q);
191
192 // Test whether the Quantum column has variable units
194
195 // Returns the column's units as a vector of strings.
196 // An empty vector is returned if the column has no fixed units.
198
199 // Test if the object is null.
200 Bool isNull() const { return (itsDataCol == 0); }
201
202 // Throw an exception if the object is null.
203 void throwIfNull() const;
204
205 protected:
206 // # Quantum column's units (if units not variable)
208
209 // Get access to itsUnitsCol.
210 // <group>
213 // </group>
214
215 private:
216 // # The underlying data column stores the quantum column's data.
218 // # Variable units array column if applicable.
220 // # Variable units scalar column if applicable.
222 // # Units to retrieve the data in.
224 // # Convert unit when getting data?
226
227 // Initialize the ArrayQuantColumn from the specified table and column.
228 void init(const Table& tab, const String& columnName);
229
230 // Deletes allocated memory etc. Called by ~tor and any member which needs
231 // to reallocate data.
232 void cleanUp();
233
234 // Get the data without possible conversion.
235 void getData(rownr_t rownr, Array<Quantum<T>>& q, Bool resize) const;
236
237 // Assignment makes no sense in a read only class.
238 // Declaring this operator private makes it unusable.
240
241 // Comparison is not defined, since its semantics are unclear.
243};
244
245} // namespace casacore
246
247// # Make old name ROArrayMeasColumn still available.
248#define ROArrayQuantColumn ArrayQuantColumn
249
250#ifndef CASACORE_NO_AUTO_TEMPLATES
251#include <casacore/measures/TableMeasures/ArrayQuantColumn.tcc>
252#endif // # CASACORE_NO_AUTO_TEMPLATES
253#endif
ArrayQuantColumn(const Table &tab, const String &columnName)
Create the ArrayQuantColumn from the supplied table and column name.
ArrayQuantColumn()
The default constructor creates a null object.
Bool isUnitVariable() const
Test whether the Quantum column has variable units.
Bool isNull() const
Test if the object is null.
ArrayColumn< String > * itsArrUnitsCol
void getData(rownr_t rownr, Array< Quantum< T > > &q, Bool resize) const
Get the data without possible conversion.
void get(rownr_t rownr, Array< Quantum< T > > &q, const Quantum< T > &other, Bool resize=False) const
Get the quantum array in the specified row.
Vector< String > getUnits() const
Returns the column's units as a vector of strings.
Array< Quantum< T > > operator()(rownr_t rownr, const Quantum< T > &other) const
Return the quantum array stored in the specified row, converted to the unit in other.
void get(rownr_t rownr, Array< Quantum< T > > &q, Bool resize=False) const
Get the quantum array in the specified row.
void attach(const Table &tab, const String &columnName)
Attach a column to the object.
Bool operator==(const ArrayQuantColumn< T > &that)
Comparison is not defined, since its semantics are unclear.
ArrayQuantColumn & operator=(const ArrayQuantColumn< T > &that)
Assignment makes no sense in a read only class.
void get(rownr_t rownr, Array< Quantum< T > > &q, const Unit &, Bool resize=False) const
Get the quantum array in the specified row.
void put(rownr_t rownr, const Array< Quantum< T > > &q)
Put an array of quanta into the specified row of the table.
void get(rownr_t rownr, Array< Quantum< T > > &q, const Vector< Unit > &, Bool resize=False) const
Get the quantum array in the specified row.
void cleanUp()
Deletes allocated memory etc.
void attach(const Table &tab, const String &columnName, const Vector< Unit > &)
void throwIfNull() const
Throw an exception if the object is null.
ArrayColumn< T > * itsDataCol
Array< Quantum< T > > operator()(rownr_t rownr, const Unit &) const
Return the quantum array stored in the specified row, converted to the given unit.
const ScalarColumn< String > * scaUnitsCol() const
void reference(const ArrayQuantColumn< T > &that)
Make this object reference the column in "that".
Array< Quantum< T > > operator()(rownr_t rownr, const Vector< Unit > &) const
Return the quantum array stored in the specified row, converted to the given units.
ArrayQuantColumn(const Table &tab, const String &columnName, const Unit &)
Create the ArrayQuantColumn from the supplied table and column name.
void init(const Table &tab, const String &columnName)
Initialize the ArrayQuantColumn from the specified table and column.
void attach(const Table &tab, const String &columnName, const Unit &)
ScalarColumn< String > * itsScaUnitsCol
ArrayQuantColumn(const Table &tab, const String &columnName, const Vector< Unit > &)
Array< Quantum< T > > operator()(rownr_t rownr) const
Return the quantum array stored in the specified row.
ArrayQuantColumn(const ArrayQuantColumn< T > &that)
Copy constructor (copy semantics).
const ArrayColumn< String > * arrUnitsCol() const
Get access to itsUnitsCol.
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
const Bool False
Definition aipstype.h:42
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const T & get() const
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44