casacore
Public Member Functions | List of all members
casacore::TableExprData Class Referenceabstract

More...

#include <TableExprData.h>

Public Member Functions

 TableExprData ()
 Construct it from a row number. More...
 
virtual ~TableExprData ()
 
virtual IPosition shape (const Block< Int > &fieldNrs) const
 Get the shape of the given field. More...
 
virtual DataType dataType (const Block< Int > &fieldNrs) const =0
 Get the data type of the given field. More...
 
virtual Bool getBool (const Block< Int > &fieldNrs) const
 Get a scalar in the given type. More...
 
virtual Int64 getInt (const Block< Int > &fieldNrs) const
 
virtual Double getDouble (const Block< Int > &fieldNrs) const
 
virtual DComplex getDComplex (const Block< Int > &fieldNrs) const
 
virtual String getString (const Block< Int > &fieldNrs) const
 
virtual Array< BoolgetArrayBool (const Block< Int > &fieldNrs) const
 Get an array in the given type. More...
 
virtual Array< Int64getArrayInt (const Block< Int > &fieldNrs) const
 
virtual Array< DoublegetArrayDouble (const Block< Int > &fieldNrs) const
 
virtual Array< DComplex > getArrayDComplex (const Block< Int > &fieldNrs) const
 
virtual Array< StringgetArrayString (const Block< Int > &fieldNrs) const
 

Detailed Description

Abstract base class for data object in a TaQL expression.

Intended use:

Public interface

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Prerequisite

Synopsis

The Table Query Language (TaQL) is implemented by means of the TableExprNode classes. It is primarily meant to do selection on tables. However, it is also possible to use it for selection on any other set of data resembling tabular data.
An example of such a data set is a set of Record objects. TaQL can be used to select some of those records based on the contents of one or more fields in the records. Note that this example is already directly supported by TaQL.
Another example is when a user has several equally long vectors with data. The vectors can be seen as fields and TaQL can be used to select entries from the vectors. This example requires that this class TableExprData is used.

The TableExprNodeRecordField and TableExprId classes form the means by which TaQL can deal with any set of data.
First the TaQL expression has to be setup. This is done by constructing a TableExprNodeRecordField object for each 'field' to be used in the expression. TableExprNodeRecordField uses a RecordInterface object to make the data type of a field in the data set known and to map a field name to a field index (the index is the sequence number of the field in the record description).
When evaluating the expression for each member in the data set, a TableExprData> needs to be passed (which is automatically converted to TableExprId). So a class needs to be written to access the data in the data set. It needs to be derived from the abstract base class TableExprData defined in this file. An example is given below.

