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