casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ISMIndColumn.h
Go to the documentation of this file.
00001 //# ISMIndColumn.h: A column in Incremental storage manager for indirect arrays
00002 //# Copyright (C) 1996,1997,1998,1999,2002
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: ISMIndColumn.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_ISMINDCOLUMN_H
00029 #define TABLES_ISMINDCOLUMN_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/ISMColumn.h>
00035 #include <tables/Tables/StIndArray.h>
00036 #include <casa/Arrays/IPosition.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 class StManArrayFile;
00042 class AipsIO;
00043 
00044 
00045 // <summary>
00046 // A column of Incremental storage manager for indirect arrays.
00047 // </summary>
00048 
00049 // <use visibility=local>
00050 
00051 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00052 // </reviewed>
00053 
00054 // <prerequisite>
00055 //# Classes you should understand before using this one.
00056 //   <li> <linkto class=ISMColumn>ISMColumn</linkto>
00057 //   <li> <linkto class=StIndArray>StIndArray</linkto>
00058 // </prerequisite>
00059 
00060 // <etymology>
00061 // ISMIndColumn represents a Column in the Incremental Storage Manager
00062 // containing INDirect arrays.
00063 // </etymology>
00064 
00065 // <synopsis> 
00066 // ISMIndColumn is the implementation of an
00067 // <linkto class=ISMColumn>ISMColumn</linkto> class
00068 // to handle indirect arrays. The arrays (shape and data) are stored in
00069 // a separate file using class <linkto class=StIndArray>StIndArray</linkto>.
00070 // The file offset of the beginning of the array in stored in the
00071 // ISM using the standard ISMColumn functions.
00072 // <p>
00073 // ISMIndColumn contains functions which are called when ISMColumn
00074 // duplicates or removes a value. In that way the array can also be
00075 // duplicated or removed in the StIndArray file by incrementing or
00076 // decrementing the reference count manitained in the file.
00077 // <p>
00078 // Unlike ISMColumn it is not tested if a value put is equal to
00079 // the value in the previous or next row, because it is too time-consuming
00080 // to do so (although this behaviour could be changed in the future).
00081 // Instead the user should not put equal values to prevent storing
00082 // equal values.
00083 // <p>
00084 // Note that an indirect array can have a fixed shape. In that case
00085 // adding a row results in reserving space for the array in the StIndArray
00086 // file, so for each row an array is present.
00087 // On the other hand adding a row does nothing for variable shaped arrays.
00088 // So when no data is put or shape is set, a row may contain no array at all.
00089 // In that case the function <src>isShapeDefined</src> returns False for
00090 // that row.
00091 // </synopsis> 
00092 
00093 // <todo asof="$DATE:$">
00094 //# A List of bugs, limitations, extensions or planned refinements.
00095 //   <li> Maybe TpArrayInt, etc. should be used instead of TpInt.
00096 // </todo>
00097 
00098 
00099 class ISMIndColumn : public ISMColumn
00100 {
00101 public:
00102 
00103     // Create a column of the given data type.
00104     // It keeps the pointer to its parent (but does not own it).
00105     ISMIndColumn (ISMBase* parent, int dataType, uInt colnr);
00106 
00107     // Frees up the storage.
00108     ~ISMIndColumn();
00109 
00110     // It can handle access to a slice in a cell.
00111     virtual Bool canAccessSlice (Bool& reask) const;
00112 
00113     // Add (newNrrow-oldNrrow) rows to the column.
00114     virtual void addRow (uInt newNrrow, uInt oldNrrow);
00115 
00116     // Set the (fixed) shape of the arrays in the entire column.
00117     virtual void setShapeColumn (const IPosition& shape);
00118 
00119     // Get the dimensionality of the item in the given row.
00120     virtual uInt ndim (uInt rownr);
00121 
00122     // Set the shape of the array in the given row and allocate the array
00123     // in the file.
00124     void setShape (uInt rownr, const IPosition& shape);
00125 
00126     // Is the shape defined (i.e. is there an array) in this row?
00127     virtual Bool isShapeDefined (uInt rownr);
00128 
00129     // Get the shape of the array in the given row.
00130     virtual IPosition shape (uInt rownr);
00131 
00132     // This storage manager can handle changing array shapes.
00133     Bool canChangeShape() const;
00134 
00135     // Get an array value in the given row.
00136     // The buffer pointed to by dataPtr has to have the correct length
00137     // (which is guaranteed by the ArrayColumn get function).
00138     // <group>
00139     virtual void getArrayBoolV     (uInt rownr, Array<Bool>* dataPtr);
00140     virtual void getArrayuCharV    (uInt rownr, Array<uChar>* dataPtr);
00141     virtual void getArrayShortV    (uInt rownr, Array<Short>* dataPtr);
00142     virtual void getArrayuShortV   (uInt rownr, Array<uShort>* dataPtr);
00143     virtual void getArrayIntV      (uInt rownr, Array<Int>* dataPtr);
00144     virtual void getArrayuIntV     (uInt rownr, Array<uInt>* dataPtr);
00145     virtual void getArrayfloatV    (uInt rownr, Array<float>* dataPtr);
00146     virtual void getArraydoubleV   (uInt rownr, Array<double>* dataPtr);
00147     virtual void getArrayComplexV  (uInt rownr, Array<Complex>* dataPtr);
00148     virtual void getArrayDComplexV (uInt rownr, Array<DComplex>* dataPtr);
00149     virtual void getArrayStringV   (uInt rownr, Array<String>* dataPtr);
00150     // </group>
00151 
00152     // Put an array value into the given row.
00153     // The buffer pointed to by dataPtr has to have the correct length
00154     // (which is guaranteed by the ArrayColumn put function).
00155     // <group>
00156     virtual void putArrayBoolV     (uInt rownr, const Array<Bool>* dataPtr);
00157     virtual void putArrayuCharV    (uInt rownr, const Array<uChar>* dataPtr);
00158     virtual void putArrayShortV    (uInt rownr, const Array<Short>* dataPtr);
00159     virtual void putArrayuShortV   (uInt rownr, const Array<uShort>* dataPtr);
00160     virtual void putArrayIntV      (uInt rownr, const Array<Int>* dataPtr);
00161     virtual void putArrayuIntV     (uInt rownr, const Array<uInt>* dataPtr);
00162     virtual void putArrayfloatV    (uInt rownr, const Array<float>* dataPtr);
00163     virtual void putArraydoubleV   (uInt rownr, const Array<double>* dataPtr);
00164     virtual void putArrayComplexV  (uInt rownr, const Array<Complex>* dataPtr);
00165     virtual void putArrayDComplexV (uInt rownr, const Array<DComplex>* dataPtr);
00166     virtual void putArrayStringV   (uInt rownr, const Array<String>* dataPtr);
00167     // </group>
00168 
00169     // Get a section of the array in the given row.
00170     // The buffer pointed to by dataPtr has to have the correct length
00171     // (which is guaranteed by the ArrayColumn getSlice function).
00172     // <group>
00173     virtual void getSliceBoolV     (uInt rownr, const Slicer&,
00174                                     Array<Bool>* dataPtr);
00175     virtual void getSliceuCharV    (uInt rownr, const Slicer&,
00176                                     Array<uChar>* dataPtr);
00177     virtual void getSliceShortV    (uInt rownr, const Slicer&,
00178                                     Array<Short>* dataPtr);
00179     virtual void getSliceuShortV   (uInt rownr, const Slicer&,
00180                                     Array<uShort>* dataPtr);
00181     virtual void getSliceIntV      (uInt rownr, const Slicer&,
00182                                     Array<Int>* dataPtr);
00183     virtual void getSliceuIntV     (uInt rownr, const Slicer&,
00184                                     Array<uInt>* dataPtr);
00185     virtual void getSlicefloatV    (uInt rownr, const Slicer&,
00186                                     Array<float>* dataPtr);
00187     virtual void getSlicedoubleV   (uInt rownr, const Slicer&,
00188                                     Array<double>* dataPtr);
00189     virtual void getSliceComplexV  (uInt rownr, const Slicer&,
00190                                     Array<Complex>* dataPtr);
00191     virtual void getSliceDComplexV (uInt rownr, const Slicer&,
00192                                     Array<DComplex>* dataPtr);
00193     virtual void getSliceStringV   (uInt rownr, const Slicer&,
00194                                     Array<String>* dataPtr);
00195     // </group>
00196 
00197     // Put into a section of the array in the given row.
00198     // The buffer pointed to by dataPtr has to have the correct length
00199     // (which is guaranteed by the ArrayColumn putSlice function).
00200     // <group>
00201     virtual void putSliceBoolV     (uInt rownr, const Slicer&,
00202                                     const Array<Bool>* dataPtr);
00203     virtual void putSliceuCharV    (uInt rownr, const Slicer&,
00204                                     const Array<uChar>* dataPtr);
00205     virtual void putSliceShortV    (uInt rownr, const Slicer&,
00206                                     const Array<Short>* dataPtr);
00207     virtual void putSliceuShortV   (uInt rownr, const Slicer&,
00208                                     const Array<uShort>* dataPtr);
00209     virtual void putSliceIntV      (uInt rownr, const Slicer&,
00210                                     const Array<Int>* dataPtr);
00211     virtual void putSliceuIntV     (uInt rownr, const Slicer&,
00212                                     const Array<uInt>* dataPtr);
00213     virtual void putSlicefloatV    (uInt rownr, const Slicer&,
00214                                     const Array<float>* dataPtr);
00215     virtual void putSlicedoubleV   (uInt rownr, const Slicer&,
00216                                     const Array<double>* dataPtr);
00217     virtual void putSliceComplexV  (uInt rownr, const Slicer&,
00218                                     const Array<Complex>* dataPtr);
00219     virtual void putSliceDComplexV (uInt rownr, const Slicer&,
00220                                     const Array<DComplex>* dataPtr);
00221     virtual void putSliceStringV   (uInt rownr, const Slicer&,
00222                                     const Array<String>* dataPtr);
00223     // </group>
00224 
00225     // Let the column object create its array file.
00226     virtual void doCreate (ISMBucket* bucket);
00227 
00228     // Let the column object open an existing file.
00229     virtual void getFile (uInt nrrow);
00230 
00231     // Flush and optionally fsync the data.
00232     virtual Bool flush (uInt nrrow, Bool fsync);
00233 
00234     // Resync the storage manager with the new file contents.
00235     virtual void resync (uInt nrrow);
00236 
00237     // Let the column reopen its data files for read/write access.
00238     virtual void reopenRW();
00239 
00240     // Handle the duplication of a value; i.e. increment its reference count.
00241     virtual void handleCopy (uInt rownr, const char* value);
00242 
00243     // Handle the removal of a value; i.e. decrement its reference count.
00244     virtual void handleRemove (uInt rownr, const char* value);
00245 
00246 private:
00247     // Forbid copy constructor.
00248     ISMIndColumn (const ISMIndColumn&);
00249 
00250     // Forbid assignment.
00251     ISMIndColumn& operator= (const ISMIndColumn&);
00252 
00253     // Initialize part of the object and open/create the file.
00254     // It is used by doCreate and getFile.
00255     void init (ByteIO::OpenOption fileOption);
00256 
00257     // Clear the object (used by destructor and init).
00258     void clear();
00259 
00260     // Compare the values to check if a value to be put matches the
00261     // value in the previous or next row.
00262     // It always return False, because comparing large arrays is
00263     // too expensive (it could be changed in the future). 
00264     virtual Bool compareValue (const void* val1, const void* val2) const;
00265 
00266     // Read the shape at the given row.
00267     // This will cache the information in the StIndArray
00268     // object for that row.
00269     StIndArray* getShape (uInt rownr);
00270 
00271     // Put the shape for an array being put.
00272     // When there are multiple rows in the interval, it will
00273     // split the interval.
00274     StIndArray* putShape (uInt rownr, const IPosition& shape);
00275 
00276     // Put the shape for an array of which a slice is being put.
00277     // It gets the shape for the given row.
00278     // When there are multiple rows in the interval, it will
00279     // split the interval and copy the data.
00280     StIndArray* putShapeSliced (uInt rownr);
00281 
00282     // Return a pointer to the array in the given row (for a get).
00283     StIndArray* getArrayPtr (uInt rownr);
00284 
00285     // When needed, create an array in the given row with the given shape.
00286     // When the array is created, its data are copied when the flag is set.
00287     StIndArray* putArrayPtr (uInt rownr, const IPosition& shape,
00288                              Bool copyData);
00289 
00290 
00291     // The (unique) sequence number of the column.
00292     uInt            seqnr_p;
00293     // The shape of all arrays in case it is fixed.
00294     IPosition       fixedShape_p;
00295     // Switch indicating if the shape is fixed.
00296     Bool            shapeIsFixed_p;
00297     // The file containing the arrays.
00298     StManArrayFile* iosfile_p;
00299     // The indirect array object.
00300     StIndArray      indArray_p;
00301     // The indirect array exists for the row interval last accessed.
00302     Bool            foundArray_p;
00303 };
00304 
00305 
00306 
00307 
00308 } //# NAMESPACE CASA - END
00309 
00310 #endif