casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TableMeasDescBase.h
Go to the documentation of this file.
00001 //# TableMeasDescBase.h: Definition of a Measure in a Table.
00002 //# Copyright (C) 1997,1999,2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: TableMeasDescBase.h 21298 2012-12-07 14:53:03Z gervandiepen $
00027 
00028 #ifndef MEASURES_TABLEMEASDESCBASE_H
00029 #define MEASURES_TABLEMEASDESCBASE_H
00030 
00031 //# Includes
00032 #include <measures/TableMeasures/TableMeasValueDesc.h>
00033 #include <measures/TableMeasures/TableMeasRefDesc.h>
00034 #include <measures/TableMeasures/TableMeasType.h>
00035 #include <casa/Quanta/Unit.h>
00036 #include <casa/Arrays/Vector.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 class String;
00042 class Table;
00043 class TableDesc;
00044 class TableRecord;
00045 class TableColumn;
00046 class Measure;
00047 template<class T> class Quantum;
00048 
00049 
00050 // <summary>
00051 // Definition of a Measure in a Table.
00052 // </summary>
00053 
00054 // <use visibility=local>
00055 
00056 // <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableMeasures.cc">
00057 // </reviewed>
00058 
00059 // <prerequisite>
00060 //# Classes you should understand before using this one.
00061 //   <li> <linkto module=Measures>Measures</linkto>
00062 //   <li> <linkto module=Tables>Tables</linkto>
00063 //   <li> <linkto class=TableMeasDesc>TableMeasDesc</linkto>
00064 // </prerequisite>
00065 
00066 // <synopsis>
00067 // Abstract base class for TableMeasDesc.
00068 // </synopsis>
00069 
00070 // <example>
00071 // See class <linkto class="TableMeasDesc">TableMeasDesc</linkto>.
00072 // </example>
00073 
00074 // <motivation>
00075 // Creating the required keyword for the definition of a Measure
00076 // in a Table is somewhat complicated. This class assists in that
00077 // process.
00078 // </motivation>
00079 //
00080 // <thrown>
00081 //    <li>AipsError during reconstruction if the column doesn't contain
00082 //        a MEASINFO record.
00083 //    <li>AipsError during reconstruction if the column has a MEASINFO
00084 //        but it Measure type is invalid.
00085 // </thrown>
00086 //
00087 
00088 //# <todo asof="$DATE:$">
00089 //# A List of bugs, limitations, extensions or planned refinements.
00090 //# </todo>
00091 
00092 class TableMeasDescBase
00093 {
00094 public:
00095   // Null constructor.
00096   TableMeasDescBase();
00097 
00098   // Constructor with value and reference descriptors.
00099   // Note that setMeasType is always called by the derived class.
00100   TableMeasDescBase (const TableMeasValueDesc&, const TableMeasRefDesc&);
00101 
00102   // Copy constructor.
00103   TableMeasDescBase (const TableMeasDescBase& that);
00104 
00105   virtual ~TableMeasDescBase();
00106 
00107   // Clone the object.
00108   virtual TableMeasDescBase* clone() const;
00109 
00110   // Assignment operator.
00111   TableMeasDescBase& operator= (const TableMeasDescBase& that);
00112 
00113   // Makes the descriptor persistent.
00114   // <group>
00115   void write (TableDesc&);
00116   void write (Table&);
00117   // </group>
00118 
00119   // Make the descriptor persistent if there was no refcode vector.
00120   // This is only needed for old tables without such vectors.
00121   void writeIfOld (const Table&);
00122 
00123   // Get the name of the underlying column.
00124   const String& columnName() const
00125     { return itsValue.columnName(); }
00126 
00127   // Return the reference code.
00128   uInt getRefCode() const
00129     { return itsRef.getRefCode(); }
00130 
00131   // Returns True if the reference varies per row.
00132   Bool isRefCodeVariable() const
00133     { return itsRef.isRefCodeVariable(); }
00134 
00135   // Returns the name of the ref code column when the ref code is variable.
00136   // The null string is returned if the ref code is not variable.
00137   const String& refColumnName() const
00138     { return itsRef.columnName(); }
00139 
00140   // Returns a reference to its measure reference descriptor.
00141   const TableMeasRefDesc& getRefDesc() const
00142     { return itsRef; }
00143 
00144   // Get the name of the offset column. Empty string is returned if no
00145   // offset.
00146   const String& offsetColumnName() const
00147     { return itsRef.offsetColumnName(); }
00148 
00149   // Returns True if an offset has been defined.
00150   Bool hasOffset() const
00151     { return itsRef.hasOffset(); }
00152 
00153   // Returns True if the offset is variable.
00154   Bool isOffsetVariable() const
00155     { return itsRef.isOffsetVariable(); }
00156 
00157   // Returns True if the offset is variable and is stored in an
00158   // ArrayMeasColumn, i.e., offsets are stored per element.
00159   Bool isOffsetArray() const
00160     { return itsRef.isOffsetArray(); }
00161 
00162   // Returns a reference to the offset.
00163   const Measure& getOffset() const
00164     { return itsRef.getOffset(); }
00165 
00166   // Returns the descriptors measure type as a String.
00167   const String& type() const
00168     { return itsMeasType.type(); }
00169 
00170   // Returns the reference code for this object given a string.  Throws
00171   // an exception if the refString is invalid for this object.
00172   uInt refCode (const String& refString) const
00173     { return itsMeasType.refCode(refString); }
00174 
00175   // Translates the refCode for the descriptors measure type.
00176   const String& refType (uInt refCode) const
00177     { return itsMeasType.refType(refCode); }
00178 
00179   // Return the Units of the Measure values
00180   const Vector<Unit>& getUnits() const
00181     { return itsUnits; }
00182 
00183   // Reset the refCode, offset, or units.
00184   // It overwrites the value used when defining the TableMeasDesc.
00185   // It is only possible if it was defined as fixed for the entire column.
00186   // <group>
00187   void resetRefCode (uInt refCode)
00188     { itsRef.resetRefCode (refCode); }
00189   void resetOffset (const Measure& offset)
00190     { itsRef.resetOffset (offset); }
00191   void resetUnits (const Vector<Unit>& units);
00192   // </group>
00193 
00194   // Reconstructs the object for the given table and column name.
00195   static TableMeasDescBase* reconstruct (const Table& tab,
00196                                          const String& columnName);
00197 
00198   // Does this column contain table measures?
00199   static Bool hasMeasures (const TableColumn& column);
00200 
00201 protected:
00202   // Set the initial reference codes and types in the table.
00203   void initTabRef (const MeasureHolder& measHolder);
00204 
00205   // Set the measure and possible units.
00206   void setMeasUnits (const Measure& meas,
00207                      const Vector<Quantum<Double> >& val,
00208                      const Vector<Unit>& units);
00209 
00210 private:
00211   TableMeasValueDesc itsValue;    //# The measure value column.
00212   TableMeasRefDesc   itsRef;      //# The reference.
00213   //# this gives access to the columns Measure type etc
00214   TableMeasType itsMeasType;
00215   Vector<Unit>  itsUnits;
00216 };
00217 
00218 
00219 
00220 } //# NAMESPACE CASA - END
00221 
00222 #endif