casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VisChunkAverager.h
Go to the documentation of this file.
1 //# VisChunkAverager.h: class to time average all columns of a VisBuffer
2 //# Copyright (C) 2010
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 #ifndef MSVIS_VISCHUNKAVERAGER_H
27 #define MSVIS_VISCHUNKAVERAGER_H
28 
29 #include <casa/aips.h>
31 #include <map>
32 #include <vector>
33 
34 namespace casa { //# NAMESPACE CASA - BEGIN
35 
36 class CalVisBuffer;
37 class VisBuffer;
38 
39 // <summary>
40 // A class to time average all columns of a VisBuffer.
41 // </summary>
42 //
43 // <use visibility=export>
44 //
45 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
46 // </reviewed>
47 
48 // <prerequisite>
49 // <li> VisBuffer
50 // </prerequisite>
51 //
52 // <etymology>
53 // From "VisBuffer", "Chunk", and "averaging". "Chunk" comes from
54 // VisibilityIterator.
55 // </etymology>
56 //
57 // <synopsis>
58 // This class time averages complete rows of a VisBuffer.
59 // </synopsis>
60 //
61 // <example>
62 // See SubMS::doTimeAver().
63 // </example>
64 //
65 // <motivation>
66 // VisBuffAccumulator also time averages VisBuffers, but only for a few
67 // columns, as needed by calibration and plotms. casacore::Time averaging in split
68 // requires (in principle) that all of the columns in the input casacore::MS be written
69 // to the output MS. This is more work than required by calibration and
70 // plotms, and split also has some differences in the details of the averaging.
71 // </motivation>
72 //
73 // <note>
74 // For many of the columns averaging is trivial, i.e. the VisBuffer should only
75 // contain one ARRAY_ID, FIELD_ID, and DATA_DESC_ID, so they will all only have
76 // one value each.
77 //
78 // TIME and INTERVAL will also be univalued in the output, for a different
79 // reason. For most (all?) uses this is a feature. (See CAS-2422 + 2439 for
80 // why.)
81 // </note>
82 //
83 // <todo asof="2010/11/12">
84 // <li> averaging over other indices.
85 // </todo>
86 
87 typedef std::map<casacore::uInt, std::vector<casacore::Int> > mapuIvIType;
88 
89 class VisChunkAverager //: public VisBuffAccumulator
90 {
91 public:
92  // Construct from which *DATA column(s) to read and whether or not to use
93  // WEIGHT_SPECTRUM.
95  const casacore::Bool doSpWeight,
97 
98  // Null destructor
100 
101  // Reset the averager
102  void reset();
103 
104  // casacore::Time average vi's current chunk, AND advance vi to the end of that chunk.
105  // casacore::Input:
106  // vi ROVisibilityIterator vi.setRowBlocking(0) will be
107  // called to ensure that ++vi
108  // advances by 1 integration at a
109  // time.
110  // Output from private data:
111  // avBuf_p CalVisBuffer Output buffer for the averaged
112  // "integration".
114 
115  // Checks whether the interval of vi needs to be truncated in order to
116  // prevent collisions where two rows have the same casacore::MS key (ignoring TIME) but
117  // different SCAN_NUMBER, STATE_ID, and/or OBSERVATION_ID. ARRAY_ID is
118  // already separated by the chunking.
119  //
120  // time_to_break is set to the TIME of the earliest collision, or the end of
121  // the buffer if none are found.
122  //
124  const casacore::Bool watch_obs, const casacore::Bool watch_scan,
125  const casacore::Bool watch_state);
126 
127 
128  // max(a, b) in Math.h is so overloaded, and (u)casacore::Int is so promotable, that
129  // they're unusable together.
130  casacore::uInt uIntMax(const casacore::uInt a, const casacore::uInt b) const { return a > b ? a : b; }
131 
132 private:
133  // Prohibit null constructor, copy constructor and assignment for now
137 
138  // Initialize the next accumulation interval
139  void initialize(VisBuffer& vb);
140 
141  // Normalize the accumulation (finish the average).
142  void normalize(const casacore::Double minTime, const casacore::Double maxTime,
143  const casacore::Double firstinterval, const casacore::Double lastinterval);
144 
145  // Force vb to read all the columns (modified by colEnums_p and
146  // doSpWeight_p).
147  //
148  // Sets readyToHash_p to false.
149  //
150  void fill_vb(VisBuffer& vb);
151 
152  // Hash function to return a unique (within the VisBuffer) key (as defined by
153  // the casacore::MS def'n) for an interferometer (ant1, ant2, feed1, feed2,
154  // processor_id). Note that a VisBuffer only contains one ddid and fieldid,
155  // and TIME is deliberately excluded this that is what will be averaged over.
156  //
157  // Sorting a set of the returned keys is equivalent to sorting by
158  // (procid, ant1, ant2, feed1, feed2).
159  //
161  const casacore::Int feed1, const casacore::Int feed2,
162  const casacore::Int procid) const;
163 
164  // These return their success values. (They could fail if any of ant1, ant2,
165  // feed1, feed2, or procid are < 0, but that shouldn't happen and isn't
166  // checked for.)
169 
170  // Check whether any of the unflagged rows in vi's current chunk have the
171  // same casacore::MS key (not counting TIME) but different values for the columns in
172  // colsToWatch.
173  //
174  // time_to_break will be set to the time of the earliest collision if any are
175  // found, or the last TIME in vi's current chunk otherwise (assumes vi's
176  // current chunk is ascendingly sorted in TIME).
177  //
178  // colsToWatch should contain casacore::MS::SCAN_NUMBER, casacore::MS::STATE_ID,
179  // casacore::MS::OBSERVATION_ID, and/or nothing. Otherwise an casacore::AipsError will be
180  // thrown. casacore::MS::ARRAY_ID is already separated by the chunking.
181  //
183  const casacore::Bool watchObs, const casacore::Bool watchScan,
184  const casacore::Bool watchState);
185 
186  // Helper function for findCollision().
188  const casacore::uInt chunkletNum,
189  const std::vector<casacore::Int>& inrows_for_slot) const;
190 
191  // Start of initialization list.
192  // Which of DATA, MODEL_DATA, and/or CORRECTED_DATA to use.
194 
195  // Use WEIGHT_SPECTRUM?
197 
198  // Used for both selecting and averaging channels.
200  // End of initialization list.
201 
202  // Is everything setup for hashFunction()?
204 
205  // Is sphash_to_inprows_p OK?
207 
208  // Maxima for hashFunction().
213  // casacore::uInt maxprocp1_p; Not needed
214 
215  // A map from a sparse hash of "baseline" to a vector of input row numbers
216  // matching that hash.
217  //
218  // The hash is calculated by hashFunction().
219  //
220  // The vector has an entry, in order, for each chunklet (vb) in vi's current
221  // chunk which is either -1 (the chunklet has no row matching the hash) or
222  // the row number _relative_ to the starting row in that chunklet's vb.
223  //
225 
226  // Number of correlations and channels
228 
229  // The number of flag categories. 0 if flagCategory() is invalid.
231 
232  // Averaging buffer
234 };
235 
236 
237 } //# NAMESPACE CASA - END
238 
239 #endif
240 
241 
~VisChunkAverager()
Null destructor.
A 1-D Specialization of the Array class.
VisChunkAverager & operator=(const VisChunkAverager &)
int Int
Definition: aipstype.h:50
casacore::Bool findCollision(ROVisibilityIterator &vi, casacore::Double &time_to_break, const casacore::Bool watchObs, const casacore::Bool watchScan, const casacore::Bool watchState)
Check whether any of the unflagged rows in vi&#39;s current chunk have the same casacore::MS key (not cou...
casacore::Bool makeHashMap(ROVisibilityIterator &vi)
std::map< casacore::uInt, std::vector< casacore::Int > > mapuIvIType
A class to time average all columns of a VisBuffer.
casacore::uInt maxfeed2p1_p
void initialize(VisBuffer &vb)
Initialize the next accumulation interval.
casacore::uInt maxant2p1_p
casacore::Int nCat_p
The number of flag categories.
CalVisBuffer extends VisBuffer to support storage and recall of associated residual and differentiate...
Definition: CalVisBuffer.h:65
casacore::Bool doSpWeight_p
Use WEIGHT_SPECTRUM?
casacore::Bool checkForBreak(casacore::Vector< casacore::Int > &firstVals, const casacore::Int i, const casacore::uInt slotnum, const casacore::uInt chunkletNum, const std::vector< casacore::Int > &inrows_for_slot) const
Helper function for findCollision().
void fill_vb(VisBuffer &vb)
Force vb to read all the columns (modified by colEnums_p and doSpWeight_p).
VisBuffer & average(ROVisibilityIterator &vi)
casacore::Time average vi&#39;s current chunk, AND advance vi to the end of that chunk.
VisChunkAverager()
Prohibit null constructor, copy constructor and assignment for now.
casacore::Int nCorr_p
Number of correlations and channels.
casacore::Vector< casacore::Matrix< casacore::Int > > chanAveBounds_p
Used for both selecting and averaging channels.
double Double
Definition: aipstype.h:55
casacore::uInt uIntMax(const casacore::uInt a, const casacore::uInt b) const
max(a, b) in Math.h is so overloaded, and (u)casacore::Int is so promotable, that they&#39;re unusable to...
mapuIvIType sphash_to_inprows_p
casacore::uInt maxprocp1_p; Not needed
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void normalize(const casacore::Double minTime, const casacore::Double maxTime, const casacore::Double firstinterval, const casacore::Double lastinterval)
Normalize the accumulation (finish the average).
casacore::Bool setupHashFunction(ROVisibilityIterator &vi)
These return their success values.
void reset()
Reset the averager.
casacore::uInt hashFunction(const casacore::Int ant1, const casacore::Int ant2, const casacore::Int feed1, const casacore::Int feed2, const casacore::Int procid) const
Hash function to return a unique (within the VisBuffer) key (as defined by the casacore::MS def&#39;n) fo...
static casacore::Bool check_chunk(ROVisibilityIterator &vi, casacore::Double &time_to_break, const casacore::Bool watch_obs, const casacore::Bool watch_scan, const casacore::Bool watch_state)
Checks whether the interval of vi needs to be truncated in order to prevent collisions where two rows...
casacore::uInt maxfeed1p1_p
VisBuffers encapsulate one chunk of visibility data for processing.
Definition: VisBuffer.h:153
casacore::uInt maxant1p1_p
Maxima for hashFunction().
casacore::Bool readyToHash_p
End of initialization list.
ROVisibilityIterator iterates through one or more readonly MeasurementSets.
casacore::Bool haveHashMap_p
Is sphash_to_inprows_p OK?
CalVisBuffer avBuf_p
Averaging buffer.
casacore::Vector< casacore::MS::PredefinedColumns > colEnums_p
Start of initialization list.
unsigned int uInt
Definition: aipstype.h:51