casacore
Loading...
Searching...
No Matches
ArrayMeasColumn.h
Go to the documentation of this file.
1// # ArrayMeasColumn.h: Access to array 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_ARRAYMEASCOLUMN_H
27#define MEASURES_ARRAYMEASCOLUMN_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#include <casacore/casa/Arrays/ArrayFwd.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward Declarations
38template <class T>
39class ArrayColumn;
40template <class T>
41class ScalarColumn;
42template <class M>
44
45// <summary>
46// Access table array Measure columns.
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableMeasures.cc">
52// </reviewed>
53
54// <prerequisite>
55// <li> <linkto module=Measures>Measures</linkto>
56// <li> <linkto module=Tables>Tables</linkto>
57// <li> TableMeasDesc
58// </prerequisite>
59
60// <synopsis>
61// ArrayMeasColumn objects can be used to access array Measure Columns
62// in tables, both for reading and writing (if the table is writable).
63//
64// Before a column can be accessed it must have previously been defined as
65// a Measure column by use of the
66// <linkto class="TableMeasDesc">TableMeasDesc</linkto> object.
67//
68// The ArrayMeasColumn class is templated on Measure type and MeasValue
69// type but typedefs exist for making declaration less long winded. The
70// Measure classes (like MEpoch) have typedefs <src>ArrayColumn</src>
71// to assist in creating ArrayMeasColumn objects.
72//
73// Constructing array Measure column objects using these typedefs looks like
74// this:
75// <srcblock>
76// // Read/write MEpoch array column
77// MEpoch::ArrayColumn ec(table, "ColumnName);
78// </srcblock>
79//
80// <h3>Reading and writing Measures</h3>
81//
82// The reading and writing of Measures columns is very similar to reading and
83// writing of "ordinary" Table columns.
84// <linkto class="ArrayMeasColumn#get">get()</linkto>
85// and <linkto class="ArrayMeasColumn#get">operator()</linkto>
86// exist for reading Measures and the
87// <linkto class="ArrayMeasColumn#put">put()</linkto> member for adding
88// Measures to a column. (put() is obviously not defined for
89// ScalarMeasColumn objects.) Each of these members accepts a row number
90// as an argument.
91//
92// Care needs to be taken when adding Measures to a column. The user needs
93// to be aware that Measures are not checked for consistency, with respect to
94// a Measure's reference, between the Measures being added to a column and
95// the column's predefined Measure reference. This is only an issue if the
96// Measure column was defined to have a fixed reference. For such columns
97// the reference component of Measures added to a column is silently
98// ignored, that is, there is no warning nor is there any sort of conversion
99// to the column's reference should the reference of the added Measure be
100// different from the column's reference. The functions
101// <linkto class="TableMeasDescBase#isRefCodeVariable()">
102// TableMeasDescBase::isRefVariable()</linkto>
103// and
104// <linkto class="ArrayMeasColumn#getMeasRef()">
105// ArrayMeasColumn::getMeasRef()</linkto> can be
106// used to discover a Measure column's Measure reference characteristics.
107// </synopsis>
108
109// <example>
110// <srcblock>
111// // create an MEpoch array column object
112// ArrayMeasColumn<MEpoch> arrayCol;
113//
114// // should be null. Can test this and attach a real MEpoch column
115// // The column Time1Arr should exist in the table and would have been
116// // defined by using a TableMeasDesc
117// if (arrayCol.isNull()) {
118// arrayCol.attach(tab, "Time1Arr");
119// }
120//
121// // This would throw an Exception if the object is still null....but
122// // hopefully won't
123// arrayCol.throwIfNull();
124//
125// // create a vector of MEpochs
126// MEpoch last(Quantity(13.45, "h"), MEpoch::Ref(MEpoch::TAI));
127// Vector<MEpoch> ev(10);
128// for (uInt i=0; i<10; i++) {
129// last.set(Quantity(13.45 + i, "h"));
130// ev(i) = last;
131// }
132//
133// // before adding something check the isDefined() member
134// if (!arrayCol.isDefined(0)) {
135// cout << "PASS - nothing in the measure array column row yet\n";
136// } else {
137// cout << "FAIL - there shouldn't be a valid value in the row!\n";
138// }
139//
140// // add the MEpoch vector to the array Measure column at row 0
141// arrayCol.put(0, ev);
142//
143// // now read the array from the row. Could use same object to do this
144// // but here we'll create a ArrayMeasColumn<MEpoch> to do this
145// ArrayMeasColumn<MEpoch> roArrCol(tab, "Time1Arr");
146//
147// // need a vector to put the MEpochs into
148// Vector<MEpoch> ew;
149//
150// // setting the resize parameter to True automatically sets ew to the
151// // same shape as the array contained in the row
152// arrayCol.get(0, ew, True);
153// </srcblock>
154// </example>
155
156// <motivation>
157// The standard Casacore Table system does not support array Measure columns.
158// This class overcomes this limitation.
159// </motivation>
160
161// <thrown>
162// <li>ArrayConformanceError during get() if supplied array is the wrong
163// shape.
164// </thrown>
165
166// # <todo asof="$DATE:$">
167// # A List of bugs, limitations, extensions or planned refinements.
168// # </todo>
169
170template <class M>
171class ArrayMeasColumn : public TableMeasColumn {
172 public:
173 // The default constructor creates a null object. Useful for creating
174 // arrays of ArrayMeasColumn objects. Attempting to use a null object
175 // will produce a segmentation fault so care needs to be taken to
176 // initialise the objects by using the attach() member before any attempt
177 // is made to use the object. A ArrayMeasColumn object can be tested
178 // if it is null by using the isNull() member.
180
181 // Create the ArrayMeasColumn from the table and column Name.
182 ArrayMeasColumn(const Table& tab, const String& columnName);
183
184 // Copy constructor (copy semantics).
187 virtual ~ArrayMeasColumn();
188
189 // Change the reference to another column.
190 void reference(const ArrayMeasColumn<M>& that);
191
192 // Attach a column to the object.
193 void attach(const Table& tab, const String& columnName);
194
195 // Get the Measure array in the specified row. For get() the supplied
196 // array's shape should match the shape in the row unless resize is True.
197 // <group name=get>
198 void get(rownr_t rownr, Array<M>& meas, Bool resize = False) const;
200 // </group>
201
202 // Get the Measure array contained in the specified row and convert
203 // it to the reference and offset found in the given measure.
204 Array<M> convert(rownr_t rownr, const M& meas) const { return convert(rownr, meas.getRef()); }
205
206 // Get the Measure array contained in the specified row and convert
207 // it to the given reference.
208 // <group>
209 Array<M> convert(rownr_t rownr, const MeasRef<M>& measRef) const;
210 Array<M> convert(rownr_t rownr, uInt refCode) const;
211 // </group>
212
213 // Get the column's reference.
214 const MeasRef<M>& getMeasRef() const { return itsMeasRef; }
215
216 // Reset the refCode, offset, or units.
217 // It overwrites the value used when defining the TableMeasDesc.
218 // Resetting the refCode and offset can only be done if they were
219 // defined as fixed in the description.
220 // <note role=tip>
221 // In principle the functions can only be used if the table is empty,
222 // otherwise already written values have thereafter the incorrect
223 // reference, offset, or unit.
224 // However, it is possible that part of the table is already
225 // written and that the entire measure column is filled in later.
226 // In that case the reference, offset, or units can be set by using
227 // a False <src>tableMustBeEmpty</src> argument.
228 // </note>
229 // <group>
230 void setDescRefCode(uInt refCode, Bool tableMustBeEmpty = True);
231 void setDescOffset(const Measure& offset, Bool tableMustBeEmpty = True);
232 void setDescUnits(const Vector<Unit>& units, Bool tableMustBeEmpty = True);
233 // </group>
234
235 // Add a Measure array to the specified row.
236 // <group name=put>
237 void put(rownr_t rownr, const Array<M>&);
238 // </group>
239
240 protected:
241 // # Its measure reference when the MeasRef is constant per row.
243
244 private:
245 // # Column which contains the Measure's actual data.
247 // # Its MeasRef code column when references are variable.
250 // # Its MeasRef column when references are variable and stored as Strings.
253 // # Column containing its variable offsets. Only applicable if the
254 // # measure references have offsets and they are variable.
257
258 // Assignment makes no sense in a read only class.
259 // Declaring this operator private makes it unusable.
261
262 // Deletes allocated memory etc. Called by ~tor and any member which needs
263 // to reallocate data.
264 void cleanUp();
265
266 // Get the data and convert using conversion engine.
267 Array<M> doConvert(rownr_t rownr, typename M::Convert& conv) const;
268};
269
270} // namespace casacore
271
272// # Make old name ROArrayMeasColumn still available.
273#define ROArrayMeasColumn ArrayMeasColumn
274
275#ifndef CASACORE_NO_AUTO_TEMPLATES
276#include <casacore/measures/TableMeasures/ArrayMeasColumn.tcc>
277#endif // # CASACORE_NO_AUTO_TEMPLATES
278#endif
void cleanUp()
Deletes allocated memory etc.
Array< M > convert(rownr_t rownr, const M &meas) const
Get the Measure array contained in the specified row and convert it to the reference and offset found...
ArrayMeasColumn()
The default constructor creates a null object.
Array< M > convert(rownr_t rownr, uInt refCode) const
void setDescOffset(const Measure &offset, Bool tableMustBeEmpty=True)
ArrayMeasColumn & operator=(const ArrayMeasColumn< M > &that)
Assignment makes no sense in a read only class.
void setDescUnits(const Vector< Unit > &units, Bool tableMustBeEmpty=True)
ScalarMeasColumn< MBaseline > * itsOffsetCol
ArrayMeasColumn< MBaseline > * itsArrOffsetCol
void attach(const Table &tab, const String &columnName)
Attach a column to the object.
Array< M > doConvert(rownr_t rownr, typename M::Convert &conv) const
Get the data and convert using conversion engine.
const MeasRef< M > & getMeasRef() const
Get the column's reference.
void get(rownr_t rownr, Array< M > &meas, Bool resize=False) const
Get the Measure array in the specified row.
Array< M > operator()(rownr_t rownr) const
void put(rownr_t rownr, const Array< M > &)
Add a Measure array to the specified row.
void setDescRefCode(uInt refCode, Bool tableMustBeEmpty=True)
Reset the refCode, offset, or units.
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
const Bool False
Definition aipstype.h:42
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