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