casacore
Loading...
Searching...
No Matches
ExprFuncNode.h
Go to the documentation of this file.
1//# ExprFuncNode.h: Class representing a function in table select expression
2//# Copyright (C) 1994,1995,1996,1997,1998,2000,2001,2003
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: casa-feedback@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 TABLES_EXPRFUNCNODE_H
27#define TABLES_EXPRFUNCNODE_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/TaQL/ExprNodeRep.h>
32#include <casacore/casa/Quanta/MVAngle.h>
33#include <casacore/casa/BasicMath/Math.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38class TableExprNodeSet;
39
40
41// <summary>
42// Class representing a function in table select expression
43// </summary>
44
45// <use visibility=local>
46
47// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
48// </reviewed>
49// <prerequisite>
50//# Classes you should understand before using this one.
51// <li> <linkto class=TableExprNodeMulti>TableExprNodeMulti</linkto>
52// </prerequisite>
53
54// <synopsis>
55// This class represents a function in a table select tree.
56// The <src>rownumber</src> function is represented by class
57// <linkto class=TableExprNodeRownr>TableExprNodeRownr</linkto>.
58// The <src>rowid</src> function is represented by class
59// <linkto class=TableExprNodeRowid>TableExprNodeRowid</linkto>.
60// The <src>rand</src> function is represented by class
61// <linkto class=TableExprNodeRandom>TableExprNodeRandom</linkto>.
62// <p>
63// When one wants to add a function to the table selection grammar,
64// the following has to be done:
65// <ul>
66// <li> Add the function to the enum below.
67// <li> Implement the function in the get functions in ExprFuncNode(Array).cc.
68// <li> Implement the function in the checkOperands in ExprFuncNode.cc.
69// <li> Declare and define the function in ExprNode.h (for C++ binding).
70// <li> Add the function to findFunc in TableParse.cc (for TaQL).
71// </ul>
72// </synopsis>
73
74
76{
77public:
78 //# Define the function types.
80 piFUNC, //# 0
81 eFUNC, //# 1
82 cFUNC, //# 2
83 // for Int, or Double or Complex returning Bool
84 // (2 is with default tolerance)
85 near2FUNC, //# 3
86 near3FUNC, //# 4
89 // for Int, Double or DComplex returning Double or Complex
90 sinFUNC, //# 7
91 sinhFUNC, //# 8
92 cosFUNC, //# 9
93 coshFUNC, //# 10
94 expFUNC, //# 11
95 logFUNC, //# 12
96 log10FUNC, //# 13
97 sqrtFUNC, //# 14
98 powFUNC, //# 15
99 conjFUNC, //# 16
100 // for Int, Double or DComplex returning Int, Double or Complex
102 cubeFUNC, //# 18
103 minFUNC, //# 19
104 maxFUNC, //# 20
105 // for Int, Double or DComplex returning Int or Double
106 normFUNC, //# 21
107 absFUNC, //# 22
108 // for Int, Double or DComplex returning Double
109 argFUNC, //# 23
110 // for Int, Double, DComplex, Bool or String returning Double
111 realFUNC, //# 24
112 // for Double or DComplex returning Double
113 imagFUNC, //# 25
114 // for Int, Double, Bool or String returning Int (using floor)
115 intFUNC, //# 26
116 // for Int, Double or Complex returning Double or Complex
117 asinFUNC, //# 27
118 acosFUNC, //# 28
119 atanFUNC, //# 29
120 atan2FUNC, //# 30
121 tanFUNC, //# 31
122 tanhFUNC, //# 32
123 // for Int or Double returning Int or Double
124 signFUNC, //# 33
125 roundFUNC, //# 34
126 floorFUNC, //# 35
127 ceilFUNC, //# 36
128 fmodFUNC, //# 37
129 // for DComplex or String returning DComplex
131 // for Int, Double or Complex array returning the same
144 // for Int or Double array returning Int or Double
153 // for Int or Double array returning Double
190 // for Bool array returning Bool
196 arrallsFUNC, //# 100
197 runallFUNC, //# 101
198 boxallFUNC, //# 102
199 // for Bool array returning Int scalar
208 // for any type returning array of that type
209 arrayFUNC, //# 111
212 resizeFUNC, //# 114
214 // for Int, Double or DComplex array returning Bool
215 isnanFUNC, //# 116
216 isinfFUNC, //# 117
218 // for any array returning Bool scalar
219 isdefFUNC, //# 119
220 isnullFUNC, //# 120
221 iscolFUNC, //# 121
222 iskeyFUNC, //# 122
223 // for any array returning Int scalar
224 ndimFUNC, //# 123
225 nelemFUNC, //# 124
226 // for any array returning Int array
227 shapeFUNC, //# 125
228 // for String
229 strlengthFUNC, //# 126 returning Int
230 upcaseFUNC, //# 127 returning String
231 downcaseFUNC, //# 128 returning String
232 capitalizeFUNC, //# 129 returning String
234 trimFUNC, //# 131 returning String
235 ltrimFUNC, //# 132 returning String
236 rtrimFUNC, //# 133 returning String
237 substrFUNC, //# 134 returning String
238 replaceFUNC, //# 135 returning String
239 regexFUNC, //# 136 returning TaqlRegex
240 patternFUNC, //# 137 returning TaqlRegex
241 sqlpatternFUNC, //# 138 returning TaqlRegex
242 // for Date
243 datetimeFUNC, //# 139 returning Date
244 mjdtodateFUNC, //# 140 returning Date
245 mjdFUNC, //# 141 returning Double
246 dateFUNC, //# 142 returning Date
247 timeFUNC, //# 143 returning Double (in radians)
248 yearFUNC, //# 144 returning Int
249 monthFUNC, //# 145 returning Int
250 dayFUNC, //# 146 returning Int
251 cmonthFUNC, //# 147 returning String
252 weekdayFUNC, //# 148 returning Int
253 cdowFUNC, //# 149 returning String
254 weekFUNC, //# 150 returning Int
255 ctodFUNC, //# 151 returning String
256 cdateFUNC, //# 152 returning String
257 ctimeFUNC, //# 153 returning String
258 // return values as strings
259 stringFUNC, //# 154
260 // return angles as hms strings
261 hmsFUNC, //# 155
262 // return angles as dms strings
263 dmsFUNC, //# 156
264 // return angles as hms/dms strings
265 hdmsFUNC, //# 157
266 // special function returning a random Double number
267 randFUNC, //# 158
268 // special function returning Int row number
269 rownrFUNC, //# 159
270 // special function returning Int row id (meant for GIVING)
271 rowidFUNC, //# 160
272 // special function resembling if statement
273 iifFUNC, //# 161
274 // angular distance returning radians
275 angdistFUNC, //# 162
277 // cone search functions, implemented in derived class
278 conesFUNC, //# 164
279 cones3FUNC, //# 165
280 anyconeFUNC, //# 166
284 // normalize angle between -pi and pi
286 // for Int, Double, Complex or String returning Bool
287 boolFUNC, //# 171
288 // masked array functions
290 marrayFUNC, //# 173
291 arrdataFUNC, //# 174
292 arrmaskFUNC, //# 175
296 arrflatFUNC, //# 179
297 //# AGGREGATE functions must be the last ones.
303 //# Grouping doing aggregation on the fly; reducing to a scalar per group
304 gminFUNC, //# 184
319 //# Grouping doing aggregation on the fly; reducing to an array per group
338 //# Grouping requiring aggregation of rows when getting result
339 gaggrFUNC, //# 215
343 gexpridFUNC, //# special function (can be inserted by TableParse)
344 NRFUNC //# 220 should be last
345 };
346
347 // Constructor
349 const TableExprNodeSet& source,
350 const vector<TENShPtr>& nodes,
351 const Block<Int>& dtypeOper,
352 const TableExprInfo& = TableExprInfo());
353
354 // Destructor
356
357 // 'get' Functions to get the desired result of a function
358 // <group>
362 DComplex getDComplex (const TableExprId& id);
366 // </group>
367
368 // Check the data and value types of the operands.
369 // It sets the exptected data and value types of the operands.
370 // Set the value type of the function result and returns
371 // the data type of the function result.
373 ValueType& resVT,
374 Block<Int>& vtypeOper,
376 std::vector<TENShPtr>&);
377
378 // Fill the result unit in the node.
379 // Adapt the children nodes if their units need to be converted.
380 // It returns a possible scale factor in case result unit is SI (for sqrt).
381 void fillUnits();
382
383 // Link the children to the node and convert the children
384 // to constants if possible.
385 void fillChildNodes (const vector<TENShPtr>& nodes,
386 const Block<Int>& dtypeOper);
387
388 // Get possible unit scale factor (needed for sqrt).
390 { return scale_p; }
391
392 // Some functions to be used by TableExprNodeFuncArray.
393 // <group>
394 const std::vector<TENShPtr>& operands() const
395 { return operands_p; }
396 std::vector<TENShPtr>& rwOperands()
397 { return operands_p; }
399 { return funcType_p; }
401 { return argDataType_p; }
402 // </group>
403
404 // Get the possible print format, width, and/or precision.
405 static void getPrintFormat (String& fmt, Int& width, Int& prec,
406 const std::vector<TENShPtr>& operands,
407 const TableExprId& id);
408
409 // Convert the date and/or time to a string.
410 // <group>
411 static String stringDT (const MVTime& dt, Int prec, MVTime::formatTypes);
412 static String stringDateTime (const MVTime& dt, Int prec);
413 static String stringDate (const MVTime& dt);
414 static String stringTime (const MVTime& dt, Int prec);
415 // </group>
416
417 // Convert a value to a string.
418 // If <src>fmt</src> is empty, ostringstream is used.
419 // Otherwise the printf-like format is used.
420 // If possible, a double value is converted to radians if formatted as angle.
421 // <group>
422 static String stringValue (Bool val, const String& fmt, Int width);
423 static String stringValue (Int64 val, const String& fmt, Int width);
424 static String stringValue (Double val, const String& fmt,
425 Int width, Int prec,
426 const std::pair<int,int>& mvFormat,
427 const Unit& unit);
428 static String stringValue (const DComplex& val, const String& fmt,
429 Int width, Int prec);
430 static String stringValue (const String& val, const String& fmt,
431 Int width);
432 static String stringValue (const MVTime& val, const String& fmt,
433 Int width,
434 const std::pair<int,int>& mvFormat);
435
436 // Convert angle to a string (hms or dms).
437 // <group>
438 static String stringAngle (double val, Int prec,
440 static String stringHMS (double val, Int prec);
441 static String stringDMS (double val, Int prec);
442 // </group>
443
444 // Get the MVTime/Angle format and optional precision.
445 // 0,0 is returned if empty or unknown format.
446 static std::pair<int,int> getMVFormat (const String& fmt);
447
448 // Get the angular distance between two positions on a sphere.
449 static double angdist (double ra1, double dec1, double ra2, double dec2)
450 { return acos (sin(dec1)*sin(dec2) + cos(dec1)*cos(dec2)*cos(ra1-ra2)); }
451
452 // Read a string as an integer, double, complex or bool.
453 static Int64 string2Int (const String&);
454 static Double string2Real (const String&);
455 static DComplex string2Complex (const String&);
456 static Bool string2Bool (const String&);
457
458private:
459 // Try if the function gives a constant result.
460 // If so, set the expression type to Constant.
462
463 // Make the units of nodes from <src>starg</src> till <src>endarg</src>
464 // equal. Return the unit found.
465 static const Unit& makeEqualUnits (std::vector<TENShPtr>& nodes,
466 uInt starg, uInt endarg);
467
468 //# Data members.
469 FunctionType funcType_p; // which function
470 NodeDataType argDataType_p; // common argument data type
471 Double scale_p; // possible scaling for unit conversion
472 // (needed for sqrt)
473 Table table_p; // table (for iscolumn and iskeyword)
474};
475
476
477} //# NAMESPACE CASACORE - END
478
479#endif
simple 1-D array
Definition Block.h:198
formatTypes
Format types.
Definition MVAngle.h:249
formatTypes
Format types.
Definition MVTime.h:274
String: the storage and methods of handling collections of characters.
Definition String.h:223
static Double string2Real(const String &)
Double getDouble(const TableExprId &id)
Double getScale() const
Get possible unit scale factor (needed for sqrt).
static double angdist(double ra1, double dec1, double ra2, double dec2)
Get the angular distance between two positions on a sphere.
String getString(const TableExprId &id)
void fillUnits()
Fill the result unit in the node.
static String stringValue(const String &val, const String &fmt, Int width)
TaqlRegex getRegex(const TableExprId &id)
static String stringDateTime(const MVTime &dt, Int prec)
NodeDataType argDataType() const
static String stringValue(const MVTime &val, const String &fmt, Int width, const std::pair< int, int > &mvFormat)
@ sinFUNC
for Int, Double or DComplex returning Double or Complex
@ complexFUNC
for DComplex or String returning DComplex
@ isdefFUNC
for any array returning Bool scalar
@ stringFUNC
return values as strings
@ boolFUNC
for Int, Double, Complex or String returning Bool
@ angdistFUNC
angular distance returning radians
@ iifFUNC
special function resembling if statement
@ realFUNC
for Int, Double, DComplex, Bool or String returning Double
@ hmsFUNC
return angles as hms strings
@ arrsumFUNC
for Int, Double or Complex array returning the same
@ asinFUNC
for Int, Double or Complex returning Double or Complex
@ arranyFUNC
for Bool array returning Bool
@ arrmeanFUNC
for Int or Double array returning Double
@ rowidFUNC
special function returning Int row id (meant for GIVING)
@ arrayFUNC
for any type returning array of that type
@ shapeFUNC
for any array returning Int array
@ near2FUNC
for Int, or Double or Complex returning Bool (2 is with default tolerance)
@ conesFUNC
cone search functions, implemented in derived class
@ isnanFUNC
for Int, Double or DComplex array returning Bool
@ intFUNC
for Int, Double, Bool or String returning Int (using floor)
@ normangleFUNC
normalize angle between -pi and pi
@ rownrFUNC
special function returning Int row number
@ argFUNC
for Int, Double or DComplex returning Double
@ arrminFUNC
for Int or Double array returning Int or Double
@ nullarrayFUNC
masked array functions
@ hdmsFUNC
return angles as hms/dms strings
@ arrntrueFUNC
for Bool array returning Int scalar
@ imagFUNC
for Double or DComplex returning Double
@ ndimFUNC
for any array returning Int scalar
@ randFUNC
special function returning a random Double number
@ normFUNC
for Int, Double or DComplex returning Int or Double
@ dmsFUNC
return angles as dms strings
@ signFUNC
for Int or Double returning Int or Double
@ squareFUNC
for Int, Double or DComplex returning Int, Double or Complex
static String stringValue(Bool val, const String &fmt, Int width)
Convert a value to a string.
static String stringValue(Int64 val, const String &fmt, Int width)
static String stringValue(Double val, const String &fmt, Int width, Int prec, const std::pair< int, int > &mvFormat, const Unit &unit)
DComplex getDComplex(const TableExprId &id)
std::vector< TENShPtr > & rwOperands()
static String stringAngle(double val, Int prec, MVAngle::formatTypes type)
Convert angle to a string (hms or dms).
static Int64 string2Int(const String &)
Read a string as an integer, double, complex or bool.
static String stringDT(const MVTime &dt, Int prec, MVTime::formatTypes)
Convert the date and/or time to a string.
Table table_p
(needed for sqrt)
TableExprFuncNode(FunctionType, NodeDataType, ValueType, const TableExprNodeSet &source, const vector< TENShPtr > &nodes, const Block< Int > &dtypeOper, const TableExprInfo &=TableExprInfo())
Constructor.
static String stringValue(const DComplex &val, const String &fmt, Int width, Int prec)
static String stringDate(const MVTime &dt)
const std::vector< TENShPtr > & operands() const
Some functions to be used by TableExprNodeFuncArray.
static NodeDataType checkOperands(Block< Int > &dtypeOper, ValueType &resVT, Block< Int > &vtypeOper, FunctionType, std::vector< TENShPtr > &)
Check the data and value types of the operands.
static Bool string2Bool(const String &)
static String stringDMS(double val, Int prec)
void fillChildNodes(const vector< TENShPtr > &nodes, const Block< Int > &dtypeOper)
Link the children to the node and convert the children to constants if possible.
static String stringHMS(double val, Int prec)
FunctionType funcType() const
static void getPrintFormat(String &fmt, Int &width, Int &prec, const std::vector< TENShPtr > &operands, const TableExprId &id)
Get the possible print format, width, and/or precision.
static DComplex string2Complex(const String &)
void tryToConst()
Try if the function gives a constant result.
static String stringTime(const MVTime &dt, Int prec)
static const Unit & makeEqualUnits(std::vector< TENShPtr > &nodes, uInt starg, uInt endarg)
Make the units of nodes from starg till endarg equal.
MVTime getDate(const TableExprId &id)
Bool getBool(const TableExprId &id)
'get' Functions to get the desired result of a function
static std::pair< int, int > getMVFormat(const String &fmt)
Get the MVTime/Angle format and optional precision.
Int64 getInt(const TableExprId &id)
Class to connect a Table and its alias name.
Abstract base class for a node having multiple child nodes.
std::vector< TENShPtr > operands_p
const Unit & unit() const
Get the unit.
NodeDataType
Define the data types of a node.
ValueType
Define the value types.
this file contains all the compiler specific defines
Definition mainpage.dox:28
LatticeExprNode acos(const LatticeExprNode &expr)
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode cos(const LatticeExprNode &expr)
double Double
Definition aipstype.h:53