MSTableIndex.h

Go to the documentation of this file.
00001  //# MSTableIndex: index into a MeasurementSet sub-table
00002 //# Copyright (C) 2000,2001,2002
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 //#
00027 //# $Id$
00028 
00029 #ifndef MS_MSTABLEINDEX_H
00030 #define MS_MSTABLEINDEX_H
00031 
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/Arrays/Vector.h>
00034 #include <casacore/casa/Containers/Block.h>
00035 #include <casacore/casa/Containers/RecordField.h>
00036 #include <casacore/tables/Tables/Table.h>
00037 #include <casacore/tables/Tables/ScalarColumn.h>
00038 #include <casacore/tables/Tables/ColumnsIndex.h>
00039 
00040 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00041 
00042 //# Forward declarations
00043 class Record;
00044 // class ColumnsIndex;
00045 class String;
00046 
00047 // <summary>
00048 // </summary>
00049 
00050 // <use visibility=export>
00051 
00052 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00053 // </reviewed>
00054 
00055 // <prerequisite>
00056 //   <li> MeasurementSet
00057 //   <li> ColumnsIndex
00058 // </prerequisite>
00059 //
00060 // <etymology>
00061 // </etymology>
00062 //
00063 // <synopsis>
00064 // </synopsis>
00065 //
00066 // <example>
00067 // </example>
00068 //
00069 // <motivation>
00070 // </motivation>
00071 //
00072 // <thrown>
00073 //    <li>
00074 //    <li>
00075 // </thrown>
00076 //
00077 // <todo>
00078 //    <li> Make the searches smarter - for TIME sorted tables, if the time to search is
00079 //         past the last seach, there's no need to search any earlier times.
00080 //    <li> Need to handle the INTERVAL=-1 case fully
00081 // </todo>
00082 class MSTableIndex
00083 {
00084 public:
00085     // no index attached, use the attach function or assignment operator to change that
00086     MSTableIndex();
00087 
00088     // construct one using the indicated subtable which is part of the parent MS
00089     // using the indicated index columns.  All index columns must be scalar integer
00090     // columns.  TIME and INTERVAL will be used when present.  A compare function
00091     // can be provided to over-ride literal matching of column values.
00092     MSTableIndex(const Table &subTable, const Vector<String> &indexCols, 
00093                  ColumnsIndex::Compare *compareFunction = 0);
00094 
00095     // construct one from another
00096     MSTableIndex(const MSTableIndex &other);
00097 
00098     virtual ~MSTableIndex();
00099 
00100     // assignment operator, refernce semantics
00101     MSTableIndex &operator=(const MSTableIndex &other);
00102 
00103     // attach this to a subtable using indexCols
00104     void attach(const Table &subTable, const Vector<String> &indexCols,
00105                         ColumnsIndex::Compare *compareFunction = 0);
00106 
00107     // Call this when an index in an existing row has changed.  There is no need to
00108     // call this when new rows are added to the table
00109     virtual void setChanged();
00110 
00111     // access the record of index (integer) keys
00112     virtual Record &accessKey() {return *key_p;}
00113 
00114     // access the TIME to use in the search (seconds)
00115     virtual Double &time() {return time_p;}
00116 
00117     // access the INTERVAL to use in the search (seconds), must be >= 0
00118     virtual Double &interval() {return interval_p;}
00119 
00120     // get all of the rows in the subTable which have data during the indicated time and
00121     // interval values.  For now, this code will miss the case where the subtable has
00122     // interval = -1 and the start time is outside of the time range implied by the time
00123     // and interval.  If the table has changed and the time is > 
00124     virtual Vector<uInt> getRowNumbers();
00125 
00126     // get the row number which falls in the interval and has the time nearest to the
00127     // center of the interval (time()).  This also has the same problem as the previous function.
00128     virtual uInt getNearestRow(Bool &found);
00129 
00130     // is this attached to a null table
00131     virtual Bool isNull() { return tab_p.isNull();}
00132 
00133     // return the subtable being indexed
00134     virtual Table &table() {return tab_p;}
00135 private:
00136     // the subtable
00137     Table tab_p;
00138 
00139     ROScalarColumn<Double> timeColumn_p, intervalColumn_p;
00140     Vector<Double> timeVec_p, intervalVec_p;
00141     const Double *timeVals_p, *intervalVals_p;
00142     Bool deleteItTime_p, deleteItInterval_p;
00143 
00144     // Internal keys - set by user
00145     Record *key_p;
00146     Block<RecordFieldPtr<Int> > intKeys_p;
00147     Double time_p, interval_p;
00148 
00149     // last known integer key values
00150     Vector<Int> lastKeys_p;
00151     // last known time and interval
00152     Double lastTime_p, lastInterval_p;
00153 
00154     // last search result - matching integer keys
00155     Vector<uInt> lastSearch_p;
00156 
00157     // last nearest
00158     Int lastNearest_p;
00159     Bool nearestFound_p, nearestReady_p;
00160 
00161     // last known sub-table size
00162     uInt nrows_p;
00163 
00164     Bool hasChanged_p;
00165 
00166     ColumnsIndex *index_p;
00167     Block<RecordFieldPtr<Int> > indexKeys_p;
00168     Bool hasTime_p, hasInterval_p;
00169 
00170     void clear();
00171     void makeKeys();
00172     Bool keysChanged();
00173     void getInternals();
00174     void nearestTime();
00175 };
00176 
00177 
00178 } //# NAMESPACE CASACORE - END
00179 
00180 #endif
00181     
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1