LCOV - code coverage report
Current view: top level - msvis/MSVis - LayeredVi2Factory.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 59 104 56.7 %
Date: 2024-11-06 17:42:47 Functions: 6 10 60.0 %

          Line data    Source code
       1             : //# LayeredVi2Factory.cc: Implementation of the LayeredVi2Factory class.
       2             : //#
       3             : //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
       4             : //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
       5             : //#  Copyright (C) European Southern Observatory, 2011, All rights reserved.
       6             : //#
       7             : //#  This library is free software; you can redistribute it and/or
       8             : //#  modify it under the terms of the GNU Lesser General Public
       9             : //#  License as published by the Free software Foundation; either
      10             : //#  version 2.1 of the License, or (at your option) any later version.
      11             : //#
      12             : //#  This library is distributed in the hope that it will be useful,
      13             : //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
      14             : //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             : //#  Lesser General Public License for more details.
      16             : //#
      17             : //#  You should have received a copy of the GNU Lesser General Public
      18             : //#  License along with this library; if not, write to the Free Software
      19             : //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      20             : //#  MA 02111-1307  USA
      21             : //# $Id: $
      22             : 
      23             : #include <msvis/MSVis/LayeredVi2Factory.h>
      24             : 
      25             : 
      26             : #include <stdcasa/UtilJ.h>
      27             : #include <msvis/MSVis/VisibilityIterator2.h>
      28             : #include <msvis/MSVis/VisibilityIteratorImpl2.h>
      29             : #include <msvis/MSVis/VisBuffer2.h>
      30             : #include <msvis/MSVis/AveragingTvi2.h>
      31             : #include <msvis/MSVis/IteratingParameters.h>
      32             : #include <msvis/MSVis/AveragingVi2Factory.h>
      33             : #include <msvis/MSVis/CalibratingVi2FactoryI.h>
      34             : #include <msvis/MSVis/ViFrequencySelection.h>
      35             : #include <casacore/casa/BasicSL/String.h>
      36             : 
      37             : using namespace casacore;
      38             : namespace casa { //# NAMESPACE CASA - BEGIN
      39             : namespace vi { //# NAMESPACE VI - BEGIN
      40             : 
      41             : 
      42             : // -----------------------------------------------------------------------
      43           0 : LayeredVi2Factory::LayeredVi2Factory(MeasurementSet* ms,
      44             :                                      IteratingParameters* iterpar,
      45           0 :                                      AveragingParameters* avepar) :
      46           0 :   ms_p(ms),
      47           0 :   iterpar_p(iterpar),
      48           0 :   avepar_p(avepar),
      49           0 :   doCal_p(false),
      50           0 :   callib_p(""),
      51           0 :   calrec_p(),  
      52           0 :   nlayer_p(1),
      53           0 :   calvi2factory_p(0)
      54             : {
      55             : 
      56             :   // Count requested layers
      57           0 :   if (avepar_p) ++nlayer_p;
      58             : 
      59           0 : }
      60             : // -----------------------------------------------------------------------
      61           9 : LayeredVi2Factory::LayeredVi2Factory(MeasurementSet* ms,
      62             :                                      IteratingParameters* iterpar,
      63             :                                      const Record& calrec,
      64           9 :                                      AveragingParameters* avepar) :
      65           9 :   ms_p(ms),
      66           9 :   iterpar_p(iterpar),
      67           9 :   avepar_p(avepar),
      68           9 :   doCal_p(false),
      69           9 :   callib_p(""),
      70           9 :   calrec_p(calrec),  // This ctor, by Record _only_
      71           9 :   nlayer_p(1),
      72           9 :   calvi2factory_p(0)
      73             : {
      74             : 
      75             :   // Count requested layers
      76           9 :   if (avepar_p) ++nlayer_p;
      77             : 
      78             :   // ...and arrange for calibration, if necessary
      79           9 :   if (calrec_p.nfields()>0) {
      80           9 :     ++nlayer_p;  
      81           9 :     doCal_p=true;
      82             : 
      83             :     // Set up the CalibratingVi2Factory (via Record)
      84           9 :     calvi2factory_p = CalibratingVi2FactoryI::generate();
      85           9 :     calvi2factory_p->initialize(ms,calrec);
      86             :   }
      87             : 
      88           9 : }
      89             : 
      90             : // -----------------------------------------------------------------------
      91           0 : LayeredVi2Factory::LayeredVi2Factory(MeasurementSet* ms,
      92             :                                      IteratingParameters* iterpar,
      93             :                                      const String& callib,
      94           0 :                                      AveragingParameters* avepar) :
      95           0 :   ms_p(ms),
      96           0 :   iterpar_p(iterpar),
      97           0 :   avepar_p(avepar),
      98           0 :   doCal_p(false),
      99           0 :   callib_p(callib),    // This ctor, by String _only_
     100           0 :   calrec_p(),
     101           0 :   nlayer_p(1),
     102           0 :   calvi2factory_p(0)
     103             : {
     104             : 
     105             :   // Count requested layers
     106           0 :   if (avepar_p) ++nlayer_p;
     107             : 
     108             : 
     109           0 :   if (callib_p.length()>0) {
     110           0 :     ++nlayer_p;  
     111           0 :     doCal_p=true;  // Calibration is turned on
     112             : 
     113             :     // Set up the CalibratingVi2Factory (via String)
     114           0 :     calvi2factory_p = CalibratingVi2FactoryI::generate();
     115           0 :     calvi2factory_p->initialize(ms,callib_p);
     116             :   }
     117             : 
     118           0 : }
     119             : 
     120             : // -----------------------------------------------------------------------
     121           9 : LayeredVi2Factory::~LayeredVi2Factory() {
     122             : 
     123             :   // Delete the CalibratingVi2FactorI*, if present
     124           9 :   if (calvi2factory_p)
     125           9 :     delete calvi2factory_p;
     126             : 
     127           9 : }
     128             : 
     129             : 
     130             : // -----------------------------------------------------------------------
     131           9 : vi::ViImplementation2 * LayeredVi2Factory::createVi () const
     132             : {
     133             : 
     134             :   //  cout << "MSVis::LayeredVi2Factor::createVi" << endl;
     135             : 
     136             : 
     137             :   // A Vector of Vii's to fill up and delegate, will return the last one
     138           9 :   Vector<vi::ViImplementation2*> viis(nlayer_p);
     139             : 
     140             :   // The bottom layer is the standard vii2 that does I/O
     141           9 :   Int ilayer(0);
     142          18 :   viis[ilayer]= new vi::VisibilityIteratorImpl2 (Block<const MeasurementSet*>(1,ms_p),
     143           9 :                                                  iterpar_p->getSortColumns(),
     144           9 :                                                  iterpar_p->getChunkInterval(),
     145           9 :                                                  true); // writable!  (hardwired?)
     146             :   
     147             :   // TBD: consider if this is the layer where weight scaling should be applied?
     148           9 :   viis[ilayer]->setWeightScaling(iterpar_p->getWeightScaling());
     149             : 
     150             :   // If calibration requested
     151           9 :   if (doCal_p) {
     152           9 :     ++ilayer;
     153           9 :     Assert(ilayer<nlayer_p);
     154             :     // Call the factory
     155           9 :     viis[ilayer] = calvi2factory_p->createVi(viis[ilayer-1]);
     156             :   }
     157             : 
     158             :   // If (time) averaging requested
     159           9 :   if (avepar_p) {
     160           0 :     ++ilayer;
     161           0 :     Assert(ilayer<nlayer_p);
     162             :     // TBD: update the AveragingVi2Factory to permit layered createVi...
     163           0 :     viis[ilayer] = new AveragingTvi2(viis[ilayer-1],*avepar_p);
     164             :   }
     165             : 
     166             :   // Must be at the last layer now
     167           9 :   Assert((nlayer_p-ilayer)==1);
     168           9 :   Assert(viis[nlayer_p-1]);
     169             : 
     170             :   // Return outermost ViImplementation2 layer
     171          18 :   return viis[nlayer_p-1];
     172             : 
     173           9 : }
     174             : 
     175             : //////////////////////////////////////////////////////////////////////
     176             : //
     177             : // Class VisIterImpl2LayerFactory
     178             : //
     179        1416 : VisIterImpl2LayerFactory::VisIterImpl2LayerFactory(MeasurementSet* ms,
     180             :                                                    const IteratingParameters& pars,
     181             :                                                    Bool writable,
     182        1416 :                                                    Bool useMSIter2)
     183             : : ViiLayerFactory(),
     184        1416 :   ms_(ms),
     185        1416 :   pars_(pars),
     186        1416 :   writable_(writable),
     187        1416 :   useMSIter2_(useMSIter2),
     188        1416 :   fullSortingSpecification_p(false)
     189        1416 : {}
     190             :   
     191           0 : VisIterImpl2LayerFactory::VisIterImpl2LayerFactory(casacore::MeasurementSet * ms,
     192             :                                                    const SortColumns & chunkSortColumns,
     193             :                                                    const SortColumns & subchunkSortColumns,
     194           0 :                                                    bool writable)
     195             : : ViiLayerFactory(),
     196           0 :   ms_(ms),
     197           0 :   writable_(writable),
     198           0 :   useMSIter2_(false),
     199           0 :   fullSortingSpecification_p(true),
     200           0 :   chunkSortColumns_p(chunkSortColumns),
     201           0 :   subchunkSortColumns_p(subchunkSortColumns)
     202           0 : {}
     203             : 
     204         191 : void VisIterImpl2LayerFactory::setFrequencySelections(std::shared_ptr<FrequencySelections> selections)
     205             : {
     206         191 :   frequencySelections_p = selections;
     207         191 : }
     208             : 
     209             : // VisIterImpl2-specific layer-creater
     210        1416 : ViImplementation2 * VisIterImpl2LayerFactory::createInstance (ViImplementation2* /*vii0*/) const {
     211             : 
     212             :   // No deeper layers   (Uncomment and figure out pesky warning!)
     213             :   //  Assert(!vii0);
     214             :   
     215             :   // Make it and return it
     216             :   ViImplementation2 *vii;
     217        1416 :   if(fullSortingSpecification_p)
     218           0 :     vii = new VisibilityIteratorImpl2(Block<const MeasurementSet*>(1,ms_),
     219           0 :                                       chunkSortColumns_p,
     220           0 :                                       subchunkSortColumns_p,
     221           0 :                                       writable_);
     222             : 
     223             :   else
     224        2832 :     vii = new VisibilityIteratorImpl2(Block<const MeasurementSet*>(1,ms_),
     225        1416 :                                       pars_.getSortColumns(),
     226        1416 :                                       pars_.getChunkInterval(),
     227        1416 :                                       writable_,
     228        1416 :                                       useMSIter2_);
     229             :   
     230        1416 :   if(frequencySelections_p)
     231         191 :     vii->setFrequencySelections(*frequencySelections_p);
     232             : 
     233        1416 :   return vii;
     234             : }
     235             : 
     236             : 
     237             : 
     238             : 
     239             : } //# NAMESPACE VI - END
     240             : } //# NAMESPACE CASA - END
     241             : 
     242             : 

Generated by: LCOV version 1.16