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