00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef FLAGGING_RFFLAGCUBE_H
00029 #define FLAGGING_RFFLAGCUBE_H
00030
00031
00032 #include <flagging/Flagging/RFCubeLattice.h>
00033 #include <flagging/Flagging/RFChunkStats.h>
00034 #include <casa/Arrays/ArrayLogical.h>
00035 #include <casa/Arrays/LogiMatrix.h>
00036 #include <casa/Arrays/LogiVector.h>
00037 #include <casa/Logging/LogIO.h>
00038 #include <stdexcept>
00039
00040 namespace casa {
00041
00042 typedef RFCubeLatticeIterator<RFlagWord> FlagCubeIterator;
00043
00044
00045
00046 const RFlagWord RowFlagged=1,RowAbsent=2;
00047
00048
00049
00050 template<class T> Array<T> operator & ( const Array<T> &,const T &);
00051
00052 template<class T> LogicalArray maskBits ( const Array<T> &,const T &);
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 class RFFlagCube : public FlaggerEnums
00092 {
00093 public:
00094
00095 static LogIO default_sink;
00096
00097
00098 RFFlagCube ( RFChunkStats &ch,Bool ignore=False,Bool reset=False,LogIO &os=default_sink );
00099 ~RFFlagCube ();
00100
00101
00102 LogIO & logSink ();
00103
00104
00105 static uInt estimateMemoryUse ( const RFChunkStats &ch );
00106
00107
00108
00109 void init ( RFlagWord polmsk, uInt nAgent, bool is_selector, const String &name = "" );
00110
00111
00112 void cleanup ();
00113
00114
00115 String getSummary ();
00116
00117
00118 void printStats ();
00119
00120
00121 void reset ();
00122
00123
00124
00125
00126 void advance ( uInt it,Bool getFlags=False );
00127
00128
00129 void getMSFlags (uInt it);
00130
00131
00132 void setMSFlags (uInt itime);
00133
00134
00135 FlagCubeIterator newCustomIter ();
00136
00137
00138 const FlagMatrix & flagMatrix ();
00139
00140
00141 Bool setFlag ( uInt ich,uInt ifr,FlagCubeIterator &iter );
00142 Bool clearFlag ( uInt ich,uInt ifr,FlagCubeIterator &iter );
00143
00144
00145 RFlagWord getFlag ( uInt ich,uInt ifr,FlagCubeIterator &iter );
00146
00147
00148 Bool setFlag ( uInt ich,uInt ifr );
00149 Bool clearFlag ( uInt ich,uInt ifr );
00150 RFlagWord getFlag ( uInt ich,uInt ifr );
00151
00152
00153
00154 Bool preFlagged ( uInt ich,uInt ifr );
00155
00156
00157
00158
00159 Bool anyFlagged ( uInt ich,uInt ifr );
00160
00161
00162 Bool setRowFlag ( uInt ifr,uInt itime );
00163 Bool clearRowFlag ( uInt ifr,uInt itime );
00164
00165
00166 RFlagWord getRowFlag ( uInt ifr,uInt itime );
00167
00168
00169 Bool rowPreFlagged ( uInt ifr,uInt itime );
00170
00171
00172 Bool rowAgentFlagged ( uInt ifr,uInt itime );
00173
00174
00175 Bool rowFlagged ( uInt ifr,uInt itime );
00176
00177
00178 FlagCubeIterator & iterator ();
00179
00180
00181 RFlagWord flagMask ();
00182
00183
00184 RFlagWord corrMask ();
00185
00186
00187
00188 RFlagWord checkCorrMask ();
00189
00190
00191 static RFlagWord fullCorrMask ();
00192
00193
00194 static Int numInstances ();
00195
00196
00197 static void setMaxMem ( Int maxmem );
00198
00199 static int getMaxMem ();
00200
00201 private:
00202 RFChunkStats &chunk;
00203
00204 bool kiss;
00205 bool kiss_flagrow;
00206
00207 static Cube<Bool> in_flags;
00208 static int in_flags_time;
00209 static bool in_flags_flushed;
00210
00211
00212 uInt num ( StatEnums which ) { return chunk.num(which); }
00213
00214 static RFCubeLattice<RFlagWord> flag;
00215 static FlagMatrix flagrow;
00216 static Matrix<std::vector<bool> > flagrow_kiss;
00217 static Int pos_get_flag,pos_set_flag;
00218
00219 static Bool reset_preflags;
00220
00221 static uInt npol,nchan;
00222
00223
00224
00225
00226
00227
00228 RFlagWord flagmask,
00229 corrmask,
00230 check_corrmask,
00231
00232 check_rowmask,
00233 my_corrflagmask;
00234 unsigned long flagmask_kiss;
00235
00236 static Int agent_count;
00237 static RFlagWord base_flagmask,
00238 full_corrmask;
00239
00240
00241
00242 static Vector<RFlagWord> corr_flagmask;
00243
00244
00245 LogIO os;
00246
00247
00248 PreFlagPolicy pfpolicy;
00249
00250
00251 uInt tot_fl_raised,fl_raised,fl_cleared,
00252 tot_row_fl_raised,row_fl_raised,row_fl_cleared;
00253
00254
00255
00256
00257 FlagMatrix * flag_curs;
00258 uInt flag_itime;
00259
00260
00261 static Int num_inst;
00262 };
00263
00264 inline RFlagWord RFFlagCube::flagMask ()
00265 {
00266 if (kiss) {
00267 throw std::logic_error("Cannot do this in kiss mode (program bug, please report)");
00268 }
00269 return flagmask;
00270 }
00271
00272 inline RFlagWord RFFlagCube::corrMask ()
00273 {
00274 return corrmask;
00275 }
00276
00277 inline RFlagWord RFFlagCube::checkCorrMask ()
00278 { return check_corrmask; }
00279
00280 inline RFlagWord RFFlagCube::fullCorrMask ()
00281 { return full_corrmask; }
00282
00283 inline RFlagWord RFFlagCube::getFlag ( uInt ich,uInt ifr,FlagCubeIterator &iter )
00284 {
00285 if (kiss) {
00286
00287
00288 RFlagWord f = 0;
00289 uInt c = 1;
00290
00291 for (uInt icorr = 0; icorr < num(CORR); icorr++, c<<=1) {
00292 if ((c & corrmask) &&
00293 in_flags(icorr, ich, ifr)) {
00294 f |= c;
00295 }
00296 }
00297 return f;
00298 }
00299 else {
00300 return (iter)(ich,ifr);
00301 }
00302 }
00303
00304 inline Bool RFFlagCube::setFlag ( uInt ich,uInt ifr )
00305 { return setFlag(ich,ifr,flag.iterator()); }
00306
00307 inline Bool RFFlagCube::clearFlag ( uInt ich,uInt ifr )
00308 { return clearFlag(ich,ifr,flag.iterator()); }
00309
00310 inline RFlagWord RFFlagCube::getFlag ( uInt ich,uInt ifr )
00311 { return getFlag(ich,ifr,flag.iterator()); }
00312
00313 inline FlagCubeIterator RFFlagCube::newCustomIter ()
00314 { return flag.newIter(); }
00315
00316 inline const FlagMatrix & RFFlagCube::flagMatrix ()
00317 { return *flag_curs; }
00318
00319 inline Bool RFFlagCube::preFlagged ( uInt ich,uInt ifr )
00320 { return (getFlag(ich,ifr)&check_corrmask) != 0; }
00321
00322 inline Bool RFFlagCube::anyFlagged ( uInt ich,uInt ifr )
00323 {
00324 if (kiss) {
00325 throw std::logic_error("Cannot do this in kiss mode (program bug, please report)");
00326 }
00327 return (getFlag(ich,ifr)&(check_corrmask|my_corrflagmask)) != 0;
00328 }
00329
00330
00331 inline RFlagWord RFFlagCube::getRowFlag ( uInt ifr,uInt itime )
00332 {
00333 if (kiss) {
00334 throw std::logic_error("Cannot do this in kiss mode (program bug, please report)");
00335 }
00336 return flagrow(ifr,itime);
00337 }
00338
00339
00340 inline Bool RFFlagCube::rowPreFlagged ( uInt ifr,uInt itime )
00341 { return getRowFlag(ifr,itime)&check_rowmask; }
00342
00343
00344 inline Bool RFFlagCube::rowAgentFlagged ( uInt ifr,uInt itime )
00345 { return getRowFlag(ifr,itime)&~(RowFlagged|RowAbsent); }
00346
00347
00348 inline Bool RFFlagCube::rowFlagged ( uInt ifr,uInt itime )
00349 { return getRowFlag(ifr,itime)&(check_rowmask?~0:~RowFlagged); }
00350
00351 inline FlagCubeIterator & RFFlagCube::iterator ()
00352 { return flag.iterator(); }
00353
00354 inline int RFFlagCube::numInstances ()
00355 { return num_inst; }
00356
00357 inline LogIO & RFFlagCube::logSink ()
00358 { return os; }
00359
00360
00361 }
00362
00363 #ifndef AIPS_NO_TEMPLATE_SRC
00364 #include <flagging/Flagging/RFFlagCube.tcc>
00365 #endif //# AIPS_NO_TEMPLATE_SRC
00366 #endif