Line data Source code
1 : // -*- C++ -*-
2 : //# CFStore2.cc: Implementation of the CFStore2 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 : #include <synthesis/TransformMachines2/CFStore2.h>
29 : #include <synthesis/TransformMachines2/CFBuffer.h>
30 : #include <synthesis/TransformMachines2/Utils.h>
31 : #include <synthesis/TransformMachines/SynthesisError.h>
32 : #include <synthesis/TransformMachines2/PolOuterProduct.h>
33 :
34 : using namespace casacore;
35 : namespace casa{
36 : using namespace refim;
37 : //
38 : //---------------------------------------------------------------
39 : //
40 0 : CFStore2 & CFStore2::operator=(const CFStore2& other)
41 : {
42 0 : if (&other != this)
43 : {
44 0 : storage_p.assign(other.storage_p);
45 0 : ant1_p.assign(other.ant1_p);
46 0 : ant2_p.assign(other.ant2_p);
47 0 : pa_p.assign(other.pa_p);
48 0 : lazyFillOn_p=other.lazyFillOn_p;
49 0 : currentSPWID_p = other.currentSPWID_p;
50 0 : cfCacheDir_p = other.cfCacheDir_p;
51 : }
52 0 : return *this;
53 : };
54 : //
55 : //---------------------------------------------------------------
56 : //
57 0 : void CFStore2::show(const char *Mesg, ostream& os, const Bool verbose)
58 : {
59 0 : if (!null())
60 : {
61 0 : if (Mesg != NULL) os << Mesg << endl;
62 0 : os << "Data Shape: " << storage_p.shape() << endl;
63 0 : os << "Ant1: " << ant1_p << endl;
64 0 : os << "Ant2: " << ant2_p << endl;
65 0 : os << "PA = "; for (uInt i=0;i<pa_p.nelements();i++)
66 0 : os << pa_p[i].get("deg") << endl;
67 :
68 0 : if (verbose)
69 0 : for (int i=0; i<storage_p.shape()(0); i++)
70 0 : for(int j=0;j<storage_p.shape()(1);j++)
71 0 : storage_p(i,j)->show(Mesg,os);
72 : }
73 0 : };
74 : //
75 : //---------------------------------------------------------------
76 : //
77 0 : Vector<Int> CFStore2::resize(const Quantity& pa,
78 : const Quantity& paTol,
79 : const Int& ant1, const Int& ant2,
80 : Bool retainValues)
81 : {
82 : Int paNdx, antNdx;
83 : // getIndex(pa,wValue,ant1,ant2,paNdx, antNdx, wNdx);
84 0 : getIndex(pa,paTol,ant1,ant2,paNdx, antNdx);
85 :
86 : // If a index along any axis is negative, resize the correponding
87 : // vector holding the values along that axis.
88 0 : if (paNdx < 0)
89 0 : {paNdx=pa_p.nelements();pa_p.resize(paNdx+1,retainValues);};
90 0 : if (antNdx < 0)
91 0 : {antNdx=ant1_p.nelements();ant1_p.resize(antNdx+1,true);ant2_p.resize(antNdx+1,retainValues);};
92 : // if (wNdx < 0)
93 : // {wNdx=wValue_p.nelements();wValue_p.resize(wNdx+1,retainValues);}
94 : // Resize the storage_p Cube to the current size of required along
95 : // the 3 axis. This is a NoOp if the axis lengths did not change.
96 0 : storage_p.resize(pa_p.nelements(), ant1_p.nelements(), retainValues);
97 :
98 0 : pa_p[paNdx] = pa;
99 0 : ant1_p[antNdx] = ant1;
100 0 : ant2_p[antNdx] = ant2;
101 :
102 0 : Vector<Int> pos(2);pos(0)=paNdx;pos(1)=antNdx;
103 0 : if (storage_p(pos(0),pos(1)).null())
104 : {
105 0 : storage_p(pos(0),pos(1)) = new CFBuffer;
106 0 : storage_p(pos(0),pos(1))->setDir(cfCacheDir_p);
107 : }
108 0 : return pos;
109 0 : };
110 : //
111 : //---------------------------------------------------------------
112 : //
113 0 : void CFStore2::setCFBuffer(CFBuffer* /*dataPtr*/,
114 : Quantity /*pa*/,
115 : const Int& /*ant1*/, const Int& /*ant2*/)
116 : {
117 0 : throw(AipsError("setCFBuffer called!"));
118 : // Vector<Int> pos=resize(pa,ant1,ant2);
119 : // storage_p(pos[0], pos[1]) = dataPtr;
120 : }
121 : //
122 : //---------------------------------------------------------------
123 : //
124 0 : CountedPtr<CFBuffer>& CFStore2::getCFBuffer(const Quantity& pa,
125 : const Quantity& paTol,
126 : const Int& ant1, const Int& ant2)
127 : {
128 : Int paNdx, antNdx;
129 0 : getIndex(pa,paTol,ant1,ant2,paNdx, antNdx);
130 0 : if ((paNdx < 0) || (antNdx < 0))
131 0 : throw(CFNotCached("CFStore2::getIndex: Index not found"));
132 :
133 0 : return getCFBuffer(paNdx, antNdx);
134 : }
135 : //
136 : //---------------------------------------------------------------
137 : //
138 : // Get CFBuffer by direct indexing
139 0 : CountedPtr<CFBuffer>& CFStore2::getCFBuffer(const Int& paNdx, const Int& antNdx)
140 : {
141 0 : return storage_p(paNdx, antNdx);
142 : }
143 : //
144 : //---------------------------------------------------------------
145 : //
146 0 : void CFStore2::getParams(Quantity& pa,
147 : Int& ant1, Int& ant2,
148 : const Int& paNdx, const Int& antNdx)
149 : {
150 0 : pa = pa_p[paNdx];
151 0 : ant1 = ant1_p[antNdx];
152 0 : ant2 = ant2_p[antNdx];
153 0 : }
154 : //
155 : //---------------------------------------------------------------
156 : // This version saves the CFBuffer that corresponds to the
157 : // [PA,(Ant1,Ant2)] pixel of the CFStore storage.
158 0 : void CFStore2::makePersistent(const char *dir,
159 : const char *cfName,
160 : const char *qualifier,
161 : const Quantity &pa, const Quantity& dPA,
162 : const Int& ant1, const Int& ant2)
163 : {
164 0 : LogIO log_l(LogOrigin("CFStore2", "makePersistent(pa)[R&D]"));
165 : (void)cfName;
166 : Int paNdx, antNdx;
167 0 : getIndex(pa,dPA,ant1,ant2,paNdx, antNdx);
168 :
169 0 : log_l << "Saving CFStore of shape " << storage_p(paNdx,antNdx)->shape()
170 : << " for PA = " << pa.getValue("deg")
171 : << " BaselineType(antType1, antType2) = (" << ant1 << "," << ant2 << ")"
172 0 : << LogIO::POST;
173 0 : ostringstream name;
174 0 : name << String(qualifier) << "CFS_" << paNdx << "_" << antNdx;
175 0 : storage_p(paNdx,antNdx)->makePersistent(dir, name.str().c_str());
176 0 : }
177 : //
178 : //---------------------------------------------------------------
179 : //
180 0 : void CFStore2::makePersistent(const char *dir,
181 : const char *cfName,
182 : const char *qualifier)
183 : {
184 : (void)cfName;
185 0 : LogIO log_l(LogOrigin("CFStore2.2", "makePersistent[R&D]"));
186 : //const char *formedName;
187 :
188 0 : for (Int i=0;i<storage_p.shape()(0);i++)
189 0 : for (Int j=0;j<storage_p.shape()(1);j++)
190 : {
191 0 : log_l << "Writing CFStore("<<i<<","<<j<<") of shape " << storage_p(i,j)->shape() << LogIO::POST;
192 0 : ostringstream name;
193 : //name << dir << "/" << qualifier << "CFS_" << i << "_" << j;
194 0 : name << String(qualifier) << "CFS_" << i << "_" << j;
195 : // if (String(cfName) == "") formedName = name.str().c_str();
196 : // else formedName = cfName;
197 0 : storage_p(i,j)->makePersistent(dir,name.str().c_str());
198 0 : }
199 0 : }
200 : //
201 : //---------------------------------------------------------------
202 : //
203 0 : void CFStore2::primeTheCFB()
204 : {
205 0 : IPosition shp=getShape();
206 0 : for (Int i=0; i<shp(0); i++)
207 0 : for (Int j=0; j<shp(1); j++)
208 0 : getCFBuffer(i,j)->primeTheCache();
209 0 : }
210 : //
211 : //---------------------------------------------------------------
212 : //
213 0 : void CFStore2::initMaps(const VisBuffer2& vb, const Matrix<Double>& freqSelection, const Double& imRefFreq)
214 : {
215 0 : for (Int i=0;i<storage_p.shape()(0);i++)
216 0 : for (Int j=0;j<storage_p.shape()(1);j++)
217 0 : storage_p(i,j)->initMaps(vb, freqSelection, imRefFreq);
218 0 : }
219 : //
220 : //---------------------------------------------------------------
221 : //
222 0 : void CFStore2::initPolMaps(PolMapType& polMap, PolMapType& conjPolMap)
223 : {
224 0 : IPosition shp=getShape();
225 0 : for (Int i=0; i<shp(0); i++)
226 0 : for (Int j=0; j<shp(1); j++)
227 0 : getCFBuffer(i,j)->initPolMaps(polMap, conjPolMap);
228 0 : }
229 : //
230 0 : void CFStore2::clear()
231 : {
232 0 : IPosition cfsShape = getStorage().shape();
233 :
234 0 : for (Int ib=0;ib<cfsShape(0); ib++)
235 0 : for(int it=0;it<cfsShape(1); it++)
236 0 : getStorage()(ib,it)->clear();
237 0 : }
238 : //
239 : //---------------------------------------------------------------
240 : //
241 : //---------------------------------------------------------------
242 : //
243 0 : Double CFStore2::memUsage()
244 : {
245 0 : IPosition cfsShape = getStorage().shape();
246 0 : Double memUsed=0;
247 0 : for (Int ib=0;ib<cfsShape(0); ib++)
248 0 : for(int it=0;it<cfsShape(1); it++)
249 : {
250 0 : IPosition cfbShape = getStorage()(ib,it)->getStorage().shape();
251 0 : for(int ip=0;ip<cfbShape(2); ip++)
252 0 : for(Int ich=0;ich<cfbShape(0);ich++)
253 0 : for(Int iw=0;iw<cfbShape(1); iw++)
254 0 : memUsed += getStorage()(ib,it)->getStorage()(ich,iw,ip)->getStorage()->shape()
255 0 : .product()*sizeof(Complex);
256 0 : }
257 0 : return memUsed;
258 0 : }
259 : //
260 : //---------------------------------------------------------------
261 : //
262 0 : Int CFStore2::nearestPA(const Quantity& pa, const Quantity& paTol)
263 : {
264 0 : Int n=pa_p.nelements(), junk=-1;
265 0 : Float dpa=paTol.getValue("rad"),
266 0 : paVal = pa.getValue("rad"), cpa;
267 :
268 0 : for(Int i=0;i<n;i++)
269 : {
270 0 : cpa = pa_p(i).getValue("rad");
271 : // cerr << "##### " << i << " " << cpa*57.2956 << " " << paVal*57.2956 << " " << dpa*57.2956 << " " << (fabs(cpa - paVal))*57.2956 << endl;
272 : // if (fabs(cpa - paVal) > dpa)
273 : // {cout << "%%%%% "; cin >> junk;}
274 0 : if (fabs(cpa - paVal) < dpa) {junk=i;break;}
275 : }
276 0 : return junk;
277 : }
278 : //
279 : //---------------------------------------------------------------
280 : //
281 0 : void CFStore2::setCFCacheDir(const String& dir)
282 : {
283 0 : IPosition cfsShape = getStorage().shape();
284 :
285 0 : for (Int ib=0;ib<cfsShape(0); ib++)
286 0 : for(int it=0;it<cfsShape(1); it++)
287 0 : getStorage()(ib,it)->setDir(dir);
288 :
289 0 : cfCacheDir_p=dir;
290 0 : }
291 : //
292 : //---------------------------------------------------------------
293 : //
294 0 : void CFStore2::invokeGC(const Int& spwID)
295 : {
296 0 : if (isLazyFillOn())
297 : {
298 0 : if (spwID != currentSPWID_p)
299 : {
300 : // LogIO log_l(LogOrigin("CFStore2", "invokeGC"));
301 : // log_l << "Invoking Garbage Collector: ";
302 : // // The reason for invoking GC
303 : // if (currentSPWID_p < 0) log_l << "Initial mopping-up";
304 : // else log_l << "SPW" << currentSPWID_p << "->SPW" << spwID;
305 : // log_l << LogIO::DEBUGGING;
306 :
307 0 : clear(); currentSPWID_p=spwID;
308 : }
309 : }
310 0 : }
311 : }; // end casa namespace
312 :
313 :
314 :
|