casacore
Loading...
Searching...
No Matches
TableQuantumDesc.h
Go to the documentation of this file.
1// # TableQuantumDesc.h: Defines a 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_TABLEQUANTUMDESC_H
27#define MEASURES_TABLEQUANTUMDESC_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/Vector.h>
32#include <casacore/casa/BasicSL/String.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37class TableDesc;
38class Table;
39class TableRecord;
40class TableColumn;
41class Unit;
42
43// <summary>
44// A class for defining Quantum columns in Tables.
45// </summary>
46
47// <use visibility=export>
48
49// <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableQuantum.cc">
50// </reviewed>
51
52// <prerequisite>
53// # Classes you should understand before using this one.
54// <li> <linkto class=Table>Table</linkto>
55// <li> <linkto class=Quantum>Quantum</linkto>
56// </prerequisite>
57
58// <synopsis>
59// A TableQuantumDesc object is used to define a Quantum column in a Table.
60// The use of this object and the associated Scalar- and ArrayQuantColumn
61// objects make it possible to store (and retrieve) Quanta in Tables.<br>
62//
63// TableQuantumDesc objects are analogous to ColumnDesc objects in that they
64// add information, describing the characteristics of a column, to the Table
65// Descriptor before the Table is created. However, rather than
66// replacing the use of a ColumnDesc object, a TableQuantumDesc is
67// used in conjunction with a ColumnDesc in the definition of
68// Quantum columns.<br>
69//
70// <note role=caution>
71// A good understanding of the Table system is essential
72// before attempting to use this class.
73// </note>
74//
75// Defining a Quantum column requires the following steps:
76// <ol>
77// <li> Use a normal Scalar- or ArrayColumnDesc to define a column to use for
78// the Quanta.
79// <li> If needed (see
80// <A HREF="#TableQuantumDesc:Quantum Units">below</A>) define a column
81// for the Quantum Units.
82// <li> Add the columns to the Table Descriptor.
83// <li> Declare a TableQuantumDesc to associate the column defined in step 1
84// and the Unit column from step 2 and update the Table Descriptor.
85// <li> Setup and create the Table.
86// </ol>
87// It is also possible to define a Quantum column after the table is created.
88// which is useful when columns (to be used for quanta) are added to
89// an already existing table. <br>
90//
91// The type of the quantum columns must match the type of the underlying
92// Quanta that are to be stored in the column. Hence, for a column of
93// Quantum&lt;Complex&gt; a ScalarColumnDesc&lt;Complex&gt; must be used.<br>
94//
95// As with standard Table Columns Quanta can be stored in Scalar and Array
96// columns. This must be specified in advance by using either a
97// Scalar- or ArrayColumnDesc.<br>
98//
99// After the Table has be created a Quantum column can be accessed for writing
100// and reading of Quanta via the
101// <linkto class="ScalarQuantColumn">(RO)ScalarQuantColumn&lt;T&gt;</linkto>
102// and
103// <linkto class="ArrayQuantColumn">(RO)ArrayQuantColumn&lt;T&gt;</linkto>
104// objects.
105//
106// <ANCHOR NAME="TableQuantumDesc:Quantum Units">
107// <h3>Quantum Units</h3></ANCHOR>
108// The treatment of the Unit component of a Quantum in the TableQuantumDesc
109// class varies depending on your needs. The main consideration
110// is whether the Quanta to be stored in a specific column are to have the
111// same Unit or whether their Units could differ. In the simple case,
112// where the
113// Quanta have the same unit, a TableQuantumDesc is declared with the
114// Unit value specified as a parameter. The following defines a Quantum
115// column with units "deg":
116//
117// <srcblock>
118// ScalarColumnDesc<Double> scd("QuantumCol");
119// ...
120// // defines QuantumCol as a Quantum column with fix Units "deg"
121// TableQuantumDesc tqd(td, "QuantumCol", Unit("deg"));
122// </srcblock>
123//
124// This constructor stores the value for the Unit as a
125// column keyword. In situations, however, where it is necessary to
126// store a distinct Unit with each Quantum, it is necessary to define
127// an additional column for storing the Unit component of each Quantum.
128// The TableQuantumDesc constructor for this takes the name of
129// the Unit column as
130// a parameter. Hence an additional column must be defined for storing the
131// Units and its type must be string. The following
132// example shows how to set up a Quantum column with support for Quantum
133// unit variability:
134//
135// <srcblock>
136// // the quanta values stored here
137// ScalarColumnDesc<Double> scd("QuantumCol");
138// // a String column for the Units
139// ScalarColumnDesc<String> scd("QuantumUnitCol");
140// ...
141// TableQuantumDesc tqd(td, "QuantumCol", "QuantumUnitCol");
142// </srcblock>
143//
144// One further consideration is that for Array Quantum Columns it is
145// necessary to
146// decide on a level of granularity for the Unit storage you would like.
147// In Array Quantum columns it is possible to store a distinct Unit per row or
148// per array element per row. This distinction is established when the
149// Unit column is declared. Defining a ScalarColumn for Units specifies per
150// row variability, that is, each row in an array column of Quanta will
151// have the same unit. Alternatively, use of an ArrayColumn for the Unit
152// column
153// specifies that every Quantum stored will have its unit stored as well.
154// In both cases the Unit column's type must be String. The following
155// defines an Array Quantum Column with per row Unit storage:
156//
157// <srcblock>
158// // for the Quanta values
159// ArrayColumnDesc<Double> scd("ArrayQuantumCol");
160// // per row storage of units
161// ScalarColumnDesc<String> scd("QuantumUnitCol");
162// ...
163// TableQuantumDesc tqd(td, "ArrayQuantumCol", "QuantumUnitCol");
164// </srcblock>
165//
166// And finally, an array Quantum Column with an Array Unit Column:
167//
168// <srcblock>
169// // for Quanta values
170// ArrayColumnDesc<Double> scd("ArrayQuantumCol");
171// // per element storage of Units
172// ArrayColumnDesc<String> scd("ArrayUnitCol");
173// ...
174// TableQuantumDesc tqd(td, "ArrayQuantumCol", "ArrayUnitCol");
175// </srcblock>
176//
177//
178// After constructing an TableQuantumDesc object use of the write() member
179// updates the Table Descriptor or Table object.
180// <linkto class="ScalarQuantColumn">(RO)ScalarQuantColumn&lt;T&gt;</linkto>
181// and
182// <linkto class="ArrayQuantColumn">(RO)ArrayQuantColumn&lt;T&gt;</linkto>
183// are subsequently used to read-only and read/write access the Quantum
184// Columns.
185// </synopsis>
186//
187// <example>
188// <srcblock>
189// // create a table descriptor as normal
190// TableDesc td("measTD", "1", TableDesc::New);
191// td.comment() = "A table containing measures and quantums";
192//
193// // This example sets up a Quantum<Complex> column but any valid Quantum
194// // type can be specified. However, the type of the Quantums to be
195// // stored must match the type of the underlying table column.
196// ScalarColumnDesc<Complex> tcdQCplx("Quant", "A quantum complex column");
197//
198// // For a Quantum array column an ArrayColumnDesc is first defined
199// ArrayColumnDesc<Double> tcdQDoub("QuantArray", "A quantum array col");
200//
201// // The QuantumArray column has variable units. A string is needed
202// // for these. This could be done in two ways depending on what is
203// // wanted. Units can vary per element of array per row or
204// // just per row. In the first instance an ArrayColumn<String> would be
205// // require. Here we want to vary units only per row.
206// ScalarColumnDesc<String> tcdUnits("VarQuantUnits", "Quantum units");
207//
208// // Add the columns to the Table Descriptor
209// td.addColumn(tcdQplx);
210// td.addColumn(tcdQDoub);
211// td.addColumn(tcdUnits);
212//
213// // Create the TableQuantumDesc with units "deg" and an Array Quantum
214// // Column with per row Unit granularity
215// TableQuantumDesc tqdS(td, "Quant", unit("deg"));
216// TableQuantumDesc tqdA(td, "QuantArray", "VarQuantUnits");
217//
218// // Update the Table Descriptor
219// tqdA.write(td);
220// tqdS.write(td);
221//
222// // Setup and create the new table as usual.
223// SetupNewTable newtab("mtab", td, Table::New);
224// Table qtab(newtab);
225//
226// // Now ScalarQuantColumn and ArrayQuantColumn objects could be
227// // constructed to access the columns...
228// </srcblock>
229// Note that writing the Quantum description could also be done
230// after the table is created. It is meaningless in this case, but
231// it is useful when columns (to be used for quanta) are added to
232// an already existing table.
233// be used as
234// <srcblock>
235// // Setup and create the new table as usual.
236// SetupNewTable newtab("mtab", td, Table::New);
237// Table qtab(newtab);
238//
239// // Update the Table Descriptor
240// tqdA.write(qtab);
241// tqdS.write(qtab);
242// </srcblock>
243// </example>
244
245// <motivation>
246// This class assists in the definition of a Quantum Table Column.
247// </motivation>
248
249// <thrown>
250// <li>AipsError during construction if the column doesn't exist.
251// <li>AipsError during construction if the unit's column doesn't
252// exist (when variable units).
253// <li>AipsError during construction if the type of the variable unit's
254// column is not String.
255// <li>AipsError during a reconstruct if the column doesn't have a Unit.
256// </thrown>
257
258// # <todo asof="$DATE:$">
259// # A List of bugs, limitations, extensions or planned refinements.
260// # </todo>
261
263 public:
264 // Constructs a Quantum column descriptor with null units (Unit == "").
265 // The column should have already been added to the TableDesc.
266 // An exception is thrown if the column doesn't exist.
267 TableQuantumDesc(const TableDesc& td, const String& column);
268
269 // Constructs a Quantum column descriptor with the specified Quantum unit.
270 // The column should have already been added to the TableDesc.
271 // An exception is thrown if the column doesn't exist.
272 TableQuantumDesc(const TableDesc& td, const String& column, const Unit&);
273
274 // Constructs a Quantum column descriptor with the specified Quantum units.
275 // The column should have already been added to the TableDesc.
276 // An exception is thrown if the column doesn't exist.
277 // <group>
278 TableQuantumDesc(const TableDesc& td, const String& column, const Vector<String>& unitNames);
279 TableQuantumDesc(const TableDesc& td, const String& column, const Vector<Unit>&);
280 // </group>
281
282 // Constructs a Quantum column descriptor with variable units stored in
283 // unitCol. Both the quantum and unit column should exist in the
284 // TableDesc.
285 // # Note that the Char* constructor is needed, otherwise the compiler
286 // # cannot choose between String and Unit.
287 //<group>
288 TableQuantumDesc(const TableDesc& td, const String& column, const String& unitCol);
289 TableQuantumDesc(const TableDesc& td, const String& column, const Char* unitCol);
290 //</group>
291
292 // Copy constructor (copy semantics).
294
296
297 // Reconstructs a previously constructed TableQuantumDesc.
298 static TableQuantumDesc* reconstruct(const TableDesc& td, const String& column);
299
300 // Assignment.
302
303 // Returns the Quantum column descriptor's units. A empty vector is
304 // returned if units have not been specified. This could be because the null
305 // unit constructor was used or because the units are variable.
306 const Vector<String>& getUnits() const { return itsUnitsName; }
307
308 // Returns True if descriptor set for variable units (one per row)
309 Bool isUnitVariable() const { return (!itsUnitsColName.empty()); }
310
311 // Returns the name of the quantum column.
312 const String& columnName() const { return itsColName; }
313
314 // Returns the name of the units column (an empty String is returned
315 // if the units are not variable).
316 const String& unitColumnName() const { return itsUnitsColName; }
317
318 // Makes the TableQuantumDesc persistent (updates the Table Descriptor).
319 // <group>
321 void write(Table&);
322 // </group>
323
324 // Does this column contain table quanta?
325 static Bool hasQuanta(const TableColumn& column);
326
327 private:
328 // Name of column which stores the Quantum's values.
330 // The Quantum's unit as a string.
332 // Name of units column if units are variable.
334
335 // Write the actual keywords.
336 void writeKeys(TableRecord& columnKeyset);
337
338 // Throw an exception if the quantum column doesn't exist.
339 void checkColumn(const TableDesc& td) const;
340
341 // Throw an exception if the variable units column isn't a string column.
342 void checkUnitsColumn(const TableDesc& td) const;
343};
344
345} // namespace casacore
346
347#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
TableQuantumDesc(const TableDesc &td, const String &column, const String &unitCol)
Constructs a Quantum column descriptor with variable units stored in unitCol.
Vector< String > itsUnitsName
The Quantum's unit as a string.
void writeKeys(TableRecord &columnKeyset)
Write the actual keywords.
String itsUnitsColName
Name of units column if units are variable.
void write(TableDesc &)
Makes the TableQuantumDesc persistent (updates the Table Descriptor).
static Bool hasQuanta(const TableColumn &column)
Does this column contain table quanta?
TableQuantumDesc(const TableDesc &td, const String &column, const Char *unitCol)
TableQuantumDesc & operator=(const TableQuantumDesc &that)
Assignment.
const Vector< String > & getUnits() const
Returns the Quantum column descriptor's units.
TableQuantumDesc(const TableDesc &td, const String &column, const Unit &)
Constructs a Quantum column descriptor with the specified Quantum unit.
const String & unitColumnName() const
Returns the name of the units column (an empty String is returned if the units are not variable).
String itsColName
Name of column which stores the Quantum's values.
TableQuantumDesc(const TableQuantumDesc &that)
Copy constructor (copy semantics).
const String & columnName() const
Returns the name of the quantum column.
void checkUnitsColumn(const TableDesc &td) const
Throw an exception if the variable units column isn't a string column.
TableQuantumDesc(const TableDesc &td, const String &column, const Vector< String > &unitNames)
Constructs a Quantum column descriptor with the specified Quantum units.
void checkColumn(const TableDesc &td) const
Throw an exception if the quantum column doesn't exist.
TableQuantumDesc(const TableDesc &td, const String &column)
Constructs a Quantum column descriptor with null units (Unit == "").
static TableQuantumDesc * reconstruct(const TableDesc &td, const String &column)
Reconstructs a previously constructed TableQuantumDesc.
TableQuantumDesc(const TableDesc &td, const String &column, const Vector< Unit > &)
Bool isUnitVariable() const
Returns True if descriptor set for variable units (one per row).
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
char Char
Definition aipstype.h:44