casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TableMeasDesc.h
Go to the documentation of this file.
00001 //# TableMeasDesc.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: TableMeasDesc.h 20229 2008-01-29 15:19:06Z gervandiepen $
00027 
00028 #ifndef MEASURES_TABLEMEASDESC_H
00029 #define MEASURES_TABLEMEASDESC_H
00030 
00031 
00032 //# Includes
00033 #include <measures/TableMeasures/TableMeasDescBase.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 class String;
00039 class Table;
00040 class TableMeasRefDesc;
00041 class TableMeasValueDesc;
00042 
00043 // <summary>
00044 // Definition of a Measure column in a Table.
00045 // </summary>
00046 
00047 // <use visibility=export>
00048 
00049 // <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableMeasures.cc">
00050 // </reviewed>
00051 
00052 // <prerequisite>
00053 //# Classes you should understand before using this one.
00054 //   <li> <linkto module=Measures>Measures</linkto>
00055 //   <li> <linkto module=Tables>Tables</linkto>
00056 // </prerequisite>
00057 
00058 // <synopsis>
00059 // The TableMeasures system was created to add support for Measure
00060 // columns to the AIPS++ Table system.
00061 // Measures are not a fundamental type of the Tables system and hence
00062 // cannot be represented directly.  Instead a Measure column can be created
00063 // with the aid of
00064 // the TableMeasDesc class hierarchy.  The TableMeasDesc class hierarchy
00065 // creates a Measure column by associating some number of fundamental data
00066 // type Table
00067 // columns into a unit.  The associations between these columns
00068 // is represented in the column keywords of each of
00069 // the columns which make up a specific Measure column.
00070 //
00071 // Creating and using Measure columns
00072 // is a three step process:
00073 // <ol>
00074 // <li> For each Measure column some number of columns are defined and added
00075 //      to the Table descriptor.
00076 // <li> A TableMeasDesc object is used to define a (empty) Measure column
00077 //      from the columns created in the first step.
00078 // <li> <linkto class="ScalarMeasColumn">(RO)ScalarMeasColumns</linkto> or
00079 //  <linkto class="ArrayMeasColumn">(RO)ArrayMeasColumns</linkto> objects
00080 //   are used to access the Measure column for the reading and writing
00081 //   of Measures.
00082 // </ol>
00083 //
00084 // Defining a Measure column (that is, steps 1 and 2 above) is the more complex
00085 // operation.  However, for each Measure column it is a once only operation.
00086 // After a Measure column has been created its subsequent use is not
00087 // much different to using "ordinary" Table columns. For information
00088 // on how to use a Measure column see the
00089 // <linkto class="ScalarMeasColumn">(RO)ScalarMeasColumns</linkto> and
00090 // <linkto class="ArrayMeasColumn">(RO)ArrayMeasColumns</linkto> classes.
00091 // <p>
00092 // The TableMeasDesc class hierarchy contains classes for defining each
00093 // component of the Measures to be contained in column.  A
00094 // <linkto class="TableMeasOffsetDesc">TableMeasOffsetDesc</linkto> is used
00095 // to specify the offset component, a
00096 // <linkto class="TableMeasRefDesc">TableMeasRefDesc</linkto> to set up
00097 // the reference code component and a
00098 // <linkto class="TableMeasValueDesc">TableMeasValueDesc</linkto> names the
00099 // column used as the main Measure column through which the
00100 // Measure column is subsequently accessed.
00101 // <br>
00102 // The final step needed to create a Measure column is the creation of a
00103 // TableMeasDesc object whose
00104 // constructor takes a TableMeasValueDesc and (optionally) a
00105 // TableMeasRefDesc.   After construction the TableMeasDesc object's
00106 // write() member is used to make the
00107 // the Measure column persistent within the Table.
00108 // <p>
00109 // The following examples demonstrate the creation of Measure columns using
00110 // the above components.  Further details about each of these components
00111 // is available with each class description.
00112 // <br>
00113 // All examples write the measure description into a TableDesc object,
00114 // i.e. the argument used in the TableMeasDesc::write function is a
00115 // TableDesc object. It is, however, also possible to write them
00116 // into a Table object which is useful if measure columns are added
00117 // to an already existing table (see example 2).
00118 // </synopsis>
00119 
00120 // <example>
00121 //<ol>
00122 // <li> The following creates a MEpoch column with a fixed reference.
00123 // <srcblock>
00124 //    // Need a table to work with.
00125 //    TableDesc td("measureTable_desc", "1", TableDesc::New);
00126 //    td.comment() = "A test of TableMeasures class.";
00127 //
00128 //    // Define a column and add it to the table
00129 //    // The main measure column is always an Array column of type Double
00130 //    ArrayColumnDesc<Double> cdTime("Time", "An MEpoch column");
00131 //    td.addColumn(cdtime);
00132 //
00133 //    // Create the Measure column for an MEpoch.  The MEpoch in
00134 //    // the column has reference code MEpoch::TAI
00135 //    TableMeasRefDesc measRef(MEpoch::TAI);
00136 //    TableMeasValueDesc measVal(td, "Time");
00137 //    TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
00138 //    // write makes the Measure column persistent.
00139 //    mepochCol.write(td);
00140 //
00141 //    // create the table with 5 rows
00142 //    SetupNewTable newtab("MeasuresTable", td, Table::New);
00143 //    Table tab(newtab, 5);
00144 // </srcblock>
00145 
00146 // <li> Same as example above, but for an already existing table.
00147 // <srcblock>
00148 //    // Need a table to work with.
00149 //    TableDesc td("measureTable_desc", "1", TableDesc::New);
00150 //    td.comment() = "A test of TableMeasures class.";
00151 //
00152 //    // Define a column and add it to the table
00153 //    // The main measure column is always an Array column of type Double
00154 //    ArrayColumnDesc<Double> cdTime("Time", "An MEpoch column");
00155 //    td.addColumn(cdtime);
00156 //
00157 //    // create the table with 5 rows
00158 //    SetupNewTable newtab("MeasuresTable", td, Table::New);
00159 //    Table tab(newtab, 5);
00160 //
00161 //    // Create the Measure column for an MEpoch.  The MEpoch in
00162 //    // the column has reference code MEpoch::TAI
00163 //    TableMeasRefDesc measRef(MEpoch::TAI);
00164 //    TableMeasValueDesc measVal(tab.tableDesc(), "Time");
00165 //    TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
00166 //    // write makes the Measure column persistent.
00167 //    mepochCol.write(tab);
00168 // </srcblock>
00169 
00170 // <li> An MEpoch column with a variable reference code with a fixed offset:
00171 // <srcblock>
00172 //    // The following three columns will be used to set up a Scalar MEpoch
00173 //    // column with variable references and offsets.  3 columns are needed.
00174 //    // The "main" column where the MEpoch will be stored
00175 //    ArrayColumnDesc<Double> cdTime("Time", "An MEpoch column");
00176 
00177 //    // Variable (i.e., per row) reference code storage needs a column.
00178 //    // The column type is either Int or String (Int is faster but String
00179 //    // may be useful when browsing the table).  Either a Scalar column or
00180 //    // Array column can be used here dependent on whether a Scalar or
00181 //    // Array Measure column is used and whether in case of an Array Measure
00182 //    // column the reference code has to be variable per array element.
00183 //    ScalarColumnDesc<Int> cdRef("TimeRef", "Reference column for Time");
00184 //
00185 //    // add the columns to the Table decriptor
00186 //    td.addColumn(cdTime);
00187 //    td.addColumn(cdRef);
00188 //
00189 //    // now create the MEpoch column.
00190 //    // want a fixed offset.  Offsets are Measures
00191 //    MEpoch offset(MVEpoch(MVTime(1996, 5, 17), MEpoch::UTC);
00192 //    TableMeasOffsetDesc offsetDesc(offset);
00193 //    // the reference
00194 //    TableMeasRefDesc measRef(td, "TimeRef", offsetDesc);
00195 //    // the value descriptor, create and write the column
00196 //    TableMeasValueDesc measVal(td, "Time");
00197 //    TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
00198 //    mepochCol.write();
00199 //
00200 //    // create the table, etc
00201 //    ...
00202 // </srcblock>
00203 //
00204 // <li> An MEpoch column with a variable reference code and offset
00205 // <srcblock>
00206 //    // Variable (per row storage of) offsets needs its own column. Measure
00207 //    // offsets are Measures therefore a Measure column is needed.
00208 //    ArrayColumnDesc<Double> cdOffset("OffsetCol", "Variable Offset col");
00209 //
00210 //    // A column for the variable reference code
00211 //    ScalarColumnDesc<String> cdRef("RefCol", "Variable reference column");
00212 //
00213 //    // The main (value) column for the Measure column
00214 //    ArrayColumnDesc<Double> cdTime("Time", "MEpoch column");
00215 //
00216 //    // add the column descriptors to the table
00217 //    td.addColumn(cdOffset);
00218 //    td.addColumn(cdRef);
00219 //    td.addColumn(cdTime);
00220 //
00221 //    // Create the Measure column
00222 //
00223 //    // The offset column is itself a Measure column, but write() is not
00224 //    // called
00225 //    TableMeasValueDesc offsetVal(td, "OffsetCol");
00226 //    TableMeasDesc<MEpoch> offset(offsetVal);
00227 //    TableMeasOffsetDesc offsetDesc(offset);
00228 //
00229 //    // the reference
00230 //    TableMeasRefDesc ref(td, "RefCol", offsetDesc);
00231 //
00232 //    // create the Measure column
00233 //    TableMeasValueDesc val(td, "Time");
00234 //    TableMeasDesc<MEpoch> mepochCol(val, ref);
00235 //    mepochCol.write();
00236 
00237 //    // create the table, etc
00238 //    ...
00239 // </srcblock>
00240 //</ol>
00241 // </example>
00242 
00243 // <motivation>
00244 // Creating the required keyword for the definition of a Measure
00245 // in a Table is somewhat complicated. This class assists in that
00246 // process.
00247 // </motivation>
00248 //
00249 // <thrown>
00250 //    <li>AipsError if a reference code string is invalid.
00251 // </thrown>
00252 //
00253 //# <todo asof="$DATE:$">
00254 //# A List of bugs, limitations, extensions or planned refinements.
00255 //# </todo>
00256 
00257 
00258 template<class M> class TableMeasDesc : public TableMeasDescBase
00259 {
00260 public:
00261   // Constructor with measure value descriptor.  The Measure reference for
00262   // the column will be the default reference code for M.  Units for the
00263   // column will be the default for the Measure type.
00264   TableMeasDesc (const TableMeasValueDesc&);
00265 
00266   // Constructor with measure value descriptor and Vector of Units.
00267   // The Measure reference for the column will be the default reference
00268   // code for the Measure type.   Number of Units must be compatible
00269   // with the Measure.
00270   TableMeasDesc (const TableMeasValueDesc&, const Vector<Unit>&);
00271 
00272   // Constructor with value and reference descriptors. Units for the
00273   // column will be the default for Measure type.
00274   TableMeasDesc (const TableMeasValueDesc&, const TableMeasRefDesc&);
00275 
00276   // Constructor with value and reference descriptors and Vector of
00277   // Units. Number of Units must be compatible with the Measure.
00278   TableMeasDesc (const TableMeasValueDesc&, const TableMeasRefDesc&,
00279                  const Vector<Unit>&);
00280 
00281   // Clone the object.
00282   virtual TableMeasDescBase* clone() const;
00283 
00284   // Copy constructor (copy semantics).
00285   TableMeasDesc (const TableMeasDesc<M>& that);
00286 
00287   ~TableMeasDesc();
00288 
00289   // Assignment operator (copy semantics)
00290   TableMeasDesc<M>& operator= (const TableMeasDesc<M>& that);
00291 };
00292 
00293 
00294 
00295 } //# NAMESPACE CASA - END
00296 
00297 #ifndef CASACORE_NO_AUTO_TEMPLATES
00298 #include <measures/TableMeasures/TableMeasDesc.tcc>
00299 #endif //# CASACORE_NO_AUTO_TEMPLATES
00300 #endif