casacore
Loading...
Searching...
No Matches
MSTable.h
Go to the documentation of this file.
1//# MSTable.h: A Table to hold astronomical data (a set of Measurements)
2//# Copyright (C) 1996,1997,2000,2001,2002
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 MS_MSTABLE_H
27#define MS_MSTABLE_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Utilities/DataType.h>
31#include <casacore/tables/Tables/Table.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <casacore/tables/Tables/ColumnDesc.h>
34#include <map>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations, more could be if they weren't part of the
39//# static classes
40class TableRecord;
41template <class T> class Block;
42
43
44// <summary>
45// A struct holding the maps used in MSTable.
46// </summary>
48{
49 // ColEnum -> name
50 std::map<Int, String> columnMap_p;
51 // ColEnum -> DataType
52 std::map<Int, Int> colDTypeMap_p;
53 // ColEnum -> comment string
54 std::map<Int, String> colCommentMap_p;
55 // ColEnum -> UNIT string
56 std::map<Int, String> colUnitMap_p;
57 // ColEnum -> MEASURE_TYPE string
58 std::map<Int, String> colMeasureTypeMap_p;
59 // KeyEnum -> name
60 std::map<Int, String> keywordMap_p;
61 // KeyEnum -> DataType
62 std::map<Int, Int> keyDTypeMap_p;
63 // KeyEnum -> comment string
64 std::map<Int, String> keyCommentMap_p;
65 // The required TableDesc
67
68 // Convert a name to a ColEnum or KeyEnum.
69 Int columnType (const String& name) const
70 { return mapType (columnMap_p, name); }
71 Int keywordType (const String& name) const
72 { return mapType (keywordMap_p, name); }
73 Int mapType (const std::map<Int,String>&, const String& name) const;
74};
75
76
77// <summary>
78// A Table intended to hold astronomical data
79// </summary>
80
81// <use visibility=export>
82
83// <reviewed reviewer="Bob Garwood" date="1997/02/01" tests="" demos="">
84
85// <prerequisite>
86// <li> <linkto module="Tables:description">Tables</linkto> module
87// </prerequisite>
88//
89// <etymology>
90// The MSTable is the base class for all MeasurementSet Tables, hence the
91// name.
92// </etymology>
93//
94// <synopsis>
95// A MSTable is a Table. Most operations on a MSTable are
96// Table operations. See the <linkto module="Tables:description">Tables</linkto>
97// module for a list of those operations. The member functions provided by this
98// class are primarily convenience functions to help users follow the
99// agreed upon column and keyword naming conventions. They are useful when
100// creating a Table following the MSTable conventions from
101// scratch as well as when creating the column objects to access those
102// columns. All actual MeasurementSet Tables will be derived from this class.
103//
104// The standard way of accessing
105// table columns is through Strings. Mistakes in typing the column
106// name will not be caught at compile time (and may not be caught at
107// run time). We have therefore decided to use an enumeration
108// to specify columns so that many mistakes will be caught at compile
109// time. This requires functions to map to and from this enumeration
110// to the strings that are ultimately used.
111//
112// Upon destruction, the table is checked to see that all
113// required columns and keywords are still present.
114// If not an exception is thrown. (Not a good idea!) Nevertheless,
115// the table will be flushed to disk if it is writable -
116// preserving its state.
117//
118// </synopsis>
119//
120// <example>
121// For examples of use, see the MeasurementSet class.
122// </example>
123//
124// <motivation>
125// The Table module is more than adequate as a container of data.
126// However, in order for applications to be useful with data from
127// different sources, some conventions need to be adopted in the use
128// of Tables to store data. The MSTable provides the framework for
129// these conventions and conversion functions. The actual definitions
130// of columns and keywords are found in the derived classes and their
131// "enum" base class (e.g. MSAntenna and MSAntennaEnums).
132// </motivation>
133//
134// <todo asof="1996/2/22">
135// <li> referenceCopy() should be more flexible with the storage managers used
136// for the columns which are not merely references.
137// <li> When ForwardColumnEngine is fixed so that it can deal with
138// tables already in the cache, modify the test program. It may also
139// be necessary to modify referenceCopy().
140// </todo>
141
142template <class MSEnum> class MSTable : public Table
143{
144public:
145 // Define the column and keyword enuym types.
146 typedef typename MSEnum::PredefinedColumns ColEnum;
147 typedef typename MSEnum::PredefinedKeywords KeyEnum;
148
149 // ColEnum convenience functions
150 // <group name=columns>
151 // check to see if a column exists
152 Bool isColumn(ColEnum which) const;
154 // check to see if a column is writable
155 // <group>
159 Bool isColumnWritable (uInt columnIndex) const
160 { return Table::isColumnWritable(columnIndex); }
161 // </group>
162
163 // Information about scalar vs array of a column
164 // <group>
165 Bool isScalar(ColEnum which) const;
166 Bool isArray(ColEnum which) const;
167 // </group>
168
169 // Return the UNIT keyword value associated with the specified column
170 // <group>
171 const String& unit(const String& which) const;
172 const String& unit(ColEnum which) const
173 { return unit(columnName(which)); }
174 // </group>
175
176 // Convert a ColEnum to the actual column name.
177 static const String& columnName(ColEnum which);
178 // Convert a name to a ColEnum
179 static ColEnum columnType(const String &name);
180 // return the data type for a given ColEnum
181 static DataType columnDataType(ColEnum which);
182 // return the standard comment for a given ColEnum
184 // return the UNIT string for a given ColEnum
185 static const String& columnUnit(ColEnum which);
186 // return the MEASURE_TYPE string for a given ColEnum
187 static const String& columnMeasureType(ColEnum which);
188
189 // add a column to a TableDesc
190 // An exception is thrown for an invalid data type. This indicates a
191 // programming error in this class when this occurs.
192 // For Array columns you can optionally define the dimension here.
193 // For Measure columns you can define a variable reference column.
194 // <thrown>
195 // <li> AipsError
196 // </thrown>
197 static void addColumnToDesc(TableDesc & tabDesc, ColEnum which,
198 Int ndim=-1,const String& refCol="");
199 // add a column to a TableDesc, defining the shape and setting
200 // the ColumnDesc option (Fixed, Undefined, Direct)
201 // For Measure columns you can define a variable reference column.
202 static void addColumnToDesc(TableDesc & tabDesc, ColEnum which,
203 const IPosition& shape, ColumnDesc::Option option,
204 const String& refCol="");
206 Int ndim=-1,const String& refCol="");
207 // add a column to a TableDesc, defining the shape and setting
208 // the ColumnDesc option (Fixed, Undefined, Direct)
209 // For Measure columns you can define a variable reference column.
211 const IPosition& shape, ColumnDesc::Option option,
212 const String& refCol="");
213
214 // </group>
215
216 // KeyEnum convenience functions
217 // <group name=keywords>
218 static const String& keywordName(KeyEnum which);
219 static KeyEnum keywordType(const String &name);
220 static DataType keywordDataType(KeyEnum which);
223 // check to see if a keyword exists
224 Bool isKeyword(KeyEnum which) const;
225
226 // add a keyword to a TableDesc
227 // An exception is thrown for an invalid data type. This indicates a
228 // missing data type in the code..
229 // <thrown>
230 // <li> AipsError
231 // </thrown>
234
235 // </group>
236
237 // tableDesc convenience functions
238 // <group>
239
240 // check that a TableDesc is valid
241 static Bool validate(const TableDesc& tabDesc);
242
243 // check that the keyword set is valid
244 static Bool validate(const TableRecord& tabKeySet);
245
246 // validate self (make sure that this MS is valid)
247 Bool validate() const
248 { return this->isNull() ? False : validate(this->tableDesc());}
249
250 // return the required table description
252
253 // Add the compress option for the given column to the TableDesc.
254 // It can only be used for a Float or a Complex column.
255 // For complex columns the type determines which CompressComplex
256 // engine is used. "SD" means that CompressComplexSD is used; otherwise
257 // CompressComplex is used.
258 static void addColumnCompression (TableDesc& td, ColEnum which,
259 Bool autoScale = True,
260 const String& type = String());
261
262 // </group>
263
264protected:
265 // These constructors mirror the Table ones
266 // <group name=tableLikeConstructors>
267 // Default constructor for use by derived classes
268 MSTable ();
271 TableOption option);
272 MSTable (const String &tableName, const String &tableDescName,
273 TableOption option);
274 MSTable (const String &tableName, const String &tableDescName,
276 MSTable (SetupNewTable &newTab, rownr_t nrrow,
277 Bool initialize);
278 MSTable (SetupNewTable &newTab, const TableLock& lockOptions, rownr_t nrrow,
279 Bool initialize);
280#ifdef HAVE_MPI
281 MSTable (MPI_Comm comm, SetupNewTable &newTab, rownr_t nrrow,
282 Bool initialize);
283 MSTable (MPI_Comm comm, SetupNewTable &newTab, const TableLock& lockOptions,
284 rownr_t nrrow, Bool initialize);
285#endif // HAVE_MPI
286 MSTable (const Table &table);
287 MSTable (const MSTable<MSEnum> &other);
288 // </group>
289 ~MSTable();
291 // Assignment operator, reference semantics
293
294 // Get the static struct containing all column and keyword mappings.
296
297 // Define an entry in the column maps
298 static void colMapDef(MSTableMaps& maps,
299 ColEnum col,
300 const String& colName,
301 DataType colType,
302 const String& colComment,
303 const String& colUnit="",
304 const String& colMeasureType="");
305
306 // Define an entry in the keyword maps
307 static void keyMapDef(MSTableMaps& maps,
308 KeyEnum key,
309 const String& keyName,
310 DataType keyType,
311 const String& keyComment);
312
313 // Return a table that references all columns in this table except for
314 // those given in writableColumns, those are empty and writable.
315 Table referenceCopy(const String& newTableName,
316 const Block<String>& writableColumns) const;
317
318 // Convert a ColEnum to the actual column name.
319 inline static
320 const String& columnName(const MSTableMaps& maps,
321 ColEnum which)
322 { return maps.columnMap_p.at(which); }
323
324 inline static
325 DataType columnDataType(const MSTableMaps& maps,
326 ColEnum which)
327 { return DataType(maps.colDTypeMap_p.at(which)); }
328
329 inline static
331 ColEnum which)
332 { return maps.colCommentMap_p.at(which); }
333
334 inline static
335 const String& columnUnit(const MSTableMaps& maps,
336 ColEnum which)
337 { return maps.colUnitMap_p.at(which); }
338
339 inline static
341 ColEnum which)
342 { return maps.colMeasureTypeMap_p.at(which); }
343
344 inline static
345 const String& keywordName(const MSTableMaps& maps,
346 KeyEnum which)
347 { return maps.keywordMap_p.at(which); }
348
349 inline static
350 DataType keywordDataType(const MSTableMaps& maps,
351 KeyEnum which)
352 { return DataType(maps.keyDTypeMap_p.at(which)); }
353
354 inline static
356 KeyEnum which)
357 { return maps.keyCommentMap_p.at(which); }
358
359};
360
361
362} //# NAMESPACE CASACORE - END
363
364
365//# Do not instantiate the templates automatically, because it means that the static
366//# in function getMaps() might be instantiated in many compilation units.
367//# The templates are instantiated in MSTable.cc.
368//#ifndef CASACORE_NO_AUTO_TEMPLATES
369//#include <casacore/ms/MeasurementSets/MSTable.tcc>
370//#endif //# CASACORE_NO_AUTO_TEMPLATES
371#endif
simple 1-D array
Definition Block.h:198
Option
Enumerate the possible column options.
Definition ColumnDesc.h:140
A Table intended to hold astronomical data
Definition MSTable.h:143
static const String & columnUnit(ColEnum which)
return the UNIT string for a given ColEnum
static void addColumnToDesc(TableDesc &tabDesc, ColEnum which, Int ndim=-1, const String &refCol="")
add a column to a TableDesc An exception is thrown for an invalid data type.
MSEnum::PredefinedKeywords KeyEnum
Definition MSTable.h:147
static DataType columnDataType(ColEnum which)
return the data type for a given ColEnum
MSTable(const String &tableName, const String &tableDescName, TableOption option)
static KeyEnum keywordType(const String &name)
static MSTableMaps & getMaps()
Get the static struct containing all column and keyword mappings.
MSTable(SetupNewTable &newTab, rownr_t nrrow, Bool initialize)
static void addColumnCompression(TableDesc &td, ColEnum which, Bool autoScale=True, const String &type=String())
Add the compress option for the given column to the TableDesc.
Bool isScalar(ColEnum which) const
Information about scalar vs array of a column.
MSTable & operator=(const MSTable< MSEnum > &)
Assignment operator, reference semantics.
static void addColumnToDesc(TableDesc &tabDesc, ColEnum which, const IPosition &shape, ColumnDesc::Option option, const String &refCol="")
add a column to a TableDesc, defining the shape and setting the ColumnDesc option (Fixed,...
static const TableDesc & requiredTableDesc()
return the required table description
const String & unit(const String &which) const
Return the UNIT keyword value associated with the specified column.
static void keyMapDef(MSTableMaps &maps, KeyEnum key, const String &keyName, DataType keyType, const String &keyComment)
Define an entry in the keyword maps.
MSTable(MPI_Comm comm, SetupNewTable &newTab, rownr_t nrrow, Bool initialize)
MSTable(MPI_Comm comm, SetupNewTable &newTab, const TableLock &lockOptions, rownr_t nrrow, Bool initialize)
MSTable(SetupNewTable &newTab, const TableLock &lockOptions, rownr_t nrrow, Bool initialize)
static const String & columnUnit(const MSTableMaps &maps, ColEnum which)
Definition MSTable.h:335
MSTable(const String &tableName, const TableLock &lockOptions, TableOption option)
Bool validate() const
validate self (make sure that this MS is valid)
Definition MSTable.h:247
static const String & columnStandardComment(ColEnum which)
return the standard comment for a given ColEnum
Bool isKeyword(KeyEnum which) const
check to see if a keyword exists
const String & unit(ColEnum which) const
Definition MSTable.h:172
static const String & columnStandardComment(const MSTableMaps &maps, ColEnum which)
Definition MSTable.h:330
static DataType keywordDataType(const MSTableMaps &maps, KeyEnum which)
Definition MSTable.h:350
static void addKeyToDesc(TableDesc &, KeyEnum key)
add a keyword to a TableDesc An exception is thrown for an invalid data type.
Bool isColumnWritable(ColEnum which) const
check to see if a column is writable
MSTable(const Table &table)
static ColEnum columnType(const String &name)
Convert a name to a ColEnum.
static void colMapDef(MSTableMaps &maps, ColEnum col, const String &colName, DataType colType, const String &colComment, const String &colUnit="", const String &colMeasureType="")
Define an entry in the column maps.
Bool isColumnWritable(const String &columnName) const
Definition MSTable.h:157
static const String & keywordStandardComment(KeyEnum which)
Bool isColumn(ColEnum which) const
ColEnum convenience functions
static void addColumnToDesc(MSTableMaps &, ColEnum which, Int ndim=-1, const String &refCol="")
Table referenceCopy(const String &newTableName, const Block< String > &writableColumns) const
Return a table that references all columns in this table except for those given in writableColumns,...
static const String & keywordStandardComment(const MSTableMaps &maps, KeyEnum which)
Definition MSTable.h:355
MSTable(const MSTable< MSEnum > &other)
static const String & columnMeasureType(const MSTableMaps &maps, ColEnum which)
Definition MSTable.h:340
static const String & keywordName(const MSTableMaps &maps, KeyEnum which)
Definition MSTable.h:345
MSEnum::PredefinedColumns ColEnum
Define the column and keyword enuym types.
Definition MSTable.h:146
static const String & columnName(ColEnum which)
Convert a ColEnum to the actual column name.
static const String & keywordName(KeyEnum which)
KeyEnum convenience functions
MSTable(const String &tableName, TableOption option)
static const String & columnMeasureType(ColEnum which)
return the MEASURE_TYPE string for a given ColEnum
static Bool validate(const TableRecord &tabKeySet)
check that the keyword set is valid
Bool isColumnWritable(uInt columnIndex) const
Definition MSTable.h:159
static void addColumnToDesc(MSTableMaps &, ColEnum which, const IPosition &shape, ColumnDesc::Option option, const String &refCol="")
add a column to a TableDesc, defining the shape and setting the ColumnDesc option (Fixed,...
static Bool validate(const TableDesc &tabDesc)
tableDesc convenience functions
Bool isArray(ColEnum which) const
static void addKeyToDesc(MSTableMaps &, KeyEnum key)
MSTable()
These constructors mirror the Table ones
static const String & columnName(const MSTableMaps &maps, ColEnum which)
Convert a ColEnum to the actual column name.
Definition MSTable.h:320
static DataType columnDataType(const MSTableMaps &maps, ColEnum which)
Definition MSTable.h:325
static DataType keywordDataType(KeyEnum which)
MSTable(const String &tableName, const String &tableDescName, const TableLock &lockOptions, TableOption option)
Create a new table - define shapes, data managers, etc.
String: the storage and methods of handling collections of characters.
Definition String.h:223
const TableLock & lockOptions() const
Get the locking options.
Definition Table.h:1115
Bool isNull() const
Test if the object is null, i.e.
Definition Table.h:480
Bool isColumnWritable(const String &columnName) const
Test if the given column is writable.
Definition Table.h:1138
const TableDesc & tableDesc() const
Get the table description.
Definition Table.h:1180
const String & tableName() const
Get the table name.
Definition Table.h:1192
TableOption
Define the possible options how a table can be opened.
Definition Table.h:171
TableExprNode key(const String &keywordName) const
Create a TableExprNode object for a column or for a keyword in the table keyword set.
TableExprNode col(const String &columnName) const
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
unsigned int uInt
Definition aipstype.h:49
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
int Int
Definition aipstype.h:48
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
Int keywordType(const String &name) const
Definition MSTable.h:71
TableDesc requiredTD_p
The required TableDesc.
Definition MSTable.h:66
std::map< Int, String > keyCommentMap_p
KeyEnum -> comment string.
Definition MSTable.h:64
std::map< Int, Int > keyDTypeMap_p
KeyEnum -> DataType.
Definition MSTable.h:62
std::map< Int, Int > colDTypeMap_p
ColEnum -> DataType.
Definition MSTable.h:52
std::map< Int, String > keywordMap_p
KeyEnum -> name.
Definition MSTable.h:60
std::map< Int, String > colMeasureTypeMap_p
ColEnum -> MEASURE_TYPE string.
Definition MSTable.h:58
std::map< Int, String > colCommentMap_p
ColEnum -> comment string.
Definition MSTable.h:54
std::map< Int, String > colUnitMap_p
ColEnum -> UNIT string.
Definition MSTable.h:56
Int mapType(const std::map< Int, String > &, const String &name) const
Int columnType(const String &name) const
Convert a name to a ColEnum or KeyEnum.
Definition MSTable.h:69
std::map< Int, String > columnMap_p
ColEnum -> name.
Definition MSTable.h:50