TempLattice.h

Classes

TempLattice -- A Lattice that can be used for temporary storage (full description)

template<class T> class TempLattice : public Lattice<T>

Interface

Public Members
TempLattice()
explicit TempLattice (const TiledShape& shape, Int maxMemoryInMB=-1)
TempLattice (const TiledShape& shape, Double maxMemoryInMB)
TempLattice (const TempLattice<T>& other)
virtual ~TempLattice()
TempLattice<T>& operator= (const TempLattice<T>& other)
virtual Lattice<T>* clone() const
virtual Bool isPaged() const
virtual Bool canReferenceArray() const
virtual Bool isWritable() const
virtual void flush()
virtual void tempClose()
virtual void reopen()
virtual IPosition shape() const
virtual uInt ndim() const
virtual uInt nelements() const
virtual void set (const T& value)
virtual void apply (T (*function)(T))
virtual void apply (T (*function)(const T&))
virtual void apply (const Functional<T,T>& function)
virtual uInt advisedMaxPixels() const
virtual IPosition doNiceCursorShape (uInt maxPixels) const
virtual uInt maximumCacheSize() const
virtual void setMaximumCacheSize (uInt howManyPixels)
virtual void setCacheSizeFromPath (const IPosition& sliceShape, const IPosition& windowStart, const IPosition& windowLength, const IPosition& axisPath)
virtual void setCacheSizeInTiles (uInt howManyTiles)
virtual void clearCache()
virtual void showCacheStatistics (ostream& os) const
virtual T getAt (const IPosition& where) const
virtual void putAt (const T& value, const IPosition& where)
virtual Bool ok() const
virtual LatticeIterInterface<T>* makeIter (const T& navigator, Bool useRef) const
virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section)
virtual void doPutSlice (const Array<T>& sourceBuffer, const IPosition& where, const IPosition& stride)
Private Members
void init (const TiledShape& shape, Double maxMemoryInMB=-1)
void doReopen() const
void tempReopen() const
void deleteTable()

Description

Review Status

Reviewed By:
Peter Barnes
Date Reviewed:
1999/10/30
Programs:
Tests:

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

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)

Member Description

TempLattice()

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

explicit TempLattice (const TiledShape& shape, Int maxMemoryInMB=-1)
TempLattice (const TiledShape& shape, Double maxMemoryInMB)

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.

TempLattice (const TempLattice<T>& other)

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.

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. As with the copy constructor assigning by value does not make sense.

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). It'll be reopened automatically when needed or when reopen is called explicitly.

virtual void reopen()

If needed, reopen a temporarily closed TempLattice.

virtual IPosition shape() const

Return the shape of the Lattice including all degenerate axes. (ie. axes with a length of one)

virtual uInt ndim() const

Return the number of axes in this Lattice. This includes all degenerate axes.

virtual uInt nelements() const

Return the total number of elements in this Lattice.

virtual void set (const T& value)

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

virtual void apply (T (*function)(T))
virtual void apply (T (*function)(const T&))
virtual void apply (const Functional<T,T>& function)

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.

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. In pixels.

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. 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.

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
virtual void putAt (const T& value, const IPosition& where)

Get or put a single element in the lattice. Note that Lattice::operator() can also be used to get a single element.

virtual Bool ok() const

Check class internals - used for debugging. Should always return True

virtual LatticeIterInterface<T>* makeIter (const T& navigator, Bool useRef) const

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

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.

void init (const TiledShape& shape, Double maxMemoryInMB=-1)

void doReopen() const
void tempReopen() const

Do the reopen of the table (if not open already).

void deleteTable()

Make sure that the temporary table gets deleted.