LCOV - code coverage report
Current view: top level - mstransform/MSTransform - MSTransform.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 73 93 78.5 %
Date: 2023-11-06 10:06:49 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: aips2-request@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        1168 : MSTransform::MSTransform () : mdh_p()
      46             : {
      47        1168 :         done();
      48        1168 : }
      49             : 
      50             : 
      51             : // -----------------------------------------------------------------------
      52             : // Default Destructor
      53             : // -----------------------------------------------------------------------
      54        1168 : MSTransform::~MSTransform ()
      55             : {
      56        1168 :         done();
      57        1168 : }
      58             : 
      59             : void
      60        2336 : MSTransform::done()
      61             : {
      62        2336 :         if(mdh_p){
      63        1138 :             auto *mdh = mdh_p.release();
      64        1138 :             delete mdh;
      65             :         }
      66             : 
      67             :         // Default values of parameters
      68        2336 :         msname_p = "";
      69        2336 :         outputms_p = "";
      70        2336 :         spw_p = "";
      71        2336 :         scan_p = "";
      72        2336 :         field_p = "";
      73        2336 :         antenna_p = "";
      74        2336 :         timerange_p = "";
      75        2336 :         correlation_p = "";
      76        2336 :         intent_p = "";
      77        2336 :         feed_p = "";
      78        2336 :         array_p = "";
      79        2336 :         uvrange_p = "";
      80        2336 :         observation_p = "";
      81             : 
      82        2336 :         config_p = Record();
      83        2336 :         datacolumn_p = "CORRECTED";
      84        2336 :         isconfigured_p = false;
      85             : 
      86        2336 :         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        1138 : MSTransform::configure(Record config)
     100             : {
     101        1138 :     log_p.origin(LogOrigin("MSTransform", __func__));
     102             : 
     103        1138 :         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        1138 :         if (!isconfigured_p){
     111             : 
     112             :                 // The minimum configuration is the input and output MS names.
     113        1138 :                 if (config.isDefined("inputms"))
     114        1138 :                         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        1138 :                 if (config.isDefined("outputms"))
     122        1138 :                         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        1138 :                 if(mdh_p) {
     130           0 :                    auto *mdh = mdh_p.release();
     131           0 :                    delete mdh;
     132             :                 }
     133             : 
     134             :                 // Create an object for the MSTransformManager
     135        1138 :                 mdh_p = std::unique_ptr<MSTransformManager>(new MSTransformManager());
     136             :         }
     137             : 
     138        1138 :         config_p = config;
     139             : 
     140             :         // The datacolumn must exist
     141        1138 :         if (config_p.isDefined("datacolumn")){
     142        1138 :                 config_p.get("datacolumn", datacolumn_p);
     143        1138 :                 datacolumn_p.upcase();
     144        1138 :                 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        1138 :         mdh_p->configure(config_p);
     153        1138 :         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        2276 :         ostringstream os;
     159        1138 :         config_p.print(os);
     160        1138 :         String str(os.str());
     161        1138 :         log_p << LogIO::DEBUG1 << " Configuration Record " << LogIO::POST;
     162        1138 :         log_p << LogIO::DEBUG1 << str << LogIO::POST;
     163             : 
     164        1138 :         return true;
     165             : }
     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        1138 : MSTransform::open()
     175             : {
     176             : 
     177        1138 :         log_p.origin(LogOrigin("MSTransform", __func__));
     178             : 
     179        1138 :         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        1138 :         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        1138 :         mdh_p->open();
     192             : 
     193             : 
     194             :         // Setup the DataHandler
     195        1117 :         mdh_p->setup();
     196             : 
     197        1106 :         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        1106 : MSTransform::run()
     207             : {
     208        1106 :     log_p.origin(LogOrigin("MSTransform", __func__));
     209             : 
     210        1106 :         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        1106 :         vi::VisibilityIterator2 *visIter = mdh_p->getVisIter();
     217        1106 :         vi::VisBuffer2 *vb = visIter->getVisBuffer();
     218        1106 :         visIter->originChunks();
     219       20574 :         while (visIter->moreChunks())
     220             :         {
     221       19468 :                 visIter->origin();
     222      342686 :                 while (visIter->more())
     223             :                 {
     224      323218 :                         mdh_p->fillOutputMs(vb);
     225      323218 :                                 visIter->next();
     226             :                 }
     227             : 
     228       19468 :                 visIter->nextChunk();
     229             :         }
     230        2212 :         Record result;
     231        1106 :         visIter->result(result);
     232        1106 :         mdh_p->close();
     233             : 
     234        1106 :         return result;
     235             : }
     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