casacore
ScalarQuantColumn.h
Go to the documentation of this file.
1//# ScalarQuantColumn.h: Access to a Scalar 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: 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 MEASURES_SCALARQUANTCOLUMN_H
29#define MEASURES_SCALARQUANTCOLUMN_H
30
31//# Includes
32#include <casacore/casa/aips.h>
33#include <casacore/casa/Quanta/Quantum.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38class Table;
39template <class T> class ScalarColumn;
40class String;
41class Unit;
42
43
44// <summary>
45// Provides access to Scalar 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=ScalarColumn>ScalarColumn</linkto>
58// <li> <linkto class=Quantum>Quantum</linkto>
59// </prerequisite>
60
61// <synopsis>
62// The ScalarQuantColumn class provides read/write access to quanta
63// stored in a scalar 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 ScalarQuantColumn object to be useful the column should
68// contain Quanta.
69//
70// A ScalarQuantColumn object is used much in the same way as a
71// <linkto class=ScalarColumn>ScalarColumn</linkto> object.
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 ScalarQuantColumn 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// <srcblock>
88// Quantum<Double> q(5.3, "keV");
89// // "QuantScalar" has previously been defined as a Quantum column
90// // by means of a TableQuantumDesc. This example assumes the column
91// // already contains quanta.
92// ScalarQuantColumn<Double> qCol(qtab, "QuantScalar");
93// // return and print quanta as stored in the column
94// for (i = 0; i < qtab.nrow(); i++) {
95// cout << qCol(i) << endl;
96// }
97// // The following retrieves and converts the quanta to GHz. They
98// // are then divided by the Quantum constant QC::h (Planck).
99// for (i=0; i < qtab.nrow(); i++) {
100// cout << (qCol(i, "GHz"))/(QC::h);
101// }
102// </srcblock>
103// </example>
104
105// <motivation>
106// Add support for Quanta in the Tables system.
107// </motivation>
108
109// <thrown>
110// <li>TableInvOper if the Table column is null.
111// </thrown>
112
113// <todo asof="$DATE:$">
114//# A List of bugs, limitations, extensions or planned refinements.
115// <li> Functions like getColumn
116// </todo>
117
118
119template<class T> class ScalarQuantColumn
120{
121public:
122 // The default constructor creates a null object. It is useful for creating
123 // arrays of ScalarQuantColumn objects. Attempting to use a null object
124 // will produce a segmentation fault so care needs to be taken to
125 // initialise the objects by using the attach() member before any attempt
126 // is made to use the object. The isNull() member can be used to test
127 // if a ScalarQuantColumn object is null.
129
130 // Create the ScalarQuantColumn from the specified table and column name.
131 // The default unit for data retrieved is the unit in which they were stored.
132 ScalarQuantColumn (const Table& tab, const String& columnName);
133
134 // Create the ScalarQuantColumn from the specified table and column name.
135 // The default unit for data retrieved is the given unit (the data is
136 // converted as needed).
137 ScalarQuantColumn (const Table& tab, const String& columnName,
138 const Unit&);
139
140 // Copy constructor (copy semantics).
142
144
145 // Change the reference to another column.
146 void reference (const ScalarQuantColumn<T>& 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 // </group>
154
155 // Get the quantum stored in the specified row.
156 // <group name="get">
157 void get (rownr_t rownr, Quantum<T>& q) const;
158 // Get the quantum in the specified row, converted to the given unit.
159 void get (rownr_t rownr, Quantum<T>& q, const Unit&) const;
160 // Get the quantum in the specified row, converted to the unit in other.
161 void get (rownr_t rownr, Quantum<T>& q, const Quantum<T>& other) const;
162 // </group>
163
164 // Return the quantum stored in the specified row.
165 // <group>
167 // Return the quantum stored in the specified row, converted to the
168 // given unit.
169 Quantum<T> operator() (rownr_t rownr, const Unit&) const;
170 // Return the quantum in the specified row, converted to the unit in
171 // other.
172 Quantum<T> operator() (rownr_t rownr, const Quantum<T>& other) const;
173 // </group>
174
175 // Put a quantum into the table. If the column supports variable units
176 // the q's unit is stored into the unit column defined in the
177 // TableQuantumDesc object. If units are fixed for the column, the
178 // quantum is converted as needed.
179 void put (rownr_t rownr, const Quantum<T>& q);
180
181 // Test whether the Quantum column has variable units
183 { return (itsUnitsCol != 0); }
184
185 // Returns the column's value for Units as a string.
186 // An empty string is returned if the column has variable units.
187 const String& getUnits() const
188 { return itsUnit.getName(); }
189
190 // Test if the object is null.
191 Bool isNull() const
192 { return (itsDataCol == 0); }
193
194 // Throw an exception if the object is null.
195 void throwIfNull() const;
196
197 // Get the column as a Quantum<Vector<T> >. If <src>unit</src> is
198 // not empty, the returned Quantum will have that unit. Else if
199 // the units are variable, the values in the returned Vector
200 // have been converted to the unit of the 0th row entry. Otherwise,
201 // the units of the returned Quantum are the units specified in
202 // the column descriptor.
203 std::shared_ptr<Quantum<Vector<T> > > getColumn(const Unit& unit="") const;
204
205protected:
206 //# Quantum column's units (if units not variable)
208
209 // Get access to itsUnitsCol.
211 { return itsUnitsCol; }
212
213private:
214 //# The underlying data column stores the quantum column's data.
216 //# Variable units column if applicable.
218 //# Unit to retrieve the data in.
220 //# Convert unit when getting data?
222
223
224 // Assignment makes no sense in a read only class.
225 // Declaring this operator private makes it unusable.
227
228 // Comparison is not defined, since its semantics are unclear.
230
231 // Initialize the ScalarQuantColumn from the specified table and column.
232 void init (const Table& tab, const String& columnName);
233
234 // Deletes allocated memory etc. Called by destructor and any member
235 // which needs to reallocate data.
236 void cleanUp();
237
238 // Get the data without possible conversion.
239 void getData (rownr_t rownr, Quantum<T>& q) const;
240};
241
242} //# NAMESPACE CASACORE - END
243
244
245//# Make old name ROScalarMeasColumn still available.
246#define ROScalarQuantColumn ScalarQuantColumn
247
248
249#ifndef CASACORE_NO_AUTO_TEMPLATES
250#include <casacore/measures/TableMeasures/ScalarQuantColumn.tcc>
251#endif //# CASACORE_NO_AUTO_TEMPLATES
252#endif
void get(rownr_t rownr, Quantum< T > &q) const
Get the quantum stored in the specified row.
void attach(const Table &tab, const String &columnName, const Unit &)
const String & getUnits() const
Returns the column's value for Units as a string.
Bool operator==(const ScalarQuantColumn< T > &that)
Comparison is not defined, since its semantics are unclear.
const ScalarColumn< String > * unitsCol() const
Get access to itsUnitsCol.
Bool isUnitVariable() const
Test whether the Quantum column has variable units.
Quantum< T > operator()(rownr_t rownr) const
Return the quantum stored in the specified row.
ScalarColumn< String > * itsUnitsCol
void getData(rownr_t rownr, Quantum< T > &q) const
Get the data without possible conversion.
ScalarQuantColumn()
The default constructor creates a null object.
ScalarQuantColumn(const ScalarQuantColumn< T > &that)
Copy constructor (copy semantics).
ScalarQuantColumn(const Table &tab, const String &columnName)
Create the ScalarQuantColumn from the specified table and column name.
void cleanUp()
Deletes allocated memory etc.
void attach(const Table &tab, const String &columnName)
Attach a column to the object.
Bool isNull() const
Test if the object is null.
void get(rownr_t rownr, Quantum< T > &q, const Quantum< T > &other) const
Get the quantum in the specified row, converted to the unit in other.
ScalarColumn< T > * itsDataCol
std::shared_ptr< Quantum< Vector< T > > > getColumn(const Unit &unit="") const
Get the column as a Quantum<Vector<T> >.
ScalarQuantColumn & operator=(const ScalarQuantColumn< T > &that)
Assignment makes no sense in a read only class.
ScalarQuantColumn(const Table &tab, const String &columnName, const Unit &)
Create the ScalarQuantColumn from the specified table and column name.
void throwIfNull() const
Throw an exception if the object is null.
void reference(const ScalarQuantColumn< T > &that)
Change the reference to another column.
void put(rownr_t rownr, const Quantum< T > &q)
Put a quantum into the table.
void init(const Table &tab, const String &columnName)
Initialize the ScalarQuantColumn from the specified table and column.
void get(rownr_t rownr, Quantum< T > &q, const Unit &) const
Get the quantum in the specified row, converted to the given unit.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
const String & getName() const
Get the unit name.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46