casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MSSelectableTable.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //# MSSelectableTable.h: The generic interface for tables that can be used with MSSelection
00003 //# Copyright (C) 1996,1997,1998,1999,2001
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //#
00028 //# $Id$
00029 
00030 #ifndef MS_MSSELECTABLETABLE_H
00031 #define MS_MSSELECTABLETABLE_H
00032 
00033 #include <casa/aips.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <casa/Arrays/Vector.h>
00036 #include <casa/Arrays/Matrix.h>
00037 #include <casa/Arrays/Cube.h>
00038 #include <casa/Containers/OrderedMap.h>
00039 #include <casa/Containers/MapIO.h>
00040 #include <tables/Tables/ExprNode.h>
00041 #include <ms/MeasurementSets/MeasurementSet.h>
00042 #include <ms/MeasurementSets/MSMainEnums.h>
00043 #include <ms/MeasurementSets/MSSelectionError.h>
00044 #include <ms/MeasurementSets/MSSelectableMainColumn.h>
00045 namespace casa { //# NAMESPACE CASA - BEGIN
00046 
00047 // <summary> 
00048 //
00049 // MSSelectableTable: An interface class used by MSSelection module to
00050 // access the sub-tables and main-table columns of MS-like tables.
00051 //
00052 // </summary>
00053 
00054 // <use visibility=export>
00055 
00056 // <reviewed reviewer="" date="" tests="" demos="">
00057 
00058 // <prerequisite>
00059 // </prerequisite>
00060 //
00061 // <etymology>
00062 // From "msselection" and "table".
00063 // </etymology>
00064 //
00065 //<synopsis> 
00066 //
00067 // This is a pure virtual base-class to provide a table-type agnostic
00068 // interface to the <linkto
00069 // module="MeasurementSets:description">MSSelection</linkto> module to
00070 // access sub-tables and main-table columns of MS-like tables.
00071 //
00072 // </synopsis>
00073 //
00074 // <example>
00075 // <srcblock>
00076 // </srcblock>
00077 // </example>
00078 //
00079 // <motivation>
00080 //
00081 // To allow use of the <linkto
00082 // module="MeasurementSets:description">MSSelection</linkto> module
00083 // for selection on any table that follows the general structure of the
00084 // MS database.  Via this class, minor differences in the database
00085 // layout can be hidden from the MSSelection module.  This also keeps
00086 // MeasurementSet module from depending on other MS-like database
00087 // implemention which may use the MSSelection module.  Such usage will
00088 // need to implement a specialization of <linkto
00089 // module="MeasurementSets:description">MSSelectableTable</linkto> and
00090 // use it to instantiate the <linkto
00091 // module="MeasurementSets:description">MSSelection</linkto> object.
00092 //
00093 // </motivation>
00094 //
00095 // <todo asof="19/03/13">
00096 // </todo>
00097 
00098   class MSSelectableTable
00099   {
00100   public:
00101     MSSelectableTable()                       {};
00102     MSSelectableTable(const Table& table)     {table_p = &table;}
00103     virtual ~MSSelectableTable()              {};
00104 
00105     virtual void setTable(const Table& table) {table_p = &table;}
00106     const Table* table()                      {return table_p;}
00107     TableExprNode col(const String& colName)  {return table()->col(colName);}
00108 
00109     virtual Bool isMS()                       = 0;
00110     virtual const MSAntenna& antenna()        = 0;
00111     virtual const MSField& field()            = 0;
00112     virtual const MSSpectralWindow& spectralWindow() = 0;
00113     virtual const MSDataDescription& dataDescription() = 0;
00114     virtual const MSObservation& observation() = 0;
00115 
00116     virtual String columnName(MSMainEnums::PredefinedColumns nameEnum) = 0;
00117     virtual const MeasurementSet* asMS() = 0;
00118     
00119     virtual MSSelectableMainColumn* mainColumns() = 0;
00120 
00121   protected:
00122     const Table *table_p;
00123   };
00124 
00125 // <summary> 
00126 //
00127 // MSInterface: A specialization of MSSelectableTable for accessing
00128 // MS.
00129 //
00130 // </summary>
00131 
00132 // <use visibility=export>
00133 
00134 // <reviewed reviewer="" date="" tests="" demos="">
00135 
00136 // <prerequisite>
00137 // </prerequisite>
00138 //
00139 // <etymology>
00140 //
00141 // From "ms" and "interface".
00142 //
00143 // </etymology>
00144 //
00145 //<synopsis> 
00146 //
00147 // A class that can be passed around as MSSelectableTable, with most of
00148 // the methods overloaded to work with the underlaying MS.
00149 //
00150 //</synopsis>
00151 //
00152 // <example>
00153 // <srcblock>
00154 //
00155 // //
00156 // // Fill in the expression in the various strings that are passed for
00157 // // parsing to the MSSelection object later.
00158 // //
00159 // String fieldStr,timeStr,spwStr,baselineStr,
00160 //   uvdistStr,taqlStr,scanStr,arrayStr, polnStr,stateObsModeStr,
00161 //   observationStr;
00162 // baselineStr="1&2";
00163 // timeStr="*+0:10:0";
00164 // fieldStr="CygA*";
00165 // //
00166 // // Instantiate the MS and the MSInterface objects.
00167 // //
00168 // MS ms(MSName),selectedMS(ms);
00169 // MSInterface msInterface(ms);
00170 // //
00171 // // Setup the MSSelection thingi
00172 // //
00173 // MSSelection msSelection;
00174 //
00175 // msSelection.reset(msInterface,MSSelection::PARSE_NOW,
00176 //                  timeStr,baselineStr,fieldStr,spwStr,
00177 //                  uvdistStr,taqlStr,polnStr,scanStr,arrayStr,
00178 //                  stateObsModeStr,observationStr);
00179 // if (msSelection.getSelectedMS(selectedMS))
00180 //   cerr << "Got the selected MS!" << endl;
00181 // else
00182 //   cerr << "The set of expressions resulted into null-selection";
00183 // </srcblock>
00184 // </example>
00185 //
00186 // <motivation>
00187 //
00188 // To generalize the implementation of the MSSelection parsers.
00189 //
00190 // </motivation>
00191 //
00192 // <todo asof="19/03/13">
00193 // </todo>
00194 
00195   class MSInterface: public MSSelectableTable
00196   {
00197   public:
00198     MSInterface():msMainCols_p(NULL)                   {};
00199     MSInterface(const Table& table);
00200     virtual ~MSInterface()                             {if (msMainCols_p) delete msMainCols_p;};
00201     virtual const MSAntenna& antenna()                 {return asMS()->antenna();}
00202     virtual const MSField& field()                     {return asMS()->field();}
00203     virtual const MSSpectralWindow& spectralWindow()   {return asMS()->spectralWindow();}
00204     virtual const MSDataDescription& dataDescription() {return asMS()->dataDescription();}
00205     virtual const MSObservation& observation()         {return asMS()->observation();}
00206     virtual String columnName(MSMainEnums::PredefinedColumns nameEnum) {return MS::columnName(nameEnum);}
00207     virtual Bool isMS()                                {return True;};
00208 
00209     virtual const MeasurementSet *asMS(){return static_cast<const MeasurementSet *>(table());};
00210     virtual MSSelectableMainColumn* mainColumns()
00211     {msMainCols_p = new MSMainColInterface(*table_p); return msMainCols_p;};
00212   private:
00213     MSMainColInterface *msMainCols_p;
00214   };
00215 } //# NAMESPACE CASA - END
00216 
00217 #endif