It is also possible that the data set contains records and that the selection is based on fields in those records. In such a case the record passed to TableExprNodeRecordField should contain subrecords representing those records. The field index in the various functions as passed as a Block<Int> to denote the fields in the subrecords (and possibly subsubrecords, etc.. However, normally records won't be used and fieldNrs[0] gives the field index.

Example

This example shows how a data set consisting of two vectors of scalars can be used.

// Write a class derived from TableExprData to handle the vectors.
class MyTestClass : public TableExprData
{
public:
// Constructor checks if both vectors have equal length.
MyTestClass (const Vector<Int>& fld1, const Vector<String>& fld2)
: itsFld1(fld1), itsFld2(fld2), itsEntry(0)
{ AlwaysAssert (fld1.nelements() == fld2.nelements(), AipsError); }
virtual ~MyTestClass()
{}
void next()
{ itsEntry++; }
// Note that only the get functions for the possible types are needed.
// Also note that all numeric types are handled by TaQL as Double.
// The exception should never be thrown unless things are screwed up.
virtual Double getDouble (const Block<Int>& fieldNrs) const
{ switch (fieldNrs[0]) {
case 0:
return itsFld1(itsEntry);
default:
throw AipsError();
}
}
virtual String getString (const Block<Int>& fieldNrs) const
{ switch (fieldNrs[0]) {
case 1:
return itsFld2(itsEntry);
default:
throw AipsError();
}
}
virtual DataType dataType (const Block<Int>& fieldNrs) const
{ switch (fieldNrs[0]) {
case 0:
return TpInt;
case 1:
return TpString;
default:
throw AipsError();
}
}
// Make a Record to give to vectors a name.
// The order in which the fields are defined determines the fieldnrs
// passed to the get functions.
static Record makeRecord()
{ RecordDesc desc;
desc.addField ("fld1", TpInt);
desc.addField ("fld2", TpString);
return Record(desc);
}
private:
Vector<Int> itsFld1;
Vector<String> itsFld2;
uInt itsEntry;
};
Vector<uInt> findMatches (const Vector<Int>& fld1,
const Vector<String>& fld2)
{
// Make some expression.
// First create a Record to make the names and types known.
Record rec(MyTestClass::makeRecord());
TableExprNode expr (makeRecordExpr(rec,"fld1") > 10 &&
makeRecordExpr(rec,"fld2") != pattern("*xxx*"));
// Now evaluate the expression for each entry in the vector.
// Make a MyTestClass object to handle the vectors and put it in
// a TableExprId object for the TaQL evaluator.
// Note that TableExprId holds a pointer to the original MyTestClass
// object, so the TaQL evaluator 'sees' the changes we make by
// using the its next() function.
MyTestClass subj(fld1, fld2);
TableExprId eid(subj);
// The matching entry numbers are stored in a vector.
Vector<uInt> result(fld1.nelements());
uInt nr=0;
Bool valb;
for (uInt i=0; i<fld1.nelements(); i++) {
expr.get (eid, valb);
if (valb) {
result(nr++) = i;
}
subj.next(); // Next time the next entry must be used
}
result.resize (nr, True);
return result;
}
#define AlwaysAssert(expr, exception)
These marcos are provided for use instead of simply using the constructors of assert_ to allow additi...
Definition: Assert.h:157
TableExprData()
Construct it from a row number.
virtual Double getDouble(const Block< Int > &fieldNrs) const
virtual String getString(const Block< Int > &fieldNrs) const
virtual DataType dataType(const Block< Int > &fieldNrs) const =0
Get the data type of the given field.
TableExprNode pattern(const TableExprNode &node)
Definition: ExprNode.h:1487
unsigned int uInt
Definition: aipstype.h:51
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
double Double
Definition: aipstype.h:55

Motivation

This class makes it possible that TaQL can be used in a very versatile way.

Definition at line 202 of file TableExprData.h.

Constructor & Destructor Documentation

◆ TableExprData()

casacore::TableExprData::TableExprData ( )
inline

Construct it from a row number.

Definition at line 206 of file TableExprData.h.

◆ ~TableExprData()

virtual casacore::TableExprData::~TableExprData ( )
virtual

Member Function Documentation

◆ dataType()

virtual DataType casacore::TableExprData::dataType ( const Block< Int > &  fieldNrs) const
pure virtual

Get the data type of the given field.

Note that TpArray types have to be returned for arrays. If the field is unknown, TpOther should be returned. It is used for the isdefined function to check if the field is really defined.

Implemented in casacore::LogFilterExpr.

◆ getArrayBool()

virtual Array<Bool> casacore::TableExprData::getArrayBool ( const Block< Int > &  fieldNrs) const
virtual

Get an array in the given type.

This might involve converting for Double and DComplex. Most default implementations throws an "not possible" exception. The default getArrayDComplex invokes getArrayDouble.

◆ getArrayDComplex()

virtual Array<DComplex> casacore::TableExprData::getArrayDComplex ( const Block< Int > &  fieldNrs) const
virtual

◆ getArrayDouble()

virtual Array<Double> casacore::TableExprData::getArrayDouble ( const Block< Int > &  fieldNrs) const
virtual

◆ getArrayInt()

virtual Array<Int64> casacore::TableExprData::getArrayInt ( const Block< Int > &  fieldNrs) const
virtual

◆ getArrayString()

virtual Array<String> casacore::TableExprData::getArrayString ( const Block< Int > &  fieldNrs) const
virtual

◆ getBool()

virtual Bool casacore::TableExprData::getBool ( const Block< Int > &  fieldNrs) const
virtual

Get a scalar in the given type.

This might involve converting for Double and DComplex. Most default implementations throws an "not possible" exception. The default getDouble invokes getInt. The default getDComplex invokes getDouble.

◆ getDComplex()

virtual DComplex casacore::TableExprData::getDComplex ( const Block< Int > &  fieldNrs) const
virtual

◆ getDouble()

virtual Double casacore::TableExprData::getDouble ( const Block< Int > &  fieldNrs) const
virtual

Reimplemented in casacore::LogFilterExpr.

◆ getInt()

virtual Int64 casacore::TableExprData::getInt ( const Block< Int > &  fieldNrs) const
virtual

◆ getString()

virtual String casacore::TableExprData::getString ( const Block< Int > &  fieldNrs) const
virtual

Reimplemented in casacore::LogFilterExpr.

◆ shape()

virtual IPosition casacore::TableExprData::shape ( const Block< Int > &  fieldNrs) const
virtual

Get the shape of the given field.

Need only be implemented if there are arrays in the data. The default implementation returns an empty IPosition.


The documentation for this class was generated from the following file: