casa
$Rev:20696$
|
00001 //# MSMColumn.h: A column in the MemoryStMan 00002 //# Copyright (C) 2003 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: MSMColumn.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $ 00027 00028 #ifndef TABLES_MSMCOLUMN_H 00029 #define TABLES_MSMCOLUMN_H 00030 00031 00032 //# Includes 00033 #include <casa/aips.h> 00034 #include <tables/Tables/DataManager.h> 00035 #include <tables/Tables/StManColumn.h> 00036 #include <casa/Containers/Block.h> 00037 #include <casa/BasicSL/Complex.h> 00038 #include <casa/Arrays/IPosition.h> 00039 #include <casa/BasicSL/String.h> 00040 00041 namespace casa { //# NAMESPACE CASA - BEGIN 00042 00043 //# Forward declarations 00044 class MSMBase; 00045 00046 00047 // <summary> 00048 // Column in the Memory table storage manager class 00049 // </summary> 00050 00051 // <use visibility=local> 00052 00053 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests=""> 00054 // </reviewed> 00055 00056 // <prerequisite> 00057 //# Classes you should understand before using this one. 00058 // <li> <linkto class=StManColumn>StManColumn</linkto> 00059 // <li> <linkto class=MemoryStMan>MemoryStMan</linkto> 00060 // </prerequisite> 00061 00062 // <etymology> 00063 // MSMColumn handles a column for the memory-based storage manager. 00064 // </etymology> 00065 00066 // <synopsis> 00067 // MSMColumn is used by MemoryStMan to handle the access to 00068 // the data in a table column. 00069 // It is an storage manager based in memory. Thus the data is lost 00070 // when the table is closed. 00071 // On reopen it will be initialized to the default column value. 00072 // It fully supports addition and removal of rows. 00073 // 00074 // MSMColumn serves 2 purposes: 00075 // <ol> 00076 // <li> It handles a column containing scalar values. 00077 // <li> It serves as a base class for MSMDirColumn and MSMIndColumn 00078 // These classes handle arrays and use MSMColumn to hold a pointer 00079 // to the array in each row. 00080 // </ol> 00081 // 00082 // MSMColumn does not hold a column as a consecutive array, 00083 // because extending the column (i.e. adding rows) proved be too 00084 // expensive due to the repeated copying involved when creating a table 00085 // (this method was used by the first version of the table system). 00086 // Instead it has a number of data blocks (extensions) indexed to by a 00087 // super block. Accessing a row means finding the appropriate extension 00088 // via a binary search. Because there is only 1 extension when a table is 00089 // read back, the overhead in finding a row is small. 00090 // </synopsis> 00091 00092 // <motivation> 00093 // MSMColumn handles the standard data types. The class 00094 // is not templated, but a switch statement is used instead. 00095 // Templates would cause too many instantiations. 00096 // </motivation> 00097 00098 // <todo asof="$DATE:$"> 00099 //# A List of bugs, limitations, extensions or planned refinements. 00100 // <li> StManAipsIO should use this class 00101 // </todo> 00102 00103 00104 class MSMColumn: public StManColumn 00105 { 00106 public: 00107 // Create a column of the given type. 00108 // It will maintain a pointer to its parent storage manager. 00109 MSMColumn (MSMBase* smptr, int dataType, Bool byPtr); 00110 00111 // Frees up the storage. 00112 virtual ~MSMColumn(); 00113 00114 // Get a scalar value in the given row. 00115 // The buffer pointed to by dataPtr has to have the correct length 00116 // (which is guaranteed by the Scalar/ArrayColumn get function). 00117 // <group> 00118 void getBoolV (uInt rownr, Bool* dataPtr); 00119 void getuCharV (uInt rownr, uChar* dataPtr); 00120 void getShortV (uInt rownr, Short* dataPtr); 00121 void getuShortV (uInt rownr, uShort* dataPtr); 00122 void getIntV (uInt rownr, Int* dataPtr); 00123 void getuIntV (uInt rownr, uInt* dataPtr); 00124 void getfloatV (uInt rownr, float* dataPtr); 00125 void getdoubleV (uInt rownr, double* dataPtr); 00126 void getComplexV (uInt rownr, Complex* dataPtr); 00127 void getDComplexV (uInt rownr, DComplex* dataPtr); 00128 void getStringV (uInt rownr, String* dataPtr); 00129 // </group> 00130 00131 // Put a scalar value into the given row. 00132 // The buffer pointed to by dataPtr has to have the correct length 00133 // (which is guaranteed by the Scalar/ArrayColumn put function). 00134 // <group> 00135 void putBoolV (uInt rownr, const Bool* dataPtr); 00136 void putuCharV (uInt rownr, const uChar* dataPtr); 00137 void putShortV (uInt rownr, const Short* dataPtr); 00138 void putuShortV (uInt rownr, const uShort* dataPtr); 00139 void putIntV (uInt rownr, const Int* dataPtr); 00140 void putuIntV (uInt rownr, const uInt* dataPtr); 00141 void putfloatV (uInt rownr, const float* dataPtr); 00142 void putdoubleV (uInt rownr, const double* dataPtr); 00143 void putComplexV (uInt rownr, const Complex* dataPtr); 00144 void putDComplexV (uInt rownr, const DComplex* dataPtr); 00145 void putStringV (uInt rownr, const String* dataPtr); 00146 // </group> 00147 00148 // Get scalars from the given row on with a maximum of nrmax values. 00149 // This can be used to get an entire column of scalars or to get 00150 // a part of a column (for a cache for example). 00151 // The buffer pointed to by dataPtr has to have the correct length 00152 // (which is guaranteed by the ScalarColumn get function). 00153 // <group> 00154 uInt getBlockBoolV (uInt rownr, uInt nrmax, Bool* dataPtr); 00155 uInt getBlockuCharV (uInt rownr, uInt nrmax, uChar* dataPtr); 00156 uInt getBlockShortV (uInt rownr, uInt nrmax, Short* dataPtr); 00157 uInt getBlockuShortV (uInt rownr, uInt nrmax, uShort* dataPtr); 00158 uInt getBlockIntV (uInt rownr, uInt nrmax, Int* dataPtr); 00159 uInt getBlockuIntV (uInt rownr, uInt nrmax, uInt* dataPtr); 00160 uInt getBlockfloatV (uInt rownr, uInt nrmax, float* dataPtr); 00161 uInt getBlockdoubleV (uInt rownr, uInt nrmax, double* dataPtr); 00162 uInt getBlockComplexV (uInt rownr, uInt nrmax, Complex* dataPtr); 00163 uInt getBlockDComplexV (uInt rownr, uInt nrmax, DComplex* dataPtr); 00164 uInt getBlockStringV (uInt rownr, uInt nrmax, String* dataPtr); 00165 // </group> 00166 00167 // Put nrmax scalars from the given row on. 00168 // This can be used to put an entire column of scalars or to put 00169 // a part of a column (for a cache for example). 00170 // The buffer pointed to by dataPtr has to have the correct length 00171 // (which is guaranteed by the ScalarColumn put function). 00172 // <group> 00173 void putBlockBoolV (uInt rownr, uInt nrmax, const Bool* dataPtr); 00174 void putBlockuCharV (uInt rownr, uInt nrmax, const uChar* dataPtr); 00175 void putBlockShortV (uInt rownr, uInt nrmax, const Short* dataPtr); 00176 void putBlockuShortV (uInt rownr, uInt nrmax, const uShort* dataPtr); 00177 void putBlockIntV (uInt rownr, uInt nrmax, const Int* dataPtr); 00178 void putBlockuIntV (uInt rownr, uInt nrmax, const uInt* dataPtr); 00179 void putBlockfloatV (uInt rownr, uInt nrmax, const float* dataPtr); 00180 void putBlockdoubleV (uInt rownr, uInt nrmax, const double* dataPtr); 00181 void putBlockComplexV (uInt rownr, uInt nrmax, const Complex* dataPtr); 00182 void putBlockDComplexV (uInt rownr, uInt nrmax, const DComplex* dataPtr); 00183 void putBlockStringV (uInt rownr, uInt nrmax, const String* dataPtr); 00184 // </group> 00185 00186 // Get the scalar values in some cells of the column. 00187 // The buffer pointed to by dataPtr has to have the correct length. 00188 // (which is guaranteed by the ScalarColumn getColumnCells function). 00189 // The default implementation loops through all rows. 00190 // <group> 00191 virtual void getScalarColumnCellsBoolV (const RefRows& rownrs, 00192 Vector<Bool>* dataPtr); 00193 virtual void getScalarColumnCellsuCharV (const RefRows& rownrs, 00194 Vector<uChar>* dataPtr); 00195 virtual void getScalarColumnCellsShortV (const RefRows& rownrs, 00196 Vector<Short>* dataPtr); 00197 virtual void getScalarColumnCellsuShortV (const RefRows& rownrs, 00198 Vector<uShort>* dataPtr); 00199 virtual void getScalarColumnCellsIntV (const RefRows& rownrs, 00200 Vector<Int>* dataPtr); 00201 virtual void getScalarColumnCellsuIntV (const RefRows& rownrs, 00202 Vector<uInt>* dataPtr); 00203 virtual void getScalarColumnCellsfloatV (const RefRows& rownrs, 00204 Vector<float>* dataPtr); 00205 virtual void getScalarColumnCellsdoubleV (const RefRows& rownrs, 00206 Vector<double>* dataPtr); 00207 virtual void getScalarColumnCellsComplexV (const RefRows& rownrs, 00208 Vector<Complex>* dataPtr); 00209 virtual void getScalarColumnCellsDComplexV (const RefRows& rownrs, 00210 Vector<DComplex>* dataPtr); 00211 virtual void getScalarColumnCellsStringV (const RefRows& rownrs, 00212 Vector<String>* dataPtr); 00213 // </group> 00214 00215 // Add (newNrrow-oldNrrow) rows to the column. 00216 virtual void addRow (uInt newNrrow, uInt oldNrrow); 00217 00218 // Resize the data blocks. 00219 // This adds an extension when needed. 00220 void resize (uInt nrval); 00221 00222 // Remove the given row. 00223 // If no rows remain in the extension, the extension is also removed. 00224 virtual void remove (uInt rownr); 00225 00226 // Create the number of rows in a new table. 00227 // This is used when a table gets created or opened. 00228 virtual void doCreate (uInt nrrow); 00229 00230 // Check if the class invariants still hold. 00231 virtual Bool ok() const; 00232 00233 protected: 00234 MSMBase* stmanPtr_p; 00235 // The data type (for caching purposes). 00236 int dtype_p; 00237 // The data is indirectly accessed via a pointer (for the derived classes). 00238 Bool byPtr_p; 00239 // The number of allocated rows in the column. 00240 uInt nralloc_p; 00241 // The nr of extensions in use. 00242 uInt nrext_p; 00243 // The assembly of all extensions (actually Block<T*>). 00244 Block<void*> data_p; 00245 // The cumulative nr of rows in all extensions. 00246 Block<uInt> ncum_p; 00247 00248 // Find the extension in which the row number is. 00249 // If the flag is true, it also sets the columnCache object. 00250 uInt findExt (uInt rownr, Bool setCache); 00251 00252 // Get the next extension. 00253 // For the first iteration extnr should be zero. 00254 // It returns the number of values in it until the maximum is reached. 00255 // Zero means no more extensions. 00256 uInt nextExt (void*& ext, uInt& extnr, uInt nrmax) const; 00257 00258 // Allocate an extension with the data type of the column. 00259 void* allocData (uInt nrval, Bool byPtr); 00260 00261 // Delete all extensions. 00262 // Possible underlying data (as used by StManArrayColumnMemory) 00263 // will not be deleted and should have been deleted beforehand. 00264 void deleteAll(); 00265 00266 // Delete an extension. 00267 void deleteData (void* datap, Bool byPtr); 00268 00269 // Remove an entry (i.e. a row) from an extension at the given index. 00270 // It will do this by shifting the rest (nrvalAfter elements) 00271 // one position to the left. 00272 void removeData (void* datap, uInt inx, uInt nrvalAfter); 00273 00274 // Initialize the data (after an open). 00275 void initData (void* datap, uInt nrval); 00276 00277 // Get the pointer for the given row. 00278 // This is for the derived classes like StManArrayColumnMemory. 00279 void* getArrayPtr (uInt rownr); 00280 00281 // Put the pointer for the given row. 00282 // This is for the derived classes like StManArrayColumnMemory. 00283 void putArrayPtr (uInt rownr, void* dataPtr); 00284 00285 private: 00286 // Forbid copy constructor. 00287 MSMColumn (const MSMColumn&); 00288 00289 // Forbid assignment. 00290 MSMColumn& operator= (const MSMColumn&); 00291 }; 00292 00293 00294 00295 } //# NAMESPACE CASA - END 00296 00297 #endif