casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LatticeBase.h
Go to the documentation of this file.
00001 //# LatticeBase.h: A non-templated, abstract base class for array-like classes
00002 //# Copyright (C) 1999,2000,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: LatticeBase.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $
00027 
00028 #ifndef LATTICES_LATTICEBASE_H
00029 #define LATTICES_LATTICEBASE_H
00030 
00031 
00032 //# Includes
00033 #include <lattices/Lattices/LELCoordinates.h>
00034 #include <casa/Arrays/IPosition.h>
00035 #include <casa/Utilities/DataType.h>
00036 #include <casa/IO/FileLocker.h>
00037 #include <casa/BasicSL/String.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 //# Forward Declarations
00042 class LogIO;
00043 
00044 
00045 // <summary>
00046 // A non-templated, abstract base class for array-like objects.
00047 // </summary>
00048 
00049 // <use visibility=export>
00050 
00051 // <reviewed reviewer="Bob Garwood" date="2000/01/18" tests="tArrayLattice.cc" demos="dLattice.cc">
00052 // </reviewed>
00053 
00054 // <synopsis>
00055 // This pure abstract base class defines the operations which may be
00056 // performed on a lattice of any type.
00057 // <br>See class <linkto class=Lattice>Lattice</linkto> for a detailed
00058 // description of a lattice.
00059 // </synopsis> 
00060 
00061 // <motivation>
00062 // It is very useful to be able to keep a pointer to a
00063 // non-templated base class. Furthermore it gives the opportunity to
00064 // factor out some non-templated code.
00065 // </motivation>
00066 
00067 // <note>
00068 // The cache functions (maximumCacheSize, setMaximumCacheSize,
00069 // setCacheSizeInTiles, setCacheSizeFromPath, clearCache, and
00070 // showCacheStatistics) should all be over-ridden together as
00071 // in PagedArray.
00072 // </note>
00073 //
00074 //# <todo asof="1999/02/04">
00075 //#   <li>
00076 //# </todo>
00077 
00078 
00079 class LatticeBase
00080 {
00081 public: 
00082   // A virtual destructor is needed so that it will use the actual destructor
00083   // in the derived class.
00084   virtual ~LatticeBase();
00085 
00086   // Make a copy of the derived object (reference semantics).
00087   virtual LatticeBase* clone() const = 0;
00088 
00089   // Get the data type of the lattice.
00090   virtual DataType dataType() const = 0;
00091 
00092   // Is the lattice persistent and can it be loaded by other processes as well?
00093   // That is the case for a PagedArray or PagedImage and for an ImageExpr
00094   // which does not use transient lattices or regions.
00095   // <br>The default implementation returns False.
00096   virtual Bool isPersistent() const;
00097 
00098   // Is the lattice paged to disk?
00099   // <br>The default implementation returns False.
00100   virtual Bool isPaged() const;
00101 
00102   // Can the lattice data be referenced as an array section?
00103   // That is the case for an ArrayLattice or a Temp/SubLattice using it.
00104   // It is used by LatticeIterInterface.
00105   // <br>The default implementation returns False.
00106   virtual Bool canReferenceArray() const;
00107 
00108   // Is the lattice writable?
00109   // <br>The default implementation returns True.
00110   virtual Bool isWritable() const;
00111 
00112   // It is strongly recommended to use class
00113   // <linkto class=LatticeLocker>LatticeLocker</linkto> to
00114   // handle lattice locking. It also contains a more detailed
00115   // explanation of the locking process.
00116   // <br>By default the functions do not do anything at all.
00117   // lock() and hasLock return True, which is suitable for all
00118   // non-paged lattices.
00119   // <group>
00120   virtual Bool lock (FileLocker::LockType, uInt nattempts);
00121   virtual void unlock();
00122   virtual Bool hasLock (FileLocker::LockType) const;
00123   // </group>
00124 
00125   // Resynchronize the Lattice object with the lattice file.
00126   // This function is only useful if no read-locking is used, ie.
00127   // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
00128   // In that cases the table system does not acquire a read-lock, thus
00129   // does not synchronize itself automatically.
00130   // <br>By default the function does not do anything at all.
00131   virtual void resync();
00132 
00133   // Flush the data (but do not unlock).
00134   // <br>By default the function does not do anything at all.
00135   virtual void flush();
00136 
00137   // Temporarily close the lattice.
00138   // It will be reopened automatically on the next access.
00139   // <br>By default the function does not do anything at all.
00140   virtual void tempClose();
00141 
00142   // Explicitly reopen the temporarily closed lattice.
00143   // <br>By default the function does not do anything at all.
00144   virtual void reopen();
00145 
00146   // Return the name of the current Lattice object. This will generally 
00147   // be a file name for lattices that have a persistent form.  Any path
00148   // before the actual file name can be optionally stripped off.
00149   // <br>The default implementation returns an empty string.
00150   virtual String name (Bool stripPath=False) const;
00151 
00152   // Return the shape of the Lattice including all degenerate axes
00153   // (ie. axes with a length of one)
00154   virtual IPosition shape() const = 0;
00155   
00156   // Return the number of axes in this Lattice. This includes all
00157   // degenerate axes.
00158   // <br>The default implementation returns shape().nelements().
00159   virtual uInt ndim() const;
00160   
00161   // Return the total number of elements in this Lattice.
00162   // <br>The default implementation returns shape().product().
00163   // <group>
00164   virtual size_t nelements() const;
00165   size_t size() const
00166     { return nelements(); }
00167   // </group>
00168 
00169   // Return a value of "True" if this instance of Lattice and 'other' have 
00170   // the same shape, otherwise returns a value of "False".
00171   Bool conform (const LatticeBase& other) const
00172     { return shape().isEqual (other.shape()); }
00173 
00174   // Return the coordinates of the lattice.
00175   // <br>The default implementation returns an 'empty' LELLattCoord object.
00176   virtual LELCoordinates lelCoordinates() const;
00177 
00178   // This function returns the recommended maximum number of pixels to
00179   // include in the cursor of an iterator. The Lattice class has a default
00180   // implementation which returns a number that is a power of two and
00181   // includes enough pixels to consume between 4 and 8 MBytes of memory.
00182   virtual uInt advisedMaxPixels() const = 0;
00183 
00184   // Returns a recommended cursor shape for iterating through all the pixels
00185   // in the Lattice. The default implementation sets up a shape that
00186   // completely fills as many axes as possible, but always at least the
00187   // first axis. For example, given a 10x20x30 Lattice 
00188   // <srcblock>
00189   // maxPixels = 1     --> niceCursorShape = [10,1,1]
00190   //             100   --> niceCursorShape = [10,1,1]
00191   //             300   --> niceCursorShape = [10,20,1] 
00192   //             10000 --> niceCursorShape = [10,20,30] 
00193   // </srcblock>
00194   // The default argument is the result of <src>advisedMaxPixels()</src>.
00195   // <group>
00196   IPosition niceCursorShape (uInt maxPixels) const
00197     { return doNiceCursorShape (maxPixels); }
00198   IPosition niceCursorShape() const
00199     { return doNiceCursorShape (advisedMaxPixels()); }
00200   // </group>
00201 
00202   // Check class internals - used for debugging. Should always return True
00203   virtual Bool ok() const;
00204 
00205   // The function (in the derived classes) doing the actual work.
00206   // This function is public, so it can be used internally in the
00207   // various Lattice classes.
00208   // <br>The default implementation tries to fit as many axes
00209   // as possible given <src>maxPixels</src>.
00210   virtual IPosition doNiceCursorShape (uInt maxPixels) const;
00211 
00212   // Maximum cache size - not necessarily all used. In pixels.
00213   // Default returns 0, which means that there is no maximum.
00214   virtual uInt maximumCacheSize() const;
00215 
00216   // Set the maximum (allowed) cache size as indicated.
00217   // <br>The default implementation does nothing.
00218   virtual void setMaximumCacheSize (uInt howManyPixels);
00219 
00220   // Set the actual cache size for this Array to be big enough for the
00221   // indicated number of tiles. This cache is not shared with PagedArrays
00222   // in other rows and is always clipped to be less than the maximum value
00223   // set using the setMaximumCacheSize member function.
00224   // Tiles are cached using a first in first out algorithm.
00225   // <br>The default implementation does nothing.
00226   virtual void setCacheSizeInTiles (uInt howManyTiles);
00227 
00228   // Set the cache size as to "fit" the indicated path.
00229   // <br>The default implementation does nothing.
00230   virtual void setCacheSizeFromPath (const IPosition& sliceShape,
00231                                      const IPosition& windowStart,
00232                                      const IPosition& windowLength,
00233                                      const IPosition& axisPath);
00234 
00235   // Clears and frees up the caches, but the maximum allowed cache size is
00236   // unchanged from when setCacheSize was called.
00237   // <br>The default implementation does nothing.
00238   virtual void clearCache();
00239 
00240   // Report on cache success.
00241   // <br>The default implementation does nothing.
00242   virtual void showCacheStatistics (ostream& os) const;
00243 
00244 
00245 protected:
00246   // Define default constructor to be used by derived classes.
00247   LatticeBase() {};
00248 
00249   // Copy constructor and assignment can only be used by derived classes.
00250   // <group>
00251   LatticeBase (const LatticeBase&) {};
00252   LatticeBase& operator= (const LatticeBase&)
00253     { return *this; }
00254   // </group>
00255 
00256   // Throw an exception for arithmetic on a Bool Lattice.
00257   void throwBoolMath() const;
00258 };
00259 
00260 
00261 
00262 } //# NAMESPACE CASA - END
00263 
00264 #endif