LCOV - code coverage report
Current view: top level - synthesis/CalTables - CTInterface.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 24 39 61.5 %
Date: 2024-10-12 00:35:29 Functions: 7 8 87.5 %

          Line data    Source code
       1             : //# CTInterface.cc: Implementation of CTInterface class
       2             : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2003
       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             : 
      29             : #include <synthesis/CalTables/CTInterface.h>
      30             : #include <casacore/ms/MeasurementSets/MSColumns.h>
      31             : 
      32             : #include <unordered_set>
      33             : 
      34             : using namespace casacore;
      35             : namespace casa { //# NAMESPACE CASA - BEGIN
      36             : 
      37             :   //
      38             :   //----------------------------------------------------------------------------
      39             :   //
      40         188 :   CTInterface::CTInterface(const Table& table)
      41         188 :     :MSSelectableTable(table), fakeDDSubTable(),  ctMainCols_p(NULL) 
      42         188 :   {makeDDSubTable();};
      43             :   //
      44             :   //----------------------------------------------------------------------------
      45             :   //
      46         367 :   CTInterface::~CTInterface() 
      47         367 :   {if (ctMainCols_p) delete ctMainCols_p;};
      48             :   //
      49             :   //----------------------------------------------------------------------------
      50             :   //
      51         401 :   const NewCalTable* CTInterface::asCT()
      52             :   {
      53         401 :     return static_cast<const NewCalTable *>(table());
      54             :   };
      55             :   //
      56             :   //----------------------------------------------------------------------------
      57             :   //
      58         188 :   void CTInterface::makeDDSubTable()
      59             :   {
      60             :     //
      61             :     // Make an in-memory DataDescription table.
      62             :     //
      63           0 :     SetupNewTable setup(String(""), MSDataDescription::requiredTableDesc(), 
      64         188 :       Table::Scratch);
      65         188 :     const Table tmpTab(setup, Table::Memory, spectralWindow().nrow());
      66         188 :     fakeDDSubTable = MSDataDescription(tmpTab);
      67             :     //
      68             :     // Call the in-memory table what it is.
      69             :     //
      70         188 :     TableInfo& tabInfo=fakeDDSubTable.tableInfo();
      71         188 :     tabInfo.setType("FAKE_DATA_DESCRIPTION_ID");
      72             :     //
      73             :     // Fill the required columns (flagRow and spectralWindowId).
      74             :     // These should ideally be just referenced, but I (SB) could not
      75             :     // figure out how to do it.
      76             :     //
      77         188 :     Vector<Bool> spwFlagRow=MSSpWindowColumns(spectralWindow()).flagRow().getColumn();
      78         188 :     MSDataDescColumns(fakeDDSubTable).flagRow().putColumn(spwFlagRow);
      79             : 
      80         188 :     Vector<Int> spwId(fakeDDSubTable.nrow()); indgen(spwId);
      81         188 :     MSDataDescColumns(fakeDDSubTable).spectralWindowId().putColumn(spwId);
      82         188 :   }
      83             :   //
      84             :   //----------------------------------------------------------------------------
      85             :   //
      86          14 :   const MSDataDescription& CTInterface::dataDescription() 
      87             :   {
      88          14 :     return fakeDDSubTable;
      89             :   }
      90             :   //
      91             :   //----------------------------------------------------------------------------
      92             :   // For CalTables, MS::DATA_DESC_ID maps to
      93             :   // CTEnums::SPECTRAL_WINDOW_ID.  So do only that translation.
      94             :   //
      95         573 :   String CTInterface::columnName(MSMainEnums::PredefinedColumns nameEnum) 
      96             :   {
      97         573 :     if (nameEnum == MS::DATA_DESC_ID)
      98          14 :       return CTEnums::fieldName(CTEnums::SPECTRAL_WINDOW_ID);
      99             :     else
     100         559 :       return MS::columnName(nameEnum);
     101             :   }
     102             :   //
     103             :   //----------------------------------------------------------------------------
     104             :   // Return the type of the CalTable.  Possibilities are defined in
     105             :   // the MSSelectableTable::MSSDataType enum.
     106             :   //  o For MSSelectableTable::MSSDataType::PURE_ANTENNA_BASED, only 
     107             :   //    ANTENN1 is matched and the "&" operators in selection expressions
     108             :   //    are ignored.
     109             :   //  o For MSSelectableTable::MSSDataType::REF_ANTENNA_BASED, ANTENN2
     110             :   //    is interpreted as a reference antenna and matched against the
     111             :   //    the ANT2 in a ANT2&ANT2 type expressions.
     112             :   //
     113             :   // This is the method called in the MSSelection module to determine
     114             :   // the appropriate rule-resolution.  Any CalTable type based
     115             :   // determination of the MSDataType should be done here.
     116             : 
     117           0 :   MSSelectableTable::MSSDataType CTInterface::dataType()
     118             :   {
     119           0 :     const NewCalTable* nct = asCT();
     120           0 :     casacore::ScalarColumn<casacore::Int> ant1col(*nct, "ANTENNA1");
     121           0 :     casacore::Vector<casacore::Int> ant1 = ant1col.getColumn();
     122           0 :     casacore::ScalarColumn<casacore::Int> ant2col(*nct, "ANTENNA2");
     123           0 :     casacore::Vector<casacore::Int> ant2 = ant2col.getColumn();
     124             : 
     125             :     // Check if ant2 is -1, all antennas, or subset of antennas
     126             :     // For SD caltables where ANT1=ANT2 in all rows, treat as pure
     127           0 :     if ((ant2(0) == -1) || allEQ(ant1, ant2)) {
     128           0 :       return MSSelectableTable::PURE_ANTENNA_BASED;
     129             :     } else {
     130           0 :       std::unordered_set<casacore::Int> ant2set(ant2.begin(), ant2.end());
     131           0 :       if (ant2set.size() == nct->antenna().nrow()) {
     132           0 :         return MSSelectableTable::BASELINE_BASED;
     133             :       } else {
     134           0 :         return MSSelectableTable::REF_ANTENNA_BASED;
     135             :       }
     136           0 :     }
     137           0 :   }
     138             : 
     139             :   //
     140             :   //----------------------------------------------------------------------------
     141             :   // CalTables have no OBSERVATION sub-table.  So throw a tantrum if
     142             :   // it is asked for.
     143             :   //
     144             :   //  const MSObservation& CTInterface::observation()
     145             :   //  {
     146             :   //    throw(AipsError("Internal error: OBSERVATION sub-table for CalTables requested"));
     147             :   //  };
     148             :   //----------------------------------------------------------------------------
     149             : } //# NAMESPACE CASA - END
     150             : 

Generated by: LCOV version 1.16