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