casacore
Loading...
Searching...
No Matches
TiledStManAccessor.h
Go to the documentation of this file.
1//# TiledStManAccessor.h: Gives access to some TiledStMan functions
2//# Copyright (C) 1994,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 TABLES_TILEDSTMANACCESSOR_H
27#define TABLES_TILEDSTMANACCESSOR_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/DataMan/DataManAccessor.h>
32#include <casacore/casa/iosfwd.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward Declarations
37class TiledStMan;
38class DataManager;
39class Table;
40class IPosition;
41class String;
42class Record;
43
44// <summary>
45// Give access to some TiledStMan functions
46// </summary>
47
48// <use visibility=local>
49
50// <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
51// </reviewed>
52
53// <prerequisite>
54//# Classes you should understand before using this one.
55// <li> <linkto class=TiledStMan>TiledStMan</linkto>
56// </prerequisite>
57
58// <synopsis>
59// The Table system has one or more storage managers underneath.
60// These storage managers are invisible and there is no way to
61// get access to them.
62// However, the <linkto class=TiledStMan>TiledStMan</linkto>-type
63// storage managers are quite specific.
64// This class ROTiledStManAccessor gives the user the means to
65// access a TiledStMan-type object and to control it in some way.
66// <p>
67// The actions that can be performed deal with the caches used in
68// a tiled storage manager. Per hypercube a cache is used to keep as many
69// tiles in memory as needed for efficient access to the data.
70// The cache size needed is calculated automatically. However,
71// it may be possible that a cache uses too much memory. Therefore
72// a maximum cache size can be specified, which can be done in 2 ways:
73// <ol>
74// <li> To the constructor of a tiled storage manager. This is
75// persistent and acts as the default maximum cache size.
76// <li> Using the function setMaximumCacheSize in this accessor class.
77// This is not persistent and acts as a temporary overwrite
78// of the default maximum cache size.
79// </ol>
80// It is recommended to set the maximum cache size only when the
81// tiled storage manager may use too much memory. Setting a
82// maximum could have the effect that the optimal number of tiles
83// does not fit in memory leading to excessive read/write activity.
84// <br>For example:<br>
85// A hypercube has shape [12,20,30,42] and tile shape [4,5,6,7].
86// The hypercube contains doubles, so the tilesize is 6720 bytes.
87// The number of tiles per dimension is [3,4,5,6] resulting in 360 tiles.
88// Iterating through that hypercube requires that some tiles are kept in
89// memory to avoid too many read operations. When iterating like
90// <srcblock>
91// for (uInt i3=0; i3<42; i3++)
92// for (uInt i2=0; i2<30; i2++)
93// for (uInt i1=0; i1<20; i1++)
94// for (uInt i0=0; i0<12; i0++)
95// do something with data[i0,i1,i2,i3]
96// </srcblock>
97// it is clear that it is best to have a cache which can contain at least
98// 3*4*5 tiles. In that way each tile is read only once resulting in
99// 360 reads.
100// <br>When the cache can hold 3*4 tiles, the first tiles of the 3rd
101// dimension have been flushed out when the second step in the 4th dimension
102// gets executed. So the tiles have to be reread for each step in the 4th
103// dimension, resulting in 3*4*5*42 = 2520 reads.
104// <br>When the cache can hold only one tile, the situation is dramatic.
105// A tile has to be read for every 4 pixels, resulting in 75600 reads.
106// <p>
107// Apart from setting the maximum cache size, one can also clear the
108// caches. This can be useful to free memory when an iteration through the
109// data in the tiled storage manager has been done completely. Clearing
110// the caches also clears their statistics (see below).
111// <p>
112// Showing the statistics of the caches used by a tiled storage
113// manager is possible. Per cache it shows the number of tiles accessed and
114// the number of tiles actually read, written, or initialized. The hit ratio
115// gives a good idea of the cache behaviour.
116// <p>
117// Note that the maximum cache size is not an absolute maximum.
118// When the optimal number of tiles do not fit, it is tried if they fit
119// when using an overdrawn of maximum 10%. If so, it uses that overdrawn.
120// If not, it uses the maximum cache size.
121// <p>
122// A few functions exist to get information about a hypercube.
123// The 'get' functions get the information for the given hypercube,
124// while similar functions without the 'get' prefix do the same for the
125// given row.
126// </synopsis>
127
128// <motivation>
129// In principle a pointer to TiledStMan could be used.
130// However, that would give access to all public functions.
131// Furthermore it could not distinguish between read/write and readonly
132// tables.
133// </motivation>
134
135// <example>
136// This example shows how to set the maximum cache size for
137// the tiled storage manager with the name "TSMExample". The cache
138// size is not persistent, i.e. when the same table is reopened
139// at a later time, this cache size is not remembered.
140// <srcblock>
141// // Open a table.
142// Table table("someName.data");
143// // Set the maximum cache size of its tiled hypercube storage
144// // manager TSMExample to 0.5 MiB.
145// ROTiledStManAccessor accessor(table, "TSMExample");
146// accessor.setMaximumCacheSize (512*1024);
147// </srcblock>
148// </example>
149
150//# <todo asof="$DATE:$">
151//# </todo>
152
153
155{
156public:
157 // Default constructor should be used with care.
158 // The resulting object cannot be used for any other operation
159 // until a 'true' ROTiledStManAccessor object is assigned to it.
161
162 // Construct the object for a data manager in the table given the name
163 // of the data manager or the column.
164 // An exception is thrown if the data manager type is not any tiled
165 // storage manager.
166 ROTiledStManAccessor (const Table& table, const String& name,
167 Bool byColumn=False);
168
170
171 // Copy constructor (reference semantics).
173
174 // Assignment (reference semantics).
176
177 // Set the maximum cache size (in MibiByte) to be used by a hypercube
178 // in the storage manager. Note that each hypercube has its own cache.
179 // 0 means unlimited.
180 // The initial maximum cache size is unlimited.
181 // The maximum cache size given in this way is not persistent.
182 // Only the maximum cache size given to the constructors of the tiled
183 // storage managers, is persistent.
185
186 // Get the maximum cache size (in MiB).
188
189 // Get the current cache size (in buckets) for the hypercube in
190 // the given row.
191 uInt cacheSize (rownr_t rownr) const;
192
193 // Get the hypercube shape of the data in the given row.
194 const IPosition& hypercubeShape (rownr_t rownr) const;
195
196 // Get the tile shape of the data in the given row.
197 const IPosition& tileShape (rownr_t rownr) const;
198
199 // Get the bucket size (in bytes) of the hypercube in the given row.
200 uInt bucketSize (rownr_t rownr) const;
201
202 // Get coordinate and id values of the hypercube in the given row.
203 const Record& valueRecord (rownr_t rownr) const;
204
205 // Return the number of hypercubes.
207
208 // Get the current cache size (in buckets) for the given hypercube.
209 uInt getCacheSize (uInt hypercube) const;
210
211 // Get the shape of the given hypercube.
212 const IPosition& getHypercubeShape (uInt hypercube) const;
213
214 // Get the tile shape of the given hypercube.
215 const IPosition& getTileShape (uInt hypercube) const;
216
217 // Get the bucket size (in bytes) of the given hypercube.
218 uInt getBucketSize (uInt hypercube) const;
219
220 // Get coordinate and id values of the given hypercube.
221 const Record& getValueRecord (uInt hypercube) const;
222
223 // Calculate the cache size (in buckets) for accessing the hypercube
224 // containing the given row. It takes the maximum cache size into
225 // account (allowing an overdraft of 10%).
226 // It uses the given axisPath (i.e. traversal order) to determine
227 // the optimum size. A window can be specified to indicate that only
228 // the given subset of the hypercube will be accessed. The window
229 // defaults to the entire hypercube.
230 // <br>
231 // The length of the slice and window arguments and <src>axisPath</src>
232 // must be less or equal to the dimensionality of the hypercube.
233 // The non-specified <src>windowStart</src> parts default to 0.
234 // The non-specified <src>windowLength</src> parts default to
235 // the hypercube shape.
236 // The non-specified <src>sliceShape</src> parts default to 1.
237 // <br>
238 // Axispath = [2,0,1] indicates that the z-axis changes most rapidly,
239 // thereafter x and y. An axis can occur only once in the axisPath.
240 // The non-specified <src>axisPath</src> parts get the natural order.
241 // E.g. in the previous example axisPath=[2] defines the same path.
242 // <group>
243 uInt calcCacheSize (rownr_t rownr, const IPosition& sliceShape,
244 const IPosition& axisPath) const;
245 uInt calcCacheSize (rownr_t rownr, const IPosition& sliceShape,
246 const IPosition& windowStart,
247 const IPosition& windowLength,
248 const IPosition& axisPath) const;
249 // </group>
250
251 // Set the cache size using the corresponding <src>calcCacheSize</src>
252 // function mentioned above.
253 // <br>When forceSmaller is False, the cache is not resized when the
254 // new size is smaller.
255 // <group>
256 void setCacheSize (rownr_t rownr, const IPosition& sliceShape,
257 const IPosition& axisPath,
258 Bool forceSmaller = True);
259 void setCacheSize (rownr_t rownr, const IPosition& sliceShape,
260 const IPosition& windowStart,
261 const IPosition& windowLength,
262 const IPosition& axisPath,
263 Bool forceSmaller = True);
264 // </group>
265
266 // Set the cache size for accessing the hypercube containing the given row.
267 // When the give cache size exceeds the maximum cache size with more
268 // than 10%, the maximum cache size is used instead.
269 // <br>When forceSmaller is False, the cache is not resized when the
270 // new size is smaller.
271 void setCacheSize (rownr_t rownr, uInt nbuckets, Bool forceSmaller = True);
272
273 // This version allows setting the tile cache for a particular hypercube. This
274 // is useful when iterating over the hypercubes in an StMan.
275 void setHypercubeCacheSize (uInt hypercube, uInt nbuckets, Bool forceSmaller = True);
276
277 // Clear the caches used by the hypercubes in this storage manager.
278 // It will flush the caches as needed and remove all buckets from them
279 // resulting in a possibly large drop in memory used.
281
282
283protected:
284 // Get the data manager.
286
287
288private:
289 //# Declare the data members.
291};
292
293
294
295
296} //# NAMESPACE CASACORE - END
297
298#endif
Abstract base class for a data manager.
ROTiledStManAccessor(const Table &table, const String &name, Bool byColumn=False)
Construct the object for a data manager in the table given the name of the data manager or the column...
const IPosition & getHypercubeShape(uInt hypercube) const
Get the shape of the given hypercube.
void setCacheSize(rownr_t rownr, const IPosition &sliceShape, const IPosition &axisPath, Bool forceSmaller=True)
Set the cache size using the corresponding calcCacheSize function mentioned above.
void clearCaches()
Clear the caches used by the hypercubes in this storage manager.
void setCacheSize(rownr_t rownr, const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath, Bool forceSmaller=True)
void setHypercubeCacheSize(uInt hypercube, uInt nbuckets, Bool forceSmaller=True)
This version allows setting the tile cache for a particular hypercube.
const IPosition & getTileShape(uInt hypercube) const
Get the tile shape of the given hypercube.
const IPosition & hypercubeShape(rownr_t rownr) const
Get the hypercube shape of the data in the given row.
const Record & valueRecord(rownr_t rownr) const
Get coordinate and id values of the hypercube in the given row.
const IPosition & tileShape(rownr_t rownr) const
Get the tile shape of the data in the given row.
DataManager * getDataManager() const
Get the data manager.
const Record & getValueRecord(uInt hypercube) const
Get coordinate and id values of the given hypercube.
void setMaximumCacheSize(uInt nMiB)
Set the maximum cache size (in MibiByte) to be used by a hypercube in the storage manager.
uInt getBucketSize(uInt hypercube) const
Get the bucket size (in bytes) of the given hypercube.
ROTiledStManAccessor(const ROTiledStManAccessor &that)
Copy constructor (reference semantics).
uInt maximumCacheSize() const
Get the maximum cache size (in MiB).
uInt bucketSize(rownr_t rownr) const
Get the bucket size (in bytes) of the hypercube in the given row.
uInt getCacheSize(uInt hypercube) const
Get the current cache size (in buckets) for the given hypercube.
uInt calcCacheSize(rownr_t rownr, const IPosition &sliceShape, const IPosition &axisPath) const
Calculate the cache size (in buckets) for accessing the hypercube containing the given row.
void setCacheSize(rownr_t rownr, uInt nbuckets, Bool forceSmaller=True)
Set the cache size for accessing the hypercube containing the given row.
uInt cacheSize(rownr_t rownr) const
Get the current cache size (in buckets) for the hypercube in the given row.
uInt nhypercubes() const
Return the number of hypercubes.
ROTiledStManAccessor & operator=(const ROTiledStManAccessor &that)
Assignment (reference semantics).
ROTiledStManAccessor()
Default constructor should be used with care.
uInt calcCacheSize(rownr_t rownr, const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath) const
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44