casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
StArrAipsIO.h
Go to the documentation of this file.
00001 //# StArrAipsIO.h: AipsIO storage manager for direct table arrays
00002 //# Copyright (C) 1994,1995,1996,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: StArrAipsIO.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_STARRAIPSIO_H
00029 #define TABLES_STARRAIPSIO_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <tables/Tables/StManAipsIO.h>
00034 #include <casa/Arrays/IPosition.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class AipsIO;
00040 
00041 
00042 // <summary>
00043 // AipsIO storage manager for direct table arrays
00044 // </summary>
00045 
00046 // <use visibility=local>
00047 
00048 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //# Classes you should understand before using this one.
00053 //   <li> StManAipsIO
00054 //   <li> StManColumnAipsIO
00055 // </prerequisite>
00056 
00057 // <etymology>
00058 // StManColumnArrayAipsIO handles the access to a direct array in a table
00059 // column using the AipsIO storage manager.
00060 // </etymology>
00061 
00062 // <synopsis> 
00063 // StManColumnArrayAipsIO holds the direct arrays in memory and writes
00064 // them into the AipsIO file when the table gets closed.
00065 // It fully supports addition and removal of rows.
00066 // When a row is added to the table, the direct array gets allocated.
00067 // This is possible, because the shape of direct arrays is known.
00068 //
00069 // The class is derived from StManColumnAipsIO which is used to hold
00070 // a pointer to the array.
00071 // </synopsis> 
00072 
00073 // <motivation>
00074 // StManColumnArrayAipsIO handles the standard data types. The class
00075 // is not templated, but a switch statement is used instead.
00076 // Templates would cause too many instantiations.
00077 // </motivation>
00078 
00079 // <todo asof="$DATE:$">
00080 //# A List of bugs, limitations, extensions or planned refinements.
00081 //   <li> Maybe TpArrayInt, etc. should be used instead of TpInt.
00082 //   <li> get/putSlice use too many array operations.
00083 //          To solve this requires an array constructor taking a
00084 //          pointer to the data (which is foreseen in the new Array classes).
00085 // </todo>
00086 
00087 
00088 class StManColumnArrayAipsIO : public StManColumnAipsIO
00089 {
00090 public:
00091 
00092     // Create a column of the given data type.
00093     StManColumnArrayAipsIO (StManAipsIO*, int dataType);
00094 
00095     // Frees up the storage.
00096     ~StManColumnArrayAipsIO();
00097 
00098     // It can handle access to a slice in a cell.
00099     Bool canAccessSlice (Bool& reask) const;
00100 
00101     // It can handle access to an entire column.
00102     Bool canAccessArrayColumn (Bool& reask) const;
00103 
00104     // Set the shape of the arrays in the entire column.
00105     void setShapeColumn (const IPosition& shape);
00106 
00107     // Add (newNrrow-oldNrrow) rows to the column.
00108     // Allocate the data arrays in these rows.
00109     void addRow (uInt newNrrow, uInt oldNrrow);
00110 
00111     // Get the dimensionality of the item in the given row.
00112     // This is the same for all rows.
00113     uInt ndim (uInt rownr);
00114 
00115     // Get the shape of the array in the given row.
00116     // This is the same for all rows.
00117     IPosition shape (uInt rownr);
00118 
00119     // Get an array value in the given row.
00120     // The buffer pointed to by dataPtr has to have the correct length
00121     // (which is guaranteed by the ArrayColumn get function).
00122     // <group>
00123     void getArrayBoolV     (uInt rownr, Array<Bool>* dataPtr);
00124     void getArrayuCharV    (uInt rownr, Array<uChar>* dataPtr);
00125     void getArrayShortV    (uInt rownr, Array<Short>* dataPtr);
00126     void getArrayuShortV   (uInt rownr, Array<uShort>* dataPtr);
00127     void getArrayIntV      (uInt rownr, Array<Int>* dataPtr);
00128     void getArrayuIntV     (uInt rownr, Array<uInt>* dataPtr);
00129     void getArrayfloatV    (uInt rownr, Array<float>* dataPtr);
00130     void getArraydoubleV   (uInt rownr, Array<double>* dataPtr);
00131     void getArrayComplexV  (uInt rownr, Array<Complex>* dataPtr);
00132     void getArrayDComplexV (uInt rownr, Array<DComplex>* dataPtr);
00133     void getArrayStringV   (uInt rownr, Array<String>* dataPtr);
00134     // </group>
00135 
00136     // Put an array value into the given row.
00137     // The buffer pointed to by dataPtr has to have the correct length
00138     // (which is guaranteed by the ArrayColumn put function).
00139     // <group>
00140     void putArrayBoolV     (uInt rownr, const Array<Bool>* dataPtr);
00141     void putArrayuCharV    (uInt rownr, const Array<uChar>* dataPtr);
00142     void putArrayShortV    (uInt rownr, const Array<Short>* dataPtr);
00143     void putArrayuShortV   (uInt rownr, const Array<uShort>* dataPtr);
00144     void putArrayIntV      (uInt rownr, const Array<Int>* dataPtr);
00145     void putArrayuIntV     (uInt rownr, const Array<uInt>* dataPtr);
00146     void putArrayfloatV    (uInt rownr, const Array<float>* dataPtr);
00147     void putArraydoubleV   (uInt rownr, const Array<double>* dataPtr);
00148     void putArrayComplexV  (uInt rownr, const Array<Complex>* dataPtr);
00149     void putArrayDComplexV (uInt rownr, const Array<DComplex>* dataPtr);
00150     void putArrayStringV   (uInt rownr, const Array<String>* dataPtr);
00151     // </group>
00152 
00153     // Get a section of the array in the given row.
00154     // The buffer pointed to by dataPtr has to have the correct length
00155     // (which is guaranteed by the ArrayColumn getSlice function).
00156     // <group>
00157     void getSliceBoolV     (uInt rownr, const Slicer&, Array<Bool>* dataPtr);
00158     void getSliceuCharV    (uInt rownr, const Slicer&, Array<uChar>* dataPtr);
00159     void getSliceShortV    (uInt rownr, const Slicer&, Array<Short>* dataPtr);
00160     void getSliceuShortV   (uInt rownr, const Slicer&, Array<uShort>* dataPtr);
00161     void getSliceIntV      (uInt rownr, const Slicer&, Array<Int>* dataPtr);
00162     void getSliceuIntV     (uInt rownr, const Slicer&, Array<uInt>* dataPtr);
00163     void getSlicefloatV    (uInt rownr, const Slicer&, Array<float>* dataPtr);
00164     void getSlicedoubleV   (uInt rownr, const Slicer&, Array<double>* dataPtr);
00165     void getSliceComplexV  (uInt rownr, const Slicer&, Array<Complex>* dataPtr);
00166     void getSliceDComplexV (uInt rownr, const Slicer&, Array<DComplex>* dataPtr);
00167     void getSliceStringV   (uInt rownr, const Slicer&, Array<String>* dataPtr);
00168     // </group>
00169 
00170     // Put into a section of the array in the given row.
00171     // The buffer pointed to by dataPtr has to have the correct length
00172     // (which is guaranteed by the ArrayColumn putSlice function).
00173     // <group>
00174     void putSliceBoolV     (uInt rownr, const Slicer&,
00175                             const Array<Bool>* dataPtr);
00176     void putSliceuCharV    (uInt rownr, const Slicer&,
00177                             const Array<uChar>* dataPtr);
00178     void putSliceShortV    (uInt rownr, const Slicer&,
00179                             const Array<Short>* dataPtr);
00180     void putSliceuShortV   (uInt rownr, const Slicer&,
00181                             const Array<uShort>* dataPtr);
00182     void putSliceIntV      (uInt rownr, const Slicer&,
00183                             const Array<Int>* dataPtr);
00184     void putSliceuIntV     (uInt rownr, const Slicer&,
00185                             const Array<uInt>* dataPtr);
00186     void putSlicefloatV    (uInt rownr, const Slicer&,
00187                             const Array<float>* dataPtr);
00188     void putSlicedoubleV   (uInt rownr, const Slicer&,
00189                             const Array<double>* dataPtr);
00190     void putSliceComplexV  (uInt rownr, const Slicer&,
00191                             const Array<Complex>* dataPtr);
00192     void putSliceDComplexV (uInt rownr, const Slicer&,
00193                             const Array<DComplex>* dataPtr);
00194     void putSliceStringV   (uInt rownr, const Slicer&,
00195                             const Array<String>* dataPtr);
00196     // </group>
00197 
00198     // Get all array values in the column.
00199     // The buffer pointed to by dataPtr has to have the correct length
00200     // (which is guaranteed by the ArrayColumn getColumn function).
00201     // <group>
00202     void getArrayColumnBoolV     (Array<Bool>* dataPtr);
00203     void getArrayColumnuCharV    (Array<uChar>* dataPtr);
00204     void getArrayColumnShortV    (Array<Short>* dataPtr);
00205     void getArrayColumnuShortV   (Array<uShort>* dataPtr);
00206     void getArrayColumnIntV      (Array<Int>* dataPtr);
00207     void getArrayColumnuIntV     (Array<uInt>* dataPtr);
00208     void getArrayColumnfloatV    (Array<float>* dataPtr);
00209     void getArrayColumndoubleV   (Array<double>* dataPtr);
00210     void getArrayColumnComplexV  (Array<Complex>* dataPtr);
00211     void getArrayColumnDComplexV (Array<DComplex>* dataPtr);
00212     void getArrayColumnStringV   (Array<String>* dataPtr);
00213     // </group>
00214 
00215     // Put all arrays in the column.
00216     // The buffer pointed to by dataPtr has to have the correct length
00217     // (which is guaranteed by the ArrayColumn putColumn function).
00218     // <group>
00219     void putArrayColumnBoolV     (const Array<Bool>* dataPtr);
00220     void putArrayColumnuCharV    (const Array<uChar>* dataPtr);
00221     void putArrayColumnShortV    (const Array<Short>* dataPtr);
00222     void putArrayColumnuShortV   (const Array<uShort>* dataPtr);
00223     void putArrayColumnIntV      (const Array<Int>* dataPtr);
00224     void putArrayColumnuIntV     (const Array<uInt>* dataPtr);
00225     void putArrayColumnfloatV    (const Array<float>* dataPtr);
00226     void putArrayColumndoubleV   (const Array<double>* dataPtr);
00227     void putArrayColumnComplexV  (const Array<Complex>* dataPtr);
00228     void putArrayColumnDComplexV (const Array<DComplex>* dataPtr);
00229     void putArrayColumnStringV   (const Array<String>* dataPtr);
00230     // </group>
00231 
00232     // Remove the value at the given index.
00233     void remove (uInt index);
00234 
00235     // Write the data into AipsIO.
00236     // This will call StManColumnAipsIO::putFile which will in its turn
00237     // call putData in this class for each of its chunks of data.
00238     void putFile (uInt nrval, AipsIO&);
00239 
00240     // Read the data from AipsIO.
00241     // This will call StManColumnAipsIO::getFile which will in its turn
00242     // call getData in this class for each of its chunks of data.
00243     void getFile (uInt nrval, AipsIO&);
00244 
00245     // Check if the class invariants still hold.
00246     Bool ok() const;
00247 
00248 private:
00249     // The data type of the array (as defined in DataType.h).
00250     int   dtypeArr_p;
00251     // The shape of the array.
00252     IPosition shape_p;
00253     // The nr of elements in the array.
00254     uInt  nrelem_p;
00255 
00256     // Delete the array at the given index.
00257     void deleteArray (uInt index);
00258 
00259     // Put the data of a data block.
00260     // datap is an array of nrval pointers to arrays.
00261     void putData (void* datap, uInt nrval, AipsIO&);
00262 
00263     // Get data arrays into a data block at the given index.
00264     // datap is an array of pointers to arrays. nrval arrays will
00265     // be allocated and read starting at datap[index].
00266     void getData (void* datap, uInt index, uInt nrval, AipsIO&, uInt version);
00267 
00268     // Forbid copy constructor.
00269     StManColumnArrayAipsIO (const StManColumnArrayAipsIO&);
00270 
00271     // Forbid assignment.
00272     StManColumnArrayAipsIO& operator= (const StManColumnArrayAipsIO&);
00273 };
00274 
00275 
00276 
00277 
00278 } //# NAMESPACE CASA - END
00279 
00280 #endif