casacore
ExprFuncNodeArray.h
Go to the documentation of this file.
1 //# ExprFuncNodeArray.h: Class representing an array function in table select expression
2 //# Copyright (C) 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: 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: ExprFuncNodeArray.h 21277 2012-10-31 16:07:31Z gervandiepen $
27 
28 #ifndef TABLES_EXPRFUNCNODEARRAY_H
29 #define TABLES_EXPRFUNCNODEARRAY_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/TaQL/ExprNodeArray.h>
34 #include <casacore/tables/TaQL/ExprFuncNode.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 
40 
41 // <summary>
42 // Class representing an array 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=TableExprFuncNode>TableExprFuncNode</linkto>
52 // <li> <linkto class=TableExprNodeArray>TableExprNodeArray</linkto>
53 // </prerequisite>
54 
55 // <synopsis>
56 // This class can be seen as a specialization of TableExprFuncNode
57 // for functions returning arrays.
58 // However, it is derived from TableExprNodeArray to make it possible
59 // that the ExprNode classes use all array functionality offered by
60 // that base class.
61 // <br>Internally an TableExprFuncNode object is used.
62 // <p>
63 // When a TaQL function is used, TableExprFuncNode::checkOperands
64 // determines whether the result is a scalar or an array.
65 // Thereafter TableExprNode::newFunctionNode creates a TableExprFuncNode
66 // for scalars or a TableExprFuncNodeArray for arrays.
67 // </synopsis>
68 
69 
71 {
72 public:
73  // Constructor
76  const TableExprNodeSet& source,
77  const TaQLStyle&);
78 
79  // Destructor
81 
82  // Get the nodes representing an aggregate function.
83  virtual void getAggrNodes (vector<TableExprNodeRep*>& aggr);
84 
85  // Get the nodes representing a table column.
86  virtual void getColumnNodes (vector<TableExprNodeRep*>& cols);
87 
88  // 'get' Functions to get the desired result of a function
89  // <group>
90  virtual MArray<Bool> getArrayBool (const TableExprId& id);
91  virtual MArray<Int64> getArrayInt (const TableExprId& id);
92  virtual MArray<Double> getArrayDouble (const TableExprId& id);
93  virtual MArray<DComplex> getArrayDComplex (const TableExprId& id);
94  virtual MArray<String> getArrayString (const TableExprId& id);
95  virtual MArray<MVTime> getArrayDate (const TableExprId& id);
96  // </group>
97 
98  // Get the function node.
100  { return &node_p; }
102  { return &node_p; }
103 
104  // Link the children to the node and convert the children
105  // to constants if possible. Also convert the node to
106  // constant if possible.
109  const Block<Int>& dtypeOper);
110 
111 protected:
112  // Try if the function gives a constant result.
113  // If so, set the expression type to Constant.
114  void tryToConst();
115 
116  // Some functions to be used by TableExprNodeFuncArray.
117  // <group>
119  { return node_p.operands(); }
121  { return node_p.rwOperands(); }
123  { return node_p.funcType(); }
125  { return node_p.argDataType(); }
126  // </group>
127 
128 private:
129  // Set unit scale factor (needed for sqrt).
130  void setScale (Double scale)
131  { node_p.setScale (scale); }
132 
133  // Get the collapse axes for the partial functions.
134  // It compares the values with the #dim and removes them if too high.
135  // axarg gives the argument nr of the axes.
136  IPosition getAxes (const TableExprId& id,
137  Int ndim, uInt axarg=1, Bool swapRemove=True);
138 
139  // Remove axes exceeding ndim.
140  IPosition removeAxes (const IPosition& axes, Int ndim) const;
141 
142  // Get the shape for the array function.
143  // axarg gives the argument nr of the shape.
144  const IPosition& getArrayShape (const TableExprId& id, uInt axarg=1);
145 
146  // Get the transpose order of the array axes.
147  IPosition getOrder (const TableExprId& id, Int ndim);
148 
149  // Get the arguments for the diagonals function.
150  // They are checked and if needed adapted if the shape is not empty.
151  const IPosition& getDiagonalArg (const TableExprId& id,
152  const IPosition& shp);
153 
154  // Set the alternate value expandAlt_p for array expand and return it.
155  const IPosition& getAlternate (const TableExprId& id);
156 
157  // Templated fucntion to resize/expand an array.
158  template<typename T>
159  MArray<T> TEFResize (const MArray<T>& arr, const TableExprId& id);
160 
161 
162  //# Data members
164  Int origin_p; //# axes origin
165  Bool isCOrder_p; //# axes order
166  Bool constAxes_p; //# True = collapse axes are constant
167  Bool constAlt_p; //# True = expandAlt_p is constant
168  IPosition ipos_p; //# the (maybe constant) axes or shape
169  IPosition iposN_p; //# the non-reversed axes or shape
170  IPosition expandAlt_p; //# alternate for expand/resize
171 };
172 
173 
174 
175 
176 } //# NAMESPACE CASACORE - END
177 
178 #endif
const IPosition & getAlternate(const TableExprId &id)
Set the alternate value expandAlt_p for array expand and return it.
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
IPosition getAxes(const TableExprId &id, Int ndim, uInt axarg=1, Bool swapRemove=True)
Get the collapse axes for the partial functions.
Class representing a function in table select expression.
Definition: ExprFuncNode.h:76
int Int
Definition: aipstype.h:50
PtrBlock< TableExprNodeRep * > & rwOperands()
Class representing an array function in table select expression.
void setScale(Double scale)
Set unit scale factor (needed for sqrt).
Int ndim() const
Get the fixed dimensionality (same for all rows).
Definition: ExprNodeRep.h:733
Class to hold multiple table expression nodes.
Definition: ExprNodeSet.h:306
static TableExprNodeRep * fillNode(TableExprFuncNodeArray *thisNode, PtrBlock< TableExprNodeRep *> &nodes, const Block< Int > &dtypeOper)
Link the children to the node and convert the children to constants if possible.
const TableExprFuncNode * getChild() const
void setScale(Double scale)
Set unit scale factor (needed for sqrt).
Definition: ExprFuncNode.h:368
PtrBlock< TableExprNodeRep * > & rwOperands()
Definition: ExprFuncNode.h:379
Base class for arrays in table select expression.
Definition: ExprNodeArray.h:65
NodeDataType
Define the data types of a node.
Definition: ExprNodeRep.h:155
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:151
const PtrBlock< TableExprNodeRep * > & operands() const
Some functions to be used by TableExprNodeFuncArray.
Definition: ExprFuncNode.h:377
FunctionType funcType() const
Definition: ExprFuncNode.h:381
virtual MArray< DComplex > getArrayDComplex(const TableExprId &id)
The default implementation of getArrayDComplex does getArrayDouble and converts the result...
TableExprFuncNode::FunctionType funcType() const
TableExprFuncNodeArray(TableExprFuncNode::FunctionType, NodeDataType, ValueType, const TableExprNodeSet &source, const TaQLStyle &)
Constructor.
virtual MArray< Int64 > getArrayInt(const TableExprId &id)
double Double
Definition: aipstype.h:55
virtual void getColumnNodes(vector< TableExprNodeRep *> &cols)
Get the nodes representing a table column.
Class with static members defining the TaQL style.
Definition: TaQLStyle.h:64
NodeDataType argDataType() const
Definition: ExprFuncNode.h:383
virtual void getAggrNodes(vector< TableExprNodeRep *> &aggr)
Get the nodes representing an aggregate function.
virtual MArray< Bool > getArrayBool(const TableExprId &id)
&#39;get&#39; Functions to get the desired result of a function
const PtrBlock< TableExprNodeRep * > & operands() const
Some functions to be used by TableExprNodeFuncArray.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual MArray< String > getArrayString(const TableExprId &id)
ValueType
Define the value types.
Definition: ExprNodeRep.h:170
const IPosition & getDiagonalArg(const TableExprId &id, const IPosition &shp)
Get the arguments for the diagonals function.
A drop-in replacement for Block<T*>.
Definition: Block.h:861
TableExprFuncNode * getChild()
Get the function node.
The identification of a TaQL selection subject.
Definition: TableExprId.h:98
void tryToConst()
Try if the function gives a constant result.
IPosition getOrder(const TableExprId &id, Int ndim)
Get the transpose order of the array axes.
const IPosition & getArrayShape(const TableExprId &id, uInt axarg=1)
Get the shape for the array function.
IPosition removeAxes(const IPosition &axes, Int ndim) const
Remove axes exceeding ndim.
virtual MArray< MVTime > getArrayDate(const TableExprId &id)
const Bool True
Definition: aipstype.h:43
this file contains all the compiler specific defines
Definition: mainpage.dox:28
virtual MArray< Double > getArrayDouble(const TableExprId &id)
The default implementation of getArrayDouble does getArrayInt and converts the result.
MArray< T > TEFResize(const MArray< T > &arr, const TableExprId &id)
Templated fucntion to resize/expand an array.
unsigned int uInt
Definition: aipstype.h:51