LCOV - code coverage report
Current view: top level - synthesis/TransformMachines - CFCache.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 27 0.0 %
Date: 2024-10-12 00:35:29 Functions: 0 13 0.0 %

          Line data    Source code
       1             : // -*- C++ -*-
       2             : //# ConvFuncDiskCache.cc: Definition of the ConvFuncDiskCache 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             : #ifndef SYNTHESIS_CFCACHE_H
      29             : #define SYNTHESIS_CFCACHE_H
      30             : 
      31             : #include <casacore/casa/Arrays/Matrix.h>
      32             : #include <msvis/MSVis/VisBuffer.h>
      33             : #include <casacore/images/Images/ImageInterface.h>
      34             : #include <casacore/images/Images/TempImage.h>
      35             : #include <casacore/images/Images/PagedImage.h>
      36             : #include <casacore/casa/Arrays/Array.h>
      37             : #include <casacore/casa/Arrays/Vector.h>
      38             : #include <casacore/casa/Logging/LogIO.h>
      39             : #include <casacore/casa/OS/Directory.h>
      40             : #include <casacore/casa/Logging/LogSink.h>
      41             : #include <casacore/casa/Logging/LogMessage.h>
      42             : #include <casacore/lattices/Lattices/LatticeCache.h>
      43             : #include <casacore/lattices/Lattices/ArrayLattice.h>
      44             : #include <casacore/coordinates/Coordinates/DirectionCoordinate.h>
      45             : #include <synthesis/TransformMachines/VPSkyJones.h>
      46             : #include <synthesis/TransformMachines/CFStore.h>
      47             : #include <synthesis/TransformMachines/CFStore2.h>
      48             : #include <synthesis/TransformMachines/CFDefs.h>
      49             : #include <synthesis/TransformMachines/Utils.h>
      50             : // #include <casa/Tables/Table.h>
      51             : 
      52             : namespace casa { //# NAMESPACE CASA - BEGIN
      53             :   using namespace CFDefs;
      54             :   // <summary> 
      55             :   //
      56             :   // An object to manage the caches of pre-computed convolution
      57             :   // functions on the disk and in the memory.
      58             :   //
      59             :   // </summary>
      60             :   
      61             :   // <use visibility=export>
      62             :   
      63             :   // <reviewed reviewer="" date="" tests="" demos="">
      64             :   
      65             :   // <prerequisite>
      66             :   //  CFStore class
      67             :   // </prerequisite>
      68             :   //
      69             :   // <etymology> 
      70             :   //
      71             :   // CFCache is an object, to write convolution
      72             :   // functions from the memory cache to the disk cache, and
      73             :   // search/load the disk cache for convolution functions for a give
      74             :   // Parallactic Angle.  
      75             :   //
      76             :   //</etymology>
      77             :   //
      78             :   // <synopsis> 
      79             :   //
      80             :   // FTMachines uses pre-computed convolution functions for gridding
      81             :   // (FTMachine::put()) and prediction (FTMachine::get()).  For
      82             :   // <linkto class=PBWProjectFT>PBWProjectFT</linkto>, the convolution
      83             :   // function computation is expensive.  Once computed, it is
      84             :   // efficient to cache these functions as a function of Parallactic
      85             :   // Angle and the value of the w-term (if significant). 
      86             :   //
      87             :   // CFCache class provides interface to the disk cache and
      88             :   // is used in <linkto class=PBWProjectFT>PBWProjectFT</linkto> to
      89             :   // search and load convolution functions from the disk.  If a new
      90             :   // convolution function is computed in <linkto
      91             :   // class=PBWProjectFT>PBWProjectFT</linkto>, the disk cache is
      92             :   // updated using the services of this class as well.
      93             :   //
      94             :   // </synopsis> 
      95             :   //
      96             :   // <example>
      97             :   // </example>
      98             :   //
      99             :   // <motivation>
     100             :   //
     101             :   // Factor out the code for managing convolution function caches
     102             :   // (memory and disk caches) from the FTMachine code.  This is a
     103             :   // specialized service, and has nothing to do with the details of
     104             :   // gridding and prediction of visibilities (which is the function of
     105             :   // FTMachines).
     106             :   //
     107             :   // </motivation>
     108             :   //
     109             :   // <todo asof="2005/07/21">
     110             :   //
     111             :   // <ul> Generalize to handle convolution functions for inhomogeneous
     112             :   // arrays and multi-feed antennas.
     113             :   //
     114             :   // </todo>
     115             :   //
     116             :   //----------------------------------------------------------------------
     117             :   class CFCacheTable
     118             :   {
     119             :   public:
     120           0 :     CFCacheTable(): freqList(), wList(), muellerList(), cfNameList() {};
     121           0 :     ~CFCacheTable() {};
     122             :     
     123           0 :     CFCacheTable& operator=(const CFCacheTable& other)
     124             :     {
     125             :       //      if (other != *this)
     126             :         {
     127           0 :           freqList = other.freqList;
     128           0 :           wList = other.wList;
     129           0 :           muellerList = other.muellerList;
     130           0 :           cfNameList = other.cfNameList;
     131             :         }
     132           0 :       return *this;
     133             :     }
     134             : 
     135             :     void init()
     136             :     {freqList.resize(0); wList.resize(0); muellerList.resize(0); cfNameList.resize(0);}
     137             : 
     138             :     std::vector<casacore::Double> freqList, wList;
     139             :     std::vector<casacore::Int> muellerList;
     140             :     std::vector<casacore::String> cfNameList;
     141             :   };
     142             :   //
     143             :   //----------------------------------------------------------------------
     144             :   //
     145             :   class CFCache
     146             :   {
     147             :   public:
     148             :     typedef casacore::Vector< CFStore > CFStoreCacheType;
     149             :     typedef casacore::Vector< CFStore2 > CFStoreCacheType2;
     150             :     typedef std::vector<CFCacheTable> CFCacheTableType;
     151             : 
     152           0 :     CFCache(const char *cfDir="CF"):
     153           0 :       memCache2_p(), memCacheWt2_p(),memCache_p(), memCacheWt_p(), 
     154           0 :       cfCacheTable_p(), XSup(), YSup(), paList(), 
     155           0 :       paList_p(), key2IndexMap(),
     156           0 :       Dir(""), WtImagePrefix(""), cfPrefix(cfDir), aux("aux.dat"), paCD_p(), avgPBReady_p(False),
     157           0 :       avgPBReadyQualifier_p(""), OTODone_p(False), loadPixBuf_p(True)
     158           0 :     {};
     159             :     CFCache& operator=(const CFCache& other);
     160             :     ~CFCache();
     161             :     //
     162             :     // Method to set the disk cache directory name
     163             :     //
     164           0 :     void setCacheDir(const char *dir) {Dir = casacore::String(dir);}
     165           0 :     casacore::String getCacheDir(CFCDirType dirType=USERDIR) {(void)dirType;return Dir;};
     166             : 
     167           0 :     void setWtImagePrefix(const char *prefix) {WtImagePrefix = prefix;}
     168           0 :     casacore::String getWtImagePrefix() {return WtImagePrefix;};
     169             : 
     170             :     void setLazyFill(const Bool& val);
     171             :     Bool isLazyFillOn() {return loadPixBuf_p;};
     172             :     //
     173             :     // Method to initialize the internal memory cache.
     174             :     //
     175             :     void initCache();
     176             :     void initCache2(casacore::Bool verbose=false, casacore::Float selectedPA=400.0, casacore::Float dPA=-1.0);
     177             :     void initCacheFromList2(const casacore::String& path, 
     178             :                             const casacore::Vector<casacore::String>& cfFileNames, 
     179             :                             const casacore::Vector<casacore::String>& cfWtFileNames, 
     180             :                             casacore::Float selectedPA, casacore::Float dPA,
     181             :                             const casacore::Int verbose=1);
     182             :     void initPolMaps(PolMapType& polMap, PolMapType& conjPolMap);
     183           0 :     inline casacore::Bool OTODone() {return OTODone_p;}
     184             :     //
     185             :     // Compute the size of the memory cache in bytes
     186             :     //
     187             :     casacore::Long size();
     188             :     //
     189             :     // Method to set the class to caluclate the differential
     190             :     // Parallactic Angle.  The ParAngleChangeDetector also holds the
     191             :     // delta PA value (user defined).
     192             :     //
     193           0 :     void setPAChangeDetector(const ParAngleChangeDetector& paCD) {paCD_p = paCD;};
     194             :     //
     195             :     // Methods to cache the convolution function.
     196             :     //
     197             :     // Top level method interfacing with the CFStore object
     198             :     //-------------------------------------------------------------------
     199             :     void cacheConvFunction(CFStore& cfs, 
     200             :                            casacore::String nameQualifier="",casacore::Bool savePA=true)
     201             :     {cacheConvFunction(cfs.pa, cfs,nameQualifier,savePA);}
     202             :     //-------------------------------------------------------------------
     203             :     // One level lower - the Parallactic angle can be separately
     204             :     // provided.
     205             :     void cacheConvFunction(const casacore::Quantity pa, CFStore& cfs,
     206             :                            casacore::String nameQualifier="",casacore::Bool savePA=true)
     207             :     {cacheConvFunction(pa.getValue("rad"), cfs, nameQualifier,savePA);}
     208             :     //-------------------------------------------------------------------
     209             :     // The Parallactic angle as a floating point number in radians.
     210             :     void cacheConvFunction(const casacore::Float pa, CFStore& cfs, 
     211             :                            casacore::String nameQualifier="",casacore::Bool savePA=true);
     212             :     //-------------------------------------------------------------------
     213             :     // Lowest level - all information about CFStore is explicitly
     214             :     // provided as basic types
     215             :     casacore::Int cacheConvFunction(casacore::Int which, const casacore::Float& pa, CFType& cf, 
     216             :                           casacore::CoordinateSystem& coords, casacore::CoordinateSystem& ftcoords, 
     217             :                           casacore::Int& convSize, 
     218             :                           casacore::Vector<casacore::Int>& xConvSupport, casacore::Vector<casacore::Int>& yConvSupport, 
     219             :                           casacore::Float convSampling, casacore::String nameQualifier="",casacore::Bool savePA=true);
     220             :     //-------------------------------------------------------------------
     221             :     // Methods to sarch for a convolution function in the caches (disk
     222             :     // or memory) for the give Parallactic Angle value.
     223             :     //
     224           0 :     casacore::Bool searchConvFunction(casacore::Int& which, const casacore::Quantity pa, const casacore::Quantity dPA )
     225           0 :     {return searchConvFunction(which, pa.getValue("rad"), dPA.getValue("rad"));};
     226             : 
     227             :     casacore::Bool searchConvFunction(casacore::Int& which, const casacore::Float pa, const casacore::Float dPA );
     228             :     //
     229             :     // Lower level method to load a convolution function from the disk.
     230             :     //
     231             :     casacore::Int loadFromDisk(casacore::Int where, casacore::Float pa, casacore::Float dPA,
     232             :                      casacore::Int Nx, CFStoreCacheType & convFuncCache,
     233             :                      CFStore& cfs, casacore::String nameQualifier="");
     234             :     //
     235             :     // Method to locate a convolution function for the given w-term
     236             :     // index and PA value.  This is the top level function that must
     237             :     // be used by the clients.  This uses searchConvFunction() and
     238             :     // loadFromDisk() methods and the private methods to return a
     239             :     // convolution function.
     240             :     //
     241             :     // Returns CFDefs::NOTCACHED if the convolution function was not
     242             :     // found in the cache, CFDefs::MEMCACHE or CFDefs::DISKCACHE if
     243             :     // the function was found in memory or disk cache respectively.
     244             :     //
     245             :     casacore::Int locateConvFunction(CFStore& cfs, CFStore& cftws, const casacore::Int Nw, 
     246             :                            const casacore::Quantity pa, const casacore::Quantity dPA, 
     247             :                            const casacore::Int mosXPos=0, const casacore::Int mosYPos=0)
     248             :     {return locateConvFunction(cfs, cftws, Nw,pa.getValue("rad"), dPA.getValue("rad"),mosXPos,mosYPos);};
     249             : 
     250             :     casacore::Int locateConvFunction(CFStore& cfs, const casacore::Int Nw, 
     251             :                            const casacore::Quantity pa, const casacore::Quantity dPA, 
     252             :                            const casacore::String& nameQualifier="",
     253             :                            const casacore::Int mosXPos=0, const casacore::Int mosYPos=0)
     254             :     {return locateConvFunction(cfs, Nw,pa.getValue("rad"), dPA.getValue("rad"),nameQualifier, mosXPos,mosYPos);};
     255             : 
     256             :     casacore::Int locateConvFunction(CFStore& cfs, CFStore& cfwts,
     257             :                            const casacore::Int Nw, const casacore::Float pa, const casacore::Float dPA,
     258             :                            const casacore::Int mosXPos=0, const casacore::Int mosYPos=0);
     259             : 
     260             :     casacore::Int locateConvFunction(CFStore& cfs, const casacore::Int Nw, const casacore::Float pa, const casacore::Float dPA, 
     261             :                            const casacore::String& nameQualifier="",
     262             :                            const casacore::Int mosXPos=0, const casacore::Int mosYPos=0);
     263             : 
     264             :     casacore::TableRecord getCFParams(const casacore::String& fileName,
     265             :                      casacore::Array<casacore::Complex>& pixelBuffer,
     266             :                      casacore::CoordinateSystem& coordSys, 
     267             :                      casacore::Double& sampling,
     268             :                      casacore::Double& paVal,
     269             :                      casacore::Int& xSupport, casacore::Int& ySupport,
     270             :                      casacore::Double& fVal, casacore::Double& wVal, casacore::Int& mVal,
     271             :                      casacore::Double& conjFreq, casacore::Int& conjPoln,
     272             :                      casacore::Bool loadPixels=true);
     273             :     //
     274             :     // Methods to write the auxillary information from the memory
     275             :     // cache to the disk cache.  Without this call, the disk cache
     276             :     // might not be complete.  It is safe to call this method at
     277             :     // anytime during the life of this object.
     278             :     //
     279             :     void flush();
     280             :     void flush(casacore::ImageInterface<casacore::Float>& avgPB, casacore::String qualifier=casacore::String(""));
     281             :     casacore::Int loadAvgPB(casacore::ImageInterface<casacore::Float>& avgPB, casacore::String qualifier=casacore::String(""));
     282           0 :     casacore::Int loadAvgPB(casacore::CountedPtr<casacore::ImageInterface<casacore::Float> > & avgPB, casacore::String qualifier=casacore::String(""))
     283           0 :     {if (avgPB.null()) avgPB = new casacore::TempImage<casacore::Float>(); return loadAvgPB(*avgPB,qualifier);};
     284             : 
     285             :     // loadAvgPB calls the method below if WtImgPrefix was set.
     286             :     casacore::Int loadWtImage(casacore::ImageInterface<casacore::Float>& avgPB, casacore::String qualifier);
     287             : 
     288           0 :     casacore::Bool avgPBReady(const casacore::String& qualifier=casacore::String("")) 
     289           0 :     {return (avgPBReady_p && (avgPBReadyQualifier_p == qualifier));};
     290             : 
     291             :     void summarize(CFStoreCacheType2& memCache, const casacore::String& message, const casacore::Bool cfsInfo=true);
     292             : 
     293             :     CFStoreCacheType2 memCache2_p, memCacheWt2_p;
     294             : 
     295             :   private:
     296             :     CFStoreCacheType memCache_p, memCacheWt_p;
     297             :     CFCacheTableType cfCacheTable_p;
     298             : 
     299             :     casacore::Matrix<casacore::Int> XSup, YSup;
     300             :     casacore::Vector<casacore::Float> paList, Sampling;
     301             :     std::vector<casacore::Float> paList_p;
     302             :     casacore::Matrix<casacore::Float> key2IndexMap; // Nx2 [PAVal, Freq]
     303             :     casacore::String Dir, WtImagePrefix, cfPrefix, aux;
     304             :     ParAngleChangeDetector paCD_p;
     305             :     //
     306             :     // Internal method to convert the direction co-ordinates of the
     307             :     // given casacore::CoordinateSystem to its Fourier conjuguate co-ordinates.
     308             :     //
     309             :     void makeFTCoordSys(const casacore::CoordinateSystem& coords,
     310             :                         const casacore::Int& convSize,
     311             :                         const casacore::Vector<casacore::Double>& ftRef,
     312             :                         casacore::CoordinateSystem& ftCoords);
     313             :     //
     314             :     // Internal method to add the given convolution function to the
     315             :     // memory cache.
     316             :     //
     317             :     casacore::Int addToMemCache(CFStoreCacheType& cfCache, 
     318             :                       casacore::Float pa, CFType* cf, casacore::CoordinateSystem& coords,
     319             :                       casacore::Vector<casacore::Int>& xConvSupport,
     320             :                       casacore::Vector<casacore::Int>& yConvSupport,
     321             :                       casacore::Float convSampling);
     322             :     CFStoreCacheType& getMEMCacheObj(const casacore::String& nameQualifier);
     323             : 
     324             :     void fillCFSFromDisk(const casacore::Directory dirObj, const casacore::String& pattern, 
     325             :                          CFStoreCacheType2& memStore, casacore::Bool showInfo=false, 
     326             :                          casacore::Float selectPAVal=400.0, casacore::Float dPA=-1.0,
     327             :                          const casacore::Int verbose=1);
     328             :     void fillCFListFromDisk(const casacore::Vector<casacore::String>& fileNames, const casacore::String& CFCDir,
     329             :                             CFStoreCacheType2& memStore,
     330             :                             casacore::Bool showInfo, casacore::Float selectPAVal, casacore::Float dPA,
     331             :                             const casacore::Int verbose=1);
     332             : 
     333             :     casacore::Bool avgPBReady_p;
     334             :     casacore::String avgPBReadyQualifier_p;
     335             :     casacore::Bool OTODone_p, loadPixBuf_p;
     336             :   };
     337             : }
     338             : 
     339             : #endif

Generated by: LCOV version 1.16