LCOV - code coverage report
Current view: top level - synthesis/TransformMachines2 - VB2CFBMap.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 146 164 89.0 %
Date: 2023-10-25 08:47:59 Functions: 4 6 66.7 %

          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: aips2-request@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          86 :     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          86 :       baselineType_p = new BaselineType();
      51          86 :       needsNewPOPG_p = false;
      52          86 :       needsNewFieldPG_p = false;
      53          86 :       totalCost_p=totalVB_p = 0.0;
      54          86 :       blNeedsNewPOPG_p.resize(0);
      55          86 :       blType_p=0;
      56          86 :       vectorPhaseGradCalculator_p.resize(0);
      57             :       // sigmaDev = SynthesisUtils::getenv("PO_SIGMADEV",3.0);
      58          86 :     };
      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          69 :     void VB2CFBMap::setBLNeedsNewPOPG(vector<int>& vbRow2BLMap_p)
      99             :     {
     100          69 :       blNeedsNewPOPG_p.resize(vbRow2BLMap_p.size(),false);
     101         138 :       vector<int> uniqueVbRow2BLMap_p = vbRow2BLMap_p;
     102          69 :       sort(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     103          69 :       auto itrBLMap = unique(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     104          69 :       uniqueVbRow2BLMap_p.erase(itrBLMap,uniqueVbRow2BLMap_p.end());
     105             :       
     106         172 :       for(unsigned int ii=0; ii < uniqueVbRow2BLMap_p.size(); ii++)
     107             :         {
     108         103 :           int idx = baselineType_p->returnIdx(vbRow2BLMap_p, uniqueVbRow2BLMap_p[ii]);
     109         103 :           blNeedsNewPOPG_p[idx] = true;
     110             :           // cerr << "unqVb2BL: "<< uniqueVbRow2BLMap_p[ii] << " ii " << ii << endl;
     111             :         }
     112             : 
     113             :       
     114          69 :     }
     115             : 
     116             : 
     117             : 
     118             :     //______________________________________________________
     119             :     
     120       33989 :     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       33989 :       const Int nRow=vb.nRows(); 
     130             :       //UNUSED: nChan=dataChan2ImChanMap.nelements(), 
     131             :       //UNUSED: nPol=dataPol2ImPolMap.nelements();
     132             :       //    vbRow2CFMap_p.resize(nPol, nChan, nRow);
     133       33989 :       vb2CFBMap_p.resize(nRow);
     134       33989 :       cfPhaseGrad_p.resize(nRow);
     135       33989 :       maxCFShape_p.resize(2,0);
     136       33989 :       if(cachedFieldId_p != vb.fieldId()[0])
     137             :         {
     138         141 :           needsNewFieldPG_p = true;
     139         141 :           needsNewPOPG_p = true;
     140         141 :           baselineType_p->setCachedGroups(false);
     141         141 :           cachedFieldId_p = vb.fieldId()[0];
     142         141 :           vectorPhaseGradCalculator_p.resize(0);
     143         141 :           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       33848 :       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       33848 :           baselineType_p->setCachedGroups(true);
     160       33848 :           needsNewPOPG_p = false;
     161             :         }
     162             :       
     163             : 
     164       33989 :       Quantity pa(getPA(vb),"rad");
     165             :       //PolOuterProduct outerProduct;
     166       33989 :       Int statusCode=CFDefs::MEMCACHE;
     167             : 
     168             :       // baselineType_p->setCacheGroups(vbRows_p, vb);
     169             :       // baselineType_p->setCachedGroups(true);
     170       33989 :       baselineType_p->setDoPointing(doPointing_p);
     171             : 
     172             : 
     173       33989 :       if(doPointing_p)
     174             :         {
     175             :           // cerr<<"VB2CFBMap::makeVBRow2CFBMap DoP = T"<<endl;
     176        2824 :           Float A2R = 4.848137E-06;
     177        2824 :           Vector<Double> poIncrement = pointingOffsets_p->getIncrement();
     178             :           Double offsetDeviation;
     179        2824 :           if(sigmaDev[0] > 0)
     180        2824 :             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        2824 :           if(sigmaDev[1] == 0)
     184           0 :             sigmaDev[1] = sigmaDev[0];
     185             : 
     186        2824 :           baselineType_p->findAntennaGroups(vb,pointingOffsets_p, offsetDeviation);
     187             : 
     188        2824 :           baselineType_p->makeVBRow2BLGMap(vb);
     189        2824 :           vbRow2BLMap_p = baselineType_p->getVBRow2BLMap();
     190             :           // if(cachedFieldId_p != vb.fieldId()[0])
     191        2824 :           if(needsNewPOPG_p)
     192             :             {
     193          43 :               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        2824 :           if(baselineType_p->getCachedGroups())
     206             :             {
     207        5648 :               Vector < Vector <Double> > cachedAntPO_l = baselineType_p->getCachedAntennaPO();
     208        5648 :               auto const po_l_v =  pointingOffsets_p->fetchAntOffsetToPix(vb, doPointing_p) ;
     209        5648 :               Vector < Vector <Double> > po_l(po_l_v.size());
     210        8472 :           for (size_t i = 0; i < po_l_v.size(); ++i) {
     211        5648 :               po_l[i] = Vector<Double>(po_l_v[i]);
     212             :           }
     213             : 
     214        2824 :               unsigned int poShape_X = po_l.shape()[0];
     215        2824 :               unsigned int poShape_Y = po_l(0).shape()[0];
     216        2824 :               unsigned int cachedPOShape_X = cachedAntPO_l.shape()[0];
     217        2824 :               unsigned int cachedPOShape_Y = cachedAntPO_l(0).shape()[0];
     218             : 
     219        5648 :               Vector<Double> sumResPO_l(2,0), sumAntPO_l(2,0), sumPO_l(2,0);
     220        2824 :               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        2824 :               if(poShape_X == cachedPOShape_X && poShape_Y == cachedPOShape_Y)
     233             :                 {
     234        5648 :                   Vector < Vector <Double> > residualPointingOffsets_l = cachedAntPO_l - po_l;
     235             : //                cerr << "residualPointingOffsets_l : " << residualPointingOffsets_l << endl;
     236             : //                cerr <<"___________________________________________________________________"<<endl;
     237        8472 :                   for(unsigned int ii=0; ii < poShape_X; ii++) 
     238             :                     {
     239      156662 :                       for (unsigned int jj=0; jj < poShape_Y; jj++)
     240             :                         {
     241      151014 :                           sumResPO_l[ii] = sumResPO_l[ii] + residualPointingOffsets_l[ii][jj];
     242      151014 :                           sumAntPO_l[ii] = sumAntPO_l[ii] + cachedAntPO_l[ii][jj];
     243      151014 :                           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        2824 :                   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        2824 :                   if(avgResPO_l*sqrt(poIncrement[0]*poIncrement[0] + poIncrement[1]*poIncrement[1]) >= sigmaDev[1]*A2R)
     252             :                     {
     253          26 :                       baselineType_p->setCachedGroups(false);
     254          26 :                       baselineType_p->findAntennaGroups(vb,pointingOffsets_p, sigmaDev[0]);
     255          26 :                       baselineType_p->setCachedAntennaPO(pointingOffsets_p->pullPointingOffsets());
     256          26 :                       baselineType_p->makeVBRow2BLGMap(vb);
     257          26 :                       vbRow2BLMap_p = baselineType_p->getVBRow2BLMap();
     258          26 :                       setBLNeedsNewPOPG(vbRow2BLMap_p);
     259          26 :                       if (!needsNewFieldPG_p)
     260             :                         {
     261          78 :                           LogIO log_l(LogOrigin("VB2CFBMap", "makeVBRow2CFBMap[R&D]"));
     262             : 
     263          26 :                           log_l << "The average antenna Offset : " << avgResPO_l*sqrt(poIncrement[0]*poIncrement[0] + poIncrement[1]*poIncrement[1])/A2R 
     264          26 :                                 << " arcsec, exceeds the second parameter of sigmaDev : " << sigmaDev[1] 
     265          52 :                                 << " arcsec for Field ID = " << vb.fieldId()(0) << LogIO::POST;
     266             :                           
     267             :                         }
     268             :                       // cerr << "Avg of the Residual Pointing Offsets " << avgResPO_l*sqrt(poIncrement[0]*poIncrement[0] + poIncrement[1]*poIncrement[1])/A2R <<endl; 
     269        2824 :                     }
     270             :                 }
     271             :               else
     272             :                 {
     273           0 :                   baselineType_p->setCachedGroups(false);
     274           0 :                   needsNewPOPG_p = true;
     275             :                 }
     276             :               
     277             :             }
     278        2824 :           baselineType_p->setCachedAntennaPO(pointingOffsets_p->pullPointingOffsets());
     279             :         }
     280             : 
     281             :       else
     282             :         {
     283       31165 :           sigmaDev[0] = 0;
     284       31165 :           sigmaDev[1] = 0;
     285             :         }
     286             :       
     287     3718106 :       for (Int irow=0;irow<nRow;irow++)
     288             :         {
     289             :           //
     290             :           // Translate antenna ID to antenna type
     291             :           //
     292     3684130 :           Int ant1Type = mapAntIDToAntType(vb.antenna1()(irow)),
     293     3684130 :             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     3684130 :           CountedPtr<CFBuffer> cfb_l;
     301             :           try
     302             :             {
     303     3684130 :               cfb_l = cfs.getCFBuffer(pa, dPA, ant1Type, ant2Type);
     304             :               
     305     3684117 :               if (cfb_l != cachedCFBPtr_p)
     306             :                 {
     307         191 :                   maxCFShape_p[0] = maxCFShape_p[1] = cfb_l->getMaxCFSize();
     308         573 :                   LogIO alog(LogOrigin("VB2CFBMap", "makeVBRow2CFBMap[R&D]"));
     309         191 :                   alog << "CFBShape changed " << maxCFShape_p << LogIO::DEBUG2 << LogIO::POST;
     310             :                   
     311             :                 }
     312     3684117 :               cachedCFBPtr_p = cfb_l;
     313             :             }
     314          26 :           catch (CFNotCached& x)
     315             :             {
     316          26 :               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          13 :                     << " Field ID = " << vb.fieldId()(0);
     321          13 :               log_l << " Ant1Type, Ant2Type = " << ant1Type << "," << ant2Type << LogIO::POST;
     322          13 :               statusCode=CFDefs::NOTCACHED;
     323             :             }
     324             :           
     325     3684130 :           if (statusCode==CFDefs::NOTCACHED)
     326             :             {
     327          13 :               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     3684117 :               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     3684117 :               cfPhaseGrad_p(irow).reference(setBLPhaseGrad(pointingOffsets_p, vb, irow, sigmaDev[0]));
     351     3684117 :               totalCost_p += timer_p.real();
     352     3684117 :               totalVB_p++;
     353             :               // Set the CFB per VB row
     354     3684117 :               cfb_l->setPointingOffset(pointingOffsets_p->pullPointingOffsets());
     355     3684117 :               vb2CFBMap_p(irow) = cfb_l;
     356     3684117 :               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             :         }
     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       67978 :       return statusCode;
     369             :     }
     370             : 
     371     3684117 :     Matrix<Complex> VB2CFBMap::setBLPhaseGrad(const CountedPtr<PointingOffsets>& pointingOffsets_p ,
     372             :                                               const vi::VisBuffer2& vb,
     373             :                                               const int& row,
     374             :                                               const double& /*sigmaDev*/)
     375             :     {
     376     3684117 :       int myrow=row;
     377     3684117 :       int idx = 0;
     378     3684117 :       if(doPointing_p)
     379             :         {
     380      954759 :           vector<int> uniqueVbRow2BLMap_p = vbRow2BLMap_p;
     381      954759 :           sort(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     382      954759 :           auto itrBLMap = unique(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     383      954759 :           uniqueVbRow2BLMap_p.erase(itrBLMap,uniqueVbRow2BLMap_p.end());
     384      954759 :           int maxVB2BLMap = *max_element(uniqueVbRow2BLMap_p.begin(),uniqueVbRow2BLMap_p.end());
     385      954759 :           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      954759 :           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     2918981 :               for (unsigned int i=0;i<vectorPhaseGradCalculator_p.nelements(); i++)
     418     1964222 :                 if (vectorPhaseGradCalculator_p[i].null())
     419             :                   {
     420          94 :                     vectorPhaseGradCalculator_p[i]=new PhaseGrad();
     421          94 :                     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      954759 :             vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->maxCFShape_p = maxCFShape_p;
     438      954759 :             vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewPOPG_p = blNeedsNewPOPG_p[myrow];
     439      954759 :             vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewFieldPG_p = needsNewFieldPG_p;
     440      954759 :             vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,vb,row,antGrp_l);
     441             : 
     442      954759 :             blNeedsNewPOPG_p[myrow] = false;
     443             :          
     444             :         }
     445             :       else
     446             :         {
     447     2729358 :           needsNewPOPG_p = false;
     448     2729358 :           myrow=0;
     449     2729358 :           vbRow2BLMap_p.resize(vb.nRows(),0);
     450     2729358 :           blNeedsNewPOPG_p.resize(vb.nRows(),false);
     451             :           // vbRow2BLMap_p[0]=0;
     452     2729358 :           if (vectorPhaseGradCalculator_p.nelements() <= (unsigned int) vbRow2BLMap_p[myrow])
     453             :             {
     454             :               //            cerr<<"vbRow2BLMap_p [row] doP=F "<< vbRow2BLMap_p[myrow] << " " <<myrow <<endl;
     455          96 :               vectorPhaseGradCalculator_p.resize(1);
     456          96 :               if (vectorPhaseGradCalculator_p[myrow].null())
     457          96 :                 vectorPhaseGradCalculator_p[myrow]=new PhaseGrad();
     458          96 :               vectorPhaseGradCalculator_p[myrow]->needCFPhaseGrad_p=computePhaseScreen_p;
     459             :             }
     460             :           // vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,cfb,vb,0);    
     461     2729358 :           vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->maxCFShape_p = maxCFShape_p;
     462     2729358 :           vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewPOPG_p = needsNewPOPG_p;
     463     2729358 :           vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->needsNewFieldPG_p = needsNewFieldPG_p;
     464     2729358 :           vectorPhaseGradCalculator_p[vbRow2BLMap_p[myrow]]->ComputeFieldPointingGrad(pointingOffsets_p,vb,myrow,make_pair(0,0));
     465     2729358 :           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     3684117 :           needsNewPOPG_p = false;
     473     3684117 :           needsNewFieldPG_p = false;
     474             :         }
     475             : 
     476     7368234 :       return  vectorPhaseGradCalculator_p[idx]->field_phaseGrad_p;
     477             :     
     478             :     };
     479             : 
     480             : 
     481             :   }
     482             : }

Generated by: LCOV version 1.16