casa
$Rev:20696$
|
00001 //# SSMColumn.h: A Column in the Standard Storage Manager 00002 //# Copyright (C) 2000 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: SSMColumn.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $ 00027 00028 #ifndef TABLES_SSMCOLUMN_H 00029 #define TABLES_SSMCOLUMN_H 00030 00031 00032 //# Includes 00033 #include <casa/aips.h> 00034 #include <tables/Tables/StManColumn.h> 00035 #include <tables/Tables/SSMBase.h> 00036 #include <casa/Arrays/IPosition.h> 00037 #include <casa/Containers/Block.h> 00038 #include <casa/OS/Conversion.h> 00039 00040 namespace casa { //# NAMESPACE CASA - BEGIN 00041 00042 //# Forward declarations 00043 00044 00045 // <summary> 00046 // A Column in the Standard Storage Manager. 00047 // </summary> 00048 00049 // <use visibility=local> 00050 00051 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tStandardStMan.cc"> 00052 // </reviewed> 00053 00054 // <prerequisite> 00055 //# Classes you should understand before using this one. 00056 // <li> <linkto class=SSMBase>SSMBase</linkto> 00057 // <li> <linkto class=SSMStringHandler>SSMStringHandler</linkto> 00058 // </prerequisite> 00059 00060 // <etymology> 00061 // SSMColumn represents a Column in the Standard Storage Manager. 00062 // </etymology> 00063 00064 // <synopsis> 00065 // SSMColumn is the base class for access to a column stored with 00066 // the Standard Storage manager. It provides some basic functionality 00067 // for the derived classes handling direct and indirect arrays. 00068 // <p> 00069 // The main task of SSMColumn is handling the access to a column 00070 // containing scalars of the various data types. The data is stored 00071 // in buckets. The classes <linkto class=SSMBase>SSMBase</linkto> 00072 // and <linkto class=SSMIndex>SSMIndex</linkto> keep track in which data 00073 // bucket a given row is stored and at which offset the column starts. 00074 // Using that information SSMColumn can access its data easily. 00075 // <p> 00076 // Almost all data types have a fixed length and can be handled easily. 00077 // However, strings are a special case. 00078 // <br>If the string is fixed length (which means it has a maximum length), 00079 // the string is stored directly in the data bucket. If the string is 00080 // shorter than the maximum length, its length is indicated by a 00081 // trailing 0. 00082 // <br>Variable strings are in principle stored in a special string bucket. 00083 // The data bucket contains 3 integers telling the bucketnr, offset, and 00084 // length of the string. However, it the string is short enough (ie. <= 00085 // 8 characters), the string is stored directly in data bucket using 00086 // the space for bucketnr and offset. 00087 // <p> 00088 // The class maintains a cache of the data in the bucket last read. 00089 // This cache is used by the higher level table classes to get faster 00090 // read access to the data. 00091 // The cache is not used for strings, because they are stored differently. 00092 // </synopsis> 00093 00094 //# <todo asof="$DATE:$"> 00095 //# A List of bugs, limitations, extensions or planned refinements. 00096 //# </todo> 00097 00098 00099 class SSMColumn : public StManColumn 00100 { 00101 public: 00102 // Create a SSMColumn object with the given parent. 00103 // It initializes the various variables. 00104 // It keeps the pointer to its parent (but does not own it). 00105 SSMColumn (SSMBase* aParent, int aDataType, uInt aColNr); 00106 00107 virtual ~SSMColumn(); 00108 00109 // Set the shape of an array in the column. 00110 // It is only called (right after the constructor) if the array has 00111 // a fixed shape. 00112 virtual void setShapeColumn (const IPosition& aShape); 00113 00114 // Set the maximum length of a 'fixed length' string. 00115 // It is only called (right after the constructor) if the string has 00116 // a fixed length 00117 virtual void setMaxLength (uInt maxLength); 00118 00119 // Get the dimensionality of the item in the given row. 00120 virtual uInt ndim (uInt aRowNr); 00121 00122 // Get the shape of the array in the given row. 00123 virtual IPosition shape (uInt aRowNr); 00124 00125 // Let the object initialize itself for a newly created table. 00126 // It is meant for a derived class. 00127 virtual void doCreate (uInt aNrRows); 00128 00129 // Let the column object initialize itself for an existing table 00130 virtual void getFile (uInt aNrRows); 00131 00132 // Resync the storage manager with the new file contents. 00133 // It resets the last rownr put. 00134 void resync (uInt aNrRow); 00135 00136 // Get the scalar value in the given row. 00137 // <group> 00138 virtual void getBoolV (uInt aRowNr, Bool* aDataPtr); 00139 virtual void getuCharV (uInt aRowNr, uChar* aDataPtr); 00140 virtual void getShortV (uInt aRowNr, Short* aDataPtr); 00141 virtual void getuShortV (uInt aRowNr, uShort* aDataPtr); 00142 virtual void getIntV (uInt aRowNr, Int* aDataPtr); 00143 virtual void getuIntV (uInt aRowNr, uInt* aDataPtr); 00144 virtual void getfloatV (uInt aRowNr, float* aDataPtr); 00145 virtual void getdoubleV (uInt aRowNr, double* aDataPtr); 00146 virtual void getComplexV (uInt aRowNr, Complex* aDataPtr); 00147 virtual void getDComplexV (uInt aRowNr, DComplex* aDataPtr); 00148 virtual void getStringV (uInt aRowNr, String* aDataPtr); 00149 // </group> 00150 00151 // Put the scalar value in the given row. 00152 // It updates the cache if the row is contained in the cache. 00153 // <group> 00154 virtual void putBoolV (uInt aRowNr, const Bool* aDataPtr); 00155 virtual void putuCharV (uInt aRowNr, const uChar* aDataPtr); 00156 virtual void putShortV (uInt aRowNr, const Short* aDataPtr); 00157 virtual void putuShortV (uInt aRowNr, const uShort* aDataPtr); 00158 virtual void putIntV (uInt aRowNr, const Int* aDataPtr); 00159 virtual void putuIntV (uInt aRowNr, const uInt* aDataPtr); 00160 virtual void putfloatV (uInt aRowNr, const float* aDataPtr); 00161 virtual void putdoubleV (uInt aRowNr, const double* aDataPtr); 00162 virtual void putComplexV (uInt aRowNr, const Complex* aDataPtr); 00163 virtual void putDComplexV (uInt aRowNr, const DComplex* aDataPtr); 00164 virtual void putStringV (uInt aRowNr, const String* aDataPtr); 00165 // </group> 00166 00167 // Get the scalar values of the entire column. 00168 // <group> 00169 virtual void getScalarColumnBoolV (Vector<Bool>* aDataPtr); 00170 virtual void getScalarColumnuCharV (Vector<uChar>* aDataPtr); 00171 virtual void getScalarColumnShortV (Vector<Short>* aDataPtr); 00172 virtual void getScalarColumnuShortV (Vector<uShort>* aDataPtr); 00173 virtual void getScalarColumnIntV (Vector<Int>* aDataPtr); 00174 virtual void getScalarColumnuIntV (Vector<uInt>* aDataPtr); 00175 virtual void getScalarColumnfloatV (Vector<float>* aDataPtr); 00176 virtual void getScalarColumndoubleV (Vector<double>* aDataPtr); 00177 virtual void getScalarColumnComplexV (Vector<Complex>* aDataPtr); 00178 virtual void getScalarColumnDComplexV (Vector<DComplex>* aDataPtr); 00179 virtual void getScalarColumnStringV (Vector<String>* aDataPtr); 00180 // </group> 00181 00182 // Put the scalar values of the entire column. 00183 // It invalidates the cache. 00184 // <group> 00185 virtual void putScalarColumnBoolV (const Vector<Bool>* aDataPtr); 00186 virtual void putScalarColumnuCharV (const Vector<uChar>* aDataPtr); 00187 virtual void putScalarColumnShortV (const Vector<Short>* aDataPtr); 00188 virtual void putScalarColumnuShortV (const Vector<uShort>* aDataPtr); 00189 virtual void putScalarColumnIntV (const Vector<Int>* aDataPtr); 00190 virtual void putScalarColumnuIntV (const Vector<uInt>* aDataPtr); 00191 virtual void putScalarColumnfloatV (const Vector<float>* aDataPtr); 00192 virtual void putScalarColumndoubleV (const Vector<double>* aDataPtr); 00193 virtual void putScalarColumnComplexV (const Vector<Complex>* aDataPtr); 00194 virtual void putScalarColumnDComplexV (const Vector<DComplex>* aDataPtr); 00195 virtual void putScalarColumnStringV (const Vector<String>* aDataPtr); 00196 // </group> 00197 00198 // Add (NewNrRows-OldNrRows) rows to the Column and initialize 00199 // the new rows when needed. 00200 virtual void addRow (uInt aNewNrRows, uInt anOldNrRows, Bool doInit); 00201 00202 // Remove the given row from the data bucket and possibly string bucket. 00203 // If needed, it also removes it from the cache. 00204 virtual void deleteRow (uInt aRowNr); 00205 00206 // Get the size of the dataType in bytes!! 00207 uInt getExternalSizeBytes() const; 00208 00209 // Get the size of the dataType in bits!! 00210 uInt getExternalSizeBits() const; 00211 00212 // get the sequence number of this column. 00213 uInt getColNr(); 00214 00215 // set the sequence number of this column. 00216 void setColNr (uInt aColNr); 00217 00218 // If something special has to be done before removing the Column, 00219 // as is the case with Strings, it can be done here. 00220 void removeColumn(); 00221 00222 protected: 00223 // Shift the rows in the bucket one to the left when removing the given row. 00224 void shiftRows (char* aValue, uInt rowNr, uInt startRow, uInt endRow); 00225 00226 // Fill the cache with data of the bucket containing the given row. 00227 void getValue (uInt aRowNr); 00228 00229 // Get the bucketnr, offset, and length of a variable length string. 00230 // <src>data</src> must have 3 Ints to hold the values. 00231 // It returns a pointer to the data in the bucket, which can be used 00232 // for the case that the data bucket contains the (short) string. 00233 Char* getRowValue (Int* data, uInt aRowNr); 00234 00235 // Put the given value for the row into the correct data bucket. 00236 void putValue (uInt aRowNr, const void* aValue); 00237 00238 // Put the given string for the row into the correct data bucket. 00239 // The argument <src>aValue></src> must be 3 Ints (for bucketnr, offset, 00240 // and length). Only the length is actually used. 00241 void putValueShortString (uInt aRowNr, const void* aValue, 00242 const String& string); 00243 00244 // Get the values for the entire column. 00245 // The data from all buckets is copied to the array. 00246 void getColumnValue (void* anArray, uInt aNrRows); 00247 00248 // Put the values from the array in the entire column. 00249 // Each data bucket is filled with the the appropriate part of the array. 00250 void putColumnValue (const void* anArray, uInt aNrRows); 00251 00252 00253 // Pointer to the parent storage manager. 00254 SSMBase* itsSSMPtr; 00255 // Length of column cell value in storage format (0 = variable length). 00256 uInt itsExternalSizeBytes; 00257 uInt itsExternalSizeBits; 00258 // Column sequence number of this column. 00259 uInt itsColNr; 00260 // The shape of the column. 00261 IPosition itsShape; 00262 // The maximum length of a 'fixed length' string. 00263 uInt itsMaxLen; 00264 // Number of elements in a value for this column. 00265 uInt itsNrElem; 00266 // Number of values to be copied. 00267 // Normally this is itsNrElem, but for complex types it is 2*itsNrElem. 00268 // When local format is used, it is the number of bytes. 00269 uInt itsNrCopy; 00270 // The sizeof the datatype in local format 00271 uInt itsLocalSize; 00272 // The data in local format. 00273 void* itsData; 00274 // Pointer to a convert function for writing. 00275 Conversion::ValueFunction* itsWriteFunc; 00276 // Pointer to a convert function for reading. 00277 Conversion::ValueFunction* itsReadFunc; 00278 00279 private: 00280 // Forbid copy constructor. 00281 SSMColumn (const SSMColumn&); 00282 00283 // Forbid assignment. 00284 SSMColumn& operator= (const SSMColumn&); 00285 00286 // Initialize part of the object. 00287 // It determines the nr of elements, the function to use to convert 00288 // from local to file format, etc.. 00289 void init(); 00290 00291 // Get the pointer to the cache. It is created if not done yet. 00292 char* getDataPtr(); 00293 }; 00294 00295 00296 inline uInt SSMColumn::getExternalSizeBytes() const 00297 { 00298 return itsExternalSizeBytes; 00299 } 00300 00301 inline uInt SSMColumn::getExternalSizeBits() const 00302 { 00303 return itsExternalSizeBits; 00304 } 00305 00306 inline char* SSMColumn::getDataPtr() 00307 { 00308 if (itsData == 0) { 00309 itsData = new char[itsSSMPtr->getRowsPerBucket(itsColNr) * itsLocalSize]; 00310 } 00311 return static_cast<char*>(itsData); 00312 } 00313 00314 inline uInt SSMColumn::getColNr() 00315 { 00316 return itsColNr; 00317 } 00318 00319 inline void SSMColumn::setColNr (uInt aColNr) 00320 { 00321 itsColNr = aColNr; 00322 } 00323 00324 00325 00326 } //# NAMESPACE CASA - END 00327 00328 #endif