RFCommon.h

Go to the documentation of this file.
00001 //# RFCommon.h: this defines RFCommon
00002 //# Copyright (C) 2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 #ifndef FLAGGING_RFCOMMON_H
00028 #define FLAGGING_RFCOMMON_H
00029     
00030 #include <casa/Arrays/Vector.h>
00031 #include <casa/Arrays/Matrix.h>
00032 #include <casa/Containers/RecordInterface.h>
00033 #include <casa/Containers/RecordInterface.h>
00034 #include <casa/Logging/LogIO.h>
00035 #include <algorithm>
00036 #include <limits>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 // RFAs use bitwise flags
00041 typedef uInt RFlagWord;
00042 typedef Vector<RFlagWord> FlagVector;
00043 typedef Matrix<RFlagWord> FlagMatrix;
00044 
00045 // character constants for common agent parameters
00046 const char 
00047     RF_GLISHINDEX[] = "_glishindex", // this is set automatically to indicate 1-based indexing
00048     
00049     RF_NAME[]    = "name",
00050     
00051     RF_DEBUG[]   = "debug",
00052     RF_PLOT[]    = "plot",
00053     RF_PLOTSCR[] = "plotscr",
00054     RF_GLOBAL[]  = "global",
00055     RF_TRIAL[]   = "trial",
00056 
00057     RF_RESET[]   = "reset",
00058     RF_FIGNORE[] = "fignore",
00059     RF_UNFLAG[]  = "unflag",
00060     RF_SHADOW[]  = "shadow",
00061     RF_ELEVATION[] = "elevation",
00062     
00063     RF_THR[]     = "thr",
00064     RF_ROW_THR[] = "rowthr",
00065     
00066     RF_HW[]      = "hw",
00067     RF_ROW_HW[]  = "rowhw",
00068     RF_ROW_DISABLE[] = "norow",
00069 
00070     RF_COLUMN[]  = "column",
00071     RF_EXPR[]    = "expr",
00072     
00073     RF_CLIP[]      = "clip",
00074     RF_FLAGRANGE[] = "flagrange",
00075     RF_MIN[]       = "min",
00076     RF_MAX[]       = "max",
00077     RF_CHANAVG[]   = "chanavg",
00078     
00079     RF_NDEG[]    = "ndeg",
00080     RF_SPWID[]   = "spwid", 
00081     RF_FREQS[]   = "fq",
00082     RF_CHANS[]   = "chan",
00083     RF_REGION[]  = "region",
00084     
00085     RF_NBINS[]   = "nbins",
00086     RF_MINPOP[]  = "minpop",
00087     
00088     RF_CORR[]    = "corr",
00089     RF_ANT[]     = "ant",
00090     RF_FIELD[]   = "field",
00091     RF_BASELINE[] = "baseline",
00092     RF_AUTOCORR[] = "autocorr",
00093 
00094     RF_INTENT[] = "intent",
00095     RF_SCAN[]    = "scan",
00096     RF_ARRAY[]   = "array",
00097     RF_OBSERVATION[] = "observation",
00098     RF_FEED[]    = "feed",
00099     RF_UVRANGE[] = "uvrange",
00100     RF_DIAMETER[] = "diameter",
00101     RF_LOWERLIMIT[]  = "lowerlimit",
00102     RF_UPPERLIMIT[]  = "upperlimit",
00103     
00104     RF_TIMERANGE[] = "timerng",
00105     RF_CENTERTIME[] = "timeslot",
00106     RF_TIMEDELTA[] = "dtime",
00107     
00108     RF_QUACK[]     = "quack",
00109     RF_QUACKMODE[] = "quackmode",
00110     RF_QUACKINC[]  = "quackinc",
00111 
00112     RF_NCHAN[] = "nchan",
00113     RF_START[] = "start",
00114     RF_STEP[] = "step",
00115     RF_MODE[] = "mode",
00116     RF_MSSELECT[] = "msselect";
00117 
00118 // <summary>
00119 // FlaggerEnums: collection of enums for various flagger classes
00120 // </summary>
00121 
00122 // <use visibility=local>
00123 
00124 // <reviewed reviewer="" date="" tests="" demos="">
00125 // </reviewed>
00126 class FlaggerEnums 
00127 {
00128 public:
00129   typedef enum 
00130     { POLZN = 0,POL=POLZN,CORR=POLZN,
00131       CHAN  = 1,
00132       IFR   = 2,
00133       TIME  = 3,
00134       ROW   = 4,
00135       ANT   = 5,
00136       FEED  = 6,
00137       FEEDCORR  = 7,
00138       NONE  = -1,
00139       Num_StatEnums=8 
00140     } StatEnums;
00141 
00142   typedef enum 
00143   {
00144     FL_HONOR  = 0,
00145     FL_IGNORE = 1,
00146     FL_RESET  = 2
00147   } PreFlagPolicy;
00148 };
00149    
00150 
00151 // short inline function for checking the type of a record field
00152 inline Bool fieldType ( const RecordInterface &parm,const String &id,DataType type,DataType type2 = TpNumberOfTypes )
00153 {
00154   if( !parm.isDefined(id) || !parm.shape(id).product() )
00155     return False;
00156   DataType t = parm.dataType(id);
00157   return t==type || t==type2;
00158 }
00159     
00160 // short inline function for checking a field's data type against some function
00161 inline Bool isField ( const RecordInterface &parm,const String &id,Bool (*func)(DataType) )
00162 {
00163   if( !parm.isDefined(id) )
00164     return False;
00165   DataType type = parm.dataType(id);
00166   return (*func)(type);
00167 }
00168 
00169 // short inline function for checking that a field is a non-empty record
00170 inline Bool isValidRecord ( const RecordInterface &parm,const String &id)
00171 {
00172   if( !parm.isDefined(id) || parm.dataType(id) != TpRecord )
00173     return False;
00174   return parm.asRecord(id).nfields() > 0;
00175 }
00176     
00177 // Short inline function for checking if a record field is "set",
00178 // i.e. exists, and is not an empty array or a boolean False.
00179 inline Bool isFieldSet ( const RecordInterface &parm,const String &id )
00180 {
00181   return parm.isDefined(id) && parm.shape(id).product() && ( parm.dataType(id) != TpBool || parm.asBool(id) );
00182 }
00183     
00184 // Short inline function for returning the number of elements in a field
00185 // (0 for no field, 1 for scalar, >1 for arrays)
00186 inline uInt fieldSize ( const RecordInterface &parm,const String &id )
00187 {
00188   return parm.isDefined(id) ? parm.shape(id).product() : 0;
00189 }
00190 
00191 // Basically just upcase(), but in a form suitable for Array::apply
00192 inline String stringUpper ( const String &in )
00193 {
00194   return upcase(in);
00195 }
00196 
00197 // a debug-printf function, for printf-ing debug messages
00198 int dprintf( LogIO &os, const char *format, ... );
00199 
00200 inline std::vector<bool> bitvec_from_ulong( unsigned long val, size_t len = std::numeric_limits<unsigned long>::digits ) {
00201     std::vector<bool> result(len,false);
00202     unsigned long mask = 1;
00203     for( size_t i=0; i < std::min((size_t)result.size( ),(size_t)std::numeric_limits<unsigned long>::digits); ++i ) {
00204         result[i] = mask & val ? true : false;
00205         mask = mask << 1;
00206     }
00207     return result;
00208 }
00209 
00210 inline unsigned long bitvec_to_ulong( const std::vector<bool> &val) {
00211     unsigned long result = 0;
00212     unsigned long mask = 1;
00213     for( size_t i=0; i < std::min((size_t)std::numeric_limits<unsigned long>::digits,(size_t)val.size()); ++i ) {
00214         result |= (val[i] ? mask : 0);
00215         mask = mask << 1;
00216     }
00217     return result;
00218 }
00219 
00220 } //# NAMESPACE CASA - END
00221 
00222 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1