LCOV - code coverage report
Current view: top level - synthesis/TransformMachines2 - CFStore2.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 95 125 76.0 %
Date: 2023-10-25 08:47:59 Functions: 13 17 76.5 %

          Line data    Source code
       1             : // -*- C++ -*-
       2             : //# CFStore2.cc: Implementation of the CFStore2 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             : #include <synthesis/TransformMachines2/CFStore2.h>
      29             : #include <synthesis/TransformMachines2/CFBuffer.h>
      30             : #include <synthesis/TransformMachines2/Utils.h>
      31             : #include <synthesis/TransformMachines/SynthesisError.h>
      32             : #include <synthesis/TransformMachines2/PolOuterProduct.h>
      33             : 
      34             : using namespace casacore;
      35             : namespace casa{
      36             :   using namespace refim;
      37             :   //
      38             :   //---------------------------------------------------------------
      39             :   //
      40           0 :   CFStore2 & CFStore2::operator=(const CFStore2& other)
      41             :   {
      42           0 :     if (&other != this)
      43             :       {
      44           0 :         storage_p.assign(other.storage_p); 
      45           0 :         ant1_p.assign(other.ant1_p);
      46           0 :         ant2_p.assign(other.ant2_p);
      47           0 :         pa_p.assign(other.pa_p);
      48           0 :         lazyFillOn_p=other.lazyFillOn_p;
      49           0 :         currentSPWID_p = other.currentSPWID_p;
      50           0 :         cfCacheDir_p = other.cfCacheDir_p;
      51             :       }
      52           0 :     return *this;
      53             :   };
      54             :   //
      55             :   //---------------------------------------------------------------
      56             :   //
      57           0 :   void CFStore2::show(const char *Mesg, ostream& os, const Bool verbose)
      58             :   {
      59           0 :     if (!null())
      60             :       {
      61           0 :         if (Mesg != NULL) os << Mesg << endl;
      62           0 :         os << "Data Shape: " << storage_p.shape() << endl;
      63           0 :         os << "Ant1: " << ant1_p << endl;
      64           0 :         os << "Ant2: " << ant2_p << endl;
      65           0 :         os << "PA = "; for (uInt i=0;i<pa_p.nelements();i++)
      66           0 :                          os << pa_p[i].get("deg") << endl;
      67             : 
      68           0 :         if (verbose)
      69           0 :           for (int i=0; i<storage_p.shape()(0); i++)
      70           0 :             for(int j=0;j<storage_p.shape()(1);j++)
      71           0 :               storage_p(i,j)->show(Mesg,os);
      72             :       }
      73           0 :   };
      74             :   //
      75             :   //---------------------------------------------------------------
      76             :   //
      77         196 :   Vector<Int> CFStore2::resize(const Quantity& pa,
      78             :                                const Quantity& paTol,
      79             :                                const Int& ant1, const Int& ant2,
      80             :                                Bool retainValues)
      81             :   {
      82             :     Int paNdx, antNdx;
      83             :     //    getIndex(pa,wValue,ant1,ant2,paNdx, antNdx, wNdx);
      84         196 :     getIndex(pa,paTol,ant1,ant2,paNdx, antNdx);
      85             : 
      86             :     // If a index along any axis is negative, resize the correponding
      87             :     // vector holding the values along that axis.
      88         196 :     if (paNdx < 0) 
      89         184 :       {paNdx=pa_p.nelements();pa_p.resize(paNdx+1,retainValues);};
      90         196 :     if (antNdx < 0) 
      91         184 :       {antNdx=ant1_p.nelements();ant1_p.resize(antNdx+1,true);ant2_p.resize(antNdx+1,retainValues);}; 
      92             :     // if (wNdx < 0) 
      93             :     //   {wNdx=wValue_p.nelements();wValue_p.resize(wNdx+1,retainValues);}
      94             :     // Resize the storage_p Cube to the current size of required along
      95             :     // the 3 axis.  This is a NoOp if the axis lengths did not change.
      96         196 :     storage_p.resize(pa_p.nelements(), ant1_p.nelements(), retainValues);
      97             :     
      98         196 :     pa_p[paNdx] = pa;
      99         196 :     ant1_p[antNdx] = ant1;
     100         196 :     ant2_p[antNdx] = ant2;
     101             : 
     102         196 :     Vector<Int> pos(2);pos(0)=paNdx;pos(1)=antNdx;
     103         196 :     if (storage_p(pos(0),pos(1)).null())
     104             :       {
     105         184 :       storage_p(pos(0),pos(1)) = new CFBuffer;
     106         184 :       storage_p(pos(0),pos(1))->setDir(cfCacheDir_p);
     107             :       }
     108         392 :     return pos;
     109             :   };
     110             :   //
     111             :   //---------------------------------------------------------------
     112             :   //
     113           0 :   void CFStore2::setCFBuffer(CFBuffer* /*dataPtr*/, 
     114             :                              Quantity /*pa*/, 
     115             :                              const Int& /*ant1*/, const Int& /*ant2*/)
     116             :   {
     117           0 :     throw(AipsError("setCFBuffer called!"));
     118             :     // Vector<Int> pos=resize(pa,ant1,ant2);
     119             :     // storage_p(pos[0], pos[1]) = dataPtr;
     120             :   }
     121             :   //
     122             :   //---------------------------------------------------------------
     123             :   //
     124     3684326 :   CountedPtr<CFBuffer>& CFStore2::getCFBuffer(const Quantity& pa, 
     125             :                                               const Quantity& paTol, 
     126             :                                               const Int& ant1, const Int& ant2)
     127             :   {
     128             :     Int paNdx, antNdx;
     129     3684326 :     getIndex(pa,paTol,ant1,ant2,paNdx, antNdx);
     130     3684326 :     if ((paNdx < 0) || (antNdx < 0)) 
     131          13 :         throw(CFNotCached("CFStore2::getIndex: Index not found"));
     132             :       
     133     3684313 :     return getCFBuffer(paNdx, antNdx);
     134             :   }
     135             :   //
     136             :   //---------------------------------------------------------------
     137             :   //
     138             :   // Get CFBuffer by direct indexing
     139     3684639 :   CountedPtr<CFBuffer>& CFStore2::getCFBuffer(const Int& paNdx, const Int& antNdx)
     140             :   {
     141     3684639 :     return storage_p(paNdx, antNdx);
     142             :   }
     143             :   //
     144             :   //---------------------------------------------------------------
     145             :   //
     146           0 :   void CFStore2::getParams(Quantity& pa,
     147             :                            Int& ant1, Int& ant2, 
     148             :                            const Int& paNdx, const Int& antNdx)
     149             :   {
     150           0 :     pa     = pa_p[paNdx];
     151           0 :     ant1   = ant1_p[antNdx];
     152           0 :     ant2   = ant2_p[antNdx];
     153           0 :   }
     154             :   //
     155             :   //---------------------------------------------------------------
     156             :   // This version saves the CFBuffer that corresponds to the
     157             :   // [PA,(Ant1,Ant2)] pixel of the CFStore storage.
     158          26 :   void CFStore2::makePersistent(const char *dir,
     159             :                                 const char *cfName,
     160             :                                 const char *qualifier,
     161             :                                 const Quantity &pa, const Quantity& dPA,
     162             :                                 const Int& ant1, const Int& ant2)
     163             :   {
     164          78 :     LogIO log_l(LogOrigin("CFStore2", "makePersistent(pa)[R&D]"));
     165             :     (void)cfName;
     166             :     Int paNdx, antNdx;
     167          26 :     getIndex(pa,dPA,ant1,ant2,paNdx, antNdx);
     168             :     
     169          26 :     log_l << "Saving CFStore of shape " << storage_p(paNdx,antNdx)->shape() 
     170             :           << " for PA = " << pa.getValue("deg") 
     171             :           << " BaselineType(antType1, antType2) = (" << ant1 << "," << ant2 << ")" 
     172          52 :           << LogIO::POST;
     173          26 :     ostringstream name;
     174          26 :     name << String(qualifier) << "CFS_" << paNdx << "_" << antNdx;
     175          26 :     storage_p(paNdx,antNdx)->makePersistent(dir, name.str().c_str());
     176          26 :   }
     177             :   //
     178             :   //---------------------------------------------------------------
     179             :   //
     180          12 :   void CFStore2::makePersistent(const char *dir,
     181             :                                 const char *cfName,
     182             :                                 const char *qualifier)
     183             :   {
     184             :     (void)cfName;
     185          36 :     LogIO log_l(LogOrigin("CFStore2.2", "makePersistent[R&D]"));
     186             :     //const char *formedName;
     187             : 
     188          24 :     for (Int i=0;i<storage_p.shape()(0);i++)
     189          24 :       for (Int j=0;j<storage_p.shape()(1);j++)
     190             :         {
     191          12 :           log_l << "Writing CFStore("<<i<<","<<j<<") of shape " << storage_p(i,j)->shape() << LogIO::POST;
     192          12 :           ostringstream name;
     193             :           //name << dir << "/" << qualifier << "CFS_" << i << "_" << j;
     194          12 :           name << String(qualifier) << "CFS_" << i << "_" << j;
     195             :           // if (String(cfName) == "") formedName = name.str().c_str();
     196             :           // else              formedName = cfName;
     197          12 :           storage_p(i,j)->makePersistent(dir,name.str().c_str());
     198             :         }
     199          12 :   }
     200             :   //
     201             :   //---------------------------------------------------------------
     202             :   //
     203         196 :   void CFStore2::primeTheCFB()
     204             :   {
     205         392 :     IPosition shp=getShape();
     206         366 :     for (Int i=0; i<shp(0); i++)
     207         340 :       for (Int j=0; j<shp(1); j++)
     208         170 :         getCFBuffer(i,j)->primeTheCache();
     209         196 :   }
     210             :   //
     211             :   //---------------------------------------------------------------
     212             :   //
     213         170 :   void CFStore2::initMaps(const VisBuffer2& vb, const Matrix<Double>& freqSelection, const Double& imRefFreq)
     214             :   {
     215         340 :     for (Int i=0;i<storage_p.shape()(0);i++)
     216         340 :       for (Int j=0;j<storage_p.shape()(1);j++)
     217         170 :         storage_p(i,j)->initMaps(vb, freqSelection, imRefFreq);
     218         170 :   }
     219             :   //
     220             :   //---------------------------------------------------------------
     221             :   //
     222         144 :   void CFStore2::initPolMaps(PolMapType& polMap, PolMapType& conjPolMap)
     223             :   {
     224         288 :     IPosition shp=getShape();
     225         288 :     for (Int i=0; i<shp(0); i++)
     226         288 :       for (Int j=0; j<shp(1); j++)
     227         144 :         getCFBuffer(i,j)->initPolMaps(polMap, conjPolMap);
     228         144 :   }
     229             :   //
     230         439 : void CFStore2::clear()
     231             :   {
     232         878 :     IPosition cfsShape = getStorage().shape();
     233             : 
     234         878 :     for (Int ib=0;ib<cfsShape(0); ib++)
     235         878 :       for(int it=0;it<cfsShape(1); it++)
     236         439 :           getStorage()(ib,it)->clear();
     237         439 :   }
     238             :   //
     239             :   //---------------------------------------------------------------
     240             :   //
     241             :   //---------------------------------------------------------------
     242             :   //
     243       18278 :   Double CFStore2::memUsage()
     244             :   {
     245       18278 :     IPosition cfsShape = getStorage().shape();
     246       18278 :     Double memUsed=0;
     247       36556 :     for (Int ib=0;ib<cfsShape(0); ib++)
     248       36556 :       for(int it=0;it<cfsShape(1); it++)
     249             :         {
     250       36556 :           IPosition cfbShape = getStorage()(ib,it)->getStorage().shape();
     251       54834 :           for(int ip=0;ip<cfbShape(2); ip++)
     252      141724 :             for(Int ich=0;ich<cfbShape(0);ich++)
     253      211656 :               for(Int iw=0;iw<cfbShape(1); iw++)
     254      106488 :                 memUsed += getStorage()(ib,it)->getStorage()(ich,iw,ip)->getStorage()->shape()
     255      106488 :                   .product()*sizeof(Complex);
     256             :         }
     257       36556 :     return memUsed;
     258             :   }
     259             :   //
     260             :   //---------------------------------------------------------------
     261             :   //
     262     3684548 :   Int CFStore2::nearestPA(const Quantity& pa, const Quantity& paTol)
     263             :     {
     264     3684548 :       Int n=pa_p.nelements(), junk=-1;
     265     3684548 :       Float dpa=paTol.getValue("rad"),
     266     3684548 :         paVal = pa.getValue("rad"), cpa;
     267             : 
     268     3684548 :       for(Int i=0;i<n;i++)
     269             :         {
     270     3684351 :           cpa = pa_p(i).getValue("rad");
     271             :           //      cerr << "##### " << i << " " << cpa*57.2956 << " " << paVal*57.2956 << " " << dpa*57.2956 << " " << (fabs(cpa - paVal))*57.2956 << endl; 
     272             :           // if (fabs(cpa - paVal) > dpa) 
     273             :           //   {cout << "%%%%% "; cin >> junk;}
     274     3684351 :           if (fabs(cpa - paVal) < dpa) {junk=i;break;}
     275             :         }
     276     3684548 :       return junk;
     277             :     }
     278             :   //
     279             :   //---------------------------------------------------------------
     280             :   //
     281         196 :   void CFStore2::setCFCacheDir(const String& dir)
     282             :   {
     283         392 :     IPosition cfsShape = getStorage().shape();
     284             : 
     285         208 :     for (Int ib=0;ib<cfsShape(0); ib++)
     286          24 :       for(int it=0;it<cfsShape(1); it++)
     287          12 :           getStorage()(ib,it)->setDir(dir);
     288             : 
     289         196 :     cfCacheDir_p=dir;
     290         196 :   }
     291             :   //
     292             :   //---------------------------------------------------------------
     293             :   //
     294       26675 :   void CFStore2::invokeGC(const Int& spwID)
     295             :   {
     296       26675 :     if (isLazyFillOn())
     297             :       {
     298       26675 :         if (spwID != currentSPWID_p)
     299             :           {
     300             :             // LogIO log_l(LogOrigin("CFStore2", "invokeGC"));
     301             :             // log_l << "Invoking Garbage Collector: ";
     302             :             // // The reason for invoking GC
     303             :             // if (currentSPWID_p < 0)      log_l << "Initial mopping-up";
     304             :             // else     log_l << "SPW" << currentSPWID_p << "->SPW" << spwID;
     305             :             // log_l << LogIO::DEBUGGING;
     306             : 
     307         418 :             clear(); currentSPWID_p=spwID;
     308             :           }
     309             :       }
     310       26675 :   }
     311             : }; // end casa namespace
     312             : 
     313             : 
     314             : 

Generated by: LCOV version 1.16