casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VisibilityResamplerBase.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //# VisibilityResamplerBase.h: Definition of the VisibilityResamplerBase 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 
29 #ifndef SYNTHESIS_TRANSFORM2_VISIBILITYRESAMPLERBASE_H
30 #define SYNTHESIS_TRANSFORM2_VISIBILITYRESAMPLERBASE_H
31 
37 #include <msvis/MSVis/VisBuffer2.h>
38 #include <casa/Arrays/Array.h>
39 #include <casa/Arrays/Vector.h>
41 
42 #include <casa/Logging/LogIO.h>
43 #include <casa/Logging/LogSink.h>
45 #include <casa/OS/Timer.h>
46 
47 namespace casa { //# NAMESPACE CASA - BEGIN
48  using namespace vi;
49  namespace refim{
51  {
52  public:
54  runTimeG_p(0.0), runTimeDG_p(0.0),runTimeG1_p(0.0), runTimeG2_p(0.0), runTimeG3_p(0.0), runTimeG4_p(0.0), runTimeG5_p(0.0), runTimeG6_p(0.0), runTimeG7_p(0.0),
55  timer_p(),
56  uvwScale_p(), offset_p(), chanMap_p(), polMap_p(), spwChanFreq_p(), spwChanConjFreq_p (), convFuncStore_p(), inc_p(),
57  cfMap_p(), conjCFMap_p(), paTolerance_p(360.0), cached_phaseGrad_p(),vb2CFBMap_p()
58 
59  {};
60  // VisibilityResamplerBase(const CFStore& cfs):
61  // uvwScale_p(), offset_p(), chanMap_p(), polMap_p(), convFuncStore_p(), inc_p(),
62  // cfMap_p(), conjCFMap_p()
63  // {setConvFunc(cfs);};
64 
66  uvwScale_p(), offset_p(), chanMap_p(), polMap_p(), spwChanFreq_p(), spwChanConjFreq_p (), convFuncStore_p(), inc_p(),
67  cfMap_p(), conjCFMap_p(), paTolerance_p(360.0),vb2CFBMap_p()
68  {copy(other);}
69 
71 
73 
74  virtual VisibilityResamplerBase* clone() = 0;
75 
76  virtual void copy(const VisibilityResamplerBase& other);
77  virtual void setParams(const casacore::Vector<casacore::Double>& uvwScale,
79  const casacore::Vector<casacore::Double>& dphase) = 0;
80 
81  virtual void setMaps(const casacore::Vector<casacore::Int>& chanMap, const casacore::Vector<casacore::Int>& polMap) = 0;
82  virtual void setCFMaps(const casacore::Vector<casacore::Int>& cfMap, const casacore::Vector<casacore::Int>& conjCFMap)=0;
83  virtual void setFreqMaps(const casacore::Matrix<casacore::Double>& spwChanFreqs, const casacore::Matrix<casacore::Double>& spwnChanConjFreqs) = 0;
84 
85  virtual void setConvFunc(const CFStore& cfs) = 0;
86  virtual void setPATolerance(const double& dPA) = 0;
87  //
88  //------------------------------------------------------------------------------
89  //
90  // Re-sample the griddedData on the VisBuffer (a.k.a gridding).
91  //
92  // In this class, these just call the private templated version.
93  // The first variant grids onto a double precision grid while the
94  // second one does it on a single precision grid.
95  //
96  virtual void DataToGrid(casacore::Array<casacore::DComplex>& griddedData, VBStore& vbs,
98  casacore::Bool useConjFreqCF=false) = 0;
99 
100  virtual void DataToGrid(casacore::Array<casacore::Complex>& griddedData, VBStore& vbs,
102  casacore::Bool useConjFreqCF=false) = 0;
103  //
104  //------------------------------------------------------------------------------
105  //
106  // Re-sample VisBuffer to a regular grid (griddedData) (a.k.a. de-gridding)
107  //
108  virtual void GridToData(VBStore& vbs,const casacore::Array<casacore::Complex>& griddedData) = 0;
109  // virtual void GridToData(VBStore& vbs, casacore::Array<casacore::Complex>& griddedData);
110 
111  virtual void ComputeResiduals(VBStore& vbs) = 0;
112 
113  // Forward looking genealogical baggage -- required for the
114  // MultiThreadedVisibilityResampler
115  virtual void init(const casacore::Bool& doublePrecision) = 0;
116  virtual void GatherGrids(casacore::Array<casacore::DComplex>& griddedData, casacore::Matrix<casacore::Double>& sumwt) = 0;
117  virtual void GatherGrids(casacore::Array<casacore::Complex>& griddedData, casacore::Matrix<casacore::Double>& sumwt) = 0;
118  virtual void initializePutBuffers(const casacore::Array<casacore::DComplex>& griddedData,
119  const casacore::Matrix<casacore::Double>& sumwt) = 0;
120  virtual void initializePutBuffers(const casacore::Array<casacore::Complex>& griddedData,
121  const casacore::Matrix<casacore::Double>& sumwt) = 0;
122  virtual void initializeDataBuffers(VBStore& vbs)=0;
123  //
124  // Aliases for more readable code at the FTMachine layer.
125  //
127  {GatherGrids(griddedData, sumwt);};
129  {GatherGrids(griddedData, sumwt);};
131  {initializePutBuffers(griddedData, sumwt);};
133  {initializePutBuffers(griddedData, sumwt);};
134  const casacore::Vector<casacore::Int> getCFMap() {return cfMap_p;};
135  const casacore::Vector<casacore::Int> getConjCFMap() {return conjCFMap_p;};
136 
137 
138  virtual void releaseBuffers() = 0;
139 // VBRow2CFMapType& getVBRow2CFMap() {return vbRow2CFMap_p;};
140  VB2CFBMap& getVBRow2CFBMap() {return *vb2CFBMap_p;};
141  // virtual casacore::Int makeVBRow2CFBMap(CFStore2& cfs,
142  // ConvolutionFunction& cf,
143  // const VisBuffer2& vb, const casacore::Quantity& dPA,
144  // const casacore::Vector<casacore::Int>& dataChan2ImChanMap,
145  // const casacore::Vector<casacore::Int>& dataPol2ImPolMap,
146  // const casacore::Vector<casacore::Double>& pointingOffset);
147 
148  void setFieldPhaseGrad(const casacore::Matrix<casacore::Complex>& phaseGrad) {cached_phaseGrad_p.reference(phaseGrad);};
149  void setVB2CFMap(const casacore::CountedPtr<refim::VB2CFBMap>& thisMap) {vb2CFBMap_p = thisMap;}
150 
151  casacore::Double runTimeG_p, runTimeDG_p, runTimeG1_p, runTimeG2_p, runTimeG3_p, runTimeG4_p, runTimeG5_p, runTimeG6_p, runTimeG7_p;
153  //
154  //------------------------------------------------------------------------------
155  //----------------------------Private parts-------------------------------------
156  //------------------------------------------------------------------------------
157  //
158  // private:
159  protected:
164  // casacore::Int inc0_p, inc1_p, inc2_p, inc3_p;
166  casacore::Int* __restrict__ incPtr_p;
168 // VBRow2CFMapType vbRow2CFMap_p;
172 
173  void sgrid(casacore::Int& ndim,
174  casacore::Double* __restrict__ pos,
175  casacore::Int* __restrict__ loc,
176  casacore::Int* __restrict__ off,
177  casacore::Complex& phasor, const casacore::Int& irow,
178  const casacore::Double* __restrict__ uvw,
179  const casacore::Double& dphase, const casacore::Double& freq,
180  const casacore::Double* __restrict__ scale,
181  const casacore::Double* __restrict__ offset,
182  const casacore::Float* __restrict__ sampling);
183 
184  inline casacore::Bool onGrid (const casacore::Int& nx, const casacore::Int& ny,
185  const casacore::Vector<casacore::Int>& __restrict__ loc,
186  const casacore::Vector<casacore::Int>& __restrict__ support) __restrict__
187  {
188  return (((loc(0)-support[0]) >= 0 ) && ((loc(0)+support[0]) < nx) &&
189  ((loc(1)-support[1]) >= 0 ) && ((loc(1)+support[1]) < ny));
190  };
191  inline casacore::Bool onGrid (const casacore::Int& nx, const casacore::Int& ny,
192  const casacore::Int& loc0, const casacore::Int& loc1,
193  const casacore::Int& support) __restrict__
194  {
195  return (((loc0-support) >= 0 ) && ((loc0+support) < nx) &&
196  ((loc1-support) >= 0 ) && ((loc1+support) < ny));
197  };
198 
199  // casacore::Array assignment operator in CASACore requires lhs.nelements()
200  // == 0 or lhs.nelements()=rhs.nelements()
201  // template <class T>
202  // inline void SETVEC(casacore::Vector<T>& lhs, const casacore::Vector<T>& rhs)
203  // {lhs.resize(rhs.shape()); lhs = rhs;};
204 
205 
206  //===============================================================================
207  // CASACORE-LEVEL MATERIAL
208  //===============================================================================
209  // Internal methods to address a 4D array. These should ulimately
210  // moved to a Array4D class in CASACore
211  //
212 
213  // This is called less frequently. Currently once per VisBuffer
214  inline void cacheAxisIncrements(const casacore::Int& n0, const casacore::Int& n1, const casacore::Int& n2, const casacore::Int& n3)
215  {
216  // inc0_p=1, inc1_p=inc0_p*n0, inc2_p=inc1_p*n1, inc3_p=inc2_p*n2;(void)n3;
217  inc_p.resize(4);
218  inc_p[0]=1; inc_p[1]=inc_p[0]*n0; inc_p[2]=inc_p[1]*n1; inc_p[3]=inc_p[2]*n2;(void)n3;
219  casacore::Bool D;
220  incPtr_p = inc_p.getStorage(D);
221  }
223  {cacheAxisIncrements(n[0],n[1],n[2],n[3]);}
224 
226  {inc.resize(4);inc[0]=1; inc[1]=inc[0]*n[0]; inc[2]=inc[1]*n[1]; inc[3]=inc[2]*n[2];(void)n[3];}
227 
228  inline void cacheAxisIncrements(const casacore::Int n[4], casacore::Int inc[4])
229  {inc[0]=1; inc[1]=inc[0]*n[0]; inc[2]=inc[1]*n[1]; inc[3]=inc[2]*n[2];(void)n[3];}
230 
231  // Version that use internally cached inc_p
232  // template <class T>
233  inline void addTo4DArray(casacore::DComplex* __restrict__& store, casacore::Int* __restrict__& iPos,
234  casacore::Complex& nvalue, casacore::Double& wt) __restrict__
235  {addTo4DArray(store, iPos, incPtr_p, nvalue, wt);}
236 
237  inline void addTo4DArray(casacore::Complex* __restrict__& store, casacore::Int* __restrict__& iPos,
238  casacore::Complex& nvalue, casacore::Double& wt) __restrict__
239  {addTo4DArray(store, iPos, incPtr_p, nvalue, wt);}
240 
241 
242  // Version where inc_p is supplied from outside
243  inline void addTo4DArray(casacore::DComplex* __restrict__& store, casacore::Int* __restrict__& iPos,
244  casacore::Int* __restrict__ inc, casacore::Complex& nvalue, casacore::Double& wt) __restrict__
245  {store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]] += (nvalue*casacore::Complex(wt));}
246 
247  inline void addTo4DArray(casacore::Complex* __restrict__& store, casacore::Int* __restrict__& iPos,
248  casacore::Int* __restrict__ inc, casacore::Complex& nvalue, casacore::Double& wt) __restrict__
249  {store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]] += (nvalue*casacore::Complex(wt));}
250 
251 
252  inline casacore::Complex getFrom4DArray(const casacore::Complex* __restrict__& store,
253  const casacore::Int* __restrict__& iPos,
255  // __restrict__
256  {return store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]];};
257 
258  inline casacore::Complex getFrom4DArray(const casacore::Complex* __restrict__& store,
260  // __restrict__
261  {return store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]];};
262 
263  inline casacore::DComplex getFrom4DArray(const casacore::DComplex* __restrict__& store,
264  const casacore::Int* __restrict__& iPos,
266  // __restrict__
267  {return store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]];};
268 
269  inline casacore::DComplex getFrom4DArray(const casacore::DComplex* __restrict__& store,
271  // __restrict__
272  {return store[iPos[0] + iPos[1]*inc[1] + iPos[2]*inc[2] +iPos[3]*inc[3]];};
273 
274 
275  // The following two methods are called in the innermost loop.
276  inline casacore::Complex getFrom4DArray(const casacore::Complex* __restrict__& store, const casacore::Int* __restrict__& iPos)
277  // __restrict__
278  {return getFrom4DArray(store, iPos, inc_p);}
279 
280  inline casacore::DComplex getFrom4DArray(const casacore::DComplex* __restrict__& store, const casacore::Int* __restrict__& iPos)
281  // __restrict__
282  {return getFrom4DArray(store, iPos, inc_p);}
283 
284  };
285 }; //# NAMESPACE CASA - END
286 };
287 #endif //
VB2CFBMap & getVBRow2CFBMap()
VBRow2CFMapType&amp; getVBRow2CFMap() {return vbRow2CFMap_p;};.
casacore::DComplex getFrom4DArray(const casacore::DComplex *__restrict__ &store, const casacore::Int *__restrict__ &iPos, const casacore::Vector< casacore::Int > &inc)
restrict
int Int
Definition: aipstype.h:50
void addTo4DArray(casacore::Complex *__restrict__ &store, casacore::Int *__restrict__ &iPos, casacore::Complex &nvalue, casacore::Double &wt) __restrict__
casacore::Bool onGrid(const casacore::Int &nx, const casacore::Int &ny, const casacore::Int &loc0, const casacore::Int &loc1, const casacore::Int &support) __restrict__
void cacheAxisIncrements(const casacore::Int n[4], casacore::Int inc[4])
StatsData< AccumType > copy(const StatsData< AccumType > &stats)
void finalizeToSky(casacore::Array< casacore::DComplex > &griddedData, casacore::Matrix< casacore::Double > &sumwt)
Aliases for more readable code at the FTMachine layer.
casacore::Complex getFrom4DArray(const casacore::Complex *__restrict__ &store, const casacore::Int *__restrict__ &iPos, const casacore::Vector< casacore::Int > &inc)
restrict
const casacore::Vector< casacore::Int > getCFMap()
void addTo4DArray(casacore::DComplex *__restrict__ &store, casacore::Int *__restrict__ &iPos, casacore::Int *__restrict__ inc, casacore::Complex &nvalue, casacore::Double &wt) __restrict__
Version where inc_p is supplied from outside.
double paTolerance_p
VBRow2CFMapType vbRow2CFMap_p;.
casacore::Bool onGrid(const casacore::Int &nx, const casacore::Int &ny, const casacore::Vector< casacore::Int > &__restrict__ loc, const casacore::Vector< casacore::Int > &__restrict__ support) __restrict__
PtrHolder< T > & operator=(const PtrHolder< T > &other)
VisibilityResamplerBase(const VisibilityResamplerBase &other)
VisibilityResamplerBase(const CFStore&amp; cfs): uvwScale_p(), offset_p(), chanMap_p(), polMap_p(), convFuncStore_p(), inc_p(), cfMap_p(), conjCFMap_p() {setConvFunc(cfs);};.
void cacheAxisIncrements(const casacore::Int &n0, const casacore::Int &n1, const casacore::Int &n2, const casacore::Int &n3)
casacore::Array assignment operator in CASACore requires lhs.nelements() == 0 or lhs.nelements()=rhs.nelements() template &lt;class t&gt;=&quot;&quot;&gt; inline void SETVEC(casacore::Vector&lt;T&gt;&amp; lhs, const casacore::Vector&lt;T&gt;&amp; rhs) {lhs.resize(rhs.shape()); lhs = rhs;};
casacore::Complex getFrom4DArray(const casacore::Complex *__restrict__ &store, const casacore::Vector< casacore::Int > iPos, const casacore::Vector< casacore::Int > &inc)
restrict
const casacore::Vector< casacore::Int > getConjCFMap()
casacore::Matrix< casacore::Complex > cached_phaseGrad_p
casacore::DComplex getFrom4DArray(const casacore::DComplex *__restrict__ &store, const casacore::Vector< casacore::Int > iPos, const casacore::Vector< casacore::Int > &inc)
restrict
casacore::CountedPtr< refim::VB2CFBMap > vb2CFBMap_p
void initializeToSky(const casacore::Array< casacore::Complex > &griddedData, const casacore::Matrix< casacore::Double > &sumwt)
casacore::Vector< casacore::Double > uvwScale_p
-------------------------—Private parts----------------------------------—
void addTo4DArray(casacore::Complex *__restrict__ &store, casacore::Int *__restrict__ &iPos, casacore::Int *__restrict__ inc, casacore::Complex &nvalue, casacore::Double &wt) __restrict__
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
casacore::Vector< casacore::Int > conjCFMap_p
void finalizeToSky(casacore::Array< casacore::Complex > &griddedData, casacore::Matrix< casacore::Double > &sumwt)
double Double
Definition: aipstype.h:55
LatticeExprNode ndim(const LatticeExprNode &expr)
1-argument function to get the dimensionality of a lattice.
void addTo4DArray(casacore::DComplex *__restrict__ &store, casacore::Int *__restrict__ &iPos, casacore::Complex &nvalue, casacore::Double &wt) __restrict__
Version that use internally cached inc_p template &lt;class t&gt;=&quot;&quot;&gt;
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void cacheAxisIncrements(const casacore::Vector< casacore::Int > &n, casacore::Vector< casacore::Int > &inc)
casacore::Complex getFrom4DArray(const casacore::Complex *__restrict__ &store, const casacore::Int *__restrict__ &iPos)
The following two methods are called in the innermost loop.
measure the time it takes to execute parts of a program
Definition: Timer.h:127
float Float
Definition: aipstype.h:54
casacore::Vector< casacore::Int > polMap_p
FrequencySelection * clone() const
casacore::Vector< casacore::Int > inc_p
casacore::Int inc0_p, inc1_p, inc2_p, inc3_p;
void resize(size_t len, Bool copyValues=False)
Definition: Vector.h:167
void initializeToSky(const casacore::Array< casacore::DComplex > &griddedData, const casacore::Matrix< casacore::Double > &sumwt)
casacore::Matrix< casacore::Double > spwChanFreq_p
void setVB2CFMap(const casacore::CountedPtr< refim::VB2CFBMap > &thisMap)
void setFieldPhaseGrad(const casacore::Matrix< casacore::Complex > &phaseGrad)
virtual casacore::Int makeVBRow2CFBMap(CFStore2&amp; cfs, ConvolutionFunction&amp; cf, const VisBuffer2&amp; vb...
void cacheAxisIncrements(const casacore::Vector< casacore::Int > &n)
casacore::DComplex getFrom4DArray(const casacore::DComplex *__restrict__ &store, const casacore::Int *__restrict__ &iPos)
restrict