casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFFlagCube.h
Go to the documentation of this file.
1 
2 //# RFFlagCube.h: this defines RFFlagCube
3 //# Copyright (C) 2000,2001,2002
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 #ifndef FLAGGING_RFFLAGCUBE_H
29 #define FLAGGING_RFFLAGCUBE_H
30 
31 //#include <flagging/Flagging/RedFlagger.h>
35 #include <casa/Arrays/LogiMatrix.h>
36 #include <casa/Arrays/LogiVector.h>
37 #include <casa/Logging/LogIO.h>
38 #include <stdexcept>
39 
40 namespace casa { //# NAMESPACE CASA - BEGIN
41 
43 
44 // special row flag masks. RowFlagged for flagged rows,
45 // RowAbsent for absent rows
47 
48 // casacore::Function for working with bitmasks. Does a bitwise-AND
49 // on every element, returns true if !=0 or false if ==0
50 template<class T> casacore::Array<T> operator & ( const casacore::Array<T> &,const T &);
51 // returns a casacore::LogicalArray corresponding to (ARR&MASK)!=0
52 template<class T> casacore::LogicalArray maskBits ( const casacore::Array<T> &,const T &);
53 
54 // <summary>
55 // RFFlagCube: a cube of flags
56 // </summary>
57 
58 // <use visibility=local>
59 
60 // <reviewed reviewer="" date="" tests="" demos="">
61 // </reviewed>
62 
63 // <prerequisite>
64 // <li> RFCubeLattice
65 // </prerequisite>
66 //
67 // <synopsis>
68 // RFFlagCube implements an [NCHAN,NIFR,NTIME] cube of flags, stored in
69 // a casacore::TempLattice that is iterated alog the TIME axis. One static
70 // (i.e. global) cube is used to hold the actual flags. Individual
71 // instances (instantiated by flagging agents) have individual unique
72 // bitmasks and, possibly, individual iterators.
73 //
74 // It was/is a design mistake to use a global/static buffer to hold the
75 // shared flags. Instead, every agent should point to the unique dynamically
76 // allocated buffer.
77 // </synopsis>
78 //
79 // <example>
80 // </example>
81 //
82 // <motivation>
83 // </motivation>
84 //
85 // <todo asof="2001/04/16">
86 // <li> add this feature
87 // <li> fix this bug
88 // <li> start discussion of this possible extension
89 // </todo>
90 
91 class RFFlagCube : public FlaggerEnums
92 {
93 public:
94  // default log sink
96 
97  // constructor
99  ~RFFlagCube ();
100 
101  // returns reference to logsink
103 
104  // returns estimated size of flag cube for a given chunk.
105  static casacore::uInt estimateMemoryUse ( const RFChunkStats &ch );
106 
107  // creates flag cube for current chunk. name is name of agent.
108  // nAgent is total number of agents
109  void init ( RFlagWord polmsk, casacore::uInt nAgent, bool is_selector, const casacore::String &name = "" );
110 
111  // cleans up at end of chunk
112  void cleanup ();
113 
114  // returns summary of stats in text form
116 
117  // prints flagging stats to stderr
118  void printStats ();
119 
120  // resets at start of pass
121  void reset ();
122 
123  // advances global flag iterator to time slot it (if required), sets
124  // the flag cursor from the iterator (see below). If getflags is true,
125  // also calls getDataFlags().
126  void advance ( casacore::uInt it,casacore::Bool getFlags=false );
127 
128  // fills global flag lattice with apriori flags from a VisBuffer (if required)
129  void getMSFlags (casacore::uInt it);
130 
131  // transfers all flags from lattice into VisBuffer
132  void setMSFlags (casacore::uInt itime);
133 
134  // creates a custom iterator
136 
137  // Returns full flag matrix (i.e. cursor of global iterator)
138  const FlagMatrix & flagMatrix ();
139 
140  // sets or clears a flag at the given flag cursor
143 
144  // Gets full flag word at the given flag cursor.
146 
147  // Versions of above that use global flag cursor
151 
152  // the preFlagged() function uses the corr-mask to tell if any of this
153  // agent's correlations are pre-flagged. Uses internal cursor.
155 
156  // The anyFlagged() uses the corr-flagmask to tell if any of my
157  // correlations are flagged either by any agent or pre-flagged
158  // Uses internal cursor.
160 
161  // Sets or clears a row flag
164 
165  // Gets full row flag word
167 
168  // tells if a row is pre-flagged in the casacore::MS (or does not exist)
170 
171  // tells if a row is flagged by any agent
173 
174  // preFlagged OR agentFlagged
176 
177  // returns reference to internal iterator
179 
180  // returns flag mask for this agent
181  RFlagWord flagMask ();
182 
183  // returns correlations mask for this agent
184  RFlagWord corrMask ();
185 
186  // returns the checked-correlations mask for this agent
187  // (=0 for RESET/IGNORE policies, or =corrMask() for HONOR policy).
189 
190  // returns mask of all correlations
191  static RFlagWord fullCorrMask ();
192 
193  // returns the number of instances of the flag cube
194  static casacore::Int numInstances ();
195 
196  // sets the maximum memory usage for the flag cube
197  static void setMaxMem ( casacore::Int maxmem );
198  // returns the current maximum memory usage
199  static int getMaxMem ();
200 
201  private:
202  RFChunkStats &chunk; // chunk
203 
204  bool kiss; // do things simpler (faster) if there is nothing but RFAselector agents
206 
208  static int in_flags_time; //time stamp that in_flags has reached
209  static bool in_flags_flushed; // do we need to write the flags back for this time stamp?
210 
211  // shortcut to RFChunkStats::num
212  casacore::uInt num ( StatEnums which ) { return chunk.num(which); }
213 
214  static RFCubeLattice<RFlagWord> flag; // global flag lattice
215  static FlagMatrix flagrow; // (nIfr,nTime) matrix of row flags
218 
219  static casacore::Bool reset_preflags; // flag: RESET policy specified for at least one instance
220 
222 
223  // Flag mask used by this instance. Each instance has a unique 1-bit mask.
224  // This is assigned automatically in the constructor, by updating the
225  // instance count and the nextmask member.
226  // Note that the low N bits of a mask are assigned to pre-flags (one per
227  // each correlation in the casacore::MS); so the agents start at bit N+1.
228  RFlagWord flagmask, // flagmask of this instance
229  corrmask, // corrmask of this instance (corrs used/flagged by it)
230  check_corrmask, // mask checked by preFlagged() & co. Set to 0 for
231  // RESET or IGNORE policy, or to corrmask for HONOR
232  check_rowmask, // same for row flags: 0 or RowFlagged
233  my_corrflagmask; // see above
234  unsigned long flagmask_kiss; // represents a bitmask with only bit number <n> set where
235  // <n> is the value of this variable
236  static casacore::Int agent_count; // # of agents instantiated
237  static RFlagWord base_flagmask, // flagmask of first agent instance
238  full_corrmask; // bitmask for all correlations in casacore::MS (low N bits)
239 
240  // corr_flagmask is a mapping from corrmasks into masks of agents that flag the
241  // given corrmask
243 
244  // log sink
246 
247  // pre-flag policy (can be set on a per-instance basis)
249 
250  // flagging stats for this instance
253 
254  // local flag cursor used by this instance (setFlag and clearFlag).
255  // Normally, set to flag.cursor() in advance(), but can be overridden
256  // by setFlagCursor();
259 
260  // number of instances in use
262 };
263 
265  {
266  if (kiss) {
267  throw std::logic_error("Cannot do this in kiss mode (program bug, please report)");
268  }
269  return flagmask;
270  }
271 
273  {
274  return corrmask;
275  }
276 
278  { return check_corrmask; }
279 
281  { return full_corrmask; }
282 
284  {
285  if (kiss) {
286  /* Create the bitmap (integer) from the correlation flags
287  relevant for this agent */
288  RFlagWord f = 0;
289  casacore::uInt c = 1;
290 
291  for (casacore::uInt icorr = 0; icorr < num(CORR); icorr++, c<<=1) {
292  if ((c & corrmask) &&
293  in_flags(icorr, ich, ifr)) {
294  f |= c;
295  }
296  }
297  return f;
298  }
299  else {
300  return (iter)(ich,ifr);
301  }
302  }
303 
305  { return setFlag(ich,ifr,flag.iterator()); }
306 
308  { return clearFlag(ich,ifr,flag.iterator()); }
309 
311  { return getFlag(ich,ifr,flag.iterator()); }
312 
314  { return flag.newIter(); }
315 
317  { return *flag_curs; }
318 
320  { return (getFlag(ich,ifr)&check_corrmask) != 0; }
321 
323  {
324  if (kiss) {
325  throw std::logic_error("Cannot do this in kiss mode (program bug, please report)");
326  }
327  return (getFlag(ich,ifr)&(check_corrmask|my_corrflagmask)) != 0;
328  }
329 
330 // Gets full row flag word
332  {
333  if (kiss) {
334  throw std::logic_error("Cannot do this in kiss mode (program bug, please report)");
335  }
336  return flagrow(ifr,itime);
337  }
338 
339 // tells if a row is pre-flagged in the casacore::MS (or does not exist)
341  { return getRowFlag(ifr,itime)&check_rowmask; }
342 
343 // tells if a row is flagged by any agent
345  { return getRowFlag(ifr,itime)&~(RowFlagged|RowAbsent); }
346 
347 // preFlagged OR agentFlagged
349  { return getRowFlag(ifr,itime)&(check_rowmask?~0:~RowFlagged); }
350 
352  { return flag.iterator(); }
353 
355  { return num_inst; }
356 
358  { return os; }
359 
360 
361 } //# NAMESPACE CASA - END
362 
363 #ifndef AIPS_NO_TEMPLATE_SRC
364 #include <flagging/Flagging/RFFlagCube.tcc>
365 #endif //# AIPS_NO_TEMPLATE_SRC
366 #endif
casacore::uInt flag_itime
Definition: RFFlagCube.h:258
int Int
Definition: aipstype.h:50
casacore::Bool preFlagged(casacore::uInt ich, casacore::uInt ifr)
the preFlagged() function uses the corr-mask to tell if any of this agent&#39;s correlations are pre-flag...
Definition: RFFlagCube.h:319
void printStats()
prints flagging stats to stderr
RFCubeLatticeIterator< T > newIter()
creates a new iterator for this lattice
static RFlagWord base_flagmask
Definition: RFFlagCube.h:237
static casacore::Vector< RFlagWord > corr_flagmask
corr_flagmask is a mapping from corrmasks into masks of agents that flag the given corrmask ...
Definition: RFFlagCube.h:242
casacore::uInt tot_fl_raised
flagging stats for this instance
Definition: RFFlagCube.h:251
casacore::uInt tot_row_fl_raised
Definition: RFFlagCube.h:251
casacore::uInt row_fl_cleared
Definition: RFFlagCube.h:251
const RFlagWord RowFlagged
special row flag masks.
Definition: RFFlagCube.h:46
casacore::uInt RFlagWord
RFAs use bitwise flags.
Definition: RFCommon.h:41
static casacore::Int pos_get_flag
Definition: RFFlagCube.h:217
const FlagMatrix & flagMatrix()
Returns full flag matrix (i.e.
Definition: RFFlagCube.h:316
static casacore::uInt npol
Definition: RFFlagCube.h:221
RFlagWord checkCorrMask()
returns the checked-correlations mask for this agent (=0 for RESET/IGNORE policies, or =corrMask() for HONOR policy).
Definition: RFFlagCube.h:277
casacore::Bool rowPreFlagged(casacore::uInt ifr, casacore::uInt itime)
tells if a row is pre-flagged in the casacore::MS (or does not exist)
Definition: RFFlagCube.h:340
static casacore::Matrix< std::vector< bool > > flagrow_kiss
Definition: RFFlagCube.h:216
casacore::LogIO & logSink()
returns reference to logsink
Definition: RFFlagCube.h:357
RFlagWord corrmask
Definition: RFFlagCube.h:228
void setMSFlags(casacore::uInt itime)
transfers all flags from lattice into VisBuffer
void reset()
resets at start of pass
static casacore::Cube< casacore::Bool > in_flags
Definition: RFFlagCube.h:207
static int in_flags_time
Definition: RFFlagCube.h:208
A 2-D Specialization of the Array class.
ostream-like interface to creating log messages.
Definition: LogIO.h:167
RFlagWord my_corrflagmask
Definition: RFFlagCube.h:228
RFlagWord check_rowmask
RESET or IGNORE policy, or to corrmask for HONOR.
Definition: RFFlagCube.h:228
void init(RFlagWord polmsk, casacore::uInt nAgent, bool is_selector, const casacore::String &name="")
creates flag cube for current chunk.
static casacore::LogIO default_sink
default log sink
Definition: RFFlagCube.h:95
RFlagWord check_corrmask
Definition: RFFlagCube.h:228
static casacore::Int agent_count
&lt;n&gt; is the value of this variable
Definition: RFFlagCube.h:236
static casacore::Int num_inst
number of instances in use
Definition: RFFlagCube.h:261
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the if a human readable name(i.e."black").In many places throughout the plotter
casacore::uInt num(StatEnums which) const
returns a data dimension (POL, CHAN, IFR, etc.)
Definition: RFChunkStats.h:168
RFFlagCube: a cube of flags.
Definition: RFFlagCube.h:91
void cleanup()
cleans up at end of chunk
static casacore::Bool reset_preflags
Definition: RFFlagCube.h:219
RFFlagCube(RFChunkStats &ch, casacore::Bool ignore=false, casacore::Bool reset=false, casacore::LogIO &os=default_sink)
constructor
casacore::Bool clearRowFlag(casacore::uInt ifr, casacore::uInt itime)
casacore::Bool setFlag(casacore::uInt ich, casacore::uInt ifr, FlagCubeIterator &iter)
sets or clears a flag at the given flag cursor
casacore::Bool anyFlagged(casacore::uInt ich, casacore::uInt ifr)
The anyFlagged() uses the corr-flagmask to tell if any of my correlations are flagged either by any a...
Definition: RFFlagCube.h:322
const RFlagWord RowAbsent
Definition: RFFlagCube.h:46
static casacore::Int pos_set_flag
Definition: RFFlagCube.h:217
static bool in_flags_flushed
Definition: RFFlagCube.h:209
void advance(casacore::uInt it, casacore::Bool getFlags=false)
advances global flag iterator to time slot it (if required), sets the flag cursor from the iterator (...
casacore::LogIO os
log sink
Definition: RFFlagCube.h:245
casacore::String getSummary()
returns summary of stats in text form
FlagCubeIterator & iterator()
returns reference to internal iterator
Definition: RFFlagCube.h:351
RFChunkStats & chunk
Definition: RFFlagCube.h:202
PreFlagPolicy pfpolicy
pre-flag policy (can be set on a per-instance basis)
Definition: RFFlagCube.h:248
casacore::Bool rowAgentFlagged(casacore::uInt ifr, casacore::uInt itime)
tells if a row is flagged by any agent
Definition: RFFlagCube.h:344
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
RFlagWord flagmask
Flag mask used by this instance.
Definition: RFFlagCube.h:228
FlagCubeIterator newCustomIter()
creates a custom iterator
Definition: RFFlagCube.h:313
static FlagMatrix flagrow
Definition: RFFlagCube.h:215
static casacore::uInt nchan
Definition: RFFlagCube.h:221
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
casacore::uInt row_fl_raised
Definition: RFFlagCube.h:251
FlaggerEnums: collection of enums for various flagger classes.
Definition: RFCommon.h:126
void getMSFlags(casacore::uInt it)
fills global flag lattice with apriori flags from a VisBuffer (if required)
RFCubeLatticeIterator< RFlagWord > FlagCubeIterator
Definition: RFFlagCube.h:42
casacore::uInt fl_raised
Definition: RFFlagCube.h:251
RFlagWord getFlag(casacore::uInt ich, casacore::uInt ifr, FlagCubeIterator &iter)
Gets full flag word at the given flag cursor.
Definition: RFFlagCube.h:283
casacore::uInt num(StatEnums which)
shortcut to RFChunkStats::num
Definition: RFFlagCube.h:212
casacore::uInt fl_cleared
Definition: RFFlagCube.h:251
static void setMaxMem(casacore::Int maxmem)
sets the maximum memory usage for the flag cube
casacore::LogicalArray maskBits(const casacore::Array< T > &, const T &)
returns a casacore::LogicalArray corresponding to (ARR&amp;MASK)!=0
const Double c
Fundamental physical constants (SI units):
static RFlagWord full_corrmask
Definition: RFFlagCube.h:237
String: the storage and methods of handling collections of characters.
Definition: String.h:223
FlagMatrix * flag_curs
local flag cursor used by this instance (setFlag and clearFlag).
Definition: RFFlagCube.h:257
RFChunkStats: vital information and flagging stats for a visibility chunk.
Definition: RFChunkStats.h:89
unsigned long flagmask_kiss
Definition: RFFlagCube.h:234
static RFlagWord fullCorrMask()
returns mask of all correlations
Definition: RFFlagCube.h:280
casacore::Array< T > operator&(const casacore::Array< T > &, const T &)
casacore::Function for working with bitmasks.
static casacore::Int numInstances()
returns the number of instances of the flag cube
Definition: RFFlagCube.h:354
static RFCubeLattice< RFlagWord > flag
Definition: RFFlagCube.h:214
casacore::Bool clearFlag(casacore::uInt ich, casacore::uInt ifr, FlagCubeIterator &iter)
RFCubeLatticeIterator< T > & iterator()
provides access to lattice itself std::vector&lt;std::vector&lt;bool&gt; &gt; &amp; lattice() { return lat; } ...
RFlagWord corrMask()
returns correlations mask for this agent
Definition: RFFlagCube.h:272
RFlagWord flagMask()
returns flag mask for this agent
Definition: RFFlagCube.h:264
unsigned int uInt
Definition: aipstype.h:51
casacore::Bool setRowFlag(casacore::uInt ifr, casacore::uInt itime)
Sets or clears a row flag.
static casacore::uInt estimateMemoryUse(const RFChunkStats &ch)
returns estimated size of flag cube for a given chunk.
static int getMaxMem()
returns the current maximum memory usage
RFlagWord getRowFlag(casacore::uInt ifr, casacore::uInt itime)
Gets full row flag word.
Definition: RFFlagCube.h:331
casacore::Bool rowFlagged(casacore::uInt ifr, casacore::uInt itime)
preFlagged OR agentFlagged
Definition: RFFlagCube.h:348