00001 //# RFCubeLattice.h: this defines RFCubeLattice 00002 //# Copyright (C) 2000,2001 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 #ifndef FLAGGING_RFCUBELATTICE_H 00028 #define FLAGGING_RFCUBELATTICE_H 00029 00030 #include <casa/Arrays/Matrix.h> 00031 #include <lattices/Lattices/TempLattice.h> 00032 #include <lattices/Lattices/LatticeIterator.h> 00033 #include <vector> 00034 00035 namespace casa { //# NAMESPACE CASA - BEGIN 00036 00037 00038 // <summary> 00039 // RFCubeLatticeIterator: iterator over a cubic buffer 00040 // </summary> 00041 00042 // <use visibility=local> 00043 00044 // <reviewed reviewer="" date="" tests="" demos=""> 00045 // </reviewed> 00046 00047 // <prerequisite> 00048 // <li> std::vector, Matrix 00049 // </prerequisite> 00050 // 00051 // <synopsis> 00052 // See RFCubeLattice, below 00053 // </synopsis> 00054 // 00055 // <templating arg=T> 00056 // <li> same as Matrix 00057 // </templating> 00058 // 00059 // <todo asof="2001/04/16"> 00060 // <li> add this feature 00061 // <li> fix this bug 00062 // <li> start discussion of this possible extension 00063 // </todo> 00064 00065 template<class T> 00066 class RFCubeLattice; 00067 00068 template<class T> class RFCubeLatticeIterator 00069 { 00070 private: 00071 std::vector<std::vector<bool> > *lattice; 00072 00073 unsigned int iter_pos; // current time 00074 00075 unsigned n_chan, n_ifr, n_time, n_bit, n_corr; 00076 00077 void update_curs(); 00078 00079 public: 00080 // default constructor creates empty iterator 00081 RFCubeLatticeIterator(); 00082 00083 // creates and attaches to lattice 00084 RFCubeLatticeIterator(std::vector<std::vector<bool> > *lat, 00085 unsigned nchan, unsigned nifr, 00086 unsigned ntime, unsigned nbit, unsigned ncorr); 00087 00088 // destructor 00089 ~RFCubeLatticeIterator(); 00090 00091 // resets the lattice iterator to beginning 00092 void reset(); 00093 00094 // advances internal iterator to specified slot along the Z axis 00095 void advance( uInt iz ); 00096 00097 // returns position of internal iterator 00098 uInt position () 00099 { return iter_pos; } 00100 00101 // returns element at i,j of cursor 00102 T operator () ( uInt i,uInt j ) const; 00103 00104 void set( uInt i, uInt j, const T &val ); 00105 void set( uInt ichan, uInt ifr, uInt icorrs, bool val ); 00106 00107 void flush_curs(); 00108 }; 00109 00110 00111 // <summary> 00112 // RFCubeLatice: a cubic lattice 00113 // </summary> 00114 00115 // <use visibility=local> 00116 00117 // <reviewed reviewer="" date="" tests="" demos=""> 00118 // </reviewed> 00119 00120 // <prerequisite> 00121 // <li> TempLattice 00122 // </prerequisite> 00123 // 00124 // <synopsis> 00125 // RFCubeLattice is a [NX,NY,NZ] vector of Matrices which 00126 // is iterated over the Z axis. 00127 // While a vector of Matrices may not be localized in memory, it has the 00128 // advantage that the total amount of memory allocated can exceed 00129 // the available RAM, which is probably not possible if allocated as a 00130 // single giant block. 00131 // Each element of the matrices is a few bits, therefore (in order to 00132 // save memory), the full matrix is represented as a bitsequence, which 00133 // is converted to Matrix<T> on the fly. 00134 // 00135 // The buffer is no longer implemented using a TempLattice because the 00136 // template parameter to TempLattice is restricted to certain types, and 00137 // cannot be dynamic_bitset<>. Besides, TempLattice is currently(?) 00138 // *not* well implemented: it creates TempLattice disk files although most 00139 // of the RAM is free. 00140 // 00141 // If more memory than avilable RAM is requested, swapping will occur. 00142 // The underlying OS probably knows better when to swap! 00143 // 00144 // </synopsis> 00145 // 00146 // <motivation> 00147 // Many flagging agents make use of cubic lattices (typically, to maintain 00148 // [NCHAN,NIFR,NTIME] cubes of something) in an identical way. This class 00149 // provides a clean and convenient interface to the basic functions. 00150 // </motivation> 00151 // 00152 // <templating arg=T> 00153 // <li> same as Matrix 00154 // </templating> 00155 // 00156 // <todo asof="2001/04/16"> 00157 // <li> add this feature 00158 // <li> fix this bug 00159 // <li> start discussion of this possible extension 00160 // </todo> 00161 00162 template<class T> class RFCubeLattice 00163 { 00164 protected: 00165 IPosition lat_shape; 00166 std::vector<std::vector<bool> > lat; 00167 RFCubeLatticeIterator<T> iter; 00168 unsigned n_chan, n_ifr, n_time, n_bit, n_corr; 00169 00170 public: 00171 // default constructor creates empty cube 00172 RFCubeLattice(); 00173 // creates NX x NY x NZ cube 00174 RFCubeLattice( uInt nx,uInt ny,uInt nz, uInt ncorr, uInt nAgent ); 00175 // creates NX x NY x NZ cube and fills with initial value 00176 RFCubeLattice( uInt nx,uInt ny,uInt nz, uInt ncorr, uInt nAgent, const T &init_val ); 00177 // destructor 00178 ~RFCubeLattice(); 00179 00180 // creates NX x NY x NZ cube 00181 // tile_mb is the tile size, in MB (when using paging) 00182 void init ( uInt nx,uInt ny,uInt nz, uInt ncorr, uInt nAgent ); 00183 // creates NX x NY x NZ cube and fills with initial value 00184 // tile_mb is the tile size, in MB (when using paging) 00185 void init ( uInt nx,uInt ny,uInt nz, uInt ncorr, uInt nAgent, const T &init_val ); 00186 // destroys cube 00187 void cleanup (); 00188 // returns size of cube 00189 static uInt estimateMemoryUse ( uInt nx,uInt ny,uInt nz ) 00190 { return nx*ny*nz*sizeof(T)/(1024*1024) + 1; } 00191 00192 // resets the lattice iterator to beginning. 00193 //Matrix<T> * reset( Bool will_read=True, 00194 // Bool will_write=True ); 00195 void reset(); 00196 00197 // advances internal iterator to specified slot along the Z axis 00198 void advance( Int iz ) { iter.advance(iz); }; 00199 00200 // returns position of internal iterator 00201 Int position () { return iter.position(); } 00202 00203 // returns shape 00204 IPosition & shape () { return lat_shape; } 00205 00206 // returns element at i,j of cursor 00207 T operator () ( uInt i,uInt j ) const { return iter(i,j); } 00208 00209 // sets element at i, j of cursor 00210 void set( uInt i, uInt j, const T &val ) 00211 { iter.set(i, j, val); } 00212 00213 void set( uInt ichan, uInt ifr, uInt icorr, bool val) 00214 { iter.set(ichan, ifr, icorr, val); } 00215 00216 // sets element for all (ichan, icorr) 00217 void set_column( uInt ifr, const T &val ); 00218 00219 // provides access to lattice itself 00220 // std::vector<std::vector<bool> > & lattice() { return lat; } 00221 00222 // provides access to iterator 00223 RFCubeLatticeIterator<T> & iterator() { return iter; } 00224 00225 // creates a new iterator for this lattice 00226 RFCubeLatticeIterator<T> newIter(); 00227 }; 00228 00229 00230 00231 } //# NAMESPACE CASA - END 00232 00233 #ifndef AIPS_NO_TEMPLATE_SRC 00234 #include <flagging/Flagging/RFCubeLattice.tcc> 00235 #endif //# AIPS_NO_TEMPLATE_SRC 00236 #endif