casacore
Loading...
Searching...
No Matches
TSMCubeBuff.h
Go to the documentation of this file.
1//# TSMCubeBuff.h: Tiled hypercube in a table
2//# Copyright (C) 2009
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_TSMCUBEBUFF_H
27#define TABLES_TSMCUBEBUFF_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/DataMan/TSMCube.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward declarations
37class BucketBuffered;
38
39// <summary>
40// Tiled hypercube in a table
41// </summary>
42
43// <use visibility=local>
44
45// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
46// </reviewed>
47
48// <prerequisite>
49//# Classes you should understand before using this one.
50// <li> <linkto class=TiledStMan>TiledStMan</linkto>
51// <li> <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
52// for a discussion of the maximum cache size
53// <li> <linkto class=TSMFile>TSMFile</linkto>
54// <li> <linkto class=BucketBuffered>BucketBuffered</linkto>
55// </prerequisite>
56
57// <etymology>
58// TSMCubeBuff represents a hypercube in the Tiled Storage Manager.
59// </etymology>
60
61// <synopsis>
62// TSMCubeBuff defines a tiled hypercube. The data is stored in a TSMFile
63// object and accessed using a BucketBuffered object. The hypercube can
64// be extensible in its last dimension to support tables with a size
65// which is not known in advance.
66// <br>
67// Normally hypercubes share the same TSMFile object, but extensible
68// hypercubes have their own TSMFile object (to be extensible).
69// If the hypercolumn has multiple data columns, their cells share the same
70// tiles. Per tile data column A appears first, thereafter B, etc..
71// <br>
72// The data in the cache is held in external format and is converted
73// when accessed. The alternative would be to hold it in the cache in
74// local format and convert it when read/written from the file. It was
75// felt that the latter approach would generate more needless conversions.
76// <p>
77// The possible id and coordinate values are stored in a Record
78// object. They are written in the main hypercube AipsIO file.
79// <p>
80// TSMCubeBuff uses the maximum cache size set for a Tiled Storage manager.
81// The description of class
82// <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
83// contains a discussion about the effect of setting the maximum cache size.
84// </synopsis>
85
86// <motivation>
87// TSMCubeBuff encapsulates all operations on a hypercube.
88// </motivation>
89
90//# <todo asof="$DATE:$">
91//# A List of bugs, limitations, extensions or planned refinements.
92//# </todo>
93
94
95class TSMCubeBuff: public TSMCube
96{
97public:
98 // Construct the hypercube using the given file with the given shape.
99 // The record contains the id and possible coordinate values.
100 // <br>If the cubeshape is empty, the hypercube is still undefined and
101 // can be added later with setShape. That is only used by TiledCellStMan.
102 // <br> The fileOffset argument is meant for class TiledFileAccess.
104 const IPosition& cubeShape,
105 const IPosition& tileShape,
106 const Record& values, Int64 fileOffset);
107
108 // Reconstruct the hypercube by reading its data from the AipsIO stream.
109 // It will link itself to the correct TSMFile. The TSMFile objects
110 // must have been reconstructed in advance.
112
113 ~TSMCubeBuff() override = default;
114
115 // Forbid copy constructor.
116 TSMCubeBuff (const TSMCubeBuff&) = delete;
117
118 // Forbid assignment.
120
121 // Flush the data in the cache.
122 virtual void flushCache() override;
123
124 // Show the cache statistics.
125 void showCacheStatistics (ostream& os) const override;
126
127 // Set the hypercube shape.
128 // This is only possible if the shape was not defined yet.
130 const IPosition& tileShape) override;
131
132 // Extend the last dimension of the cube with the given number.
133 // The record can contain the coordinates of the elements added.
134 void extend (uInt64 nr, const Record& coordValues,
135 const TSMColumn* lastCoordColumn) override;
136
137 // Read or write a section in the cube.
138 // It is assumed that the section buffer is long enough.
139 void accessSection (const IPosition& start, const IPosition& end,
140 char* section, uInt colnr,
141 uInt localPixelSize, uInt externalPixelSize,
142 Bool writeFlag) override;
143
144 // Read or write a section in a strided way.
145 // It is assumed that the section buffer is long enough.
146 void accessStrided (const IPosition& start, const IPosition& end,
147 const IPosition& stride,
148 char* section, uInt colnr,
149 uInt localPixelSize, uInt externalPixelSize,
150 Bool writeFlag) override;
151
152 // Set the cache size for the given slice and access path.
153 void setCacheSize (const IPosition& sliceShape,
154 const IPosition& windowStart,
155 const IPosition& windowLength,
156 const IPosition& axisPath,
157 Bool forceSmaller, Bool userSet) override;
158
159 // Resize the cache object.
160 // If forceSmaller is False, the cache will only be resized when it grows.
161 // If the given size exceeds the maximum size with more
162 // than 10%, the maximum size will be used.
163 // The cacheSize has to be given in buckets.
164 // <br>The flag <src>userSet</src> inidicates if the cache size is set by
165 // the user (by an Accessor object) or automatically (by TSMDataColumn).
166 void setCacheSize (uInt cacheSize, Bool forceSmaller, Bool userSet) override;
167
168private:
169 // Get the cache object.
170 // This will construct the cache object if not present yet.
172
173 // Construct the cache object (if not constructed yet).
174 void makeCache() override;
175
176 // Resync the cache object.
177 void resyncCache() override;
178
179 // Delete the cache object.
180 void deleteCache() override;
181
182 //# Declare member variables.
183 // The bucket cache.
184 std::unique_ptr<BucketBuffered> cache_p;
185};
186
187
188
190{
191 if (!cache_p) {
192 makeCache();
193 }
194 return cache_p.get();
195}
196
197
198
199} //# NAMESPACE CASACORE - END
200
201#endif
void setCacheSize(const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath, Bool forceSmaller, Bool userSet) override
Set the cache size for the given slice and access path.
void setCacheSize(uInt cacheSize, Bool forceSmaller, Bool userSet) override
Resize the cache object.
~TSMCubeBuff() override=default
void extend(uInt64 nr, const Record &coordValues, const TSMColumn *lastCoordColumn) override
Extend the last dimension of the cube with the given number.
TSMCubeBuff(const TSMCubeBuff &)=delete
Forbid copy constructor.
std::unique_ptr< BucketBuffered > cache_p
The bucket cache.
TSMCubeBuff & operator=(const TSMCubeBuff &)=delete
Forbid assignment.
virtual void flushCache() override
Flush the data in the cache.
void accessSection(const IPosition &start, const IPosition &end, char *section, uInt colnr, uInt localPixelSize, uInt externalPixelSize, Bool writeFlag) override
Read or write a section in the cube.
BucketBuffered * getCache()
Get the cache object.
void accessStrided(const IPosition &start, const IPosition &end, const IPosition &stride, char *section, uInt colnr, uInt localPixelSize, uInt externalPixelSize, Bool writeFlag) override
Read or write a section in a strided way.
void showCacheStatistics(ostream &os) const override
Show the cache statistics.
void resyncCache() override
Resync the cache object.
TSMCubeBuff(TiledStMan *stman, AipsIO &ios)
Reconstruct the hypercube by reading its data from the AipsIO stream.
TSMCubeBuff(TiledStMan *stman, TSMFile *file, const IPosition &cubeShape, const IPosition &tileShape, const Record &values, Int64 fileOffset)
Construct the hypercube using the given file with the given shape.
void setShape(const IPosition &cubeShape, const IPosition &tileShape) override
Set the hypercube shape.
void makeCache() override
Construct the cache object (if not constructed yet).
void deleteCache() override
Delete the cache object.
uInt cacheSize() const
Get the current cache size (in buckets).
const IPosition & tileShape() const
Get the shape of the tiles.
Definition TSMCube.h:440
const IPosition & cubeShape() const
Get the shape of the hypercube.
Definition TSMCube.h:436
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
unsigned long long uInt64
Definition aipsxtype.h:37