|
casacore
|
#include <UDFBase.h>
Public Types | |
| typedef UDFBase * | MakeUDFObject(const String &functionName) |
| The signature of a global or static member function creating an object of the UDF. | |
Public Member Functions | |
| UDFBase () | |
| Only default constructor is needed. | |
| virtual | ~UDFBase () |
| Destructor. | |
| virtual Bool | getBool (const TableExprId &id) |
| Evaluate the function and return the result. | |
| virtual Int64 | getInt (const TableExprId &id) |
| virtual Double | getDouble (const TableExprId &id) |
| virtual DComplex | getDComplex (const TableExprId &id) |
| virtual String | getString (const TableExprId &id) |
| virtual TaqlRegex | getRegex (const TableExprId &id) |
| virtual MVTime | getDate (const TableExprId &id) |
| virtual MArray< Bool > | getArrayBool (const TableExprId &id) |
| virtual MArray< Int64 > | getArrayInt (const TableExprId &id) |
| virtual MArray< Double > | getArrayDouble (const TableExprId &id) |
| virtual MArray< DComplex > | getArrayDComplex (const TableExprId &id) |
| virtual MArray< String > | getArrayString (const TableExprId &id) |
| virtual MArray< MVTime > | getArrayDate (const TableExprId &id) |
| const String & | getUnit () const |
| Get the unit. | |
| const Record & | getAttributes () const |
| Get the attributes. | |
| virtual void | flattenTree (std::vector< TableExprNodeRep * > &) |
| Flatten the node tree by adding the node and its children to the vector. | |
| void | init (const std::vector< TENShPtr > &arg, const TableExprInfo &tableInfo, const TaQLStyle &) |
| Initialize the function object. | |
| TableExprNodeRep::NodeDataType | dataType () const |
| Get the data type. | |
| Int | ndim () const |
| Get the dimensionality of the results. | |
| const IPosition & | shape () const |
| Get the result shape if the same for all results. | |
| Bool | isConstant () const |
| Tell if the UDF gives a constant result. | |
| Bool | isAggregate () const |
| Tell if the UDF is an aggregate function. | |
| void | disableApplySelection () |
| Do not apply the selection. | |
| void | applySelection (const Vector< rownr_t > &rownrs) |
| If needed, let the UDF re-create column objects for a selection of rows. | |
Static Public Member Functions | |
| static void | registerUDF (const String &name, MakeUDFObject *func) |
| Register the name and construction function of a UDF (thread-safe). | |
| static UDFBase * | createUDF (const String &name, const TaQLStyle &style) |
| Create a UDF object (thread-safe). | |
Protected Member Functions | |
| std::vector< TENShPtr > & | operands () |
| Get the operands. | |
| void | setDataType (TableExprNodeRep::NodeDataType) |
| Set the data type. | |
| void | setNDim (Int ndim) |
| Set the dimensionality of the results. | |
| void | setShape (const IPosition &shape) |
| Set the shape of the results if it is fixed and known. | |
| void | setUnit (const String &unit) |
| Set the unit of the result. | |
| void | setAttributes (const Record &attributes) |
| Set the attributes of the result. | |
| void | setConstant (Bool isConstant) |
| Define if the result is constant (e.g. | |
| void | setAggregate (Bool isAggregate) |
| Define if the UDF is an aggregate function (usually used in GROUPBY). | |
| virtual void | recreateColumnObjects (const Vector< rownr_t > &rownrs) |
| Let a derived class recreate its column objects in case a selection has to be applied. | |
Private Member Functions | |
| virtual void | setup (const Table &table, const TaQLStyle &)=0 |
| Set up the function object. | |
Private Attributes | |
| std::vector< TENShPtr > | itsOperands |
| TableExprNodeRep::NodeDataType | itsDataType |
| Int | itsNDim |
| IPosition | itsShape |
| String | itsUnit |
| Record | itsAttributes |
| Bool | itsIsConstant |
| Bool | itsIsAggregate |
| Bool | itsApplySelection |
Static Private Attributes | |
| static map< String, MakeUDFObject * > | theirRegistry |
| static std::recursive_mutex | theirMutex |
Abstract base class for a user-defined TaQL function
This class makes it possible to add user-defined functions (UDF) to TaQL. A UDF has to be implemented in a class derived from this class and can contain one or more user-defined functions.
A few functions have to be implemented in the class as described below. In this way TaQL can be extended with arbitrary functions, which can be normal functions as well as aggregate functions (often used with GROUPBY).
A UDF is a class derived from this base class. It must contain the following member functions. See also the example below.
| makeObject | a static function to create an object of the UDF class. This function needs to be registered. |
| setup | this virtual function is called after the object has been created. It should initialize the object using the function arguments that can be obtained using the function operands(). The setup function should perform the following:
|
| getXXX | these are virtual get functions for each possible data type. The get functions matching the data types set by the setup function need to be implemented. The get functions have an argument TableExprId defining the table row (or record) for which the function has to be evaluated. If the UDF is an aggregate functions the TableExprId has to be upcasted to an TableExprIdAggr object from which all TableExprId objects in an aggregation group can be retrieved. const vector< TableExprId > & ids(uInt group) const Get the set of TableExprIds for the given group. Definition ExprGroup.h:161 static const TableExprIdAggr & cast(const TableExprId &id) Cast a TableExprId object to TableExprIdAggr. Definition TableExprIdAggr.h:102 const TableExprGroupResult & result() const Get out the aggregation result object. Definition TableExprIdAggr.h:93 |
A UDF has to be made known to TaQL by adding it to the UDF registry with its name and 'makeObject' function. UDFs will usually reside in a shared library that is loaded dynamically. TaQL will load a UDF in the following way:
The following examples show a normal UDF function.
It returns True if the function argument matches 1. It can be seen that it checks if the argument is an integer scalar.
The following example shows an aggregate UDF function. It calculates the sum of the cubes of the values in a group.
More examples of UDF functions can be found in classes UDFMSCal and DirectionUDF.
| casacore::UDFBase::UDFBase | ( | ) |
Only default constructor is needed.
Referenced by createUDF(), casacore::UDFMSCal::makeAnt1Col(), casacore::UDFMSCal::makeAnt1Name(), casacore::UDFMSCal::makeAnt2Col(), casacore::UDFMSCal::makeAnt2Name(), casacore::DirectionUDF::makeAPP(), casacore::UDFMSCal::makeArray(), casacore::DirectionUDF::makeAZEL(), casacore::UDFMSCal::makeAZEL(), casacore::UDFMSCal::makeAZEL1(), casacore::UDFMSCal::makeAZEL2(), casacore::DirectionUDF::makeB1950(), casacore::UDFMSCal::makeBaseline(), casacore::UDFMSCal::makeCorr(), casacore::UDFMSCal::makeDelay(), casacore::UDFMSCal::makeDelay1(), casacore::UDFMSCal::makeDelay2(), casacore::DirectionUDF::makeDIR(), casacore::DirectionUDF::makeDIRCOS(), casacore::DopplerUDF::makeDOPPLER(), casacore::DirectionUDF::makeECL(), casacore::EarthMagneticUDF::makeEMANG(), casacore::EarthMagneticUDF::makeEMLEN(), casacore::EarthMagneticUDF::makeEMXYZ(), casacore::EpochUDF::makeEPOCH(), casacore::UDFMSCal::makeFeed(), casacore::UDFMSCal::makeField(), casacore::UDFMSCal::makeFieldCol(), casacore::FrequencyUDF::makeFREQ(), casacore::DirectionUDF::makeGAL(), casacore::UDFMSCal::makeHA(), casacore::UDFMSCal::makeHA1(), casacore::UDFMSCal::makeHA2(), casacore::DirectionUDF::makeHADEC(), casacore::UDFMSCal::makeHADEC(), casacore::UDFMSCal::makeHADEC1(), casacore::UDFMSCal::makeHADEC2(), casacore::HelpMeasUDF::makeHELP(), casacore::HelpMsCalUDF::makeHELP(), casacore::EarthMagneticUDF::makeIGRFANG(), casacore::EarthMagneticUDF::makeIGRFLEN(), casacore::EarthMagneticUDF::makeIGRFLONG(), casacore::EarthMagneticUDF::makeIGRFLOS(), casacore::EarthMagneticUDF::makeIGRFXYZ(), casacore::DirectionUDF::makeITRF(), casacore::UDFMSCal::makeITRF(), casacore::PositionUDF::makeITRFH(), casacore::PositionUDF::makeITRFLL(), casacore::PositionUDF::makeITRFLLH(), casacore::PositionUDF::makeITRFXYZ(), casacore::DirectionUDF::makeJ2000(), casacore::EpochUDF::makeLAST(), casacore::UDFMSCal::makeLAST(), casacore::UDFMSCal::makeLAST1(), casacore::UDFMSCal::makeLAST2(), casacore::UDFMSCal::makeObs(), casacore::UDFMSCal::makeObsCol(), casacore::UDFMSCal::makePA1(), casacore::UDFMSCal::makePA2(), casacore::UDFMSCal::makePolCol(), casacore::PositionUDF::makePOS(), casacore::UDFMSCal::makeProcCol(), casacore::RadialVelocityUDF::makeRADVEL(), casacore::FrequencyUDF::makeREST(), casacore::DirectionUDF::makeRISESET(), casacore::UDFMSCal::makeScan(), casacore::DirectionUDF::makeSGAL(), casacore::FrequencyUDF::makeSHIFT(), casacore::UDFMSCal::makeSpw(), casacore::UDFMSCal::makeSpwCol(), casacore::UDFMSCal::makeState(), casacore::UDFMSCal::makeStateCol(), casacore::UDFMSCal::makeStokes(), casacore::UDFMSCal::makeSubCol(), casacore::UDFMSCal::makeTime(), casacore::UDFMSCal::makeUVDist(), casacore::UDFMSCal::makeUvwAPP(), casacore::UDFMSCal::makeUvwJ2000(), casacore::UDFMSCal::makeUvwWvl(), casacore::UDFMSCal::makeUvwWvls(), casacore::PositionUDF::makeWGSH(), casacore::PositionUDF::makeWGSLL(), casacore::PositionUDF::makeWGSLLH(), casacore::PositionUDF::makeWGSXYZ(), casacore::UDFMSCal::makeWvlAPP(), casacore::UDFMSCal::makeWvlJ2000(), casacore::UDFMSCal::makeWvlsAPP(), and casacore::UDFMSCal::makeWvlsJ2000().
|
virtual |
Destructor.
If needed, let the UDF re-create column objects for a selection of rows.
It calls the function recreateColumnObjects.
Create a UDF object (thread-safe).
It looks in the map with fixed function names. If unknown, it looks if a wildcarded function name is supported (for PyTaQL).
References casacore::name(), and UDFBase().
|
inline |
|
inline |
Do not apply the selection.
Definition at line 354 of file UDFBase.h.
References casacore::False, and itsApplySelection.
|
virtual |
Flatten the node tree by adding the node and its children to the vector.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Reimplemented in casacore::DirectionUDF.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
inline |
Get the attributes.
Definition at line 269 of file UDFBase.h.
References itsAttributes, and casacore::Record().
|
virtual |
Evaluate the function and return the result.
Their default implementations throw a "not implemented" exception.
Reimplemented in casacore::UDFMSCal.
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
|
virtual |
Reimplemented in casacore::UDFMSCal.
|
virtual |
|
virtual |
Reimplemented in casacore::HelpMeasUDF, casacore::HelpMsCalUDF, and casacore::UDFMSCal.
|
inline |
| void casacore::UDFBase::init | ( | const std::vector< TENShPtr > & | arg, |
| const TableExprInfo & | tableInfo, | ||
| const TaQLStyle & | ) |
Initialize the function object.
References casacore::arg().
|
inline |
Tell if the UDF is an aggregate function.
Definition at line 350 of file UDFBase.h.
References itsIsAggregate.
Referenced by setAggregate().
|
inline |
Tell if the UDF gives a constant result.
Definition at line 346 of file UDFBase.h.
References itsIsConstant.
Referenced by setConstant().
|
inline |
|
inlineprotected |
Get the operands.
Definition at line 282 of file UDFBase.h.
References itsOperands.
Referenced by casacore::UDFMSCal::setupGetValue(), casacore::UDFMSCal::setupSelection(), casacore::UDFMSCal::setupStokes(), and casacore::UDFMSCal::setupWvls().
|
protectedvirtual |
Let a derived class recreate its column objects in case a selection has to be applied.
The default implementation does nothing.
Reimplemented in casacore::UDFMSCal.
|
static |
Register the name and construction function of a UDF (thread-safe).
An exception is thrown if this name already exists with a different construction function.
References casacore::name().
|
protected |
Define if the UDF is an aggregate function (usually used in GROUPBY).
References isAggregate().
|
protected |
Set the attributes of the result.
If this function is not called by the setup function of the derived class, the result has no attributes.
References casacore::Record().
|
protected |
Define if the result is constant (e.g.
if all arguments are constant). If this function is not called by the setup function of the derived class, the result is not constant.
References isConstant().
|
protected |
Set the data type.
This function must be called by the setup function of the derived class.
|
protected |
Set the dimensionality of the results.
0 means that the results are scalars.
-1 means that the results are arrays with unknown dimensionality.
>0 means that the results are arrays with that dimensionality. This function must be called by the setup function of the derived class.
References ndim().
|
protected |
Set the shape of the results if it is fixed and known.
References shape().
|
protected |
Set the unit of the result.
If this function is not called by the setup function of the derived class, the result has no unit.
|
privatepure virtual |
Set up the function object.
Implemented in casacore::DirectionUDF, casacore::DopplerUDF, casacore::EarthMagneticUDF, casacore::EpochUDF, casacore::FrequencyUDF, casacore::HelpMeasUDF, casacore::HelpMsCalUDF, casacore::PositionUDF, casacore::RadialVelocityUDF, and casacore::UDFMSCal.
|
inline |
Get the result shape if the same for all results.
Definition at line 342 of file UDFBase.h.
References itsShape.
Referenced by setShape().
|
private |
Definition at line 376 of file UDFBase.h.
Referenced by disableApplySelection().
|
private |
Definition at line 373 of file UDFBase.h.
Referenced by getAttributes().
|
private |
Definition at line 369 of file UDFBase.h.
Referenced by dataType().
|
private |
Definition at line 375 of file UDFBase.h.
Referenced by isAggregate().
|
private |
Definition at line 374 of file UDFBase.h.
Referenced by isConstant().
|
private |
|
private |
Definition at line 368 of file UDFBase.h.
Referenced by operands().
|
private |
|
private |
|
staticprivate |
|
staticprivate |