casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TiledCellStMan.h
Go to the documentation of this file.
00001 //# TiledCellStMan.h: Tiled Cell Storage Manager
00002 //# Copyright (C) 1995,1996,1997,1998,1999,2001
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: TiledCellStMan.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef TABLES_TILEDCELLSTMAN_H
00029 #define TABLES_TILEDCELLSTMAN_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/TiledStMan.h>
00035 #include <casa/Arrays/IPosition.h>
00036 #include <casa/BasicSL/String.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 
00042 
00043 // <summary>
00044 // Tiled Cell Storage Manager.
00045 // </summary>
00046 
00047 // <use visibility=export>
00048 
00049 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00050 // </reviewed>
00051 
00052 // <prerequisite>
00053 //# Classes you should understand before using this one.
00054 //   <li> <linkto class=TiledStMan>TiledStMan</linkto>
00055 //   <li> <linkto class=TSMCube>TSMCube</linkto>
00056 //   <li> <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
00057 //        for a discussion of the maximum cache size
00058 // </prerequisite>
00059 
00060 // <etymology>
00061 // TiledCellStMan is the Tiled Storage Manager storing
00062 // each cell as a separate hypercube.
00063 // </etymology>
00064 
00065 // <synopsis>
00066 // TiledCellStMan is a derivation from TiledStMan, the abstract
00067 // tiled storage manager class. A description of the basics
00068 // of tiled storage managers is given in the
00069 // <linkto module=Tables:TiledStMan>Tables module</linkto> description.
00070 // <p>
00071 // TiledCellStMan allows the user to create a tiled hypercube for
00072 // each data cell in an automatic way. It is meant to be used for
00073 // storing regularly shaped data like images (where the table contains
00074 // a possibly differently shaped image in each row).
00075 // <p>
00076 // The TiledCellStMan has the following (extra) properties:
00077 // <ul>
00078 //  <li> Addition of a row results in the addition of a hypercube in
00079 //       which the data cells in that row will be stored. Thus each row
00080 //       of the hypercolumn is stored in its own hypercube.
00081 //       Note that a hypercolumn has a given dimensionality, so each
00082 //       data cell in the hypercolumn has to match that dimensionality.
00083 //  <li> Although there are multiple hypercubes, an id value is not needed.
00084 //       The row number serves as the id value.
00085 //  <li> Coordinates for the hypercubes can be defined and (of course)
00086 //       their shapes have to match the hypercube shape.
00087 //       Their values have to be put explicitly (so it is not possible
00088 //       to define them via an addHypercube call like in
00089 //       <linkto class=TiledDataStMan>TiledDataStMan</linkto>).
00090 //  <li> It is possible to define a (default) tile shape in the
00091 //       TiledCellStMan constructor. When setting the shape of the
00092 //       array in a row (using <linkto class=ArrayColumn>
00093 //       ArrayColumn::setShape</linkto>), it is possible to override
00094 //       that default for the hypercube in this particular row.
00095 // </ul>
00096 // </synopsis> 
00097 
00098 // <motivation>
00099 // This tiled storage manager does not require any special action
00100 // (like calling add/extendHypercube) when used with a column
00101 // containing variable shaped arrays.
00102 // </motivation>
00103 
00104 // <example>
00105 // <srcblock>
00106 //  // Define the table description and the columns in it.
00107 //  TableDesc td ("", "1", TableDesc::Scratch);
00108 //  td.addColumn (ArrayColumnDesc<float>  ("RA", 1));
00109 //  td.addColumn (ArrayColumnDesc<float>  ("Dec", 1));
00110 //  td.addColumn (ArrayColumnDesc<float>  ("Velocity", 1));
00111 //  td.addColumn (ArrayColumnDesc<float>  ("Image", 3));
00112 //  // Define the 3-dim hypercolumn with its data and coordinate columns.
00113 //  // Note that its dimensionality must match the dimensionality
00114 //  // of the data cells.
00115 //  td.defineHypercolumn ("TSMExample",
00116 //                        3,
00117 //                        stringToVector ("Image"),
00118 //                        stringToVector ("RA,Dec,Velocity"));
00119 //  // Now create a new table from the description.
00120 //  SetupNewTable newtab("tTiledCellStMan_tmp.data", td, Table::New);
00121 //  // Create a TiledCellStMan storage manager for the hypercolumn
00122 //  // and bind the columns to it.
00123 //  TiledCellStMan sm1 ("TSMExample");
00124 //  newtab.bindAll (sm1);
00125 //  // Create the table.
00126 //  Table table(newtab);
00127 //  // Define the values for the coordinates of the hypercube.
00128 //  Vector<float> raValues(512);
00129 //  Vector<float> DecValues(512);
00130 //  Vector<float> VelocityValues(64);
00131 //  indgen (raValues);
00132 //  indgen (decValues, float(100));
00133 //  indgen (velocityValues, float(200));
00134 //  ArrayColumn<float> ra (table, "RA");
00135 //  ArrayColumn<float> dec (table, "Dec");
00136 //  ArrayColumn<float> velocity (table, "Velocity");
00137 //  ArrayColumn<float> image (table, "Image");
00138 //  Cube<float> imageValues(IPosition(3,512,512,64));
00139 //  indgen (imageValues);
00140 //  // Write some data into the data columns.
00141 //  uInt i;
00142 //  for (i=0; i<4; i++) {
00143 //      table.addRow();
00144 //      image.put (i, imageValues);
00145 //      ra.put (i, raValues);
00146 //      dec.put (i, decValues);
00147 //      velocity.put (i, velocityValues);
00148 //  }
00149 // </srcblock>
00150 // </example>
00151 
00152 //# <todo asof="$DATE:$">
00153 //# A List of bugs, limitations, extensions or planned refinements.
00154 //# </todo>
00155 
00156 
00157 class TiledCellStMan : public TiledStMan
00158 {
00159 public:
00160     // Create a TiledDataStMan storage manager for the hypercolumn
00161     // with the given name. The columns used should have the FixedShape
00162     // attribute set.
00163     // The hypercolumn name is also the name of the storage manager.
00164     // The given tile shape will be used as the default for the hypercube
00165     // in each cell. Per cell it can be redefined via ArrayColumn::setShape.
00166     // The given maximum cache size (default is unlimited) is persistent,
00167     // thus will be reused when the table is read back. Note that the class
00168     // <linkto class=ROTiledStManAccessor>ROTiledStManAccessor</linkto>
00169     // allows one to overwrite the maximum cache size temporarily.
00170     // Its description contains a discussion about the effects of
00171     // setting a maximum cache.
00172     // <br>The constructor taking a Record expects fields in the record with
00173     // the name of the arguments in uppercase. If not defined, their
00174     // default value is used.
00175     // <group>
00176     TiledCellStMan (const String& hypercolumnName,
00177                     const IPosition& defaultTileShape,
00178                     uInt maximumCacheSize = 0);
00179     TiledCellStMan (const String& hypercolumnName,
00180                     const Record& spec);
00181     // </group>
00182 
00183     ~TiledCellStMan();
00184 
00185     // Clone this object.
00186     // It does not clone TSMColumn objects possibly used.
00187     DataManager* clone() const;
00188 
00189     // Get the type name of the data manager (i.e. TiledCellStMan).
00190     String dataManagerType() const;
00191 
00192     // This tiled storage manager can handle changing array shapes.
00193     Bool canChangeShape() const;
00194 
00195     // Set the shape and tile shape of the hypercube.
00196     virtual void setShape (uInt rownr, TSMCube* hypercube,
00197                            const IPosition& shape,
00198                            const IPosition& tileShape);
00199 
00200     // Make the object from the type name string.
00201     // This function gets registered in the DataManager "constructor" map.
00202     static DataManager* makeObject (const String& dataManagerType,
00203                                     const Record& spec);
00204 
00205 private:
00206     // Create a TiledCellStMan.
00207     // This constructor is private, because it should only be used
00208     // by makeObject.
00209     TiledCellStMan();
00210 
00211     // Forbid copy constructor.
00212     TiledCellStMan (const TiledCellStMan&);
00213 
00214     // Forbid assignment.
00215     TiledCellStMan& operator= (const TiledCellStMan&);
00216 
00217     // Get the default tile shape.
00218     virtual IPosition defaultTileShape() const;
00219 
00220     // Add rows to the storage manager.
00221     void addRow (uInt nrrow);
00222 
00223     // Get the hypercube in which the given row is stored.
00224     virtual TSMCube* getHypercube (uInt rownr);
00225 
00226     // Get the hypercube in which the given row is stored.
00227     // It also returns the position of the row in that hypercube.
00228     virtual TSMCube* getHypercube (uInt rownr, IPosition& position);
00229 
00230     // Check if the hypercolumn definition fits this storage manager.
00231     virtual void setupCheck (const TableDesc& tableDesc,
00232                              const Vector<String>& dataNames) const;
00233 
00234     // Flush and optionally fsync the data.
00235     // It returns a True status if it had to flush (i.e. if data have changed).
00236     virtual Bool flush (AipsIO&, Bool fsync);
00237 
00238     // Let the storage manager create files as needed for a new table.
00239     // This allows a column with an indirect array to create its file.
00240     virtual void create (uInt nrrow);
00241 
00242     // Read the header info.
00243     virtual void readHeader (uInt nrrow, Bool firstTime);
00244 
00245 
00246     //# Declare the data members.
00247     IPosition defaultTileShape_p;
00248 };
00249 
00250 
00251 
00252 
00253 } //# NAMESPACE CASA - END
00254 
00255 #endif