casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ArrColData.h
Go to the documentation of this file.
00001 //# ArrColData.h: Access to a table column containing arrays
00002 //# Copyright (C) 1994,1995,1996,1998,1999
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: ArrColData.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_ARRCOLDATA_H
00029 #define TABLES_ARRCOLDATA_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <tables/Tables/PlainColumn.h>
00034 #include <casa/Arrays/IPosition.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class ColumnSet;
00040 template<class T> class ArrayColumnDesc;
00041 class AipsIO;
00042 
00043 
00044 // <summary>
00045 // Access to a table column containing arrays
00046 // </summary>
00047 
00048 // <use visibility=local>
00049 
00050 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
00051 // </reviewed>
00052 
00053 // <prerequisite>
00054 //# Classes you should understand before using this one.
00055 //   <li> PlainColumn
00056 //   <li> ArrayColumnDesc
00057 //   <li> Table
00058 // </prerequisite>
00059 
00060 // <etymology>
00061 // ArrayColumnData represents a table column containing array data.
00062 // </etymology>
00063 
00064 // <synopsis> 
00065 // The class ArrayColumnData is derived from PlainColumn.
00066 // It implements the virtual functions accessing a table column
00067 // containing arrays with an arbitrary data type.
00068 // Both direct and indirect arrays are supported.
00069 //
00070 // It is possible to access an array or a subsection of it in an
00071 // individual cell (i.e. table row) or in the entire column.
00072 // The functions accessing the entire column are implemented by
00073 // looping over the individual cells.
00074 //
00075 // The main task of this class is to communicate with the data manager
00076 // column object. This consists of:
00077 // <ul>
00078 //  <li> Binding itself to a data manager.
00079 //  <li> Letting the data manager create its column object and
00080 //         setting the shape for direct arrays.
00081 //  <li> Closing the data manager column object (in putFileDerived).
00082 //  <li> Reconstructing the data manager object for an existing table
00083 //         (in getFileDerived).
00084 //  <li> Transferring get/put calls to the data manager column object.
00085 // </ul>
00086 //
00087 // The class is hidden from the user by the envelope class ArrayColumn.
00088 // It used directly, it should be done with care. It assumes that the
00089 // arrays in the various get and put functions have the correct length.
00090 // ArrayColumn does that check.
00091 // </synopsis> 
00092 
00093 // <templating arg=T>
00094 //  <li> Default constructor
00095 //  <li> Copy constructor
00096 //  <li> Assignment operator
00097 // </templating>
00098 
00099 // <todo asof="$DATE:$">
00100 //# A List of bugs, limitations, extensions or planned refinements.
00101 //   <li> support tiling
00102 // </todo>
00103 
00104 
00105 template<class T> class ArrayColumnData : public PlainColumn
00106 {
00107 public:
00108 
00109     // Construct an array column object from the given description
00110     // in the given column set.
00111     // This constructor is used by ArrayColumnDesc::makeColumn.
00112     ArrayColumnData (const ArrayColumnDesc<T>*, ColumnSet*);
00113 
00114     ~ArrayColumnData();
00115 
00116     // Ask the data manager if the shape of an existing array can be changed.
00117     virtual Bool canChangeShape() const;
00118 
00119     // Ask if the data manager can handle a cell slice.
00120     virtual Bool canAccessSlice (Bool& reask) const;
00121 
00122     // Ask if the data manager can handle a column.
00123     virtual Bool canAccessArrayColumn (Bool& reask) const;
00124 
00125     // Ask if the data manager can handle some cells in a column.
00126     virtual Bool canAccessArrayColumnCells (Bool& reask) const;
00127 
00128     // Ask if the data manager can handle a column slice.
00129     virtual Bool canAccessColumnSlice (Bool& reask) const;
00130 
00131     // Initialize the rows from startRownr till endRownr (inclusive)
00132     // with the default value defined in the column description (if defined).
00133     void initialize (uInt startRownr, uInt endRownr);
00134 
00135     // Get the global #dimensions of an array (ie. for all rows).
00136     uInt ndimColumn() const;
00137 
00138     // Get the global shape of an array (ie. for all rows).
00139     IPosition shapeColumn() const;
00140 
00141     // Set shape of all arrays in the column.
00142     // It can only be used for direct arrays.
00143     void setShapeColumn (const IPosition& shape);
00144 
00145     // Get the #dimensions of an array in a particular cell.
00146     // If the cell does not contain an array, 0 is returned.
00147     uInt ndim (uInt rownr) const;
00148 
00149     // Get the shape of an array in a particular cell.
00150     // If the cell does not contain an array, an empty IPosition is returned.
00151     IPosition shape(uInt rownr) const;
00152 
00153     // Set dimensions of array in a particular cell.
00154     // <group>
00155     void setShape (uInt rownr, const IPosition& shape);
00156     // The shape of tiles in the array can also be defined.
00157     void setShape (uInt rownr, const IPosition& shape,
00158                    const IPosition& tileShape);
00159     // </group>
00160 
00161     // Test if the given cell contains an array.
00162     Bool isDefined (uInt rownr) const;
00163 
00164     // Get the array from a particular cell.
00165     // The length of the buffer pointed to by arrayPtr must match
00166     // the actual length. This is checked by ArrayColumn.
00167     void get (uInt rownr, void* arrayPtr) const;
00168 
00169     // Get a slice of an N-dimensional array in a particular cell.
00170     // The length of the buffer pointed to by arrayPtr must match
00171     // the actual length. This is checked by ArrayColumn.
00172     void getSlice (uInt rownr, const Slicer&, void* arrayPtr) const;
00173 
00174     // Get the array of all values in a column.
00175     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00176     // The arrays in the column have to have the same shape in all cells.
00177     // The length of the buffer pointed to by arrayPtr must match
00178     // the actual length. This is checked by ArrayColumn.
00179     void getArrayColumn (void* arrayPtr) const;
00180 
00181     // Get the array of some values in a column.
00182     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00183     // The arrays in the column have to have the same shape in all cells.
00184     // The length of the buffer pointed to by arrayPtr must match
00185     // the actual length. This is checked by ArrayColumn.
00186     void getArrayColumnCells (const RefRows& rownrs, void* arrayPtr) const;
00187 
00188     // Get subsections from all arrays in the column.
00189     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00190     // The arrays in the column have to have the same shape in all cells.
00191     // The length of the buffer pointed to by arrayPtr must match
00192     // the actual length. This is checked by ArrayColumn.
00193     void getColumnSlice (const Slicer&, void* arrayPtr) const;
00194 
00195     // Get subsections from some arrays in the column.
00196     // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
00197     // The arrays in the column have to have the same shape in all cells.
00198     // The length of the buffer pointed to by arrayPtr must match
00199     // the actual length. This is checked by ArrayColumn.
00200     void getColumnSliceCells (const RefRows& rownrs, const Slicer&,
00201                               void* arrayPtr) const;
00202 
00203     // Put the value in a particular cell.
00204     // The length of the buffer pointed to by arrayPtr must match
00205     // the actual length. This is checked by ArrayColumn.
00206     void put (uInt rownr, const void* arrayPtr);
00207 
00208     // Put a slice of an N-dimensional array in a particular cell.
00209     // The length of the buffer pointed to by arrayPtr must match
00210     // the actual length. This is checked by ArrayColumn.
00211     void putSlice (uInt rownr, const Slicer&, const void* arrayPtr);
00212 
00213     // Put the array of all values in the column.
00214     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00215     // The arrays in the column have to have the same shape in all cells.
00216     // The length of the buffer pointed to by arrayPtr must match
00217     // the actual length. This is checked by ArrayColumn.
00218     void putArrayColumn (const void* arrayPtr);
00219 
00220     // Put the array of some values in the column.
00221     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00222     // The arrays in the column have to have the same shape in all cells.
00223     // The length of the buffer pointed to by arrayPtr must match
00224     // the actual length. This is checked by ArrayColumn.
00225     void putArrayColumnCells (const RefRows& rownrs, const void* arrayPtr);
00226 
00227     // Put into subsections of all table arrays in the column.
00228     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00229     // The arrays in the column have to have the same shape in all cells.
00230     // The length of the buffer pointed to by arrayPtr must match
00231     // the actual length. This is checked by ArrayColumn.
00232     void putColumnSlice (const Slicer&, const void* arrayPtr);
00233 
00234     // Put into subsections of some table arrays in the column.
00235     // If the column contains n-dim arrays, the source array is (n+1)-dim.
00236     // The arrays in the column have to have the same shape in all cells.
00237     // The length of the buffer pointed to by arrayPtr must match
00238     // the actual length. This is checked by ArrayColumn.
00239     void putColumnSliceCells (const RefRows& rownrs, const Slicer&,
00240                               const void* arrayPtr);
00241 
00242     // Create a data manager column object for this column.
00243     void createDataManagerColumn();
00244 
00245 
00246 private:
00247     // Pointer to column description.
00248     const ArrayColumnDesc<T>* arrDescPtr_p;
00249     // Is the shape for all arrays in the columns defined.
00250     Bool shapeColDef_p;
00251     // Shape for all arrays in the column.
00252     IPosition shapeCol_p;
00253     
00254 
00255     // Copy constructor cannot be used.
00256     ArrayColumnData (const ArrayColumnData<T>&);
00257 
00258     // Assignment cannot be used.
00259     ArrayColumnData<T>& operator= (const ArrayColumnData<T>&);
00260 
00261     // Check if the shape of an array can be set and if it is set
00262     // correctly (i.e. if matching possible #dim in column description).
00263     void checkShape (const IPosition& shape) const;
00264 
00265     // Write the column data.
00266     // The control information is written into the given AipsIO object,
00267     // while the data is written/flushed by the data manager.
00268     void putFileDerived (AipsIO&);
00269 
00270     // Read the column data back.
00271     // The control information is read from the given AipsIO object.
00272     // This is used to bind the column to the appropriate data manager.
00273     // Thereafter the data manager gets opened.
00274     void getFileDerived (AipsIO&, const ColumnSet&);
00275 };
00276 
00277 
00278 
00279 
00280 } //# NAMESPACE CASA - END
00281 
00282 #ifndef CASACORE_NO_AUTO_TEMPLATES
00283 #include <tables/Tables/ArrColData.tcc>
00284 #endif //# CASACORE_NO_AUTO_TEMPLATES
00285 #endif