casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Attributes
casa::TempLattice< T > Class Template Reference

A Lattice that can be used for temporary storage. More...

#include <TempLattice.h>

Inheritance diagram for casa::TempLattice< T >:
casa::Lattice< T > casa::LatticeBase

List of all members.

Public Member Functions

 TempLattice ()
 The default constructor creates a TempLattice containing a default ArrayLattice object.
 TempLattice (const TiledShape &shape, Int maxMemoryInMB=-1)
 Create a TempLattice of the specified shape.
 TempLattice (const TiledShape &shape, Double maxMemoryInMB)
 TempLattice (const TempLattice< T > &other)
 The copy constructor uses reference semantics.
virtual ~TempLattice ()
 The destructor removes the Lattice from memory and if necessary disk.
TempLattice< T > & operator= (const TempLattice< T > &other)
 The assignment operator with reference semantics.
virtual Lattice< T > * clone () const
 Make a copy of the object (reference semantics).
virtual Bool isPaged () const
 Is the TempLattice paged to disk?
virtual Bool canReferenceArray () const
 Can the lattice data be referenced as an array section?
virtual Bool isWritable () const
 Is the TempLattice writable? It should be.
virtual void flush ()
 Flush the data.
virtual void tempClose ()
 Close the Lattice temporarily (if it is paged to disk).
virtual void reopen ()
 If needed, reopen a temporarily closed TempLattice.
virtual IPosition shape () const
 Return the shape of the Lattice including all degenerate axes.
virtual void set (const T &value)
 Set all of the elements in the Lattice to the given value.
virtual void apply (T(*function)(T))
 Replace every element, x, of the Lattice with the result of f(x).
virtual void apply (T(*function)(const T &))
virtual void apply (const Functional< T, T > &function)
virtual uInt advisedMaxPixels () const
 This function returns the recommended maximum number of pixels to include in the cursor of an iterator.
virtual IPosition doNiceCursorShape (uInt maxPixels) const
 Get the best cursor shape.
virtual uInt maximumCacheSize () const
 Maximum size - not necessarily all used.
virtual void setMaximumCacheSize (uInt howManyPixels)
 Set the maximum (allowed) cache size as indicated.
virtual void setCacheSizeFromPath (const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath)
 Set the cache size as to "fit" the indicated path.
virtual void setCacheSizeInTiles (uInt howManyTiles)
 Set the actual cache size for this Array to be be big enough for the indicated number of tiles.
virtual void clearCache ()
 Clears and frees up the caches, but the maximum allowed cache size is unchanged from when setCacheSize was called.
virtual void showCacheStatistics (ostream &os) const
 Report on cache success.
virtual T getAt (const IPosition &where) const
 Get or put a single element in the lattice.
virtual void putAt (const T &value, const IPosition &where)
 Put the value of a single element.
virtual Bool ok () const
 Check class internals - used for debugging.
virtual LatticeIterInterface< T > * makeIter (const LatticeNavigator &navigator, Bool useRef) const
 This function is used by the LatticeIterator class to generate an iterator of the correct type for this Lattice.
virtual Bool doGetSlice (Array< T > &buffer, const Slicer &section)
 Do the actual getting of an array of values.
