casa
5.7.0-16
|
A Lattice that is read from or written to disk. More...
#include <PagedArray.h>
Public Member Functions | |
PagedArray () | |
The default constructor creates a PagedArray that is useless for just about everything, except that it can be assigned to with the assignment operator. More... | |
PagedArray (const TiledShape &shape, const String &filename) | |
Construct a new PagedArray with the specified shape. More... | |
PagedArray (const TiledShape &shape) | |
Construct a new PagedArray with the specified shape. More... | |
PagedArray (const TiledShape &shape, Table &file) | |
Construct a new PagedArray, with the specified shape, in the default row and column of the supplied Table. More... | |
PagedArray (const TiledShape &shape, Table &file, const String &columnName, uInt rowNum) | |
Construct a new PagedArray, with the specified shape, in the specified row and column of the supplied Table. More... | |
PagedArray (const String &filename) | |
Reconstruct from a pre-existing PagedArray in the default row and column of the supplied Table with the supplied filename. More... | |
PagedArray (Table &file) | |
Reconstruct from a pre-existing PagedArray in the default row and column of the supplied Table. More... | |
PagedArray (Table &file, const String &columnName, uInt rowNum) | |
Reconstruct from a pre-existing PagedArray in the specified row and column of the supplied Table. More... | |
PagedArray (const PagedArray< T > &other) | |
The copy constructor which uses reference semantics. More... | |
~PagedArray () | |
The destructor flushes the PagedArrays contents to disk. More... | |
PagedArray< T > & | operator= (const PagedArray< 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 | isPersistent () const |
A PagedArray is always persistent. More... | |
virtual Bool | isPaged () const |
A PagedArray is always paged to disk. More... | |
virtual Bool | isWritable () const |
Is the PagedArray writable? More... | |
virtual IPosition | shape () const |
Returns the shape of the PagedArray. More... | |
virtual String | name (Bool stripPath=False) const |
Return the current Table name. More... | |
void | resize (const TiledShape &newShape) |
Functions to resize the PagedArray. More... | |
const String & | tableName () const |
Returns the current table name (ie. More... | |
Table & | table () |
Return the current table object. More... | |
const Table & | table () const |
const String & | columnName () const |
Returns the current Table column name of this PagedArray. More... | |
const ROTiledStManAccessor & | accessor () const |
Returns an accessor to the tiled storage manager. More... | |
uInt | rowNumber () const |
Returns the current row number of this PagedArray. More... | |
IPosition | tileShape () const |
Returns the current tile shape for this PagedArray. More... | |
virtual uInt | advisedMaxPixels () const |
Returns the maximum recommended number of pixels for a cursor. More... | |
virtual void | setMaximumCacheSize (uInt howManyPixels) |
Set the maximum allowed cache size for all Arrays in this column of the Table. More... | |
virtual uInt | maximumCacheSize () const |
Return the maximum allowed cache size (in pixels) for all Arrays in this column of the Table. More... | |
virtual void | setCacheSizeInTiles (uInt howManyTiles) |
Set the actual cache size for this Array to be big enough for the indicated number of tiles. More... | |
virtual void | setCacheSizeFromPath (const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath) |
Set the actual cache size for this Array to "fit" the indicated path. More... | |
virtual void | clearCache () |
Clears and frees up the tile cache. More... | |
virtual void | showCacheStatistics (ostream &os) const |
Generate a report on how the cache is doing. More... | |
virtual T | getAt (const IPosition &where) const |
Return the value of the single element located at the argument IPosition. More... | |
virtual void | putAt (const T &value, const IPosition &where) |
Put the value of a single element. More... | |
virtual Bool | ok () const |
A function which checks for internal consistency. 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 a specified Lattice. More... | |
virtual Bool | doGetSlice (Array< T > &buffer, const Slicer §ion) |
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... | |
virtual IPosition | doNiceCursorShape (uInt maxPixels) const |
Get the best cursor shape. More... | |
virtual Bool | lock (FileLocker::LockType, uInt nattempts) |
Handle the (un)locking. More... | |
virtual void | unlock () |
virtual Bool | hasLock (FileLocker::LockType) const |
virtual void | resync () |
Resynchronize the PagedArray object with the lattice file. More... | |
virtual void | flush () |
Flush the data (but do not unlock). More... | |
virtual void | tempClose () |
Temporarily close the lattice. More... | |
virtual void | reopen () |
Explicitly reopen the temporarily closed lattice. More... | |
Public Member Functions inherited from casacore::Lattice< T > | |
virtual | ~Lattice () |
a virtual destructor is needed so that it will use the actual destructor in the derived class More... | |
virtual DataType | dataType () const |
Get the data type of the lattice. More... | |
T | operator() (const IPosition &where) const |
Return the value of the single element located at the argument IPosition. More... | |
Bool | get (COWPtr< Array< T > > &buffer, Bool removeDegenerateAxes=False) const |
Functions which extract an Array of values from a Lattice. More... | |
Bool | getSlice (COWPtr< Array< T > > &buffer, const Slicer §ion, Bool removeDegenerateAxes=False) const |
Bool | getSlice (COWPtr< Array< T > > &buffer, const IPosition &start, const IPosition &shape, Bool removeDegenerateAxes=False) const |
Bool | getSlice (COWPtr< Array< T > > &buffer, const IPosition &start, const IPosition &shape, const IPosition &stride, Bool removeDegenerateAxes=False) const |
Bool | get (Array< T > &buffer, Bool removeDegenerateAxes=False) |
Bool | getSlice (Array< T > &buffer, const Slicer §ion, Bool removeDegenerateAxes=False) |
Bool | getSlice (Array< T > &buffer, const IPosition &start, const IPosition &shape, Bool removeDegenerateAxes=False) |
Bool | getSlice (Array< T > &buffer, const IPosition &start, const IPosition &shape, const IPosition &stride, Bool removeDegenerateAxes=False) |
Array< T > | get (Bool removeDegenerateAxes=False) const |
Array< T > | getSlice (const Slicer §ion, Bool removeDegenerateAxes=False) const |
Array< T > | getSlice (const IPosition &start, const IPosition &shape, Bool removeDegenerateAxes=False) const |
Array< T > | getSlice (const IPosition &start, const IPosition &shape, const IPosition &stride, Bool removeDegenerateAxes=False) const |
void | putSlice (const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride) |
A function which places an Array of values within this instance of the Lattice at the location specified by the IPosition "where", incrementing by "stride". More... | |
void | putSlice (const Array< T > &sourceBuffer, const IPosition &where) |
void | put (const Array< T > &sourceBuffer) |
virtual void | set (const T &value) |
Set all 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) |
void | operator+= (const Lattice< T > &other) |
Add, subtract, multiple, or divide by another Lattice. More... | |
void | operator-= (const Lattice< T > &other) |
void | operator*= (const Lattice< T > &other) |
void | operator/= (const Lattice< T > &other) |
virtual void | copyData (const Lattice< T > &from) |
Copy the data from the given lattice to this one. More... | |
virtual void | copyDataTo (Lattice< T > &to) const |
Copy the data from this lattice to the given lattice. More... | |
Public Member Functions inherited from casacore::LatticeBase | |
virtual | ~LatticeBase () |
A virtual destructor is needed so that it will use the actual destructor in the derived class. More... | |
virtual String | imageType () const |
Get the image type (returns name of derived class). More... | |
virtual Bool | canReferenceArray () const |
Can the lattice data be referenced as an array section? That is the case for an ArrayLattice or a Temp/SubLattice using it. More... | |
virtual void | save (const String &fileName) const |
Save the image in an AipsIO file with the given name. More... | |
virtual uInt | ndim () const |
Return the number of axes in this Lattice. More... | |
virtual size_t | nelements () const |
Return the total number of elements in this Lattice. More... | |
size_t | size () const |
Bool | conform (const LatticeBase &other) const |
Return a value of "True" if this instance of Lattice and 'other' have the same shape, otherwise returns a value of "False". More... | |
virtual LELCoordinates | lelCoordinates () const |
Return the coordinates of the lattice. More... | |
IPosition | niceCursorShape (uInt maxPixels) const |
Returns a recommended cursor shape for iterating through all the pixels in the Lattice. More... | |
IPosition | niceCursorShape () const |
Static Public Member Functions | |
static String | defaultColumn () |
Returns the default TableColumn name for a PagedArray. More... | |
static uInt | defaultRow () |
Returns the default row number for a PagedArray. More... | |
Private Member Functions | |
void | setTableType () |
Set the data in the TableInfo file. More... | |
void | makeArray (const TiledShape &shape) |
make the ArrayColumn More... | |
void | makeTable (const String &filename, Table::TableOption option) |
Make a Table to hold this PagedArray. More... | |
ArrayColumn< T > & | getRWArray () |
Get the writable ArrayColumn object. More... | |
void | doReopen () const |
Do the reopen of the table (if not open already). More... | |
void | tempReopen () const |
Static Private Member Functions | |
static String | defaultComment () |
The default comment for PagedArray Colums. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from casacore::Lattice< T > | |
Lattice () | |
Define default constructor to satisfy compiler. More... | |
virtual void | handleMath (const Lattice< T > &from, int oper) |
Handle the Math operators (+=, -=, *=, /=). More... | |
virtual void | handleMathTo (Lattice< T > &to, int oper) const |
Lattice (const Lattice< T > &) | |
Copy constructor and assignment can only be used by derived classes. More... | |
Lattice< T > & | operator= (const Lattice< T > &) |
template<> | |
void | handleMathTo (Lattice< Bool > &, int) const |
Protected Member Functions inherited from casacore::LatticeBase | |
LatticeBase () | |
Define default constructor to be used by derived classes. More... | |
LatticeBase (const LatticeBase &) | |
Copy constructor and assignment can only be used by derived classes. More... | |
LatticeBase & | operator= (const LatticeBase &) |
void | throwBoolMath () const |
Throw an exception for arithmetic on a Bool Lattice. More... | |
A Lattice that is read from or written to disk.
Public interface
"Demand paging" is a technique used to implement virtual memory in computer operating systems. In this scheme, code or data are read from disk to memory only as needed by a process, and are read in fixed-sized chunks called "pages". PagedArrays are somewhat the same – though without the automatic features found in virtual memory demand paging. However PagedArrays do allow the user to access chunks of the disk in a flexible way, that can match the requirements of many algorithms.
At the time of writing, typical scientific computers provide sufficient memory for storing and manipulating 2-dimensional astronomical images, which have average size of around 8 MBytes. Astronomy is increasingly using three or higher dimensional arrays, which can be larger by one or two orders of magnitude. PagedArrays provide a convenient way of accessing these large arrays without requiring all the data to be read into real or virtual memory.
When you construct a PagedArray you do not read any data into memory. Instead a disk file (ie. a Table) is created, in a place you specify, to hold the data. This means you need to have enough disk space to hold the array. Constructing a PagedArray is equivalent to opening a file.
Because the data is stored on disk it can be saved after the program, function, or task that created the PagedArray has finished. This saved array can then be read again at a later stage.
So there are two reasons for using a PagedArray:
To access the data in a PagedArray you can either:
These access methods are given in order of preference. Some examples of these access methods are in the documentation for the Lattice class as well as below.
In nearly all cases you access the PagedArray by reading a "slice" of the PagedArray into a Casacore Array. Because the slice is stored in memory it is important that the slice you read is not too big compared to the physical memory on your computer. Otherwise your computer will page excessively and performance will be poor.
To overcome this you may be tempted to access the PagedArray a pixel at a time. This will use little memory but the overhead of accessing a large data set by separately reading each pixel from disk will also lead to poor performance.
In general the best way to access the data in PagedArrays is to use a LatticeIterator with a cursor size that "fits" nicely into memory. Not only do the LaticeIterator classes provide a relatively simple way to read/write all the data but they optimally set up the cache that is associated with each PagedArray.
If the LatticeIterator classes do not access the data the way you want you can use the getSlice and putSlice member functions. These functions do not set up the cache for you and improved performance may be obtained by tweaking the cache using the setCacheSizeFromPath member frunction.
In order to utilise PagedArrays fully and understand many of the member functions and data access methods in this class, you need to be familiar with some of the concepts involved in the implementation of PagedArrays.
Each PagedArray is stored in one cell of a Table as an indirect Array (see the documentation for the Tables module for more information). This means that multiple PagedArrays can be stored in one Table. To specify which PagedArray you are referring to in a given Table you need to specify the cell using its column name and row number during construction. If a cell is not specified the default column name (as given by the defaultColumnName function) and row number (as given by the defaultRowNumber function) are used. This ability to store multiple PagedArrays's is used in the PagedImage class where the image is stored in one cell and a mask is optionally stored in a another column in the same row.
There are currently a number of limitations when storing multiple PagedArrays in the same Table.
Each PagedArray is stored on disk using the tiled cell storage manager (TiledCellStMan). This stores the data in tiles which are regular subsections of the PagedArray. For example a PagedArray of shape [1024,1024,4,128] may have a tile shape of [32,16,4,16]. The data in each tile is stored as a unit on the disk. This means that there is no preferred axis when accessing multi-dimensional data.
The tile shape can be specified when constructing a new PagedArray but not when reading an old one as it is intrinsic to the way the data is stored on disk. It is NOT recommended that you specify the tile shape unless you can control the lifetime of the PagedArray (this includes the time it spends on disk), or can guarantee the access pattern. For example if you know that a PagedArray of shape [512,512,4,32] will always be sliced plane by plane you may prefer to specify a tile shape of [512,64,1,1] rather than the default of [32,16,4,16].
Tiles can be cached by the tile storage manager so that it does not need to read the data from disk every time you are accessing the a pixel in a different tile. In order to cache the correct tiles you should tell the storage manager what section of the PagedArray you will be accessing. This is done using the setCacheSizeFromPath member function. Alternatively you can set the size of the cache using the setCacheSizeInTiles member function.
By default there is no limit on how much memory the tile cache can consume. This can be changed using the setMaximumCacheSize member function. The tiled storage manager always tries to cache enough tiles to ensure that each tile is read from disk only once, so setting the maximum cache size will trade off memory usage for disk I/O. Setting the cache size is illustrated in example 5 below.
The showCacheStatistics member function is provided to allow you to evaluate the performance of the tile cache.
All the examples in this section are available in dPagedArray.cc
Create a PagedArray of Floats of shape [1024,1024,4,256] in a file called "myData_tmp.array" and initialize it to zero. This will create a directory on disk called "myData_tmp.array" that contains files that exceed 1024*1024*4*256*4 (= 4 GBytes) in size.
Read the PagedArray produced in Example 1 and put a Gaussian profile into each spectral channel.
Now multiply the I-polarization data by 10.0 in this PagedArray. The I-polarization data occupies 1 GByte of RAM which is too big to read into the memory of most computers. So an iterator is used to get suitable sized chunks.
Use a direct call to getSlice to access a small central region of the V-polarization in spectral channel 0 only. The region is small enough to not warrant constructing iterators and setting up LatticeNavigators. In this example the call to the getSlice function is unnecessary but is done for illustration purposes anyway.
In this example the data in the PagedArray will be accessed a row at a time while setting the cache size to different values. The comments illustrate the results when running on an Ultra 1/140 with 64MBytes of memory.
Arrays of data are sometimes much too large to hold in random access memory. PagedArrays, especially in combination with LatticeIterator, provide convenient access to such large data sets.
Definition at line 373 of file PagedArray.h.
casacore::PagedArray< T >::PagedArray | ( | ) |
The default constructor creates a PagedArray that is useless for just about everything, except that it can be assigned to with the assignment operator.
casacore::PagedArray< T >::PagedArray | ( | const TiledShape & | shape, |
const String & | filename | ||
) |
Construct a new PagedArray with the specified shape.
A new Table with the specified filename is constructed to hold the array. The Table will remain on disk after the PagedArray goes out of scope or is deleted.
|
explicit |
Construct a new PagedArray with the specified shape.
A scratch Table is created in the current working directory to hold the array. This Table will be deleted automatically when the PagedArray goes out of scope or is deleted.
casacore::PagedArray< T >::PagedArray | ( | const TiledShape & | shape, |
Table & | file | ||
) |
Construct a new PagedArray, with the specified shape, in the default row and column of the supplied Table.
casacore::PagedArray< T >::PagedArray | ( | const TiledShape & | shape, |
Table & | file, | ||
const String & | columnName, | ||
uInt | rowNum | ||
) |
Construct a new PagedArray, with the specified shape, in the specified row and column of the supplied Table.
|
explicit |
Reconstruct from a pre-existing PagedArray in the default row and column of the supplied Table with the supplied filename.
|
explicit |
Reconstruct from a pre-existing PagedArray in the default row and column of the supplied Table.
casacore::PagedArray< T >::PagedArray | ( | Table & | file, |
const String & | columnName, | ||
uInt | rowNum | ||
) |
Reconstruct from a pre-existing PagedArray in the specified row and column of the supplied Table.
casacore::PagedArray< T >::PagedArray | ( | const PagedArray< T > & | other | ) |
The copy constructor which uses reference semantics.
Copying by value doesn't make sense, because it would require the creation of a temporary (but possibly huge) file on disk.
casacore::PagedArray< T >::~PagedArray | ( | ) |
The destructor flushes the PagedArrays contents to disk.
|
inline |
Returns an accessor to the tiled storage manager.
Definition at line 645 of file PagedArray.h.
|
virtual |
Returns the maximum recommended number of pixels for a cursor.
This is the number of pixels in a tile.
Reimplemented from casacore::Lattice< T >.
|
virtual |
Clears and frees up the tile cache.
The maximum allowed cache size is unchanged from when setMaximumCacheSize
was last called.
Reimplemented from casacore::LatticeBase.
|
virtual |
Make a copy of the object (reference semantics).
Implements casacore::Lattice< T >.
|
inline |
Returns the current Table column name of this PagedArray.
Definition at line 633 of file PagedArray.h.
|
inlinestatic |
Returns the default TableColumn name for a PagedArray.
Definition at line 639 of file PagedArray.h.
|
staticprivate |
The default comment for PagedArray Colums.
|
inlinestatic |
Returns the default row number for a PagedArray.
Definition at line 657 of file PagedArray.h.
|
virtual |
Do the actual getting of an array of values.
Implements casacore::Lattice< T >.
|
virtual |
Get the best cursor shape.
Reimplemented from casacore::LatticeBase.
|
virtual |
Do the actual getting of an array of values.
Implements casacore::Lattice< T >.
|
private |
Do the reopen of the table (if not open already).
Definition at line 663 of file PagedArray.h.
|
virtual |
Flush the data (but do not unlock).
Reimplemented from casacore::LatticeBase.
|
virtual |
Return the value of the single element located at the argument IPosition.
Note that Lattice::operator()
can also be used.
Reimplemented from casacore::Lattice< T >.
|
inlineprivate |
Get the writable ArrayColumn object.
It reopens the table for write if needed.
Definition at line 607 of file PagedArray.h.
References casacore::True.
|
virtual |
Reimplemented from casacore::LatticeBase.
|
virtual |
A PagedArray is always paged to disk.
Reimplemented from casacore::LatticeBase.
|
virtual |
A PagedArray is always persistent.
Reimplemented from casacore::LatticeBase.
|
virtual |
Is the PagedArray writable?
Reimplemented from casacore::LatticeBase.
|
virtual |
Handle the (un)locking.
Reimplemented from casacore::LatticeBase.
|
private |
make the ArrayColumn
|
virtual |
This function is used by the LatticeIterator class to generate an iterator of the correct type for a specified Lattice.
Not recommended for general use.
Reimplemented from casacore::Lattice< T >.
|
private |
Make a Table to hold this PagedArray.
|
virtual |
Return the maximum allowed cache size (in pixels) for all Arrays in this column of the Table.
The actual cache size may be smaller. A value of zero means that no maximum is currently defined.
Reimplemented from casacore::LatticeBase.
|
virtual |
Return the current Table name.
By default this includes the full path. The path preceeding the file name can be stripped off on request.
Reimplemented from casacore::LatticeBase.
|
virtual |
A function which checks for internal consistency.
Returns False if something nasty has happened to the PagedArray. In that case it also throws an exception.
Reimplemented from casacore::LatticeBase.
PagedArray<T>& casacore::PagedArray< T >::operator= | ( | const PagedArray< T > & | other | ) |
The assignment operator with reference semantics.
As with the copy constructor assigning by value does not make sense.
|
virtual |
Put the value of a single element.
Reimplemented from casacore::Lattice< T >.
|
virtual |
Explicitly reopen the temporarily closed lattice.
Reimplemented from casacore::LatticeBase.
void casacore::PagedArray< T >::resize | ( | const TiledShape & | newShape | ) |
Functions to resize the PagedArray.
The old contents are lost. Usage of this function is NOT currently recommended (see the More Details section above).
|
virtual |
Resynchronize the PagedArray object with the lattice file.
This function is only useful if no read-locking is used, ie. if the table lock option is UserNoReadLocking or AutoNoReadLocking. In that cases the table system does not acquire a read-lock, thus does not synchronize itself automatically.
Reimplemented from casacore::LatticeBase.
|
inline |
Returns the current row number of this PagedArray.
Definition at line 651 of file PagedArray.h.
|
virtual |
Set the actual cache size for this Array to "fit" the indicated path.
This cache is not shared with PagedArrays in other rows and is always less than the maximum value. The sliceShape is the cursor or slice that you will be requiring (with each call to {get,put}Slice). The windowStart and windowLength delimit the range of pixels that will ultimatly be accessed. The AxisPath is described in the documentation for the LatticeStepper class.
Reimplemented from casacore::LatticeBase.
|
virtual |
Set the actual cache size for this Array to 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 are cached using a first in first out algorithm.
Reimplemented from casacore::LatticeBase.
|
virtual |
Set the maximum allowed cache size for all Arrays in this column of the Table.
The actual value used may be smaller. A value of zero means that there is no maximum.
Reimplemented from casacore::LatticeBase.
|
private |
Set the data in the TableInfo file.
|
virtual |
Returns the shape of the PagedArray.
Implements casacore::LatticeBase.
|
virtual |
Generate a report on how the cache is doing.
This is reset every time clearCache
is called.
Reimplemented from casacore::LatticeBase.
|
inline |
Return the current table object.
Definition at line 620 of file PagedArray.h.
|
inline |
Definition at line 626 of file PagedArray.h.
const String& casacore::PagedArray< T >::tableName | ( | ) | const |
Returns the current table name (ie.
filename) of this PagedArray.
|
virtual |
Temporarily close the lattice.
It will be reopened automatically on the next access.
Reimplemented from casacore::LatticeBase.
|
private |
IPosition casacore::PagedArray< T >::tileShape | ( | ) | const |
Returns the current tile shape for this PagedArray.
|
virtual |
Reimplemented from casacore::LatticeBase.
|
mutableprivate |
Definition at line 602 of file PagedArray.h.
|
mutableprivate |
Definition at line 601 of file PagedArray.h.
|
private |
Definition at line 594 of file PagedArray.h.
|
mutableprivate |
Definition at line 596 of file PagedArray.h.
|
private |
Definition at line 600 of file PagedArray.h.
|
mutableprivate |
Definition at line 597 of file PagedArray.h.
|
private |
Definition at line 595 of file PagedArray.h.
|
mutableprivate |
Definition at line 593 of file PagedArray.h.
|
private |
Definition at line 598 of file PagedArray.h.
|
private |
Definition at line 599 of file PagedArray.h.