LCOV - code coverage report
Current view: top level - calanalysis/CalAnalysis - CalAnalysisSPW_INFO.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 100 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 7 0.0 %

          Line data    Source code
       1             : 
       2             : // -----------------------------------------------------------------------------
       3             : 
       4             : /*
       5             : 
       6             : CalAnalysisSPW_INFO.cc
       7             : 
       8             : Description:
       9             : ------------
      10             : This file contains member functions for the nested CalAnalysis::SPW_INFO class.
      11             : 
      12             : Classes:
      13             : --------
      14             : CalAnalysis::SPW_INFO - This nested class contains the spectral window
      15             : information for the CalAnalysis class.
      16             : 
      17             : Modification history:
      18             : ---------------------
      19             : 2012 Apr 27 - Nick Elias, NRAO
      20             :               Initial version.
      21             : 
      22             : */
      23             : 
      24             : // -----------------------------------------------------------------------------
      25             : // Includes
      26             : // -----------------------------------------------------------------------------
      27             : 
      28             : #include <calanalysis/CalAnalysis/CalAnalysis.h>
      29             : 
      30             : // -----------------------------------------------------------------------------
      31             : // Start of casa namespace
      32             : // -----------------------------------------------------------------------------
      33             : 
      34             : using namespace casacore;
      35             : namespace casa {
      36             : 
      37             : // -----------------------------------------------------------------------------
      38             : // Start of CalAnalysis::SPW_INFO nested class
      39             : // -----------------------------------------------------------------------------
      40             : 
      41             : /*
      42             : 
      43             : CalAnalysis::SPW_INFO
      44             : 
      45             : Description:
      46             : ------------
      47             : This nested class contains the spectral window information for the CalAnalysis
      48             : class.
      49             : 
      50             : Class public member functions:
      51             : ------------------------------
      52             : SPW_INFO     - This member function constructs an instance of this class using
      53             :                the new calibration table name as an input.
      54             : SPW_INFO     - This member function constructs an instance of this class from
      55             :                another instance.
      56             : SPW_INFO     - This member function constructs a default instance of this class.
      57             : ~SPW_INFO    - This member function destructs an instance of this class.
      58             : operator=    - This member function copies an instance of this class to this
      59             :                instance.
      60             : freq         - This member function creates a frequency vector based on
      61             :                specified spectral window and channel numbers.
      62             : spwInfoCheck - This member function checks and eliminates duplicate spectral
      63             :                window and channel numbers.
      64             : 
      65             : Modification history:
      66             : ---------------------
      67             : 2012 Apr 27 - Nick Elias, NRAO
      68             :               Initial version containing public member functions SPW_INFO()
      69             :               (standard), SPW_INFO() (copy), SPW_INFO() (default), ~SPW_INFO(),
      70             :               operator=(), freq(), and spwInfoCheck().
      71             : 
      72             : */
      73             : 
      74             : // -----------------------------------------------------------------------------
      75             : // Start of CalAnalysis::SPW_INFO public member functions
      76             : // -----------------------------------------------------------------------------
      77             : 
      78             : /*
      79             : 
      80             : CalAnalysis::SPW_INFO::SPW_INFO (standard)
      81             : 
      82             : Description:
      83             : ------------
      84             : This member function constructs an instance of this class using the new
      85             : calibration table name as an input.
      86             : 
      87             : Inputs:
      88             : -------
      89             : oTableName - This reference to a String instance contains the name of the new
      90             :              calibration table name.
      91             : 
      92             : Outputs:
      93             : --------
      94             : None.
      95             : 
      96             : Modification history:
      97             : ---------------------
      98             : 2012 Apr 27 - Nick Elias, NRAO
      99             :               Initial version.
     100             : 
     101             : */
     102             : 
     103             : // -----------------------------------------------------------------------------
     104             : 
     105           0 : CalAnalysis::SPW_INFO::SPW_INFO( const String& oTableName ) {
     106             : 
     107             :   // Get the NAME column from the spectral window subtable
     108             : 
     109           0 :   String oSPWName( oTableName + "/SPECTRAL_WINDOW" );
     110             : 
     111           0 :   CTSpectralWindow oCalSPW( oSPWName, Table::Old );
     112           0 :   ArrayColumn<Double> oFreqACD( MSSpWindowColumns(oCalSPW).chanFreq() );
     113             : 
     114             : 
     115             :   // Initialize this instance
     116             : 
     117           0 :   bValid = true;
     118             : 
     119           0 :   uiNumSPW = oFreqACD.nrow();
     120             : 
     121           0 :   oSPW = Vector<uInt>( uiNumSPW );
     122           0 :   indgen<uInt>( oSPW, 0 );
     123             : 
     124           0 :   oNumChannel = Vector<uInt>( uiNumSPW );
     125           0 :   for ( uInt s=0; s<uiNumSPW; s++ ) oNumChannel[s] = oFreqACD( s ).nelements();
     126             : 
     127           0 :   oFrequency = Vector<Vector<Double> >( uiNumSPW );
     128           0 :   for ( uInt s=0; s<uiNumSPW; s++ ) oFrequency[s] = oFreqACD( s );
     129             : 
     130             : 
     131             :   // Return
     132             : 
     133           0 :   return;
     134             : 
     135           0 : }
     136             : 
     137             : // -----------------------------------------------------------------------------
     138             : 
     139             : /*
     140             : 
     141             : CalAnalysis::SPW_INFO::SPW_INFO (copy)
     142             : 
     143             : Description:
     144             : ------------
     145             : This member function constructs an instance of this class from another instance.
     146             : 
     147             : Inputs:
     148             : -------
     149             : oSPWInfoIn - This reference to a SPW_INFO& instance contains the spectral
     150             :              window information.
     151             : 
     152             : Outputs:
     153             : --------
     154             : None.
     155             : 
     156             : Modification history:
     157             : ---------------------
     158             : 2012 Apr 27 - Nick Elias, NRAO
     159             :               Initial version.
     160             : 
     161             : */
     162             : 
     163             : // -----------------------------------------------------------------------------
     164             : 
     165           0 : CalAnalysis::SPW_INFO::SPW_INFO( const SPW_INFO& oSPWInfoIn ) {
     166             : 
     167             :   // Initialize this instance from the input instance
     168             : 
     169           0 :   bValid = oSPWInfoIn.bValid;
     170             : 
     171           0 :   uiNumSPW = oSPWInfoIn.uiNumSPW;
     172           0 :   oSPW = oSPWInfoIn.oSPW.copy();
     173             : 
     174           0 :   oNumChannel = oSPWInfoIn.oNumChannel.copy();
     175             : 
     176           0 :   oFrequency = Vector<Vector<Double> >( uiNumSPW );
     177           0 :   for ( uInt s=0; s<uiNumSPW; s++ ) {
     178           0 :     oFrequency[s] = oSPWInfoIn.oFrequency[s].copy();
     179             :   }
     180             : 
     181             : 
     182             :   // Return
     183             : 
     184           0 :   return;
     185             : 
     186           0 : }
     187             : 
     188             : // -----------------------------------------------------------------------------
     189             : 
     190             : /*
     191             : 
     192             : CalAnalysis::SPW_INFO::SPW_INFO (default)
     193             : 
     194             : Description:
     195             : ------------
     196             : This member function constructs a default instance of this class.
     197             : 
     198             : Inputs:
     199             : -------
     200             : None.
     201             : 
     202             : Outputs:
     203             : --------
     204             : None.
     205             : 
     206             : Modification history:
     207             : ---------------------
     208             : 2012 Apr 27 - Nick Elias, NRAO
     209             :               Initial version.
     210             : 
     211             : */
     212             : 
     213             : // -----------------------------------------------------------------------------
     214             : 
     215           0 : CalAnalysis::SPW_INFO::SPW_INFO( void ) {
     216             : 
     217             :   // Initialize all instances to their default values
     218             : 
     219           0 :   bValid = false;
     220             : 
     221           0 :   uiNumSPW = 0;
     222           0 :   oSPW = Vector<uInt>();
     223             : 
     224           0 :   oNumChannel = Vector<uInt>();
     225             : 
     226           0 :   oFrequency = Vector<Vector<Double> >();
     227             : 
     228             : 
     229             :   // Return
     230             : 
     231           0 :   return;
     232             : 
     233           0 : }
     234             : 
     235             : // -----------------------------------------------------------------------------
     236             : 
     237             : /*
     238             : 
     239             : CalAnalysis::SPW_INFO::~SPW_INFO
     240             : 
     241             : Description:
     242             : ------------
     243             : This member function destructs an instance of this class.
     244             : 
     245             : Inputs:
     246             : -------
     247             : None.
     248             : 
     249             : Outputs:
     250             : --------
     251             : None.
     252             : 
     253             : Modification history:
     254             : ---------------------
     255             : 2012 Apr 27 - Nick Elias, NRAO
     256             :               Initial version.
     257             : 
     258             : */
     259             : 
     260             : // -----------------------------------------------------------------------------
     261             : 
     262           0 : CalAnalysis::SPW_INFO::~SPW_INFO( void ) {}
     263             : 
     264             : // -----------------------------------------------------------------------------
     265             : 
     266             : /*
     267             : 
     268             : CalAnalysis::SPW_INFO::operator=
     269             : 
     270             : Description:
     271             : ------------
     272             : This member function copies an instance of this class to this instance.
     273             : 
     274             : Inputs:
     275             : -------
     276             : oSPWInfoIn - This reference to a SPW_INFO& instance contains the spectral
     277             :              window information.
     278             : 
     279             : Outputs:
     280             : --------
     281             : None.
     282             : 
     283             : Modification history:
     284             : ---------------------
     285             : 2012 Apr 27 - Nick Elias, NRAO
     286             :               Initial version.
     287             : 
     288             : */
     289             : 
     290             : // -----------------------------------------------------------------------------
     291             : 
     292           0 : CalAnalysis::SPW_INFO& CalAnalysis::SPW_INFO::operator=(
     293             :     const CalAnalysis::SPW_INFO& oSPWInfoIn ) {
     294             : 
     295             :   // Copy the input instance to this instance
     296             : 
     297           0 :   if ( this != &oSPWInfoIn ) {
     298             : 
     299           0 :     bValid = oSPWInfoIn.bValid;
     300             : 
     301           0 :     uiNumSPW = oSPWInfoIn.uiNumSPW;
     302             : 
     303           0 :     oSPW.resize();
     304           0 :     oSPW = oSPWInfoIn.oSPW.copy();
     305             : 
     306           0 :     oNumChannel.resize();
     307           0 :     oNumChannel = oSPWInfoIn.oNumChannel.copy();
     308             : 
     309           0 :     oFrequency.resize();
     310           0 :     oFrequency = Vector<Vector<Double> >( uiNumSPW );
     311           0 :     for ( uInt s=0; s<uiNumSPW; s++ ) {
     312           0 :       oFrequency[s].resize();
     313           0 :       oFrequency[s] = oSPWInfoIn.oFrequency[s].copy();
     314             :     }
     315             : 
     316             :   }
     317             : 
     318             : 
     319             :   // Return the reference to this instance
     320             : 
     321           0 :   return( *this );
     322             : 
     323             : }
     324             : 
     325             : // -----------------------------------------------------------------------------
     326             : 
     327             : /*
     328             : 
     329             : CalAnalysis::SPW_INFO::freq
     330             : 
     331             : Description:
     332             : ------------
     333             : This member function creates a frequency vector based on specified spectral
     334             : window and channel numbers.
     335             : 
     336             : NB: Before using this function, the spectral window and channel numbers should
     337             : be checked by CalAnalysis::SPW_INFO::spwInfoCheck().
     338             : 
     339             : NB: This function now always returns true.  It could return false previously
     340             : because it did some checking.  I have not changed the output of this function
     341             : just in case I want to add checking again.
     342             : 
     343             : Inputs:
     344             : -------
     345             : oSPWIn     - This reference to a Vector<uInt> contains the spectral window
     346             :              numbers.
     347             : oChannelIn - This reference to a Vector<Vector<uInt> > contains the channel
     348             :              numbers for each spectral window number.
     349             : 
     350             : Outputs:
     351             : --------
     352             : oFreqOut - The reference to the Vector<Double> instance containing the
     353             :            frequencies.
     354             : The Bool variable containing the success boolean, returned via
     355             : the function value.
     356             : 
     357             : Modification history:
     358             : ---------------------
     359             : 2012 Apr 27 - Nick Elias, NRAO
     360             :               Initial version.
     361             : 
     362             : */
     363             : 
     364             : // -----------------------------------------------------------------------------
     365             : 
     366           0 : Bool CalAnalysis::SPW_INFO::freq( const Vector<uInt>& oSPWIn,
     367             :     const Vector<Vector<uInt> >& oChannelIn, Vector<Double>& oFreqOut ) const {
     368             : 
     369             :   // Declare the success boolean
     370             : 
     371           0 :   Bool success( false );
     372             : 
     373             : 
     374             :   // Check the inputs
     375             : 
     376           0 :   if ( oSPWIn.nelements() != oChannelIn.nelements() ) {
     377           0 :     success = false;
     378           0 :     return success;
     379             :   }
     380             : 
     381             : 
     382             :   // Initialize the output frequency vector
     383             : 
     384           0 :   oFreqOut.resize();
     385             : 
     386           0 :   uInt uiNumFreqOut = 0;
     387             : 
     388             : 
     389             :   // Load the output frequency vector with the frequencies specified by the
     390             :   // spectral window and channel numbers
     391             : 
     392           0 :   for ( uInt s=0; s<oSPWIn.nelements(); s++ ) {
     393           0 :     for ( uInt c=0; c<oChannelIn[s].nelements(); c++ ) {
     394           0 :       oFreqOut.resize( ++uiNumFreqOut, true );
     395           0 :       oFreqOut[uiNumFreqOut-1] = oFrequency[oSPWIn[s]][oChannelIn[s][c]];
     396             :     }
     397             :   }
     398             : 
     399             : 
     400             :   // Return true
     401             : 
     402           0 :   success = true;
     403             : 
     404           0 :   return success;
     405             : 
     406             : }
     407             : 
     408             : // -----------------------------------------------------------------------------
     409             : 
     410             : /*
     411             : 
     412             : CalAnalysis::SPW_INFO::spwInfoCheck
     413             : 
     414             : Description:
     415             : ------------
     416             : This member function checks and eliminates duplicate spectral window and channel
     417             : numbers.
     418             : 
     419             : NB: The output values are compared against the internal spectral window and
     420             : channel vector instances.
     421             : 
     422             : Inputs:
     423             : -------
     424             : oSPWIn     - This reference to a Vector<uInt> contains the spectral window
     425             :              numbers.
     426             : oChannelIn - This reference to a Vector<Vector<uInt> > contains the channel
     427             :              numbers for each spectral window number.
     428             : 
     429             : Outputs:
     430             : --------
     431             : oSPWOut     - This reference to a Vector<uInt> contains the checked and unique
     432             :               spectral window numbers.
     433             : oChannelOut - This reference to a Vector<Vector<uInt> > contains the checked and
     434             :               unique channel numbers for each spectral window number.
     435             : The reference to the Bool variable containing the check boolean, returned via
     436             : the function value.
     437             : 
     438             : Modification history:
     439             : ---------------------
     440             : 2012 Apr 27 - Nick Elias, NRAO
     441             :               Initial version.
     442             : 
     443             : */
     444             : 
     445             : // -----------------------------------------------------------------------------
     446             : 
     447           0 : Bool CalAnalysis::SPW_INFO::spwInfoCheck( const Vector<uInt>& oSPWIn,
     448             :     const Vector<Vector<uInt> >& oChannelIn, Vector<uInt>& oSPWOut,
     449             :     Vector<Vector<uInt> >& oChannelOut ) const {
     450             : 
     451             :   // Declare the success boolean
     452             : 
     453           0 :   Bool success( false );
     454             : 
     455             : 
     456             :   // Does this instance contain valid spectral window and channel numbers?
     457             : 
     458           0 :   if ( !bValid ) {
     459           0 :     success = false;
     460           0 :     return success;
     461             :   }
     462             : 
     463             : 
     464             :   // Get the output sorted unique spectral window number vector
     465             : 
     466           0 :   oSPWOut.resize();
     467           0 :   unique<uInt>( oSPWIn, oSPWOut );
     468             : 
     469           0 :   uInt uiNumSPWOut = oSPWOut.nelements();
     470             : 
     471             : 
     472             :   // Check the output spectral window numbers
     473             : 
     474           0 :   if ( uiNumSPWOut == 0 ) {
     475           0 :     success = false;
     476           0 :     return success;
     477             :   }
     478             : 
     479           0 :   for ( uInt s=0; s<uiNumSPWOut; s++ ) {
     480           0 :     if ( !exists<uInt>( oSPWOut[s], oSPW ) ) {
     481           0 :       success = false;
     482           0 :       return success;
     483             :     }
     484             :   }
     485             : 
     486             : 
     487             :   // Initialize the output channel vector of vectors.  If the input spectral
     488             :   // window vector has duplicates, the channels corresponding to these
     489             :   // duplicates are concatenated.
     490             : 
     491           0 :   uInt uiNumSPWIn = oSPWIn.nelements();
     492             : 
     493           0 :   oChannelOut.resize( uiNumSPWOut, false );
     494             : 
     495           0 :   for ( uInt so=0; so<uiNumSPWOut; so++ ) {
     496           0 :     oChannelOut[so].resize();
     497           0 :     for ( uInt si=0; si<uiNumSPWIn; si++ ) {
     498           0 :       if ( oSPWIn[si] != oSPWOut[so] ) continue;
     499           0 :       uInt uiNumChannelOut = oChannelOut[so].nelements();
     500           0 :       uInt uiNumChannelIn = oChannelIn[si].nelements();
     501           0 :       for ( uInt c=0; c<uiNumChannelIn; c++ ) {
     502           0 :         oChannelOut[so].resize( ++uiNumChannelOut, true );
     503           0 :         oChannelOut[so][uiNumChannelOut-1] = oChannelIn[si][c];
     504             :       }
     505             :     }
     506             :   }
     507             : 
     508             : 
     509             :   // Get output sorted unique channels within each spectral window
     510             : 
     511           0 :   for ( uInt s=0; s<uiNumSPWOut; s++ ) {
     512           0 :     Vector<uInt> oChannelTemp;
     513           0 :     unique<uInt>(oChannelOut[s], oChannelTemp);
     514           0 :     oChannelOut[s].resize();
     515           0 :     oChannelOut[s] = oChannelTemp;
     516           0 :   }
     517             : 
     518             : 
     519             :   // Check the output channels for each spectral window
     520             : 
     521           0 :   for ( uInt s=0; s<uiNumSPWOut; s++ ) {
     522           0 :     uInt uiNumChannelOut = oChannelOut[s].nelements();
     523           0 :     for ( uInt c=0; c<uiNumChannelOut; c++ ) {
     524           0 :       if ( oChannelOut[s][c] >= oNumChannel[oSPWOut[s]] ) {
     525           0 :         success = false;
     526           0 :         return success;
     527             :       }
     528             :     }
     529             :   }
     530             : 
     531             : 
     532             :   // Return true
     533             : 
     534           0 :   success = true;
     535             : 
     536           0 :   return success;
     537             : 
     538             : }
     539             : 
     540             : // -----------------------------------------------------------------------------
     541             : // End of CalAnalysis::SPW_INFO public member functions
     542             : // -----------------------------------------------------------------------------
     543             : 
     544             : // -----------------------------------------------------------------------------
     545             : // End of CalAnalysis::SPW_INFO nested class
     546             : // -----------------------------------------------------------------------------
     547             : 
     548             : };
     549             : 
     550             : // -----------------------------------------------------------------------------
     551             : // End of casa namespace
     552             : // -----------------------------------------------------------------------------

Generated by: LCOV version 1.16