casacore
Loading...
Searching...
No Matches
TempLatticeImpl.h
Go to the documentation of this file.
1// # TempLatticeImpl.h: A Lattice that can be used for temporary storage
2// # Copyright (C) 1997,1998,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_TEMPLATTICEIMPL_H
27#define LATTICES_TEMPLATTICEIMPL_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/lattices/Lattices/Lattice.h>
32#include <casacore/lattices/Lattices/TiledShape.h>
33#include <casacore/tables/Tables/Table.h>
34#include <memory>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38// # Forward Declarations
39class Table;
40
41// <summary>
42// The class implementing TempLattice
43// </summary>
44
45// <use visibility=local>
46
47// <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tTempLattice.cc" demos="">
48// </reviewed>
49
50// <prerequisite>
51// <li> <linkto class="TempLattice">Lattice</linkto>
52// </prerequisite>
53
54// <synopsis>
55// The class is used as <src>std::shared_ptr<TempLatticeImpl></src> in class
56// TempLattice. In that way the making a copy of a TempLattice uses the
57// same object underneath.
58// This was needed to have a correct implementation of tempClose. Otherwise
59// when deleting a copy of a TempLattice, that destructor would delete the
60// underlying table and the original TempLattice could not reopen it.
61// </synopsis>
62
63template <class T>
65 public:
66 // The default constructor creates a TempLatticeImpl containing a
67 // default ArrayLattice object.
69
70 // Create a TempLatticeImpl of the specified shape. You can specify how much
71 // memory the Lattice can consume before it becomes disk based by giving a
72 // non-negative value to the maxMemoryInMB argument. Otherwise it will assume
73 // it can use up to 25% of the memory on your machine as defined in aipsrc
74 // (this algorithm may change). Setting maxMemoryInMB to zero will force
75 // the lattice to disk.
76 // <group>
77 TempLatticeImpl(const TiledShape& shape, Int maxMemoryInMB);
78 TempLatticeImpl(const TiledShape& shape, Double maxMemoryInMB);
79 // </group>
80
81 // The destructor removes the Lattice from memory and if necessary disk.
83
84 // Is the TempLattice paged to disk?
85 Bool isPaged() const { return (!itsTableName.empty()); }
86
87 // Can the lattice data be referenced as an array section?
88 Bool canReferenceArray() const { return (itsTableName.empty()); }
89
90 // Is the TempLattice writable? It should be.
91 Bool isWritable() const { return True; }
92
93 // Flush the data.
94 void flush() {
95 if (!itsTable.isNull()) itsTable.flush();
96 }
97
98 // Close the Lattice temporarily (if it is paged to disk).
99 // It'll be reopened automatically when needed or when
100 // <src>reopen</src> is called explicitly.
101 void tempClose();
102
103 // If needed, reopen a temporarily closed TempLatticeImpl.
104 void reopen();
105
106 // Return the shape of the Lattice including all degenerate axes.
107 // (ie. axes with a length of one)
108 IPosition shape() const {
109 doReopen();
110 return itsLatticePtr->shape();
111 }
112
113 // Set all of the elements in the Lattice to the given value.
114 void set(const T& value) {
115 doReopen();
116 itsLatticePtr->set(value);
117 }
118
119 // Replace every element, x, of the Lattice with the result of f(x). You
120 // must pass in the address of the function -- so the function must be
121 // declared and defined in the scope of your program. All versions of
122 // apply require a function that accepts a single argument of type T (the
123 // Lattice template type) and return a result of the same type. The first
124 // apply expects a function with an argument passed by value; the second
125 // expects the argument to be passed by const reference; the third
126 // requires an instance of the class <src>Functional<T,T></src>. The
127 // first form ought to run faster for the built-in types, which may be an
128 // issue for large Lattices stored in memory, where disk access is not an
129 // issue.
130 // <group>
131 void apply(T (*function)(T)) {
132 doReopen();
133 itsLatticePtr->apply(function);
134 }
135 void apply(T (*function)(const T&)) {
136 doReopen();
137 itsLatticePtr->apply(function);
138 }
139 void apply(const Functional<T, T>& function) {
140 doReopen();
141 itsLatticePtr->apply(function);
142 }
143 // </group>
144
145 // This function returns the recommended maximum number of pixels to
146 // include in the cursor of an iterator.
148 doReopen();
149 return itsLatticePtr->advisedMaxPixels();
150 }
151
152 // Get the best cursor shape.
154 doReopen();
155 return itsLatticePtr->niceCursorShape(maxPixels);
156 }
157
158 // Maximum size - not necessarily all used. In pixels.
159 uInt maximumCacheSize() const { return itsLatticePtr->maximumCacheSize(); }
160
161 // Set the maximum (allowed) cache size as indicated.
162 void setMaximumCacheSize(uInt howManyPixels) {
163 itsLatticePtr->setMaximumCacheSize(howManyPixels);
164 }
165
166 // Set the cache size as to "fit" the indicated path.
167 void setCacheSizeFromPath(const IPosition& sliceShape, const IPosition& windowStart,
168 const IPosition& windowLength, const IPosition& axisPath) {
169 itsLatticePtr->setCacheSizeFromPath(sliceShape, windowStart, windowLength, axisPath);
170 }
171
172 // Set the actual cache size for this Array to be be big enough for the
173 // indicated number of tiles. This cache is not shared with PagedArrays
174 // in other rows and is always clipped to be less than the maximum value
175 // set using the setMaximumCacheSize member function.
176 // tiles. Tiles are cached using a first in first out algorithm.
177 void setCacheSizeInTiles(uInt howManyTiles) { itsLatticePtr->setCacheSizeInTiles(howManyTiles); }
178
179 // Clears and frees up the caches, but the maximum allowed cache size is
180 // unchanged from when setCacheSize was called
181 void clearCache() { itsLatticePtr->clearCache(); }
182
183 // Report on cache success.
184 void showCacheStatistics(std::ostream& os) const { itsLatticePtr->showCacheStatistics(os); }
185
186 // Get or put a single element in the lattice.
187 // Note that Lattice::operator() can also be used to get a single element.
188 // <group>
189 T getAt(const IPosition& where) const {
190 doReopen();
191 return itsLatticePtr->getAt(where);
192 }
193 void putAt(const T& value, const IPosition& where) {
194 doReopen();
195 itsLatticePtr->putAt(value, where);
196 }
197 // </group>
198
199 // Check class internals - used for debugging. Should always return True
200 Bool ok() const {
201 doReopen();
202 return itsLatticePtr->ok();
203 }
204
205 // This function is used by the LatticeIterator class to generate an
206 // iterator of the correct type for this Lattice. Not recommended
207 // for general use.
208 LatticeIterInterface<T>* makeIter(const LatticeNavigator& navigator, Bool useRef) const {
209 doReopen();
210 return itsLatticePtr->makeIter(navigator, useRef);
211 }
212
213 // Do the actual getting of an array of values.
214 Bool doGetSlice(Array<T>& buffer, const Slicer& section) {
215 doReopen();
216 return itsLatticePtr->doGetSlice(buffer, section);
217 }
218
219 // Do the actual getting of an array of values.
220 void doPutSlice(const Array<T>& sourceBuffer, const IPosition& where, const IPosition& stride) {
221 doReopen();
222 itsLatticePtr->putSlice(sourceBuffer, where, stride);
223 }
224
225 // Do the reopen of the table (if not open already).
226 void doReopen() const {
227 if (itsIsClosed) tempReopen();
228 }
229
230 private:
231 // The copy constructor cannot be used.
233
234 // The assignment operator cannot be used.
236
237 // Initialize the object.
238 void init(const TiledShape& shape, Double maxMemoryInMB = -1);
239
240 // Do the actual reopen of the temporarily closed table (if not open already).
241 void tempReopen() const;
242
243 // Make sure that the temporary table gets deleted.
245
247 mutable std::shared_ptr<Lattice<T>> itsLatticePtr;
250};
251
252} // namespace casacore
253
254#ifndef CASACORE_NO_AUTO_TEMPLATES
255#include <casacore/lattices/Lattices/TempLatticeImpl.tcc>
256#endif // # CASACORE_NO_AUTO_TEMPLATES
257#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
TempLatticeImpl< T > & operator=(const TempLatticeImpl< T > &other)
The assignment operator cannot be used.
void setCacheSizeInTiles(uInt howManyTiles)
Set the actual cache size for this Array to be be big enough for the indicated number of tiles.
void init(const TiledShape &shape, Double maxMemoryInMB=-1)
Initialize the object.
void clearCache()
Clears and frees up the caches, but the maximum allowed cache size is unchanged from when setCacheSiz...
void setMaximumCacheSize(uInt howManyPixels)
Set the maximum (allowed) cache size as indicated.
Bool isWritable() const
Is the TempLattice writable?
void tempClose()
Close the Lattice temporarily (if it is paged to disk).
void deleteTable()
Make sure that the temporary table gets deleted.
IPosition doNiceCursorShape(uInt maxPixels)
Get the best cursor shape.
Bool doGetSlice(Array< T > &buffer, const Slicer &section)
Do the actual getting of an array of values.
void apply(T(*function)(const T &))
void set(const T &value)
Set all of the elements in the Lattice to the given value.
void showCacheStatistics(std::ostream &os) const
Report on cache success.
void putAt(const T &value, const IPosition &where)
uInt maximumCacheSize() const
Maximum size - not necessarily all used.
TempLatticeImpl()
The default constructor creates a TempLatticeImpl containing a default ArrayLattice object.
LatticeIterInterface< T > * makeIter(const LatticeNavigator &navigator, Bool useRef) const
This function is used by the LatticeIterator class to generate an iterator of the correct type for th...
TempLatticeImpl(const TempLatticeImpl< T > &other)
The copy constructor cannot be used.
void apply(const Functional< T, T > &function)
Bool ok() const
Check class internals - used for debugging.
TempLatticeImpl(const TiledShape &shape, Double maxMemoryInMB)
uInt advisedMaxPixels() const
This function returns the recommended maximum number of pixels to include in the cursor of an iterato...
std::shared_ptr< Lattice< T > > itsLatticePtr
void doReopen() const
Do the reopen of the table (if not open already).
T getAt(const IPosition &where) const
Get or put a single element in the lattice.
~TempLatticeImpl()
The destructor removes the Lattice from memory and if necessary disk.
TempLatticeImpl(const TiledShape &shape, Int maxMemoryInMB)
Create a TempLatticeImpl of the specified shape.
void setCacheSizeFromPath(const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath)
Set the cache size as to "fit" the indicated path.
void apply(T(*function)(T))
Replace every element, x, of the Lattice with the result of f(x).
void reopen()
If needed, reopen a temporarily closed TempLatticeImpl.
void tempReopen() const
Do the actual reopen of the temporarily closed table (if not open already).
Bool canReferenceArray() const
Can the lattice data be referenced as an array section?
void doPutSlice(const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride)
Do the actual getting of an array of values.
Bool isPaged() const
Is the TempLattice paged to disk?
void flush()
Flush the data.
IPosition shape() const
Return the shape of the Lattice including all degenerate axes.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
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
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
double Double
Definition aipstype.h:53