casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TSMCubeBuff.h
Go to the documentation of this file.
00001 //# TSMCubeBuff.h: Tiled hypercube in a table
00002 //# Copyright (C) 2009
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: TSMCubeBuff.h 20874 2010-03-30 06:28:34Z gervandiepen $
00027 
00028 #ifndef TABLES_TSMCUBEBUFF_H
00029 #define TABLES_TSMCUBEBUFF_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/TSMCube.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward declarations
00039 class BucketBuffered;
00040 
00041 // <summary>
00042 // Tiled hypercube in a table
00043 // </summary>
00044 
00045 // <use visibility=local>
00046 
00047 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00048 // </reviewed>
00049 
00050 // <prerequisite>
00051 //# Classes you should understand before using this one.
00052 //   <li> <linkto class=TiledStMan>TiledStMan</linkto>
00053 //   <li> <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
00054 //        for a discussion of the maximum cache size
00055 //   <li> <linkto class=TSMFile>TSMFile</linkto>
00056 //   <li> <linkto class=BucketBuffered>BucketBuffered</linkto>
00057 // </prerequisite>
00058 
00059 // <etymology>
00060 // TSMCubeBuff represents a hypercube in the Tiled Storage Manager.
00061 // </etymology>
00062 
00063 // <synopsis>
00064 // TSMCubeBuff defines a tiled hypercube. The data is stored in a TSMFile
00065 // object and accessed using a BucketBuffered object. The hypercube can
00066 // be extensible in its last dimension to support tables with a size
00067 // which is not known in advance.
00068 // <br>
00069 // Normally hypercubes share the same TSMFile object, but extensible
00070 // hypercubes have their own TSMFile object (to be extensible).
00071 // If the hypercolumn has multiple data columns, their cells share the same
00072 // tiles. Per tile data column A appears first, thereafter B, etc..
00073 // <br>
00074 // The data in the cache is held in external format and is converted
00075 // when accessed. The alternative would be to hold it in the cache in
00076 // local format and convert it when read/written from the file. It was
00077 // felt that the latter approach would generate more needless conversions.
00078 // <p>
00079 // The possible id and coordinate values are stored in a Record
00080 // object. They are written in the main hypercube AipsIO file.
00081 // <p>
00082 // TSMCubeBuff uses the maximum cache size set for a Tiled Storage manager.
00083 // The description of class
00084 // <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
00085 // contains a discussion about the effect of setting the maximum cache size.
00086 // </synopsis> 
00087 
00088 // <motivation>
00089 // TSMCubeBuff encapsulates all operations on a hypercube.
00090 // </motivation>
00091 
00092 //# <todo asof="$DATE:$">
00093 //# A List of bugs, limitations, extensions or planned refinements.
00094 //# </todo>
00095 
00096 
00097 class TSMCubeBuff: public TSMCube
00098 {
00099 public:
00100     // Construct the hypercube using the given file with the given shape.
00101     // The record contains the id and possible coordinate values.
00102     // <br>If the cubeshape is empty, the hypercube is still undefined and
00103     // can be added later with setShape. That is only used by TiledCellStMan.
00104     // <br> The fileOffset argument is meant for class TiledFileAccess.
00105     TSMCubeBuff (TiledStMan* stman, TSMFile* file,
00106                  const IPosition& cubeShape,
00107                  const IPosition& tileShape,
00108                  const Record& values, Int64 fileOffset, uInt bufferSize);
00109 
00110     // Reconstruct the hypercube by reading its data from the AipsIO stream.
00111     // It will link itself to the correct TSMFile. The TSMFile objects
00112     // must have been reconstructed in advance.
00113     TSMCubeBuff (TiledStMan* stman, AipsIO& ios, uInt bufferSize);
00114 
00115     virtual ~TSMCubeBuff();
00116 
00117     // Flush the data in the cache.
00118     virtual void flushCache();
00119 
00120     // Show the cache statistics.
00121     virtual void showCacheStatistics (ostream& os) const;
00122 
00123     // Set the hypercube shape.
00124     // This is only possible if the shape was not defined yet.
00125     virtual void setShape (const IPosition& cubeShape,
00126                            const IPosition& tileShape);
00127 
00128     // Extend the last dimension of the cube with the given number.
00129     // The record can contain the coordinates of the elements added.
00130     virtual void extend (uInt nr, const Record& coordValues,
00131                          const TSMColumn* lastCoordColumn);
00132 
00133     // Read or write a section in the cube.
00134     // It is assumed that the section buffer is long enough.
00135     virtual void accessSection (const IPosition& start, const IPosition& end,
00136                                 char* section, uInt colnr,
00137                                 uInt localPixelSize, uInt externalPixelSize,
00138                                 Bool writeFlag);
00139 
00140     // Read or write a section in a strided way.
00141     // It is assumed that the section buffer is long enough.
00142     virtual void accessStrided (const IPosition& start, const IPosition& end,
00143                                 const IPosition& stride,
00144                                 char* section, uInt colnr,
00145                                 uInt localPixelSize, uInt externalPixelSize,
00146                                 Bool writeFlag);
00147 
00148     // Set the cache size for the given slice and access path.
00149     virtual void setCacheSize (const IPosition& sliceShape,
00150                                const IPosition& windowStart,
00151                                const IPosition& windowLength,
00152                                const IPosition& axisPath,
00153                                Bool forceSmaller, Bool userSet);
00154 
00155     // Resize the cache object.
00156     // If forceSmaller is False, the cache will only be resized when it grows.
00157     // If the given size exceeds the maximum size with more
00158     // than 10%, the maximum size will be used.
00159     // The cacheSize has to be given in buckets.
00160     // <br>The flag <src>userSet</src> inidicates if the cache size is set by
00161     // the user (by an Accessor object) or automatically (by TSMDataColumn).
00162     virtual void setCacheSize (uInt cacheSize, Bool forceSmaller, Bool userSet);
00163 
00164 private:
00165     // Forbid copy constructor.
00166     TSMCubeBuff (const TSMCubeBuff&);
00167 
00168     // Forbid assignment.
00169     TSMCubeBuff& operator= (const TSMCubeBuff&);
00170 
00171     // Get the cache object.
00172     // This will construct the cache object if not present yet.
00173     BucketBuffered* getCache();
00174 
00175     // Construct the cache object (if not constructed yet).
00176     virtual void makeCache();
00177 
00178     // Resync the cache object.
00179     virtual void resyncCache();
00180 
00181     // Delete the cache object.
00182     virtual void deleteCache();
00183 
00184     //# Declare member variables.
00185     // The bucket cache.
00186     BucketBuffered* cache_p;
00187     // The buffer size to use.
00188     uInt bufferSize_p;
00189 };
00190 
00191 
00192 
00193 inline BucketBuffered* TSMCubeBuff::getCache()
00194 {
00195     if (cache_p == 0) {
00196         makeCache();
00197     }
00198     return cache_p;
00199 }
00200 
00201 
00202 
00203 } //# NAMESPACE CASA - END
00204 
00205 #endif