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 <msvis/MSVis/VisBuffer.h> 00033 #include <msvis/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 void setTVIDebug(Bool debug) {tvi_debug = debug;} 00120 00121 protected: 00122 // Averaging buffer 00123 CalVisBuffer avBuf_p; 00124 00125 // Number of correlations and channels 00126 Int nCorr_p, nChan_p; 00127 00128 private: 00129 // Prohibit null constructor, copy constructor and assignment for now 00130 VisBuffAccumulator(); 00131 VisBuffAccumulator& operator= (const VisBuffAccumulator&); 00132 VisBuffAccumulator (const VisBuffAccumulator&); 00133 00134 // Diagnostic printing level 00135 Int& prtlev() { return prtlev_; }; 00136 00137 // Initialize the next accumulation interval 00138 void initialize(const Bool& copydata); 00139 00140 // Normalize the current accumulation 00141 void normalize(); 00142 00143 // Hash function to return the row offset for an interferometer (ant1, ant2) 00144 Int hashFunction (const Int& ant1, const Int& ant2); 00145 00146 // Shuffle error handling elsewhere in an attempt to let the calling function 00147 // be efficient and inlinable. 00148 void throw_err(const String& origin, const String &msg); 00149 00150 // Number of antennas 00151 Int nAnt_p; 00152 00153 // Averaging interval 00154 Double interval_p; 00155 00156 // Pre-normalization flag 00157 Bool prenorm_p; 00158 00159 // Diagnostic print level 00160 Int prtlev_; 00161 00162 // How many VisBuffers have been accumulated. 00163 uInt nBuf_p; 00164 00165 Bool fillModel_p; // Whether or not to accumulate MODEL_DATA 00166 00167 // End of initialization list 00168 00169 // Per-interval timestamp averaging 00170 Double aveTime_p; 00171 Double aveTimeWt_p; 00172 00173 // Global timestamp average 00174 Double globalTime_p; 00175 Double globalTimeWt_p; 00176 00177 // Start time and row of current accumulation 00178 Double tStart_p; 00179 Int avrow_p; 00180 00181 // Flag to mark the first accumulation interval 00182 Bool firstInterval_p; 00183 00184 // A map from avBuf_p's row numbers to row numbers in the VisBuffer used to 00185 // fill avBuf_p. Only useful if nBuf_p == 1. Unfilled rows point to -1. 00186 Vector<Int> outToInRow_p; 00187 00188 Bool tvi_debug; 00189 }; 00190 00191 00192 } //# NAMESPACE CASA - END 00193 00194 #endif 00195 00196