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$ 00027 00028 #ifndef TABLES_MAPPEDARRAYENGINE_H 00029 #define TABLES_MAPPEDARRAYENGINE_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/tables/DataMan/BaseMappedArrayEngine.h> 00034 00035 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00036 00037 00038 // <summary> 00039 // Templated virtual column engine to map the data type of a table array 00040 // </summary> 00041 00042 // <use visibility=export> 00043 00044 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests=""> 00045 // </reviewed> 00046 00047 // <prerequisite> 00048 //# Classes you should understand before using this one. 00049 // <li> VirtualColumnEngine 00050 // <li> VirtualArrayColumn 00051 // </prerequisite> 00052 00053 // <synopsis> 00054 // MappedArrayEngine is a virtual column engine which maps an array 00055 // of one type to another type (without any scaling). 00056 // 00057 // An engine object should be used for one column only, because the stored 00058 // column name is part of the engine. If it would be used for more than 00059 // one column, they would all share the same stored column. 00060 // When the engine is bound to a column, it is checked if the name 00061 // of that column matches the given virtual column name. 00062 // 00063 // The engine can be used for a column containing any kind of array 00064 // (thus direct or indirect, fixed or variable shaped)) as long as the 00065 // virtual array can be stored in the stored array. Thus a fixed shaped 00066 // virtual can use a variable shaped stored, but not vice versa. 00067 // A fixed shape indirect virtual can use a stored with direct arrays. 00068 // </synopsis> 00069 00070 // <motivation> 00071 // For precision it is sometimes needed to store the visibility data in a 00072 // MeasurementSet in double precision. To be able to use other applications 00073 // on such data, it is needed to map them to single precision. 00074 // 00075 // Because the engine can serve only one column, it was possible to 00076 // combine the engine and the column functionality in one class. 00077 // This has been achieved using multiple inheritance. 00078 // The advantage of this is that only one templated class is used, 00079 // so less template instantiations are needed. 00080 // </motivation> 00081 00082 // <example> 00083 // <srcblock> 00084 // // Create the table description and 2 columns with indirect arrays in it. 00085 // // The Int column will be stored, while the double will be 00086 // // used as virtual. 00087 // TableDesc tableDesc ("", TableDesc::Scratch); 00088 // tableDesc.addColumn (ArrayColumnDesc<Int> ("storedArray")); 00089 // tableDesc.addColumn (ArrayColumnDesc<double> ("virtualArray")); 00090 // 00091 // // Create a new table using the table description. 00092 // SetupNewTable newtab (tableDesc, "tab.data", Table::New); 00093 // 00094 // // Create the array mapping engine to map from double to Int 00095 // // and bind it to the double column. 00096 // // Create the table. 00097 // MappedArrayEngine<double,Int> mappingEngine("virtualArray", 00098 // "storedArray", 10); 00099 // newtab.bindColumn ("virtualArray", mappingEngine); 00100 // Table table (newtab); 00101 // 00102 // // Store a 3-D array (with dim. 2,3,4) into each row of the column. 00103 // // The shape of each array in the column is implicitly set by the put 00104 // // function. This will also set the shape of the underlying Int array. 00105 // ArrayColumn data (table, "virtualArray"); 00106 // Array<double> someArray(IPosition(4,2,3,4)); 00107 // someArray = 0; 00108 // for (uInt i=0, i<10; i++) { // table will have 10 rows 00109 // table.addRow(); 00110 // data.put (i, someArray) 00111 // } 00112 // </srcblock> 00113 // </example> 00114 00115 // <templating arg=VirtualType> 00116 // <li> only suited for built-in numerics data types 00117 // </templating> 00118 // <templating arg=StoredType> 00119 // <li> only suited for built-in numerics data types 00120 // </templating> 00121 00122 template<class VirtualType, class StoredType> class MappedArrayEngine : public BaseMappedArrayEngine<VirtualType, StoredType> 00123 { 00124 //# Make members of parent class known. 00125 public: 00126 using BaseMappedArrayEngine<VirtualType,StoredType>::virtualName; 00127 protected: 00128 using BaseMappedArrayEngine<VirtualType,StoredType>::storedName; 00129 using BaseMappedArrayEngine<VirtualType,StoredType>::table; 00130 using BaseMappedArrayEngine<VirtualType,StoredType>::column; 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 CASACORE - END 00204 00205 #ifndef CASACORE_NO_AUTO_TEMPLATES 00206 #include <casacore/tables/DataMan/MappedArrayEngine.tcc> 00207 #endif //# CASACORE_NO_AUTO_TEMPLATES 00208 #endif