casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VisBuffAccumulator.h
Go to the documentation of this file.
00001 //# VisBuffAccumulator.h: class to average VisBuffers in time
00002 //# Copyright (C) 2000,2002
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: VisBuffAccumulator.h,v 19.6 2004/11/30 17:50:38 ddebonis Exp $
00027 
00028 #ifndef MSVIS_VISBUFFACCUMULATOR_H
00029 #define MSVIS_VISBUFFACCUMULATOR_H
00030 
00031 #include <casa/aips.h>
00032 #include <synthesis/MSVis/VisBuffer.h>
00033 #include <synthesis/MSVis/CalVisBuffer.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary>
00038 // A class to average VisBuffers in time
00039 // </summary>
00040 //
00041 // <use visibility=export>
00042 //
00043 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00044 // </reviewed>
00045 
00046 // <prerequisite>
00047 //   <li> VisBuffer
00048 // </prerequisite>
00049 //
00050 // <etymology>
00051 // From "visibility", "time" and "averaging".
00052 // </etymology>
00053 //
00054 // <synopsis>
00055 // This class averages VisBuffers in time.
00056 // </synopsis>
00057 //
00058 // <example>
00059 // </example>
00060 //
00061 // <motivation>
00062 // Collect all time averaging capabilities for VisBuffer averaging.
00063 // </motivation>
00064 //
00065 // <thrown>
00066 //    <li>
00067 //    <li>
00068 // </thrown>
00069 //
00070 // <todo asof="2000/09/01">
00071 //   <li> averaging over other indices.
00072 // </todo>
00073 
00074 class VisBuffAccumulator
00075 {
00076 public:
00077   // Construct from the number of antennas, the averaging interval and
00078   // the pre-normalization flag
00079   VisBuffAccumulator (const Int& nAnt, const Double& interval, 
00080                       const Bool& prenorm, const Bool fillModel=True);
00081 
00082   // Null destructor
00083   ~VisBuffAccumulator();
00084 
00085   // Reset the averager
00086   void reset();
00087 
00088   // Accumulate a VisBuffer
00089   void accumulate (const VisBuffer& vb);
00090 
00091   // Finalize averaging, and return the result
00092   void finalizeAverage();
00093 
00094   // Return a reference to the result
00095   // TBD: is it ok to return a CVB as a VB reference?  (do I need an
00096   //      explicit cast here?
00097   VisBuffer& aveVisBuff() { return avBuf_p; }
00098   CalVisBuffer& aveCalVisBuff() { return avBuf_p; }
00099 
00100   // Global timestamp info
00101   Double& timeStamp() { return globalTime_p; };
00102   Double& timeStampWt() { return globalTimeWt_p; };
00103 
00104   // The number of VisBuffers that have been accumulated.
00105   uInt nBuf() {return nBuf_p;}
00106 
00107   // Return a map from row numbers in the VisBuffer returned by aveVisBuff() or
00108   // aveCalVisBuff() to row numbers in the input VisBuffer.  Only useful if
00109   // nBuf_p == 1 or you are sure that the last input VisBuffer will meet your
00110   // needs (i.e. all the input VisBuffers had same set of antennas and the
00111   // metadata you want also matches).  hurl controls whether an exception will
00112   // be thrown if nBuf() != 1.  Unfilled rows point to -1.
00113   const Vector<Int>& outToInRow(const Bool hurl=true){
00114     if(hurl && nBuf_p != 1)
00115       throw_err("outToInRow", "The output to input row map is unreliable");
00116     return outToInRow_p;
00117   }
00118 
00119 protected:
00120   // Averaging buffer
00121   CalVisBuffer avBuf_p;
00122 
00123   // Number of correlations and channels
00124   Int nCorr_p, nChan_p;
00125 
00126 private:
00127   // Prohibit null constructor, copy constructor and assignment for now
00128   VisBuffAccumulator();
00129   VisBuffAccumulator& operator= (const VisBuffAccumulator&);
00130   VisBuffAccumulator (const VisBuffAccumulator&);
00131 
00132   // Diagnostic printing level
00133   Int& prtlev() { return prtlev_; };
00134 
00135   // Initialize the next accumulation interval
00136   void initialize(const Bool& copydata);
00137 
00138   // Normalize the current accumulation
00139   void normalize();
00140 
00141   // Hash function to return the row offset for an interferometer (ant1, ant2)
00142   Int hashFunction (const Int& ant1, const Int& ant2);
00143 
00144   // Shuffle error handling elsewhere in an attempt to let the calling function
00145   // be efficient and inlinable.
00146   void throw_err(const String& origin, const String &msg);
00147 
00148   // Number of antennas
00149   Int nAnt_p;
00150 
00151   // Averaging interval
00152   Double interval_p;
00153 
00154   // Pre-normalization flag
00155   Bool prenorm_p;
00156 
00157   // Diagnostic print level
00158   Int prtlev_;
00159 
00160   // How many VisBuffers have been accumulated.
00161   uInt nBuf_p;
00162 
00163   Bool fillModel_p;     // Whether or not to accumulate MODEL_DATA
00164 
00165   // End of initialization list
00166 
00167   // Per-interval timestamp averaging
00168   Double aveTime_p;
00169   Double aveTimeWt_p;
00170 
00171   // Global timestamp average
00172   Double globalTime_p;
00173   Double globalTimeWt_p;
00174 
00175   // Start time and row of current accumulation
00176   Double tStart_p;
00177   Int avrow_p;
00178 
00179   // Flag to mark the first accumulation interval
00180   Bool firstInterval_p;
00181   
00182   // A map from avBuf_p's row numbers to row numbers in the VisBuffer used to
00183   // fill avBuf_p.  Only useful if nBuf_p == 1.  Unfilled rows point to -1.
00184   Vector<Int> outToInRow_p;
00185 };
00186 
00187 
00188 } //# NAMESPACE CASA - END
00189 
00190 #endif
00191 
00192