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