LCOV - code coverage report
Current view: top level - synthesis/TransformMachines2 - VB2CFBMap.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 172 0.0 %
Date: 2024-10-28 15:53:10 Functions: 0 6 0.0 %

          Line data    Source code
       1             : //-*- C++ -*-
       2             : //# VB2CFBMap.h: Definition of the VB2CFBMap class
       3             : //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
       4             : //# Associated Universities, Inc. Washington DC, USA.
       5             : //#
       6             : //# This library is free software; you can redistribute it and/or modify it
       7             : //# under the terms of the GNU Library General Public License as published by
       8             : //# the Free Software Foundation; either version 2 of the License, or (at your
       9             : //# option) any later version.
      10             : //#
      11             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      12             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      14             : //# License for more details.
      15             : //#
      16             : //# You should have received a copy of the GNU Library General Public License
      17             : //# along with this library; if not, write to the Free Software Foundation,
      18             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      19             : //#
      20             : //# Correspondence concerning AIPS++ should be addressed as follows:
      21             : //#        Internet email: casa-feedback@nrao.edu.
      22             : //#        Postal address: AIPS++ Project Office
      23             : //#                        National Radio Astronomy Observatory
      24             : //#                        520 Edgemont Road
      25             : //#                        Charlottesville, VA 22903-2475 USA
      26             : //#
      27             : //# $Id$
      28             : //
      29             : #include <synthesis/TransformMachines/SynthesisMath.h>
      30             : #include <casacore/casa/Logging/LogIO.h>
      31             : #include <casacore/casa/Logging/LogSink.h>
      32             : #include <casacore/casa/Logging/LogOrigin.h>
      33             : #include <casacore/casa/Arrays/Matrix.h>
      34             : #include <casacore/casa/Arrays/Vector.h>
      35             : #include <casacore/casa/Arrays/Array.h>
      36             : #include <casacore/casa/Utilities/CountedPtr.h>
      37             : #include <synthesis/TransformMachines2/CFStore2.h>
      38             : #include <synthesis/TransformMachines2/ConvolutionFunction.h>
      39             : #include <synthesis/TransformMachines2/CFBuffer.h>
      40             : #include <msvis/MSVis/VisBuffer2.h>
      41             : #include <synthesis/TransformMachines2/VB2CFBMap.h>
      42             : #include <synthesis/TransformMachines2/Utils.h>
      43             : namespace casa{
      44             :   using namespace vi;
      45             :   namespace refim{
      46           0 :     Int mapAntIDToAntType(const casacore::Int& /*ant*/) {return 0;};
      47             : 
      48           0 :     VB2CFBMap::VB2CFBMap(): vb2CFBMap_p(), cfPhaseGrad_p(), baselineType_p(), vectorPhaseGradCalculator_p(), doPointing_p(false), cachedFieldId_p(-1), vbRow2BLMap_p(), vbRows_p(0), sigmaDev(2), cachedCFBPtr_p(), maxCFShape_p(2), timer_p(),computePhaseScreen_p(true)
      49             :     {
      50           0 :       baselineType_p = new BaselineType();
      51           0 :       needsNewPOPG_p = false;
      52           0 :       needsNewFieldPG_p = false;
      53           0 :       totalCost_p=totalVB_p = 0.0;
      54           0 :       blNeedsNewPOPG_p.resize(0);
      55           0 :       blType_p=0;
      56           0 :       vectorPhaseGradCalculator_p.resize(0);
      57             :       // sigmaDev = SynthesisUtils::getenv("PO_SIGMADEV",3.0);
      58           0 :     };
      59             : 
      60           0 :     VB2CFBMap& VB2CFBMap::operator=(const VB2CFBMap& other)
      61             :     {
      62           0 :       if(this!=&other) 
      63             :         {
      64           0 :           baselineType_p = other.baselineType_p;
      65           0 :           cfPhaseGrad_p.assign(other.cfPhaseGrad_p);
      66           0 :           vb2CFBMap_p.assign(other.vb2CFBMap_p);
      67           0 :           vbRow2BLMap_p = other.vbRow2BLMap_p;
      68           0 :           vectorPhaseGradCalculator_p.assign(other.vectorPhaseGradCalculator_p);
      69           0 :           doPointing_p = other.doPointing_p;
      70           0 :           computePhaseScreen_p = other.computePhaseScreen_p;
      71             :         }
      72           0 :       return *this;
      73             :     };
      74             : 
      75             :     // void VB2CFBMap::setPhaseGradPerRow(const CountedPtr<PointingOffsets>& pointingOffset,
      76             :     //                                 const casacore::CountedPtr<CFBuffer>& cfb,
      77             :     //                                 const vi::VisBuffer2& vb,
      78             :     //                                 const int& row)
      79             :     // {
      80             :     //   // if (doPointing_p)
      81             :     //   //     {
      82             :     //   //       if (phaseGradCalculator_p->needsNewPhaseGrad(pointingOffset, vb, 0))
      83             :     //   //         {
      84             :     //   //           phaseGradCalculator_p->ComputeFieldPointingGrad(pointingOffset,cfb,vb, 0);
      85             :     //   //           newPhaseGradComputed_p=true;
      86             :     //   //         }
      87             :     //   //     }
      88             :     //   // else
      89             :     //  {
      90             :     //    baselineType_p->phaseGradCalculator_p->ComputeFieldPointingGrad(pointingOffset,cfb,vb, 0);
      91             :     //  }
      92             :     //  {
      93             :     //    //cfPhaseGrad_p(row).assign(phaseGradCalculator_p->getFieldPointingGrad());
      94             :     //    cfPhaseGrad_p(row).reference(baselineType_p->phaseGradCalculator_p->field_phaseGrad_p);
      95             :     //  }
      96             :     // }
      97             : 
      98           0 :     void VB2CFBMap::setBLNeedsNewPOPG(vector<int>& vbRow2BLMap_p)
      99             :     {
     100           0 :       blNeedsNewPOPG_p.resize(vbRow2BLMap_p.size(),false);
     101           0 :       vector<int> uniqueVbRow2BLMap_p = vbRow2BLMap_p;
     102           0 :       sort(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     103           0 :       auto itrBLMap = unique(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     104           0 :       uniqueVbRow2BLMap_p.erase(itrBLMap,uniqueVbRow2BLMap_p.end());
     105             :       
     106           0 :       for(unsigned int ii=0; ii < uniqueVbRow2BLMap_p.size(); ii++)
     107             :         {
     108           0 :           int idx = baselineType_p->returnIdx(vbRow2BLMap_p, uniqueVbRow2BLMap_p[ii]);
     109           0 :           blNeedsNewPOPG_p[idx] = true;
     110             :           // cerr << "unqVb2BL: "<< uniqueVbRow2BLMap_p[ii] << " ii " << ii << endl;
     111             :         }
     112             : 
     113             :       
     114           0 :     }
     115             : 
     116             : 
     117             : 
     118             :     //______________________________________________________
     119             :     
     120           0 :     Int VB2CFBMap::makeVBRow2CFBMap(CFStore2& cfs,
     121             :                                     const VisBuffer2& vb, 
     122             :                                     const Quantity& dPA,
     123             :                                     const Vector<Int>& /*dataChan2ImChanMap*/,
     124             :                                     const Vector<Int>& /*dataPol2ImPolMap*/,
     125             :                                     const CountedPtr<PointingOffsets>& pointingOffsets_p)
     126             :     //const Bool& /*doPointing*/)
     127             :     {
     128             :       //    VBRow2CFMapType& vbRow2CFMap_p,
     129           0 :       const Int nRow=vb.nRows(); 
     130             :       //UNUSED: nChan=dataChan2ImChanMap.nelements(), 
     131             :       //UNUSED: nPol=dataPol2ImPolMap.nelements();
     132             :       //    vbRow2CFMap_p.resize(nPol, nChan, nRow);
     133           0 :       vb2CFBMap_p.resize(nRow);
     134           0 :       cfPhaseGrad_p.resize(nRow);
     135           0 :       maxCFShape_p.resize(2,0);
     136           0 :       if(cachedFieldId_p != vb.fieldId()[0])
     137             :         {
     138           0 :           needsNewFieldPG_p = true;
     139           0 :           needsNewPOPG_p = true;
     140           0 :           baselineType_p->setCachedGroups(false);
     141           0 :           cachedFieldId_p = vb.fieldId()[0];
     142           0 :           vectorPhaseGradCalculator_p.resize(0);
     143           0 :           vbRows_p = vb.nRows();
     144             :         }
     145             :       // else if (vbRows_p == 0)
     146             :       //        {
     147             :       //          vbRows_p = vb.nRows();
     148             :       //          baselineType_p->setCachedGroups(false);
     149             :       //          needsNewPOPG_p = false;
     150             :       //        }
     151           0 :       else if (vbRows_p != vb.nRows())
     152             :         {
     153           0 :           vbRows_p = vb.nRows();
     154           0 :           baselineType_p->setCachedGroups(false);
     155           0 :           needsNewPOPG_p = true;
     156             :         }
     157             :       else
     158             :         {
     159           0 :           baselineType_p->setCachedGroups(true);
     160           0 :           needsNewPOPG_p = false;
     161             :         }
     162             :       
     163             : 
     164           0 :       Quantity pa(getPA(vb),"rad");
     165             :       //PolOuterProduct outerProduct;
     166           0 :       Int statusCode=CFDefs::MEMCACHE;
     167             : 
     168             :       // baselineType_p->setCacheGroups(vbRows_p, vb);
     169             :       // baselineType_p->setCachedGroups(true);
     170           0 :       baselineType_p->setDoPointing(doPointing_p);
     171             : 
     172             : 
     173           0 :       if(doPointing_p)
     174             :         {
     175             :           // cerr<<"VB2CFBMap::makeVBRow2CFBMap DoP = T"<<endl;
     176           0 :           Float A2R = 4.848137E-06;
     177           0 :           Vector<Double> poIncrement = pointingOffsets_p->getIncrement();
     178             :           Double offsetDeviation;
     179           0 :           if(sigmaDev[0] > 0)
     180           0 :             offsetDeviation = sigmaDev[0] * A2R / sqrt(poIncrement[0]*poIncrement[0] + poIncrement[1]*poIncrement[1]);
     181             :           else
     182           0 :             offsetDeviation = 1e-3*A2R / sqrt(poIncrement[0]*poIncrement[0] + poIncrement[1]*poIncrement[1]);
     183           0 :           if(sigmaDev[1] == 0)
     184           0 :             sigmaDev[1] = sigmaDev[0];
     185             : 
     186           0 :           baselineType_p->findAntennaGroups(vb,pointingOffsets_p, offsetDeviation);
     187             : 
     188           0 :           baselineType_p->makeVBRow2BLGMap(vb);
     189           0 :           vbRow2BLMap_p = baselineType_p->getVBRow2BLMap();
     190             :           // if(cachedFieldId_p != vb.fieldId()[0])
     191           0 :           if(needsNewPOPG_p)
     192             :             {
     193           0 :               setBLNeedsNewPOPG(vbRow2BLMap_p);
     194             :               // cerr << "Setting blNeedsNewPOPG_p" <<endl;
     195             :               // for (unsigned int ii= 0; ii < blNeedsNewPOPG_p.size();ii++)
     196             :               //        cerr << "row " << ii << " "<<blNeedsNewPOPG_p[ii] << endl;
     197             :             }
     198             : 
     199             : 
     200             :           // cerr << "vbRow2BLMap_p" ;
     201             :           // for(int i=0; i <= vbRow2BLMap_p.size(); i++)
     202             :           //   cerr << vbRow2BLMap_p[i]<<" ";
     203             :           // cerr <<endl;
     204             :           // cerr << "baselineType->cachedGroups_p : "<< baselineType_p->cachedGroups_p <<endl;
     205           0 :           if(baselineType_p->getCachedGroups())
     206             :             {
     207           0 :               Vector < Vector <Double> > cachedAntPO_l = baselineType_p->getCachedAntennaPO();
     208           0 :               auto const po_l_v =  pointingOffsets_p->fetchAntOffsetToPix(vb, doPointing_p) ;
     209           0 :               Vector < Vector <Double> > po_l(po_l_v.size());
     210           0 :           for (size_t i = 0; i < po_l_v.size(); ++i) {
     211           0 :               po_l[i] = Vector<Double>(po_l_v[i]);
     212             :           }
     213             : 
     214           0 :               unsigned int poShape_X = po_l.shape()[0];
     215           0 :               unsigned int poShape_Y = po_l(0).shape()[0];
     216           0 :               unsigned int cachedPOShape_X = cachedAntPO_l.shape()[0];
     217           0 :               unsigned int cachedPOShape_Y = cachedAntPO_l(0).shape()[0];
     218             : 
     219           0 :               Vector<Double> sumResPO_l(2,0), sumAntPO_l(2,0), sumPO_l(2,0);
     220           0 :               double avgResPO_l = 0.0;
     221             : //            sumResPO_l.resize(2,0);
     222             : //            sumAntPO_l.resize(2,0);
     223             : //            sumPO_l.resize(2,0);
     224             : 
     225             : //            cerr << "cachedAntPO_l : " << cachedAntPO_l << endl;
     226             : //            cerr << "po_l : " << po_l << endl;
     227             : 
     228             : //            cerr << " After initialization sumResPO_l "<< sumResPO_l[0] << " sumAntPO_l " << sumAntPO_l[0] <<" sumPO_l " << sumPO_l[0] << endl;
     229             : 
     230             : //            cerr << " After initialization sumResPO_l "<< sumResPO_l[1] << " sumAntPO_l " << sumAntPO_l[1] << " sumPO_l " << sumPO_l[1] << endl;
     231             : 
     232           0 :               if(poShape_X == cachedPOShape_X && poShape_Y == cachedPOShape_Y)
     233             :                 {
     234           0 :                   Vector < Vector <Double> > residualPointingOffsets_l = cachedAntPO_l - po_l;
     235             : //                cerr << "residualPointingOffsets_l : " << residualPointingOffsets_l << endl;
     236             : //                cerr <<"___________________________________________________________________"<<endl;
     237           0 :                   for(unsigned int ii=0; ii < poShape_X; ii++) 
     238             :                     {
     239           0 :                       for (unsigned int jj=0; jj < poShape_Y; jj++)
     240             :                         {
     241           0 :                           sumResPO_l[ii] = sumResPO_l[ii] + residualPointingOffsets_l[ii][jj];
     242           0 :                           sumAntPO_l[ii] = sumAntPO_l[ii] + cachedAntPO_l[ii][jj];
     243           0 :                           sumPO_l[ii] = sumPO_l[ii] + po_l[ii][jj];
     244             :                         }
     245             : //                    cerr << " ii " << ii << " sumResPO_l " << sumResPO_l[ii] << " sumAntPO_l " << sumAntPO_l[ii] << " sumPO_l " << sumPO_l[ii] << endl;
     246             :                     }
     247             : //                cerr <<"___________________________________________________________________"<<endl;               
     248             : 
     249           0 :                   avgResPO_l = sqrt(sumResPO_l[0]*sumResPO_l[0] + sumResPO_l[1]*sumResPO_l[1])/poShape_Y; // The units are in pixels here
     250             : 
     251           0 :                   if(avgResPO_l*sqrt(poIncrement[0]*poIncrement[0] + poIncrement[1]*poIncrement[1]) >= sigmaDev[1]*A2R)
     252             :                     {
     253           0 :                       baselineType_p->setCachedGroups(false);
     254           0 :                       baselineType_p->findAntennaGroups(vb,pointingOffsets_p, sigmaDev[0]);
     255           0 :                       baselineType_p->setCachedAntennaPO(pointingOffsets_p->pullPointingOffsets());
     256           0 :                       baselineType_p->makeVBRow2BLGMap(vb);
     257           0 :                       vbRow2BLMap_p = baselineType_p->getVBRow2BLMap();
     258           0 :                       setBLNeedsNewPOPG(vbRow2BLMap_p);
     259           0 :                       if (!needsNewFieldPG_p)
     260             :                         {
     261           0 :                           LogIO log_l(LogOrigin("VB2CFBMap", "makeVBRow2CFBMap[R&D]"));
     262             : 
     263           0 :                           log_l << "The average antenna Offset : " << avgResPO_l*sqrt(poIncrement[0]*poIncrement[0] + poIncrement[1]*poIncrement[1])/A2R 
     264           0 :                                 << " arcsec, exceeds the second parameter of sigmaDev : " << sigmaDev[1] 
     265           0 :                                 << " arcsec for Field ID = " << vb.fieldId()(0) << LogIO::POST;
     266             :                           
     267           0 :                         }
     268             :                       // cerr << "Avg of the Residual Pointing Offsets " << avgResPO_l*sqrt(poIncrement[0]*poIncrement[0] + poIncrement[1]*poIncrement[1])/A2R <<endl; 
     269             :                     }
     270           0 :                 }
     271             :               else
     272             :                 {
     273           0 :                   baselineType_p->setCachedGroups(false);
     274           0 :                   needsNewPOPG_p = true;
     275             :                 }
     276             :               
     277           0 :             }
     278           0 :           baselineType_p->setCachedAntennaPO(pointingOffsets_p->pullPointingOffsets());
     279           0 :         }
     280             : 
     281             :       else
     282             :         {
     283           0 :           sigmaDev[0] = 0;
     284           0 :           sigmaDev[1] = 0;
     285             :         }
     286             :       
     287           0 :       for (Int irow=0;irow<nRow;irow++)
     288             :         {
     289             :           //
     290             :           // Translate antenna ID to antenna type
     291             :           //
     292           0 :           Int ant1Type = mapAntIDToAntType(vb.antenna1()(irow)),
     293           0 :             ant2Type = mapAntIDToAntType(vb.antenna2()(irow));
     294             :           //
     295             :           // Get the CFBuffer for the given PA and baseline catagorized
     296             :           // by the two antenna types.  For homgeneous arrays, all
     297             :           // baselines will map to a single antenna-type pair.
     298             :           //
     299             :           
     300           0 :           CountedPtr<CFBuffer> cfb_l;
     301             :           try
     302             :             {
     303           0 :               cfb_l = cfs.getCFBuffer(pa, dPA, ant1Type, ant2Type);
     304             :               
     305           0 :               if (cfb_l != cachedCFBPtr_p)
     306             :                 {
     307           0 :                   maxCFShape_p[0] = maxCFShape_p[1] = cfb_l->getMaxCFSize();
     308           0 :                   LogIO alog(LogOrigin("VB2CFBMap", "makeVBRow2CFBMap[R&D]"));
     309           0 :                   alog << "CFBShape changed " << maxCFShape_p << LogIO::DEBUG2 << LogIO::POST;
     310             :                   
     311           0 :                 }
     312           0 :               cachedCFBPtr_p = cfb_l;
     313             :             }
     314           0 :           catch (CFNotCached& x)
     315             :             {
     316           0 :               LogIO log_l(LogOrigin("VB2CFBMap", "makeVBRow2CFBMap[R&D]"));
     317             : 
     318             :               log_l << "CFs not cached for " << pa.getValue("deg") 
     319             :                     << " deg, dPA = " << dPA.getValue("deg") 
     320           0 :                     << " Field ID = " << vb.fieldId()(0);
     321           0 :               log_l << " Ant1Type, Ant2Type = " << ant1Type << "," << ant2Type << LogIO::POST;
     322           0 :               statusCode=CFDefs::NOTCACHED;
     323           0 :             }
     324             :           
     325           0 :           if (statusCode==CFDefs::NOTCACHED)
     326             :             {
     327           0 :               break;
     328             :             }
     329             :           else
     330             :             {
     331             :               // Set the phase grad for the CF per VB row
     332             :               // setPhaseGradPerRow(pointingOffsets_p, cfb_l, vb, irow);
     333           0 :               timer_p.mark();
     334             :               // if (vbRows_p == 0)
     335             :               //   {
     336             :               //     vbRows_p = vb.nRows();
     337             :               //     baselineType_p->setcachedGroups(false);
     338             :               //   }
     339             :               // else if (vbRows_p != vb.nRows())
     340             :               //   {
     341             :               //     vbRows_p = vb.nRows();
     342             :               //     baselineType_p->setcachedGroups(false);
     343             :               //   }
     344             :               // else
     345             :               //   baselineType_p->setcachedGroups_p(true);
     346             :               // baselineType_p->setCacheGroups(vbRows_p, vb);
     347             :               // baselineType_p->setDoPointing(doPointing_p);
     348             :               // if(computeAntennaGroups_p)
     349             :               // baselineType_p->findAntennaGroups(vb,pointingOffsets_p,sigmaDev);
     350           0 :               cfPhaseGrad_p(irow).reference(setBLPhaseGrad(pointingOffsets_p, vb, irow, sigmaDev[0]));
     351           0 :               totalCost_p += timer_p.real();
     352           0 :               totalVB_p++;
     353             :               // Set the CFB per VB row
     354           0 :               cfb_l->setPointingOffset(pointingOffsets_p->pullPointingOffsets());
     355           0 :               vb2CFBMap_p(irow) = cfb_l;
     356           0 :               vbRows_p = vb.nRows();
     357             :               // if( needsNewPOPG_p ||  needsNewFieldPG_p)
     358             :               //        cerr << "NeedsNewPOPG_p " << needsNewPOPG_p << " NeedsNewFieldPG_p "<< needsNewFieldPG_p << " row " << myrow << endl;
     359             :                   
     360             :             }
     361           0 :         }
     362             :       // {
     363             :       //        double n=0;
     364             :       //        for (int i=0;i<cfPhaseGrad_p.nelements();i++)
     365             :       //          n+=cfPhaseGrad_p[i].shape().product()*sizeof(casacore::Complex);
     366             :       //        log_l << "Size of VB2CFBMap::cfPhaseGrad_p = " << n << " bytes" << LogIO::POST;
     367             :       // }
     368           0 :       return statusCode;
     369           0 :     }
     370             : 
     371           0 :     Matrix<Complex> VB2CFBMap::setBLPhaseGrad(const CountedPtr<PointingOffsets>& pointingOffsets_p ,
     372             :                                               const vi::VisBuffer2& vb,
     373             :                                               const int& row,
     374             :                                               const double& /*sigmaDev*/)
     375             :     {
     376           0 :       int myrow=row;
     377           0 :       int idx = 0;
     378           0 :       if(doPointing_p)
     379             :         {
     380           0 :           vector<int> uniqueVbRow2BLMap_p = vbRow2BLMap_p;
     381           0 :           sort(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     382           0 :           auto itrBLMap = unique(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     383           0 :           uniqueVbRow2BLMap_p.erase(itrBLMap,uniqueVbRow2BLMap_p.end());
     384           0 :           int maxVB2BLMap = *max_element(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     385           0 :           pair<int,int> antGrp_l = (baselineType_p->getAntGrpPairs(myrow));
     386             :           // if (myrow==0 )
     387             :           //   {
     388             :               // blType_p = vbRow2BLMap_p[myrow];
     389             :               // blNeedsNewPOPG_p[myrow] = true;
     390             :               // cerr <<"New POPG_p required for vb row : "<< myrow << " vbRow2BLMap_p[row] " << vbRow2BLMap_p[myrow] << endl;
     391             :             // }
     392             :           // else if (blType_p != vbRow2BLMap_p[myrow])
     393             :           //   {
     394             :           //     needsNewPOPG_p=true;
     395             :           //     blType_p = vbRow2BLMap_p[myrow];
     396             :           //     // cerr <<"New POPG_p required for vb row : "<< myrow << " vbRow2BLMap_p[row] " << vbRow2BLMap_p[myrow] << endl;
     397             :           //   }
     398             :           // else
     399             :           //   blNeedsNewPOPG_p[myrow]=false;
     400             :             
     401             :           // if (vectorPhaseGradCalculator_p.nelements() <= (unsigned int) vbRow2BLMap_p[row])
     402             :           // auto itrBLMap_p = find(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end(), vbRow2BLMap_p[row]);
     403             :           // idx = distance(uniqueVbRow2BLMap_p.begin(), itrBLMap_p);
     404             :           
     405             :           // cerr<<"#######################" <<endl << "unqVBRow: ";
     406             :           // for(int ii=0; ii<uniqueVbRow2BLMap_p.size();idx++)
     407             :           //   cerr << uniqueVbRow2BLMap_p[ii] << " " ;
     408             :           // cerr<<"#######################"<<endl;
     409             :           // if (vectorPhaseGradCalculator_p.nelements() <= maxVB2BLMap + 1)
     410             :           // vectorPhaseGradCalculator_p.resize(uniqueVbRow2BLMap_p.size()+1,true);
     411             : 
     412             : 
     413           0 :           vectorPhaseGradCalculator_p.resize(maxVB2BLMap+1,true); // not zero counted hence the plus 1 - PJ
     414             :             {
     415             :               // cerr<<"vbRow2BLMap_p [row] doP=T "<< vbRow2BLMap_p[row] << " " <<row << " " << maxVB2BLMap+1 << endl;
     416             :               // vectorPhaseGradCalculator_p.resize(vbRow2BLMap_p[myrow]+1,true); // Revisit this.
     417           0 :               for (unsigned int i=0;i<vectorPhaseGradCalculator_p.nelements(); i++)
     418           0 :                 if (vectorPhaseGradCalculator_p[i].null())
     419             :                   {
     420           0 :                     vectorPhaseGradCalculator_p[i]=new PhaseGrad();
     421           0 :                     vectorPhaseGradCalculator_p[i]->needCFPhaseGrad_p=computePhaseScreen_p;
     422             :                     // blNeedsNewPOPG_p[i] = true;
     423             :                   }
     424             :             }
     425             : 
     426             : 
     427             :           // if( baselineType_p->cachedGroups_p)
     428             :           //   vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,cfb,vb,0);
     429             :           // else
     430             :             // vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,cfb,vb,row);
     431             :           // vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewPOPG_p = blNeedsNewPOPG_p[myrow];
     432             :             // needsNewPOPG_p = true;
     433             :             // vectorPhaseGradCalculator_p[idx]->needsNewPOPG_p = needsNewPOPG_p;
     434             :             // vectorPhaseGradCalculator_p[idx]->needsNewFieldPG_p = needsNewFieldPG_p;
     435             :             // vectorPhaseGradCalculator_p[idx]->ComputeFieldPointingGrad(pointingOffsets_p,cfb,vb,myrow);
     436             :             // cerr << "maxVB2BLMap "<< maxVB2BLMap << " vbRow2BLMap_p[myrow]" << vbRow2BLMap_p[myrow] << " "  << myrow << " " << needsNewPOPG_p << endl;
     437           0 :             vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->maxCFShape_p = maxCFShape_p;
     438           0 :             vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewPOPG_p = blNeedsNewPOPG_p[myrow];
     439           0 :             vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewFieldPG_p = needsNewFieldPG_p;
     440           0 :             vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,vb,row,antGrp_l);
     441             : 
     442           0 :             blNeedsNewPOPG_p[myrow] = false;
     443             :          
     444           0 :         }
     445             :       else
     446             :         {
     447           0 :           needsNewPOPG_p = false;
     448           0 :           myrow=0;
     449           0 :           vbRow2BLMap_p.resize(vb.nRows(),0);
     450           0 :           blNeedsNewPOPG_p.resize(vb.nRows(),false);
     451             :           // vbRow2BLMap_p[0]=0;
     452           0 :           if (vectorPhaseGradCalculator_p.nelements() <= (unsigned int) vbRow2BLMap_p[myrow])
     453             :             {
     454             :               //            cerr<<"vbRow2BLMap_p [row] doP=F "<< vbRow2BLMap_p[myrow] << " " <<myrow <<endl;
     455           0 :               vectorPhaseGradCalculator_p.resize(1);
     456           0 :               if (vectorPhaseGradCalculator_p[myrow].null())
     457           0 :                 vectorPhaseGradCalculator_p[myrow]=new PhaseGrad();
     458           0 :               vectorPhaseGradCalculator_p[myrow]->needCFPhaseGrad_p=computePhaseScreen_p;
     459             :             }
     460             :           // vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,cfb,vb,0);    
     461           0 :           vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->maxCFShape_p = maxCFShape_p;
     462           0 :           vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewPOPG_p = needsNewPOPG_p;
     463           0 :           vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewFieldPG_p = needsNewFieldPG_p;
     464           0 :           vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,vb,myrow,make_pair(0,0));
     465           0 :           idx =0;
     466             :         }
     467             :       // if (needsNewPOPG_p)
     468             :         {
     469             : 
     470             :           // vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewFieldPG_p = needsNewFieldPG_p;
     471             :           // vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,cfb,vb,myrow);
     472           0 :           needsNewPOPG_p = false;
     473           0 :           needsNewFieldPG_p = false;
     474             :         }
     475             : 
     476           0 :       return  vectorPhaseGradCalculator_p[idx]->field_phaseGrad_p;
     477             :     
     478             :     };
     479             : 
     480             : 
     481             :   }
     482             : }

Generated by: LCOV version 1.16