00001 //# MSTableImpl.h: Helper class to implement common functions for MS Tables 00002 //# Copyright (C) 1996,2000,2001,2002 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id$ 00028 00029 #ifndef MS_MSTABLEIMPL_H 00030 #define MS_MSTABLEIMPL_H 00031 00032 //# Includes 00033 #include <casacore/casa/aips.h> 00034 #include <casacore/casa/Utilities/DataType.h> 00035 #include <casacore/tables/Tables/Table.h> 00036 #include <casacore/casa/Containers/SimOrdMap.h> 00037 #include <casacore/casa/BasicSL/String.h> 00038 #include <casacore/tables/Tables/TableDesc.h> 00039 #include <casacore/casa/Utilities/Fallible.h> 00040 #include <casacore/casa/Arrays/Vector.h> 00041 #include <casacore/casa/OS/Mutex.h> 00042 00043 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00044 00045 //# Forward declarations 00046 class SetupNewTable; 00047 00048 // <summary> 00049 // An implementation class for the MeasurementSet to share code. 00050 // </summary> 00051 00052 // <use visibility=local> 00053 00054 // <reviewed reviewer="Bob Garwood" date="1997/02/01" tests="" demos=""> 00055 00056 // <prerequisite> 00057 // <li> <linkto class=MeasurementSet:description">MeasurementSet</linkto> 00058 // </prerequisite> 00059 // 00060 // <etymology> 00061 // The MSTableImpl implements non-templated static functions shared by 00062 // all MSTable objects. 00063 // </etymology> 00064 // 00065 // <synopsis> 00066 // MSTableImpl is only for internal use by the MeasurementSet base class 00067 // MSTable. 00068 // </synopsis> 00069 // 00070 // <example> 00071 // </example> 00072 // 00073 // 00074 // <motivation> 00075 // The reasons for existance for this class are: sharing of code between 00076 // the various MeasurementSet Tables and avoiding duplicate code in the 00077 // instantiations of MSTable 00078 // </motivation> 00079 // 00080 // <todo asof="1996/2/22"> 00081 // </todo> 00082 00083 class MSTableImpl 00084 { 00085 public: 00086 // Convert a name to a ColEnum, 00087 static Int mapType(const SimpleOrderedMap<Int,String>& map, 00088 const String &name); 00089 00090 // add a column to a TableDesc 00091 // An exception is thrown for an invalid data type. This indicates a 00092 // programming error in this class when this occurs. 00093 // If option!=0 shape is used to set the shape of the column and 00094 // option defines the type of column (ColumnDesc::Fixed/Direct). 00095 // If option==0, shape is ignored and ndim is used to specify the 00096 // array dimension if any. 00097 // If refCol is not empty, a column with variable reference will be 00098 // created, note that refCol should already exist in td. 00099 // <thrown> 00100 // <li> AipsError 00101 // </thrown> 00102 static void addColumnToDesc(TableDesc &td, const String& colName, 00103 Int colDType, const String& colComment, 00104 const String& colUnit, 00105 const String& colMeasure, 00106 Int ndim, const IPosition & shape, 00107 Int option, const String& refCol); 00108 00109 // add a keyword to a TableDesc 00110 // An exception is thrown for an invalid data type. This indicates a 00111 // missing data type in the code.. 00112 // <thrown> 00113 // <li> AipsError 00114 // </thrown> 00115 static void addKeyToDesc(TableDesc& td, const String& keyName, 00116 Int keyDType, const String& keyComment); 00117 00118 // add a MeasureColumn for the specified Measure, with default reference 00119 static void addMeasColumn(TableDesc &td, const String& colName, 00120 const String& colMeasure, const String& refCol); 00121 00122 // Add the compress option for the given column to the TableDesc. 00123 static void addColumnCompression (TableDesc&, const String& colName, 00124 Bool autoScale, const String& type); 00125 00126 // Setup the compression data managers if needed. 00127 static SetupNewTable& setupCompression (SetupNewTable&); 00128 00129 // Define an entry in the column maps 00130 static void colMapDef(SimpleOrderedMap<Int,String>& colMap, 00131 SimpleOrderedMap<Int,Int>& colDTypeMap, 00132 SimpleOrderedMap<Int,String>& colCommentMap, 00133 SimpleOrderedMap<Int,String>& colUnitMap, 00134 SimpleOrderedMap<Int,String>& colMeasureTypeMap, 00135 Int col, 00136 const String& colName, 00137 Int colType, 00138 const String& colComment, 00139 const String& colUnit, 00140 const String& colMeasureType); 00141 00142 // Define an entry in the keyword maps 00143 static void keyMapDef(SimpleOrderedMap<Int,String>& keyMap, 00144 SimpleOrderedMap<Int,Int>& keyDTypeMap, 00145 SimpleOrderedMap<Int,String>& keyCommentMap, 00146 Int key, 00147 const String& keyName, 00148 Int keyType, 00149 const String& keyComment); 00150 00151 // tableDesc convenience functions 00152 // <group> 00153 00154 // check that a TableDesc is valid 00155 static Bool validate(const TableDesc& tabDesc, 00156 const TableDesc& requiredTD); 00157 00158 // check that the keyword set is valid 00159 static Bool validate(const TableRecord& tabRec, 00160 const TableDesc& requiredTD); 00161 00162 // </group> 00163 00164 // Return a table that references all columns in this table except for 00165 // those given in writableColumns, those are empty and writable. 00166 static Table referenceCopy(const Table& tab, const String& newTableName, 00167 const Block<String>& writableColumns); 00168 // Initialize all MeasurementSet static mappings 00169 static void init(); 00170 00171 private: 00172 static Mutex initialized_mutex; 00173 static Bool initialized_p; 00174 }; 00175 00176 00177 } //# NAMESPACE CASACORE - END 00178 00179 #endif