casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef LATTICES_LATTICECACHE_H
27#define LATTICES_LATTICECACHE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/Array.h>
32#include <casacore/casa/Arrays/Vector.h>
33#include <casacore/casa/Containers/Block.h>
34
35// # Forward Declarations
36#include <casacore/casa/iosfwd.h>
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39template <class T>
40class Block;
41template <class T>
42class Lattice;
43
44// <summary> a class for caching image access via tiles</summary>
45//
46// <use visibility=export>
47//
48// <reviewed reviewer="" date="" tests="" demos="">
49// </reviewed>
50//
51// <prerequisite>
52// <li> <linkto class=Lattice>Lattice</linkto>
53// </prerequisite>
54//
55// <etymology>
56// This class divides an image into Tiles that are stored in
57// a Cache.
58// </etymology>
59//
60// <synopsis>
61// An image is divided into tiles of a specified shape. Access to the
62// image pixels is via these tiles. A cache of active tiles is kept
63// in memory up to a specified limit in memory allocation. Tiles
64// are flushed to disk using a Least-Recently-Used Criterion.
65//
66// The tile size specified is the maximum dimension. Near the edge,
67// smaller tiles are returned if necessary.
68//
69// The offset needed to get back to true pixels is also available.
70//
71// The cache hit rate for a sufficient number of random accesses
72// goes as the ratio of cache size to image size.
73//
74// Tiles may be overlapped. If there is any overlap then the
75// caller is responsible for dealing with the overlap. Normally
76// one will only want overlapping windows for additive operations
77// in which case the additive flag to the constructor should be
78// used.
79// </synopsis>
80//
81// <example>
82// <srcblock>
83// </srcblock>
84//
85// </example>
86//
87// <motivation>
88// To aid in gridding
89// </motivation>
90//
91// <todo asof="1997/02/27">
92// </todo>
93
94template <class T>
96 public:
97 // Constructor: cachesize in units of T. tileOverlap is the fractional
98 // overlap between neighbouring tile.
100 Bool additive);
101
103
105
106 virtual ~LatticeCache();
107
108 // Return the tile for a given location
109 // <group>
110 Array<T>& tile(IPosition& cacheLoc, const IPosition& tileLoc, Bool discard = True);
111 Array<T>& tile(const IPosition& tileLoc, Bool discard = True);
112 // </group>
113
114 // const version is needed
115 const Array<T>& tile(const IPosition& tileLoc);
116
117 // Return the IPosition for the start of this tile
118 IPosition& cacheLocation(IPosition& cacheLoc, const IPosition& tileLoc);
119
120 // Show the statistics of cache access
121 virtual void showCacheStatistics(std::ostream& os);
122
123 // Clear the statistics of cache access
124 virtual void clearCacheStatistics();
125
126 // Flush contents
127 virtual void flush();
128
129 protected:
131
137
144
146
150
152 void readTile(Int tile, Bool readonly);
153
155};
156
157} // namespace casacore
158
159#ifndef CASACORE_NO_AUTO_TEMPLATES
160#include <casacore/lattices/Lattices/LatticeCache.tcc>
161#endif // # CASACORE_NO_AUTO_TEMPLATES
162#endif
Block< IPosition > tileLocs
const Array< T > & tile(const IPosition &tileLoc)
const version is needed
void writeTile(Int tile)
Vector< Float > tileOverlap
virtual void clearCacheStatistics()
Clear the statistics of cache access.
virtual void showCacheStatistics(std::ostream &os)
Show the statistics of cache access.
Array< T > & tile(IPosition &cacheLoc, const IPosition &tileLoc, Bool discard=True)
Return the tile for a given location.
IPosition & cacheLocation(IPosition &cacheLoc, const IPosition &tileLoc)
Return the IPosition for the start of this tile.
Lattice< T > * image_p
LatticeCache(Lattice< T > &image, Int cacheSize, IPosition tileShape, Vector< Float > &tileOverlap, Bool additive)
Constructor: cachesize in units of T.
Vector< Int > tileOffsetVec
Block< Array< T > > tileContents
LatticeCache< T > & operator=(const LatticeCache< T > &other)
Block< Int > tileSequence
Vector< Int > tileShapeVec
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.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41