virtual void doPutSlice (const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
 Do the actual getting of an array of values.

Private Attributes

CountedPtr< TempLatticeImpl< T > > itsImpl

Detailed Description

template<class T>
class casa::TempLattice< T >

A Lattice that can be used for temporary storage.

Intended use:

Public interface

Review Status

Reviewed By:
Peter Barnes
Date Reviewed:
1999/10/30
Test programs:
tTempLattice

Prerequisite

Etymology

A TempLattice disappears from both memory and disk when it goes out of scope. Hence it is only useful for temporary storage of data.

Synopsis

Lattice classes are designed to allow the memory-efficient handling of large amounts of data. But they can also used with much smaller arrays. With large amounts of data the PagedArray class should be used, as this will store the data on disk and efficiently access specified portions of the data on request. With small amounts of data the ArrayLattice class should be used as all the data is always in memory avoiding the I/O associated with PagedArrays.

Applications often cannot predict until run time whether they will be dealing with a large or small amount of data. So the use of a PagedArray or an ArrayLattice cannot be made until the size of the arrays are known. TempLattice makes this decision given the size of the Array. To help in making a good choice the TempLattice class also examines how much memory the operating system has (using an aipsrc variable) and compares it with the size of the requested Array.

The algorithm currently used is: create an ArrayLattice if the size of the array is less than a quarter of the total system memory; otherwise a PagedArray is created. The PagedArray is stored in the current working directory and given a unique name that contains the string "pagedArray". This pagedArray will be deleted once the TempLattice goes out of scope. So unlike PagedArrays which can be made to exist longer than the time they are used by a process, the PagedArrays created by the TempLattice class are always scratch arrays.

It is possible to temporarily close a TempLattice, which only takes effect when it is created as a PagedArray. In this way it is possible to reduce the number of open files in case a lot of TempLattice objects are used. A temporarily closed TempLattice will be reopened automatically when needed. It can also be reopened explicitly.

You can force the TempLattice to be disk based by setting the memory argument in the constructors to 0

TempLattice is implemented using TempLatticeImpl for reasons explained in that class.

Example

     // Create a temporary lattice and initialize to 0.
     TempLattice<Float> myLat (IPosition(2,1024,1024));
     myLat.set (0.);
     // Temporarily close the lattice.
     myLat.tempClose();
     // Do an operation, which will automatically reopen the lattice.
     myLat.set (1.);
     // Note that the destructor deletes the table (if the TempLattice
     // was created on disk).

Motivation

I needed a temporary Lattice when converting the Convolver class to using Lattices. This was to store the Transfer function.

Template Type Argument Requirements (T)

Definition at line 131 of file TempLattice.h.


Constructor & Destructor Documentation

template<class T>
casa::TempLattice< T >::TempLattice ( ) [inline]

The default constructor creates a TempLattice containing a default ArrayLattice object.

Definition at line 136 of file TempLattice.h.

template<class T>
casa::TempLattice< T >::TempLattice ( const TiledShape shape,
Int  maxMemoryInMB = -1 
) [inline, explicit]

Create a TempLattice of the specified shape.

You can specify how much memory the Lattice can consume before it becomes disk based by giving a non-negative value to the maxMemoryInMB argument. Otherwise it will assume it can use up to 25% of the memory on your machine as defined in aipsrc (this algorithm may change). Setting maxMemoryInMB to zero will force the lattice to disk.

Definition at line 146 of file TempLattice.h.

template<class T>
casa::TempLattice< T >::TempLattice ( const TiledShape shape,
Double  maxMemoryInMB 
) [inline]

Definition at line 148 of file TempLattice.h.

template<class T>
casa::TempLattice< T >::TempLattice ( const TempLattice< T > &  other) [inline]

The copy constructor uses reference semantics.

ie modifying data in the copied TempLattice also modifies the data in the original TempLattice. Passing by value doesn't make sense, because it may require the creation of a temporary (but possibly huge) file on disk.

Definition at line 156 of file TempLattice.h.

template<class T>
virtual casa::TempLattice< T >::~TempLattice ( ) [virtual]

The destructor removes the Lattice from memory and if necessary disk.


Member Function Documentation

template<class T>
virtual uInt casa::TempLattice< T >::advisedMaxPixels ( ) const [virtual]

This function returns the recommended maximum number of pixels to include in the cursor of an iterator.

Reimplemented from casa::Lattice< T >.

template<class T>
virtual void casa::TempLattice< T >::apply ( T(*)(T)  function) [virtual]

Replace every element, x, of the Lattice with the result of f(x).

You must pass in the address of the function -- so the function must be declared and defined in the scope of your program. All versions of apply require a function that accepts a single argument of type T (the Lattice template type) and return a result of the same type. The first apply expects a function with an argument passed by value; the second expects the argument to be passed by const reference; the third requires an instance of the class Functional<T,T>. The first form ought to run faster for the built-in types, which may be an issue for large Lattices stored in memory, where disk access is not an issue.

Reimplemented from casa::Lattice< T >.

template<class T>
virtual void casa::TempLattice< T >::apply ( T(*)(const T &)  function) [virtual]

Reimplemented from casa::Lattice< T >.

template<class T>
virtual void casa::TempLattice< T >::apply ( const Functional< T, T > &  function) [virtual]

Reimplemented from casa::Lattice< T >.

template<class T>
virtual Bool casa::TempLattice< T >::canReferenceArray ( ) const [virtual]

Can the lattice data be referenced as an array section?

Reimplemented from casa::LatticeBase.

template<class T>
virtual void casa::TempLattice< T >::clearCache ( ) [virtual]

Clears and frees up the caches, but the maximum allowed cache size is unchanged from when setCacheSize was called.

Reimplemented from casa::LatticeBase.

template<class T>
virtual Lattice<T>* casa::TempLattice< T >::clone ( ) const [virtual]

Make a copy of the object (reference semantics).

Implements casa::Lattice< T >.

template<class T>
virtual Bool casa::TempLattice< T >::doGetSlice ( Array< T > &  buffer,
const Slicer section 
) [virtual]

Do the actual getting of an array of values.

Implements casa::Lattice< T >.

template<class T>
virtual IPosition casa::TempLattice< T >::doNiceCursorShape ( uInt  maxPixels) const [virtual]

Get the best cursor shape.

Reimplemented from casa::LatticeBase.

template<class T>
virtual void casa::TempLattice< T >::doPutSlice ( const Array< T > &  sourceBuffer,
const IPosition where,
const IPosition stride 
) [virtual]

Do the actual getting of an array of values.

Implements casa::Lattice< T >.

template<class T>
virtual void casa::TempLattice< T >::flush ( ) [virtual]

Flush the data.

Reimplemented from casa::LatticeBase.

template<class T>
virtual T casa::TempLattice< T >::getAt ( const IPosition where) const [virtual]

Get or put a single element in the lattice.

Note that Lattice::operator() can also be used to get a single element.

Reimplemented from casa::Lattice< T >.

template<class T>
virtual Bool casa::TempLattice< T >::isPaged ( ) const [virtual]

Is the TempLattice paged to disk?

Reimplemented from casa::LatticeBase.

template<class T>
virtual Bool casa::TempLattice< T >::isWritable ( ) const [virtual]

Is the TempLattice writable? It should be.

Reimplemented from casa::LatticeBase.

template<class T>
virtual LatticeIterInterface<T>* casa::TempLattice< T >::makeIter ( const LatticeNavigator navigator,
Bool  useRef 
) const [virtual]

This function is used by the LatticeIterator class to generate an iterator of the correct type for this Lattice.

Not recommended for general use.

Reimplemented from casa::Lattice< T >.

template<class T>
virtual uInt casa::TempLattice< T >::maximumCacheSize ( ) const [virtual]

Maximum size - not necessarily all used.

In pixels.

Reimplemented from casa::LatticeBase.

template<class T>
virtual Bool casa::TempLattice< T >::ok ( ) const [virtual]

Check class internals - used for debugging.

Should always return True

Reimplemented from casa::LatticeBase.

template<class T>
TempLattice<T>& casa::TempLattice< T >::operator= ( const TempLattice< T > &  other) [inline]

The assignment operator with reference semantics.

As with the copy constructor assigning by value does not make sense.

Definition at line 164 of file TempLattice.h.

template<class T>
virtual void casa::TempLattice< T >::putAt ( const T &  value,
const IPosition where 
) [virtual]

Put the value of a single element.


The default implementation uses putSlice.

Reimplemented from casa::Lattice< T >.

template<class T>
virtual void casa::TempLattice< T >::reopen ( ) [virtual]

If needed, reopen a temporarily closed TempLattice.

Reimplemented from casa::LatticeBase.

template<class T>
virtual void casa::TempLattice< T >::set ( const T &  value) [virtual]

Set all of the elements in the Lattice to the given value.

Reimplemented from casa::Lattice< T >.

template<class T>
virtual void casa::TempLattice< T >::setCacheSizeFromPath ( const IPosition sliceShape,
const IPosition windowStart,
const IPosition windowLength,
const IPosition axisPath 
) [virtual]

Set the cache size as to "fit" the indicated path.

Reimplemented from casa::LatticeBase.

template<class T>
virtual void casa::TempLattice< T >::setCacheSizeInTiles ( uInt  howManyTiles) [virtual]

Set the actual cache size for this Array to be be big enough for the indicated number of tiles.

This cache is not shared with PagedArrays in other rows and is always clipped to be less than the maximum value set using the setMaximumCacheSize member function. tiles. Tiles are cached using a first in first out algorithm.

Reimplemented from casa::LatticeBase.

template<class T>
virtual void casa::TempLattice< T >::setMaximumCacheSize ( uInt  howManyPixels) [virtual]

Set the maximum (allowed) cache size as indicated.

Reimplemented from casa::LatticeBase.

template<class T>
virtual IPosition casa::TempLattice< T >::shape ( ) const [virtual]

Return the shape of the Lattice including all degenerate axes.

(ie. axes with a length of one)

Implements casa::LatticeBase.

Referenced by casa::LatticeStatistics< Float >::_storageLatticeShape().

template<class T>
virtual void casa::TempLattice< T >::showCacheStatistics ( ostream &  os) const [virtual]

Report on cache success.

Reimplemented from casa::LatticeBase.

template<class T>
virtual void casa::TempLattice< T >::tempClose ( ) [virtual]

Close the Lattice temporarily (if it is paged to disk).

It'll be reopened automatically when needed or when reopen is called explicitly.

Reimplemented from casa::LatticeBase.


Member Data Documentation

template<class T>
CountedPtr<TempLatticeImpl<T> > casa::TempLattice< T >::itsImpl [private]

The documentation for this class was generated from the following file: