GlishRecordExpr.h

Classes

GlishRecordExpr -- Filter GlishRecords using a TaQL expression. (full description)

class GlishRecordExpr : public TableExprData

Interface

Public Members
GlishRecordExpr (const GlishRecord& proto, const String& expr)
GlishRecordExpr (const Record& proto, const TableExprNode& expr)
GlishRecordExpr (const Record& proto, const String& expr)
GlishRecordExpr (const GlishRecordExpr&)
virtual ~GlishRecordExpr()
GlishRecordExpr& operator= (const GlishRecordExpr&)
Bool matches (const GlishRecord& record)
virtual Bool getBool (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<Bool> getArrayBool (const Block<Int>& fieldNrs) const
virtual Array<Double> getArrayDouble (const Block<Int>& fieldNrs) const
virtual Array<DComplex> getArrayDComplex (const Block<Int>& fieldNrs) const
virtual Array<String> getArrayString (const Block<Int>& fieldNrs) const
virtual IPosition shape (const Block<Int>& fieldNrs) const
virtual DataType dataType (const Block<Int>& fieldNrs) const
Private Members
GlishArray getValue (const Block<Int>& fieldNrs) const

Description

Review Status

Programs:
Tests:

Prerequisite

Synopsis

This class builds a TaQL expression tree from an expression string and a prototype GlishRecord. See note 199 for a full description of TaQL. Thereafter the matches function can be used to test if a given GlishRecord matches the expression. This function can repreatedly be called for a series of records.

If the record contains subrecords, it is possible to use fields in those subrecords (or subsubrecords, etc.) by specifying all parts of the full field name separated by dots (as shown in the example). Array fields can also be handled in the expression.

The GlishRecord given to the matches function must in principle have the same structure as the prototype record, otherwise bad things (like an exception, or even worse a segmentation fault) can happen when evaulating the expression, because checking would take too much time. However, by using the TaQL function isdefined one can explicitly check if a field is defined and has the data type as defined in the prototype record.

Example

In the following example a block of GlishRecords is matched against an expression.
    void someFunc (const Block<GlishRecord>& recs)
    {
      AlwaysAssert (recs.nelements() > 0, AipsError);
      GlishRecordExpr expr("ant_data.ON_SOURCE", recs[0]);
      for (uInt i=0; i<recs.nelements(); i++) {
        cout << expr.matches (recs[i]) << endl;
      }
    }
    
The following example is the same as above, but uses the isdefined function in the expression to make sure no unexpected things can happen.
    void someFunc (const Block<GlishRecord>& recs)
    {
      AlwaysAssert (recs.nelements() > 0, AipsError);
      GlishRecordExpr expr
          ("isdefined(ant_data.ON_SOURCE) && ant_data.ON_SOURCE", recs[0]);
      for (uInt i=0; i<recs.nelements(); i++) {
        cout << expr.matches (recs[i]) << endl;
      }
    }
    

Member Description

GlishRecordExpr (const GlishRecord& proto, const String& expr)

Construct it from an expression which gets parsed. The proto GlishRecord is used to get a description of the records to be compared with the expression.

GlishRecordExpr (const Record& proto, const TableExprNode& expr)

Construct it from an already created expression tree. The proto Record should be the same as the one used to create the expression (in the GlishRecordExpr (const Record& proto, const String& expr)

Construct it from an expression which gets parsed. The proto Record is used to get a description of the records to be compared with the expression.

GlishRecordExpr (const GlishRecordExpr&)

Copy constructor (copy semantics).

virtual ~GlishRecordExpr()

GlishRecordExpr& operator= (const GlishRecordExpr&)

Assignment (copy semantics).

Bool matches (const GlishRecord& record)

Does this record match the expression? The record must have the same description as the proto record used when constructing the object.

Caution It is not checked if the description is the same, because it is too time-consuming.

virtual Bool getBool (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<Bool> getArrayBool (const Block<Int>& fieldNrs) const
virtual Array<Double> getArrayDouble (const Block<Int>& fieldNrs) const
virtual Array<DComplex> getArrayDComplex (const Block<Int>& fieldNrs) const
virtual Array<String> getArrayString (const Block<Int>& fieldNrs) const

Get a scalar in the given type.

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

Get the shape of the of the given (array) field.

virtual DataType dataType (const Block<Int>& fieldNrs) const

Get the data type of the given field.

GlishArray getValue (const Block<Int>& fieldNrs) const

Get the value of the given field in the subject GlishRecord.