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

          Line data    Source code
       1             : //# MSIter2.h: MSIter w/ smarter interval handling
       2             : //# Copyright (C) 1996,1999,2000,2001,2002
       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             : //# $Id$
      27             : 
      28             : #ifndef MS_MSITER2_H
      29             : #define MS_MSITER2_H
      30             : 
      31             : #include <casacore/casa/aips.h>
      32             : #include <casacore/ms/MeasurementSets/MSIter.h>
      33             : 
      34             : namespace casa { //# NAMESPACE CASA - BEGIN
      35             : namespace vi {  //# NAMESPACE VI - BEGIN
      36             : 
      37             : //# forward decl
      38             : //class MSColumns;
      39             : //class TableIterator;
      40             : 
      41             : // <summary>
      42             : // Small helper class to specify an 'interval' comparison
      43             : // </summary>
      44             : // <synopsis>
      45             : // Small helper class to specify an 'interval' comparison for table iteration
      46             : // by time interval.
      47             : // </synopsis>
      48             : class MSSmartInterval : public casacore::MSInterval
      49             : {
      50             : public:
      51             :   explicit MSSmartInterval(casacore::Double interval,
      52             :                            casacore::Vector<casacore::Double>& timeboundaries); 
      53         168 :   virtual ~MSSmartInterval() {}
      54             :   virtual void setOffset(casacore::Double offset);
      55             :   virtual int comp(const void * obj1, const void * obj2) const;
      56             : 
      57             : private:
      58             : 
      59             :     // Local versions of MSInterval::interval_p,offset_p so we
      60             :     //   can avoid function calls and obj copies in comp()
      61             :     casacore::Double interval2_;
      62             :     mutable casacore::Double offset2_;
      63             : 
      64             :     // A list of enforced interval time boundaries (e.g., scan bounds).
      65             :     //   the interval grid will be re-registered to each 
      66             :     //   of the values in this Vector as supplied times cross them
      67             :     casacore::Vector<casacore::Double> timeBounds_;
      68             :     int nBounds_;
      69             : 
      70             :     // Is specified interval effectively zero?
      71             :     casacore::Bool zeroInterval_;
      72             : 
      73             :     // Utility variables used in comp
      74             :     mutable casacore::Bool found_;
      75             :     mutable int bidx_;
      76             :     mutable double t1_,t2_;
      77             : 
      78             : };
      79             : 
      80             : // <summary> 
      81             : // An iterator class for MeasurementSets
      82             : // </summary>
      83             :  
      84             : // <use visibility=export>
      85             :  
      86             : // <prerequisite>
      87             : //   <li> <linkto class="MeasurementSet:description">MeasurementSet</linkto> 
      88             : // </prerequisite>
      89             : //
      90             : // <etymology>
      91             : // MSIter stands for the MeasurementSet Iterator class.
      92             : // </etymology>
      93             : //
      94             : // <synopsis> 
      95             : // An MSIter is a class to traverse a MeasurementSet in various orders.  It
      96             : // automatically adds four predefined sort columns to your selection of sort
      97             : // columns (see constructor) so that it can keep track of changes in frequency
      98             : // or polarization setup, field position and sub-array.  Note that this can
      99             : // cause iterations to occur in a different way from what you would expect, see
     100             : // examples below.  MSIter implements iteration by time interval for the use of
     101             : // e.g., calibration tasks that want to calculate solutions over some interval
     102             : // of time.  You can iterate over multiple MeasurementSets with this class.
     103             : // </synopsis> 
     104             : //
     105             : // <example>
     106             : // <srcblock>
     107             : // // The following code iterates by by ARRAY_ID, FIELD_ID, DATA_DESC_ID and
     108             : // // TIME (all implicitly added columns) and then by baseline (antenna pair),
     109             : // // in 3000s intervals.
     110             : // MeasurementSet ms("3C273XC1.ms"); 
     111             : // Block<int> sort(2);
     112             : //        sort[0] = MS::ANTENNA1;
     113             : //        sort[1] = MS::ANTENNA2;
     114             : // Double timeInterval = 3000;
     115             : // MSIter msIter(ms,sort,timeInteval);
     116             : // for (msIter.origin(); msIter.more(); msIter++) {
     117             : // // print out some of the iteration state
     118             : //    cout << msIter.fieldId() << endl;
     119             : //    cout << msIter.fieldName() << endl;
     120             : //    cout << msIter.dataDescriptionId() << endl;
     121             : //    cout << msIter.frequency0() << endl;
     122             : //    cout << msIter.table().nrow() << endl;
     123             : //    process(msIter.table()); // process the data in the current iteration
     124             : // }
     125             : // // Output shows only 1 row at a time because the table is sorted on TIME
     126             : // // first and ANTENNA1, ANTENNA2 next and each baseline occurs only once per 
     127             : // // TIME stamp. The interval has no effect in this case.
     128             : // </srcblock>
     129             : // </example>
     130             : 
     131             : // <example>
     132             : // <srcblock>
     133             : // // The following code iterates by baseline (antenna pair), TIME, and,
     134             : // // implicitly, by ARRAY_ID, FIELD_ID and DATA_DESC_ID in 3000s
     135             : // // intervals.
     136             : // MeasurementSet ms("3C273XC1.ms"); 
     137             : // Block<int> sort(3);
     138             : //        sort[0] = MS::ANTENNA1;
     139             : //        sort[1] = MS::ANTENNA2;
     140             : //        sort[2] = MS::TIME;
     141             : // Double timeInterval = 3000;
     142             : // MSIter msIter(ms,sort,timeInteval);
     143             : // for (msIter.origin(); msIter.more(); msIter++) {
     144             : // // print out some of the iteration state
     145             : //    cout << msIter.fieldId() << endl;
     146             : //    cout << msIter.fieldName() << endl;
     147             : //    cout << msIter.dataDescriptionId() << endl;
     148             : //    cout << msIter.frequency0() << endl;
     149             : //    cout << msIter.table().nrow() << endl;
     150             : //    process(msIter.table()); // process the data in the current iteration
     151             : // // Now the output shows 7 rows at a time, all with identical ANTENNA1
     152             : // // and ANTENNA2 values and TIME values within a 3000s interval.
     153             : // }
     154             : // </srcblock>
     155             : // </example>
     156             : //
     157             : // <motivation>
     158             : // This class was originally part of the VisibilityIterator class, but that 
     159             : // class was getting too large and complicated. By splitting out the toplevel
     160             : // iteration into this class the code is much easier to understand. It is now
     161             : // also available through the ms tool.
     162             : // </motivation>
     163             : //
     164             : // <todo>
     165             : // multiple observatories in a single MS are not handled correctly (need to
     166             : // sort on observation id and check observatory name to set position frame)
     167             : // </todo>
     168             : 
     169             : class MSIter2 : public casacore::MSIter
     170             : {
     171             : public:
     172             : 
     173             :   // Default constructor - useful only to assign another iterator later.
     174             :   // Use of other member functions on this object is likely to dump core.
     175             :   MSIter2();
     176             : 
     177             :   MSIter2(const casacore::MeasurementSet& ms, const casacore::Block<int>& sortColumns, 
     178             :           double timeInterval=0, bool addDefaultSortColumns=true,
     179             :           bool storeSorted=true);
     180             : 
     181             :   // Same as above with multiple MSs as input.
     182             :   MSIter2(const casacore::Block<casacore::MeasurementSet>& mss, const casacore::Block<int>& sortColumns, 
     183             :           double timeInterval=0, bool addDefaultSortColumns=true,
     184             :           bool storeSorted=true);
     185             : 
     186             :   // Copy construct. This calls the assigment operator.
     187             :   MSIter2(const MSIter2& other);
     188             : 
     189             :   // Destructor
     190             :   virtual ~MSIter2();
     191             :   
     192             :   // Assigment. This will reset the iterator to the origin.
     193             :   MSIter2 & operator=(const MSIter2 &other);
     194             : 
     195             :   // Reset iterator to start of data
     196             :   //  This specialization resets the time-compare object 
     197             :   //   before calling parent
     198             :   virtual void origin();
     199             :  
     200             : protected:
     201             :   // handle the construction details
     202             :   void construct2(const casacore::Block<int>& sortColumns, casacore::Bool addDefaultSortColumns);
     203             : 
     204             :   // set the iteration state
     205             :   virtual void setState();
     206             : 
     207             :   virtual void discernEnforcedTimeBounds(casacore::Vector<casacore::Double>& solbounds,
     208             :                                          casacore::Bool scanBounded);
     209             :   virtual void discernEnforcedTimeBounds(casacore::Vector<casacore::Double>& solbounds,
     210             :                                          casacore::Bool scanBounded,casacore::Bool fieldBounded);
     211             :   virtual void discernEnforcedTimeBounds(casacore::Vector<casacore::Double>& solbounds,
     212             :                                          casacore::Bool scanBounded,casacore::Bool fieldBounded,
     213             :                                          casacore::Double dt);
     214             : 
     215             : };
     216             : 
     217             : } //# NAMESPACE VI - END
     218             : } //# NAMESPACE CASA - END
     219             : 
     220             : #endif

Generated by: LCOV version 1.16