casacore
Loading...
Searching...
No Matches
ScalarMeasColumn.h
Go to the documentation of this file.
1//# ScalarMeasColumn.h: Access to Scalar Measure Columns in Tables.
2//# Copyright (C) 1997,1998,1999,2000
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_SCALARMEASCOLUMN_H
27#define MEASURES_SCALARMEASCOLUMN_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/measures/TableMeasures/TableMeasColumn.h>
32#include <casacore/measures/Measures/MeasRef.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward Declarations
37template <class T> class ArrayColumn;
38template <class T> class ScalarColumn;
39
40
41// <summary>
42// Read only access to table scalar Measure columns.
43// </summary>
44
45// <use visibility=export>
46
47// <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableMeasures.cc">
48// </reviewed>
49
50// <prerequisite>
51//# Classes you should understand before using this one.
52// <li> <linkto module=Measures>Measures</linkto>
53// <li> <linkto module=Tables>Tables</linkto>
54// <li> <linkto class=TableMeasDesc>TableMeasDesc</linkto>
55// </prerequisite>
56
57// <synopsis>
58// ScalarMeasColumn objects can be used to access scalar Measure Columns
59// in tables, both for reading and writing (if the table is writable).
60//
61// Before a column can be accessed it must have previously been defined as
62// a Measure column by use of the
63// <linkto class="TableMeasDesc">TableMeasDesc</linkto> object.
64//
65// The ScalarMeasColumn class is templated on Measure type.
66// Typedefs exist in the various Measure classes
67// (e.g. <linkto class=MEpoch>MEpoch</linkto>) to make declaration
68// less long winded.
69// Constructing scalar Measure column objects using these typedefs looks like
70// this:
71// <srcblock>
72// MEpoch::ScalarMeasColumn ec(table, "ColumnName);
73// </srcblock>
74//
75// <h3>Reading and writing Measures</h3>
76//
77// The reading and writing of Measures columns is very similar to reading and
78// writing of "ordinary" Table columns.
79// <linkto class="ScalarMeasColumn#get">get()</linkto>
80// and <linkto class="ScalarMeasColumn#get">operator()</linkto>
81// exist for reading Measures and the
82// <linkto class="ScalarMeasColumn#put">put()</linkto> member for adding
83// Measures to a column. (put() is obviously not defined for
84// ScalarMeasColumn objects.) Each of these members accepts a row number
85// as an argument.
86// The get() function gets the measure with the reference and offset as
87// it is stored in the column. Furthermore the convert() function is
88// available to get the measure with the given reference, possible offset,
89// and possible frame
90//
91// When a Measure is put, the reference and possible offset are converted
92// if the measure column is defined with a fixed reference and/or offset.
93// If the column's reference and offset are variable, the reference and
94// offset of the measure as put are written into the appropriate
95// reference and offset columns.
96// </synopsis>
97
98// <example>
99// <srcblock>
100// // This creates a Scalar MEpoch column for read/write access. Column
101// // "Time1" must exist in Table "tab" and must have previously been
102// // defined as a MEpoch column using a TableMeasDesc.
103// MEpoch::ScalarMeasColumn timeCol(tab, "Time1");
104//
105// // print some details about the column
106// if (timeCol.measDesc().isRefCodeVariable()) {
107// cout << "The column has variable references." << endl;
108// } else {
109// cout << "The fixed MeasRef for the column is: "
110// << timeCol.getMeasRef() << endl;
111// }
112//
113// // Add tab.nrow() measures to the column.
114// MEpoch tm(Quantity(MeasData::MJD2000, "d"), MEpoch::TAI);
115// for (rownr_t i=0; i<tab.nrow(); i++) {
116// timeCol.put(i, tm);
117// }
118//
119// // We could read from the column using timeCol but instead a read
120// // only column object is created.
121// MEpoch::ScalarMeasColumn timeColRead(tab, "Time1");
122// for (i=0; i<tab.nrow(); i++) {
123// cout << timeColRead(i) << endl;
124// }
125// </srcblock>
126// </example>
127
128// <motivation>
129// The standard Casacore Table system does not support Measures columns.
130// This class overcomes this limitation.
131// </motivation>
132//
133// <thrown>
134// <li>AipsError during construction if the column specified variable
135// offsets which are stored in an Array- rather than a ScalarColumn.
136// </thrown>
137//
138//# <todo asof="$DATE:$">
139//# </todo>
140
141template <class M> class ScalarMeasColumn : public TableMeasColumn
142{
143public:
144 // The default constructor creates a null object. Useful for creating
145 // arrays of ScalarMeasColumn objects. Attempting to use a null object
146 // will produce a segmentation fault so care needs to be taken to
147 // initialize the objects first by using attach().
148 // An ScalarMeasColumn object can be tested if it is null by using the
149 // isNull() member.
151
152 // Create the ScalarMeasColumn from the table and column Name.
154
155 // Copy constructor (copy semantics).
157
159
160 // Change the reference to another column.
161 void reference (const ScalarMeasColumn<M>& that);
162
163 // Attach a column to the object.
164 void attach (const Table& tab, const String& columnName);
165
166 // Get the Measure contained in the specified row.
167 // It returns the Measure as found in the table.
168 // <group name=get>
169 void get (rownr_t rownr, M& meas) const;
170 M operator() (rownr_t rownr) const;
171 // </group>
172
173 // Get the Measure contained in the specified row and convert
174 // it to the reference and offset found in the given measure.
175 M convert (rownr_t rownr, const M& meas) const
176 { return convert (rownr, meas.getRef()); }
177
178 // Get the Measure contained in the specified row and convert
179 // it to the given reference.
180 // <group>
181 M convert (rownr_t rownr, const MeasRef<M>& measRef) const;
182 M convert (rownr_t rownr, uInt refCode) const;
183 // </group>
184
185 // Returns the column's fixed reference or the reference of the last
186 // read Measure if references are variable.
187 const MeasRef<M>& getMeasRef() const
188 { return itsMeasRef; }
189
190 // Reset the refCode, offset, or units.
191 // It overwrites the value used when defining the TableMeasDesc.
192 // Resetting the refCode and offset can only be done if they were
193 // defined as fixed in the description.
194 // <note role=tip>
195 // In principle the functions can only be used if the table is empty,
196 // otherwise already written values have thereafter the incorrect
197 // reference, offset, or unit.
198 // However, it is possible that part of the table is already
199 // written and that the entire measure column is filled in later.
200 // In that case the reference, offset, or units can be set by using
201 // a False <src>tableMustBeEmpty</src> argument.
202 // </note>
203 // <group>
204 void setDescRefCode (uInt refCode, Bool tableMustBeEmpty=True);
205 void setDescOffset (const Measure& offset, Bool tableMustBeEmpty=True);
206 void setDescUnits (const Vector<Unit>& units, Bool tableMustBeEmpty=True);
207 // </group>
208
209 // Put a Measure into the given row.
210 // <group name=put>
211 void put (rownr_t rownr, const M& meas);
212 // </group>
213
214protected:
215 // Make a MeasRef for the given row.
217
218private:
219 //# Whether conversion is needed during a put. True if either
220 //# the reference code or offset is fixed for the column
222 //# Column which contains the Measure's actual data. An array column
223 //# is needed if the data component of the underlying Measure is
224 //# represented by more than 1 value
227 //# Its MeasRef code column when references are variable.
230 //# Column containing its variable offsets. Only applicable if the
231 //# measure references have offsets and they are variable.
233 //# This is either the column's fixed Measure reference or the reference
234 //# of the last Measure read.
236
237
238 // Assignment makes no sense in a readonly class.
239 // Declaring this operator private makes it unusable.
241
242 // Check if refs have the same value (as opposed to being the same object).
243 Bool equalRefs (const MRBase& r1, const MRBase& r2) const;
244
245 //# Deletes allocated memory etc. Called by ~tor and any member which
246 //# needs to reallocate data.
247 void cleanUp();
248};
249
250
251} //# NAMESPACE CASACORE - END
252
253
254//# Make old name ROScalarMeasColumn still available.
255#define ROScalarMeasColumn ScalarMeasColumn
256
257
258#ifndef CASACORE_NO_AUTO_TEMPLATES
259#include <casacore/measures/TableMeasures/ScalarMeasColumn.tcc>
260#endif //# CASACORE_NO_AUTO_TEMPLATES
261#endif
M convert(rownr_t rownr, uInt refCode) const
Bool equalRefs(const MRBase &r1, const MRBase &r2) const
Check if refs have the same value (as opposed to being the same object).
void setDescUnits(const Vector< Unit > &units, Bool tableMustBeEmpty=True)
ScalarMeasColumn()
The default constructor creates a null object.
M operator()(rownr_t rownr) const
void get(rownr_t rownr, M &meas) const
Get the Measure contained in the specified row.
void put(rownr_t rownr, const M &meas)
Put a Measure into the given row.
void setDescOffset(const Measure &offset, Bool tableMustBeEmpty=True)
ScalarMeasColumn< M > * itsOffsetCol
M convert(rownr_t rownr, const MeasRef< M > &measRef) const
Get the Measure contained in the specified row and convert it to the given reference.
ArrayColumn< Double > * itsArrDataCol
void reference(const ScalarMeasColumn< M > &that)
Change the reference to another column.
ScalarMeasColumn(const Table &tab, const String &columnName)
Create the ScalarMeasColumn from the table and column Name.
void attach(const Table &tab, const String &columnName)
Attach a column to the object.
MeasRef< M > makeMeasRef(rownr_t rownr) const
Make a MeasRef for the given row.
ScalarMeasColumn(const ScalarMeasColumn< M > &that)
Copy constructor (copy semantics).
void setDescRefCode(uInt refCode, Bool tableMustBeEmpty=True)
Reset the refCode, offset, or units.
ScalarColumn< Double > * itsScaDataCol
ScalarColumn< String > * itsRefStrCol
ScalarMeasColumn & operator=(const ScalarMeasColumn< M > &that)
Assignment makes no sense in a readonly class.
const MeasRef< M > & getMeasRef() const
Returns the column's fixed reference or the reference of the last read Measure if references are vari...
M convert(rownr_t rownr, const M &meas) const
Get the Measure contained in the specified row and convert it to the reference and offset found in th...
ScalarColumn< Int > * itsRefIntCol
String: the storage and methods of handling collections of characters.
Definition String.h:223
const String & columnName() const
Get the name of the column.
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44