casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RFChunkStats.h
Go to the documentation of this file.
00001 //# RFChunkStats.h: this defines RFChunkStats
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_RFCHUNKSTATS_H
00028 #define FLAGGING_RFCHUNKSTATS_H
00029 
00030 #include <measures/Measures/Stokes.h> 
00031 #include <casa/Arrays/Vector.h> 
00032 #include <casa/Arrays/Matrix.h> 
00033 #include <casa/Arrays/Cube.h> 
00034 #include <casa/Containers/Block.h> 
00035 #include <lattices/Lattices/LatticeIterator.h> 
00036 #include <flagging/Flagging/RFCommon.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 class Flagger;
00041 class MeasurementSet;
00042 class VisibilityIterator;
00043 class VisBuffer;
00044 
00045 class RFABase;
00046 typedef RFABase RFA;
00047 
00048 // <summary>
00049 // RFChunkStats: vital information and flagging stats for a visibility chunk
00050 // </summary>
00051 
00052 // <use visibility=local>
00053 
00054 // <reviewed reviewer="" date="" tests="" demos="">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 //   <li> VisibilityIterator
00059 //   <li> VisBuffer
00060 //   <li> MeasurementSet
00061 //   <li> Flagger
00062 // </prerequisite>
00063 //
00064 // <etymology>
00065 // </etymology>
00066 //
00067 // <synopsis>
00068 // RFChunkStats maintains various stats, derived values, and flagging
00069 // counts for a single visibility chunk. Also serves as an interface to
00070 // VisIter and VisBuffer.
00071 // </synopsis>
00072 //
00073 // <motivation>
00074 // Vital information about an MS or a visibility chunk is spread all over 
00075 // three classes (MS, VisIter, VisBuffer). RFChunkStats provides a central
00076 // point for flagging agents to look this info up. 
00077 // </motivation>
00078 //
00079 // <todo asof="2001/04/16">
00080 //   <li> add this feature
00081 //   <li> fix this bug
00082 //   <li> start discussion of this possible extension
00083 // </todo>
00084 
00085 class RFChunkStats : public FlaggerEnums
00086 {
00087 protected:
00088   VisibilityIterator &visiter;
00089   VisBuffer          &visbuf;
00090   Flagger            &flagger;
00091   
00092   IPosition visshape;  
00093   uInt counts[Num_StatEnums];
00094   Matrix<uInt> nf_ifr_time,nf_chan_ifr;
00095   Vector<uInt> rows_per_ifr;
00096   Vector<uInt> nrf_ifr,nrf_time;
00097   Vector<Int>  ifr_nums;
00098   Vector<Int>  feed_nums;
00099   Vector<Int>  corrtypes;
00100   Vector<Double> freq;
00101   String       corr_string;
00102   Double       start_time,end_time,current_time;
00103   uInt chunk_no,pass_no;
00104   Int itime;
00105 
00106 //  Matrix<uInt> nf_corr_ifr, nf_chan_corr, nf_chan_time, nf_corr_time;
00107   
00108   std::vector<double> scan_start;      /* first time stamp in scan */
00109   std::vector<double> scan_start_flag; /* first time stamp with any 
00110                                           unflagged data in scan*/
00111   std::vector<double> scan_end, scan_end_flag; /* as above */
00112   
00113 
00114 
00115 public:
00116 // constructor
00117   RFChunkStats( VisibilityIterator &vi,VisBuffer &vb,Flagger &rf );
00118 
00119 // accessors to VisIter
00120   const VisibilityIterator & visIter () const { return visiter; }
00121   VisibilityIterator & visIter () { return visiter; }
00122 // accessor to VisBuffer
00123   VisBuffer &visBuf () { return visbuf; }
00124 // accessor to MS
00125   const MeasurementSet & measSet () const;
00126 // accessor to MS
00127   const String msName () const;
00128 // returns antenna names
00129   const Vector<String>  & antNames () const;
00130 
00131   // scan start/end times
00132   double get_scan_start(unsigned scan) const
00133     { return scan_start[scan]; }
00134 
00135   double get_scan_end(unsigned scan) const
00136     { return scan_end[scan]; }
00137 
00138   // scan start/end times for unflagged data
00139   //
00140   // returns: time stamps of first/last unflagged
00141   // data in the given scan, or a negative number 
00142   // if there's no unflagged data in the scan.
00143   double get_scan_start_unflagged(unsigned scan) const
00144     { return scan_start_flag[scan]; }
00145 
00146   double get_scan_end_unflagged(unsigned scan) const
00147     { return scan_end_flag[scan]; }
00148 
00149 // loads data for new chunk, resets all flag stat counters
00150   void newChunk (bool init_quack);
00151 // loads data for new pass
00152   void newPass (uInt npass);
00153 // loads data for new iteration
00154   void newTime ();
00155 
00156 // returns current chunk number
00157   uInt nchunk() const { return chunk_no; };
00158 // returns current pass number
00159   uInt npass()  const { return pass_no; };
00160 // returns current time slot
00161   Int  iTime()  const { return itime; };
00162 
00163 // returns a data dimension (POL, CHAN, IFR, etc.)
00164   uInt num ( StatEnums which ) const { return counts[which]; }
00165 // returns vector of frequencies (one per channel)
00166   const Vector<Double> & frequency ();
00167   
00168 // returns time of currently iterated time slot
00169   Double currentMJD () const     
00170     { return current_time; }
00171 // return first time slot in chunk
00172   Double startMJD () const     
00173     { return start_time; }
00174 // return last time slot in chunk
00175   Double endMJD () const       
00176     { return end_time; }
00177 
00178 // returns corr mask corresponding to specified Stokes types
00179 // (templated, but only String and Int will actually work)
00180   template<class T> RFlagWord getCorrMask ( const Vector<T> &corrspec );
00181   
00182 // returns mask with all correlations
00183   RFlagWord fullCorrMask () { return (1<<num(CORR))-1; };
00184 // returns string of correlations
00185   const String & getCorrString () { return corr_string; }
00186 
00187 // returns IFR index corresponding to current VisBuffer rows
00188   uInt ifrNum( uInt nr )  { return ifr_nums(nr); };
00189 // returns IFR index corresponding to current VisBuffer rows
00190   const Vector<Int> & ifrNums ()  { return ifr_nums; };
00191 
00192 // returns FEED index corresponding to current VisBuffer rows
00193   uInt feedNum( uInt nr )  { return feed_nums(nr); };
00194 // returns FEED index corresponding to current VisBuffer rows
00195   const Vector<Int> & feedNums ()  { return feed_nums; };
00196 
00197 // converts antenna indices into IFR index
00198   uInt antToIfr ( uInt ant1,uInt ant2 );
00199 // converts IFR index back to antenna numbers
00200   void ifrToAnt ( uInt &ant1,uInt &ant2,uInt ifr );
00201 // converts IFR index to standard ID string 
00202   String ifrString ( uInt ifr ); 
00203   
00204 // data availability stats, per IFR
00205   uInt nrowPerIfr ( uInt ifr )            { return rows_per_ifr(ifr); }
00206   const Vector<uInt> & nrowPerIfr () const { return rows_per_ifr; }
00207 
00208 // accessors to various flagging stats
00209   uInt & nfIfrTime ( uInt ifr,uInt itime )  
00210                                           { return nf_ifr_time(ifr,itime); }
00211   const Matrix<uInt> & nfIfrTime () const    
00212                                           { return nf_ifr_time; }
00213   uInt & nfChanIfr ( uInt ich,uInt ifr   )  // flags per channel and ifr
00214                                           { return nf_chan_ifr(ich,ifr); }
00215   const Matrix<uInt> & nfChanIfr () const   
00216                                           { return nf_chan_ifr; }        
00217   Matrix<uInt> & nfChanIfr ()
00218                                           { return nf_chan_ifr; }        
00219   uInt & nrfIfr  (uInt i)                  
00220                                           { return nrf_ifr(i); }
00221   uInt & nrfTime (uInt i)                  
00222                                           { return nrf_time(i); }
00223   const Vector<uInt> & nrfIfr  () const     
00224                                           { return nrf_ifr; };
00225   const Vector<uInt> & nrfTime () const     
00226                                           { return nrf_time; };
00227 
00228   //Matrix<uInt> nf_corr_ifr, nf_chan_corr, nf_chan_time, nf_corr_time;
00229   //uInt & nfCorrIfr( uInt icorr, uInt ifr ) { return nf_corr_ifr(icorr,ifr); }
00230   //const Matrix<uInt> & nfCorrIfr () const { return nf_corr_ifr; }
00231   //uInt & nfChanCorr( uInt ich, uInt icorr ) { return nf_chan_corr(ich,icorr); }
00232   //const Matrix<uInt> & nfChanCorr () const { return nf_chan_corr; }
00233   //uInt & nfChanTime( uInt ich, uInt itime ) { return nf_chan_time(ich,itime); }
00234   //const Matrix<uInt> & nfChanTime () const { return nf_chan_time; }
00235   //uInt & nfCorrTime( uInt icorr, uInt itime ) { return nf_corr_time(icorr,itime); }
00236   //const Matrix<uInt> & nfCorrTime () const { return nf_corr_time; }
00237   
00238 // prints stats to stderr
00239   void printStats ();
00240 };
00241 
00242 // enums for which stats are actually collected
00243 const RFChunkStats::StatEnums active_stats[] = { RFChunkStats::CHAN,RFChunkStats::IFR,RFChunkStats::TIME };
00244 const uInt num_active_stats = 3;
00245 
00246 // global function for finding polarization by index
00247 Int findCorrType( Stokes::StokesTypes type,const Vector<Int> &corr );
00248 
00249 
00250 } //# NAMESPACE CASA - END
00251 
00252 #ifndef AIPS_NO_TEMPLATE_SRC
00253 #include <flagging/Flagging/RFChunkStats.tcc>
00254 #endif //# AIPS_NO_TEMPLATE_SRC
00255 #endif