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_CFCACHE_H
29 #define SYNTHESIS_CFCACHE_H
30 
31 #include <casa/Arrays/Matrix.h>
32 #include <msvis/MSVis/VisBuffer.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  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  //----------------------------------------------------------------------
118  {
119  public:
120  CFCacheTable(): freqList(), wList(), muellerList(), cfNameList() {};
122 
124  {
125  // if (other != *this)
126  {
127  freqList = other.freqList;
128  wList = other.wList;
129  muellerList = other.muellerList;
130  cfNameList = other.cfNameList;
131  }
132  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:
150  typedef std::vector<CFCacheTable> CFCacheTableType;
151 
152  CFCache(const char *cfDir="CF"):
153  memCache2_p(), memCacheWt2_p(),memCache_p(), memCacheWt_p(),
154  cfCacheTable_p(), XSup(), YSup(), paList(),
155  paList_p(), key2IndexMap(),
156  Dir(""), WtImagePrefix(""), cfPrefix(cfDir), aux("aux.dat"), paCD_p(), avgPBReady_p(False),
157  avgPBReadyQualifier_p(""), OTODone_p(False), loadPixBuf_p(True)
158  {};
159  CFCache& operator=(const CFCache& other);
160  ~CFCache();
161  //
162  // Method to set the disk cache directory name
163  //
164  void setCacheDir(const char *dir) {Dir = casacore::String(dir);}
165  casacore::String getCacheDir(CFCDirType dirType=USERDIR) {(void)dirType;return Dir;};
166 
167  void setWtImagePrefix(const char *prefix) {WtImagePrefix = prefix;}
168  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  inline casacore::Bool OTODone() {return OTODone_p;}
184  //
185  // Compute the size of the memory cache in bytes
186  //
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  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  //-------------------------------------------------------------------
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.
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,
217  casacore::Int& convSize,
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  //
225  {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  //
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  //
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 
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 
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,
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();
283  {if (avgPB.null()) avgPB = new casacore::TempImage<casacore::Float>(); return loadAvgPB(*avgPB,qualifier);};
284 
285  // loadAvgPB calls the method below if WtImgPrefix was set.
287 
289  {return (avgPBReady_p && (avgPBReadyQualifier_p == qualifier));};
290 
291  void summarize(CFStoreCacheType2& memCache, const casacore::String& message, const casacore::Bool cfsInfo=true);
292 
294 
295  private:
298 
301  std::vector<casacore::Float> paList_p;
303  casacore::String Dir, WtImagePrefix, cfPrefix, aux;
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,
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,
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 
335  casacore::Bool OTODone_p, loadPixBuf_p;
336  };
337 }
338 
339 #endif
std::vector< casacore::Float > paList_p
Definition: CFCache.h:301
int Int
Definition: aipstype.h:50
std::vector< casacore::Double > wList
Definition: CFCache.h:138
casacore::Matrix< casacore::Float > key2IndexMap
Definition: CFCache.h:302
casacore::Bool OTODone()
Definition: CFCache.h:183
casacore::Vector< casacore::Float > Sampling
Definition: CFCache.h:300
An object to manage the caches of pre-computed convolution functions on the disk and in the memory...
Definition: CFCache.h:117
CFStoreCacheType memCacheWt_p
Definition: CFCache.h:296
CFCacheTable & operator=(const CFCacheTable &other)
Definition: CFCache.h:123
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:224
casacore::Bool avgPBReady(const casacore::String &qualifier=casacore::String(""))
Definition: CFCache.h:288
casacore::Matrix< casacore::Int > YSup
Definition: CFCache.h:299
PtrHolder< T > & operator=(const PtrHolder< T > &other)
casacore::Double conjFreq(const casacore::Double &freq, const casacore::Double &refFreq)
Definition: Utils.h:110
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:245
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:205
Get information about, and manipulate directories.
Definition: Directory.h:87
size_t size() const
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:334
casacore::String getWtImagePrefix()
Definition: CFCache.h:168
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)
void setCacheDir(const char *dir)
Method to set the disk cache directory name.
Definition: CFCache.h:164
long Long
Definition: aipstype.h:52
ParAngleChangeDetector paCD_p
Definition: CFCache.h:304
casacore::String getCacheDir(CFCDirType dirType=USERDIR)
Definition: CFCache.h:165
casacore::Bool OTODone_p
Definition: CFCache.h:335
std::vector< casacore::Double > freqList
Definition: CFCache.h:138
void setWtImagePrefix(const char *prefix)
Definition: CFCache.h:167
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
casacore::Vector< CFStore > CFStoreCacheType
Definition: CFCache.h:148
casacore::Int loadAvgPB(casacore::CountedPtr< casacore::ImageInterface< casacore::Float > > &avgPB, casacore::String qualifier=casacore::String(""))
Definition: CFCache.h:282
double Double
Definition: aipstype.h:55
std::string path(const std::string &name)
casacore::Bool avgPBReady_p
Definition: CFCache.h:333
std::vector< casacore::Int > muellerList
Definition: CFCache.h:139
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
std::vector< CFCacheTable > CFCacheTableType
Definition: CFCache.h:150
float Float
Definition: aipstype.h:54
//////////////////////////////////////////////////////////////////////////
Definition: Utils.h:184
const Bool False
Definition: aipstype.h:44
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:182
casacore::Vector< CFStore2 > CFStoreCacheType2
Definition: CFCache.h:149
std::vector< casacore::String > cfNameList
Definition: CFCache.h:140
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:250
CFStoreCacheType2 memCacheWt2_p
Definition: CFCache.h:293
const Qtype & getValue() const
Get value of quantum in current units (i.e.
void cacheConvFunction(CFStore &cfs, casacore::String nameQualifier="", casacore::Bool savePA=true)
Methods to cache the convolution function.
Definition: CFCache.h:199
casacore::Quantity pa
Definition: CFStore.h:90
void setPAChangeDetector(const ParAngleChangeDetector &paCD)
Method to set the class to caluclate the differential Parallactic Angle.
Definition: CFCache.h:193
String: the storage and methods of handling collections of characters.
Definition: String.h:223
CFCacheTableType cfCacheTable_p
Definition: CFCache.h:297
casacore::String WtImagePrefix
Definition: CFCache.h:303
Bool isLazyFillOn()
Definition: CFCache.h:171
const Bool True
Definition: aipstype.h:43
Interconvert pixel and world coordinates.
CFCache(const char *cfDir="CF")
Definition: CFCache.h:152