CFCache.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //# ConvFuncDiskCache.cc: Definition of the ConvFuncDiskCache class
00003 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //# $Id$
00028 #ifndef SYNTHESIS_CFCACHE_H
00029 #define SYNTHESIS_CFCACHE_H
00030 
00031 #include <casa/Arrays/Matrix.h>
00032 #include <msvis/MSVis/VisBuffer.h>
00033 #include <images/Images/ImageInterface.h>
00034 #include <images/Images/TempImage.h>
00035 #include <images/Images/PagedImage.h>
00036 #include <casa/Arrays/Array.h>
00037 #include <casa/Arrays/Vector.h>
00038 #include <casa/Logging/LogIO.h>
00039 #include <casa/OS/Directory.h>
00040 #include <casa/Logging/LogSink.h>
00041 #include <casa/Logging/LogMessage.h>
00042 #include <lattices/Lattices/LatticeCache.h>
00043 #include <lattices/Lattices/ArrayLattice.h>
00044 #include <coordinates/Coordinates/DirectionCoordinate.h>
00045 #include <synthesis/TransformMachines/VPSkyJones.h>
00046 #include <synthesis/TransformMachines/CFStore.h>
00047 #include <synthesis/TransformMachines/CFStore2.h>
00048 #include <synthesis/TransformMachines/CFDefs.h>
00049 #include <synthesis/TransformMachines/Utils.h>
00050 // #include <casa/Tables/Table.h>
00051 
00052 namespace casa { //# NAMESPACE CASA - BEGIN
00053   using namespace CFDefs;
00054   // <summary> 
00055   //
00056   // An object to manage the caches of pre-computed convolution
00057   // functions on the disk and in the memory.
00058   //
00059   // </summary>
00060   
00061   // <use visibility=export>
00062   
00063   // <reviewed reviewer="" date="" tests="" demos="">
00064   
00065   // <prerequisite>
00066   //  CFStore class
00067   // </prerequisite>
00068   //
00069   // <etymology> 
00070   //
00071   // CFCache is an object, to write convolution
00072   // functions from the memory cache to the disk cache, and
00073   // search/load the disk cache for convolution functions for a give
00074   // Parallactic Angle.  
00075   //
00076   //</etymology>
00077   //
00078   // <synopsis> 
00079   //
00080   // FTMachines uses pre-computed convolution functions for gridding
00081   // (FTMachine::put()) and prediction (FTMachine::get()).  For
00082   // <linkto class=PBWProjectFT>PBWProjectFT</linkto>, the convolution
00083   // function computation is expensive.  Once computed, it is
00084   // efficient to cache these functions as a function of Parallactic
00085   // Angle and the value of the w-term (if significant). 
00086   //
00087   // CFCache class provides interface to the disk cache and
00088   // is used in <linkto class=PBWProjectFT>PBWProjectFT</linkto> to
00089   // search and load convolution functions from the disk.  If a new
00090   // convolution function is computed in <linkto
00091   // class=PBWProjectFT>PBWProjectFT</linkto>, the disk cache is
00092   // updated using the services of this class as well.
00093   //
00094   // </synopsis> 
00095   //
00096   // <example>
00097   // </example>
00098   //
00099   // <motivation>
00100   //
00101   // Factor out the code for managing convolution function caches
00102   // (memory and disk caches) from the FTMachine code.  This is a
00103   // specialized service, and has nothing to do with the details of
00104   // gridding and prediction of visibilities (which is the function of
00105   // FTMachines).
00106   //
00107   // </motivation>
00108   //
00109   // <todo asof="2005/07/21">
00110   //
00111   // <ul> Generalize to handle convolution functions for inhomogeneous
00112   // arrays and multi-feed antennas.
00113   //
00114   // </todo>
00115   //
00116   //----------------------------------------------------------------------
00117   class CFCacheTable
00118   {
00119   public:
00120     CFCacheTable(): freqList(), wList(), muellerList(), cfNameList() {};
00121     ~CFCacheTable() {};
00122     
00123     CFCacheTable& operator=(const CFCacheTable& other)
00124     {
00125       //      if (other != *this)
00126         {
00127           freqList = other.freqList;
00128           wList = other.wList;
00129           muellerList = other.muellerList;
00130           cfNameList = other.cfNameList;
00131         }
00132       return *this;
00133     }
00134 
00135     void init()
00136     {freqList.resize(0); wList.resize(0); muellerList.resize(0); cfNameList.resize(0);}
00137 
00138     vector<Double> freqList, wList;
00139     vector<Int> muellerList;
00140     vector<String> cfNameList;
00141   };
00142   //
00143   //----------------------------------------------------------------------
00144   //
00145   class CFCache
00146   {
00147   public:
00148     typedef Vector< CFStore > CFStoreCacheType;
00149     typedef Vector< CFStore2 > CFStoreCacheType2;
00150     typedef vector<CFCacheTable> CFCacheTableType;
00151     CFCache(const char *cfDir="CF"):
00152       memCache2_p(), memCacheWt2_p(),memCache_p(), memCacheWt_p(), 
00153       cfCacheTable_p(), XSup(), YSup(), paList(), 
00154       paList_p(), key2IndexMap(),
00155       Dir(""), WtImagePrefix(""), cfPrefix(cfDir), aux("aux.dat"), paCD_p(), avgPBReady_p(False),
00156       avgPBReadyQualifier_p(""), OTODone_p(False)
00157     {};
00158     CFCache& operator=(const CFCache& other);
00159     ~CFCache();
00160     //
00161     // Method to set the disk cache directory name
00162     //
00163     void setCacheDir(const char *dir) {Dir = String(dir);}
00164     String getCacheDir() {return Dir;};
00165 
00166     void setWtImagePrefix(const char *prefix) {WtImagePrefix = prefix;}
00167     String getWtImagePrefix() {return WtImagePrefix;};
00168     //
00169     // Method to initialize the internal memory cache.
00170     //
00171     void initCache();
00172     void initCache2(Bool verbose=False, Float selectedPA=400.0, Float dPA=-1.0);
00173     void initCacheFromList2(const String& path, 
00174                             const Vector<String>& cfFileNames, 
00175                             const Vector<String>& cfWtFileNames, 
00176                             Float selectedPA, Float dPA,
00177                             const Int verbose=1);
00178     void initPolMaps(PolMapType& polMap, PolMapType& conjPolMap);
00179     inline Bool OTODone() {return OTODone_p;}
00180     //
00181     // Compute the size of the memory cache in bytes
00182     //
00183     Long size();
00184     //
00185     // Method to set the class to caluclate the differential
00186     // Parallactic Angle.  The ParAngleChangeDetector also holds the
00187     // delta PA value (user defined).
00188     //
00189     void setPAChangeDetector(const ParAngleChangeDetector& paCD) {paCD_p = paCD;};
00190     //
00191     // Methods to cache the convolution function.
00192     //
00193     // Top level method interfacing with the CFStore object
00194     //-------------------------------------------------------------------
00195     void cacheConvFunction(CFStore& cfs, 
00196                            String nameQualifier="",Bool savePA=True)
00197     {cacheConvFunction(cfs.pa, cfs,nameQualifier,savePA);}
00198     //-------------------------------------------------------------------
00199     // One level lower - the Parallactic angle can be separately
00200     // provided.
00201     void cacheConvFunction(const Quantity pa, CFStore& cfs,
00202                            String nameQualifier="",Bool savePA=True)
00203     {cacheConvFunction(pa.getValue("rad"), cfs, nameQualifier,savePA);}
00204     //-------------------------------------------------------------------
00205     // The Parallactic angle as a floating point number in radians.
00206     void cacheConvFunction(const Float pa, CFStore& cfs, 
00207                            String nameQualifier="",Bool savePA=True);
00208     //-------------------------------------------------------------------
00209     // Lowest level - all information about CFStore is explicitly
00210     // provided as basic types
00211     Int cacheConvFunction(Int which, const Float& pa, CFType& cf, 
00212                           CoordinateSystem& coords, CoordinateSystem& ftcoords, 
00213                           Int& convSize, 
00214                           Vector<Int>& xConvSupport, Vector<Int>& yConvSupport, 
00215                           Float convSampling, String nameQualifier="",Bool savePA=True);
00216     //-------------------------------------------------------------------
00217     // Methods to sarch for a convolution function in the caches (disk
00218     // or memory) for the give Parallactic Angle value.
00219     //
00220     Bool searchConvFunction(Int& which, const Quantity pa, const Quantity dPA )
00221     {return searchConvFunction(which, pa.getValue("rad"), dPA.getValue("rad"));};
00222 
00223     Bool searchConvFunction(Int& which, const Float pa, const Float dPA );
00224     //
00225     // Lower level method to load a convolution function from the disk.
00226     //
00227     Int loadFromDisk(Int where, Float pa, Float dPA,
00228                      Int Nx, CFStoreCacheType & convFuncCache,
00229                      CFStore& cfs, String nameQualifier="");
00230     //
00231     // Method to locate a convolution function for the given w-term
00232     // index and PA value.  This is the top level function that must
00233     // be used by the clients.  This uses searchConvFunction() and
00234     // loadFromDisk() methods and the private methods to return a
00235     // convolution function.
00236     //
00237     // Returns CFDefs::NOTCACHED if the convolution function was not
00238     // found in the cache, CFDefs::MEMCACHE or CFDefs::DISKCACHE if
00239     // the function was found in memory or disk cache respectively.
00240     //
00241     Int locateConvFunction(CFStore& cfs, CFStore& cftws, const Int Nw, 
00242                            const Quantity pa, const Quantity dPA, 
00243                            const Int mosXPos=0, const Int mosYPos=0)
00244     {return locateConvFunction(cfs, cftws, Nw,pa.getValue("rad"), dPA.getValue("rad"),mosXPos,mosYPos);};
00245 
00246     Int locateConvFunction(CFStore& cfs, const Int Nw, 
00247                            const Quantity pa, const Quantity dPA, 
00248                            const String& nameQualifier="",
00249                            const Int mosXPos=0, const Int mosYPos=0)
00250     {return locateConvFunction(cfs, Nw,pa.getValue("rad"), dPA.getValue("rad"),nameQualifier, mosXPos,mosYPos);};
00251 
00252     Int locateConvFunction(CFStore& cfs, CFStore& cfwts,
00253                            const Int Nw, const Float pa, const Float dPA,
00254                            const Int mosXPos=0, const Int mosYPos=0);
00255 
00256     Int locateConvFunction(CFStore& cfs, const Int Nw, const Float pa, const Float dPA, 
00257                            const String& nameQualifier="",
00258                            const Int mosXPos=0, const Int mosYPos=0);
00259 
00260     TableRecord getCFParams(const String& fileName,
00261                      Array<Complex>& pixelBuffer,
00262                      CoordinateSystem& coordSys, 
00263                      Double& sampling,
00264                      Double& paVal,
00265                      Int& xSupport, Int& ySupport,
00266                      Double& fVal, Double& wVal, Int& mVal,
00267                      Double& conjFreq, Int& conjPoln,
00268                      Bool loadPixels=True);
00269     //
00270     // Methods to write the auxillary information from the memory
00271     // cache to the disk cache.  Without this call, the disk cache
00272     // might not be complete.  It is safe to call this method at
00273     // anytime during the life of this object.
00274     //
00275     void flush();
00276     void flush(ImageInterface<Float>& avgPB, String qualifier=String(""));
00277     Int loadAvgPB(ImageInterface<Float>& avgPB, String qualifier=String(""));
00278     Int loadAvgPB(CountedPtr<ImageInterface<Float> > & avgPB, String qualifier=String(""))
00279     {if (avgPB.null()) avgPB = new TempImage<Float>(); return loadAvgPB(*avgPB,qualifier);};
00280 
00281     // loadAvgPB calls the method below if WtImgPrefix was set.
00282     Int loadWtImage(ImageInterface<Float>& avgPB, String qualifier);
00283 
00284     Bool avgPBReady(const String& qualifier=String("")) 
00285     {return (avgPBReady_p && (avgPBReadyQualifier_p == qualifier));};
00286 
00287     void summarize(CFStoreCacheType2& memCache, const String& message, const Bool cfsInfo=True);
00288 
00289     CFStoreCacheType2 memCache2_p, memCacheWt2_p;
00290 
00291   private:
00292     CFStoreCacheType memCache_p, memCacheWt_p;
00293     CFCacheTableType cfCacheTable_p;
00294 
00295     Matrix<Int> XSup, YSup;
00296     Vector<Float> paList, Sampling;
00297     vector<Float> paList_p;
00298     Matrix<Float> key2IndexMap; // Nx2 [PAVal, Freq]
00299     String Dir, WtImagePrefix, cfPrefix, aux;
00300     ParAngleChangeDetector paCD_p;
00301     //
00302     // Internal method to convert the direction co-ordinates of the
00303     // given CoordinateSystem to its Fourier conjuguate co-ordinates.
00304     //
00305     void makeFTCoordSys(const CoordinateSystem& coords,
00306                         const Int& convSize,
00307                         const Vector<Double>& ftRef,
00308                         CoordinateSystem& ftCoords);
00309     //
00310     // Internal method to add the given convolution function to the
00311     // memory cache.
00312     //
00313     Int addToMemCache(CFStoreCacheType& cfCache, 
00314                       Float pa, CFType* cf, CoordinateSystem& coords,
00315                       Vector<Int>& xConvSupport,
00316                       Vector<Int>& yConvSupport,
00317                       Float convSampling);
00318     CFStoreCacheType& getMEMCacheObj(const String& nameQualifier);
00319 
00320     void fillCFSFromDisk(const Directory dirObj, const String& pattern, 
00321                          CFStoreCacheType2& memStore, Bool showInfo=False, 
00322                          Float selectPAVal=400.0, Float dPA=-1.0,
00323                          const Int verbose=1);
00324     void fillCFListFromDisk(const Vector<String>& fileNames, const String& CFCDir,
00325                             CFStoreCacheType2& memStore,
00326                             Bool showInfo, Float selectPAVal, Float dPA,
00327                             const Int verbose=1);
00328 
00329     Bool avgPBReady_p;
00330     String avgPBReadyQualifier_p;
00331     Bool OTODone_p;
00332   };
00333 }
00334 
00335 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1