casacore
Loading...
Searching...
No Matches
TableMeasRefDesc.h
Go to the documentation of this file.
1//# TableMeasRefDesc.h: Definition of a Measure Reference in a Table.
2//# Copyright (C) 1997,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_TABLEMEASREFDESC_H
27#define MEASURES_TABLEMEASREFDESC_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/measures/TableMeasures/TableMeasOffsetDesc.h>
32#include <casacore/casa/Quanta/Unit.h>
33#include <casacore/casa/Arrays/Vector.h>
34#include <casacore/casa/BasicSL/String.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39class TableMeasDescBase;
40class Table;
41class TableDesc;
42class TableRecord;
43
44
45// <summary>
46// Definition of a Measure Reference in a Table.
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//# Classes you should understand before using this one.
56// <li> <linkto module=Measures>Measures</linkto>
57// <li> <linkto module=Tables>Tables</linkto>
58// <li> <linkto class=TableMeasDesc>TableMeasDesc</linkto>
59// </prerequisite>
60
61// <synopsis>
62// TableMeasRefDesc is a class for setting up the MeasRef
63// component of a TableMeasDesc in the TableMeasures system. With the aid
64// of a
65// TableMeasRefDesc the following possibilities for defining a Measure
66// column's reference exist:
67// <ul>
68// <li> a fixed, non-variable, reference code, where all Measures in a
69// column are to have the same reference code.
70// <li> a unique (and probably different) reference code stored in each row.
71// <li> a unique reference code stored in each array element per
72// (Array)column row.
73// </ul>
74// For each of the above options an offset component can be specified
75// along with a reference code. When a Measure offset is required a
76// <linkto class="TableMeasOffsetDesc">TableMeasOffsetDesc</linkto> is
77// supplied as an argument to the TableMeasRefDesc constructor.
78// With references containing an offset component either component can be set
79// to be variable or fixed independently of the other.
80//
81// <note role=tip>
82// It is not necessary to specify a Reference when defining a
83// Measure column. In such cases the Measures retrieved from the column
84// will have the default reference for the type of Measure stored in the
85// column.
86// </note>
87//
88// A fixed reference code is trivially stored as part of the column
89// keywords in the Measure column but a variable reference code requires
90// its own column. A Scalar or Array column can be used dependent on your
91// needs but its type must always be either Int or String. Note that it is
92// legal to specify a Scalar
93// reference column for use with an ArrayMeasColumn. In such cases a single
94// reference code will be stored per array (row) of Measures. However,
95// attempting to associate an Array column for references with a
96// ScalarMeasColumn will generate an exception.
97// <note>
98// Because the reference codes stored are the enums defined in the Measures
99// classes, it is possible that they change over time. The type strings,
100// however, wille never change. Therefore the reference codes and types
101// valid at the time of the table creation, are stored in the column keywords
102// if the reference codes are kept in an integer column.
103// <br>
104// This has only been added in March 2007, but is fully backward compatible.
105// Older tables will get the codes and types stored when accessed for
106// read/write.
107// </note>
108//
109// <note role=caution>
110// When storing Measures into a Measure column with a fixed reference code
111// the reference code component of the Measures stored is
112// ignored.
113// </note>
114// </synopsis>
115
116// <example>
117//<ol>
118// <li>Simplest kind of TableMeasRefDesc (apart from not specifying one at
119// all) is a fixed reference code. All Measures subsequently
120// retrieved from the column will have the reference MEpoch::LAST.
121// <srcblock>
122// // measure reference column
123// TableMeasRefDesc reference(MEpoch::LAST);
124// </srcblock>
125// <li>A variable reference code requires its own Int column.
126// <srcblock>
127// // An int column for the variable references.
128// ScalarColumnDesc<Int> cdRefCol("refCol", "Measure reference column");
129// td.addColumn(cdRefCol);
130// ...
131// // create the Measure reference descriptor
132// TableMeasRefDesc varRef(td, "refCol");
133// </srcblock>
134// <li>A fix Measure reference code with a fixed Offset
135// <srcblock>
136// // Create the Offset descriptor
137// MEpoch offset(MVEpoch(MVTime(1996, 5, 17, (8+18./60.)/24.))
138// TableMeasOffsetDesc offsetDesc(offset);
139// // create the Measure reference descriptor
140// TableMeasRefDesc varRef(MEpoch::LAST, offsetDesc);
141// </srcblock>
142//</ol>
143// For an example of the use of a TableMeasRefDesc in the context of a full
144// TableMeasDesc declaration see class
145// <linkto class="TableMeasDesc">TableMeasDesc</linkto>.
146// </example>
147
148// <motivation>
149// Creating the required keyword for the definition of a Measure
150// in a Table is somewhat complicated. This class assists in that
151// process.
152// </motivation>
153//
154// <thrown>
155// <li>AipsError if the specified column doesn't exist or its type is
156// not Int or String.
157// </thrown>
158//
159
160//# <todo asof="$DATE:$">
161//# A List of bugs, limitations, extensions or planned refinements.
162//# </todo>
163
164
166{
167public:
168 // Define a fixed MeasRef by supplying its reference code
169 // Optionally a Measure offset can be specified.
170 // The reference code and offset should not need a reference frame.
171 // <group>
172 explicit TableMeasRefDesc (uInt refCode = 0);
174 // </group>
175
176 // Define a variable reference by supplying the name of the column
177 // in which the reference is to be stored. Either an <src>Int</src> or
178 // <src>String</src> column can be specified. This determines how
179 // references are stored. <src>Int</src> columns are likely to be
180 // faster but storing
181 // references as <src>Strings</src> may be useful if there is a need to
182 // browse tables manually. Optionally supply a Measure offset.
183 // The reference code and offset should not need a reference frame.
184 // <group>
185 TableMeasRefDesc (const TableDesc&, const String& column);
186 TableMeasRefDesc (const TableDesc&, const String& column,
187 const TableMeasOffsetDesc&);
188 // </group>
189
190 // Reconstruct the object from the MEASINFO record.
191 // Not useful for the public.
193 const Table&,
194 const MeasureHolder& measHolder,
195 const TableMeasDescBase&);
196
197 // Copy constructor (copy semantics)
199
201
202 // Assignment operator (copy semantics).
204
205 // Return the reference code.
207 { return itsRefCode; }
208
209 // Is the reference variable?
211 { return (! itsColumn.empty()); }
212
213 // Return the name of its variable reference code column.
214 const String& columnName() const
215 { return itsColumn; }
216
217 // Is the reference code variable and stored in an integer column?
219 { return itsRefCodeColInt; }
220
221 // Do the keywords contain the reference codes and types.
222 // For old tables this might not be the case.
224 { return itsHasRefTab; }
225
226 // Returns True if the reference has an offset.
228 { return (itsOffset != 0); }
229
230 // Returns True if the offset is variable.
232 { return (itsOffset != 0 ? itsOffset->isVariable() : False); }
233
234 // Returns True is the offset is variable and it is an ArrayMeasColumn.
236 { return (itsOffset != 0 ? itsOffset->isArray() : False); }
237
238 // Return the fixed Measure offset.
239 // It does not test if the offset is defined; hasOffset() should be used
240 // for that purpose.
241 const Measure& getOffset() const
242 { return itsOffset->getOffset(); }
243
244 // Return the name of the Measure offset column.
245 // An empty string is returned if no variable offset is used.
247 { return itsOffset->columnName(); }
248
249 // Reset the refCode or offset.
250 // It overwrites the value used when defining the TableMeasDesc.
251 // It is only possible if it was defined as fixed for the entire column.
252 // <group>
253 void resetRefCode (uInt refCode);
254 void resetOffset (const Measure& offset);
255 // </group>
256
257 // Make the Measure value descriptor persistent. Normally would not be
258 // called by the user directly.
259 // <group>
260 void write (TableDesc&, TableRecord& measInfo, const TableMeasDescBase&);
261 void write (Table&, TableRecord& measInfo, const TableMeasDescBase&);
262 // </group>
263
264 // Initialize the table reference codes and types and
265 // the maps (mapping a code onto itself).
266 void initTabRef (const MeasureHolder& measHolder);
267
268 // Reference codes can be persistent in tables.
269 // Because their enum values can change, a mapping of current table
270 // to table value is maintained. The mapping is created using their
271 // never-changing string representations.
272 // These functions convert current refcode to and from table refcode.
273 // <group>
274 uInt tab2cur (uInt tabRefCode) const;
275 uInt cur2tab (uInt curRefCode) const;
276 // </group>
277
278 // Set the function used to get all reference codes for a MeasureHolder.
279 // This is not really needed for normal practice, but makes it possible
280 // to add extra codes when testing.
281 // <br> The default function simply calls MeasureHolder.asMeasure.allTypes.
282 // <group>
283 typedef void TypesFunc (Vector<String>& types,
284 Vector<uInt>& codes, const MeasureHolder&);
285 static void setTypesFunc (TypesFunc* func)
286 { theirTypesFunc = func; }
287 static void defaultTypesFunc (Vector<String>& types,
288 Vector<uInt>& codes, const MeasureHolder&);
290 // </group>
291
292private:
294 // The name of column containing its variable references.
296 // Is the reference code column a string column?
298 // Do the keywords contain the reference codes and types?
300 //# Its reference offset.
302 //# Define the vectors holding the measref codes and types.
303 //# These are the codes as used in the table, which might be different
304 //# from the current values.
307 //# Define the mappings of table measref codes to current ones and back.
308 //# There are only filled in and used if a variable reference code is used.
311
312 // Fill the reference code mappings for table<->current.
313 // <group>
315 void fillTabRefMap (const MeasureHolder& measHolder);
317 const Vector<uInt>& codesf,
318 const Vector<String>& typesf,
319 Vector<uInt>& codest,
320 Vector<String>& typest,
321 Int maxnr);
322 // </group>
323
324 // Write the actual keywords.
325 void writeKeys (TableRecord& measInfo,
326 const TableMeasDescBase& measDesc);
327
328 // Throw an exception if the column doesn't exist or is of the
329 // wrong type.
330 void checkColumn (const TableDesc& td);
331};
332
333
334
335} //# NAMESPACE CASACORE - END
336
337#endif
simple 1-D array
Definition Block.h:198
String: the storage and methods of handling collections of characters.
Definition String.h:223
Bool empty() const
Test for empty.
Definition String.h:375
const String & columnName() const
Gets the name of the column which stores the variable offset.
const Measure & getOffset() const
Get the (non-variable) measure offset for this column.
Bool isArray() const
Returns True if the offset varies per array element.
Bool isVariable() const
Returns True if the offset varies per row.
String itsColumn
The name of column containing its variable references.
TableMeasRefDesc(const TableDesc &, const String &column)
Define a variable reference by supplying the name of the column in which the reference is to be store...
TableMeasRefDesc(const TableDesc &, const String &column, const TableMeasOffsetDesc &)
Bool isRefCodeVariable() const
Is the reference variable?
Bool hasRefTab() const
Do the keywords contain the reference codes and types.
TableMeasRefDesc & operator=(const TableMeasRefDesc &that)
Assignment operator (copy semantics).
const Measure & getOffset() const
Return the fixed Measure offset.
void write(TableDesc &, TableRecord &measInfo, const TableMeasDescBase &)
Make the Measure value descriptor persistent.
uInt getRefCode() const
Return the reference code.
void fillTabRefMap(const MeasureHolder &measHolder)
Bool isOffsetArray() const
Returns True is the offset is variable and it is an ArrayMeasColumn.
static void defaultTypesFunc(Vector< String > &types, Vector< uInt > &codes, const MeasureHolder &)
void initTabRef(const MeasureHolder &measHolder)
Initialize the table reference codes and types and the maps (mapping a code onto itself).
uInt cur2tab(uInt curRefCode) const
const String & columnName() const
Return the name of its variable reference code column.
Bool itsHasRefTab
Do the keywords contain the reference codes and types?
void write(Table &, TableRecord &measInfo, const TableMeasDescBase &)
Bool isOffsetVariable() const
Returns True if the offset is variable.
TableMeasRefDesc(uInt refCode=0)
Define a fixed MeasRef by supplying its reference code Optionally a Measure offset can be specified.
void checkColumn(const TableDesc &td)
Throw an exception if the column doesn't exist or is of the wrong type.
TableMeasRefDesc(const TableMeasRefDesc &that)
Copy constructor (copy semantics)
TableMeasOffsetDesc * itsOffset
const String & offsetColumnName() const
Return the name of the Measure offset column.
void writeKeys(TableRecord &measInfo, const TableMeasDescBase &measDesc)
Write the actual keywords.
void initTabRefMap()
Fill the reference code mappings for table<->current.
TableMeasRefDesc(uInt refCode, const TableMeasOffsetDesc &)
TableMeasRefDesc(const TableRecord &measInfo, const Table &, const MeasureHolder &measHolder, const TableMeasDescBase &)
Reconstruct the object from the MEASINFO record.
Bool hasOffset() const
Returns True if the reference has an offset.
void resetRefCode(uInt refCode)
Reset the refCode or offset.
uInt fillMap(Block< Int > &f2t, const Vector< uInt > &codesf, const Vector< String > &typesf, Vector< uInt > &codest, Vector< String > &typest, Int maxnr)
static void setTypesFunc(TypesFunc *func)
static TypesFunc * theirTypesFunc
uInt tab2cur(uInt tabRefCode) const
Reference codes can be persistent in tables.
void resetOffset(const Measure &offset)
Bool isRefCodeColumnInt() const
Is the reference code variable and stored in an integer column?
Bool itsRefCodeColInt
Is the reference code column a string column?
void TypesFunc(Vector< String > &types, Vector< uInt > &codes, const MeasureHolder &)
Set the function used to get all reference codes for a MeasureHolder.
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
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40