casacore
Public Member Functions | Private Attributes | List of all members
casacore::TempLattice< T > Class Template Reference

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

#include <LatticeCleaner.h>

Public Member Functions

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

Private Attributes

CountedPtr< TempLatticeImpl< T > > itsImpl
 

Detailed Description

template<class T>
class casacore::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 44 of file LatticeCleaner.h.

Constructor & Destructor Documentation

◆ TempLattice() [1/4]

template<class T >
casacore::TempLattice< T >::TempLattice ( )
inline

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

Definition at line 137 of file TempLattice.h.

◆ TempLattice() [2/4]

template<class T >
casacore::TempLattice< T >::TempLattice ( const TiledShape shape,
Int  maxMemoryInMB = -1 
)
inlineexplicit

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 147 of file TempLattice.h.

◆ TempLattice() [3/4]

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

Definition at line 149 of file TempLattice.h.

◆ TempLattice() [4/4]

template<class T >
casacore::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 157 of file TempLattice.h.

◆ ~TempLattice()

template<class T >
virtual casacore::TempLattice< T >::~TempLattice ( )
virtual

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

Member Function Documentation

◆ advisedMaxPixels()

template<class T >
virtual uInt casacore::TempLattice< T >::advisedMaxPixels ( ) const
virtual

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

◆ apply() [1/3]

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

◆ apply() [2/3]

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

◆ apply() [3/3]

template<class T >
virtual void casacore::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.

◆ canReferenceArray()

template<class T >
virtual Bool casacore::TempLattice< T >::canReferenceArray ( ) const
virtual

Can the lattice data be referenced as an array section?

◆ clearCache()

template<class T >
virtual void casacore::TempLattice< T >::clearCache ( )
virtual

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

◆ clone()

template<class T >
virtual Lattice<T>* casacore::TempLattice< T >::clone ( ) const
virtual

Make a copy of the object (reference semantics).

◆ doGetSlice()

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

Do the actual getting of an array of values.

◆ doNiceCursorShape()

template<class T >
virtual IPosition casacore::TempLattice< T >::doNiceCursorShape ( uInt  maxPixels) const
virtual

Get the best cursor shape.

◆ doPutSlice()

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

Do the actual getting of an array of values.

◆ flush()

template<class T >
virtual void casacore::TempLattice< T >::flush ( )
virtual

Flush the data.

◆ getAt()

template<class T >
virtual T casacore::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.

◆ isPaged()

template<class T >
virtual Bool casacore::TempLattice< T >::isPaged ( ) const
virtual

Is the TempLattice paged to disk?

◆ isWritable()

template<class T >
virtual Bool casacore::TempLattice< T >::isWritable ( ) const
virtual

Is the TempLattice writable? It should be.

◆ makeIter()

template<class T >
virtual LatticeIterInterface<T>* casacore::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.

◆ maximumCacheSize()

template<class T >
virtual uInt casacore::TempLattice< T >::maximumCacheSize ( ) const
virtual

Maximum size - not necessarily all used.

In pixels.

◆ ok()

template<class T >
virtual Bool casacore::TempLattice< T >::ok ( ) const
virtual

Check class internals - used for debugging.

Should always return True

◆ operator=()

template<class T >
TempLattice<T>& casacore::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 165 of file TempLattice.h.

◆ putAt()

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

◆ reopen()

template<class T >
virtual void casacore::TempLattice< T >::reopen ( )
virtual

If needed, reopen a temporarily closed TempLattice.

◆ set()

template<class T >
virtual void casacore::TempLattice< T >::set ( const T &  value)
virtual

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

◆ setCacheSizeFromPath()

template<class T >
virtual void casacore::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.

◆ setCacheSizeInTiles()

template<class T >
virtual void casacore::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.

◆ setMaximumCacheSize()

template<class T >
virtual void casacore::TempLattice< T >::setMaximumCacheSize ( uInt  howManyPixels)
virtual

Set the maximum (allowed) cache size as indicated.

◆ shape()

template<class T >
virtual IPosition casacore::TempLattice< T >::shape ( ) const
virtual

Return the shape of the Lattice including all degenerate axes.

(ie. axes with a length of one)

◆ showCacheStatistics()

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

Report on cache success.

◆ tempClose()

template<class T >
virtual void casacore::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.

Member Data Documentation

◆ itsImpl

template<class T >
CountedPtr<TempLatticeImpl<T> > casacore::TempLattice< T >::itsImpl
private

Definition at line 273 of file TempLattice.h.

Referenced by casacore::TempLattice< Complex >::operator=().


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