casa
$Rev:20696$
|
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 <boost/dynamic_bitset.hpp> 00034 #include <vector> 00035 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 00039 // <summary> 00040 // RFCubeLatticeIterator: iterator over a cubic buffer 00041 // </summary> 00042 00043 // <use visibility=local> 00044 00045 // <reviewed reviewer="" date="" tests="" demos=""> 00046 // </reviewed> 00047 00048 // <prerequisite> 00049 // <li> std::vector, Matrix 00050 // </prerequisite> 00051 // 00052 // <synopsis> 00053 // See RFCubeLattice, below 00054 // </synopsis> 00055 // 00056 // <templating arg=T> 00057 // <li> same as Matrix 00058 // </templating> 00059 // 00060 // <todo asof="2001/04/16"> 00061 // <li> add this feature 00062 // <li> fix this bug 00063 // <li> start discussion of this possible extension 00064 // </todo> 00065 00066 template<class T> 00067 class RFCubeLattice; 00068 00069 template<class T> class RFCubeLatticeIterator 00070 { 00071 private: 00072 std::vector<boost::dynamic_bitset<> > *lattice; 00073 00074 unsigned int iter_pos; // current time 00075 00076 unsigned n_chan, n_ifr, n_time, n_bit, n_corr; 00077 00078 void update_curs(); 00079 00080 public: 00081 // default constructor creates empty iterator 00082 RFCubeLatticeIterator(); 00083 00084 // creates and attaches to lattice 00085 RFCubeLatticeIterator(std::vector<boost::dynamic_bitset<> > *lat, 00086 unsigned nchan, unsigned nifr, 00087 unsigned ntime, unsigned nbit, unsigned ncorr); 00088 00089 // destructor 00090 ~RFCubeLatticeIterator(); 00091 00092 // resets the lattice iterator to beginning 00093 void reset(); 00094 00095 // advances internal iterator to specified slot along the Z axis 00096 void advance( uInt iz ); 00097 00098 // returns position of internal iterator 00099 uInt position () 00100 { return iter_pos; } 00101 00102 // returns element at i,j of cursor 00103 T operator () ( uInt i,uInt j ) const; 00104 00105 void set( uInt i, uInt j, const T &val ); 00106 void set( uInt ichan, uInt ifr, uInt icorrs, bool val ); 00107 00108 void flush_curs(); 00109 }; 00110 00111 00112 // <summary> 00113 // RFCubeLatice: a cubic lattice 00114 // </summary> 00115 00116 // <use visibility=local> 00117 00118 // <reviewed reviewer="" date="" tests="" demos=""> 00119 // </reviewed> 00120 00121 // <prerequisite> 00122 // <li> TempLattice 00123 // </prerequisite> 00124 // 00125 // <synopsis> 00126 // RFCubeLattice is a [NX,NY,NZ] vector of Matrices which 00127 // is iterated over the Z axis. 00128 // While a vector of Matrices may not be localized in memory, it has the 00129 // advantage that the total amount of memory allocated can exceed 00130 // the available RAM, which is probably not possible if allocated as a 00131 // single giant block. 00132 // Each element of the matrices is a few bits, therefore (in order to 00133 // save memory), the full matrix is represented as a bitsequence, which 00134 // is converted to Matrix<T> on the fly. 00135 // 00136 // The buffer is no longer implemented using a TempLattice because the 00137 // template parameter to TempLattice is restricted to certain types, and 00138 // cannot be boost::dynamic_bitset<>. Besides, TempLattice is currently(?) 00139 // *not* well implemented: it creates TempLattice disk files although most 00140 // of the RAM is free. 00141 // 00142 // If more memory than avilable RAM is requested, swapping will occur. 00143 // The underlying OS probably knows better when to swap! 00144 // 00145 // </synopsis> 00146 // 00147 // <motivation> 00148 // Many flagging agents make use of cubic lattices (typically, to maintain 00149 // [NCHAN,NIFR,NTIME] cubes of something) in an identical way. This class 00150 // provides a clean and convenient interface to the basic functions. 00151 // </motivation> 00152 // 00153 // <templating arg=T> 00154 // <li> same as Matrix 00155 // </templating> 00156 // 00157 // <todo asof="2001/04/16"> 00158 // <li> add this feature 00159 // <li> fix this bug 00160 // <li> start discussion of this possible extension 00161 // </todo> 00162 00163 template<class T> class RFCubeLattice 00164 { 00165 protected: 00166 IPosition lat_shape; 00167 std::vector<boost::dynamic_bitset<> > lat; 00168 RFCubeLatticeIterator<T> iter; 00169 unsigned n_chan, n_ifr, n_time, n_bit, n_corr; 00170 00171 public: 00172 // default constructor creates empty cube 00173 RFCubeLattice(); 00174 // creates NX x NY x NZ cube 00175 RFCubeLattice( uInt nx,uInt ny,uInt nz, uInt ncorr, uInt nAgent ); 00176 // creates NX x NY x NZ cube and fills with initial value 00177 RFCubeLattice( uInt nx,uInt ny,uInt nz, uInt ncorr, uInt nAgent, const T &init_val ); 00178 // destructor 00179 ~RFCubeLattice(); 00180 00181 // creates NX x NY x NZ cube 00182 // tile_mb is the tile size, in MB (when using paging) 00183 void init ( uInt nx,uInt ny,uInt nz, uInt ncorr, uInt nAgent ); 00184 // creates NX x NY x NZ cube and fills with initial value 00185 // tile_mb is the tile size, in MB (when using paging) 00186 void init ( uInt nx,uInt ny,uInt nz, uInt ncorr, uInt nAgent, const T &init_val ); 00187 // destroys cube 00188 void cleanup (); 00189 // returns size of cube 00190 static uInt estimateMemoryUse ( uInt nx,uInt ny,uInt nz ) 00191 { return nx*ny*nz*sizeof(T)/(1024*1024) + 1; } 00192 00193 // resets the lattice iterator to beginning. 00194 //Matrix<T> * reset( Bool will_read=True, 00195 // Bool will_write=True ); 00196 void reset(); 00197 00198 // advances internal iterator to specified slot along the Z axis 00199 void advance( Int iz ) { iter.advance(iz); }; 00200 00201 // returns position of internal iterator 00202 Int position () { return iter.position(); } 00203 00204 // returns shape 00205 IPosition & shape () { return lat_shape; } 00206 00207 // returns element at i,j of cursor 00208 T operator () ( uInt i,uInt j ) const { return iter(i,j); } 00209 00210 // sets element at i, j of cursor 00211 void set( uInt i, uInt j, const T &val ) 00212 { iter.set(i, j, val); } 00213 00214 void set( uInt ichan, uInt ifr, uInt icorr, bool val) 00215 { iter.set(ichan, ifr, icorr, val); } 00216 00217 // sets element for all (ichan, icorr) 00218 void set_column( uInt ifr, const T &val ); 00219 00220 // provides access to lattice itself 00221 // std::vector<boost::dynamic_bitset<> > & lattice() { return lat; } 00222 00223 // provides access to iterator 00224 RFCubeLatticeIterator<T> & iterator() { return iter; } 00225 00226 // creates a new iterator for this lattice 00227 RFCubeLatticeIterator<T> newIter(); 00228 }; 00229 00230 00231 00232 } //# NAMESPACE CASA - END 00233 00234 #ifndef AIPS_NO_TEMPLATE_SRC 00235 #include <flagging/Flagging/RFCubeLattice.tcc> 00236 #endif //# AIPS_NO_TEMPLATE_SRC 00237 #endif