casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LatticeRegion.h
Go to the documentation of this file.
00001 //# LatticeRegion.h: An optionally strided region in a lattice
00002 //# Copyright (C) 1998,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 //#
00027 //# $Id: LatticeRegion.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $
00028 
00029 #ifndef LATTICES_LATTICEREGION_H
00030 #define LATTICES_LATTICEREGION_H
00031 
00032 
00033 //# Includes
00034 #include <lattices/Lattices/Lattice.h>
00035 #include <casa/Arrays/Slicer.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward Declarations
00040 class LCRegion;
00041 
00042 
00043 // <summary>
00044 // An optionally strided  region in a Lattice
00045 // </summary>
00046 
00047 // <use visibility=local>
00048 
00049 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00050 // </reviewed>
00051 
00052 // <prerequisite>
00053 //   <li> <linkto class="LCRegion">LCRegion</linkto>
00054 // </prerequisite>
00055 
00056 // <synopsis>
00057 // A LatticeRegion is a lattice referencing a subset of another lattice
00058 // by means of a <linkto class="Slicer">Slicer</linkto> object.
00059 // <br>It is useful when only a subset of a lattice needs to be accessed.
00060 // <p>
00061 // When the LatticeRegion is created from a const <src>Lattice</src> object,
00062 // it is not writable, thus it can only be used as an rvalue.
00063 // </synopsis>
00064 
00065 // <example>
00066 // <srcblock>
00067 // </srcblock>
00068 // </example>
00069 
00070 //# <todo asof="yyyy/mm/dd">
00071 //# </todo>
00072 
00073 class LatticeRegion: public Lattice<Bool>
00074 {
00075 public:
00076     // The default constructor creates a LatticeRegion that is useless for just
00077     // about everything, except that it can be assigned to with the assignment
00078     // operator.
00079     LatticeRegion();
00080 
00081     // Create from the given region.
00082     // The pointer to the parent can be 0.
00083     LatticeRegion (const LCRegion& region);
00084 
00085     // Create from the given region and take over the pointer.
00086     // This means the user should not delete the region object pointed to,
00087     // because it will be deleted by the LatticeRegion destructor.
00088     // The pointer to the parent is set to 0.
00089     LatticeRegion (LCRegion* region);
00090 
00091     // Construct from the given slicer. The lattice shape has to be
00092     // the lattice shape of the lattice where the region is taken from.
00093     LatticeRegion (const Slicer& slicer, const IPosition& latticeShape);
00094 
00095     // Copy constructor (reference semantics).
00096     LatticeRegion (const LatticeRegion& other);
00097 
00098     virtual ~LatticeRegion();
00099 
00100     // Assignment (reference semantics).
00101     LatticeRegion& operator= (const LatticeRegion& other);
00102 
00103     // Make a copy of the object (reference semantics).
00104     virtual Lattice<Bool>* clone() const;
00105 
00106     // Is the LatticeRegion writable?
00107     virtual Bool isWritable() const;
00108 
00109     // Has the region a mask?
00110     Bool hasMask() const;
00111 
00112     // Handle the (un)locking.
00113     // <group>
00114     virtual Bool lock (FileLocker::LockType, uInt nattempts);
00115     virtual void unlock();
00116     virtual Bool hasLock (FileLocker::LockType) const;
00117     // </group>
00118 
00119     // Resynchronize the PagedArray object with the lattice file.
00120     // This function is only useful if no read-locking is used, ie.
00121     // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
00122     // In that cases the table system does not acquire a read-lock, thus
00123     // does not synchronize itself automatically.
00124     virtual void resync();
00125 
00126     // Flush the data (but do not unlock).
00127     virtual void flush();
00128 
00129     // Temporarily close the lattice.
00130     // It will be reopened automatically on the next access.
00131     virtual void tempClose();
00132 
00133     // Explicitly reopen the temporarily closed lattice.
00134     virtual void reopen();
00135 
00136     // Get the LCRegion object describing the region.
00137     // Note that it does not contain strides, even if this LatticeRegion
00138     // object was constructed from a Slicer with strides. In that case
00139     // the region only defines the resulting shape.
00140     const LCRegion& region() const;
00141 
00142     // Get the Slicer object describing the region.
00143     // Note that it may contain strides.
00144     const Slicer& slicer() const;
00145 
00146     // Returns the shape of the LatticeRegion including all degenerate axes
00147     // (i.e. axes with a length of one).
00148     virtual IPosition shape() const;
00149 
00150     // Returns the number of axes in this LatticeRegion. This includes all
00151     // degenerate axes.
00152     virtual uInt ndim() const;
00153 
00154     // Returns the total number of elements in this LatticeRegion.
00155     virtual size_t nelements() const;
00156 
00157     // Check class internals - used for debugging. Should always return True
00158     virtual Bool ok() const;
00159 
00160     // This function is used by the LatticeIterator class to generate an
00161     // iterator of the correct type for this Lattice. Not recommended
00162     // for general use. 
00163     virtual LatticeIterInterface<Bool>*  makeIter
00164                            (const LatticeNavigator& navigator,
00165                             Bool useRef) const;
00166 
00167     // Returns the maximum recommended number of pixels for a cursor.
00168     // This is the number of pixels in a tile. 
00169     virtual uInt advisedMaxPixels() const;
00170 
00171     // Help the user pick a cursor for most efficient access.
00172     virtual IPosition doNiceCursorShape (uInt maxPixels) const;
00173 
00174     // Maximum size - not necessarily all used. In pixels.
00175     virtual uInt maximumCacheSize() const;
00176 
00177     // Set the maximum (allowed) cache size as indicated.
00178     virtual void setMaximumCacheSize (uInt howManyPixels);
00179 
00180     // Set the cache size as to "fit" the indicated path.
00181     virtual void setCacheSizeFromPath (const IPosition& sliceShape,
00182                                        const IPosition& windowStart,
00183                                        const IPosition& windowLength,
00184                                        const IPosition& axisPath);
00185     
00186     // Set the actual cache size for this Array to be be big enough for the
00187     // indicated number of tiles. This cache is not shared with PagedArrays
00188     // in other rows and is always clipped to be less than the maximum value
00189     // set using the setMaximumCacheSize member function.
00190     // tiles. Tiles are cached using a first in first out algorithm. 
00191     virtual void setCacheSizeInTiles (uInt howManyTiles);
00192 
00193     // Clears and frees up the caches, but the maximum allowed cache size is 
00194     // unchanged from when setCacheSize was called
00195     virtual void clearCache();
00196 
00197     // Report on cache success.
00198     virtual void showCacheStatistics (ostream& os) const;
00199 
00200     // The following "put" functions are described in detail in class
00201     // <linkto class=Lattice>Lattice</linkto>.
00202     // They'll throw an exception is no mask is available or if
00203     // the mask is not writable.
00204     // <group>
00205     virtual void set (const Bool& value);
00206     virtual void apply (Bool (*function)(Bool));
00207     virtual void apply (Bool (*function)(const Bool&));
00208     virtual void apply (const Functional<Bool,Bool>& function);
00209     virtual void putAt (const Bool& value, const IPosition& where);
00210     virtual void copyData (const Lattice<Bool>& from);
00211     // </group>
00212 
00213     // Convert positions to positions in the parent object.
00214     // <group>
00215     Slicer convert (const Slicer& slicer) const;
00216     IPosition convert (const IPosition& position) const;
00217     // </group>
00218 
00219     // Do the actual getting of the mask.
00220     virtual Bool doGetSlice (Array<Bool>& buffer, const Slicer& section);
00221 
00222     // Do the actual putting of the mask. Only possible if region is writable.
00223     virtual void doPutSlice (const Array<Bool>& sourceBuffer,
00224                              const IPosition& where,
00225                              const IPosition& stride);
00226 
00227 
00228 private:
00229     LCRegion*  itsRegion;
00230     Slicer     itsSlicer;
00231     Bool       itsHasRegionMask;
00232 };
00233 
00234 
00235 inline Bool LatticeRegion::hasMask() const
00236 {
00237     return itsHasRegionMask;
00238 }
00239 inline const LCRegion& LatticeRegion::region() const
00240 {
00241     return *itsRegion;
00242 }
00243 inline const Slicer& LatticeRegion::slicer() const
00244 {
00245     return itsSlicer;
00246 }
00247 
00248 
00249 
00250 } //# NAMESPACE CASA - END
00251 
00252 #endif