casacore
LatticeCache.h
Go to the documentation of this file.
1//# LatticeCache: Cache for accessing a Lattice in Tiles
2//# Copyright (C) 1995,1996,1997,1999,2000,2001
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: aips2-request@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25//#
26//# $Id$
27
28#ifndef LATTICES_LATTICECACHE_H
29#define LATTICES_LATTICECACHE_H
30
31
32//# Includes
33#include <casacore/casa/aips.h>
34#include <casacore/casa/Arrays/Array.h>
35#include <casacore/casa/Arrays/Vector.h>
36#include <casacore/casa/Containers/Block.h>
37
38//# Forward Declarations
39#include <casacore/casa/iosfwd.h>
40namespace casacore { //# NAMESPACE CASACORE - BEGIN
41
42template <class T> class Block;
43template <class T> class Lattice;
44
45// <summary> a class for caching image access via tiles</summary>
46//
47// <use visibility=export>
48//
49// <reviewed reviewer="" date="" tests="" demos="">
50// </reviewed>
51//
52// <prerequisite>
53// <li> <linkto class=Lattice>Lattice</linkto>
54// </prerequisite>
55//
56// <etymology>
57// This class divides an image into Tiles that are stored in
58// a Cache.
59// </etymology>
60//
61// <synopsis>
62// An image is divided into tiles of a specified shape. Access to the
63// image pixels is via these tiles. A cache of active tiles is kept
64// in memory up to a specified limit in memory allocation. Tiles
65// are flushed to disk using a Least-Recently-Used Criterion.
66//
67// The tile size specified is the maximum dimension. Near the edge,
68// smaller tiles are returned if necessary.
69//
70// The offset needed to get back to true pixels is also available.
71//
72// The cache hit rate for a sufficient number of random accesses
73// goes as the ratio of cache size to image size.
74//
75// Tiles may be overlapped. If there is any overlap then the
76// caller is responsible for dealing with the overlap. Normally
77// one will only want overlapping windows for additive operations
78// in which case the additive flag to the constructor should be
79// used.
80// </synopsis>
81//
82// <example>
83// <srcblock>
84// </srcblock>
85//
86// </example>
87//
88// <motivation>
89// To aid in gridding
90// </motivation>
91//
92// <todo asof="1997/02/27">
93// </todo>
94
95template <class T> class LatticeCache
96{
97public:
98
99 // Constructor: cachesize in units of T. tileOverlap is the fractional
100 // overlap between neighbouring tile.
103
105
107
108 virtual ~LatticeCache();
109
110 // Return the tile for a given location
111 // <group>
112 Array<T>& tile(IPosition& cacheLoc, const IPosition& tileLoc, Bool discard=True);
113 Array<T>& tile(const IPosition& tileLoc, Bool discard=True);
114 // </group>
115
116 // const version is needed
117 const Array<T>& tile(const IPosition& tileLoc);
118
119 // Return the IPosition for the start of this tile
120 IPosition& cacheLocation(IPosition& cacheLoc, const IPosition& tileLoc);
121
122 // Show the statistics of cache access
123 virtual void showCacheStatistics(ostream& os);
124
125 // Clear the statistics of cache access
126 virtual void clearCacheStatistics();
127
128 // Flush contents
129 virtual void flush();
130
131protected:
132
134
140
147
149
153
155 void readTile(Int tile, Bool readonly);
156
158};
159
160
161} //# NAMESPACE CASACORE - END
162
163#ifndef CASACORE_NO_AUTO_TEMPLATES
164#include <casacore/lattices/Lattices/LatticeCache.tcc>
165#endif //# CASACORE_NO_AUTO_TEMPLATES
166#endif
simple 1-D array
Definition: Block.h:200
Block< IPosition > tileLocs
Definition: LatticeCache.h:150
const Array< T > & tile(const IPosition &tileLoc)
const version is needed
void writeTile(Int tile)
Vector< Float > tileOverlap
Definition: LatticeCache.h:138
virtual void clearCacheStatistics()
Clear the statistics of cache access.
Array< T > & tile(IPosition &cacheLoc, const IPosition &tileLoc, Bool discard=True)
Return the tile for a given location.
virtual void showCacheStatistics(ostream &os)
Show the statistics of cache access.
IPosition & cacheLocation(IPosition &cacheLoc, const IPosition &tileLoc)
Return the IPosition for the start of this tile.
Lattice< T > * image_p
Definition: LatticeCache.h:157
LatticeCache(Lattice< T > &image, Int cacheSize, IPosition tileShape, Vector< Float > &tileOverlap, Bool additive)
Constructor: cachesize in units of T.
Vector< Int > tileOffsetVec
Definition: LatticeCache.h:137
Block< Array< T > > tileContents
Definition: LatticeCache.h:152
LatticeCache< T > & operator=(const LatticeCache< T > &other)
Block< Int > tileSequence
Definition: LatticeCache.h:151
Vector< Int > tileShapeVec
Definition: LatticeCache.h:137
Array< T > & tile(const IPosition &tileLoc, Bool discard=True)
Int getFreeTile(Bool readonly)
void readTile(Int tile, Bool readonly)
LatticeCache(const LatticeCache< T > &other)
virtual void flush()
Flush contents.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43