Line data Source code
1 : //# RFCubeLattice.h: this defines RFCubeLattice
2 : //# Copyright (C) 2000,2001
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: aips2-request@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 : //# $Id$
27 : #ifndef FLAGGING_RFCUBELATTICE_H
28 : #define FLAGGING_RFCUBELATTICE_H
29 :
30 : #include <casacore/casa/Arrays/Matrix.h>
31 : #include <casacore/lattices/Lattices/TempLattice.h>
32 : #include <casacore/lattices/Lattices/LatticeIterator.h>
33 : #include <vector>
34 :
35 : namespace casa { //# NAMESPACE CASA - BEGIN
36 :
37 :
38 : // <summary>
39 : // RFCubeLatticeIterator: iterator over a cubic buffer
40 : // </summary>
41 :
42 : // <use visibility=local>
43 :
44 : // <reviewed reviewer="" date="" tests="" demos="">
45 : // </reviewed>
46 :
47 : // <prerequisite>
48 : // <li> std::vector, Matrix
49 : // </prerequisite>
50 : //
51 : // <synopsis>
52 : // See RFCubeLattice, below
53 : // </synopsis>
54 : //
55 : // <templating arg=T>
56 : // <li> same as Matrix
57 : // </templating>
58 : //
59 : // <todo asof="2001/04/16">
60 : // <li> add this feature
61 : // <li> fix this bug
62 : // <li> start discussion of this possible extension
63 : // </todo>
64 :
65 : template<class T>
66 : class RFCubeLattice;
67 :
68 : template<class T> class RFCubeLatticeIterator
69 : {
70 : private:
71 : std::vector<std::vector<bool> > *lattice;
72 :
73 : unsigned int iter_pos; // current time
74 :
75 : unsigned n_chan, n_ifr, n_time, n_bit, n_corr;
76 :
77 : void update_curs();
78 :
79 : public:
80 : // default constructor creates empty iterator
81 : RFCubeLatticeIterator();
82 :
83 : // creates and attaches to lattice
84 : RFCubeLatticeIterator(std::vector<std::vector<bool> > *lat,
85 : unsigned nchan, unsigned nifr,
86 : unsigned ntime, unsigned nbit, unsigned ncorr);
87 :
88 : // destructor
89 : ~RFCubeLatticeIterator();
90 :
91 : // resets the lattice iterator to beginning
92 : void reset();
93 :
94 : // advances internal iterator to specified slot along the Z axis
95 : void advance( casacore::uInt iz );
96 :
97 : // returns position of internal iterator
98 0 : casacore::uInt position ()
99 0 : { return iter_pos; }
100 :
101 : // returns element at i,j of cursor
102 : T operator () ( casacore::uInt i,casacore::uInt j ) const;
103 :
104 : void set( casacore::uInt i, casacore::uInt j, const T &val );
105 : void set( casacore::uInt ichan, casacore::uInt ifr, casacore::uInt icorrs, bool val );
106 :
107 : void flush_curs();
108 : };
109 :
110 :
111 : // <summary>
112 : // RFCubeLatice: a cubic lattice
113 : // </summary>
114 :
115 : // <use visibility=local>
116 :
117 : // <reviewed reviewer="" date="" tests="" demos="">
118 : // </reviewed>
119 :
120 : // <prerequisite>
121 : // <li> TempLattice
122 : // </prerequisite>
123 : //
124 : // <synopsis>
125 : // RFCubeLattice is a [NX,NY,NZ] vector of Matrices which
126 : // is iterated over the Z axis.
127 : // While a vector of Matrices may not be localized in memory, it has the
128 : // advantage that the total amount of memory allocated can exceed
129 : // the available RAM, which is probably not possible if allocated as a
130 : // single giant block.
131 : // Each element of the matrices is a few bits, therefore (in order to
132 : // save memory), the full matrix is represented as a bitsequence, which
133 : // is converted to casacore::Matrix<T> on the fly.
134 : //
135 : // The buffer is no longer implemented using a casacore::TempLattice because the
136 : // template parameter to casacore::TempLattice is restricted to certain types, and
137 : // cannot be dynamic_bitset<>. Besides, casacore::TempLattice is currently(?)
138 : // *not* well implemented: it creates casacore::TempLattice disk files although most
139 : // of the RAM is free.
140 : //
141 : // If more memory than avilable RAM is requested, swapping will occur.
142 : // The underlying OS probably knows better when to swap!
143 : //
144 : // </synopsis>
145 : //
146 : // <motivation>
147 : // Many flagging agents make use of cubic lattices (typically, to maintain
148 : // [NCHAN,NIFR,NTIME] cubes of something) in an identical way. This class
149 : // provides a clean and convenient interface to the basic functions.
150 : // </motivation>
151 : //
152 : // <templating arg=T>
153 : // <li> same as Matrix
154 : // </templating>
155 : //
156 : // <todo asof="2001/04/16">
157 : // <li> add this feature
158 : // <li> fix this bug
159 : // <li> start discussion of this possible extension
160 : // </todo>
161 :
162 : template<class T> class RFCubeLattice
163 : {
164 : protected:
165 : casacore::IPosition lat_shape;
166 : std::vector<std::vector<bool> > lat;
167 : RFCubeLatticeIterator<T> iter;
168 : unsigned n_chan, n_ifr, n_time, n_bit, n_corr;
169 :
170 : public:
171 : // default constructor creates empty cube
172 : RFCubeLattice();
173 : // creates NX x NY x NZ cube
174 : RFCubeLattice( casacore::uInt nx,casacore::uInt ny,casacore::uInt nz, casacore::uInt ncorr, casacore::uInt nAgent );
175 : // creates NX x NY x NZ cube and fills with initial value
176 : RFCubeLattice( casacore::uInt nx,casacore::uInt ny,casacore::uInt nz, casacore::uInt ncorr, casacore::uInt nAgent, const T &init_val );
177 : // destructor
178 : ~RFCubeLattice();
179 :
180 : // creates NX x NY x NZ cube
181 : // tile_mb is the tile size, in MB (when using paging)
182 : void init ( casacore::uInt nx,casacore::uInt ny,casacore::uInt nz, casacore::uInt ncorr, casacore::uInt nAgent );
183 : // creates NX x NY x NZ cube and fills with initial value
184 : // tile_mb is the tile size, in MB (when using paging)
185 : void init ( casacore::uInt nx,casacore::uInt ny,casacore::uInt nz, casacore::uInt ncorr, casacore::uInt nAgent, const T &init_val );
186 : // destroys cube
187 : void cleanup ();
188 : // returns size of cube
189 : static casacore::uInt estimateMemoryUse ( casacore::uInt nx,casacore::uInt ny,casacore::uInt nz )
190 : { return nx*ny*nz*sizeof(T)/(1024*1024) + 1; }
191 :
192 : // resets the lattice iterator to beginning.
193 : //casacore::Matrix<T> * reset( casacore::Bool will_read=true,
194 : // casacore::Bool will_write=true );
195 : void reset();
196 :
197 : // advances internal iterator to specified slot along the Z axis
198 0 : void advance( casacore::Int iz ) { iter.advance(iz); };
199 :
200 : // returns position of internal iterator
201 0 : casacore::Int position () { return iter.position(); }
202 :
203 : // returns shape
204 0 : casacore::IPosition & shape () { return lat_shape; }
205 :
206 : // returns element at i,j of cursor
207 0 : T operator () ( casacore::uInt i,casacore::uInt j ) const { return iter(i,j); }
208 :
209 : // sets element at i, j of cursor
210 0 : void set( casacore::uInt i, casacore::uInt j, const T &val )
211 0 : { iter.set(i, j, val); }
212 :
213 0 : void set( casacore::uInt ichan, casacore::uInt ifr, casacore::uInt icorr, bool val)
214 0 : { iter.set(ichan, ifr, icorr, val); }
215 :
216 : // sets element for all (ichan, icorr)
217 : void set_column( casacore::uInt ifr, const T &val );
218 :
219 : // provides access to lattice itself
220 : // std::vector<std::vector<bool> > & lattice() { return lat; }
221 :
222 : // provides access to iterator
223 0 : RFCubeLatticeIterator<T> & iterator() { return iter; }
224 :
225 : // creates a new iterator for this lattice
226 : RFCubeLatticeIterator<T> newIter();
227 : };
228 :
229 :
230 :
231 : } //# NAMESPACE CASA - END
232 :
233 : #ifndef AIPS_NO_TEMPLATE_SRC
234 : #include <flagging/Flagging/RFCubeLattice.tcc>
235 : #endif //# AIPS_NO_TEMPLATE_SRC
236 : #endif
|