LCOV - code coverage report
Current view: top level - msvis/MSVis - VisibilityIteratorImpl2.h (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 15 16 93.8 %
Date: 2023-10-25 08:47:59 Functions: 20 23 87.0 %

          Line data    Source code
       1             : // -*- mode: c++ -*-
       2             : //# VisibilityIterator.h: Step through the MeasurementEquation by visibility
       3             : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
       4             : //# Associated Universities, Inc. Washington DC, USA.
       5             : //#
       6             : //# This library is free software; you can redistribute it and/or modify it
       7             : //# under the terms of the GNU Library General Public License as published by
       8             : //# the Free Software Foundation; either version 2 of the License, or (at your
       9             : //# option) any later version.
      10             : //#
      11             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      12             : //# ANY WARRANTY; without even the Implied warranty of MERCHANTABILITY or
      13             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      14             : //# License for more details.
      15             : //#
      16             : //# You should have received a copy of the GNU Library General Public License
      17             : //# along with this library; if not, write to the Free Software Foundation,
      18             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      19             : //#
      20             : //# Correspondence concerning AIPS++ should be addressed as follows:
      21             : //#        Internet email: aips2-request@nrao.edu.
      22             : //#        Postal address: AIPS++ Project Office
      23             : //#                        National Radio Astronomy Observatory
      24             : //#                        520 Edgemont Road
      25             : //#                        Charlottesville, VA 22903-2475 USA
      26             : //#
      27             : //# $Id: VisibilityIterator2.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $
      28             : 
      29             : #ifndef MSVIS_VISIBILITYITERATORIMPL2_H
      30             : #define MSVIS_VISIBILITYITERATORIMPL2_H
      31             : 
      32             : #include <casacore/casa/aips.h>
      33             : #include <casacore/ms/MSOper/MSDerivedValues.h>
      34             : #include <msvis/MSVis/ViImplementation2.h>
      35             : #include <msvis/MSVis/ViColumns2.h>
      36             : #include <casacore/tables/Tables/ArrayColumn.h>
      37             : #include <casacore/tables/Tables/ScalarColumn.h>
      38             : #include <msvis/MSVis/VisImagingWeight.h>
      39             : #include <msvis/MSVis/VisBuffer2.h>
      40             : 
      41             : #include <tuple>
      42             : #include <map>
      43             : #include <vector>
      44             : #include <mutex>
      45             : #include <memory>
      46             : 
      47             : namespace casacore{
      48             : 
      49             : template <typename T> class ArrayColumn;
      50             : template <typename T> class CountedPtr;
      51             : class VisModelDataI;
      52             : template <typename T> class ArrayColumn;
      53             : template <typename T, Int N> class RigidVector;
      54             : template <typename T, Int N> class SquareMatrix;
      55             : }
      56             : 
      57             : namespace casa { //# NAMESPACE CASA - BEGIN
      58             : 
      59             : class MsIter;
      60             : class VisModelDataI;
      61             : 
      62             : namespace vi {
      63             : 
      64             : //# forward decl
      65             : 
      66             : class VisBuffer2;
      67             : 
      68             : class ChannelSelector;
      69             : class ChannelSelectorCache;
      70             : class PointingDirectionCache;
      71             : class PointingSource;
      72             : class SpectralWindowChannelsCache;
      73             : class SpectralWindowChannels;
      74             : class SubtableColumns;
      75             : 
      76             : class VisibilityIteratorImpl2 : public ViImplementation2 {
      77             : 
      78             :         friend class AsyncEnabler;
      79             :         friend class ViImplAsync2;
      80             :         friend class VisibilityIterator2;
      81             :         friend class VLAT; // allow VI lookahead thread class to access protected functions
      82             :         friend class VisBuffer2Adapter;
      83             :         // VLAT should not access private parts, especially variables
      84             : 
      85             : public:
      86             : 
      87             :         using DataColumn = VisibilityIterator2::DataColumn;
      88             :         using ChannelInfo = std::tuple<
      89             :             casacore::Vector<casacore::Int>, casacore::Vector<casacore::Int>,
      90             :             casacore::Vector<casacore::Int>, casacore::Vector<casacore::Int>
      91             :         >;
      92             : 
      93             :         // Default constructor - useful only to assign another iterator later
      94             :         ////VisibilityIteratorImpl2 ();
      95             : 
      96             :         // Construct from an casacore::MS and a casacore::Block of casacore::MS
      97             :         // column enums specifying the iteration order.  If no order is specified,
      98             :         // it uses the default sort order of MSIter, which is not necessarily the
      99             :         // raw order of ms!  The default ordering is ARRAY_ID, FIELD_ID,
     100             :         // DATA_DESC_ID, and TIME, but check MSIter.h to be sure.  These columns
     101             :         // will be added first if they are not specified.
     102             :         //
     103             :         // An optional timeInterval (in seconds) can be given to iterate through
     104             :         // chunks of time.  The default interval of 0 groups all times together.
     105             :         // Every 'chunk' of data contains all data within a certain time interval
     106             :         // and with identical values of the other iteration columns (e.g.
     107             :         // DATA_DESC_ID and FIELD_ID).  Using selectChannel (), a number of groups
     108             :         // of channels can be requested.  At present the channel group iteration
     109             :         // will always occur before the interval iteration.
     110             : //    VisibilityIteratorImpl (const casacore::MeasurementSet & ms,
     111             : //                                const casacore::Block<casacore::Int> & sortColumns,
     112             : //                                casacore::Double timeInterval = 0);
     113             : 
     114             :         // Same as above, but with the option of using the raw order of ms
     115             :         // (addDefaultSortCols=false).
     116             : //    VisibilityIteratorImpl (const casacore::MeasurementSet & ms,
     117             : //                                const casacore::Block<casacore::Int> & sortColumns, const casacore::Bool addDefaultSortCols,
     118             : //                                casacore::Double timeInterval = 0);
     119             : 
     120             :         // Same as previous constructors, but with multiple MSs to iterate over.
     121             : //    VisibilityIteratorImpl (const casacore::Block<casacore::MeasurementSet> & mss,
     122             : //                                const casacore::Block<casacore::Int> & sortColumns,
     123             : //                                casacore::Double timeInterval = 0);
     124             : 
     125             :     VisibilityIteratorImpl2(
     126             :         const casacore::Block<const casacore::MeasurementSet *> & mss,
     127             :         const SortColumns & sortColumns,
     128             :         casacore::Double timeInterval,
     129             :         casacore::Bool isWritable,
     130             :         casacore::Bool useMSIter2=false);
     131             : 
     132             :     // This constructor is similar to previous one but it allows to explicitely
     133             :     // define the sorting criteria used for chunk iteration and for subchunk
     134             :     // iteration. Also the criteria can be generic functions
     135             :     VisibilityIteratorImpl2(
     136             :         const casacore::Block<const casacore::MeasurementSet *> & mss,
     137             :         const SortColumns & chunkSortColumns,
     138             :         const SortColumns & subchunkSortColumns,
     139             :         bool isWritable);
     140             : 
     141             :         VisibilityIteratorImpl2(const VisibilityIteratorImpl2& vii);
     142             : 
     143             :         VisibilityIteratorImpl2 & operator=(const VisibilityIteratorImpl2& vii);
     144             : 
     145             :         VisibilityIteratorImpl2(VisibilityIteratorImpl2&& vii);
     146             : 
     147             :         VisibilityIteratorImpl2 & operator=(VisibilityIteratorImpl2&& vii);
     148             : 
     149             :         // Destructor
     150             : 
     151             :         virtual ~VisibilityIteratorImpl2();
     152             : 
     153             :         // Members
     154             : 
     155             :         std::unique_ptr<VisibilityIteratorImpl2> clone() const;
     156             : 
     157             :     // Set the scope of metadata, i.e., how long a given metadata is valid.
     158             :     // For instance, if ddIDScope = SubchunkScope, the ddId will be unique
     159             :     // within a subchunk.
     160             :     void setMetadataScope();
     161             : 
     162             :         // Report the the ViImplementation type
     163             :         //  TBD:  indicate writable?
     164             :         virtual casacore::String
     165          44 :         ViiType() const  override {
     166          44 :                 return casacore::String("DiskIO()");
     167             :         };
     168             : 
     169             :         virtual casacore::Bool
     170             :         isWritable() const override;
     171             : 
     172             :         // Reset iterator to origin/start of data (of current chunk)
     173             :         virtual void
     174             :         origin() override;
     175             : 
     176             :         // Reset iterator to true start of data (first chunk)
     177             :         virtual void
     178             :         originChunks();
     179             : 
     180             :         // Return the time interval (in seconds) used for iteration.  This is not
     181             :         // the same as the INTERVAL column.
     182             : 
     183             :         virtual casacore::Double
     184             :         getInterval() const override;
     185             : 
     186             :         // Set or reset the time interval (in seconds) to use for iteration.  You
     187             :         // should call originChunks() to reset the iteration after calling this.
     188             :         virtual void
     189             :         setInterval(casacore::Double timeInterval) override;
     190             : 
     191             :     // Set the 'blocking' size for returning data. If set to 0 (the default),
     192             :     // the chunk will be grouped in subchunks using the subchunk sorting functions
     193             :     // (which default to group by unique timestamp.
     194             :     // With blocking set, up to nRows can be returned in one go.
     195             :     // The chunk size determines the actual maximum.
     196             :     virtual void
     197             :     setRowBlocking(casacore::rownr_t nRows = 0) override;
     198             : 
     199             :         virtual casacore::rownr_t
     200             :         getRowBlocking() const override;
     201             : 
     202             :         virtual casacore::Bool
     203             :         existsColumn(VisBufferComponent2 id) const override;
     204             : 
     205             :         // Return false if no more data (in current chunk)
     206             :         virtual casacore::Bool
     207             :         more() const override;
     208             : 
     209             :         virtual Subchunk
     210             :         getSubchunkId() const override;
     211             : 
     212             :         virtual const SortColumns &
     213             :         getSortColumns() const override;
     214             : 
     215             :         virtual void
     216             :         setFrequencySelections(const FrequencySelections & selection) override;
     217             : 
     218             :         // Return false if no more 'Chunks' of data left
     219             :         virtual casacore::Bool
     220             :         moreChunks() const override;
     221             : 
     222             :         virtual void
     223             :         result(casacore::Record& res) const override;
     224             : 
     225             :         // Check if ms has change since last iteration
     226             : 
     227             :         virtual casacore::Bool
     228             :         isNewArrayId() const override;
     229             : 
     230             :         virtual casacore::Bool
     231             :         isNewFieldId() const override;
     232             : 
     233             :         virtual casacore::Bool
     234             :         isNewMs() const override;
     235             : 
     236             :         virtual casacore::Bool
     237             :         isNewSpectralWindow() const override;
     238             : 
     239             :         virtual casacore::Int
     240             :         msId() const override;
     241             : 
     242             :         virtual casacore::Int
     243             :         getNMs() const override;
     244             : 
     245             :         virtual VisBuffer2 *
     246             :         getVisBuffer() const override;
     247             : 
     248             :         //reference to actual ms in interator
     249             :         virtual const casacore::MeasurementSet &
     250             :         ms() const override;
     251             : 
     252             :         // Name of the MS in the interator
     253             :         virtual casacore::String
     254             :         msName() const override;
     255             : 
     256             :         // advance the iteration
     257             :         virtual void
     258             :         next() override;
     259             : 
     260             :         // Advance to the next Chunk of data
     261             :         virtual void
     262             :         nextChunk() override;
     263             : 
     264             :         // Report Name of slowest column that changes at end of current iteration
     265             :         virtual casacore::String
     266       20259 :         keyChange() const  override {
     267       20259 :                 return msIter_p->keyChange();
     268             :         };
     269             : 
     270             :         // Return antenna1
     271             :         virtual void
     272             :         antenna1(casacore::Vector<casacore::Int> & ant1) const override;
     273             : 
     274             :         // Return antenna2
     275             :         virtual void
     276             :         antenna2(casacore::Vector<casacore::Int> & ant2) const override;
     277             : 
     278             :         // Return feed1
     279             :         virtual void
     280             :         feed1(casacore::Vector<casacore::Int> & fd1) const override;
     281             : 
     282             :         // Return feed2
     283             :         virtual void
     284             :         feed2(casacore::Vector<casacore::Int> & fd2) const override;
     285             : 
     286             :         // Return feed configuration matrix for specified antenna
     287             :         void
     288             :         jonesC(
     289             :                 casacore::Vector<casacore::SquareMatrix<casacore::Complex, 2> > & cjones) const override;
     290             : 
     291             :         // Return receptor angles for all antennae and feeds First axis of the cube
     292             :         // is a receptor number, 2nd is antennaId, 3rd is feedId Note: the method is
     293             :         // intended to provide an access to MSIter::receptorAngles for VisBuffer in
     294             :         // the multi-feed case. It may be worth to change the interface of feed_pa
     295             :         // to return the information for all feeds.
     296             :         virtual const casacore::Cube<casacore::Double> &
     297             :         receptorAngles() const override;
     298             : 
     299             :         // return a string mount identifier for each antenna
     300             :         virtual const casacore::Vector<casacore::String> &
     301             :         antennaMounts() const override;
     302             : 
     303             :         // Return a cube containing pairs of coordinate offsets for each
     304             :         // receptor of each feed (values are in radians, coordinate system is fixed
     305             :         // with antenna and is the same one as used to define the BEAM_OFFSET
     306             :         // parameter in the feed table). The cube axes are receptor, antenna, feed.
     307             :         virtual const casacore::Cube<casacore::RigidVector<casacore::Double, 2> > &
     308             :         getBeamOffsets() const override;
     309             : 
     310             :         virtual std::pair<bool, casacore::MDirection>
     311             :         getPointingAngle(int antenna, double time) const override;
     312             : 
     313             :         // true if all elements of the cube returned by getBeamOffsets are zero
     314             :         virtual casacore::Bool
     315             :         allBeamOffsetsZero() const override;
     316             : 
     317             :         // Return feed parallactic angles casacore::Vector (nant) (1 feed/ant)
     318             :         virtual const casacore::Vector<casacore::Float> &
     319             :         feed_pa(casacore::Double time) const override;
     320             : 
     321             :         // Return nominal parallactic angle at specified time
     322             :         // (does not include feed position angle offset--see feed_pa)
     323             :         // A global value for all antennas (e.g., small array)
     324             :         virtual const casacore::Float &
     325             :         parang0(casacore::Double time) const override;
     326             : 
     327             :         // Per antenna:
     328             :         virtual const casacore::Vector<casacore::Float> &
     329             :         parang(casacore::Double time) const override;
     330             : 
     331             :         // Return the antenna AZ/EL casacore::Vector(nant)
     332             :         virtual casacore::MDirection
     333             :         azel0(casacore::Double time) const override;
     334             : 
     335             :         virtual const casacore::Vector<casacore::MDirection> &
     336             :         azel(casacore::Double time) const override;
     337             : 
     338             :         // Return the hour angle for the specified time
     339             :         virtual casacore::Double
     340             :         hourang(casacore::Double time) const override;
     341             : 
     342             :         // Return the current FieldId
     343             :         virtual void
     344             :         fieldIds(casacore::Vector<casacore::Int>&) const override;
     345             : 
     346             :         // Return the current ArrayId
     347             :         virtual void
     348             :         arrayIds(casacore::Vector<casacore::Int>&) const override;
     349             : 
     350             :         // Return the current Field Name
     351             :         virtual casacore::String
     352             :         fieldName() const override;
     353             : 
     354             :         // Return the current Source Name
     355             :         virtual casacore::String
     356             :         sourceName() const override;
     357             : 
     358             :     // Return flag for each polarization, channel and row
     359             :     virtual void
     360             :     flag(casacore::Cube<casacore::Bool> & flags) const override;
     361             : 
     362             :     // Return flag for each polarization, channel and row
     363             :     // Supports returning a vector of cubes.
     364             :     // If VisBuffer contains rows with different number of channels
     365             :     // each of the cubes will have a different shape
     366             :     virtual void
     367             :     flag(casacore::Vector<casacore::Cube<casacore::Bool>> & flags) const override;
     368             : 
     369             :         // Return flag for each channel & row
     370             :         virtual void
     371             :         flag(casacore::Matrix<casacore::Bool> & flags) const override;
     372             : 
     373             :         // Determine whether FLAG_CATEGORY is valid.
     374             :         casacore::Bool
     375             :         flagCategoryExists() const override;
     376             : 
     377             :         // Return flags for each polarization, channel, category, and row.
     378             :         virtual void
     379             :         flagCategory(casacore::Array<casacore::Bool> & flagCategories) const override;
     380             : 
     381             :         // Return row flag
     382             :         virtual void
     383             :         flagRow(casacore::Vector<casacore::Bool> & rowflags) const override;
     384             : 
     385             :         // Return scan number
     386             :         virtual void
     387             :         scan(casacore::Vector<casacore::Int> & scans) const override;
     388             : 
     389             :         // Return the OBSERVATION_IDs
     390             :         virtual void
     391             :         observationId(casacore::Vector<casacore::Int> & obsids) const override;
     392             : 
     393             :         // Return the PROCESSOR_IDs
     394             :         virtual void
     395             :         processorId(casacore::Vector<casacore::Int> & procids) const override;
     396             : 
     397             :         // Return the STATE_IDs
     398             :         virtual void
     399             :         stateId(casacore::Vector<casacore::Int> & stateids) const override;
     400             : 
     401             :         // Return the current phase center as an MDirection
     402             :         virtual const casacore::MDirection &
     403             :         phaseCenter() const override;
     404             : 
     405             :         // Return frame for polarization(returns PolFrame enum)
     406             :         virtual casacore::Int
     407             :         polFrame() const override;
     408             : 
     409             :         // Return the correlation type (returns casacore::Stokes enums)
     410             :         virtual void
     411             :         corrType(casacore::Vector<casacore::Int> & corrTypes) const override;
     412             : 
     413             :     // Return sigma
     414             :     virtual void
     415             :     sigma(casacore::Matrix<casacore::Float> & sig) const override;
     416             : 
     417             :     // Return sigma
     418             :     // Supports returning a vector of cubes.
     419             :     // If VisBuffer contains rows with different number of channels
     420             :     // each of the cubes will have a different shape
     421             :     virtual void
     422             :     sigma(casacore::Vector<casacore::Matrix<casacore::Float>> & sig) const override;
     423             : 
     424             :     // Return spw Ids for each row of the current iteration
     425             :     virtual void
     426             :     spectralWindows(casacore::Vector<casacore::Int> & spws) const override;
     427             : 
     428             :     // Return polarization Ids for each row of the current iteration
     429             :     virtual void
     430             :     polarizationIds(casacore::Vector<casacore::Int> & polIds) const override;
     431             : 
     432             :         // Return current Polarization Id
     433             :         virtual casacore::Int
     434             :         polarizationId() const override;
     435             : 
     436             :         // Return current DataDescription Id
     437             :         virtual casacore::Int
     438             :         dataDescriptionId() const override;
     439             : 
     440             :     // Return ddIds for each row of the current iteration
     441             :     virtual void
     442             :     dataDescriptionIds(casacore::Vector<casacore::Int> & ddis) const override;
     443             : 
     444             :         // Return MJD midpoint of interval.
     445             :         virtual void
     446             :         time(casacore::Vector<casacore::Double> & t) const override;
     447             : 
     448             :         // Return MJD centroid of interval.
     449             :         virtual void
     450             :         timeCentroid(casacore::Vector<casacore::Double> & t) const override;
     451             : 
     452             :         // Return nominal time interval
     453             :         virtual void
     454             :         timeInterval(casacore::Vector<casacore::Double> & ti) const override;
     455             : 
     456             :         // Return actual time interval
     457             :         virtual void
     458             :         exposure(casacore::Vector<casacore::Double> & expo) const override;
     459             : 
     460             :     // Return the visibilities as found in the casacore::MS,
     461             :     // casacore::Cube(npol,nchan,nrow).
     462             :     virtual void
     463             :     visibilityCorrected(casacore::Cube<casacore::Complex> & vis) const override;
     464             : 
     465             :     // Return the corrected visibilities
     466             :     // Supports returning a vector of cubes.
     467             :     // If VisBuffer contains rows with different number of channels
     468             :     // each of the cubes will have a different shape
     469             :     virtual void
     470             :     visibilityCorrected (casacore::Vector<casacore::Cube<casacore::Complex>> & vis) const override;
     471             : 
     472             :     // Return the observed visibilities
     473             :     virtual void
     474             :     visibilityObserved(casacore::Cube<casacore::Complex> & vis) const override;
     475             : 
     476             :     // Return the observed visibilities
     477             :     // Supports returning a vector of cubes.
     478             :     // If VisBuffer contains rows with different number of channels
     479             :     // each of the cubes will have a different shape
     480             :     virtual void
     481             :     visibilityObserved(casacore::Vector<casacore::Cube<casacore::Complex>> & vis) const override;
     482             : 
     483             :     // Return the model visibilities
     484             :     virtual void
     485             :     visibilityModel(casacore::Cube<casacore::Complex> & vis) const override;
     486             : 
     487             :     // Return the model visibilities
     488             :     // Supports returning a vector of cubes.
     489             :     // If VisBuffer contains rows with different number of channels
     490             :     // each of the cubes will have a different shape
     491             :     virtual void
     492             :     visibilityModel(casacore::Vector<casacore::Cube<casacore::Complex>> & vis) const override;
     493             : 
     494             :         // This will return all selected spwids for each ms attached with this iterator
     495             :         virtual casacore::Vector<casacore::Vector<casacore::Int> > getAllSelectedSpws() const;
     496             : 
     497             :     // Return FLOAT_DATA as a casacore::Cube(npol, nchan, nrow) if found in the
     498             :     // MS.
     499             :     virtual void
     500             :     floatData(casacore::Cube<casacore::Float> & fcube) const override;
     501             : 
     502             :     // Return FLOAT_DATA as a casacore::Cube(npol, nchan, nrow) if found in the
     503             :     // MS.
     504             :     // Supports returning a vector of cubes.
     505             :     // If VisBuffer contains rows with different number of channels
     506             :     // each of the cubes will have a different shape
     507             :     virtual void
     508             :     floatData(casacore::Vector<casacore::Cube<casacore::Float>> & fcubes) const override;
     509             : 
     510             :         // Return the visibility 4-vector of polarizations for each channel.  If the
     511             :         // casacore::MS doesn't contain all polarizations, it is assumed it contains
     512             :         // one or two parallel hand polarizations.
     513             : 
     514             : //    virtual void visibilityCorrected(casacore::Matrix<CStokesVector> & vis) const;
     515             : //    virtual void visibilityModel(casacore::Matrix<CStokesVector> & vis) const;
     516             : //    virtual void visibilityObserved(casacore::Matrix<CStokesVector> & vis) const;
     517             : 
     518             :         // Return the shape of the visibility Cube
     519             :         virtual casacore::IPosition
     520             :         visibilityShape() const override;
     521             : 
     522             :         // Return u,v and w (in meters)
     523             :         virtual void
     524             :         uvw(casacore::Matrix<casacore::Double> & uvwmat) const override;
     525             : 
     526             :     // Return weight
     527             :     virtual void
     528             :     weight(casacore::Matrix<casacore::Float> & wt) const override;
     529             : 
     530             :     // Return weight
     531             :     // Supports returning a vector of cubes.
     532             :     // If VisBuffer contains rows with different number of channels
     533             :     // each of the cubes will have a different shape
     534             :     virtual void
     535             :     weight(casacore::Vector<casacore::Matrix<casacore::Float>> & wt) const override;
     536             : 
     537             :         // Determine whether WEIGHT_SPECTRUM exists.
     538             :         casacore::Bool
     539             :         weightSpectrumExists() const override;
     540             : 
     541             :         // Determine whether SIGMA_SPECTRUM exists.
     542             :         casacore::Bool
     543             :         sigmaSpectrumExists() const override;
     544             : 
     545             :     // Return weightspectrum(a weight for each channel)
     546             :     virtual void
     547             :     weightSpectrum(casacore::Cube<casacore::Float> & wtsp) const override;
     548             : 
     549             :     // Return weightspectrum(a weight for each channel)
     550             :     // Supports returning a vector of cubes.
     551             :     // If VisBuffer contains rows with different number of channels
     552             :     // each of the cubes will have a different shape
     553             :     virtual void
     554             :     weightSpectrum(casacore::Vector<casacore::Cube<casacore::Float>> & wtsp) const override;
     555             : 
     556             :     // Return sigmaspectrum(a sigma for each channel)
     557             :     virtual void
     558             :     sigmaSpectrum(casacore::Cube<casacore::Float> & sigsp) const override;
     559             : 
     560             :     // Return sigmaspectrum(a sigma for each channel)
     561             :     // Supports returning a vector of cubes.
     562             :     // If VisBuffer contains rows with different number of channels
     563             :     // each of the cubes will have a different shape
     564             :     virtual void
     565             :     sigmaSpectrum(casacore::Vector<casacore::Cube<casacore::Float>> & sigsp) const override;
     566             : 
     567             :         virtual void
     568             :         setWeightScaling(casacore::CountedPtr<WeightScaling> weightscaling) override;
     569             : 
     570             :         virtual casacore::CountedPtr<WeightScaling>
     571             :         getWeightScaling() const override;
     572             : 
     573             :         virtual casacore::Bool
     574             :         hasWeightScaling() const override;
     575             : 
     576             :         // Return imaging weight (a weight for each channel)
     577             :         //virtual casacore::Matrix<casacore::Float> & imagingWeight(casacore::Matrix<casacore::Float> & wt) const;
     578             :         const VisImagingWeight &
     579             :         getImagingWeightGenerator() const override;
     580             : 
     581             :         // Return true if FieldId/Source has changed since last iteration
     582             :         virtual casacore::Bool
     583             :         newFieldId() const;
     584             : 
     585             :         // Return true if arrayID has changed since last iteration
     586             :         virtual casacore::Bool
     587             :         newArrayId() const;
     588             : 
     589             :         // Return true if SpectralWindow has changed since last iteration
     590             :         virtual casacore::Bool
     591             :         newSpectralWindow() const;
     592             : 
     593             :     // Return the number of rows in the current iteration
     594             :     virtual casacore::rownr_t
     595             :     nRows() const override;
     596             : 
     597             :     // Return the number of distinct array/cube shapes in the current iteration
     598             :     virtual casacore::rownr_t
     599             :     nShapes() const override;
     600             : 
     601             :     // Return the number of rows for each distinct array/cube shapes in the current iteration
     602             :     virtual const casacore::Vector<casacore::rownr_t>& 
     603             :     nRowsPerShape () const override;
     604             : 
     605             :     // Return the number of channels for each distinct array/cube shapes in the current iteration
     606             :     virtual const casacore::Vector<casacore::Int>& 
     607             :     nChannelsPerShape () const override;
     608             : 
     609             :     // Return the number of correlations for each distinct array/cube shapes in the current iteration
     610             :     virtual const casacore::Vector<casacore::Int>& 
     611             :     nCorrelationsPerShape () const override;
     612             : 
     613             :         // Return the row ids as from the original root table. This is useful
     614             :         // to find correspondance between a given row in this iteration to the
     615             :         // original ms row
     616             :         virtual void
     617             :         getRowIds(casacore::Vector<casacore::rownr_t> & rowids) const override;
     618             : 
     619             :         // Return the numbers of rows in the current chunk
     620             :         virtual casacore::rownr_t
     621             :         nRowsInChunk() const override;
     622             : 
     623             :     // number of unique time stamps in chunk
     624             :     virtual casacore::Int nTimes() const override;
     625             :  
     626             :         // Return the number of sub-intervals in the current chunk
     627             : 
     628             :         //virtual casacore::Int nSubInterval() const;
     629             : 
     630             :         // Call to use the slurp i/o method for all scalar columns. This will set
     631             :         // the casacore::BucketCache cache size to the full column length and cause
     632             :         // the full column to be cached in memory, if any value of the column is
     633             :         // used. In case of out-of-memory, it will automatically fall-back on the
     634             :         // smaller cache size.  Slurping the column is to be considered as a
     635             :         // work-around for the casacore::Table i/o code, which uses
     636             :         // casacore::BucketCache and performs extremely bad for random
     637             :         // access. Slurping is useful when iterating non-sequentially an
     638             :         // casacore::MS or parts of an casacore::MS, it is not tested with multiple
     639             :         // MSs.
     640             :         virtual void
     641             :         slurp() const override;
     642             : 
     643             :         // Get the spw, start and nchan for all the ms's is this Visiter that match
     644             :         // the frequecy "freqstart-freqStep" and "freqEnd+freqStep" range Can help
     645             :         // in doing channel selection above..  freqFrame is the frame the caller
     646             :         // frequency values are in(freqStart and freqEnd) These will be converted to
     647             :         // the frame of the selected spw to match
     648             : 
     649             : //    virtual void getSpwInFreqRange(casacore::Block<casacore::Vector<casacore::Int> > & spw,
     650             : //                                    casacore::Block<casacore::Vector<casacore::Int> > & start,
     651             : //                                    casacore::Block<casacore::Vector<casacore::Int> > & nchan,
     652             : //                                    casacore::Double freqStart, casacore::Double freqEnd,
     653             : //                                    casacore::Double freqStep, casacore::MFrequency::Types freqFrame = casacore::MFrequency::LSRK) const;
     654             : 
     655             :         // Get the range of frequency convered by the selected data in the frame
     656             :         // requested
     657             : 
     658             : //    virtual void getFreqInSpwRange(casacore::Double& freqStart, casacore::Double& freqEnd, casacore::MFrequency::Types freqframe = casacore::MFrequency::LSRK) const;
     659             : 
     660             :         // Access the current casacore::MSColumns object in MSIter
     661             :         virtual const vi::SubtableColumns &
     662             :         subtableColumns() const override;
     663             : 
     664             :         // get back the selected spectral windows and spectral channels for
     665             :         // current ms
     666             : 
     667             :         virtual const SpectralWindowChannels &
     668             :         getSpectralWindowChannels(
     669             :                 casacore::Int msId,
     670             :                 casacore::Int spectralWindowId) const override;
     671             : 
     672             :         //assign a VisImagingWeight object to this iterator
     673             :         virtual void
     674             :         useImagingWeight(const VisImagingWeight & imWgt) override;
     675             : 
     676             :         //return number  of Ant
     677             :         virtual casacore::Int
     678             :         nAntennas() const override;
     679             : 
     680             :         //Return number of rows in all selected ms's
     681             :         virtual casacore::rownr_t
     682             :         nRowsViWillSweep() const override;
     683             : 
     684             :         // Return number of spws, polids, ddids
     685             :         virtual casacore::Int
     686             :         nSpectralWindows() const override;
     687             : 
     688             :         virtual casacore::Int
     689             :         nPolarizationIds() const override;
     690             : 
     691             :         virtual casacore::Int
     692             :         nDataDescriptionIds() const override;
     693             : 
     694             :         virtual casacore::MEpoch
     695             :         getEpoch() const override;
     696             : 
     697             :         casacore::MFrequency::Types
     698             :         getObservatoryFrequencyType() const override; //???
     699             : 
     700             :         casacore::MPosition
     701             :         getObservatoryPosition() const override;
     702             : 
     703             :         casacore::Vector<casacore::Float>
     704             :         getReceptor0Angle() override;
     705             : 
     706             :         // Write/modify the flags in the data.  This will flag all channels in the
     707             :         // original data that contributed to the output channel in the case of
     708             :         // channel averaging.  All polarizations have the same flag value.
     709             : 
     710             : //    virtual void writeFlag(const casacore::Matrix<casacore::Bool> & flag);
     711             : 
     712             :         // Write/modify the flags in the data.
     713             : 
     714             :         // This writes the flags as found in the casacore::MS,
     715             :         // casacore::Cube(npol,nchan,nrow), where nrow is the number of rows in the
     716             :         // current iteration(given by nRow()).
     717             : 
     718             :         virtual void
     719             :         writeFlag(const casacore::Cube<casacore::Bool> & flag) override;
     720             : 
     721             :         // Write/modify the flag row column; dimension casacore::Vector(nrow)
     722             :         virtual void
     723             :         writeFlagRow(const casacore::Vector<casacore::Bool> & rowflags) override;
     724             : 
     725             :         void
     726             :         writeFlagCategory(const casacore::Array<casacore::Bool>& fc) override;
     727             : 
     728             :         // Write/modify the visibilities.  This is possibly only for a 'reference'
     729             :         // casacore::MS which has a new DATA column.  The first axis of the matrix
     730             :         // should equal the selected number of channels in the original MS.  If the
     731             :         // casacore::MS does not contain all polarizations, only the parallel hand
     732             :         // polarizations are used.
     733             : 
     734             : //    void writeVisCorrected(const casacore::Matrix<CStokesVector> & visibilityStokes);
     735             : //    void writeVisModel(const casacore::Matrix<CStokesVector> & visibilityStokes);
     736             : //    void writeVisObserved(const casacore::Matrix<CStokesVector> & visibilityStokes);
     737             : 
     738             :         // Write/modify the visibilities
     739             : 
     740             :         // This writes the data as found in the casacore::MS,
     741             :         // casacore::Cube(npol,nchan,nrow).
     742             :         virtual void
     743             :         writeVisCorrected(const casacore::Cube<casacore::Complex> & vis) override;
     744             : 
     745             :         virtual void
     746             :         writeVisModel(const casacore::Cube<casacore::Complex> & vis) override;
     747             : 
     748             :         virtual void
     749             :         writeVisObserved(const casacore::Cube<casacore::Complex> & vis) override;
     750             : 
     751             :         // Write/modify the weights
     752             :         virtual void
     753             :         writeWeight(const casacore::Matrix<casacore::Float> & wt) override;
     754             : 
     755             :         // Write/modify the weightMat
     756             :         //virtual void writeWeightMat(const casacore::Matrix<casacore::Float> & wtmat);
     757             : 
     758             :         // Write/modify the weightSpectrum
     759             :         virtual void
     760             :         writeWeightSpectrum(const casacore::Cube<casacore::Float> & wtsp) override;
     761             : 
     762             :         // Initialize the weightSpectrum column
     763             :         virtual void
     764             :         initWeightSpectrum(const casacore::Cube<casacore::Float> & weightSpectrum) override;
     765             : 
     766             :         // Write/modify the sigmaSpectrum
     767             :         virtual void
     768             :         writeSigmaSpectrum(const casacore::Cube<casacore::Float> & sigsp) override;
     769             : 
     770             :         // Initialize the sigmaSpectrum column
     771             :         virtual void
     772             :         initSigmaSpectrum(const casacore::Cube<casacore::Float> & sigmaSpectrum) override;
     773             : 
     774             :         // Write/modify the Sigma
     775             :         virtual void
     776             :         writeSigma(const casacore::Matrix<casacore::Float> & sig) override;
     777             : 
     778             :         // Write/modify the ncorr x nrow SigmaMat.
     779             :         //virtual void writeSigmaMat(const casacore::Matrix<casacore::Float> & sigmat);
     780             : 
     781             :         virtual void
     782             :         writeModel(
     783             :                 const casacore::RecordInterface& rec,
     784             :                 casacore::Bool iscomponentlist=true,
     785             :                 casacore::Bool incremental=false) override;
     786             : 
     787             :         virtual void
     788             :         writeBackChanges(VisBuffer2 *) override;
     789             : 
     790             :     //**********************************************************************
     791             :     // Methods to access the subtables.
     792             :     //**********************************************************************
     793             : 
     794             :     // Access to antenna subtable
     795             :     const casacore::MSAntennaColumns& antennaSubtablecols() const override;
     796             : 
     797             :     // Access to dataDescription subtable
     798             :     const casacore::MSDataDescColumns& dataDescriptionSubtablecols() const override;
     799             : 
     800             :     // Access to feed subtable
     801             :     const casacore::MSFeedColumns& feedSubtablecols() const override;
     802             : 
     803             :     // Access to field subtable
     804             :     const casacore::MSFieldColumns& fieldSubtablecols() const override;
     805             : 
     806             :     // Access to flagCmd subtable
     807             :     const casacore::MSFlagCmdColumns& flagCmdSubtablecols() const override;
     808             : 
     809             :     // Access to history subtable
     810             :     const casacore::MSHistoryColumns& historySubtablecols() const override;
     811             : 
     812             :     // Access to observation subtable
     813             :     const casacore::MSObservationColumns& observationSubtablecols() const override;
     814             : 
     815             :     // Access to pointing subtable
     816             :     const casacore::MSPointingColumns& pointingSubtablecols() const override;
     817             : 
     818             :     // Access to polarization subtable
     819             :     const casacore::MSPolarizationColumns& polarizationSubtablecols() const override;
     820             : 
     821             :     // Access to processor subtable
     822             :     const casacore::MSProcessorColumns& processorSubtablecols() const override;
     823             : 
     824             :     // Access to spectralWindow subtable
     825             :     const casacore::MSSpWindowColumns& spectralWindowSubtablecols() const override;
     826             : 
     827             :     // Access to state subtable
     828             :     const casacore::MSStateColumns& stateSubtablecols() const override;
     829             : 
     830             :     // Access to doppler subtable
     831             :     const casacore::MSDopplerColumns& dopplerSubtablecols() const override;
     832             : 
     833             :     // Access to freqOffset subtable
     834             :     const casacore::MSFreqOffsetColumns& freqOffsetSubtablecols() const override;
     835             : 
     836             :     // Access to source subtable
     837             :     const casacore::MSSourceColumns& sourceSubtablecols() const override;
     838             : 
     839             :     // Access to sysCal subtable
     840             :     const casacore::MSSysCalColumns& sysCalSubtablecols() const override;
     841             : 
     842             :     // Access to weather subtable
     843             :     const casacore::MSWeatherColumns& weatherSubtablecols() const override;
     844             : 
     845             : protected:
     846             : 
     847             : 
     848             :         virtual void
     849             :         attachColumns(const casacore::Table & t);
     850             : 
     851             :         // returns the table, to which columns are attached,
     852             :         // can be overridden in derived classes
     853             : 
     854             :         virtual const casacore::Table
     855             :         attachTable() const;
     856             : 
     857             :         virtual void
     858             :         applyPendingChanges();
     859             : 
     860             :         virtual void
     861             :         allSpectralWindowsSelected(
     862             :                 casacore::Vector<casacore::Int> & selectedWindows,
     863             :                 casacore::Vector<casacore::Int> & nChannels) const;
     864             : 
     865             :         // set the iteration state
     866             : 
     867             :         virtual void
     868             :         configureNewChunk();
     869             : 
     870             :         // set the currently selected table
     871             : 
     872             :         virtual void
     873             :         configureNewSubchunk();
     874             : 
     875             :         std::shared_ptr<vi::ChannelSelector>
     876             :         createDefaultChannelSelector(
     877             :                 casacore::Double time,
     878             :                 casacore::Int msId,
     879             :                 casacore::Int spectralWindowId);
     880             : 
     881             :         virtual std::shared_ptr<vi::ChannelSelector>
     882             :         determineChannelSelection(
     883             :                 casacore::Double time,
     884             :                 casacore::Int spectralWindowId = -1,
     885             :                 casacore::Int polarizationId = -1,
     886             :                 casacore::Int msId = -1) const;
     887             : 
     888             :         bool
     889             :         fillFromVirtualModel(casacore::Cube <casacore::Complex> & value) const;
     890             : 
     891             :         casacore::Slice
     892             :         findChannelsInRange(
     893             :                 casacore::Double lowerFrequency,
     894             :                 casacore::Double upperFrequency,
     895             :                 const vi::SpectralWindowChannels & spectralWindowChannels) const;
     896             : 
     897             :         ChannelInfo
     898             :         getChannelInformation() const;
     899             : 
     900             :         ChannelInfo
     901             :         getChannelInformationUsingFrequency() const;
     902             : 
     903             :         // Methods to get the data out of a table column according to whatever
     904             :         // selection criteria (e.g., slicing) is in effect.
     905             : 
     906             :         template <typename T>
     907             :         void
     908             :         getColumnRows(
     909             :                 const casacore::ScalarColumn<T> & column,
     910             :                 casacore::Vector<T> & array) const;
     911             : 
     912             :     template <typename T>
     913             :     void
     914             :     getColumnRowsMatrix(const casacore::ArrayColumn<T> & column,
     915             :                         casacore::Matrix<T> & array,
     916             :                         casacore::Bool correlationSlicing) const;
     917             : 
     918             :     template <typename T>
     919             :     void
     920             :     getColumnRowsMatrix(const casacore::ArrayColumn<T> & column,
     921             :                         casacore::Vector<casacore::Matrix<T>> & matrixVector) const;
     922             : 
     923             :     template <typename T>
     924             :     void
     925             :     getColumnRows(const casacore::ArrayColumn<T> & column,
     926             :                   casacore::Array<T> & array) const;
     927             : 
     928             :     template <typename T>
     929             :     void
     930             :     getColumnRows(const casacore::ArrayColumn<T> & column,
     931             :                   casacore::Vector<casacore::Cube<T>> & cubeVector) const;
     932             : 
     933             :         casacore::Vector<casacore::Double>
     934             :         getFrequencies(
     935             :                 casacore::Double time,
     936             :                 casacore::Int frameOfReference,
     937             :                 casacore::Int spectralWindowId,
     938             :                 casacore::Int msId) const override; // helper method
     939             : 
     940             :         casacore::Vector<casacore::Double>
     941             :         getChanWidths(
     942             :                 casacore::Double time,
     943             :                 casacore::Int frameOfReference,
     944             :                 casacore::Int spectralWindowId,
     945             :                 casacore::Int msId) const override; // helper method
     946             : 
     947             :         casacore::Vector<casacore::Int>
     948             :         getChannels(
     949             :                 casacore::Double time,
     950             :                 casacore::Int frameOfReference,
     951             :                 casacore::Int spectralWindowId,
     952             :                 casacore::Int msId) const override;
     953             : 
     954             :         casacore::Vector<casacore::Int>
     955             :         getCorrelations() const override;
     956             : 
     957             :         casacore::Vector<casacore::Stokes::StokesTypes>
     958             :         getCorrelationTypesDefined() const override;
     959             : 
     960             :         casacore::Vector<casacore::Stokes::StokesTypes>
     961             :         getCorrelationTypesSelected() const override;
     962             : 
     963             :         int getMeasurementFrame(int spectralWindowId) const;
     964             : 
     965             :         casacore::Int
     966             :         getPolarizationId(
     967             :                 casacore::Int spectralWindowId,
     968             :                 casacore::Int msId) const;
     969             : 
     970             :         casacore::Int
     971             :         getReportingFrameOfReference() const override;
     972             : 
     973             :         // Returns the casacore::MS objects that this VI is iterating over.
     974             : 
     975             :         casacore::Block
     976             :         <casacore::MeasurementSet> getMeasurementSets() const;
     977             : 
     978             :         // Provides access to the casacore::MS-derived values object
     979             : 
     980             :         const casacore::MSDerivedValues &
     981             :         getMsd() const; // for use by Async I/O *ONLY*
     982             : 
     983             :         // Get privileged (non-const) access to the containing ROVI
     984             : 
     985             :         VisibilityIterator2 *
     986             :         getViP() const;
     987             : 
     988             : //    void getVisibilityAsStokes(casacore::Matrix<CStokesVector> & visibilityStokes,
     989             : //                                const casacore::ArrayColumn<casacore::Complex> & column) const;
     990             : 
     991             :         VisBuffer2 *
     992             :         getVisBuffer(const VisibilityIterator2 *) const;
     993             : 
     994             :         // Ctor auxiliary method
     995             : 
     996             :         virtual void
     997             :         addDataSelection(const casacore::MeasurementSet & ms);
     998             : 
     999             :         virtual void
    1000             :         initialize(
    1001             :                 const casacore::Block<const casacore::MeasurementSet *> & mss,
    1002             :                 casacore::Bool useMSIter2);
    1003             : 
    1004             :     // Initialize using only the generic sorting criteria
    1005             :     void
    1006             :     initialize(const casacore::Block<const casacore::MeasurementSet *> &mss);
    1007             : 
    1008             :         // Returns true if casacore::MS Iterator is currently pointing to a selected
    1009             :         // spectral window
    1010             : 
    1011             :         casacore::Bool
    1012             :         isInASelectedSpectralWindow() const;
    1013             : 
    1014             :         // Creates a channel selection for the current subchunk based on the channel
    1015             :         // or frequency selection made by the user.
    1016             : 
    1017             :         std::shared_ptr<vi::ChannelSelector>
    1018             :         makeChannelSelectorC(
    1019             :                 const FrequencySelection & selection,
    1020             :                 casacore::Double time,
    1021             :                 casacore::Int msId,
    1022             :                 casacore::Int spectralWindowId,
    1023             :                 casacore::Int polarizationId) const;
    1024             : 
    1025             :         std::shared_ptr<vi::ChannelSelector>
    1026             :         makeChannelSelectorF(
    1027             :                 const FrequencySelection & selection,
    1028             :                 casacore::Double time,
    1029             :                 casacore::Int msId,
    1030             :                 casacore::Int spectralWindowId,
    1031             :                 casacore::Int polarizationId) const;
    1032             : 
    1033             :         casacore::MFrequency::Convert
    1034             :         makeFrequencyConverter(
    1035             :                 casacore::Double time,
    1036             :                 int spectralWindowId,
    1037             :                 casacore::Int otherFrameOfReference,
    1038             :                 casacore::Bool toObservedFrame,
    1039             :                 casacore::Unit) const;
    1040             : 
    1041             :         // Allow access to the casacore::MSColumns object; for use by
    1042             :         // VisBuffer2Adapter *KLUGE*
    1043             : 
    1044             :         const casacore::MSColumns *
    1045             :         msColumnsKluge() const;
    1046             : 
    1047             :         // Method to reset the VI back to the start.  Unlike the public version
    1048             :         // there is a parameter to allow forcing the rewind even if the
    1049             :         // casacore::MS Iter is already at the origin.
    1050             : 
    1051             :         virtual void
    1052             :         originChunks(casacore::Bool forceRewind) override;
    1053             : 
    1054             :         // Advances the casacore::MS Iterator until it points at a spectral window
    1055             :         // that is part of the frequency selection.
    1056             : 
    1057             :         void
    1058             :         positionMsIterToASelectedSpectralWindow();
    1059             : 
    1060             :         // Sets the default frequency reporting frame of reference.  This
    1061             :         // affects the default frame for obtaining the frequencies in a
    1062             :         // VisBuffer.
    1063             : 
    1064             :         void
    1065             :         setReportingFrameOfReference(casacore::Int) override;
    1066             : 
    1067             :         // Adjusts the tile cache for some columns so that the cache size is
    1068             :         // optimized for the current input state (e.g., a new data description).
    1069             : 
    1070             :         virtual void
    1071             :         setTileCache();
    1072             : 
    1073             :         void
    1074             :         setMsCacheSizes(
    1075             :                 const casacore::MeasurementSet & ms,
    1076             :                 std::vector<casacore::MSMainEnums::PredefinedColumns> columnIds);
    1077             : 
    1078             :         void
    1079             :         setMsColumnCacheSizes(const casacore::MeasurementSet&, const string &);
    1080             : 
    1081             :         // Throws exception if there is a pending (i.e., unapplied) change to
    1082             :         // the VI's properties.  Called when the VI is advanced since the user
    1083             :         // probably forgot to apply the changes.
    1084             : 
    1085             :         virtual void
    1086             :         throwIfPendingChanges();
    1087             : 
    1088             :         // Returns true if the named column uses a tiled data manager in the
    1089             :         // specified MS
    1090             : 
    1091             :         casacore::Bool
    1092             :         usesTiledDataManager(
    1093             :                 const casacore::String & columnName,
    1094             :                 const casacore::MeasurementSet & ms) const;
    1095             : 
    1096             : 
    1097             : //    +========================|
    1098             : //    |                        |
    1099             : //    | Output Related Methods |
    1100             : //    |                        |
    1101             : //    +========================|
    1102             : 
    1103             :         // A BackWriter is a functor that will extract a piece of information out of
    1104             :         // its VisBuffer argument and write it out using a "set" method on the
    1105             :         // supplied VisibilityIterator2.
    1106             :         class BackWriter {
    1107             : 
    1108             :         public:
    1109             : 
    1110           0 :                 virtual ~BackWriter() {}
    1111             : 
    1112             :                 virtual void operator()(VisibilityIteratorImpl2 * vi, VisBuffer2 * vb) = 0;
    1113             : 
    1114             :         };
    1115             : 
    1116             :         // A simple BackWriterImpl2 uses a nullary accessor on a VisBuffer.
    1117             :         template <typename Setter, typename Getter>
    1118             :         class BackWriterImpl : public BackWriter {
    1119             :         public:
    1120             : 
    1121        1820 :                 BackWriterImpl(Setter setter, Getter getter)
    1122        1820 :                         : getter_p(getter), setter_p(setter) {}
    1123             : 
    1124             :                 void
    1125      556198 :                 operator() (VisibilityIteratorImpl2 * vi, VisBuffer2 * vb) {
    1126      556198 :                         (vi ->* setter_p)((vb ->* getter_p)());
    1127      556198 :                 }
    1128             : 
    1129             :         private:
    1130             : 
    1131             :                 Getter getter_p;
    1132             :                 Setter setter_p;
    1133             :         };
    1134             : 
    1135             :         // BackWriterImpl2 is slightly more complicated in that it uses a unary
    1136             :         // accessor.  The argument to the unary accessor is a member of the
    1137             :         // VisibilityIterator2 DataColumn enumeration which specifies which
    1138             :         // visibilty or visCube type is wanted (e.g., observed, model or corrected).
    1139             :         template <typename Setter, typename Getter>
    1140             :         class BackWriterImpl2 : public BackWriter {
    1141             :         public:
    1142             : 
    1143             :                 typedef VisibilityIteratorImpl2::DataColumn DataColumn;
    1144             : 
    1145             :                 BackWriterImpl2(Setter setter, Getter getter, DataColumn dc)
    1146             :                         : dataColumn_p(dc), getter_p(getter), setter_p(setter)
    1147             :                         {}
    1148             : 
    1149             :                 void
    1150             :                 operator() (VisibilityIteratorImpl2 * vi, VisBuffer2 * vb) {
    1151             :                         (vi ->* setter_p)((vb ->* getter_p)(), dataColumn_p);
    1152             :                 }
    1153             : 
    1154             :         private:
    1155             : 
    1156             :                 DataColumn dataColumn_p;
    1157             :                 Getter getter_p;
    1158             :                 Setter setter_p;
    1159             :         };
    1160             : 
    1161             :         // Backwriter(2) creation methods.  These methods make it fairly
    1162             :         // straightforward to create a BackWriter object.
    1163             : 
    1164             :         template <typename Ret>
    1165             :         static
    1166             :         BackWriter *
    1167        1820 :         makeBackWriter(
    1168             :                 void (VisibilityIteratorImpl2::* setter)(Ret),
    1169             :                 Ret (VisBuffer2::* getter)() const) {
    1170        1820 :                 return new BackWriterImpl<void(VisibilityIteratorImpl2:: *)(Ret),
    1171             :                                           Ret(VisBuffer2:: *)() const >(
    1172        1820 :                                                   setter, getter);
    1173             :         }
    1174             : 
    1175             :         template <typename Ret>
    1176             :         static
    1177             :         BackWriter *
    1178             :         makeBackWriter2(
    1179             :                 void (VisibilityIteratorImpl2::* setter)(Ret, VisibilityIteratorImpl2::DataColumn),
    1180             :                 Ret (VisBuffer2::* getter)() const,
    1181             :                 VisibilityIterator2::DataColumn dc) {
    1182             : 
    1183             :                 // Define the Getter and Setter types
    1184             : 
    1185             :                 typedef void (VisibilityIteratorImpl2::* Setter)(Ret, VisibilityIteratorImpl2::DataColumn);
    1186             :                 typedef Ret (VisBuffer2::* Getter)() const;
    1187             : 
    1188             :                 return new BackWriterImpl2 < Setter, Getter>(setter, getter, dc);
    1189             :         }
    1190             : 
    1191             :         void
    1192             :         initializeBackWriters();
    1193             : 
    1194             :         template <typename T>
    1195             :         void
    1196             :         putColumnRows(
    1197             :                 casacore::ArrayColumn<T> & column,
    1198             :                 const casacore::Array<T> & array);
    1199             : 
    1200             :         template <typename T>
    1201             :         void
    1202             :         putColumnRows(
    1203             :                 casacore::ArrayColumn<T> & column,
    1204             :                 const casacore::Matrix<T> & array);
    1205             : 
    1206             :         template <typename T>
    1207             :         void
    1208             :         putColumnRows(
    1209             :                 casacore::ScalarColumn<T> & column,
    1210             :                 const casacore::Vector <T> & array);
    1211             : 
    1212             : //    void convertVisFromStokes(const casacore::Matrix<CStokesVector> & visibilityStokes,
    1213             : //                               casacore::Cube<casacore::Complex> & visCube);
    1214             : 
    1215             :         class Cache {
    1216             : 
    1217             :         public:
    1218             : 
    1219             :                 Cache();
    1220             : 
    1221             :                 void flush();
    1222             : 
    1223             :                 casacore::MDirection azel0_p;
    1224             :                 casacore::Double azel0Time_p;
    1225             :                 casacore::Vector<casacore::MDirection> azel_p;
    1226             :                 casacore::Double azelTime_p;
    1227             :                 // Row numbers of underlying casacore::MS; used to map form chunk rows
    1228             :                 // to casacore::MS rows.  See rowIds method.
    1229             :                 casacore::Vector<casacore::rownr_t> chunkRowIds_p;
    1230             :                 casacore::Vector<casacore::Float> feedpa_p;
    1231             :                 casacore::Double feedpaTime_p;
    1232             :                 casacore::Double hourang_p;
    1233             :                 casacore::Double hourangTime_p;
    1234             :                 casacore::Matrix<casacore::Float> imagingWeight_p;
    1235             :                 // Does the current casacore::MS have a valid FLAG_CATEGORY?
    1236             :                 casacore::Bool msHasFlagCategory_p;
    1237             :                 // Does the current casacore::MS have a valid WEIGHT_SPECTRUM?
    1238             :                 casacore::Bool msHasWeightSpectrum_p;
    1239             :                 // Does the current casacore::MS have a valid SIGMA_SPECTRUM?
    1240             :                 casacore::Bool msHasSigmaSpectrum_p;
    1241             :                 casacore::Float parang0_p;
    1242             :                 casacore::Double parang0Time_p;
    1243             :                 casacore::Vector<casacore::Float> parang_p;
    1244             :                 casacore::Double parangTime_p;
    1245             :         };
    1246             : 
    1247             :         class PendingChanges {
    1248             : 
    1249             :         public:
    1250             : 
    1251             :                 PendingChanges();
    1252             :                 ~PendingChanges();
    1253             : 
    1254             :                 PendingChanges *
    1255             :                 clone() const;
    1256             : 
    1257             :                 casacore::Bool
    1258             :                 empty() const;
    1259             : 
    1260             :                 // yields ownership
    1261             :                 std::pair<casacore::Bool, FrequencySelections *>
    1262             :                 popFrequencySelections();
    1263             : 
    1264             :                 std::pair<casacore::Bool, casacore::Double>
    1265             :                 popInterval();
    1266             : 
    1267             :                 std::pair<casacore::Bool, casacore::Int>
    1268             :                 popNRowBlocking();
    1269             : 
    1270             :                 // takes ownership
    1271             :                 void
    1272             :                 setFrequencySelections(FrequencySelections *);
    1273             : 
    1274             :                 void
    1275             :                 setInterval(casacore::Double);
    1276             : 
    1277             :                 void
    1278             :                 setNRowBlocking(casacore::Int);
    1279             : 
    1280             :         private:
    1281             : 
    1282             :                 enum {Empty = -1};
    1283             : 
    1284             :                 FrequencySelections * frequencySelections_p;
    1285             :                 casacore::Bool frequencySelectionsPending_p;
    1286             :                 casacore::Double interval_p;
    1287             :                 casacore::Int nRowBlocking_p;
    1288             :         };
    1289             : 
    1290             :         typedef casacore::Block <casacore::MeasurementSet> MeasurementSets;
    1291             : 
    1292             :     class RowBounds
    1293             :     {
    1294             :     public:
    1295             : 
    1296        5434 :         RowBounds() :
    1297             :             chunkNRows_p(-1), subchunkBegin_p(-1), subchunkEnd_p(-1),
    1298        5434 :             subchunkNRows_p(-1), subchunkRows_p(0, 0), timeMax_p(-1), timeMin_p(-1)
    1299        5434 :         {}
    1300             : 
    1301             :         // last row in current chunk
    1302             :         ssize_t chunkNRows_p;
    1303             :         // first row in current subchunk
    1304             :         ssize_t subchunkBegin_p;
    1305             :         // last row in current subchunk
    1306             :         ssize_t subchunkEnd_p;
    1307             :         // # rows in subchunk
    1308             :         ssize_t subchunkNRows_p;
    1309             :         // subchunk's table row numbers
    1310             :         casacore::RefRows subchunkRows_p;
    1311             :         // List of Row numbers for each subset of the subchunk with equal channel selector
    1312             :         std::vector<casacore::RefRows> subchunkEqChanSelRows_p;
    1313             :         // times for each row in the chunk
    1314             :         casacore::Vector<casacore::Double> times_p;
    1315             :         // max timestamp in the chunk
    1316             :         casacore::Double timeMax_p;
    1317             :         // min timechunk in the chunk
    1318             :         casacore::Double timeMin_p;
    1319             : 
    1320             :     };
    1321             : 
    1322             : 
    1323             :     casacore::Bool autoTileCacheSizing_p;
    1324             :     std::map <VisBufferComponent2, BackWriter *> backWriters_p;
    1325             :     // general collection of cached values
    1326             :     mutable Cache cache_p;
    1327             :     // [use] current channel selectors for this chunk 
    1328             :     std::vector<std::shared_ptr<ChannelSelector>>  channelSelectors_p;
    1329             :     // Number of rows in the VisBuffer for which each of the channel selector applies
    1330             :     std::vector<size_t>  channelSelectorsNrows_p;
    1331             :     // [own] cache of recently used channel selectors
    1332             :     ChannelSelectorCache * channelSelectorCache_p;
    1333             :     // The main columns for the current MS
    1334             :     ViColumns2 columns_p;
    1335             :     // true if a float data column was found
    1336             :     casacore::Bool floatDataFound_p;
    1337             :     // [own] Current frequency selection
    1338             :     FrequencySelections * frequencySelections_p;
    1339             :     // object to calculate imaging weight
    1340             :     VisImagingWeight imwgt_p;
    1341             :     // cached value of observatory type
    1342             :     mutable casacore::Int measurementFrame_p;
    1343             :     MeasurementSets measurementSets_p; // [use]
    1344             :     VisModelDataI * modelDataGenerator_p; // [own]
    1345             :     // true if more data in this chunk
    1346             :     casacore::Bool more_p;
    1347             :     // array index of current MS
    1348             :     casacore::Int msIndex_p;
    1349             :     // true if casacore::MS Iter is a start of first MS
    1350             :     casacore::Bool msIterAtOrigin_p;
    1351             :     // casacore::MS Iter that underlies the VI (sweeps in chunks)
    1352             :     casacore::CountedPtr<casacore::MSIter> msIter_p;
    1353             :     // Helper class holding casacore::MS derived values.
    1354             :     mutable casacore::MSDerivedValues msd_p;
    1355             :     casacore::Int nCorrelations_p;
    1356             :     // suggested # of rows in a subchunk
    1357             :     casacore::Int nRowBlocking_p;
    1358             :     // holds pending changes to VI properties
    1359             :     std::unique_ptr<PendingChanges> pendingChanges_p;
    1360             :     mutable std::unique_ptr<PointingDirectionCache>  pointingDirectionCache_p;
    1361             :     mutable std::unique_ptr<PointingSource>  pointingSource_p;
    1362             :     // default frequency reporting (not selecting) frame of reference
    1363             :     casacore::Int reportingFrame_p;
    1364             :     // Subchunk row management object (see above)
    1365             :     RowBounds rowBounds_p;
    1366             :     // [own] Info about spectral windows
    1367             :     mutable SpectralWindowChannelsCache * spectralWindowChannelsCache_p;
    1368             :     // (chunkN #, subchunk #) pair
    1369             :     Subchunk subchunk_p;
    1370             :     // Number of rows for each distinct array/cube shapes in the current iteration
    1371             :     casacore::Vector<casacore::rownr_t> nRowsPerShape_p;
    1372             :     // Number of channels for each distinct array/cube shapes in the current iteration
    1373             :     casacore::Vector<casacore::Int> nChannPerShape_p;
    1374             :     // Number of correlations for each distinct array/cube shapes in the current iteration
    1375             :     casacore::Vector<casacore::Int> nCorrsPerShape_p;
    1376             :     // [own] Allows const access to casacore::MS's subtable columns
    1377             :     SubtableColumns * subtableColumns_p;
    1378             :     casacore::MeasRef<casacore::MEpoch> timeFrameOfReference_p;
    1379             :     std::shared_ptr<std::mutex> tileCacheModMtx_p;
    1380             :     std::shared_ptr<std::vector<bool> > tileCacheIsSet_p;
    1381             :     casacore::Double timeInterval_p;
    1382             :     VisBufferType vbType;
    1383             :     // [own] VisBuffer attached to this VI
    1384             :     VisBuffer2 * vb_p;
    1385             :     casacore::CountedPtr<WeightScaling> weightScaling_p;
    1386             :     casacore::Bool writable_p;
    1387             :     // Determine several metadata uniqueness. For each metadata
    1388             :     // the valus could be unique in each chunk or subchunk,
    1389             :     // or in the worst case for each row.
    1390             :     MetadataScope ddIdScope_p;
    1391             :     MetadataScope timeScope_p;
    1392             :     MetadataScope freqSelScope_p;
    1393             :     MetadataScope antenna1Scope_p;
    1394             :     MetadataScope antenna2Scope_p;
    1395             : 
    1396             :     // Variables for the handling of the subchunk  loop
    1397             :     std::shared_ptr<casacore::MeasurementSet> msSubchunk_p;
    1398             :     std::shared_ptr<casacore::MSIter> msIterSubchunk_p;
    1399             :     // sort columns specified when creating VI
    1400             :     SortColumns sortColumns_p;
    1401             :     SortColumns subchunkSortColumns_p;
    1402             : };
    1403             : 
    1404             : } // end namespace vi
    1405             : 
    1406             : } //# NAMESPACE CASA - END
    1407             : 
    1408             : #endif

Generated by: LCOV version 1.16