LCOV - code coverage report
Current view: top level - mstransform/MSTransform - MSTransform.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 75 95 78.9 %
Date: 2024-10-12 00:35:29 Functions: 6 6 100.0 %

          Line data    Source code
       1             : ///# MSTransform.cc: this defines MSTransform
       2             : //# Copyright (C) 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             : #include <stdarg.h>
      28             : #include <sstream>
      29             : #include <iostream>
      30             : #include <vector>
      31             : #include <casacore/casa/Utilities/Regex.h>
      32             : #include <casacore/casa/OS/HostInfo.h>
      33             : #include <casacore/casa/Exceptions/Error.h>
      34             : #include <mstransform/MSTransform/MSTransform.h>
      35             : #include <casacore/casa/stdio.h>
      36             : #include <casacore/casa/math.h>
      37             : 
      38             : using namespace casacore;
      39             : namespace casa {
      40             : 
      41             : 
      42             : // -----------------------------------------------------------------------
      43             : // Default Constructor
      44             : // -----------------------------------------------------------------------
      45          32 : MSTransform::MSTransform () : mdh_p()
      46             : {
      47          32 :         done();
      48          32 : }
      49             : 
      50             : 
      51             : // -----------------------------------------------------------------------
      52             : // Default Destructor
      53             : // -----------------------------------------------------------------------
      54          32 : MSTransform::~MSTransform ()
      55             : {
      56          32 :         done();
      57          32 : }
      58             : 
      59             : void
      60          64 : MSTransform::done()
      61             : {
      62          64 :         if(mdh_p){
      63          32 :             auto *mdh = mdh_p.release();
      64          32 :             delete mdh;
      65             :         }
      66             : 
      67             :         // Default values of parameters
      68          64 :         msname_p = "";
      69          64 :         outputms_p = "";
      70          64 :         spw_p = "";
      71          64 :         scan_p = "";
      72          64 :         field_p = "";
      73          64 :         antenna_p = "";
      74          64 :         timerange_p = "";
      75          64 :         correlation_p = "";
      76          64 :         intent_p = "";
      77          64 :         feed_p = "";
      78          64 :         array_p = "";
      79          64 :         uvrange_p = "";
      80          64 :         observation_p = "";
      81             : 
      82          64 :         config_p = Record();
      83          64 :         datacolumn_p = "CORRECTED";
      84          64 :         isconfigured_p = false;
      85             : 
      86          64 :         return;
      87             : }
      88             : 
      89             : 
      90             : 
      91             : // ---------------------------------------------------------------------
      92             : // MSTransform::configure
      93             : // Configure the MSTransformManager and the parameters.
      94             : // The config Record is mandatory and needs to have at least
      95             : // the parameters for the input and output MSs.
      96             : // This method may be called again to add or change parameters.
      97             : // ---------------------------------------------------------------------
      98             : bool
      99          32 : MSTransform::configure(Record config)
     100             : {
     101          32 :     log_p.origin(LogOrigin("MSTransform", __func__));
     102             : 
     103          32 :         if (config.empty()){
     104           0 :                 log_p << LogIO::SEVERE << "There is no configuration for the tool"
     105           0 :                                 << LogIO::POST;
     106           0 :                 return false;
     107             :         }
     108             : 
     109             :         // First time configuration
     110          32 :         if (!isconfigured_p){
     111             : 
     112             :                 // The minimum configuration is the input and output MS names.
     113          32 :                 if (config.isDefined("inputms"))
     114          32 :                         config.get("inputms", msname_p);
     115             :                 else{
     116           0 :                         log_p << LogIO::SEVERE << "There is no \"inputms\" in configuration Record"
     117           0 :                                 << LogIO::POST;
     118           0 :                         return false;
     119             :                 }
     120             : 
     121          32 :                 if (config.isDefined("outputms"))
     122          32 :                         config.get("outputms", outputms_p);
     123             :                 else{
     124           0 :                         log_p << LogIO::SEVERE << "There is no \"outputms\" in configuration Record"
     125           0 :                                 << LogIO::POST;
     126           0 :                         return false;
     127             :                 }
     128             : 
     129          32 :                 if(mdh_p) {
     130           0 :                    auto *mdh = mdh_p.release();
     131           0 :                    delete mdh;
     132             :                 }
     133             : 
     134             :                 // Create an object for the MSTransformManager
     135          32 :                 mdh_p = std::unique_ptr<MSTransformManager>(new MSTransformManager());
     136             :         }
     137             : 
     138          32 :         config_p = config;
     139             : 
     140             :         // The datacolumn must exist
     141          32 :         if (config_p.isDefined("datacolumn")){
     142          32 :                 config_p.get("datacolumn", datacolumn_p);
     143          32 :                 datacolumn_p.upcase();
     144          32 :                 config_p.define("datacolumn", datacolumn_p);
     145             :         }
     146             :         else {
     147             :                 // Add the default column to the Record
     148           0 :                 config_p.define("datacolumn", datacolumn_p);
     149             :         }
     150             : 
     151             :         // Configure the MSTransformManager object
     152          32 :         mdh_p->configure(config_p);
     153          32 :         isconfigured_p = true;
     154             : 
     155             :         // TODO: should I check all the other parameters in the config_p Record?
     156             :         // Which other parameters should be checked here?
     157             : 
     158          32 :         ostringstream os;
     159          32 :         config_p.print(os);
     160          32 :         String str(os.str());
     161          32 :         log_p << LogIO::DEBUG1 << " Configuration Record " << LogIO::POST;
     162          32 :         log_p << LogIO::DEBUG1 << str << LogIO::POST;
     163             : 
     164          32 :         return true;
     165          32 : }
     166             : 
     167             : 
     168             : // ---------------------------------------------------------------------
     169             : // MSTransform::open
     170             : // Setup the MSTranformDataHandler and generate the iterators
     171             : // It assumes that MSTransform::configure is run first
     172             : // ---------------------------------------------------------------------
     173             : bool
     174          32 : MSTransform::open()
     175             : {
     176             : 
     177          32 :         log_p.origin(LogOrigin("MSTransform", __func__));
     178             : 
     179          32 :         if (! isconfigured_p){
     180           0 :                 log_p << LogIO::SEVERE << "There is no configuration for the tool"
     181           0 :                                 << LogIO::POST;
     182           0 :                 return false;
     183             :         }
     184             : 
     185          32 :         if(!mdh_p){
     186           0 :                 log_p << LogIO::SEVERE << "The tool was not configured" << LogIO::POST;
     187           0 :                 return false;
     188             :         }
     189             : 
     190             :         // Open the MS and select the data
     191          32 :         mdh_p->open();
     192             : 
     193             : 
     194             :         // Setup the DataHandler
     195          32 :         mdh_p->setup();
     196             : 
     197          32 :         return true;
     198             : }
     199             : 
     200             : // ---------------------------------------------------------------------
     201             : // MSTransform::run
     202             : // Run the tool
     203             : // TODO: For the moment it returns a Record, but verify this later
     204             : // ---------------------------------------------------------------------
     205             : Record
     206          32 : MSTransform::run()
     207             : {
     208          32 :     log_p.origin(LogOrigin("MSTransform", __func__));
     209             : 
     210          32 :         if (! mdh_p){
     211           0 :                 log_p << LogIO::SEVERE << "The tool is not configured. Please run mt.config and mt.open first."
     212           0 :                                 << LogIO::POST;
     213           0 :                 return Record();
     214             :         }
     215             : 
     216          32 :         vi::VisibilityIterator2 *visIter = mdh_p->getVisIter();
     217          32 :         vi::VisBuffer2 *vb = visIter->getVisBuffer();
     218          32 :         visIter->originChunks();
     219          75 :         while (visIter->moreChunks())
     220             :         {
     221          43 :                 visIter->origin();
     222         734 :                 while (visIter->more())
     223             :                 {
     224         691 :                         mdh_p->fillOutputMs(vb);
     225         691 :                                 visIter->next();
     226             :                 }
     227             : 
     228          43 :                 visIter->nextChunk();
     229             :         }
     230          32 :         Record result;
     231          32 :         visIter->result(result);
     232          32 :         mdh_p->close();
     233             : 
     234          32 :         return result;
     235          32 : }
     236             : 
     237             : /*
     238             : // ---------------------------------------------------------------------
     239             : // MSTransform::defaultOptions
     240             : // Set the defaults for all the parameters
     241             : // Returns a Record with the default of each parameter
     242             : // ---------------------------------------------------------------------
     243             : Record &
     244             : MSTransform::defaultOptions()
     245             : {
     246             :         Record defaults;
     247             : 
     248             :         defaults.define("inputms", "");
     249             :         defaults.define("outputms", "");
     250             :         defaults.define("createmms", true);
     251             :         defaults.define("separationaxis", "both");
     252             :         defaults.define("numsubms", "");
     253             :         defaults.define("tileshape", "");
     254             :         defaults.define("spw", "");
     255             :         defaults.define("scan", "");
     256             :         defaults.define("antenna", "");
     257             :         defaults.define("array", "");
     258             :         defaults.define("correlation", "");
     259             :         defaults.define("field", "");
     260             :         defaults.define("timerange", "");
     261             :         defaults.define("uvrange", "");
     262             :         defaults.define("state", "");
     263             :         defaults.define("observation", "");
     264             :         defaults.define("datacolumn", "CORRECTED");
     265             :         defaults.define("realmodelcol", false);
     266             :         defaults.define("combinespws", false);
     267             :         defaults.define("freqaverage", false);
     268             :         defaults.define("freqbin", "");
     269             :         defaults.define("useweights", "");
     270             :         defaults.define("hanning", false);
     271             :         defaults.define("regridms", false);
     272             :         defaults.define("mode", "");
     273             :         defaults.define("nchan", "");
     274             :         defaults.define("start", "");
     275             :         defaults.define("width", "");
     276             :         defaults.define("interpolation", "");
     277             :         defaults.define("phasecenter", "");
     278             :         defaults.define("restfreq", "");
     279             :         defaults.define("outframe", "");
     280             :         defaults.define("veltype", "");
     281             :         defaults.define("separatespws", false);
     282             :         defaults.define("nspws", "");
     283             :         defaults.define("timeaverage", false);
     284             :         defaults.define("timebing", "");
     285             :         defaults.define("timespan", "");
     286             :         defaults.define("quantize_c", "");
     287             :         defaults.define("minbaselines", "");
     288             : 
     289             :         return defauts;
     290             : }
     291             : */
     292             : 
     293             : 
     294             : // ---------------------------------------------------------------------
     295             : // MSTransform::validateDataColumn
     296             : // Check if datacolumn is valid
     297             : // Return validated datacolumn
     298             : // ---------------------------------------------------------------------
     299             : /*
     300             : String
     301             : MSTransform::validateDataColumn(String datacol)
     302             : {
     303             :         String ret = "";
     304             :         Bool checkcol = false;
     305             :         datacol.upcase();
     306             : 
     307             :         LogIO log_p(LogOrigin("MSTransform", __FUNCTION__, WHERE));
     308             : 
     309             :         if (mdh_p->checkIfColumnExists(datacol))
     310             :                 ret = datacol;
     311             :         else {
     312             :                 // Check if default column exist
     313             :                 if (mdh_p->checkIfColumnExists("CORRECTED"))
     314             :                         ret = "CORRECTED";
     315             :         }
     316             : 
     317             :         return ret;
     318             : }
     319             : */
     320             : 
     321             : 
     322             : 
     323             : } //#end casa namespace
     324             : 
     325             : 

Generated by: LCOV version 1.16