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