casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
StIndArrAIO.h
Go to the documentation of this file.
00001 //# StIndArrAIO.h: AipsIO storage manager for indirect table arrays
00002 //# Copyright (C) 1994,1995,1996,1997,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: StIndArrAIO.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_STINDARRAIO_H
00029 #define TABLES_STINDARRAIO_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/StManAipsIO.h>
00035 #include <casa/Arrays/IPosition.h>
00036 #include <casa/IO/ByteIO.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 class AipsIO;
00042 class StManArrayFile;
00043 class StIndArray;
00044 
00045 
00046 // <summary>
00047 // AipsIO storage manager for indirect table arrays
00048 // </summary>
00049 
00050 // <use visibility=local>
00051 
00052 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00053 // </reviewed>
00054 
00055 // <prerequisite>
00056 //# Classes you should understand before using this one.
00057 //   <li> StManAipsIO
00058 //   <li> StManColumnAipsIO
00059 //   <li> StIndArray
00060 // </prerequisite>
00061 
00062 // <etymology>
00063 // StManColumnIndArrayAipsIO handles the access to an indirect array
00064 // in a table column using the AipsIO storage manager.
00065 // </etymology>
00066 
00067 // <synopsis> 
00068 // StManColumnArrayAipsIO handles indirect arrays in a table column.
00069 // An StManArrayFile object is used to read and write the arrays
00070 // from/into a file in a simple way. So this column has a file of its own
00071 // to store the actual data in. It uses the (unique) column sequence
00072 // number to make the file name unique.
00073 //
00074 // An array (or section of an array) is only read when needed.
00075 // It, however, caches the array shape using the helper class
00076 // StIndArray. Pointers to these objects
00077 // are maintained using the standard StManColumnAipsIO facilities.
00078 // When the column gets written, the offsets in the StManArrayFile file
00079 // get written. Those will be read back when the column is read in.
00080 //
00081 // When a row gets deleted or when the array gets bigger, the file space
00082 // is lost. This storage manager is a simple one and no attempts
00083 // are done to make it smart.
00084 // </synopsis> 
00085 
00086 // <motivation>
00087 // StManColumnIndArrayAipsIO handles the standard data types. The class
00088 // is not templated, but a switch statement is used instead.
00089 // Templates would cause too many instantiations.
00090 // </motivation>
00091 
00092 // <todo asof="$DATE:$">
00093 //# A List of bugs, limitations, extensions or planned refinements.
00094 // </todo>
00095 
00096 
00097 class StManColumnIndArrayAipsIO : public StManColumnAipsIO
00098 {
00099 public:
00100 
00101     // Create a column of the given type.
00102     // The StManArrayFile object is not allocated here but by doCreate.
00103     StManColumnIndArrayAipsIO (StManAipsIO*, int dataType);
00104 
00105     // Frees up the storage and delete the StManArrayFile object.
00106     ~StManColumnIndArrayAipsIO();
00107 
00108     // It can handle access to a slice in a cell.
00109     Bool canAccessSlice (Bool& reask) const;
00110 
00111     // Set the (fixed) shape of the arrays in the entire column.
00112     void setShapeColumn (const IPosition& shape);
00113 
00114     // Add (newNrrow-oldNrrow) rows to the column.
00115     // Allocate the data arrays in these rows if the shape is fixed.
00116     void addRow (uInt newNrrow, uInt oldNrrow);
00117 
00118     // Set the shape of the array in the given row and allocate the array
00119     // in the file.
00120     void setShape (uInt rownr, const IPosition& shape);
00121 
00122     // Is the shape defined (i.e. is there an array) in this row?
00123     Bool isShapeDefined (uInt rownr);
00124 
00125     // Get the dimensionality of the item in the given row.
00126     // 0 is returned if there is no array.
00127     uInt ndim (uInt rownr);
00128 
00129     // Get the shape of the array in the given row.
00130     // An zero-length IPosition is returned if there is no array.
00131     IPosition shape (uInt rownr);
00132 
00133     // This storage manager can handle changing array shapes
00134     // for non-FixedShape columns.
00135     Bool canChangeShape() const;
00136 
00137     // Get an array value in the given row.
00138     // The buffer pointed to by dataPtr has to have the correct length
00139     // (which is guaranteed by the ArrayColumn get function).
00140     // <group>
00141     void getArrayBoolV     (uInt rownr, Array<Bool>* dataPtr);
00142     void getArrayuCharV    (uInt rownr, Array<uChar>* dataPtr);
00143     void getArrayShortV    (uInt rownr, Array<Short>* dataPtr);
00144     void getArrayuShortV   (uInt rownr, Array<uShort>* dataPtr);
00145     void getArrayIntV      (uInt rownr, Array<Int>* dataPtr);
00146     void getArrayuIntV     (uInt rownr, Array<uInt>* dataPtr);
00147     void getArrayfloatV    (uInt rownr, Array<float>* dataPtr);
00148     void getArraydoubleV   (uInt rownr, Array<double>* dataPtr);
00149     void getArrayComplexV  (uInt rownr, Array<Complex>* dataPtr);
00150     void getArrayDComplexV (uInt rownr, Array<DComplex>* dataPtr);
00151     void getArrayStringV   (uInt rownr, Array<String>* dataPtr);
00152     // </group>
00153 
00154     // Put an array value into the given row.
00155     // The buffer pointed to by dataPtr has to have the correct length
00156     // (which is guaranteed by the ArrayColumn put function).
00157     // <group>
00158     void putArrayBoolV     (uInt rownr, const Array<Bool>* dataPtr);
00159     void putArrayuCharV    (uInt rownr, const Array<uChar>* dataPtr);
00160     void putArrayShortV    (uInt rownr, const Array<Short>* dataPtr);
00161     void putArrayuShortV   (uInt rownr, const Array<uShort>* dataPtr);
00162     void putArrayIntV      (uInt rownr, const Array<Int>* dataPtr);
00163     void putArrayuIntV     (uInt rownr, const Array<uInt>* dataPtr);
00164     void putArrayfloatV    (uInt rownr, const Array<float>* dataPtr);
00165     void putArraydoubleV   (uInt rownr, const Array<double>* dataPtr);
00166     void putArrayComplexV  (uInt rownr, const Array<Complex>* dataPtr);
00167     void putArrayDComplexV (uInt rownr, const Array<DComplex>* dataPtr);
00168     void putArrayStringV   (uInt rownr, const Array<String>* dataPtr);
00169     // </group>
00170 
00171     // Get a section of the array in the given row.
00172     // The buffer pointed to by dataPtr has to have the correct length
00173     // (which is guaranteed by the ArrayColumn getSlice function).
00174     // <group>
00175     void getSliceBoolV     (uInt rownr, const Slicer&, Array<Bool>* dataPtr);
00176     void getSliceuCharV    (uInt rownr, const Slicer&, Array<uChar>* dataPtr);
00177     void getSliceShortV    (uInt rownr, const Slicer&, Array<Short>* dataPtr);
00178     void getSliceuShortV   (uInt rownr, const Slicer&, Array<uShort>* dataPtr);
00179     void getSliceIntV      (uInt rownr, const Slicer&, Array<Int>* dataPtr);
00180     void getSliceuIntV     (uInt rownr, const Slicer&, Array<uInt>* dataPtr);
00181     void getSlicefloatV    (uInt rownr, const Slicer&, Array<float>* dataPtr);
00182     void getSlicedoubleV   (uInt rownr, const Slicer&, Array<double>* dataPtr);
00183     void getSliceComplexV  (uInt rownr, const Slicer&, Array<Complex>* dataPtr);
00184     void getSliceDComplexV (uInt rownr, const Slicer&, Array<DComplex>* dataPtr);
00185     void getSliceStringV   (uInt rownr, const Slicer&, Array<String>* dataPtr);
00186     // </group>
00187 
00188     // Put into a section of the array in the given row.
00189     // The buffer pointed to by dataPtr has to have the correct length
00190     // (which is guaranteed by the ArrayColumn putSlice function).
00191     // <group>
00192     void putSliceBoolV     (uInt rownr, const Slicer&,
00193                             const Array<Bool>* dataPtr);
00194     void putSliceuCharV    (uInt rownr, const Slicer&,
00195                             const Array<uChar>* dataPtr);
00196     void putSliceShortV    (uInt rownr, const Slicer&,
00197                             const Array<Short>* dataPtr);
00198     void putSliceuShortV   (uInt rownr, const Slicer&,
00199                             const Array<uShort>* dataPtr);
00200     void putSliceIntV      (uInt rownr, const Slicer&,
00201                             const Array<Int>* dataPtr);
00202     void putSliceuIntV     (uInt rownr, const Slicer&,
00203                             const Array<uInt>* dataPtr);
00204     void putSlicefloatV    (uInt rownr, const Slicer&,
00205                             const Array<float>* dataPtr);
00206     void putSlicedoubleV   (uInt rownr, const Slicer&,
00207                             const Array<double>* dataPtr);
00208     void putSliceComplexV  (uInt rownr, const Slicer&,
00209                             const Array<Complex>* dataPtr);
00210     void putSliceDComplexV (uInt rownr, const Slicer&,
00211                             const Array<DComplex>* dataPtr);
00212     void putSliceStringV   (uInt rownr, const Slicer&,
00213                             const Array<String>* dataPtr);
00214     // </group>
00215 
00216     // Remove the value in the given row.
00217     // This will result in lost file space.
00218     void remove (uInt rownr);
00219 
00220     // Let the column create its array file.
00221     void doCreate (uInt nrrow);
00222 
00223     // Write the data into AipsIO.
00224     // This will call StManColumnAipsIO::putFile which will in its turn
00225     // call putData in this class for each of its chunks of data.
00226     void putFile (uInt nrval, AipsIO&);
00227 
00228     // Read the data from AipsIO.
00229     // This will call StManColumnAipsIO::getFile which will in its turn
00230     // call getData in this class for each of its chunks of data.
00231     void getFile (uInt nrval, AipsIO&);
00232 
00233     // Reopen the storage manager files for read/write.
00234     virtual void reopenRW();
00235 
00236     // Check if the class invariants still hold.
00237     Bool ok() const;
00238 
00239 private:
00240     // The (unique) sequence number of the column.
00241     uInt seqnr_p;
00242     // The shape of all arrays in case it is fixed.
00243     IPosition fixedShape_p;
00244     // Switch indicating if the shape is fixed.
00245     Bool shapeIsFixed_p;
00246     // The version of the object retrieved from a file.
00247     // Versions < 2 use a StManArrayFile of their own.
00248     // Newer versions share the one in StManAipsIO.
00249     uInt version_p;
00250     // The file containing the indirect arrays.
00251     StManArrayFile* iosfile_p;
00252 
00253 
00254     // Open the file with the given mode.
00255     void openFile (ByteIO::OpenOption opt);
00256 
00257     // Delete the array in the given row.
00258     void deleteArray (uInt rownr);
00259 
00260     // Read the shape at the given row.
00261     // This will cache the information in the StIndArray
00262     // object for that row.
00263     StIndArray* getShape (uInt rownr);
00264 
00265     // Put the data of a data block.
00266     // datap is an array of nrval pointers to StIndArray.
00267     // Only the file offsets get written.
00268     void putData (void* datap, uInt nrval, AipsIO&);
00269 
00270     // Get file offsets to the arrays into a data block at the given index.
00271     // datap is an array of pointers to StIndArray.
00272     // nrval blocks will be allocated and read starting at datap[index].
00273     // The actual shape and array data will be read when needed.
00274     void getData (void* datap, uInt index, uInt nrval, AipsIO&, uInt version);
00275         
00276     // Forbid copy constructor.
00277     StManColumnIndArrayAipsIO (const StManColumnIndArrayAipsIO&);
00278 
00279     // Forbid assignment.
00280     StManColumnIndArrayAipsIO& operator= (const StManColumnIndArrayAipsIO&);
00281 };
00282 
00283 
00284 
00285 
00286 } //# NAMESPACE CASA - END
00287 
00288 #endif