casacore
Loading...
Searching...
No Matches
LatticeBase.h
Go to the documentation of this file.
1//# LatticeBase.h: A non-templated, abstract base class for array-like classes
2//# Copyright (C) 1999,2000,2003
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 LATTICES_LATTICEBASE_H
27#define LATTICES_LATTICEBASE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/lattices/LEL/LELCoordinates.h>
33#include <casacore/casa/Arrays/IPosition.h>
34#include <casacore/casa/Utilities/DataType.h>
35#include <casacore/casa/IO/FileLocker.h>
36#include <casacore/casa/BasicSL/String.h>
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40//# Forward Declarations
41class LogIO;
42
43
44// <summary>
45// A non-templated, abstract base class for array-like objects.
46// </summary>
47
48// <use visibility=export>
49
50// <reviewed reviewer="Bob Garwood" date="2000/01/18" tests="tArrayLattice.cc" demos="dLattice.cc">
51// </reviewed>
52
53// <synopsis>
54// This pure abstract base class defines the operations which may be
55// performed on a lattice of any type.
56// <br>See class <linkto class=Lattice>Lattice</linkto> for a detailed
57// description of a lattice.
58// </synopsis>
59
60// <motivation>
61// It is very useful to be able to keep a pointer to a
62// non-templated base class. Furthermore it gives the opportunity to
63// factor out some non-templated code.
64// </motivation>
65
66// <note>
67// The cache functions (maximumCacheSize, setMaximumCacheSize,
68// setCacheSizeInTiles, setCacheSizeFromPath, clearCache, and
69// showCacheStatistics) should all be over-ridden together as
70// in PagedArray.
71// </note>
72//
73//# <todo asof="1999/02/04">
74//# <li>
75//# </todo>
76
77
79{
80public:
81 // A virtual destructor is needed so that it will use the actual destructor
82 // in the derived class.
83 virtual ~LatticeBase();
84
85 // Make a copy of the derived object (reference semantics).
86 virtual LatticeBase* clone() const = 0;
87
88 // Get the image type (returns name of derived class).
89 // The default implementation returns "Lattice".
90 // Note it is made pure virtual in ImageInterface.
91 virtual String imageType() const;
92
93 // Get the data type of the lattice.
94 virtual DataType dataType() const = 0;
95
96 // Is the lattice persistent and can it be loaded by other processes as well?
97 // That is the case for a PagedArray or PagedImage and for an ImageExpr
98 // which does not use transient lattices or regions.
99 // <br>The default implementation returns False.
100 virtual Bool isPersistent() const;
101
102 // Is the lattice paged to disk?
103 // <br>The default implementation returns False.
104 virtual Bool isPaged() const;
105
106 // Can the lattice data be referenced as an array section?
107 // That is the case for an ArrayLattice or a Temp/SubLattice using it.
108 // It is used by LatticeIterInterface.
109 // <br>The default implementation returns False.
110 virtual Bool canReferenceArray() const;
111
112 // Is the lattice writable?
113 // <br>The default implementation returns True.
114 virtual Bool isWritable() const;
115
116 // Save the image in an AipsIO file with the given name.
117 // Its purpose is to make ImageConcat and ImageExpr objects
118 // persistent.
119 // <br>The default implementation throws an exception.
120 virtual void save (const String& fileName) const;
121
122 // It is strongly recommended to use class
123 // <linkto class=LatticeLocker>LatticeLocker</linkto> to
124 // handle lattice locking. It also contains a more detailed
125 // explanation of the locking process.
126 // <br>By default the functions do not do anything at all.
127 // lock() and hasLock return True, which is suitable for all
128 // non-paged lattices.
129 // <group>
130 virtual Bool lock (FileLocker::LockType, uInt nattempts);
131 virtual void unlock();
133 // </group>
134
135 // Resynchronize the Lattice object with the lattice file.
136 // This function is only useful if no read-locking is used, ie.
137 // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
138 // In that cases the table system does not acquire a read-lock, thus
139 // does not synchronize itself automatically.
140 // <br>By default the function does not do anything at all.
141 virtual void resync();
142
143 // Flush the data (but do not unlock).
144 // <br>By default the function does not do anything at all.
145 virtual void flush();
146
147 // Temporarily close the lattice.
148 // It will be reopened automatically on the next access.
149 // <br>By default the function does not do anything at all.
150 virtual void tempClose();
151
152 // Explicitly reopen the temporarily closed lattice.
153 // <br>By default the function does not do anything at all.
154 virtual void reopen();
155
156 // Return the name of the current Lattice object. This will generally
157 // be a file name for lattices that have a persistent form. Any path
158 // before the actual file name can be optionally stripped off.
159 // <br>The default implementation returns an empty string.
160 virtual String name (Bool stripPath=False) const;
161
162 // Return the shape of the Lattice including all degenerate axes
163 // (ie. axes with a length of one)
164 virtual IPosition shape() const = 0;
165
166 // Return the number of axes in this Lattice. This includes all
167 // degenerate axes.
168 // <br>The default implementation returns shape().nelements().
169 virtual uInt ndim() const;
170
171 // Return the total number of elements in this Lattice.
172 // <br>The default implementation returns shape().product().
173 // <group>
174 virtual size_t nelements() const;
175 size_t size() const
176 { return nelements(); }
177 // </group>
178
179 // Return a value of "True" if this instance of Lattice and 'other' have
180 // the same shape, otherwise returns a value of "False".
181 Bool conform (const LatticeBase& other) const
182 { return shape().isEqual (other.shape()); }
183
184 // Return the coordinates of the lattice.
185 // <br>The default implementation returns an 'empty' LELLattCoord object.
187
188 // This function returns the recommended maximum number of pixels to
189 // include in the cursor of an iterator. The Lattice class has a default
190 // implementation which returns a number that is a power of two and
191 // includes enough pixels to consume between 4 and 8 MBytes of memory.
192 virtual uInt advisedMaxPixels() const = 0;
193
194 // Returns a recommended cursor shape for iterating through all the pixels
195 // in the Lattice. The default implementation sets up a shape that
196 // completely fills as many axes as possible, but always at least the
197 // first axis. For example, given a 10x20x30 Lattice
198 // <srcblock>
199 // maxPixels = 1 --> niceCursorShape = [10,1,1]
200 // 100 --> niceCursorShape = [10,1,1]
201 // 300 --> niceCursorShape = [10,20,1]
202 // 10000 --> niceCursorShape = [10,20,30]
203 // </srcblock>
204 // The default argument is the result of <src>advisedMaxPixels()</src>.
205 // <group>
207 { return doNiceCursorShape (maxPixels); }
210 // </group>
211
212 // Check class internals - used for debugging. Should always return True
213 virtual Bool ok() const;
214
215 // The function (in the derived classes) doing the actual work.
216 // This function is public, so it can be used internally in the
217 // various Lattice classes.
218 // <br>The default implementation tries to fit as many axes
219 // as possible given <src>maxPixels</src>.
220 virtual IPosition doNiceCursorShape (uInt maxPixels) const;
221
222 // Maximum cache size - not necessarily all used. In pixels.
223 // Default returns 0, which means that there is no maximum.
224 virtual uInt maximumCacheSize() const;
225
226 // Set the maximum (allowed) cache size as indicated.
227 // <br>The default implementation does nothing.
228 virtual void setMaximumCacheSize (uInt howManyPixels);
229
230 // Set the actual cache size for this Array to be big enough for the
231 // indicated number of tiles. This cache is not shared with PagedArrays
232 // in other rows and is always clipped to be less than the maximum value
233 // set using the setMaximumCacheSize member function.
234 // Tiles are cached using a first in first out algorithm.
235 // <br>The default implementation does nothing.
236 virtual void setCacheSizeInTiles (uInt howManyTiles);
237
238 // Set the cache size as to "fit" the indicated path.
239 // <br>The default implementation does nothing.
240 virtual void setCacheSizeFromPath (const IPosition& sliceShape,
241 const IPosition& windowStart,
242 const IPosition& windowLength,
243 const IPosition& axisPath);
244
245 // Clears and frees up the caches, but the maximum allowed cache size is
246 // unchanged from when setCacheSize was called.
247 // <br>The default implementation does nothing.
248 virtual void clearCache();
249
250 // Report on cache success.
251 // <br>The default implementation does nothing.
252 virtual void showCacheStatistics (ostream& os) const;
253
254
255protected:
256 // Define default constructor to be used by derived classes.
258
259 // Copy constructor and assignment can only be used by derived classes.
260 // <group>
263 { return *this; }
264 // </group>
265
266 // Throw an exception for arithmetic on a Bool Lattice.
267 void throwBoolMath() const;
268};
269
270
271
272} //# NAMESPACE CASACORE - END
273
274#endif
LockType
Define the possible lock types.
Definition FileLocker.h:93
bool isEqual(const IPosition &other) const
Element-by-element comparison for equality.
virtual Bool isPersistent() const
Is the lattice persistent and can it be loaded by other processes as well? That is the case for a Pag...
virtual uInt maximumCacheSize() const
Maximum cache size - not necessarily all used.
virtual String imageType() const
Get the image type (returns name of derived class).
Bool conform(const LatticeBase &other) const
Return a value of "True" if this instance of Lattice and 'other' have the same shape,...
virtual IPosition shape() const =0
Return the shape of the Lattice including all degenerate axes (ie.
size_t size() const
virtual Bool isPaged() const
Is the lattice paged to disk? The default implementation returns False.
IPosition niceCursorShape(uInt maxPixels) const
Returns a recommended cursor shape for iterating through all the pixels in the Lattice.
virtual Bool canReferenceArray() const
Can the lattice data be referenced as an array section? That is the case for an ArrayLattice or a Tem...
LatticeBase & operator=(const LatticeBase &)
virtual Bool lock(FileLocker::LockType, uInt nattempts)
It is strongly recommended to use class LatticeLocker to handle lattice locking.
virtual void resync()
Resynchronize the Lattice object with the lattice file.
virtual uInt advisedMaxPixels() const =0
This function returns the recommended maximum number of pixels to include in the cursor of an iterato...
virtual void flush()
Flush the data (but do not unlock).
IPosition niceCursorShape() const
virtual void setCacheSizeInTiles(uInt howManyTiles)
Set the actual cache size for this Array to be big enough for the indicated number of tiles.
virtual size_t nelements() const
Return the total number of elements in this Lattice.
LatticeBase()
Define default constructor to be used by derived classes.
virtual uInt ndim() const
Return the number of axes in this Lattice.
virtual void showCacheStatistics(ostream &os) const
Report on cache success.
virtual void unlock()
void throwBoolMath() const
Throw an exception for arithmetic on a Bool Lattice.
LatticeBase(const LatticeBase &)
Copy constructor and assignment can only be used by derived classes.
virtual void tempClose()
Temporarily close the lattice.
virtual LELCoordinates lelCoordinates() const
Return the coordinates of the lattice.
virtual void reopen()
Explicitly reopen the temporarily closed lattice.
virtual ~LatticeBase()
A virtual destructor is needed so that it will use the actual destructor in the derived class.
virtual Bool hasLock(FileLocker::LockType) const
virtual Bool isWritable() const
Is the lattice writable? The default implementation returns True.
virtual IPosition doNiceCursorShape(uInt maxPixels) const
The function (in the derived classes) doing the actual work.
virtual LatticeBase * clone() const =0
Make a copy of the derived object (reference semantics).
virtual void clearCache()
Clears and frees up the caches, but the maximum allowed cache size is unchanged from when setCacheSiz...
virtual void setCacheSizeFromPath(const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath)
Set the cache size as to "fit" the indicated path.
virtual Bool ok() const
Check class internals - used for debugging.
virtual void setMaximumCacheSize(uInt howManyPixels)
Set the maximum (allowed) cache size as indicated.
virtual String name(Bool stripPath=False) const
Return the name of the current Lattice object.
virtual void save(const String &fileName) const
Save the image in an AipsIO file with the given name.
virtual DataType dataType() const =0
Get the data type of the lattice.
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