casacore
Loading...
Searching...
No Matches
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: 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_SCALARQUANTCOLUMN_H
27#define MEASURES_SCALARQUANTCOLUMN_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Quanta/Quantum.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35//# Forward Declarations
36class Table;
37template <class T> class ScalarColumn;
38class String;
39class Unit;
40
41
42// <summary>
43// Provides access to Scalar Quantum Columns in Tables.
44// </summary>
45
46// <use visibility=export>
47
48// <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableQuantum.cc">
49// </reviewed>
50
51// <prerequisite>
52//# Classes you should understand before using this one.
53// <li> <linkto class=TableQuantumDesc>TableQuantumDesc</linkto>
54// <li> <linkto class=Table>Table</linkto>
55// <li> <linkto class=ScalarColumn>ScalarColumn</linkto>
56// <li> <linkto class=Quantum>Quantum</linkto>
57// </prerequisite>
58
59// <synopsis>
60// The ScalarQuantColumn class provides read/write access to quanta
61// stored in a scalar Quantum Table column. The Quantum column should
62// already exist in the table and would have been defined by means of a
63// <linkto class=TableQuantumDesc>TableQuantumDesc object</linkto>.
64// In addition,
65// for a ScalarQuantColumn object to be useful the column should
66// contain Quanta.
67//
68// A ScalarQuantColumn object is used much in the same way as a
69// <linkto class=ScalarColumn>ScalarColumn</linkto> object.
70//
71// <h3>Quantum Units</h3></A>
72// Quanta retrieved from the column will normally have the Unit that was
73// specified when the Quantum column was defined.
74// However, it is possible to override the default column Unit by
75// supplying a Unit in the ScalarQuantColumn constructor.
76// When constructed in this fashion the retrieved Quanta will by
77// default be retrieved in this unit, i.e. they will by default be
78// converted to this unit.
79// <br>
80// By giving a unit (as a Unit or Quantum object) to a get function,
81// the data can be retrieved in another unit than the default.
82// </synopsis>
83
84// <example>
85// <srcblock>
86// Quantum<Double> q(5.3, "keV");
87// // "QuantScalar" has previously been defined as a Quantum column
88// // by means of a TableQuantumDesc. This example assumes the column
89// // already contains quanta.
90// ScalarQuantColumn<Double> qCol(qtab, "QuantScalar");
91// // return and print quanta as stored in the column
92// for (i = 0; i < qtab.nrow(); i++) {
93// cout << qCol(i) << endl;
94// }
95// // The following retrieves and converts the quanta to GHz. They
96// // are then divided by the Quantum constant QC::h (Planck).
97// for (i=0; i < qtab.nrow(); i++) {
98// cout << (qCol(i, "GHz"))/(QC::h);
99// }
100// </srcblock>
101// </example>
102
103// <motivation>
104// Add support for Quanta in the Tables system.
105// </motivation>
106
107// <thrown>
108// <li>TableInvOper if the Table column is null.
109// </thrown>
110
111// <todo asof="$DATE:$">
112//# A List of bugs, limitations, extensions or planned refinements.
113// <li> Functions like getColumn
114// </todo>
115
116
117template<class T> class ScalarQuantColumn
118{
119public:
120 // The default constructor creates a null object. It is useful for creating
121 // arrays of ScalarQuantColumn objects. Attempting to use a null object
122 // will produce a segmentation fault so care needs to be taken to
123 // initialise 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 ScalarQuantColumn object is null.
127
128 // Create the ScalarQuantColumn from the specified table and column name.
129 // The default unit for data retrieved is the unit in which they were stored.
130 ScalarQuantColumn (const Table& tab, const String& columnName);
131
132 // Create the ScalarQuantColumn from the specified table and column name.
133 // The default unit for data retrieved is the given unit (the data is
134 // converted as needed).
135 ScalarQuantColumn (const Table& tab, const String& columnName,
136 const Unit&);
137
138 // Copy constructor (copy semantics).
140
142
143 // Change the reference to another column.
144 void reference (const ScalarQuantColumn<T>& that);
145
146 // Attach a column to the object. Optionally supply a default unit
147 // which has the same meaning as the constructor unit argument.
148 // <group name="attach">
149 void attach (const Table& tab, const String& columnName);
150 void attach (const Table& tab, const String& columnName, const Unit&);
151 // </group>
152
153 // Get the quantum stored in the specified row.
154 // <group name="get">
155 void get (rownr_t rownr, Quantum<T>& q) const;
156 // Get the quantum in the specified row, converted to the given unit.
157 void get (rownr_t rownr, Quantum<T>& q, const Unit&) const;
158 // Get the quantum in the specified row, converted to the unit in other.
159 void get (rownr_t rownr, Quantum<T>& q, const Quantum<T>& other) const;
160 // </group>
161
162 // Return the quantum stored in the specified row.
163 // <group>
165 // Return the quantum stored in the specified row, converted to the
166 // given unit.
167 Quantum<T> operator() (rownr_t rownr, const Unit&) const;
168 // Return the quantum in the specified row, converted to the unit in
169 // other.
170 Quantum<T> operator() (rownr_t rownr, const Quantum<T>& other) const;
171 // </group>
172
173 // Put a quantum into the table. If the column supports variable units
174 // the q's unit is stored into the unit column defined in the
175 // TableQuantumDesc object. If units are fixed for the column, the
176 // quantum is converted as needed.
177 void put (rownr_t rownr, const Quantum<T>& q);
178
179 // Test whether the Quantum column has variable units
181 { return (itsUnitsCol != 0); }
182
183 // Returns the column's value for Units as a string.
184 // An empty string is returned if the column has variable units.
185 const String& getUnits() const
186 { return itsUnit.getName(); }
187
188 // Test if the object is null.
189 Bool isNull() const
190 { return (itsDataCol == 0); }
191
192 // Throw an exception if the object is null.
193 void throwIfNull() const;
194
195 // Get the column as a Quantum<Vector<T> >. If <src>unit</src> is
196 // not empty, the returned Quantum will have that unit. Else if
197 // the units are variable, the values in the returned Vector
198 // have been converted to the unit of the 0th row entry. Otherwise,
199 // the units of the returned Quantum are the units specified in
200 // the column descriptor.
201 std::shared_ptr<Quantum<Vector<T> > > getColumn(const Unit& unit="") const;
202
203protected:
204 //# Quantum column's units (if units not variable)
206
207 // Get access to itsUnitsCol.
209 { return itsUnitsCol; }
210
211private:
212 //# The underlying data column stores the quantum column's data.
214 //# Variable units column if applicable.
216 //# Unit to retrieve the data in.
218 //# Convert unit when getting data?
220
221
222 // Assignment makes no sense in a read only class.
223 // Declaring this operator private makes it unusable.
225
226 // Comparison is not defined, since its semantics are unclear.
228
229 // Initialize the ScalarQuantColumn from the specified table and column.
230 void init (const Table& tab, const String& columnName);
231
232 // Deletes allocated memory etc. Called by destructor and any member
233 // which needs to reallocate data.
234 void cleanUp();
235
236 // Get the data without possible conversion.
237 void getData (rownr_t rownr, Quantum<T>& q) const;
238};
239
240} //# NAMESPACE CASACORE - END
241
242
243//# Make old name ROScalarMeasColumn still available.
244#define ROScalarQuantColumn ScalarQuantColumn
245
246
247#ifndef CASACORE_NO_AUTO_TEMPLATES
248#include <casacore/measures/TableMeasures/ScalarQuantColumn.tcc>
249#endif //# CASACORE_NO_AUTO_TEMPLATES
250#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.
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:223
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:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44