LCOV - code coverage report
Current view: top level - synthesis/TransformMachines - CFStore2.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 129 0.0 %
Date: 2024-10-10 19:51:30 Functions: 0 17 0.0 %

          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: 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             : #include <synthesis/TransformMachines/CFStore2.h>
      29             : #include <synthesis/TransformMachines/CFBuffer.h>
      30             : #include <synthesis/TransformMachines/CFCell.h>
      31             : #include <synthesis/TransformMachines/Utils.h>
      32             : #include <synthesis/TransformMachines/SynthesisError.h>
      33             : #include <synthesis/TransformMachines/PolOuterProduct.h>
      34             : 
      35             : using namespace casacore;
      36             : namespace casa{
      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           0 :   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           0 :     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           0 :     if (paNdx < 0) 
      89           0 :       {paNdx=pa_p.nelements();pa_p.resize(paNdx+1,retainValues);};
      90           0 :     if (antNdx < 0) 
      91           0 :       {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           0 :     storage_p.resize(pa_p.nelements(), ant1_p.nelements(), retainValues);
      97             :     
      98           0 :     pa_p[paNdx] = pa;
      99           0 :     ant1_p[antNdx] = ant1;
     100           0 :     ant2_p[antNdx] = ant2;
     101             : 
     102           0 :     Vector<Int> pos(2);pos(0)=paNdx;pos(1)=antNdx;
     103           0 :     if (storage_p(pos(0),pos(1)).null())
     104             :       {
     105           0 :         storage_p(pos(0),pos(1)) = new CFBuffer;
     106           0 :         storage_p(pos(0),pos(1))->setDir(cfCacheDir_p);
     107             :       }
     108           0 :     return pos;
     109           0 :   };
     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("CFStore2::setCFBuffer called!"));
     118             :     // Vector<Int> pos=resize(pa,ant1,ant2);
     119             :     // storage_p(pos[0], pos[1]) = dataPtr;
     120             :   }
     121             :   //
     122             :   //---------------------------------------------------------------
     123             :   //
     124           0 :   CountedPtr<CFBuffer>& CFStore2::getCFBuffer(const Quantity& pa, 
     125             :                                               const Quantity& paTol, 
     126             :                                               const Int& ant1, const Int& ant2)
     127             :   {
     128             :     Int paNdx, antNdx;
     129           0 :     getIndex(pa,paTol,ant1,ant2,paNdx, antNdx);
     130           0 :     if ((paNdx < 0) || (antNdx < 0)) 
     131           0 :         throw(CFNotCached("CFStore2::getIndex: Index not found"));
     132             :       
     133           0 :     return getCFBuffer(paNdx, antNdx);
     134             :   }
     135             :   //
     136             :   //---------------------------------------------------------------
     137             :   //
     138             :   // Get CFBuffer by direct indexing
     139           0 :   CountedPtr<CFBuffer>& CFStore2::getCFBuffer(const Int& paNdx, const Int& antNdx)
     140             :   {
     141           0 :     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           0 :   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           0 :     LogIO log_l(LogOrigin("CFStore2", "makePersistent(pa)[R&D]"));
     165             :     (void)cfName;
     166             :     Int paNdx, antNdx;
     167           0 :     getIndex(pa,dPA,ant1,ant2,paNdx, antNdx);
     168             :     
     169           0 :     log_l << "Saving " << storage_p(paNdx,antNdx)->shape().product() << " "
     170             :           << "CFs for PA = " << pa.getValue("deg") 
     171             :           << " BaselineType = (" << ant1 << "," << ant2 << ")" 
     172           0 :           << LogIO::POST;
     173           0 :     ostringstream name;
     174           0 :     name << String(qualifier) << "CFS_" << paNdx << "_" << antNdx;
     175           0 :     storage_p(paNdx,antNdx)->makePersistent(dir, name.str().c_str());
     176           0 :   }
     177             :   //
     178             :   //---------------------------------------------------------------
     179             :   // This version saves the entire storage of CFStore (all CFs
     180             :   // in the CFStore).
     181           0 :   void CFStore2::makePersistent(const char *dir,
     182             :                                 const char *cfName,
     183             :                                 const char *qualifier)
     184             :   {
     185             :     (void)cfName;
     186           0 :     LogIO log_l(LogOrigin("CFStore2", "makePersistent[R&D]"));
     187             :     //const char *formedName;
     188             : 
     189           0 :     for (Int i=0;i<storage_p.shape()(0);i++)
     190           0 :       for (Int j=0;j<storage_p.shape()(1);j++)
     191             :         {
     192           0 :           log_l << "Writing CFStore("<<i<<","<<j<<") of shape " << storage_p(i,j)->shape() << LogIO::POST;
     193           0 :           ostringstream name;
     194             :           //name << dir << "/" << qualifier << "CFS_" << i << "_" << j;
     195           0 :           name << String(qualifier) << "CFS_" << i << "_" << j;
     196             :           // if (String(cfName) == "") formedName = name.str().c_str();
     197             :           // else              formedName = cfName;
     198           0 :           storage_p(i,j)->makePersistent(dir,name.str().c_str());
     199           0 :         }
     200           0 :   }
     201             :   //
     202             :   //---------------------------------------------------------------
     203             :   //
     204           0 :   void CFStore2::primeTheCFB()
     205             :   {
     206           0 :     IPosition shp=getShape();
     207           0 :     for (Int i=0; i<shp(0); i++)
     208           0 :       for (Int j=0; j<shp(1); j++)
     209           0 :         getCFBuffer(i,j)->primeTheCache();
     210           0 :   }
     211             :   //
     212             :   //---------------------------------------------------------------
     213             :   //
     214           0 :   void CFStore2::initMaps(const VisBuffer& vb, const Matrix<Double>& freqSelection, const Double& imRefFreq)
     215             :   {
     216           0 :     for (Int i=0;i<storage_p.shape()(0);i++)
     217           0 :       for (Int j=0;j<storage_p.shape()(1);j++)
     218           0 :         storage_p(i,j)->initMaps(vb, freqSelection, imRefFreq);
     219           0 :   }
     220             :   //
     221             :   //---------------------------------------------------------------
     222             :   //
     223           0 :   void CFStore2::initPolMaps(PolMapType& polMap, PolMapType& conjPolMap)
     224             :   {
     225           0 :     IPosition shp=getShape();
     226           0 :     for (Int i=0; i<shp(0); i++)
     227           0 :       for (Int j=0; j<shp(1); j++)
     228           0 :         getCFBuffer(i,j)->initPolMaps(polMap, conjPolMap);
     229           0 :   }
     230             :   //
     231             :   //---------------------------------------------------------------
     232             :   //
     233           0 :   void CFStore2::clear()
     234             :   {
     235           0 :     IPosition cfsShape = getStorage().shape();
     236             : 
     237           0 :     for (Int ib=0;ib<cfsShape(0); ib++)
     238           0 :       for(int it=0;it<cfsShape(1); it++)
     239           0 :           getStorage()(ib,it)->clear();
     240           0 :   }
     241             :   //
     242             :   //---------------------------------------------------------------
     243             :   //
     244           0 :   Double CFStore2::memUsage()
     245             :   {
     246           0 :     IPosition cfsShape = getStorage().shape();
     247           0 :     Double memUsed=0;
     248           0 :     for (Int ib=0;ib<cfsShape(0); ib++)
     249           0 :       for(int it=0;it<cfsShape(1); it++)
     250             :         {
     251           0 :           IPosition cfbShape = getStorage()(ib,it)->getStorage().shape();
     252           0 :           for(int ip=0;ip<cfbShape(2); ip++)
     253           0 :             for(Int ich=0;ich<cfbShape(0);ich++)
     254           0 :               for(Int iw=0;iw<cfbShape(1); iw++)
     255           0 :                 memUsed += getStorage()(ib,it)->getStorage()(ich,iw,ip)->getStorage()->shape()
     256           0 :                   .product()*sizeof(Complex);
     257           0 :         }
     258           0 :     return memUsed;
     259           0 :   }
     260             :   //
     261             :   //---------------------------------------------------------------
     262             :   //
     263           0 :   Int CFStore2::nearestPA(const Quantity& pa, const Quantity& paTol)
     264             :     {
     265           0 :       Int n=pa_p.nelements(), junk=-1;
     266           0 :       Float dpa=paTol.getValue("rad"),
     267           0 :         paVal = pa.getValue("rad"), cpa;
     268             : 
     269           0 :       for(Int i=0;i<n;i++)
     270             :         {
     271           0 :           cpa = pa_p(i).getValue("rad");
     272             :           //      cerr << "##### " << i << " " << cpa*57.2956 << " " << paVal*57.2956 << " " << dpa*57.2956 << " " << (fabs(cpa - paVal))*57.2956 << endl; 
     273             :           // if (fabs(cpa - paVal) > dpa) 
     274             :           //   {cout << "%%%%% "; cin >> junk;}
     275           0 :           if (fabs(cpa - paVal) < dpa) {junk=i;break;}
     276             :         }
     277           0 :       return junk;
     278             :     }
     279             :   //
     280             :   //---------------------------------------------------------------
     281             :   //
     282           0 :   void CFStore2::setCFCacheDir(const String& dir)
     283             :   {
     284           0 :     IPosition cfsShape = getStorage().shape();
     285             : 
     286           0 :     for (Int ib=0;ib<cfsShape(0); ib++)
     287           0 :       for(int it=0;it<cfsShape(1); it++)
     288           0 :           getStorage()(ib,it)->setDir(dir);
     289             : 
     290           0 :     cfCacheDir_p=dir;
     291           0 :   }
     292             :   //
     293             :   //---------------------------------------------------------------
     294             :   //
     295           0 :   void CFStore2::invokeGC(const Int& spwID)
     296             :   {
     297           0 :     if (isLazyFillOn())
     298             :       {
     299           0 :         if (spwID != currentSPWID_p)
     300             :           {
     301             :             // While the message below is useful as NORMAL1, in a
     302             :             // parallel run, it appears on the console.  So shutting
     303             :             // it down.
     304             : 
     305             :             // LogIO log_l(LogOrigin("CFStore2", "invokeGC"));
     306             :             // log_l << "Invoking Garbage Collector: ";
     307             :             // // The reason for invoking GC
     308             :             // if (currentSPWID_p < 0)      log_l << "Initial mopping-up";
     309             :             // else     log_l << "SPW" << currentSPWID_p << "->SPW" << spwID;
     310             :             // log_l << LogIO::NORMAL1;
     311             : 
     312           0 :             clear(); currentSPWID_p=spwID;
     313             :           }
     314             :       }
     315           0 :   }
     316             : }; // end casa namespace
     317             : 
     318             : 
     319             : 

Generated by: LCOV version 1.16