casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFCommon.h
Go to the documentation of this file.
1 //# RFCommon.h: this defines RFCommon
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 //# $Id$
27 #ifndef FLAGGING_RFCOMMON_H
28 #define FLAGGING_RFCOMMON_H
29 
30 #include <casa/Arrays/Vector.h>
31 #include <casa/Arrays/Matrix.h>
34 #include <casa/Logging/LogIO.h>
35 #include <algorithm>
36 #include <limits>
37 
38 namespace casa { //# NAMESPACE CASA - BEGIN
39 
40 // RFAs use bitwise flags
44 
45 // character constants for common agent parameters
46 const char
47  RF_GLISHINDEX[] = "_glishindex", // this is set automatically to indicate 1-based indexing
48 
49  RF_NAME[] = "name",
50 
51  RF_DEBUG[] = "debug",
52  RF_PLOT[] = "plot",
53  RF_PLOTSCR[] = "plotscr",
54  RF_GLOBAL[] = "global",
55  RF_TRIAL[] = "trial",
56 
57  RF_RESET[] = "reset",
58  RF_FIGNORE[] = "fignore",
59  RF_UNFLAG[] = "unflag",
60  RF_SHADOW[] = "shadow",
61  RF_ELEVATION[] = "elevation",
62 
63  RF_THR[] = "thr",
64  RF_ROW_THR[] = "rowthr",
65 
66  RF_HW[] = "hw",
67  RF_ROW_HW[] = "rowhw",
68  RF_ROW_DISABLE[] = "norow",
69 
70  RF_COLUMN[] = "column",
71  RF_EXPR[] = "expr",
72 
73  RF_CLIP[] = "clip",
74  RF_FLAGRANGE[] = "flagrange",
75  RF_MIN[] = "min",
76  RF_MAX[] = "max",
77  RF_CHANAVG[] = "chanavg",
78 
79  RF_NDEG[] = "ndeg",
80  RF_SPWID[] = "spwid",
81  RF_FREQS[] = "fq",
82  RF_CHANS[] = "chan",
83  RF_REGION[] = "region",
84 
85  RF_NBINS[] = "nbins",
86  RF_MINPOP[] = "minpop",
87 
88  RF_CORR[] = "corr",
89  RF_ANT[] = "ant",
90  RF_FIELD[] = "field",
91  RF_BASELINE[] = "baseline",
92  RF_AUTOCORR[] = "autocorr",
93 
94  RF_INTENT[] = "intent",
95  RF_SCAN[] = "scan",
96  RF_ARRAY[] = "array",
97  RF_OBSERVATION[] = "observation",
98  RF_FEED[] = "feed",
99  RF_UVRANGE[] = "uvrange",
100  RF_DIAMETER[] = "diameter",
101  RF_LOWERLIMIT[] = "lowerlimit",
102  RF_UPPERLIMIT[] = "upperlimit",
103 
104  RF_TIMERANGE[] = "timerng",
105  RF_CENTERTIME[] = "timeslot",
106  RF_TIMEDELTA[] = "dtime",
107 
108  RF_QUACK[] = "quack",
109  RF_QUACKMODE[] = "quackmode",
110  RF_QUACKINC[] = "quackinc",
111 
112  RF_NCHAN[] = "nchan",
113  RF_START[] = "start",
114  RF_STEP[] = "step",
115  RF_MODE[] = "mode",
116  RF_MSSELECT[] = "msselect";
117 
118 // <summary>
119 // FlaggerEnums: collection of enums for various flagger classes
120 // </summary>
121 
122 // <use visibility=local>
123 
124 // <reviewed reviewer="" date="" tests="" demos="">
125 // </reviewed>
127 {
128 public:
129  typedef enum
131  CHAN = 1,
132  IFR = 2,
133  TIME = 3,
134  ROW = 4,
135  ANT = 5,
136  FEED = 6,
137  FEEDCORR = 7,
138  NONE = -1,
140  } StatEnums;
141 
142  typedef enum
143  {
144  FL_HONOR = 0,
147  } PreFlagPolicy;
148 };
149 
150 
151 // short inline function for checking the type of a record field
153  const casacore::String &id,casacore::DataType type,
154  casacore::DataType type2 = casacore::TpNumberOfTypes )
155 {
156  if( !parm.isDefined(id) || !parm.shape(id).product() )
157  return false;
158  casacore::DataType t = parm.dataType(id);
159  return t==type || t==type2;
160 }
161 
162 // short inline function for checking a field's data type against some function
163 inline casacore::Bool isField ( const casacore::RecordInterface &parm,const casacore::String &id,casacore::Bool (*func)(casacore::DataType) )
164 {
165  if( !parm.isDefined(id) )
166  return false;
167  casacore::DataType type = parm.dataType(id);
168  return (*func)(type);
169 }
170 
171 // short inline function for checking that a field is a non-empty record
173 {
174  if( !parm.isDefined(id) || parm.dataType(id) != casacore::TpRecord )
175  return false;
176  return parm.asRecord(id).nfields() > 0;
177 }
178 
179 // casacore::Short inline function for checking if a record field is "set",
180 // i.e. exists, and is not an empty array or a boolean false.
182 {
183  return parm.isDefined(id) && parm.shape(id).product() &&
184  ( parm.dataType(id) != casacore::TpBool || parm.asBool(id) );
185 }
186 
187 // casacore::Short inline function for returning the number of elements in a field
188 // (0 for no field, 1 for scalar, >1 for arrays)
190 {
191  return parm.isDefined(id) ? parm.shape(id).product() : 0;
192 }
193 
194 // Basically just upcase(), but in a form suitable for casacore::Array::apply
196 {
197  return upcase(in);
198 }
199 
200 // a debug-printf function, for printf-ing debug messages
201 int dprintf( casacore::LogIO &os, const char *format, ... );
202 
203 inline std::vector<bool> bitvec_from_ulong( unsigned long val, size_t len = std::numeric_limits<unsigned long>::digits ) {
204  std::vector<bool> result(len,false);
205  unsigned long mask = 1;
206  for( size_t i=0; i < std::min((size_t)result.size( ),(size_t)std::numeric_limits<unsigned long>::digits); ++i ) {
207  result[i] = mask & val ? true : false;
208  mask = mask << 1;
209  }
210  return result;
211 }
212 
213 inline unsigned long bitvec_to_ulong( const std::vector<bool> &val) {
214  unsigned long result = 0;
215  unsigned long mask = 1;
216  for( size_t i=0; i < std::min((size_t)std::numeric_limits<unsigned long>::digits,(size_t)val.size()); ++i ) {
217  result |= (val[i] ? mask : 0);
218  mask = mask << 1;
219  }
220  return result;
221 }
222 
223 } //# NAMESPACE CASA - END
224 
225 #endif
Bool asBool(const RecordFieldId &) const
The following functions get the value based on field name or number.
const char RF_START[]
Definition: RFCommon.h:113
virtual const RecordInterface & asRecord(const RecordFieldId &) const =0
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
const char RF_MIN[]
Definition: RFCommon.h:75
casacore::uInt RFlagWord
RFAs use bitwise flags.
Definition: RFCommon.h:41
const char RF_INTENT[]
Definition: RFCommon.h:94
casacore::Vector< RFlagWord > FlagVector
Definition: RFCommon.h:42
casacore::uInt fieldSize(const casacore::RecordInterface &parm, const casacore::String &id)
casacore::Short inline function for returning the number of elements in a field (0 for no field...
Definition: RFCommon.h:189
const char RF_FEED[]
Definition: RFCommon.h:98
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
const char RF_CENTERTIME[]
Definition: RFCommon.h:105
#define min(a, b)
Definition: hio.h:45
virtual Type type()
Return the type enum.
unsigned long bitvec_to_ulong(const std::vector< bool > &val)
Definition: RFCommon.h:213
const char RF_QUACK[]
Definition: RFCommon.h:108
const char RF_BASELINE[]
Definition: RFCommon.h:91
const char RF_EXPR[]
Definition: RFCommon.h:71
const char RF_ANT[]
Definition: RFCommon.h:89
const char RF_MSSELECT[]
Definition: RFCommon.h:116
const char RF_UNFLAG[]
Definition: RFCommon.h:59
A 2-D Specialization of the Array class.
ostream-like interface to creating log messages.
Definition: LogIO.h:167
const char RF_FIELD[]
Definition: RFCommon.h:90
const char RF_MINPOP[]
Definition: RFCommon.h:86
const char RF_NAME[]
Definition: RFCommon.h:49
const char RF_THR[]
Definition: RFCommon.h:63
const char RF_SPWID[]
Definition: RFCommon.h:80
DataType dataType(const RecordFieldId &) const
const char RF_DIAMETER[]
Definition: RFCommon.h:100
casacore::Matrix< RFlagWord > FlagMatrix
Definition: RFCommon.h:43
const char RF_CHANAVG[]
Definition: RFCommon.h:77
const char RF_TIMEDELTA[]
Definition: RFCommon.h:106
const char RF_HW[]
Definition: RFCommon.h:66
const char RF_CORR[]
Definition: RFCommon.h:88
casacore::Bool fieldType(const casacore::RecordInterface &parm, const casacore::String &id, casacore::DataType type, casacore::DataType type2=casacore::TpNumberOfTypes)
short inline function for checking the type of a record field
Definition: RFCommon.h:152
const char RF_ELEVATION[]
Definition: RFCommon.h:61
const char RF_MAX[]
Definition: RFCommon.h:76
const char RF_NCHAN[]
Definition: RFCommon.h:112
const char RF_REGION[]
Definition: RFCommon.h:83
const char RF_COLUMN[]
Definition: RFCommon.h:70
int dprintf(casacore::LogIO &os, const char *format,...)
a debug-printf function, for printf-ing debug messages
const char RF_GLISHINDEX[]
character constants for common agent parameters
Definition: RFCommon.h:47
const char RF_GLOBAL[]
Definition: RFCommon.h:54
const char RF_SCAN[]
Definition: RFCommon.h:95
std::vector< bool > bitvec_from_ulong(unsigned long val, size_t len=std::numeric_limits< unsigned long >::digits)
Definition: RFCommon.h:203
const char RF_AUTOCORR[]
Definition: RFCommon.h:92
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
TableExprNode upcase(const TableExprNode &node)
Definition: ExprNode.h:1425
casacore::String stringUpper(const casacore::String &in)
Basically just upcase(), but in a form suitable for casacore::Array::apply.
Definition: RFCommon.h:195
const char RF_LOWERLIMIT[]
Definition: RFCommon.h:101
Bool isDefined(const String &fieldName) const
Test if a field name exists.
casacore::Bool isField(const casacore::RecordInterface &parm, const casacore::String &id, casacore::Bool(*func)(casacore::DataType))
short inline function for checking a field&#39;s data type against some function
Definition: RFCommon.h:163
virtual uInt nfields() const =0
How many fields does this structure have?
const char RF_FREQS[]
Definition: RFCommon.h:81
casacore::Bool isFieldSet(const casacore::RecordInterface &parm, const casacore::String &id)
casacore::Short inline function for checking if a record field is &quot;set&quot;, i.e.
Definition: RFCommon.h:181
const char RF_TRIAL[]
Definition: RFCommon.h:55
const char RF_PLOT[]
Definition: RFCommon.h:52
const char RF_CHANS[]
Definition: RFCommon.h:82
FlaggerEnums: collection of enums for various flagger classes.
Definition: RFCommon.h:126
const char RF_STEP[]
Definition: RFCommon.h:114
const char RF_SHADOW[]
Definition: RFCommon.h:60
const char RF_ROW_DISABLE[]
Definition: RFCommon.h:68
casacore::Bool isValidRecord(const casacore::RecordInterface &parm, const casacore::String &id)
short inline function for checking that a field is a non-empty record
Definition: RFCommon.h:172
const char RF_NBINS[]
Definition: RFCommon.h:85
const char RF_NDEG[]
Definition: RFCommon.h:79
const char RF_FIGNORE[]
Definition: RFCommon.h:58
const char RF_QUACKMODE[]
Definition: RFCommon.h:109
String: the storage and methods of handling collections of characters.
Definition: String.h:223
const char RF_UPPERLIMIT[]
Definition: RFCommon.h:102
const char RF_ARRAY[]
Definition: RFCommon.h:96
const char RF_CLIP[]
Definition: RFCommon.h:73
Abstract base class for Record classes.
const char RF_QUACKINC[]
Definition: RFCommon.h:110
const char RF_DEBUG[]
Definition: RFCommon.h:51
const char RF_OBSERVATION[]
Definition: RFCommon.h:97
const char RF_MODE[]
Definition: RFCommon.h:115
const char RF_FLAGRANGE[]
Definition: RFCommon.h:74
const char RF_UVRANGE[]
Definition: RFCommon.h:99
const char RF_ROW_THR[]
Definition: RFCommon.h:64
const char RF_TIMERANGE[]
Definition: RFCommon.h:104
const char RF_ROW_HW[]
Definition: RFCommon.h:67
const char RF_PLOTSCR[]
Definition: RFCommon.h:53
Int64 product() const
Returns 0 if nelements() == 0, otherwise it returns the product of its elements.
unsigned int uInt
Definition: aipstype.h:51
const char RF_RESET[]
Definition: RFCommon.h:57