00001 //# ArrColData.h: Access to a table column containing arrays 00002 //# Copyright (C) 1994,1995,1996,1998,1999 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_ARRCOLDATA_H 00029 #define TABLES_ARRCOLDATA_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/tables/Tables/PlainColumn.h> 00034 #include <casacore/casa/Arrays/IPosition.h> 00035 00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00037 00038 //# Forward Declarations 00039 class ColumnSet; 00040 template<class T> class ArrayColumnDesc; 00041 class AipsIO; 00042 00043 00044 // <summary> 00045 // Access to a table column containing arrays 00046 // </summary> 00047 00048 // <use visibility=local> 00049 00050 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests=""> 00051 // </reviewed> 00052 00053 // <prerequisite> 00054 //# Classes you should understand before using this one. 00055 // <li> PlainColumn 00056 // <li> ArrayColumnDesc 00057 // <li> Table 00058 // </prerequisite> 00059 00060 // <etymology> 00061 // ArrayColumnData represents a table column containing array data. 00062 // </etymology> 00063 00064 // <synopsis> 00065 // The class ArrayColumnData is derived from PlainColumn. 00066 // It implements the virtual functions accessing a table column 00067 // containing arrays with an arbitrary data type. 00068 // Both direct and indirect arrays are supported. 00069 // 00070 // It is possible to access an array or a subsection of it in an 00071 // individual cell (i.e. table row) or in the entire column. 00072 // The functions accessing the entire column are implemented by 00073 // looping over the individual cells. 00074 // 00075 // The main task of this class is to communicate with the data manager 00076 // column object. This consists of: 00077 // <ul> 00078 // <li> Binding itself to a data manager. 00079 // <li> Letting the data manager create its column object and 00080 // setting the shape for direct arrays. 00081 // <li> Closing the data manager column object (in putFileDerived). 00082 // <li> Reconstructing the data manager object for an existing table 00083 // (in getFileDerived). 00084 // <li> Transferring get/put calls to the data manager column object. 00085 // </ul> 00086 // 00087 // The class is hidden from the user by the envelope class ArrayColumn. 00088 // It used directly, it should be done with care. It assumes that the 00089 // arrays in the various get and put functions have the correct length. 00090 // ArrayColumn does that check. 00091 // </synopsis> 00092 00093 // <templating arg=T> 00094 // <li> Default constructor 00095 // <li> Copy constructor 00096 // <li> Assignment operator 00097 // </templating> 00098 00099 // <todo asof="$DATE:$"> 00100 //# A List of bugs, limitations, extensions or planned refinements. 00101 // <li> support tiling 00102 // </todo> 00103 00104 00105 template<class T> class ArrayColumnData : public PlainColumn 00106 { 00107 public: 00108 00109 // Construct an array column object from the given description 00110 // in the given column set. 00111 // This constructor is used by ArrayColumnDesc::makeColumn. 00112 ArrayColumnData (const ArrayColumnDesc<T>*, ColumnSet*); 00113 00114 ~ArrayColumnData(); 00115 00116 // Ask the data manager if the shape of an existing array can be changed. 00117 virtual Bool canChangeShape() const; 00118 00119 // Ask if the data manager can handle a cell slice. 00120 virtual Bool canAccessSlice (Bool& reask) const; 00121 00122 // Ask if the data manager can handle a column. 00123 virtual Bool canAccessArrayColumn (Bool& reask) const; 00124 00125 // Ask if the data manager can handle some cells in a column. 00126 virtual Bool canAccessArrayColumnCells (Bool& reask) const; 00127 00128 // Ask if the data manager can handle a column slice. 00129 virtual Bool canAccessColumnSlice (Bool& reask) const; 00130 00131 // Initialize the rows from startRownr till endRownr (inclusive) 00132 // with the default value defined in the column description (if defined). 00133 void initialize (uInt startRownr, uInt endRownr); 00134 00135 // Get the global #dimensions of an array (ie. for all rows). 00136 uInt ndimColumn() const; 00137 00138 // Get the global shape of an array (ie. for all rows). 00139 IPosition shapeColumn() const; 00140 00141 // Set shape of all arrays in the column. 00142 // It can only be used for direct arrays. 00143 void setShapeColumn (const IPosition& shape); 00144 00145 // Get the #dimensions of an array in a particular cell. 00146 // If the cell does not contain an array, 0 is returned. 00147 uInt ndim (uInt rownr) const; 00148 00149 // Get the shape of an array in a particular cell. 00150 // If the cell does not contain an array, an empty IPosition is returned. 00151 IPosition shape(uInt rownr) const; 00152 00153 // Get the tile shape of an array in a particular cell. 00154 // If the cell does not contain an array, an empty IPosition is returned. 00155 IPosition tileShape(uInt rownr) const; 00156 00157 // Set dimensions of array in a particular cell. 00158 // <group> 00159 void setShape (uInt rownr, const IPosition& shape); 00160 // The shape of tiles in the array can also be defined. 00161 void setShape (uInt rownr, const IPosition& shape, 00162 const IPosition& tileShape); 00163 // </group> 00164 00165 // Test if the given cell contains an array. 00166 Bool isDefined (uInt rownr) const; 00167 00168 // Get the array from a particular cell. 00169 // The length of the buffer pointed to by arrayPtr must match 00170 // the actual length. This is checked by ArrayColumn. 00171 void get (uInt rownr, void* arrayPtr) const; 00172 00173 // Get a slice of an N-dimensional array in a particular cell. 00174 // The length of the buffer pointed to by arrayPtr must match 00175 // the actual length. This is checked by ArrayColumn. 00176 void getSlice (uInt rownr, const Slicer&, void* arrayPtr) const; 00177 00178 // Get the array of all values in a column. 00179 // If the column contains n-dim arrays, the resulting array is (n+1)-dim. 00180 // The arrays in the column have to have the same shape in all cells. 00181 // The length of the buffer pointed to by arrayPtr must match 00182 // the actual length. This is checked by ArrayColumn. 00183 void getArrayColumn (void* arrayPtr) const; 00184 00185 // Get the array of some values in a column. 00186 // If the column contains n-dim arrays, the resulting array is (n+1)-dim. 00187 // The arrays in the column have to have the same shape in all cells. 00188 // The length of the buffer pointed to by arrayPtr must match 00189 // the actual length. This is checked by ArrayColumn. 00190 void getArrayColumnCells (const RefRows& rownrs, void* arrayPtr) const; 00191 00192 // Get subsections from all arrays in the column. 00193 // If the column contains n-dim arrays, the resulting array is (n+1)-dim. 00194 // The arrays in the column have to have the same shape in all cells. 00195 // The length of the buffer pointed to by arrayPtr must match 00196 // the actual length. This is checked by ArrayColumn. 00197 void getColumnSlice (const Slicer&, void* arrayPtr) const; 00198 00199 // Get subsections from some arrays in the column. 00200 // If the column contains n-dim arrays, the resulting array is (n+1)-dim. 00201 // The arrays in the column have to have the same shape in all cells. 00202 // The length of the buffer pointed to by arrayPtr must match 00203 // the actual length. This is checked by ArrayColumn. 00204 void getColumnSliceCells (const RefRows& rownrs, const Slicer&, 00205 void* arrayPtr) const; 00206 00207 // Put the value in a particular cell. 00208 // The length of the buffer pointed to by arrayPtr must match 00209 // the actual length. This is checked by ArrayColumn. 00210 void put (uInt rownr, const void* arrayPtr); 00211 00212 // Put a slice of an N-dimensional array in a particular cell. 00213 // The length of the buffer pointed to by arrayPtr must match 00214 // the actual length. This is checked by ArrayColumn. 00215 void putSlice (uInt rownr, const Slicer&, const void* arrayPtr); 00216 00217 // Put the array of all values in the column. 00218 // If the column contains n-dim arrays, the source array is (n+1)-dim. 00219 // The arrays in the column have to have the same shape in all cells. 00220 // The length of the buffer pointed to by arrayPtr must match 00221 // the actual length. This is checked by ArrayColumn. 00222 void putArrayColumn (const void* arrayPtr); 00223 00224 // Put the array of some values in the column. 00225 // If the column contains n-dim arrays, the source array is (n+1)-dim. 00226 // The arrays in the column have to have the same shape in all cells. 00227 // The length of the buffer pointed to by arrayPtr must match 00228 // the actual length. This is checked by ArrayColumn. 00229 void putArrayColumnCells (const RefRows& rownrs, const void* arrayPtr); 00230 00231 // Put into subsections of all table arrays in the column. 00232 // If the column contains n-dim arrays, the source array is (n+1)-dim. 00233 // The arrays in the column have to have the same shape in all cells. 00234 // The length of the buffer pointed to by arrayPtr must match 00235 // the actual length. This is checked by ArrayColumn. 00236 void putColumnSlice (const Slicer&, const void* arrayPtr); 00237 00238 // Put into subsections of some table arrays in the column. 00239 // If the column contains n-dim arrays, the source array is (n+1)-dim. 00240 // The arrays in the column have to have the same shape in all cells. 00241 // The length of the buffer pointed to by arrayPtr must match 00242 // the actual length. This is checked by ArrayColumn. 00243 void putColumnSliceCells (const RefRows& rownrs, const Slicer&, 00244 const void* arrayPtr); 00245 00246 // Create a data manager column object for this column. 00247 void createDataManagerColumn(); 00248 00249 00250 private: 00251 // Pointer to column description. 00252 const ArrayColumnDesc<T>* arrDescPtr_p; 00253 // Is the shape for all arrays in the columns defined. 00254 Bool shapeColDef_p; 00255 // Shape for all arrays in the column. 00256 IPosition shapeCol_p; 00257 00258 00259 // Copy constructor cannot be used. 00260 ArrayColumnData (const ArrayColumnData<T>&); 00261 00262 // Assignment cannot be used. 00263 ArrayColumnData<T>& operator= (const ArrayColumnData<T>&); 00264 00265 // Check if the shape of an array can be set and if it is set 00266 // correctly (i.e. if matching possible #dim in column description). 00267 void checkShape (const IPosition& shape) const; 00268 00269 // Write the column data. 00270 // The control information is written into the given AipsIO object, 00271 // while the data is written/flushed by the data manager. 00272 void putFileDerived (AipsIO&); 00273 00274 // Read the column data back. 00275 // The control information is read from the given AipsIO object. 00276 // This is used to bind the column to the appropriate data manager. 00277 // Thereafter the data manager gets opened. 00278 void getFileDerived (AipsIO&, const ColumnSet&); 00279 }; 00280 00281 00282 00283 00284 } //# NAMESPACE CASACORE - END 00285 00286 #ifndef CASACORE_NO_AUTO_TEMPLATES 00287 #include <casacore/tables/Tables/ArrColData.tcc> 00288 #endif //# CASACORE_NO_AUTO_TEMPLATES 00289 #endif