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 214 : 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 214 : 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 214 : if (paNdx < 0)
89 200 : {paNdx=pa_p.nelements();pa_p.resize(paNdx+1,retainValues);};
90 214 : if (antNdx < 0)
91 200 : {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 214 : storage_p.resize(pa_p.nelements(), ant1_p.nelements(), retainValues);
97 :
98 214 : pa_p[paNdx] = pa;
99 214 : ant1_p[antNdx] = ant1;
100 214 : ant2_p[antNdx] = ant2;
101 :
102 214 : Vector<Int> pos(2);pos(0)=paNdx;pos(1)=antNdx;
103 214 : if (storage_p(pos(0),pos(1)).null())
104 : {
105 200 : storage_p(pos(0),pos(1)) = new CFBuffer;
106 200 : storage_p(pos(0),pos(1))->setDir(cfCacheDir_p);
107 : }
108 428 : 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 3826851 : CountedPtr<CFBuffer>& CFStore2::getCFBuffer(const Quantity& pa,
125 : const Quantity& paTol,
126 : const Int& ant1, const Int& ant2)
127 : {
128 : Int paNdx, antNdx;
129 3826851 : getIndex(pa,paTol,ant1,ant2,paNdx, antNdx);
130 3826851 : if ((paNdx < 0) || (antNdx < 0))
131 14 : throw(CFNotCached("CFStore2::getIndex: Index not found"));
132 :
133 7653674 : return getCFBuffer(paNdx, antNdx);
134 : }
135 : //
136 : //---------------------------------------------------------------
137 : //
138 : // Get CFBuffer by direct indexing
139 3827195 : CountedPtr<CFBuffer>& CFStore2::getCFBuffer(const Int& paNdx, const Int& antNdx)
140 : {
141 3827195 : 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 28 : 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 56 : LogIO log_l(LogOrigin("CFStore2", "makePersistent(pa)[R&D]"));
165 : (void)cfName;
166 : Int paNdx, antNdx;
167 28 : getIndex(pa,dPA,ant1,ant2,paNdx, antNdx);
168 :
169 28 : log_l << "Saving CFStore of shape " << storage_p(paNdx,antNdx)->shape()
170 : << " for PA = " << pa.getValue("deg")
171 : << " BaselineType(antType1, antType2) = (" << ant1 << "," << ant2 << ")"
172 56 : << LogIO::POST;
173 28 : ostringstream name;
174 28 : name << String(qualifier) << "CFS_" << paNdx << "_" << antNdx;
175 28 : storage_p(paNdx,antNdx)->makePersistent(dir, name.str().c_str());
176 28 : }
177 : //
178 : //---------------------------------------------------------------
179 : //
180 14 : void CFStore2::makePersistent(const char *dir,
181 : const char *cfName,
182 : const char *qualifier)
183 : {
184 : (void)cfName;
185 28 : LogIO log_l(LogOrigin("CFStore2.2", "makePersistent[R&D]"));
186 : //const char *formedName;
187 :
188 28 : for (Int i=0;i<storage_p.shape()(0);i++)
189 28 : for (Int j=0;j<storage_p.shape()(1);j++)
190 : {
191 14 : log_l << "Writing CFStore("<<i<<","<<j<<") of shape " << storage_p(i,j)->shape() << LogIO::POST;
192 14 : ostringstream name;
193 : //name << dir << "/" << qualifier << "CFS_" << i << "_" << j;
194 14 : name << String(qualifier) << "CFS_" << i << "_" << j;
195 : // if (String(cfName) == "") formedName = name.str().c_str();
196 : // else formedName = cfName;
197 14 : storage_p(i,j)->makePersistent(dir,name.str().c_str());
198 14 : }
199 14 : }
200 : //
201 : //---------------------------------------------------------------
202 : //
203 214 : void CFStore2::primeTheCFB()
204 : {
205 214 : IPosition shp=getShape();
206 400 : for (Int i=0; i<shp(0); i++)
207 372 : for (Int j=0; j<shp(1); j++)
208 186 : getCFBuffer(i,j)->primeTheCache();
209 214 : }
210 : //
211 : //---------------------------------------------------------------
212 : //
213 186 : void CFStore2::initMaps(const VisBuffer2& vb, const Matrix<Double>& freqSelection, const Double& imRefFreq)
214 : {
215 372 : for (Int i=0;i<storage_p.shape()(0);i++)
216 372 : for (Int j=0;j<storage_p.shape()(1);j++)
217 186 : storage_p(i,j)->initMaps(vb, freqSelection, imRefFreq);
218 186 : }
219 : //
220 : //---------------------------------------------------------------
221 : //
222 158 : void CFStore2::initPolMaps(PolMapType& polMap, PolMapType& conjPolMap)
223 : {
224 158 : IPosition shp=getShape();
225 316 : for (Int i=0; i<shp(0); i++)
226 316 : for (Int j=0; j<shp(1); j++)
227 158 : getCFBuffer(i,j)->initPolMaps(polMap, conjPolMap);
228 158 : }
229 : //
230 457 : void CFStore2::clear()
231 : {
232 457 : IPosition cfsShape = getStorage().shape();
233 :
234 914 : for (Int ib=0;ib<cfsShape(0); ib++)
235 914 : for(int it=0;it<cfsShape(1); it++)
236 457 : getStorage()(ib,it)->clear();
237 457 : }
238 : //
239 : //---------------------------------------------------------------
240 : //
241 : //---------------------------------------------------------------
242 : //
243 18603 : Double CFStore2::memUsage()
244 : {
245 18603 : IPosition cfsShape = getStorage().shape();
246 18603 : Double memUsed=0;
247 37206 : for (Int ib=0;ib<cfsShape(0); ib++)
248 37206 : for(int it=0;it<cfsShape(1); it++)
249 : {
250 18603 : IPosition cfbShape = getStorage()(ib,it)->getStorage().shape();
251 55809 : for(int ip=0;ip<cfbShape(2); ip++)
252 144324 : for(Int ich=0;ich<cfbShape(0);ich++)
253 215556 : for(Int iw=0;iw<cfbShape(1); iw++)
254 108438 : memUsed += getStorage()(ib,it)->getStorage()(ich,iw,ip)->getStorage()->shape()
255 108438 : .product()*sizeof(Complex);
256 18603 : }
257 18603 : return memUsed;
258 18603 : }
259 : //
260 : //---------------------------------------------------------------
261 : //
262 3827093 : Int CFStore2::nearestPA(const Quantity& pa, const Quantity& paTol)
263 : {
264 3827093 : Int n=pa_p.nelements(), junk=-1;
265 3827093 : Float dpa=paTol.getValue("rad"),
266 3827093 : paVal = pa.getValue("rad"), cpa;
267 :
268 3827093 : for(Int i=0;i<n;i++)
269 : {
270 3826879 : 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 3826879 : if (fabs(cpa - paVal) < dpa) {junk=i;break;}
275 : }
276 3827093 : return junk;
277 : }
278 : //
279 : //---------------------------------------------------------------
280 : //
281 214 : void CFStore2::setCFCacheDir(const String& dir)
282 : {
283 214 : IPosition cfsShape = getStorage().shape();
284 :
285 228 : for (Int ib=0;ib<cfsShape(0); ib++)
286 28 : for(int it=0;it<cfsShape(1); it++)
287 14 : getStorage()(ib,it)->setDir(dir);
288 :
289 214 : cfCacheDir_p=dir;
290 214 : }
291 : //
292 : //---------------------------------------------------------------
293 : //
294 27035 : void CFStore2::invokeGC(const Int& spwID)
295 : {
296 27035 : if (isLazyFillOn())
297 : {
298 27035 : 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 436 : clear(); currentSPWID_p=spwID;
308 : }
309 : }
310 27035 : }
311 : }; // end casa namespace
312 :
313 :
314 :
|