ScalarMeasColumn.h

Classes

ROScalarMeasColumn -- Read only access to table scalar Measure columns. (full description)
ScalarMeasColumn -- Read write access to table scalar Measure columns. (full description)

template <class M> class ROScalarMeasColumn : public ROTableMeasColumn

Interface

Public Members
ROScalarMeasColumn()
ROScalarMeasColumn (const Table& tab, const String& columnName)
ROScalarMeasColumn (const ROScalarMeasColumn<M>& that)
virtual ~ROScalarMeasColumn()
void reference (const ROScalarMeasColumn<M>& that)
void attach (const Table& tab, const String& columnName)
void get (uInt rownr, M& meas) const
M operator() (uInt rownr) const
M convert (uInt rownr, const M& meas) const
M convert (uInt rownr, const MeasRef<M>& measRef) const
M convert (uInt rownr, uInt refCode) const
const MeasRef<M>& getMeasRef() const
Protected Members
MeasRef<M> makeMeasRef (uInt rownr) const
Private Members
ROScalarMeasColumn& operator= (const ROScalarMeasColumn<M>& that)
void cleanUp()

Description

Review Status

Reviewed By:
Bob Garwood
Date Reviewed:
1999/12/23
Programs:
Tests:

Prerequisite

Synopsis

ROScalarMeasColumn and ScalarMeasColumn objects can be used to access Scalar Measure Columns in tables. The ROScalarMeasColumn provides read only access whereas the ScalarMeasColumn object can be used for writing and reading of Measures to and from a Table column.

Before a column can be accessed it must have previously been defined as a Measure column by use of the TableMeasDesc object.

