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