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