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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1