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>
38class ScalarColumn;
39class String;
40class Unit;
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
116template <class T>
118 public:
119 // The default constructor creates a null object. It is useful for creating
120 // arrays of ScalarQuantColumn objects. Attempting to use a null object
121 // will produce a segmentation fault so care needs to be taken to
122 // initialise the objects by using the attach() member before any attempt
123 // is made to use the object. The isNull() member can be used to test
124 // if a ScalarQuantColumn object is null.
126
127 // Create the ScalarQuantColumn from the specified table and column name.
128 // The default unit for data retrieved is the unit in which they were stored.
129 ScalarQuantColumn(const Table& tab, const String& columnName);
130
131 // Create the ScalarQuantColumn from the specified table and column name.
132 // The default unit for data retrieved is the given unit (the data is
133 // converted as needed).
134 ScalarQuantColumn(const Table& tab, const String& columnName, const Unit&);
135
136 // Copy constructor (copy semantics).
138
140
141 // Change the reference to another column.
143
144 // Attach a column to the object. Optionally supply a default unit
145 // which has the same meaning as the constructor unit argument.
146 // <group name="attach">
147 void attach(const Table& tab, const String& columnName);
148 void attach(const Table& tab, const String& columnName, const Unit&);
149 // </group>
150
151 // Get the quantum stored in the specified row.
152 // <group name="get">
153 void get(rownr_t rownr, Quantum<T>& q) const;
154 // Get the quantum in the specified row, converted to the given unit.
155 void get(rownr_t rownr, Quantum<T>& q, const Unit&) const;
156 // Get the quantum in the specified row, converted to the unit in other.
157 void get(rownr_t rownr, Quantum<T>& q, const Quantum<T>& other) const;
158 // </group>
159
160 // Return the quantum stored in the specified row.
161 // <group>
163 // Return the quantum stored in the specified row, converted to the
164 // given unit.
165 Quantum<T> operator()(rownr_t rownr, const Unit&) const;
166 // Return the quantum in the specified row, converted to the unit in
167 // other.
168 Quantum<T> operator()(rownr_t rownr, const Quantum<T>& other) const;
169 // </group>
170
171 // Put a quantum into the table. If the column supports variable units
172 // the q's unit is stored into the unit column defined in the
173 // TableQuantumDesc object. If units are fixed for the column, the
174 // quantum is converted as needed.
175 void put(rownr_t rownr, const Quantum<T>& q);
176
177 // Test whether the Quantum column has variable units
178 Bool isUnitVariable() const { return (itsUnitsCol != 0); }
179
180 // Returns the column's value for Units as a string.
181 // An empty string is returned if the column has variable units.
182 const String& getUnits() const { return itsUnit.getName(); }
183
184 // Test if the object is null.
185 Bool isNull() const { return (itsDataCol == 0); }
186
187 // Throw an exception if the object is null.
188 void throwIfNull() const;
189
190 // Get the column as a Quantum<Vector<T> >. If <src>unit</src> is
191 // not empty, the returned Quantum will have that unit. Else if
192 // the units are variable, the values in the returned Vector
193 // have been converted to the unit of the 0th row entry. Otherwise,
194 // the units of the returned Quantum are the units specified in
195 // the column descriptor.
196 std::shared_ptr<Quantum<Vector<T>>> getColumn(const Unit& unit = "") const;
197
198 protected:
199 // # Quantum column's units (if units not variable)
201
202 // Get access to itsUnitsCol.
203 const ScalarColumn<String>* unitsCol() const { return itsUnitsCol; }
204
205 private:
206 // # The underlying data column stores the quantum column's data.
208 // # Variable units column if applicable.
210 // # Unit to retrieve the data in.
212 // # Convert unit when getting data?
214
215 // Assignment makes no sense in a read only class.
216 // Declaring this operator private makes it unusable.
218
219 // Comparison is not defined, since its semantics are unclear.
221
222 // Initialize the ScalarQuantColumn from the specified table and column.
223 void init(const Table& tab, const String& columnName);
224
225 // Deletes allocated memory etc. Called by destructor and any member
226 // which needs to reallocate data.
227 void cleanUp();
228
229 // Get the data without possible conversion.
230 void getData(rownr_t rownr, Quantum<T>& q) const;
231};
232
233} // namespace casacore
234
235// # Make old name ROScalarMeasColumn still available.
236#define ROScalarQuantColumn ScalarQuantColumn
237
238#ifndef CASACORE_NO_AUTO_TEMPLATES
239#include <casacore/measures/TableMeasures/ScalarQuantColumn.tcc>
240#endif // # CASACORE_NO_AUTO_TEMPLATES
241#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.
Quantum< T > operator()(rownr_t rownr, const Unit &) const
Return the quantum stored in the specified row, converted to the given unit.
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.
Quantum< T > operator()(rownr_t rownr, const Quantum< T > &other) const
Return the quantum in the specified row, converted to the unit in other.
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
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