casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VisibilityIteratorImpl2.h
Go to the documentation of this file.
00001 //# VisibilityIterator.h: Step through the MeasurementEquation by visibility
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
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: VisibilityIterator2.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $
00027 
00028 #ifndef MSVIS_VISIBILITYITERATORIMPL2_H
00029 #define MSVIS_VISIBILITYITERATORIMPL2_H
00030 
00031 #include <casa/aips.h>
00032 #include <ms/MeasurementSets/MSDerivedValues.h>
00033 #include <synthesis/MSVis/ViImplementation2.h>
00034 #include <synthesis/MSVis/ViColumns2.h>
00035 #include <tables/Tables/ArrayColumn.h>
00036 #include <tables/Tables/ScalarColumn.h>
00037 #include <synthesis/MSVis/VisImagingWeight.h>
00038 #include <synthesis/MSVis/VisBuffer2.h>
00039 
00040 #include <boost/noncopyable.hpp>
00041 #include <map>
00042 #include <vector>
00043 
00044 namespace casa { //# NAMESPACE CASA - BEGIN
00045 
00046 template <typename T> class ArrayColumn;
00047 //class CStokesVector;
00048 template <typename T> class ROArrayColumn;
00049 template <typename T, Int N> class RigidVector;
00050 template <typename T, Int N> class SquareMatrix;
00051 
00052 namespace vi {
00053 
00054 //# forward decl
00055 
00056 class VisBuffer2;
00057 
00058 class ChannelSelector;
00059 class ChannelSelectorCache;
00060 class SpectralWindowChannelsCache;
00061 class SpectralWindowChannels;
00062 class SubtableColumns;
00063 
00064 
00065 // <summary>
00066 // VisibilityIterator2 iterates through one or more readonly MeasurementSets
00067 // </summary>
00068 
00069 // <use visibility=export>
00070 
00071 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00072 // </reviewed>
00073 
00074 // <prerequisite>
00075 //   <li> <linkto class="MSIter">MSIter</linkto>
00076 //   <li> <linkto class="MeasurementSet">MeasurementSet</linkto>
00077 //   <li> <linkto class="VisSet">VisSet</linkto>
00078 // </prerequisite>
00079 //
00080 // <etymology>
00081 // The VisibilityIterator2 is a readonly iterator returning visibilities
00082 // </etymology>
00083 //
00084 // <synopsis>
00085 // VisibilityIterator2 provides iteration with various sort orders
00086 // for one or more MSs. It has member functions to retrieve the fields
00087 // commonly needed in synthesis calibration and imaging.
00088 //
00089 // One should use <linkto class="VisBuffer">VisBuffer</linkto>
00090 // to access chunks of data.
00091 // </synopsis>
00092 //
00093 // <example>
00094 // <code>
00095 // //
00096 // </code>
00097 // </example>
00098 //
00099 // <motivation>
00100 // For imaging and calibration you need to access an MS in some consistent
00101 // order (by field, spectralwindow, time interval etc.). This class provides
00102 // that access.
00103 // </motivation>
00104 //
00105 // <thrown>
00106 //    <li>
00107 //    <li>
00108 // </thrown>
00109 //
00110 // <todo asof="1997/05/30">
00111 //   <li> cleanup the currently dual interface for visibilities and flags
00112 //   <li> sort out what to do with weights when interpolating
00113 // </todo>
00114 
00115 class VisibilityIteratorImpl2 : public ViImplementation2 {
00116 
00117     friend class AsyncEnabler;
00118     friend class ViImplAsync2;
00119     friend class VisibilityIterator2;
00120     friend class VLAT; // allow VI lookahead thread class to access protected functions
00121     friend class VisBuffer2Adapter;
00122     // VLAT should not access private parts, especially variables
00123 
00124 public:
00125 
00126     //# the following is a copy of the enum in MSIter
00127     //# can't think of a way to get one that known to the outside world from here
00128     //  enum PolFrame {
00129     //    // Circular polarization
00130     //    Circular=0,
00131     //    // Linear polarization
00132     //    Linear=1
00133     //  };
00134     //
00135     //  enum DataColumn {
00136     //    // Observed data
00137     //    Observed=0,
00138     //    // Model data
00139     //    Model,
00140     //    // Corrected data
00141     //    Corrected
00142     //  };
00143 
00144     typedef VisibilityIterator2::DataColumn DataColumn;
00145 
00146     //    class AsyncEnabler {
00147     //    public:
00148     //        AsyncEnabler (VisibilityIterator2 &);
00149     //        AsyncEnabler (VisibilityIterator2 *);
00150     //        ~AsyncEnabler ();
00151     //
00152     //        void release ();
00153     //
00154     //    private:
00155     //
00156     //        Bool oldEnabledState_p;
00157     //        VisibilityIterator2 * roVisibilityIterator2_p;
00158     //    };
00159 
00160     // Default constructor - useful only to assign another iterator later
00162 
00163     // Construct from an MS and a Block of MS column enums specifying the
00164     // iteration order.  If no order is specified, it uses the default sort
00165     // order of MSIter, which is not necessarily the raw order of ms!
00166     // The default ordering is ARRAY_ID, FIELD_ID, DATA_DESC_ID,
00167     // and TIME, but check MSIter.h to be sure.
00168     // These columns will be added first if they are not specified.
00169     //
00170     // An optional timeInterval (in seconds) can be given to iterate through
00171     // chunks of time.  The default interval of 0 groups all times together.
00172     // Every 'chunk' of data contains all data within a certain time interval and
00173     // with identical values of the other iteration columns (e.g.  DATA_DESC_ID
00174     // and FIELD_ID).  Using selectChannel (), a number of groups of channels can
00175     // be requested.  At present the channel group iteration will always occur
00176     // before the interval iteration.
00177 //    VisibilityIteratorImpl (const MeasurementSet & ms,
00178 //                                const Block<Int> & sortColumns,
00179 //                                Double timeInterval = 0);
00180 
00181     // Same as above, but with the option of using the raw order of ms
00182     // (addDefaultSortCols=false).
00183 //    VisibilityIteratorImpl (const MeasurementSet & ms,
00184 //                                const Block<Int> & sortColumns, const Bool addDefaultSortCols,
00185 //                                Double timeInterval = 0);
00186 
00187     // Same as previous constructors, but with multiple MSs to iterate over.
00188 //    VisibilityIteratorImpl (const Block<MeasurementSet> & mss,
00189 //                                const Block<Int> & sortColumns,
00190 //                                Double timeInterval = 0);
00191 
00192     VisibilityIteratorImpl2 (VisibilityIterator2 * rovi,
00193                              const Block<MeasurementSet> & mss,
00194                              const Block<Int> & sortColumns,
00195                              Bool addDefaultSortCols,
00196                              Double timeInterval,
00197                              VisBufferType vbType,
00198                              Bool isWritable);
00199 
00200 //    // Copy construct. This calls the assigment operator.
00201 //    VisibilityIteratorImpl2 (const VisibilityIteratorImpl2 & other,
00202 //                                  VisibilityIterator2 * rovi);
00203 
00204     // Destructor
00205     virtual ~VisibilityIteratorImpl2 ();
00206 
00207         // Members
00208 
00209     virtual Bool isWritable () const;
00210 
00211     // Reset iterator to origin/start of data (of current chunk)
00212     virtual void origin ();
00213     // Reset iterator to true start of data (first chunk)
00214     virtual void originChunks ();
00215 
00216     // Return the time interval (in seconds) used for iteration.
00217     // This is not the same as the INTERVAL column.
00218 
00219     virtual Double getInterval() const;
00220 
00221     // Set or reset the time interval (in seconds) to use for iteration.
00222     // You should call originChunks () to reset the iteration after
00223     // calling this.
00224     virtual void setInterval (Double timeInterval);
00225 
00226     // Set the 'blocking' size for returning data.
00227     // With the default (0) only a single integration is returned at a time, this
00228     // is what is currently required for the calibration software. With blocking
00229     // set, up to nRows can be returned in one go. The chunk
00230     // size determines the actual maximum.
00231     virtual void setRowBlocking (Int nRows = 0);
00232 
00233     virtual Bool existsColumn (VisBufferComponent2 id) const;
00234 
00235     // Return False if no more data (in current chunk)
00236     virtual Bool more () const;
00237 
00238     virtual Subchunk getSubchunkId () const;
00239 
00240     virtual const Block<Int>& getSortColumns() const;
00241 
00242     virtual void setFrequencySelections (const FrequencySelections & selection);
00243 
00244     // Return False if no more 'Chunks' of data left
00245     virtual Bool moreChunks () const;
00246 
00247     // Check if ms has change since last iteration
00248 
00249     virtual Bool isNewArrayId () const;
00250     virtual Bool isNewFieldId () const;
00251     virtual Bool isNewMs () const;
00252     virtual Bool isNewSpectralWindow () const;
00253 
00254     virtual Int msId () const;
00255     virtual Int getNMs () const;
00256 
00257     virtual VisBuffer2 * getVisBuffer ();
00258 
00259     //reference to actual ms in interator
00260     virtual const MeasurementSet & ms () const;
00261 
00262     // advance the iteration
00263 
00264     virtual void next ();
00265 
00266     // Advance to the next Chunk of data
00267     virtual void nextChunk ();
00268 
00269     // Return antenna1
00270     virtual void antenna1 (Vector<Int> & ant1) const;
00271 
00272     // Return antenna2
00273     virtual void antenna2 (Vector<Int> & ant2) const;
00274 
00275     // Return feed1
00276     virtual void feed1 (Vector<Int> & fd1) const;
00277 
00278     // Return feed2
00279     virtual void feed2 (Vector<Int> & fd2) const;
00280 
00281 
00282     // Return feed configuration matrix for specified antenna
00283     void jonesC (Vector<SquareMatrix<Complex, 2> > & cjones) const;
00284 
00285     // Return receptor angles for all antennae and feeds
00286     // First axis of the cube is a receptor number,
00287     // 2nd is antennaId, 3rd is feedId
00288     // Note: the method is intended to provide an access to MSIter::receptorAngles
00289     // for VisBuffer in the multi-feed case. It may be worth to change the
00290     // interface of feed_pa to return the information for all feeds.
00291     virtual const Cube<Double> & receptorAngles () const;
00292 
00293     // return a string mount identifier for each antenna
00294     virtual const Vector<String> & antennaMounts () const;
00295 
00296     // Return a cube containing pairs of coordinate offsets for each
00297     // receptor of each feed (values are in radians, coordinate system is fixed
00298     // with antenna and is the same one as used to define the BEAM_OFFSET
00299     // parameter in the feed table). The cube axes are receptor, antenna, feed.
00300     virtual const Cube<RigidVector<Double, 2> > & getBeamOffsets () const;
00301 
00302     // True if all elements of the cube returned by getBeamOffsets are zero
00303     virtual Bool allBeamOffsetsZero () const;
00304 
00305     // Return feed parallactic angles Vector (nant) (1 feed/ant)
00306     virtual const Vector<Float> & feed_pa (Double time) const;
00307 
00308     // Return nominal parallactic angle at specified time
00309     // (does not include feed position angle offset--see feed_pa)
00310     // A global value for all antennas (e.g., small array)
00311     virtual const Float & parang0 (Double time) const;
00312 
00313     // Per antenna:
00314     virtual const Vector<Float> & parang (Double time) const;
00315 
00316     // Return the antenna AZ/EL Vector (nant)
00317     virtual MDirection azel0 (Double time) const;
00318 
00319     virtual const Vector<MDirection> & azel (Double time) const;
00320 
00321     // Return the hour angle for the specified time
00322     virtual Double hourang (Double time) const;
00323 
00324     // Return the current FieldId
00325     virtual void fieldIds (Vector<Int>&) const;
00326 
00327     // Return the current ArrayId
00328     virtual void arrayIds (Vector<Int>&) const;
00329 
00330     // Return the current Field Name
00331     virtual String fieldName () const;
00332 
00333     // Return the current Source Name
00334     virtual String sourceName () const;
00335 
00336     // Return flag for each polarization, channel and row
00337     virtual void flag (Cube<Bool> & flags) const;
00338 
00339     // Return flag for each channel & row
00340     virtual void flag (Matrix<Bool> & flags) const;
00341 
00342     // Determine whether FLAG_CATEGORY is valid.
00343     Bool flagCategoryExists () const;
00344 
00345     // Return flags for each polarization, channel, category, and row.
00346     virtual void flagCategory (Array<Bool> & flagCategories) const;
00347 
00348     // Return row flag
00349     virtual void flagRow (Vector<Bool> & rowflags) const;
00350 
00351     // Return scan number
00352     virtual void scan (Vector<Int> & scans) const;
00353 
00354     // Return the OBSERVATION_IDs
00355     virtual void observationId (Vector<Int> & obsids) const;
00356 
00357     // Return the PROCESSOR_IDs
00358     virtual void processorId (Vector<Int> & procids) const;
00359 
00360     // Return the STATE_IDs
00361     virtual void stateId (Vector<Int> & stateids) const;
00362 
00363     // Return the current phase center as an MDirection
00364     virtual const MDirection & phaseCenter () const;
00365 
00366     // Return frame for polarization (returns PolFrame enum)
00367     virtual Int polFrame () const;
00368 
00369     // Return the correlation type (returns Stokes enums)
00370     virtual void corrType (Vector<Int> & corrTypes) const;
00371 
00372     // Return sigma
00373     virtual void sigma (Vector<Float> & sig) const;
00374 
00375     // Return sigma matrix (pol-dep)
00376     virtual void sigmaMat (Matrix<Float> & sigmat) const;
00377 
00378     // Return current SpectralWindow
00379     virtual Int spectralWindow () const;
00380 
00381     virtual void spectralWindows (Vector<Int> & spws) const;
00382 
00383     // Return current Polarization Id
00384     virtual Int polarizationId () const;
00385 
00386     // Return current DataDescription Id
00387     virtual Int dataDescriptionId () const;
00388 
00389     virtual void dataDescriptionIds (Vector<Int> & ddis) const;
00390 
00391     // Return MJD midpoint of interval.
00392     virtual void time (Vector<Double> & t) const;
00393 
00394     // Return MJD centroid of interval.
00395     virtual void timeCentroid (Vector<Double> & t) const;
00396 
00397     // Return nominal time interval
00398     virtual void timeInterval (Vector<Double> & ti) const;
00399 
00400     // Return actual time interval
00401     virtual void  exposure (Vector<Double> & expo) const;
00402 
00403     // Return the visibilities as found in the MS, Cube (npol,nchan,nrow).
00404     virtual void visibilityCorrected (Cube<Complex> & vis) const;
00405     virtual void visibilityModel (Cube<Complex> & vis) const;
00406     virtual void visibilityObserved (Cube<Complex> & vis) const;
00407 
00408     // Return FLOAT_DATA as a Cube (npol, nchan, nrow) if found in the MS.
00409     virtual void floatData (Cube<Float> & fcube) const;
00410 
00411     // Return the visibility 4-vector of polarizations for each channel.
00412     // If the MS doesn't contain all polarizations, it is assumed it
00413     // contains one or two parallel hand polarizations.
00414 //    virtual void visibilityCorrected (Matrix<CStokesVector> & vis) const;
00415 //    virtual void visibilityModel (Matrix<CStokesVector> & vis) const;
00416 //    virtual void visibilityObserved (Matrix<CStokesVector> & vis) const;
00417 
00418     // Return the shape of the visibility Cube
00419     virtual IPosition visibilityShape () const;
00420 
00421     // Return u,v and w (in meters)
00422 
00423     virtual void uvw (Matrix<Double> & uvwmat) const;
00424 
00425     // Return weight
00426     virtual void weight (Vector<Float> & wt) const;
00427 
00428     // Returns the nPol_p x curNumRow_p weight matrix
00429     virtual void weightMat (Matrix<Float> & wtmat) const;
00430 
00431     // Determine whether WEIGHT_SPECTRUM exists.
00432     Bool weightSpectrumExists () const;
00433 
00434     // Return weightspectrum (a weight for each channel)
00435     virtual void weightSpectrum (Cube<Float> & wtsp) const;
00436 
00437     // Return imaging weight (a weight for each channel)
00438     //virtual Matrix<Float> & imagingWeight (Matrix<Float> & wt) const;
00439     const VisImagingWeight & getImagingWeightGenerator () const;
00440 
00441     // Return True if FieldId/Source has changed since last iteration
00442     virtual Bool newFieldId () const;
00443 
00444     // Return True if arrayID has changed since last iteration
00445     virtual Bool newArrayId () const;
00446 
00447     // Return True if SpectralWindow has changed since last iteration
00448     virtual Bool newSpectralWindow () const;
00449 
00450     // Return the number of rows in the current iteration
00451     virtual Int nRows () const;
00452 
00453     // Return the row ids as from the original root table. This is useful
00454     // to find correspondance between a given row in this iteration to the
00455     // original ms row
00456     virtual void getRowIds (Vector<uInt> & rowids) const;
00457 
00458     // Return the numbers of rows in the current chunk
00459 
00460     virtual Int nRowsInChunk () const;
00461 
00462     // Return the number of sub-intervals in the current chunk
00463 
00464     //virtual Int nSubInterval () const;
00465 
00466     // Call to use the slurp i/o method for all scalar columns. This
00467     // will set the BucketCache cache size to the full column length
00468     // and cause the full column to be cached in memory, if
00469     // any value of the column is used. In case of out-of-memory,
00470     // it will automatically fall-back on the smaller cache size.
00471     // Slurping the column is to be considered as a work-around for the
00472     // Table i/o code, which uses BucketCache and performs extremely bad
00473     // for random access. Slurping is useful when iterating non-sequentially
00474     // an MS or parts of an MS, it is not tested with multiple MSs.
00475     virtual void slurp () const;
00476 
00477     // Get the spw, start  and nchan for all the ms's is this Visiter that
00478     // match the frequecy "freqstart-freqStep" and "freqEnd+freqStep" range
00479     // Can help in doing channel selection above..
00480     // freqFrame is the frame the caller frequency values are in (freqStart and freqEnd)
00481     // These will be converted to the frame of the selected spw to match
00482 
00483 //    virtual void getSpwInFreqRange (Block<Vector<Int> > & spw,
00484 //                                    Block<Vector<Int> > & start,
00485 //                                    Block<Vector<Int> > & nchan,
00486 //                                    Double freqStart, Double freqEnd,
00487 //                                    Double freqStep, MFrequency::Types freqFrame = MFrequency::LSRK) const;
00488 
00489     // Get the range of frequency convered by the selected data in the frame requested
00490 
00491 //    virtual void getFreqInSpwRange(Double& freqStart, Double& freqEnd, MFrequency::Types freqframe = MFrequency::LSRK) const;
00492 
00493     // Access the current ROMSColumns object in MSIter
00494     virtual const vi::SubtableColumns & subtableColumns () const;
00495 
00496     // get back the selected spectral windows and spectral channels for
00497     // current ms
00498 
00499     virtual const SpectralWindowChannels & getSpectralWindowChannels (Int msId, Int spectralWindowId) const;
00500 
00501     //assign a VisImagingWeight object to this iterator
00502     virtual void useImagingWeight (const VisImagingWeight & imWgt);
00503     //return number  of Ant
00504     virtual Int nAntennas () const;
00505     //Return number of rows in all selected ms's
00506     virtual Int nRowsViWillSweep () const;
00507 
00508     // Return number of spws, polids, ddids
00509 
00510     virtual Int nSpectralWindows () const;
00511     virtual Int nPolarizations () const;
00512     virtual Int nDataDescriptionIds () const;
00513 
00514     virtual MEpoch getEpoch () const;
00515     MFrequency::Types getObservatoryFrequencyType () const; //???
00516     MPosition getObservatoryPosition () const;
00517     Vector<Float> getReceptor0Angle ();
00518 
00519     // Write/modify the flags in the data.
00520     // This will flag all channels in the original data that contributed to
00521     // the output channel in the case of channel averaging.
00522     // All polarizations have the same flag value.
00523     virtual void writeFlag (const Matrix<Bool> & flag);
00524 
00525     // Write/modify the flags in the data.
00526     // This writes the flags as found in the MS, Cube (npol,nchan,nrow),
00527     // where nrow is the number of rows in the current iteration (given by
00528     // nRow ()).
00529     virtual void writeFlag (const Cube<Bool> & flag);
00530 
00531     // Write/modify the flag row column; dimension Vector (nrow)
00532     virtual void writeFlagRow (const Vector<Bool> & rowflags);
00533 
00534     void writeFlagCategory(const Array<Bool>& fc);
00535 
00536     // Write/modify the visibilities.
00537     // This is possibly only for a 'reference' MS which has a new DATA column.
00538     // The first axis of the matrix should equal the selected number of channels
00539     // in the original MS.
00540     // If the MS does not contain all polarizations, only the parallel
00541     // hand polarizations are used.
00542 //    void writeVisCorrected (const Matrix<CStokesVector> & visibilityStokes);
00543 //    void writeVisModel (const Matrix<CStokesVector> & visibilityStokes);
00544 //    void writeVisObserved (const Matrix<CStokesVector> & visibilityStokes);
00545 
00546     // Write/modify the visibilities
00547     // This writes the data as found in the MS, Cube (npol,nchan,nrow).
00548     virtual void writeVisCorrected (const Cube<Complex> & vis);
00549     virtual void writeVisModel (const Cube<Complex> & vis);
00550     virtual void writeVisObserved (const Cube<Complex> & vis);
00551 
00552     // Write/modify the weights
00553     virtual void writeWeight (const Matrix<Float> & wt);
00554 
00555     // Write/modify the weightMat
00556     //virtual void writeWeightMat (const Matrix<Float> & wtmat);
00557 
00558     // Write/modify the weightSpectrum
00559     virtual void writeWeightSpectrum (const Cube<Float> & wtsp);
00560 
00561     // Write/modify the Sigma
00562     virtual void writeSigma (const Matrix<Float> & sig);
00563 
00564     // Write/modify the ncorr x nrow SigmaMat.
00565     //virtual void writeSigmaMat (const Matrix<Float> & sigmat);
00566 
00567     virtual void writeModel(const RecordInterface& rec, Bool iscomponentlist=True,
00568                             Bool incremental=False);
00569 
00570     virtual void writeBackChanges (VisBuffer2 *);
00571 
00572 protected:
00573 
00574     void addDataSelection (const MeasurementSet & ms);
00575 
00576     void allSpectralWindowsSelected (Vector<Int> & spectralWindows,
00577                                      Vector<Int> & nChannels) const; /*KLUGE*/
00578 
00579     void attachColumnsSafe (const Table & t);
00580 
00581     // attach the column objects to the currently selected table
00582 
00583     virtual void attachColumns (const Table & t);
00584 
00585     // returns the table, to which columns are attached,
00586     // can be overridden in derived classes
00587 
00588     virtual const Table attachTable () const;
00589 
00590     virtual void applyPendingChanges ();
00591 
00592     // set the iteration state
00593 
00594     virtual void configureNewChunk ();
00595 
00596     // set the currently selected table
00597 
00598     virtual void configureNewSubchunk ();
00599 
00600     const ChannelSelector *
00601     createDefaultChannelSelector (Double time, Int msId, Int spectralWindowId);
00602 
00603     virtual const vi::ChannelSelector * determineChannelSelection (Double time);
00604 
00605     Slice findChannelsInRange (Double lowerFrequency, Double upperFrequency,
00606                                const vi::SpectralWindowChannels & spectralWindowChannels);
00607 
00608     // Methods to get the data out of a table column according to whatever selection
00609     // criteria (e.g., slicing) is in effect.
00610 
00611     template <typename T>
00612     void getColumnRows (const ROArrayColumn<T> & column, Array<T> & array) const;
00613 
00614     template <typename T>
00615     void
00616     getColumnRowsMatrix (const ROArrayColumn<T> & column, Matrix<T> & array) const;
00617 
00618     template <typename T>
00619     void getColumnRows (const ROScalarColumn<T> & column, Vector<T> & array) const;
00620 
00621     Vector<Double> getFrequencies (Double time, Int frameOfReference) const;
00622     Vector<Double> getFrequencies (Double time, Int frameOfReference,
00623                                    Int spectralWindowId, Int msId) const; // helper method
00624 
00625     Vector<Int> getChannels (Double time, Int frameOfReference) const;
00626     Vector<Int> getCorrelations () const;
00627 
00628     Int getReportingFrameOfReference () const;
00629 
00630     // Returns the MS objects that this VI is iterating over.
00631 
00632     Vector <MeasurementSet> getMeasurementSets () const;
00633 
00634     // Provides access to the MS-derived values object
00635 
00636     const MSDerivedValues & getMsd () const; // for use by Async I/O *ONLY*
00637 
00638     // Get privileged (non-const) access to the containing ROVI
00639 
00640     VisibilityIterator2 * getViP () const;
00641 
00642 //    void getVisibilityAsStokes (Matrix<CStokesVector> & visibilityStokes,
00643 //                                const ROArrayColumn<Complex> & column) const;
00644 
00645     // Ctor auxiliary method
00646 
00647     virtual void initialize (const Block<MeasurementSet> & mss);
00648 
00649     // Returns true if MS Iterator is currently pointing to a selected
00650     // spectral window
00651 
00652     Bool isInASelectedSpectralWindow () const;
00653 
00654     // Creates a channel selection for the current subchunk based on the channel
00655     // or frequency selection made by the user.
00656 
00657     vi::ChannelSelector *
00658     makeChannelSelectorC (const FrequencySelection & selection,
00659                           Double time, Int msId, Int spectralWindowId,
00660                           Int polarizationId);
00661 
00662     vi::ChannelSelector *
00663     makeChannelSelectorF (const FrequencySelection & selection,
00664                           Double time, Int msId, Int spectralWindowId);
00665 
00666     MFrequency::Convert makeFrequencyConverter (Double time, Int otherFrameOfReference,
00667                                                 Bool toObservedFrame) const;
00668 
00669     // Allow access to the MSColumns object; for use by VisBuffer2Adapter *KLUGE*
00670 
00671     const ROMSColumns * msColumnsKluge () const;
00672 
00673     // Method to reset the VI back to the start.  Unlike the public version
00674     // there is a parameter to allow forcing the rewind even if the
00675     // MS Iter is already at the origin.
00676 
00677     virtual void originChunks (Bool forceRewind);
00678 
00679     // Advances the MS Iterator until it points at a spectral window
00680     // that is part of the frequency selection.
00681 
00682     void positionMsIterToASelectedSpectralWindow ();
00683 
00684     // Sets the default frequency reporting frame of reference.  This
00685     // affects the default frame for obtaining the frequencies in a
00686     // VisBuffer.
00687 
00688     void setReportingFrameOfReference (Int);
00689 
00690     // Adjusts the tile cache for some columns so that the cache size is
00691     // optimized for the current input state (e.g., a new data description).
00692 
00693     virtual void setTileCache ();
00694 
00695     // Throws exception if there is a pending (i.e., unapplied) change to
00696     // the VI's properties.  Called when the VI is advanced since the user
00697     // probably forgot to apply the changes.
00698 
00699     virtual void throwIfPendingChanges ();
00700 
00701 
00702     // Returns true if the named column uses a tiled data manager in the specified MS
00703 
00704     Bool usesTiledDataManager (const String & columnName, const MeasurementSet & ms) const;
00705 
00706 
00707 //    +========================|
00708 //    |                        |
00709 //    | Output Related Methods |
00710 //    |                        |
00711 //    +========================|
00712 
00713     // A BackWriter is a functor that will extract a piece of information out of its VisBuffer
00714     // argument and write it out using a "set" method on the supplied VisibilityIterator2.
00715     class BackWriter {
00716 
00717     public:
00718 
00719         virtual ~BackWriter () {}
00720 
00721         virtual void operator () (VisibilityIteratorImpl2 * vi, VisBuffer2 * vb) = 0;
00722 
00723     };
00724 
00725     // A simple BackWriterImpl2 uses a nullary accessor on a VisBuffer.
00726     template <typename Setter, typename Getter>
00727     class BackWriterImpl : public BackWriter {
00728     public:
00729 
00730         BackWriterImpl (Setter setter, Getter getter) : getter_p (getter), setter_p (setter) {}
00731         void operator () (VisibilityIteratorImpl2 * vi, VisBuffer2 * vb) {
00732             (vi ->* setter_p) ((vb ->* getter_p) ());
00733         }
00734 
00735     private:
00736 
00737         Getter getter_p;
00738         Setter setter_p;
00739     };
00740 
00741     // BackWriterImpl2 is slightly more complicated in that it uses a unary accessor.  The argument
00742     // to the unary accessor is a member of the VisibilityIterator2 DataColumn enumeration which
00743     // specifies which visibilty or visCube type is wanted (e.g., observed, model or corrected).
00744     template <typename Setter, typename Getter>
00745     class BackWriterImpl2 : public BackWriter {
00746     public:
00747 
00748         typedef VisibilityIteratorImpl2::DataColumn DataColumn;
00749 
00750         BackWriterImpl2 (Setter setter, Getter getter, DataColumn dc)
00751         : dataColumn_p (dc), getter_p (getter), setter_p (setter)
00752         {}
00753         void operator () (VisibilityIteratorImpl2 * vi, VisBuffer2 * vb) {
00754             (vi ->* setter_p) ((vb ->* getter_p) (), dataColumn_p);
00755         }
00756 
00757     private:
00758 
00759         DataColumn dataColumn_p;
00760         Getter getter_p;
00761         Setter setter_p;
00762     };
00763 
00764     // Backwriter(2) creation methods.  These methods make it fairly straightforward to create
00765     // a BackWriter object.
00766 
00767     template <typename Ret>
00768     static
00769     BackWriter *
00770     makeBackWriter (void (VisibilityIteratorImpl2::* setter) (Ret), Ret (VisBuffer2::* getter) () const) {
00771         return new BackWriterImpl <void (VisibilityIteratorImpl2:: *) (Ret),
00772                                    Ret (VisBuffer2:: *) () const >
00773         (setter, getter);
00774     }
00775 
00776     template <typename Ret>
00777     static
00778     BackWriter *
00779     makeBackWriter2 (void (VisibilityIteratorImpl2::* setter) (Ret, VisibilityIteratorImpl2::DataColumn),
00780                      Ret (VisBuffer2::* getter) () const,
00781                      VisibilityIterator2::DataColumn dc) {
00782 
00783         // Define the Getter and Setter types
00784 
00785         typedef void (VisibilityIteratorImpl2::* Setter) (Ret, VisibilityIteratorImpl2::DataColumn);
00786         typedef Ret (VisBuffer2::* Getter) () const;
00787 
00788         return new BackWriterImpl2 < Setter, Getter> (setter, getter, dc);
00789     }
00790 
00791     void initializeBackWriters ();
00792 
00793     template <typename T>
00794     void putColumnRows (ArrayColumn<T> & column, const Array<T> & array);
00795 
00796     template <typename T>
00797     void putColumnRows (ArrayColumn<T> & column, const Matrix<T> & array);
00798 
00799     template <typename T>
00800     void putColumnRows (ScalarColumn<T> & column, const Vector <T> & array);
00801 
00802 //    void convertVisFromStokes (const Matrix<CStokesVector> & visibilityStokes,
00803 //                               Cube<Complex> & visCube);
00804 
00805     class Cache {
00806 
00807     public:
00808 
00809         Cache ();
00810 
00811         Cache & operator= (const Cache & other);
00812 
00813         void flush ();
00814 
00815         MDirection         azel0_p;
00816         Double             azel0Time_p;
00817         Vector<MDirection> azel_p;
00818         Double             azelTime_p;
00819         Vector<uInt>       chunkRowIds_p; // Row numbers of underlying MS; used to map
00820                                           // form chunk rows to MS rows.  See rowIds method.
00821         Vector<Float>      feedpa_p;
00822         Double             feedpaTime_p;
00823         Double             hourang_p;
00824         Double             hourangTime_p;
00825         Matrix<Float>      imagingWeight_p;
00826         Bool               msHasFC_p;   // Does the current MS have a valid FLAG_CATEGORY?
00827         Bool               msHasWtSp_p; // Does the current MS have a valid WEIGHT_SPECTRUM?
00828         Float              parang0_p;
00829         Double             parang0Time_p;
00830         Vector<Float>      parang_p;
00831         Double             parangTime_p;
00832     };
00833 
00834     class PendingChanges {
00835 
00836     public:
00837 
00838         PendingChanges ();
00839         ~PendingChanges ();
00840 
00841         PendingChanges * clone () const;
00842         Bool empty () const;
00843 
00844         pair<Bool, FrequencySelections *> popFrequencySelections (); // yields ownership
00845         pair<Bool, Double> popInterval ();
00846         pair<Bool, Int> popNRowBlocking ();
00847 
00848         void setFrequencySelections (FrequencySelections *); // takes ownership
00849         void setInterval (Double);
00850         void setNRowBlocking (Int);
00851 
00852     private:
00853 
00854         enum {Empty = -1};
00855 
00856         FrequencySelections * frequencySelections_p;
00857         Bool frequencySelectionsPending_p;
00858         Double interval_p;
00859         Int nRowBlocking_p;
00860     };
00861 
00862     typedef Vector <MeasurementSet> MeasurementSets;
00863 
00864     class RowBounds {
00865     public:
00866 
00867         RowBounds () : chunkNRows_p (-1), subchunkBegin_p (-1),
00868                        subchunkEnd_p (-1), subchunkNRows_p (-1),
00869                        subchunkRows_p (0, 0),
00870                        timeMax_p (-1), timeMin_p (-1)
00871         {}
00872 
00873         Int chunkNRows_p;      // last row in current chunk
00874         Int subchunkBegin_p; // first row in current subchunk
00875         Int subchunkEnd_p;   // last row in current subchunk
00876         Int subchunkNRows_p; // # rows in subchunk
00877         RefRows subchunkRows_p; // subchunk's table row numbers
00878         Vector<Double> times_p; // times for each row in the chunk
00879         Double timeMax_p;       // max timestamp in the chunk
00880         Double timeMin_p;       // min timechunk in the chunk
00881 
00882     };
00883 
00884     std::map <VisBufferComponent2, BackWriter *> backWriters_p;
00885     mutable Cache                 cache_p; // general copllection of cached values
00886     const ChannelSelector *       channelSelector_p; // [use] current channel selector for this MS & Spw
00887     ChannelSelectorCache *        channelSelectorCache_p; // [own] cache of recently used channel selectors
00888     ViColumns2                    columns_p; // The main columns for the current MS
00889     Bool                          floatDataFound_p; // True if a float data column was found
00890     FrequencySelections *         frequencySelections_p; // [own] Current frequency selection
00891     VisImagingWeight              imwgt_p;    // object to calculate imaging weight
00892     MeasurementSets               measurementSets_p; // [use]
00893     Bool                          more_p; // True if more data in this chunk
00894     Int                           msIndex_p; // array index of current MS
00895     Bool                          msIterAtOrigin_p; // True if MS Iter is a start of first MS
00896     MSIter                        msIter_p; // MS Iter that underlies the VI (sweeps in chunks)
00897     mutable MSDerivedValues       msd_p; // Helper class holding MS derived values.
00898     Int                           nPolarizations_p;
00899     Int                           nRowBlocking_p; // suggested # of rows in a subchunk
00900     PendingChanges                pendingChanges_p; // holds pending changes to VI properties
00901     Int                           reportingFrame_p; // default frequency reporting (not selecting)
00902                                                     // frame of reference
00903     RowBounds                     rowBounds_p; // Subchunk row management object (see above)
00904     Block<Int>                    sortColumns_p; // sort columns specified when creating VI
00905     mutable SpectralWindowChannelsCache * spectralWindowChannelsCache_p; // [own] Info about spectral windows
00906     Subchunk                      subchunk_p; // (chunkN #, subchunk #) pair
00907     SubtableColumns *             subtableColumns_p; // [own] Allows const access to MS's subtable columns
00908     Vector<Bool>                  tileCacheIsSet_p; // Flags indicating whether tile cache set for this column
00909     Double                        timeInterval_p;
00910     VisBuffer2 *                  vb_p;  // [own] VisBuffer attached to this VI
00911     VisibilityIterator2 *         vi_p; // [use] Containing VI
00912 };
00913 
00914 } // end namespace vi
00915 
00916 } //# NAMESPACE CASA - END
00917 
00918 #endif
00919