The (RO)ScalarMeasColumn class is templated on Measure type. Typedefs exist in the various Measure classes (e.g. MEpoch) to make declaration less long winded. Constructing scalar Measure column objects using these typedefs looks like this:

    MEpoch::ScalarMeasColumn ec(table, "ColumnName);
    MDoppler::ROScalarMeasColumn dc(table, "DopplerCol");
    

Reading and writing Measures

The reading and writing of Measures columns is very similar to reading and writing of "ordinary" Table columns. get() and operator() exist for reading Measures and the put() member for adding Measures to a column. (put() is obviously not defined for ROScalarMeasColumn objects.) Each of these members accepts a row number as an argument. The get() function gets the measure with the reference and offset as it is stored in the column. Furthermore the convert() function is available to get the measure with the given reference, possible offset, and possible frame

When a Measure is put, the reference and possible offset are converted if the measure column is defined with a fixed reference and/or offset. If the column's reference and offset are variable, the reference and offset of the measure as put are written into the appropriate reference and offset columns.

Example

     // This creates a Scalar MEpoch column for read/write access.  Column
     // "Time1" must exist in Table "tab" and must have previously been
     // defined as a MEpoch column using a TableMeasDesc.
     MEpoch::ScalarMeasColumn timeCol(tab, "Time1");
 	
     // print some details about the column
     if (timeCol.isRefVariable()) {
        cout << "The column has variable references." << endl;
     } else {
         cout << "The fixed MeasRef for the column is: "
	        << timeCol.getMeasRef() << endl;
     }

     // Add tab.nrow() measures to the column.	
     MEpoch tm(Quantity(MeasData::MJD2000, "d"), MEpoch::TAI);
     for (uInt i=0; i<tab.nrow(); i++) {
         timeCol.put(i, tm);
     }

     // We could read from the column using timeCol but instead a read
     // only column object is created.
     MEpoch::ROScalarMeasColumn timeColRead(tab, "Time1");
     for (i=0; i<tab.nrow(); i++) {
         cout << timeColRead(i) << endl;
     }

Motivation

The standard Aips++ Table system does not support Measures columns. This class overcomes this limitation.

Thrown Exceptions

Member Description

ROScalarMeasColumn()

The default constructor creates a null object. Useful for creating arrays of ROScalarMeasColumn objects. Attempting to use a null object will produce a segmentation fault so care needs to be taken to initialize the objects first by using attach(). An ROScalarMeasColumn object can be tested if it is null by using the isNull() member.

ROScalarMeasColumn (const Table& tab, const String& columnName)

Create the ScalarMeasColumn from the table and column Name.

ROScalarMeasColumn (const ROScalarMeasColumn<M>& that)

Copy constructor (copy semantics).

virtual ~ROScalarMeasColumn()

void reference (const ROScalarMeasColumn<M>& that)

Change the reference to another column.

void attach (const Table& tab, const String& columnName)

Attach a column to the object.

void get (uInt rownr, M& meas) const
M operator() (uInt rownr) const

Get the Measure contained in the specified row. It returns the Measure as found in the table.

M convert (uInt rownr, const M& meas) const

Get the Measure contained in the specified row and convert it to the reference and offset found in the given measure.

M convert (uInt rownr, const MeasRef<M>& measRef) const
M convert (uInt rownr, uInt refCode) const

Get the Measure contained in the specified row and convert it to the given reference.

const MeasRef<M>& getMeasRef() const

Returns the column's fixed reference or the reference of the last read Measure if references are variable.

MeasRef<M> makeMeasRef (uInt rownr) const

Make a MeasRef for the given row.

ROScalarMeasColumn& operator= (const ROScalarMeasColumn<M>& that)

Assignment makes no sense in a readonly class. Declaring this operator private makes it unusable.

void cleanUp()


template <class M> class ScalarMeasColumn : public ROScalarMeasColumn<M>

Interface

Public Members
ScalarMeasColumn()
ScalarMeasColumn (const Table& tab, const String& columnName)
ScalarMeasColumn (const ScalarMeasColumn<M>& that)
virtual ~ScalarMeasColumn()
void reference (const ScalarMeasColumn<M>& that)
void attach (const Table& tab, const String& columnName)
void setDescRefCode (uInt refCode, Bool tableMustBeEmpty=True)
void setDescOffset (const Measure& offset, Bool tableMustBeEmpty=True)
void setDescUnits (const Vector<Unit>& units, Bool tableMustBeEmpty=True)
void put (uInt rownr, const M& meas)
Private Members
ScalarMeasColumn& operator= (const ScalarMeasColumn<M>& that)
Bool equalRefs (const MRBase& r1, const MRBase& r2) const
void cleanUp()

Description

Review Status

Reviewed By:
Bob Garwood
Date Reviewed:
1999/12/23
Programs:
Tests:
  • tTableMeasures.cc

Synopsis

See description for ROScalarMeasColumn.

Member Description

ScalarMeasColumn()

The default constructor creates a null object. Useful for creating arrays of ScalarMeasColumn objects. Attempting to use a null object will produce a segmentation fault so care needs to be taken when initializing a null object by using the attach() member before any attempt is made to use it. A ScalarMeasColumn object can be tested if it is null by using the isNull() member.

ScalarMeasColumn (const Table& tab, const String& columnName)

Create the ScalarMeasColumn from the table and column Name.

ScalarMeasColumn (const ScalarMeasColumn<M>& that)

Copy constructor (copy semantics).

virtual ~ScalarMeasColumn()

void reference (const ScalarMeasColumn<M>& that)

Change the column reference to another column.

void attach (const Table& tab, const String& columnName)

Attach a column to the object.

void setDescRefCode (uInt refCode, Bool tableMustBeEmpty=True)
void setDescOffset (const Measure& offset, Bool tableMustBeEmpty=True)
void setDescUnits (const Vector<Unit>& units, Bool tableMustBeEmpty=True)

Reset the refCode, offset, or units. It overwrites the value used when defining the TableMeasDesc. Resetting the refCode and offset can only be done if they were defined as fixed in the description.

Tip In principle the functions can only be used if the table is empty, otherwise already written values have thereafter the incorrect reference, offset, or unit. However, it is possible that part of the table is already written and that the entire measure column is filled in later. In that case the reference, offset, or units can be set by using a False tableMustBeEmpty argument.

void put (uInt rownr, const M& meas)

Put a Measure into the given row.

ScalarMeasColumn& operator= (const ScalarMeasColumn<M>& that)

Declaring this operator private makes it unusable. See class ScalarColumn for an explanation as to why this operation is disallowed. Use the reference function instead.

Bool equalRefs (const MRBase& r1, const MRBase& r2) const

Check if refs have the same value (as opposed to being the same object).

void cleanUp()