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