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> class ArrayColumn;
39template <class T> class ScalarColumn;
40class String;
41
42
43// <summary>
44// Provides read/write access to Array Quantum columns in Tables.
45// </summary>
46
47// <use visibility=export>
48
49// <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableQuantum.cc">
50// </reviewed>
51
52// <prerequisite>
53//# Classes you should understand before using this one.
54// <li> <linkto class=TableQuantumDesc>TableQuantumDesc</linkto>
55// <li> <linkto class=Table>Table</linkto>
56// <li> <linkto class=ArrayColumn>ArrayColumn</linkto>
57// <li> <linkto class=Quantum>Quantum</linkto>
58// </prerequisite>
59
60// <synopsis>
61// The ArrayQuantColumn class provides read/write access to quanta
62// stored in a array Quantum Table column. The Quantum column should
63// already exist in the table and would have been defined by means of a
64// <linkto class=TableQuantumDesc>TableQuantumDesc object</linkto>.
65// In addition,
66// for a ArrayQuantColumn object to be useful the column should
67// contain Quanta.
68//
69// The ArrayQuantColumn class is the array version
70// of the <linkto class=ScalarQuantColumn>ScalarQuantColumn</linkto>
71// class.
72//
73// <h3>Quantum Units</h3></A>
74// Quanta retrieved from the column will normally have the Unit that was
75// specified when the Quantum column was defined.
76// However, it is possible to override the default column Unit by
77// supplying a Unit in the ArrayQuantColumn constructor.
78// When constructed in this fashion the retrieved Quanta will by
79// default be retrieved in this unit, i.e. they will by default be
80// converted to this unit.
81// <br>
82// By giving a unit (as a Unit or Quantum object) to a get function,
83// the data can be retrieved in another unit than the default.
84// </synopsis>
85
86// <example>
87// (See <linkto class=TableQuantumDesc>TableQuantumDesc</linkto> class
88// for an example of how to define a Quantum column).
89// <srcblock>
90// // Create the column object with default units "deg".
91// // It gets the quantum array from row 0 and prints it to stdout.
92// ArrayQuantColumn<Double> roaqCol(qtab, "ArrQuantDouble", "deg");
93// cout << roaqCol(0) << endl;
94// // This retrieves the same array with units converted to "m/s".
95// cout << roaqCol(0, "m/s") << endl;
96// </srcblock>
97// </example>
98
99// <motivation>
100// Add support for Quanta in the Tables system.
101// </motivation>
102
103// <thrown>
104// <li>TableInvOper if the Table column is null.
105// </thrown>
106
107// <todo asof="$DATE:$">
108//# A List of bugs, limitations, extensions or planned refinements.
109// <li> Support for fixed unit per array element (e.g. for positions)
110// In that case #units should match first array dimension.
111// <li> Functions like getColumn, getSlice.
112// <li> get as <src>Quantum<Array<T>></src>.
113// <li> optimize when converting when units are the same for entire array.
114// </todo>
115
116
117template<class T> class ArrayQuantColumn
118{
119public:
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,
137 const Unit&);
138 ArrayQuantColumn (const Table& tab, const String& columnName,
139 const Vector<Unit>&);
140 // </group>
141
142 // Copy constructor (copy semantics).
144
146
147 // Make this object reference the column in "that".
148 void reference (const ArrayQuantColumn<T>& that);
149
150 // Attach a column to the object. Optionally supply a default unit.
151 // which has the same meaning as the constructor unit argument.
152 // <group name="attach">
153 void attach (const Table& tab, const String& columnName);
154 void attach (const Table& tab, const String& columnName,
155 const Unit&);
156 void attach (const Table& tab, const String& columnName,
158 // </group>
159
160 // Get the quantum array in the specified row.
161 // If resize is True the resulting array is resized if its shape
162 // is not correct. Otherwise a "conformance exception" is thrown
163 // if the array is not empty and its shape mismatches.
164 // <group name="get">
165 void get (rownr_t rownr, Array<Quantum<T> >& q, Bool resize = False) const;
166 // Get the quantum array in the specified row. Each quantum is
167 // converted to the given unit.
168 void get (rownr_t rownr, Array<Quantum<T> >& q,
169 const Unit&, Bool resize = False) const;
170 // Get the quantum array in the specified row. Each quantum is
171 // converted to the given units.
172 void get (rownr_t rownr, Array<Quantum<T> >& q,
173 const Vector<Unit>&, Bool resize = False) const;
174 // Get the quantum array in the specified row. Each quantum is
175 // converted to the unit in other.
176 void get (rownr_t rownr, Array<Quantum<T> >& q,
177 const Quantum<T>& other, Bool resize = False) const;
178 // </group>
179
180 // Return the quantum array stored in the specified row.
181 // <group>
183 // Return the quantum array stored in the specified row, converted
184 // to the given unit.
185 Array<Quantum<T> > operator() (rownr_t rownr, const Unit&) const;
186 // Return the quantum array stored in the specified row, converted
187 // to the given units.
189 // Return the quantum array stored in the specified row, converted
190 // to the unit in other.
191 Array<Quantum<T> > operator() (rownr_t rownr, const Quantum<T>& other) const;
192 // </group>
193
194 // Put an array of quanta into the specified row of the table.
195 // If the column supports variable units, the units are stored as well.
196 // Otherwise the quanta are converted to the column's units.
197 void put (rownr_t rownr, const Array<Quantum<T> >& q);
198
199 // Test whether the Quantum column has variable units
201 { return (itsArrUnitsCol || itsScaUnitsCol); }
202
203 // Returns the column's units as a vector of strings.
204 // An empty vector is returned if the column has no fixed units.
206
207 // Test if the object is null.
208 Bool isNull() const
209 { return (itsDataCol == 0); }
210
211 // Throw an exception if the object is null.
212 void throwIfNull() const;
213
214protected:
215 //# Quantum column's units (if units not variable)
217
218 // Get access to itsUnitsCol.
219 // <group>
221 { return itsArrUnitsCol; }
223 { return itsScaUnitsCol; }
224 // </group>
225
226
227private:
228 //# The underlying data column stores the quantum column's data.
230 //# Variable units array column if applicable.
232 //# Variable units scalar column if applicable.
234 //# Units to retrieve the data in.
236 //# Convert unit when getting data?
238
239
240 // Initialize the ArrayQuantColumn from the specified table and column.
241 void init (const Table& tab, const String& columnName);
242
243 // Deletes allocated memory etc. Called by ~tor and any member which needs
244 // to reallocate data.
245 void cleanUp();
246
247 // Get the data without possible conversion.
248 void getData (rownr_t rownr, Array<Quantum<T> >& q, Bool resize) const;
249
250 // Assignment makes no sense in a read only class.
251 // Declaring this operator private makes it unusable.
253
254 // Comparison is not defined, since its semantics are unclear.
256};
257
258} //# NAMESPACE CASACORE - END
259
260
261//# Make old name ROArrayMeasColumn still available.
262#define ROArrayQuantColumn ArrayQuantColumn
263
264
265#ifndef CASACORE_NO_AUTO_TEMPLATES
266#include <casacore/measures/TableMeasures/ArrayQuantColumn.tcc>
267#endif //# CASACORE_NO_AUTO_TEMPLATES
268#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.
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
const ScalarColumn< String > * scaUnitsCol() const
void reference(const ArrayQuantColumn< T > &that)
Make this object reference the column in "that".
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:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
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