casa
$Rev:20696$
|
00001 //# MappedArrayEngine.h: Templated virtual column engine to map a table array 00002 //# Copyright (C) 2005 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 //# $Id: MappedArrayEngine.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $ 00027 00028 #ifndef TABLES_MAPPEDARRAYENGINE_H 00029 #define TABLES_MAPPEDARRAYENGINE_H 00030 00031 //# Includes 00032 #include <tables/Tables/BaseMappedArrayEngine.h> 00033 00034 namespace casa { //# NAMESPACE CASA - BEGIN 00035 00036 00037 // <summary> 00038 // Templated virtual column engine to map the data type of a table array 00039 // </summary> 00040 00041 // <use visibility=export> 00042 00043 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests=""> 00044 // </reviewed> 00045 00046 // <prerequisite> 00047 //# Classes you should understand before using this one. 00048 // <li> VirtualColumnEngine 00049 // <li> VirtualArrayColumn 00050 // </prerequisite> 00051 00052 // <synopsis> 00053 // MappedArrayEngine is a virtual column engine which maps an array 00054 // of one type to another type (without any scaling). 00055 // 00056 // An engine object should be used for one column only, because the stored 00057 // column name is part of the engine. If it would be used for more than 00058 // one column, they would all share the same stored column. 00059 // When the engine is bound to a column, it is checked if the name 00060 // of that column matches the given virtual column name. 00061 // 00062 // The engine can be used for a column containing any kind of array 00063 // (thus direct or indirect, fixed or variable shaped)) as long as the 00064 // virtual array can be stored in the stored array. Thus a fixed shaped 00065 // virtual can use a variable shaped stored, but not vice versa. 00066 // A fixed shape indirect virtual can use a stored with direct arrays. 00067 // </synopsis> 00068 00069 // <motivation> 00070 // For precision it is sometimes needed to store the visibility data in a 00071 // MeasurementSet in double precision. To be able to use other applications 00072 // on such data, it is needed to map them to single precision. 00073 // 00074 // Because the engine can serve only one column, it was possible to 00075 // combine the engine and the column functionality in one class. 00076 // This has been achieved using multiple inheritance. 00077 // The advantage of this is that only one templated class is used, 00078 // so less template instantiations are needed. 00079 // </motivation> 00080 00081 // <example> 00082 // <srcblock> 00083 // // Create the table description and 2 columns with indirect arrays in it. 00084 // // The Int column will be stored, while the double will be 00085 // // used as virtual. 00086 // TableDesc tableDesc ("", TableDesc::Scratch); 00087 // tableDesc.addColumn (ArrayColumnDesc<Int> ("storedArray")); 00088 // tableDesc.addColumn (ArrayColumnDesc<double> ("virtualArray")); 00089 // 00090 // // Create a new table using the table description. 00091 // SetupNewTable newtab (tableDesc, "tab.data", Table::New); 00092 // 00093 // // Create the array mapping engine to map from double to Int 00094 // // and bind it to the double column. 00095 // // Create the table. 00096 // MappedArrayEngine<double,Int> mappingEngine("virtualArray", 00097 // "storedArray", 10); 00098 // newtab.bindColumn ("virtualArray", mappingEngine); 00099 // Table table (newtab); 00100 // 00101 // // Store a 3-D array (with dim. 2,3,4) into each row of the column. 00102 // // The shape of each array in the column is implicitly set by the put 00103 // // function. This will also set the shape of the underlying Int array. 00104 // ArrayColumn data (table, "virtualArray"); 00105 // Array<double> someArray(IPosition(4,2,3,4)); 00106 // someArray = 0; 00107 // for (uInt i=0, i<10; i++) { // table will have 10 rows 00108 // table.addRow(); 00109 // data.put (i, someArray) 00110 // } 00111 // </srcblock> 00112 // </example> 00113 00114 // <templating arg=VirtualType> 00115 // <li> only suited for built-in numerics data types 00116 // </templating> 00117 // <templating arg=StoredType> 00118 // <li> only suited for built-in numerics data types 00119 // </templating> 00120 00121 template<class VirtualType, class StoredType> class MappedArrayEngine : public BaseMappedArrayEngine<VirtualType, StoredType> 00122 { 00123 //# Make members of parent class known. 00124 public: 00125 using BaseMappedArrayEngine<VirtualType,StoredType>::virtualName; 00126 protected: 00127 using BaseMappedArrayEngine<VirtualType,StoredType>::storedName; 00128 using BaseMappedArrayEngine<VirtualType,StoredType>::table; 00129 using BaseMappedArrayEngine<VirtualType,StoredType>::roColumn; 00130 using BaseMappedArrayEngine<VirtualType,StoredType>::rwColumn; 00131 using BaseMappedArrayEngine<VirtualType,StoredType>::setNames; 00132 00133 public: 00134 // Construct an engine to map all arrays in a column. 00135 // StoredColumnName is the name of the column where the mapped 00136 // data will be put and must have data type StoredType. 00137 // The virtual column using this engine must have data type VirtualType. 00138 MappedArrayEngine (const String& virtualColumnName, 00139 const String& storedColumnName); 00140 00141 // Construct from a record specification as created by dataManagerSpec(). 00142 MappedArrayEngine (const Record& spec); 00143 00144 // Destructor is mandatory. 00145 ~MappedArrayEngine(); 00146 00147 // Return the type name of the engine (i.e. its class name). 00148 virtual String dataManagerType() const; 00149 00150 // Get the name given to the engine (is the virtual column name). 00151 virtual String dataManagerName() const; 00152 00153 // Record a record containing data manager specifications. 00154 virtual Record dataManagerSpec() const; 00155 00156 // Return the name of the class. 00157 // This includes the names of the template arguments. 00158 static String className(); 00159 00160 // Register the class name and the static makeObject "constructor". 00161 // This will make the engine known to the table system. 00162 // The automatically invoked registration function in DataManReg.cc 00163 // contains MappedArrayEngine<double,Int>. 00164 // Any other instantiation of this class must be registered "manually" 00165 // (or added to DataManReg.cc). 00166 static void registerClass(); 00167 00168 private: 00169 // Copy constructor is only used by clone(). 00170 // (so it is made private). 00171 MappedArrayEngine (const MappedArrayEngine<VirtualType,StoredType>&); 00172 00173 // Assignment is not needed and therefore forbidden 00174 // (so it is made private and not implemented). 00175 MappedArrayEngine<VirtualType,StoredType>& operator= 00176 (const MappedArrayEngine<VirtualType,StoredType>&); 00177 00178 // Clone the engine object. 00179 DataManager* clone() const; 00180 00181 // Copy the stored array to the virtual array. 00182 virtual void mapOnGet (Array<VirtualType>& array, 00183 const Array<StoredType>& stored); 00184 00185 // Copy the virtual array to the stored array. 00186 virtual void mapOnPut (const Array<VirtualType>& array, 00187 Array<StoredType>& stored); 00188 00189 00190 public: 00191 // Define the "constructor" to construct this engine when a 00192 // table is read back. 00193 // This "constructor" has to be registered by the user of the engine. 00194 // If the engine is commonly used, its registration can be added 00195 // to the registerAllCtor function in DataManReg.cc. 00196 // That function gets automatically invoked by the table system. 00197 static DataManager* makeObject (const String& dataManagerType, 00198 const Record& spec); 00199 }; 00200 00201 00202 00203 } //# NAMESPACE CASA - END 00204 00205 #ifndef CASACORE_NO_AUTO_TEMPLATES 00206 #include <tables/Tables/MappedArrayEngine.tcc> 00207 #endif //# CASACORE_NO_AUTO_TEMPLATES 00208 #endif