LCOV - code coverage report
Current view: top level - msvis/MSVis - VisChunkAverager.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 1 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 1 0.0 %

          Line data    Source code
       1             : //# VisChunkAverager.h: class to time average all columns of a VisBuffer
       2             : //# Copyright (C) 2010
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : 
      26             : #ifndef MSVIS_VISCHUNKAVERAGER_H
      27             : #define MSVIS_VISCHUNKAVERAGER_H
      28             : 
      29             : #include <casacore/casa/aips.h>
      30             : #include <msvis/MSVis/CalVisBuffer.h>
      31             : #include <map>
      32             : #include <vector>
      33             : 
      34             : namespace casa { //# NAMESPACE CASA - BEGIN
      35             : 
      36             : class CalVisBuffer;
      37             : class VisBuffer;
      38             : 
      39             : // <summary>
      40             : // A class to time average all columns of a VisBuffer.
      41             : // </summary>
      42             : //
      43             : // <use visibility=export>
      44             : //
      45             : // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
      46             : // </reviewed>
      47             : 
      48             : // <prerequisite>
      49             : //   <li> VisBuffer
      50             : // </prerequisite>
      51             : //
      52             : // <etymology>
      53             : // From "VisBuffer", "Chunk", and "averaging".  "Chunk" comes from
      54             : // VisibilityIterator.
      55             : // </etymology>
      56             : //
      57             : // <synopsis>
      58             : // This class time averages complete rows of a VisBuffer.
      59             : // </synopsis>
      60             : //
      61             : // <example>
      62             : // See SubMS::doTimeAver().
      63             : // </example>
      64             : //
      65             : // <motivation>
      66             : // VisBuffAccumulator also time averages VisBuffers, but only for a few
      67             : // columns, as needed by calibration and plotms.  casacore::Time averaging in split
      68             : // requires (in principle) that all of the columns in the input casacore::MS be written
      69             : // to the output MS.  This is more work than required by calibration and
      70             : // plotms, and split also has some differences in the details of the averaging.
      71             : // </motivation>
      72             : //
      73             : // <note>
      74             : // For many of the columns averaging is trivial, i.e. the VisBuffer should only
      75             : // contain one ARRAY_ID, FIELD_ID, and DATA_DESC_ID, so they will all only have
      76             : // one value each.
      77             : //
      78             : // TIME and INTERVAL will also be univalued in the output, for a different
      79             : // reason.  For most (all?) uses this is a feature.  (See CAS-2422 + 2439 for
      80             : // why.)
      81             : // </note>
      82             : //
      83             : // <todo asof="2010/11/12">
      84             : //   <li> averaging over other indices.
      85             : // </todo>
      86             : 
      87             : typedef std::map<casacore::uInt, std::vector<casacore::Int> > mapuIvIType;
      88             : 
      89             : class VisChunkAverager //: public VisBuffAccumulator
      90             : {
      91             : public:
      92             :   // Construct from which *DATA column(s) to read and whether or not to use
      93             :   // WEIGHT_SPECTRUM.
      94             :   VisChunkAverager(const casacore::Vector<casacore::MS::PredefinedColumns>& dataCols,
      95             :                    const casacore::Bool doSpWeight,
      96             :                    const casacore::Vector<casacore::Matrix<casacore::Int> >& chBounds=casacore::Vector<casacore::Matrix<casacore::Int> >());
      97             : 
      98             :   // Null destructor
      99             :   ~VisChunkAverager();
     100             : 
     101             :   // Reset the averager
     102             :   void reset();
     103             : 
     104             :   // casacore::Time average vi's current chunk, AND advance vi to the end of that chunk.
     105             :   // casacore::Input:
     106             :   //    vi              ROVisibilityIterator  vi.setRowBlocking(0) will be
     107             :   //                                          called to ensure that ++vi
     108             :   //                                          advances by 1 integration at a
     109             :   //                                          time.
     110             :   // Output from private data:
     111             :   //    avBuf_p         CalVisBuffer          Output buffer for the averaged 
     112             :   //                                          "integration".
     113             :   VisBuffer& average(ROVisibilityIterator& vi);
     114             : 
     115             :   // Checks whether the interval of vi needs to be truncated in order to
     116             :   // prevent collisions where two rows have the same casacore::MS key (ignoring TIME) but
     117             :   // different SCAN_NUMBER, STATE_ID, and/or OBSERVATION_ID.  ARRAY_ID is
     118             :   // already separated by the chunking.
     119             :   //
     120             :   // time_to_break is set to the TIME of the earliest collision, or the end of
     121             :   // the buffer if none are found.
     122             :   //
     123             :   static casacore::Bool check_chunk(ROVisibilityIterator& vi, casacore::Double& time_to_break,
     124             :                           const casacore::Bool watch_obs, const casacore::Bool watch_scan,
     125             :                           const casacore::Bool watch_state);
     126             : 
     127             : 
     128             :   // max(a, b) in Math.h is so overloaded, and (u)casacore::Int is so promotable, that
     129             :   // they're unusable together.
     130           0 :   casacore::uInt uIntMax(const casacore::uInt a, const casacore::uInt b) const { return a > b ? a : b; }
     131             : 
     132             : private:
     133             :   // Prohibit null constructor, copy constructor and assignment for now
     134             :   VisChunkAverager();
     135             :   VisChunkAverager& operator= (const VisChunkAverager&);
     136             :   VisChunkAverager (const VisChunkAverager&);
     137             : 
     138             :   // Initialize the next accumulation interval
     139             :   void initialize(VisBuffer& vb);
     140             : 
     141             :   // Normalize the accumulation (finish the average).
     142             :   void normalize(const casacore::Double minTime, const casacore::Double maxTime,
     143             :                  const casacore::Double firstinterval, const casacore::Double lastinterval);
     144             : 
     145             :   // Force vb to read all the columns (modified by colEnums_p and
     146             :   // doSpWeight_p).
     147             :   //
     148             :   // Sets readyToHash_p to false.
     149             :   //
     150             :   void fill_vb(VisBuffer& vb);
     151             : 
     152             :   // Hash function to return a unique (within the VisBuffer) key (as defined by
     153             :   // the casacore::MS def'n) for an interferometer (ant1, ant2, feed1, feed2,
     154             :   // processor_id).  Note that a VisBuffer only contains one ddid and fieldid,
     155             :   // and TIME is deliberately excluded this that is what will be averaged over.
     156             :   //
     157             :   // Sorting a set of the returned keys is equivalent to sorting by
     158             :   // (procid, ant1, ant2, feed1, feed2).
     159             :   //
     160             :   casacore::uInt hashFunction(const casacore::Int ant1, const casacore::Int ant2,
     161             :                     const casacore::Int feed1, const casacore::Int feed2,
     162             :                     const casacore::Int procid) const;
     163             : 
     164             :   // These return their success values.  (They could fail if any of ant1, ant2,
     165             :   // feed1, feed2, or procid are < 0, but that shouldn't happen and isn't
     166             :   // checked for.)
     167             :   casacore::Bool setupHashFunction(ROVisibilityIterator& vi);
     168             :   casacore::Bool makeHashMap(ROVisibilityIterator& vi);
     169             : 
     170             :   // Check whether any of the unflagged rows in vi's current chunk have the
     171             :   // same casacore::MS key (not counting TIME) but different values for the columns in
     172             :   // colsToWatch.
     173             :   //
     174             :   // time_to_break will be set to the time of the earliest collision if any are
     175             :   // found, or the last TIME in vi's current chunk otherwise (assumes vi's
     176             :   // current chunk is ascendingly sorted in TIME).
     177             :   //
     178             :   // colsToWatch should contain casacore::MS::SCAN_NUMBER, casacore::MS::STATE_ID,
     179             :   // casacore::MS::OBSERVATION_ID, and/or nothing.  Otherwise an casacore::AipsError will be
     180             :   // thrown.  casacore::MS::ARRAY_ID is already separated by the chunking.
     181             :   //
     182             :   casacore::Bool findCollision(ROVisibilityIterator& vi, casacore::Double& time_to_break,
     183             :                      const casacore::Bool watchObs, const casacore::Bool watchScan,
     184             :                      const casacore::Bool watchState);
     185             : 
     186             :   // Helper function for findCollision().
     187             :   casacore::Bool checkForBreak(casacore::Vector<casacore::Int>& firstVals, const casacore::Int i, const casacore::uInt slotnum,
     188             :                      const casacore::uInt chunkletNum,
     189             :                      const std::vector<casacore::Int>& inrows_for_slot) const;
     190             : 
     191             :   // Start of initialization list.
     192             :   // Which of DATA, MODEL_DATA, and/or CORRECTED_DATA to use.
     193             :   casacore::Vector<casacore::MS::PredefinedColumns> colEnums_p;
     194             : 
     195             :   // Use WEIGHT_SPECTRUM?
     196             :   casacore::Bool doSpWeight_p;
     197             : 
     198             :   // Used for both selecting and averaging channels.
     199             :   casacore::Vector<casacore::Matrix<casacore::Int> > chanAveBounds_p;
     200             :   // End of initialization list.
     201             : 
     202             :   // Is everything setup for hashFunction()?
     203             :   casacore::Bool readyToHash_p;
     204             : 
     205             :   // Is sphash_to_inprows_p OK?
     206             :   casacore::Bool haveHashMap_p;
     207             : 
     208             :   // Maxima for hashFunction().
     209             :   casacore::uInt maxant1p1_p;
     210             :   casacore::uInt maxant2p1_p;
     211             :   casacore::uInt maxfeed1p1_p;
     212             :   casacore::uInt maxfeed2p1_p;
     213             :   // casacore::uInt maxprocp1_p; Not needed
     214             : 
     215             :   // A map from a sparse hash of "baseline" to a vector of input row numbers
     216             :   // matching that hash.
     217             :   //
     218             :   // The hash is calculated by hashFunction().
     219             :   //
     220             :   // The vector has an entry, in order, for each chunklet (vb) in vi's current
     221             :   // chunk which is either -1 (the chunklet has no row matching the hash) or
     222             :   // the row number _relative_ to the starting row in that chunklet's vb.
     223             :   //
     224             :   mapuIvIType sphash_to_inprows_p;
     225             : 
     226             :   // Number of correlations and channels
     227             :   casacore::Int nCorr_p, nChan_p;
     228             : 
     229             :   // The number of flag categories.  0 if flagCategory() is invalid.
     230             :   casacore::Int nCat_p;
     231             : 
     232             :   // Averaging buffer
     233             :   CalVisBuffer avBuf_p;
     234             : };
     235             : 
     236             : 
     237             : } //# NAMESPACE CASA - END
     238             : 
     239             : #endif
     240             : 
     241             : 

Generated by: LCOV version 1.16