casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
36 
37 //# Forward Declarations
38 #include <casacore/casa/iosfwd.h>
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 template <class T> class Block;
42 template <class T> class 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 
94 template <class T> class LatticeCache
95 {
96 public:
97 
98  // Constructor: cachesize in units of T. tileOverlap is the fractional
99  // overlap between neighbouring tile.
102 
103  LatticeCache(const LatticeCache<T> & other);
104 
105  LatticeCache<T> &operator=(const LatticeCache<T> & other);
106 
107  virtual ~LatticeCache();
108 
109  // Return the tile for a given location
110  // <group>
111  Array<T>& tile(IPosition& cacheLoc, const IPosition& tileLoc, Bool discard=True);
112  Array<T>& tile(const IPosition& tileLoc, Bool discard=True);
113  // </group>
114 
115  // const version is needed
116  const Array<T>& tile(const IPosition& tileLoc);
117 
118  // Return the IPosition for the start of this tile
119  IPosition& cacheLocation(IPosition& cacheLoc, const IPosition& tileLoc);
120 
121  // Show the statistics of cache access
122  virtual void showCacheStatistics(ostream& os);
123 
124  // Clear the statistics of cache access
125  virtual void clearCacheStatistics();
126 
127  // Flush contents
128  virtual void flush();
129 
130 protected:
131 
133 
139 
146 
147  Int getFreeTile(Bool readonly);
148 
152 
153  void writeTile(Int tile);
154  void readTile(Int tile, Bool readonly);
155 
157 };
158 
159 
160 } //# NAMESPACE CASACORE - END
161 
162 #ifndef CASACORE_NO_AUTO_TEMPLATES
163 #include <casacore/lattices/Lattices/LatticeCache.tcc>
164 #endif //# CASACORE_NO_AUTO_TEMPLATES
165 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
virtual void showCacheStatistics(ostream &os)
Show the statistics of cache access.
Vector< Float > tileOverlap
Definition: LatticeCache.h:137
int Int
Definition: aipstype.h:50
Vector< Int > tileOffsetVec
Definition: LatticeCache.h:136
Vector< Int > tileShapeVec
Definition: LatticeCache.h:136
a class for caching image access via tiles
Definition: LatticeCache.h:94
virtual void flush()
Flush contents.
Block< IPosition > tileLocs
Definition: LatticeCache.h:149
LatticeCache< T > & operator=(const LatticeCache< T > &other)
Lattice< T > * image_p
Definition: LatticeCache.h:156
void readTile(Int tile, Bool readonly)
A templated, abstract base class for array-like objects.
void writeTile(Int tile)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Array< T > & tile(IPosition &cacheLoc, const IPosition &tileLoc, Bool discard=True)
Return the tile for a given location.
virtual void clearCacheStatistics()
Clear the statistics of cache access.
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
Block< Int > tileSequence
Definition: LatticeCache.h:150
Block< Array< T > > tileContents
Definition: LatticeCache.h:151
simple 1-D array
IPosition & cacheLocation(IPosition &cacheLoc, const IPosition &tileLoc)
Return the IPosition for the start of this tile.
const Bool True
Definition: aipstype.h:43
Int getFreeTile(Bool readonly)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42