casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataLoadingBuf.h
Go to the documentation of this file.
1 //# DataLoadingBuf.h: this defines a container for filler data buffers
2 //# Copyright (C) 2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id: DataLoadingBuf.h,v 1.1 2009/09/03 18:54:47 pteuben Exp $
28 
29 #ifndef BIMA_DATALOADINGBUF_H
30 #define BIMA_DATALOADINGBUF_H
31 
32 #include <casa/Containers/Block.h>
33 #include <casa/Arrays/Matrix.h>
34 #include <casa/Arrays/Cube.h>
35 #include <casa/Arrays/Vector.h>
36 
37 #include <casa/namespace.h>
38 //# Forward Declarations
39 
40 // <summary>
41 // a container for data buffers used to fill a measurement set
42 // </summary>
43 //
44 // <use visibility=export>
45 //
46 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
47 // </reviewed>
48 //
49 // <etymology>
50 // class holds buffers used to load data into a Measurment Set
51 // </etymology>
52 //
53 // <motivation>
54 // Miriad data support multiple spectral windows for a given correllator
55 // setup. Furthermore, a dataset can contain multiple setups. This class
56 // attempts to avoid having to repeatedly create a buffer inside a loading
57 // loop.
58 // </motivation>
59 //
60 // <synopsis>
61 // This class allows one to create reusable buffers for each of the spectral
62 // windows that can be passed to an
63 // <linkto class="casacore::ArrayColumn">casacore::ArrayColumn's</linkto>
64 // <src>put()</src> function. This avoids the cost of recreating the buffers
65 // inside a loading loop that cycles through the input Miriad windows. The
66 // buffers can be resized if necessary if the Miriad correllator setup
67 // changes. <p>
68 //
69 // This class stores for each window a casacore::Matrix<casacore::Complex> to store the visibility data
70 // and a casacore::Cube<casacore::Bool> to hold the flags. Normally, you can have all wide-band windows
71 // share a single buffer
72 // (since they are all the same size, namely having 1 channel). The buffers are
73 // access via their (zero-base) window index, starting with the narrow band windows.
74 // A window index greater than or equal to the number of narrow band windows (set
75 // via <src>resizeForNspec()</src>) is assumed to refer a wide-band window and the
76 // last buffer is returned.
77 //
78 // If the size of a buffer needs to be changed (e.g. because the correllator setup
79 // changed such that the number of channels in a window subsequently changed), it
80 // is most convenient to do the resizing via <src>resizeForSpWin()</src>.
81 // </synopsis>
82 //
83 // <example>
84 // To set up the buffers, you need to know how many windows you have, and the
85 // number of channels in each window.
86 // <srcblock>
87 // casacore::Int nspec = 6
88 // casacore::Int *nchan = { 512, 256, 256, 512, 256, 256 };
89 // DataLoadingBuf buf();
90 // buf.resizeForNspect(nspec+1) // to hold both narrow and wide band data
91 // for(casacore::Int i=0; i < nspec; i++)
92 // buf.resizeForSpWin(i, nchan[i]);
93 // buf.resizeForSpWin(nspec, 1);
94 // </srcblock>
95 //
96 // Now to use the buffers...
97 // <srcblock>
98 // for(casacore::Int i=0; i < 2*nspec; i++) {
99 //
100 // // get data-loading buffers
101 // casacore::Matrix<casacore::Complex> &vis = buf.visForSpWin(i);
102 // casacore::Cube<casacore::Bool> &flgs = buf.flagsForSpWin(i);
103 //
104 // // load in the data
105 // casacore::Int n = (i < nspec) ? nchan[i] : 1;
106 // for(casacore::Int j=0; j < n; j++) {
107 // vis(0,j) = casacore::Complex( corr[2*(j+offset)],
108 // -corr[2*(j+offset)+1] );
109 // flgs(0,j,1) = (flags[j+offset] == 0);
110 // }
111 //
112 // // load it into casacore::MS column
113 // msc->data().put(row, vis);
114 // msc->flagCategory().put(row, flgs);
115 // }
116 // </srcblock>
117 // </example>
118 //
119 // <todo asof="2001/02/22">
120 // <li> the most important functions in this class are inlined even though
121 // they are a tad long (4-6 lines). This is because it is expected
122 // that they are called once within a loop. Under this assumption,
123 // the benefit probably out-weighs the cost. If this assumption
124 // changes, this code should probably be moved out of line.
125 // </todo>
126 //
128 private:
133 
135 public:
136 
137  // create the container
138  DataLoadingBuf();
139 
140  // delete the container
141  ~DataLoadingBuf();
142 
143  // resize our arrays of containers to hold data for wide band data
144  // and a given number of narrow band spectral windows. <src>i</src>
145  // is the number of narrow band spectral windows.
147 
148  // return the number of channels that can be stored in a given window.
149  // A value for <src>i</src> greater than or equal to the number of
150  // narrow band windows is assumed to refer to a wideband window; thus,
151  // 1 will be returned.
153 
154  // return a reference to the flags casacore::Cube for a given window.
155  // A value for <src>i</src> greater than or equal to the number of
156  // narrow band windows is assumed to refer to a wideband window.
158  if ((casacore::uInt)winid >= flgslist.nelements())
159  winid = flgslist.nelements()-1;
160  if (flgslist[winid] == NULL) flgslist[winid] = new casacore::Cube<casacore::Bool>();
161  return *(flgslist[winid]);
162  }
163 
164  // return a reference to the vis casacore::Matrix for a given window
166  if ((casacore::uInt)winid >= vislist.nelements()) winid = vislist.nelements()-1;
167  if (vislist[winid] == NULL) vislist[winid] = new casacore::Matrix<casacore::Complex>();
168  return *(vislist[winid]);
169  }
170 
171  // return a reference to the weight vector
173 
174  // return a reference to the sigma vector
176 
177  // resize the containers for a given window to the given number of channels
179  casacore::Int npol;
180 
181  if (winid > casacore::Int(vislist.nelements())) winid = vislist.nelements();
182  if (vislist[winid] == NULL ||
183  visForSpWin(winid).ncolumn() != (casacore::uInt)nchan)
184  {
185  npol = (vislist[winid] == NULL) ? 1 : vislist[winid]->nrow();
186  if (vislist[winid] != NULL) delete vislist[winid];
187  vislist[winid] = new casacore::Matrix<casacore::Complex>(npol, nchan);
188  if (flgslist[winid] != NULL) delete flgslist[winid];
189  flgslist[winid] = new casacore::Cube<casacore::Bool>(npol, nchan, 2, false);
190  }
191  }
192 
193  // resize the containers for a given number of polarization correlations
195  for(casacore::Int i=0; i < casacore::Int(vislist.nelements()); i++) {
196  if (vislist[i] != NULL) {
197  casacore::Int nchan = vislist[i]->ncolumn();
198  vislist[i]->resize(npol, nchan);
199  flgslist[i]->resize(npol, nchan, 2);
200  *(flgslist[i]) = false;
201  }
202  }
203  wt.resize(npol);
204  rms.resize(npol);
205  }
206 
207 
208 };
209 
210 #endif
211 
212 
int Int
Definition: aipstype.h:50
void resizeForNspect(casacore::Int i)
resize our arrays of containers to hold data for wide band data and a given number of narrow band spe...
void resize(size_t n, Bool forceSmaller=False, Bool copyElements=True)
Resizes the Block.
Definition: Block.h:377
size_t nelements() const
The number of elements contained in this Block&lt;T&gt;.
Definition: Block.h:611
DataLoadingBuf()
create the container
casacore::Vector< casacore::Float > wt
casacore::Vector< casacore::Float > & weight()
return a reference to the weight vector
casacore::Int nchanForSpWin(casacore::Int i)
return the number of channels that can be stored in a given window.
casacore::Vector< casacore::Float > & sigma()
return a reference to the sigma vector
casacore::Vector< casacore::Float > rms
casacore::Cube< casacore::Bool > & flagsForSpWin(casacore::Int winid)
return a reference to the flags casacore::Cube for a given window.
void resizeForNpol(casacore::Int npol)
resize the containers for a given number of polarization correlations
void resizeForSpWin(casacore::Int winid, casacore::Int nchan)
resize the containers for a given window to the given number of channels
a container for data buffers used to fill a measurement set
casacore::Block< casacore::Cube< casacore::Bool > * > flgslist
size_t ncolumn() const
The number of columns in the Matrix, i.e.
Definition: Matrix.h:305
simple 1-D array
~DataLoadingBuf()
delete the container
casacore::Block< casacore::Matrix< casacore::Complex > * > vislist
casacore::Matrix< casacore::Complex > & visForSpWin(casacore::Int winid)
return a reference to the vis casacore::Matrix for a given window
void resize(size_t len, Bool copyValues=False)
Definition: Vector.h:167
unsigned int uInt
Definition: aipstype.h:51