casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ConcatColumn.h
Go to the documentation of this file.
00001 //# ConcatColumn.h: A column in a concatenated table
00002 //# Copyright (C) 2008
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: ConcatColumn.h 20997 2010-11-17 07:05:29Z gervandiepen $
00027 
00028 #ifndef TABLES_CONCATCOLUMN_H
00029 #define TABLES_CONCATCOLUMN_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/BaseColumn.h>
00035 #include <tables/Tables/ColumnCache.h>
00036 #include <tables/Tables/TableRecord.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040   //# Forward Declarations
00041   class ConcatTable;
00042   class BaseColumnDesc;
00043   class TableRecord;
00044   class Slicer;
00045   class IPosition;
00046   template<class T> class Vector;
00047 
00048 
00049   // <summary>
00050   // A column in a concatenated table
00051   // </summary>
00052 
00053   // <use visibility=local>
00054 
00055   // <reviewed reviewer="UNKNOWN" date="" tests="">
00056   // </reviewed>
00057 
00058   // <prerequisite>
00059   //# Classes you should understand before using this one.
00060   //   <li> ConcatTable
00061   //   <li> BaseColumn
00062   // </prerequisite>
00063 
00064   // <etymology>
00065   // ConcatTable represents a column in a ConcatTable. A ConcatTable is a table
00066   // referencing another table, usually as the result of a select, etc..
00067   // </etymology>
00068 
00069   // <synopsis> 
00070   // ConcatColumn handles the access of a column in a ConcatTable.
00071   // It calls the corresponding function in the referenced column
00072   // while converting the given row number to the row number in the
00073   // referenced table.
00074   // </synopsis> 
00075 
00076   // <motivation>
00077   // This class is untyped, i.e. not templated.
00078   // Every call is sent to the underlying referenced BaseColumn which
00079   // is typed by the virtual function mechanism.
00080   // A ConcatColumn can never be used directly. A user always has to
00081   // construct a typed ArrayColumn or ScalarColumn object to access a column.
00082   // This means everyting is fully type safe.
00083   // </motivation>
00084 
00085   // <todo asof="$DATE:$">
00086   //# A List of bugs, limitations, extensions or planned refinements.
00087   //   <li> Act upon removal of rows or the underlying column
00088   // </todo>
00089 
00090 
00091   class ConcatColumn : public BaseColumn
00092   {
00093   public:
00094     // Construct the ConcatColumn. It will point to the given column
00095     // description, ConcatTable and referenced column.
00096     // The ConcatTable will be used to convert the rownr to the rownr
00097     // in the referenced column.
00098     ConcatColumn (const BaseColumnDesc*, ConcatTable*);
00099 
00100     ~ConcatColumn();
00101 
00102     // Test if the column is writable in the parent table.
00103     virtual Bool isWritable() const;
00104 
00105     // Test if the column is stored (otherwise it is virtual).
00106     virtual Bool isStored() const;
00107 
00108     // Get access to the column keyword set.
00109     // The initial keyword set is a copy of the keyword set of the first table.
00110     // <group>
00111     virtual TableRecord& rwKeywordSet();
00112     virtual TableRecord& keywordSet();
00113     // </group>
00114 
00115     // Get nr of rows in the column.
00116     virtual uInt nrow() const;
00117 
00118     // Test if a value in a particular cell has been defined.
00119     virtual Bool isDefined (uInt rownr) const;
00120 
00121     // Set the shape of the array in the given row.
00122     virtual void setShape (uInt rownr, const IPosition& shape);
00123 
00124     // Set the shape and tile shape of the array in the given row.
00125     virtual void setShape (uInt rownr, const IPosition& shape,
00126                            const IPosition& tileShape);
00127 
00128     // Get the global #dimensions of an array (i.e. for all rows).
00129     virtual uInt ndimColumn() const;
00130 
00131     // Get the global shape of an array (i.e. for all rows).
00132     virtual IPosition shapeColumn() const;
00133 
00134     // Get the #dimensions of an array in a particular cell.
00135     virtual uInt ndim (uInt rownr) const;
00136 
00137     // Get the shape of an array in a particular cell.
00138     virtual IPosition shape (uInt rownr) const;
00139 
00140     // It can change shape if the underlying column can.
00141     virtual Bool canChangeShape() const;
00142 
00143     // It can handle a scalar column if the underlying column
00144     // can handle cells in a scalar column.
00145     virtual Bool canAccessScalarColumn (Bool& reask) const;
00146 
00147     // It can handle an array column if the underlying column
00148     // can handle cells in an array column.
00149     virtual Bool canAccessArrayColumn (Bool& reask) const;
00150 
00151     // It can handle a cell slice if the underlying column can do it.
00152     virtual Bool canAccessSlice (Bool& reask) const;
00153 
00154     // It can handle a column slice if the underlying column
00155     // can handle a collection of cells in a column and a column slice.
00156     virtual Bool canAccessColumnSlice (Bool& reask) const;
00157 
00158     // It can handle cells in a scalar column if the underlying column
00159     // can do it.
00160     virtual Bool canAccessScalarColumnCells (Bool& reask) const;
00161 
00162     // It can handle cells in an array column if the underlying column
00163     // can do it.
00164     virtual Bool canAccessArrayColumnCells (Bool& reask) const;
00165 
00166     // Initialize the rows from startRownr till endRownr (inclusive)
00167     // with the default value defined in the column description (if defined).
00168     void initialize (uInt startRownr, uInt endRownr);
00169 
00170     // Get the value from a particular cell.
00171     // This can be a scalar or an array.
00172     virtual void get (uInt rownr, void* dataPtr) const;
00173 
00174     // Get a slice of an N-dimensional array in a particular cell.
00175     virtual void getSlice (uInt rownr, const Slicer&, void* dataPtr) const;
00176 
00177     // Put the value in a particular cell.
00178     // This can be a scalar or an array.
00179     virtual void put (uInt rownr, const void* dataPtr);
00180 
00181     // Put a slice of an N-dimensional array in a particular cell.
00182     virtual void putSlice (uInt rownr, const Slicer&, const void* dataPtr);
00183 
00184     // Get the array of all array values in a column.
00185     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00186     // The arrays in the column have to have the same shape in all cells.
00187     virtual void getArrayColumn (void* dataPtr) const;
00188 
00189     // Get subsections from all arrays in the column.
00190     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00191     // The arrays in the column have to have the same shape in all cells.
00192     virtual void getColumnSlice (const Slicer&, void* dataPtr) const;
00193 
00194     // Get the array of some array values in a column.
00195     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00196     // The arrays in the column have to have the same shape in all cells.
00197     virtual void getArrayColumnCells (const RefRows& rownrs,
00198                                       void* dataPtr) const;
00199 
00200     // Get subsections from some arrays in the column.
00201     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00202     // The arrays in the column have to have the same shape in all cells.
00203     virtual void getColumnSliceCells (const RefRows& rownrs,
00204                                       const Slicer&, void* dataPtr) const;
00205 
00206     // Put the array of all array values in the column.
00207     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00208     // The arrays in the column have to have the same shape in all cells.
00209     virtual void putArrayColumn (const void* dataPtr);
00210 
00211     // Put into subsections of all table arrays in the column.
00212     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00213     // The arrays in the column have to have the same shape in all cells.
00214     virtual void putColumnSlice (const Slicer&, const void* dataPtr);
00215 
00216     // Get the array of some array values in a column.
00217     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00218     // The arrays in the column have to have the same shape in all cells.
00219     virtual void putArrayColumnCells (const RefRows& rownrs,
00220                                       const void* dataPtr);
00221 
00222     // Put subsections of some arrays in the column.
00223     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00224     // The arrays in the column have to have the same shape in all cells.
00225     virtual void putColumnSliceCells (const RefRows& rownrs,
00226                                       const Slicer&, const void* dataPtr);
00227 
00228     // Get the underlying column cache.
00229     virtual ColumnCache& columnCache();
00230 
00231     // Set the maximum cache size (in bytes) to be used by a storage manager.
00232     virtual void setMaximumCacheSize (uInt nbytes);
00233 
00234     // Allocate value buffers for the table iterator.
00235     // Also get a comparison function if undefined.
00236     // The function freeIterBuf must be called to free the buffers.
00237     virtual void allocIterBuf (void*& lastVal, void*& curVal,
00238                                CountedPtr<BaseCompare>& cmpObj);
00239 
00240     // Free the value buffers allocated by allocIterBuf.
00241     virtual void freeIterBuf (void*& lastVal, void*& curVal);
00242 
00243   private:
00244     // Define the function to handle access to an entire column.
00245     typedef void AccessColumnFunc (BaseColumn* col,
00246                                    const Slicer*, ArrayBase* array);
00247 
00248     // Define the function to handle access to a number of rows.
00249     typedef void AccessRowsFunc (BaseColumn* col, const RefRows& rows,
00250                                   const Slicer*, ArrayBase* array);
00251 
00252     // Access the data for an entire column.
00253     void accessColumn (const Slicer* ns,
00254                        void* dataPtr,
00255                        AccessColumnFunc*) const;
00256 
00257     // Access the data with multiple rows combined.
00258     void accessRows (const RefRows& rownrs,
00259                      const Slicer* ns,
00260                      void* dataPtr,
00261                      AccessRowsFunc*) const;
00262 
00263     // Define the access functions.
00264     static void getColumnPart (BaseColumn* col,
00265                                const Slicer*, ArrayBase* arr);
00266     static void putColumnPart (BaseColumn* col,
00267                                const Slicer*, ArrayBase* arr);
00268     static void getColumnSlicePart (BaseColumn* col,
00269                                     const Slicer* ns, ArrayBase* arr);
00270     static void putColumnSlicePart (BaseColumn* col,
00271                                     const Slicer* ns, ArrayBase* arr);
00272     static void getRowsPart (BaseColumn* col, const RefRows& rows,
00273                              const Slicer*, ArrayBase* array);
00274     static void putRowsPart (BaseColumn* col, const RefRows& rows,
00275                              const Slicer*, ArrayBase* array);
00276     static void getRowsSlicePart (BaseColumn* col, const RefRows& rows,
00277                                   const Slicer*, ArrayBase* array);
00278     static void putRowsSlicePart (BaseColumn* col, const RefRows& rows,
00279                                   const Slicer*, ArrayBase* array);
00280     // </group>
00281 
00282   protected:
00283     // Set the column cache to the cache of the given table.
00284     // The row numbers will be adjusted as needed.
00285     void setColumnCache (uInt tableNr, const ColumnCache&) const;
00286 
00287     //# Data members
00288     ConcatTable*        refTabPtr_p;
00289     Block<BaseColumn*>  refColPtr_p;
00290     mutable ColumnCache colCache_p;
00291     TableRecord         keywordSet_p;
00292   };
00293 
00294 } //# NAMESPACE CASA - END
00295 
00296 #endif