casa
$Rev:20696$
|
00001 //# ScalarQuantColumn.h: Access to a Scalar Quantum Column in a table. 00002 //# Copyright (C) 1997,1998,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: ScalarQuantColumn.h 21298 2012-12-07 14:53:03Z gervandiepen $ 00027 00028 #ifndef MEASURES_SCALARQUANTCOLUMN_H 00029 #define MEASURES_SCALARQUANTCOLUMN_H 00030 00031 //# Includes 00032 #include <casa/Quanta/Quantum.h> 00033 00034 namespace casa { //# NAMESPACE CASA - BEGIN 00035 00036 //# Forward Declarations 00037 class Table; 00038 template <class T> class ScalarColumn; 00039 class String; 00040 class Unit; 00041 00042 00043 // <summary> 00044 // Provides read-only access to Scalar Quantum Columns in Tables. 00045 // </summary> 00046 00047 // <use visibility=export> 00048 00049 // <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableQuantum.cc"> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 //# Classes you should understand before using this one. 00054 // <li> <linkto class=TableQuantumDesc>TableQuantumDesc</linkto> 00055 // <li> <linkto class=Table>Table</linkto> 00056 // <li> <linkto class=ScalarColumn>ScalarColumn</linkto> 00057 // <li> <linkto class=Quantum>Quantum</linkto> 00058 // </prerequisite> 00059 00060 // <synopsis> 00061 // The ROScalarQuantColumn class provides read-only access to quanta 00062 // stored in a scalar Quantum Table column. The Quantum column should 00063 // already exist in the table and would have been defined by means of a 00064 // <linkto class=TableQuantumDesc>TableQuantumDesc object</linkto>. 00065 // In addition, 00066 // for a ROScalarQuantColumn object to be useful the column should 00067 // contain Quanta. Inserting Quanta into a column requires the use of a 00068 // <linkto class=ScalarQuantColumn">ScalarQuantColumn</linkto> 00069 // object.<br> 00070 // 00071 // A ROScalarQuantColumn object is used much in the same way as a 00072 // <linkto class=ScalarColumn>ScalarColumn</linkto> object. 00073 // 00074 // <h3>Quantum Units</h3></A> 00075 // Quanta retrieved from the column will normally have the Unit that was 00076 // specified when the Quantum column was defined. 00077 // However, it is possible to override the default column Unit by 00078 // supplying a Unit in the ROScalarQuantColumn constructor. 00079 // When constructed in this fashion the retrieved Quanta will by 00080 // default be retrieved in this unit, i.e. they will by default be 00081 // converted to this unit. 00082 // <br> 00083 // By giving a unit (as a Unit or Quantum object) to a get function, 00084 // the data can be retrieved in another unit than the default. 00085 // </synopsis> 00086 00087 // <example> 00088 // <srcblock> 00089 // Quantum<Double> q(5.3, "keV"); 00090 // // "QuantScalar" has previously been defined as a Quantum column 00091 // // by means of a TableQuantumDesc. This example assumes the column 00092 // // already contains quanta. 00093 // ROScalarQuantColumn<Double> qCol(qtab, "QuantScalar"); 00094 // // return and print quanta as stored in the column 00095 // for (i = 0; i < qtab.nrow(); i++) { 00096 // cout << qCol(i) << endl; 00097 // } 00098 // // The following retrieves and converts the quanta to GHz. They 00099 // // are then divided by the Quantum constant QC::h (Planck). 00100 // for (i=0; i < qtab.nrow(); i++) { 00101 // cout << (qCol(i, "GHz"))/(QC::h); 00102 // } 00103 // </srcblock> 00104 // </example> 00105 00106 // <motivation> 00107 // Add support for Quanta in the Tables system. 00108 // </motivation> 00109 00110 // <thrown> 00111 // <li>TableInvOper if the Table column is null. 00112 // </thrown> 00113 00114 // <todo asof="$DATE:$"> 00115 //# A List of bugs, limitations, extensions or planned refinements. 00116 // <li> Functions like getColumn 00117 // </todo> 00118 00119 00120 template<class T> class ROScalarQuantColumn 00121 { 00122 public: 00123 // The default constructor creates a null object. It is useful for creating 00124 // arrays of ROScalarQuantColumn objects. Attempting to use a null object 00125 // will produce a segmentation fault so care needs to be taken to 00126 // initialise the objects by using the attach() member before any attempt 00127 // is made to use the object. The isNull() member can be used to test 00128 // if a ROScalarQuantColumn object is null. 00129 ROScalarQuantColumn(); 00130 00131 // Create the ROScalarQuantColumn from the specified table and column name. 00132 // The default unit for data retrieved is the unit in which they were stored. 00133 ROScalarQuantColumn (const Table& tab, const String& columnName); 00134 00135 // Create the ROScalarQuantColumn from the specified table and column name. 00136 // The default unit for data retrieved is the given unit (the data is 00137 // converted as needed). 00138 ROScalarQuantColumn (const Table& tab, const String& columnName, 00139 const Unit&); 00140 00141 // Copy constructor (copy semantics). 00142 ROScalarQuantColumn (const ROScalarQuantColumn<T>& that); 00143 00144 ~ROScalarQuantColumn(); 00145 00146 // Change the reference to another column. 00147 void reference (const ROScalarQuantColumn<T>& that); 00148 00149 // Attach a column to the object. Optionally supply a default unit 00150 // which has the same meaning as the constructor unit argument. 00151 // <group name="attach"> 00152 void attach (const Table& tab, const String& columnName); 00153 void attach (const Table& tab, const String& columnName, const Unit&); 00154 // </group> 00155 00156 // Get the quantum stored in the specified row. 00157 // <group name="get"> 00158 void get (uInt rownr, Quantum<T>& q) const; 00159 // Get the quantum in the specified row, converted to the given unit. 00160 void get (uInt rownr, Quantum<T>& q, const Unit&) const; 00161 // Get the quantum in the specified row, converted to the unit in other. 00162 void get (uInt rownr, Quantum<T>& q, const Quantum<T>& other) const; 00163 // </group> 00164 00165 // Return the quantum stored in the specified row. 00166 // <group> 00167 Quantum<T> operator() (uInt rownr) const; 00168 // Return the quantum stored in the specified row, converted to the 00169 // given unit. 00170 Quantum<T> operator() (uInt rownr, const Unit&) const; 00171 // Return the quantum in the specified row, converted to the unit in 00172 // other. 00173 Quantum<T> operator() (uInt rownr, const Quantum<T>& other) const; 00174 // </group> 00175 00176 // Test whether the Quantum column has variable units 00177 Bool isUnitVariable() const 00178 { return (itsUnitsCol != 0); } 00179 00180 // Returns the column's value for Units as a string. 00181 // An empty string is returned if the column has variable units. 00182 const String& getUnits() const 00183 { return itsUnit.getName(); } 00184 00185 // Test if the object is null. 00186 Bool isNull() const 00187 { return (itsDataCol == 0); } 00188 00189 // Throw an exception if the object is null. 00190 void throwIfNull() const; 00191 00192 protected: 00193 //# Quantum column's units (if units not variable) 00194 Unit itsUnit; 00195 00196 // Get access to itsUnitsCol. 00197 const ScalarColumn<String>* unitsCol() const 00198 { return itsUnitsCol; } 00199 00200 private: 00201 //# The underlying data column stores the quantum column's data. 00202 ScalarColumn<T>* itsDataCol; 00203 //# Variable units column if applicable. 00204 ScalarColumn<String>* itsUnitsCol; 00205 //# Unit to retrieve the data in. 00206 Unit itsUnitOut; 00207 //# Convert unit when getting data? 00208 Bool itsConvOut; 00209 00210 00211 // Assignment makes no sense in a read only class. 00212 // Declaring this operator private makes it unusable. 00213 ROScalarQuantColumn& operator= (const ROScalarQuantColumn<T>& that); 00214 00215 // Comparison is not defined, since its semantics are unclear. 00216 Bool operator== (const ROScalarQuantColumn<T>& that); 00217 00218 // Initialize the ROScalarQuantColumn from the specified table and column. 00219 void init (const Table& tab, const String& columnName); 00220 00221 // Deletes allocated memory etc. Called by destructor and any member 00222 // which needs to reallocate data. 00223 void cleanUp(); 00224 00225 // Get the data without possible conversion. 00226 void getData (uInt rownr, Quantum<T>& q) const; 00227 }; 00228 00229 00230 00231 // <summary> 00232 // Provides read/write access to Scalar Quantum Columns in Tables. 00233 // </summary> 00234 00235 // <use visibility=export> 00236 00237 // <reviewed reviewer="Bob Garwood" date="1999/12/23" tests="tTableQuantum.cc"> 00238 // </reviewed> 00239 00240 // <prerequisite> 00241 // <li> <linkto class=TableQuantumDesc>TableQuantumDesc</linkto> 00242 // <li> <linkto class=Table>Table</linkto> 00243 // <li> <linkto class=ScalarColumn>ScalarColumn</linkto> 00244 // <li> <linkto class=Quantum>Quantum</linkto> 00245 // </prerequisite> 00246 00247 // <synopsis> 00248 // The ScalarQuantColumn class provides read/write access to Quanta 00249 // stored in a Quantum Table column. The column should previously have 00250 // been defined as a Quantum column by means of the 00251 // <linkto class=TableQuantumDesc>TableQuantumDesc</linkto> object. 00252 // In addition to the operations provided by its read-only partner, 00253 // <linkto class=ROScalarQuantColumn>ROScalarQuantColumn</linkto>, use 00254 // of a ScalarQuantColumn object allows the insertion of Quanta into a column. 00255 // <br> 00256 // 00257 // <h3>Quantum Units</h3></A> 00258 // The underlying Quantum column will have been defined to have either 00259 // variable or fixed Units. 00260 // If the Quantum column's Unit is fixed then writing quanta converts 00261 // the data to that unit. If the column's unit is variable, the data is 00262 // written unconverted and the unit is written into the unit column 00263 // defined in the TableQuantumDesc object. 00264 // </synopsis> 00265 00266 // <example> 00267 // <srcblock> 00268 // Quantum<Double> q(5.3, "keV"); 00269 // // "QuantScalar" has previously been defined as a Quantum column 00270 // // by means of a TableQuantumDesc. 00271 // ScalarQuantColumn<Double> qCol(qtab, "QuantScalar"); 00272 // for (uInt i=0; i < qtab.nrow(); i++) { 00273 // qCol.put(i, q); 00274 // } 00275 // </srcblock> 00276 // </example> 00277 00278 // <motivation> 00279 // Add support for Quanta in the Tables system. 00280 // </motivation> 00281 // 00282 // <thrown> 00283 // <li>TableInvOper if the Table column is null. 00284 // </thrown> 00285 00286 // <todo asof="$DATE:$"> 00287 //# A List of bugs, limitations, extensions or planned refinements. 00288 // <li> Functions like putColumn 00289 // </todo> 00290 00291 00292 template<class T> class ScalarQuantColumn : public ROScalarQuantColumn<T> 00293 { 00294 public: 00295 // The default constructor creates a null object. Useful for creating 00296 // arrays of ScalarQuantColumn objects. Attempting to use a null object 00297 // will produce a segmentation fault so care needs to be taken to 00298 // initialise the objects by using the attach() member before any attempt 00299 // is made to use the object. The isNull() member can be used to test 00300 // if a ScalarQuantColumn object is null. 00301 ScalarQuantColumn(); 00302 00303 // Create the ROScalarQuantColumn from the specified table and column name. 00304 // The default unit for data retrieved is the unit in which they were stored. 00305 ScalarQuantColumn (const Table& tab, const String& columnName); 00306 00307 // Copy constructor (copy semantics). 00308 ScalarQuantColumn (const ScalarQuantColumn<T>& that); 00309 00310 ~ScalarQuantColumn(); 00311 00312 // Change the reference to another column. 00313 void reference (const ScalarQuantColumn<T>& that); 00314 00315 // Attach a column to the object. 00316 // <group name="attach"> 00317 void attach (const Table& tab, const String& columnName); 00318 // </group> 00319 00320 // Put a quantum into the table. If the column supports variable units 00321 // the q's unit is stored into the unit column defined in the 00322 // TableQuantumDesc object. If units are fixed for the column, the 00323 // quantum is converted as needed. 00324 void put (uInt rownr, const Quantum<T>& q); 00325 00326 private: 00327 //# The underlying data column stores the quantum column's data. 00328 ScalarColumn<T>* itsDataCol; 00329 //# Variable units column if applicable. 00330 ScalarColumn<String>* itsUnitsCol; 00331 00332 00333 // Assignment facility offered via reference() member. 00334 // Declaring this operator private makes it unusable. 00335 ScalarQuantColumn& operator= (const ScalarQuantColumn<T>& that); 00336 00337 // Comparison is not defined, since its semantics are unclear. 00338 Bool operator== (const ScalarQuantColumn<T>& that); 00339 00340 // Deletes allocated memory etc. Called by destructor and any member 00341 // which needs to reallocate data. 00342 void cleanUp(); 00343 00344 //# Make members of parent class known. 00345 protected: 00346 using ROScalarQuantColumn<T>::unitsCol; 00347 using ROScalarQuantColumn<T>::itsUnit; 00348 }; 00349 00350 00351 00352 00353 } //# NAMESPACE CASA - END 00354 00355 #ifndef CASACORE_NO_AUTO_TEMPLATES 00356 #include <measures/TableMeasures/ScalarQuantColumn.tcc> 00357 #endif //# CASACORE_NO_AUTO_TEMPLATES 00358 #endif