DataLoadingBuf.h

Go to the documentation of this file.
00001 //# DataLoadingBuf.h: this defines a container for filler data buffers
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 //#
00027 //# $Id: DataLoadingBuf.h,v 1.1 2009/09/03 18:54:47 pteuben Exp $
00028 
00029 #ifndef BIMA_DATALOADINGBUF_H
00030 #define BIMA_DATALOADINGBUF_H
00031 
00032 #include <casa/Containers/Block.h>
00033 #include <casa/Arrays/Matrix.h>
00034 #include <casa/Arrays/Cube.h>
00035 #include <casa/Arrays/Vector.h>
00036 
00037 #include <casa/namespace.h>
00038 //# Forward Declarations
00039 
00040 // <summary>
00041 // a container for data buffers used to fill a measurement set
00042 // </summary>
00043 // 
00044 // <use visibility=export>
00045 // 
00046 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00047 // </reviewed>
00048 //
00049 // <etymology>
00050 // class holds buffers used to load data into a Measurment Set 
00051 // </etymology>
00052 //
00053 // <motivation>
00054 // Miriad data support multiple spectral windows for a given correllator
00055 // setup.  Furthermore, a dataset can contain multiple setups.  This class
00056 // attempts to avoid having to repeatedly create a buffer inside a loading
00057 // loop.
00058 // </motivation>
00059 //
00060 // <synopsis>
00061 // This class allows one to create reusable buffers for each of the spectral 
00062 // windows that can be passed to an 
00063 // <linkto class="ArrayColumn">ArrayColumn's</linkto>
00064 // <src>put()</src> function.  This avoids the cost of recreating the buffers
00065 // inside a loading loop that cycles through the input Miriad windows.  The 
00066 // buffers can be resized if necessary if the Miriad correllator setup 
00067 // changes.  <p>
00068 //
00069 // This class stores for each window a Matrix<Complex> to store the visibility data
00070 // and a Cube<Bool> to hold the flags.  Normally, you can have all wide-band windows 
00071 // share a single buffer
00072 // (since they are all the same size, namely having 1 channel).  The buffers are 
00073 // access via their (zero-base) window index, starting with the narrow band windows.  
00074 // A window index greater than or equal to the number of narrow band windows (set 
00075 // via <src>resizeForNspec()</src>) is assumed to refer a wide-band window and the 
00076 // last buffer is returned.  
00077 //
00078 // If the size of a buffer needs to be changed (e.g. because the correllator setup
00079 // changed such that the number of channels in a window subsequently changed), it 
00080 // is most convenient to do the resizing via <src>resizeForSpWin()</src>.
00081 // </synopsis>
00082 //
00083 // <example>
00084 // To set up the buffers, you need to know how many windows you have, and the 
00085 // number of channels in each window.
00086 // <srcblock>
00087 //     Int nspec = 6
00088 //     Int *nchan = { 512, 256, 256, 512, 256, 256 };
00089 //     DataLoadingBuf buf();
00090 //     buf.resizeForNspect(nspec+1)  // to hold both narrow and wide band data
00091 //     for(Int i=0; i < nspec; i++)
00092 //         buf.resizeForSpWin(i, nchan[i]);
00093 //     buf.resizeForSpWin(nspec, 1);
00094 // </srcblock>
00095 //
00096 // Now to use the buffers...
00097 // <srcblock>
00098 //     for(Int i=0; i < 2*nspec; i++) {
00099 //
00100 //         // get data-loading buffers
00101 //         Matrix<Complex> &vis = buf.visForSpWin(i);
00102 //         Cube<Bool> &flgs = buf.flagsForSpWin(i);
00103 // 
00104 //         // load in the data
00105 //         Int n = (i < nspec) ? nchan[i] : 1;
00106 //         for(Int j=0; j < n; j++) {
00107 //             vis(0,j) = Complex( corr[2*(j+offset)], 
00108 //                                -corr[2*(j+offset)+1] );
00109 //             flgs(0,j,1) = (flags[j+offset] == 0);
00110 //         }
00111 //     
00112 //         // load it into MS column
00113 //         msc->data().put(row, vis);
00114 //         msc->flagCategory().put(row, flgs);
00115 //     }
00116 // </srcblock>
00117 // </example>
00118 //
00119 // <todo asof="2001/02/22">
00120 //   <li> the most important functions in this class are inlined even though 
00121 //        they are a tad long (4-6 lines).  This is because it is expected 
00122 //        that they are called once within a loop.  Under this assumption, 
00123 //        the benefit probably out-weighs the cost.  If this assumption 
00124 //        changes, this code should probably be moved out of line.
00125 // </todo>
00126 //
00127 class DataLoadingBuf {
00128 private:
00129     Block< Matrix<Complex>* > vislist;
00130     Block< Cube<Bool>* > flgslist;
00131     Vector<Float> wt;
00132     Vector<Float> rms;
00133 
00134     DataLoadingBuf(DataLoadingBuf&);
00135 public:
00136 
00137     // create the container
00138     DataLoadingBuf();
00139 
00140     // delete the container
00141     ~DataLoadingBuf();
00142 
00143     // resize our arrays of containers to hold data for wide band data 
00144     // and a given number of narrow band spectral windows.  <src>i</src>
00145     // is the number of narrow band spectral windows.  
00146     void resizeForNspect(Int i);
00147 
00148     // return the number of channels that can be stored in a given window.
00149     // A value for <src>i</src> greater than or equal to the number of 
00150     // narrow band windows is assumed to refer to a wideband window; thus, 
00151     // 1 will be returned.
00152     Int nchanForSpWin(Int i) { return visForSpWin(i).ncolumn(); }
00153 
00154     // return a reference to the flags Cube for a given window.
00155     // A value for <src>i</src> greater than or equal to the number of 
00156     // narrow band windows is assumed to refer to a wideband window.
00157     Cube<Bool>& flagsForSpWin(Int winid) {
00158         if ((uInt)winid >= flgslist.nelements()) 
00159             winid = flgslist.nelements()-1;
00160         if (flgslist[winid] == NULL) flgslist[winid] = new Cube<Bool>();
00161         return *(flgslist[winid]);
00162     }
00163 
00164     // return a reference to the vis Matrix for a given window
00165     Matrix<Complex>& visForSpWin(Int winid) {
00166         if ((uInt)winid >= vislist.nelements()) winid = vislist.nelements()-1;
00167         if (vislist[winid] == NULL) vislist[winid] = new Matrix<Complex>();
00168         return *(vislist[winid]);
00169     }
00170 
00171     // return a reference to the weight vector
00172     Vector<Float>& weight() { return wt; }
00173 
00174     // return a reference to the sigma vector
00175     Vector<Float>& sigma() { return rms; }
00176 
00177     // resize the containers for a given window to the given number of channels
00178     void resizeForSpWin(Int winid, Int nchan) {
00179         Int npol;
00180 
00181         if (winid > Int(vislist.nelements())) winid = vislist.nelements();
00182         if (vislist[winid] == NULL ||
00183             visForSpWin(winid).ncolumn() != (uInt)nchan) 
00184         {
00185             npol = (vislist[winid] == NULL) ? 1 : vislist[winid]->nrow();
00186             if (vislist[winid] != NULL) delete vislist[winid];
00187             vislist[winid] = new Matrix<Complex>(npol, nchan);
00188             if (flgslist[winid] != NULL) delete flgslist[winid];
00189             flgslist[winid] = new Cube<Bool>(npol, nchan, 2, False);
00190         }
00191     }
00192 
00193     // resize the containers for a given number of polarization correlations
00194     void resizeForNpol(Int npol) {
00195         for(Int i=0; i < Int(vislist.nelements()); i++) {
00196             if (vislist[i] != NULL) {
00197                 Int nchan = vislist[i]->ncolumn();
00198                 vislist[i]->resize(npol, nchan);
00199                 flgslist[i]->resize(npol, nchan, 2);
00200                 *(flgslist[i]) = False;
00201             }
00202         }
00203         wt.resize(npol);
00204         rms.resize(npol);
00205     }
00206 
00207     
00208 };
00209 
00210 #endif
00211 
00212 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1