casacore
Loading...
Searching...
No Matches
TiledFileAccess.h
Go to the documentation of this file.
1//# TiledFileAccess.h: Tiled access to an array in a file
2//# Copyright (C) 2001,2002
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_TILEDFILEACCESS_H
27#define TABLES_TILEDFILEACCESS_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/DataMan/TSMCube.h>
33#include <casacore/tables/DataMan/TSMOption.h>
34#include <casacore/casa/Utilities/DataType.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward Declarations
39class TiledFileHelper;
40class Slicer;
41
42
43// <summary>
44// Tiled access to an array in a file.
45// </summary>
46
47// <use visibility=export>
48
49// <reviewed reviewer="" date="" tests="tTiledFileAccess.cc">
50// </reviewed>
51
52// <prerequisite>
53//# Classes you should understand before using this one.
54// <li> Description of Tiled Storage Manager in module file
55// <linkto module=Tables:TiledStMan>Tables.h</linkto>
56// <li> <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
57// for a discussion of the maximum cache size
58// </prerequisite>
59
60// <synopsis>
61// TiledFileAccess is a class that makes it possible to access
62// an arbitrary array in a file using the tiled storage manager classes.
63// It can handle arrays of any type supported by the tiled storage
64// managers. The array can be in big or little endian canonical format.
65// <p>
66// See <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
67// for a more detailed discussion.
68// </synopsis>
69
70// <motivation>
71// This class makes it possible to access an image in a FITS file.
72// </motivation>
73
74// <example>
75// <srcblock>
76// // Define the object which also opens the file.
77// // The (float) array starts at offset 2880.
78// TiledFileAccess tfa ("fits.file", 2880, IPosition(2,512,512),
79// IPosition(2,512,1), TpFloat);
80// // Get all the data.
81// Array<Float> data = tfa.getFloat (Slicer(IPosition(2,0,0), tfa.shape()));
82// </srcblock>
83// </example>
84
85//# <todo asof="$DATE:$">
86//# A List of bugs, limitations, extensions or planned refinements.
87//# </todo>
88
89
91{
92public:
93 // Create a TiledFileAccess object.
94 // The data is assumed to be in local canonical format
95 // (thus big endian on e.g. SUN and little endian on e.g. PC).
96 // The TSMOption determines how the file is accessed.
97 TiledFileAccess (const String& fileName, Int64 fileOffset,
98 const IPosition& shape, const IPosition& tileShape,
99 DataType dataType,
100 const TSMOption& = TSMOption(),
101 Bool writable=False);
102
103 // Create a TiledFileAccess object.
104 // The endian format of the data is explicitly given.
105 TiledFileAccess (const String& fileName, Int64 fileOffset,
106 const IPosition& shape, const IPosition& tileShape,
107 DataType dataType,
108 const TSMOption&,
109 Bool writable, Bool bigEndian);
110
112
113 // Forbid copy constructor.
115
116 // Forbid assignment.
118
119 // Is the file writable?
121 { return itsWritable; }
122
123 DataType dataType() const
124 { return itsDataType; }
125
126 // Get part of the array.
127 // The Array object is resized if needed.
128 // <group>
129 Array<Bool> getBool (const Slicer& section);
130 Array<uChar> getUChar (const Slicer& section);
131 Array<Short> getShort (const Slicer& section);
132 Array<Int> getInt (const Slicer& section);
133 Array<Float> getFloat (const Slicer& section);
137 void get (Array<Bool>&, const Slicer& section);
138 void get (Array<uChar>&, const Slicer& section);
139 void get (Array<Short>&, const Slicer& section);
140 void get (Array<Int>&, const Slicer& section);
141 void get (Array<Float>&, const Slicer& section);
142 void get (Array<Double>&, const Slicer& section);
143 void get (Array<Complex>&, const Slicer& section);
144 void get (Array<DComplex>&, const Slicer& section);
145 // </group>
146
147 // Get the array and scale/offset the data using the given values.
148 // It is meant for FITS, so for now they can only be used for TpUChar, TpShort
149 // or TpInt TiledFileAccess objects.
150 // A deleteValue is set to a NaN without being scaled.
151 // <group>
152 Array<Float> getFloat (const Slicer& section, Float scale, Float offset,
153 uChar deleteValue, Bool examineForDeleteValues=True);
154 Array<Float> getFloat (const Slicer& section, Float scale, Float offset,
155 Short deleteValue, Bool examineForDeleteValues=True);
156 Array<Float> getFloat (const Slicer& section, Float scale, Float offset,
157 Int deleteValue, Bool examineForDeleteValues=True);
158 void get (Array<Float>&, const Slicer& section,
159 Float scale, Float offset, uChar deleteValue,
160 Bool examineForDeleteValues=True);
161 void get (Array<Float>&, const Slicer& section,
162 Float scale, Float offset, Short deleteValue,
163 Bool examineForDeleteValues=True);
164 void get (Array<Float>&, const Slicer& section,
165 Float scale, Float offset, Int deleteValue,
166 Bool examineForDeleteValues=True);
167 // </group>
168
169 // Put part of the array.
170 // <group>
171 void put (const Array<Bool>&, const Slicer& section);
172 void put (const Array<uChar>&, const Slicer& section);
173 void put (const Array<Short>&, const Slicer& section);
174 void put (const Array<Int>&, const Slicer& section);
175 void put (const Array<Float>&, const Slicer& section);
176 void put (const Array<Double>&, const Slicer& section);
177 void put (const Array<Complex>&, const Slicer& section);
178 void put (const Array<DComplex>&, const Slicer& section);
179 // </group>
180
181 // Flush the cache.
182 void flush()
183 { itsCube->flushCache(); }
184
185 // Empty the cache.
186 // It will flush the cache as needed and remove all buckets from it
187 // resulting in a possibly large drop in memory used.
188 // It'll also clear the <src>userSetCache_p</src> flag.
190 { itsCube->emptyCache(); }
191
192 // Show the cache statistics.
193 void showCacheStatistics (ostream& os) const
195
196 // Get the shape of the array.
197 const IPosition& shape() const
198 { return itsCube->cubeShape(); }
199
200 // Get the shape of the tiles.
201 const IPosition& tileShape() const
202 { return itsCube->tileShape(); }
203
204 // Set the maximum cache size (in bytes).
205 // 0 means no maximum.
207
208 // Get the maximum cache size (in bytes).
210
211 // Get the current cache size (in buckets).
213 { return itsCube->cacheSize(); }
214
215 // Set the cache size using the given access pattern.
216 // <group>
217 void setCacheSize (const IPosition& sliceShape,
218 const IPosition& axisPath,
219 Bool forceSmaller=True)
220 { itsCube->setCacheSize (sliceShape, IPosition(), IPosition(),
221 axisPath, forceSmaller, True); }
222 void setCacheSize (const IPosition& sliceShape,
223 const IPosition& windowStart,
224 const IPosition& windowLength,
225 const IPosition& axisPath,
226 Bool forceSmaller=True)
227 { itsCube->setCacheSize (sliceShape, windowStart, windowLength,
228 axisPath, forceSmaller, True); }
229 // </group>
230
231 // Set the cache size for accessing the data.
232 // When the give cache size exceeds the maximum cache size with more
233 // than 10%, the maximum cache size is used instead.
234 // <br>When forceSmaller is False, the cache is not resized when the
235 // new size is smaller.
236 void setCacheSize (uInt nbuckets, Bool forceSmaller=True)
237 { itsCube->setCacheSize (nbuckets, forceSmaller, True); }
238
239 // Make a tile shape from the array shape to fit as closely as possible
240 // the number of pixels in the tile.
241 static IPosition makeTileShape (const IPosition& arrayShape,
242 uInt nrPixelsPerTile = 32768);
243
244
245private:
250 DataType itsDataType;
251};
252
253
254
255} //# NAMESPACE CASACORE - END
256
257#endif
String: the storage and methods of handling collections of characters.
Definition String.h:223
uInt cacheSize() const
Get the current cache size (in buckets).
void emptyCache()
Empty the cache.
virtual void showCacheStatistics(ostream &os) const
Show the cache statistics.
virtual void setCacheSize(const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath, Bool forceSmaller, Bool userSet)
Set the cache size for the given slice and access path.
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
virtual void flushCache()
Flush the data in the cache.
Array< Complex > getComplex(const Slicer &section)
void setCacheSize(uInt nbuckets, Bool forceSmaller=True)
Set the cache size for accessing the data.
const IPosition & tileShape() const
Get the shape of the tiles.
uInt cacheSize() const
Get the current cache size (in buckets).
Array< Short > getShort(const Slicer &section)
void get(Array< Complex > &, const Slicer &section)
void put(const Array< Short > &, const Slicer &section)
void get(Array< Bool > &, const Slicer &section)
void put(const Array< DComplex > &, const Slicer &section)
Array< DComplex > getDComplex(const Slicer &section)
Array< Bool > getBool(const Slicer &section)
Get part of the array.
void put(const Array< Int > &, const Slicer &section)
void get(Array< DComplex > &, const Slicer &section)
void get(Array< Short > &, const Slicer &section)
Array< uChar > getUChar(const Slicer &section)
void clearCache()
Empty the cache.
Array< Float > getFloat(const Slicer &section, Float scale, Float offset, Int deleteValue, Bool examineForDeleteValues=True)
void get(Array< Double > &, const Slicer &section)
const IPosition & shape() const
Get the shape of the array.
void setCacheSize(const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath, Bool forceSmaller=True)
Array< Float > getFloat(const Slicer &section)
void put(const Array< uChar > &, const Slicer &section)
TiledFileAccess & operator=(const TiledFileAccess &)=delete
Forbid assignment.
Array< Float > getFloat(const Slicer &section, Float scale, Float offset, uChar deleteValue, Bool examineForDeleteValues=True)
Get the array and scale/offset the data using the given values.
void get(Array< Int > &, const Slicer &section)
void put(const Array< Complex > &, const Slicer &section)
Bool isWritable() const
Is the file writable?
Array< Float > getFloat(const Slicer &section, Float scale, Float offset, Short deleteValue, Bool examineForDeleteValues=True)
void get(Array< uChar > &, const Slicer &section)
uInt64 maximumCacheSize() const
Get the maximum cache size (in bytes).
void put(const Array< Bool > &, const Slicer &section)
Put part of the array.
void get(Array< Float > &, const Slicer &section)
void flush()
Flush the cache.
TiledFileAccess(const String &fileName, Int64 fileOffset, const IPosition &shape, const IPosition &tileShape, DataType dataType, const TSMOption &=TSMOption(), Bool writable=False)
Create a TiledFileAccess object.
void setMaximumCacheSize(uInt64 nbytes)
Set the maximum cache size (in bytes).
Array< Int > getInt(const Slicer &section)
void put(const Array< Double > &, const Slicer &section)
Array< Double > getDouble(const Slicer &section)
void put(const Array< Float > &, const Slicer &section)
TiledFileAccess(const String &fileName, Int64 fileOffset, const IPosition &shape, const IPosition &tileShape, DataType dataType, const TSMOption &, Bool writable, Bool bigEndian)
Create a TiledFileAccess object.
void get(Array< Float > &, const Slicer &section, Float scale, Float offset, Short deleteValue, Bool examineForDeleteValues=True)
TiledFileAccess(const TiledFileAccess &)=delete
Forbid copy constructor.
void setCacheSize(const IPosition &sliceShape, const IPosition &axisPath, Bool forceSmaller=True)
Set the cache size using the given access pattern.
void showCacheStatistics(ostream &os) const
Show the cache statistics.
static IPosition makeTileShape(const IPosition &arrayShape, uInt nrPixelsPerTile=32768)
Make a tile shape from the array shape to fit as closely as possible the number of pixels in the tile...
void get(Array< Float > &, const Slicer &section, Float scale, Float offset, uChar deleteValue, Bool examineForDeleteValues=True)
void get(Array< Float > &, const Slicer &section, Float scale, Float offset, Int deleteValue, Bool examineForDeleteValues=True)
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
const Bool False
Definition aipstype.h:42
short Short
Definition aipstype.h:46
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
float Float
Definition aipstype.h:52
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
unsigned long long uInt64
Definition aipsxtype.h:37