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