casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ArrColDesc.h
Go to the documentation of this file.
00001 //# ArrColDesc.h: Templated class to describe columns of arrays in tables
00002 //# Copyright (C) 1994,1995,1996,1997,1999,2000
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: ArrColDesc.h 21051 2011-04-20 11:46:29Z gervandiepen $
00027 
00028 #ifndef TABLES_ARRCOLDESC_H
00029 #define TABLES_ARRCOLDESC_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <tables/Tables/BaseColDesc.h>
00034 #include <casa/Containers/SimOrdMap.h>
00035 #include <casa/Arrays/IPosition.h>
00036 
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 class PlainColumn;
00042 class ColumnSet;
00043 template<class T> class Array;
00044 
00045 // <summary>
00046 // Templated class for description of table array columns
00047 // </summary>
00048 
00049 // <use visibility=export>
00050 
00051 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
00052 // </reviewed>
00053 
00054 // <prerequisite>
00055 //   <li> BaseColumnDesc (and its prerequisites)
00056 //   <li> TableDesc
00057 // </prerequisite>
00058 
00059 // <etymology>
00060 // This class builds descriptions of table columns where each cell (which
00061 // may also be called a row) will hold an array.
00062 // </etymology>
00063 
00064 // <synopsis> 
00065 // ArrayColumnDesc is a templated class for defining a table column
00066 // containing arrays.
00067 //
00068 // The table values are handled by a data manager. This can be
00069 // a storage manager to store the values in a file or it can be
00070 // a virtual column engine to calculate them on-the-fly.
00071 // Only the basic data types are allowed when storing in a file. These are:
00072 //  Bool, uChar, Short, uShort, Int, uInt, float, double,
00073 //  Complex, DComplex and String.
00074 //
00075 // At table creation time (when a table gets created from a table
00076 // description), each column needs to be bound to a data manager.
00077 // If not done explicitly, the table system will bind a column to the
00078 // default manager defined in the column description.
00079 //
00080 // An array column description consists of the following attributes:
00081 // <ul>
00082 //  <li> Name, which has to be unique and must also be different
00083 //         from possible table keyword names.
00084 //  <li> Data type, which is determined by the template parameter
00085 //         (e.g. ArrayColumnDesc<Int>).
00086 //  <li> A data type id, which tells the unique name of non-standard
00087 //         data types (i.e. for data type == TpOther).
00088 //  <li> Comment, which defaults to the empty string.
00089 //         This serves purely as an informational string for the user.
00090 //  <li> Dimensionality. If given, all arrays in the column need
00091 //         to have that dimensionality.
00092 //  <li> Shape. If given, all arrays in the column need to have
00093 //         that shape.
00094 //  <li> Default data manager, which will be used if a column
00095 //         for a newly created table is not explicitly bound to a
00096 //         datamanager.
00097 //  <li> Data manager group, which serves 2 purposes.
00098 //         Firstly it can be used in class SetupNewTable to bind a group
00099 //         of columns.
00100 //         Secondly, when the default data managers are used, it
00101 //         allows, for example, to have 2 AipsIO storage managers.
00102 //         One for one group of columns and one for another group of columns.
00103 //  <li> Options. These are defined in ColumnDesc.h and can be combined
00104 //       by logically or-ing them.
00105 //       <ol>
00106 //        <li>
00107 //         ColumnDesc::FixedShape says that the arrays in all cells
00108 //         of a column have the same shape. This shape must be defined
00109 //         before a table is created. It does not tell if
00110 //         the array is direct or indirect.
00111 //         A FixedShape array is defined in every cell, while for
00112 //         non-FixedShape arrays a cell can be empty.
00113 //        <li>
00114 //         ColumnDesc::Direct determines if an array is directly
00115 //         stored in the table or if it is stored indirectly in a separate
00116 //         file. Direct arrays enforce the FixedShape option.
00117 //         Usually indirect arrays are only read in on command, while
00118 //         direct arrays are held in memory. So the size of the
00119 //         arrays is an important factor.
00120 //       </ol>
00121 //  <li> Default keyword set, which defaults to an empty set.
00122 //         When a table column gets created from the description, it gets
00123 //         a copy of this keyword set as its initial keyword set.
00124 // </ul>
00125 //
00126 // There are several constructors, which allow the definition of most
00127 // of the above mentioned attributes. Others, like the default keyword
00128 // set, have to be defined explicitly.
00129 //
00130 // This class is derived from BaseColumnDesc, thus the functions
00131 // in there also apply to this class.
00132 //
00133 // Once a column description is set up satisfactorily, it must be added
00134 // to a table description before it can be used by the table system.
00135 // </synopsis>
00136 
00137 // <example>
00138 // <srcblock>
00139 //     TableDesc tabDesc("tTableDesc", "1", TableDesc::New);
00140 //
00141 //     // Now define array columns.
00142 //     // This one is indirect and has no dimensionality mentioned yet.
00143 //     // Define the keyword UNIT in it.
00144 //     ArrayColumnDesc<Complex> arr1Column("Arr1", "comment for Arr1");
00145 //     arr1Column.rwKeywordSet().define ("UNIT", "Jy");
00146 //     tabDesc.addColumn (arr1Column);
00147 //
00148 //     // This one is indirect and has 3-dim arrays.
00149 //     tabDesc.addColumn (ArrayColumnDesc<Int>("Arr2",
00150 //                                             "comment for Arr2",
00151 //                                             3));
00152 //     // This one is direct and has 2-dim arrays with axis lengths 4 and 7.
00153 //     tabDesc.addColumn (ArrayColumnDesc<uInt>("Arr3",
00154 //                                              "comment for Arr1",
00155 //                                              IPosition(2,4,7),
00156 //                                              ColumnDesc::Direct));
00157 // </srcblock>
00158 // </example>
00159 
00160 // <motivation>
00161 // Several column description classes are needed to allow the user
00162 // to define attributes which are special for each column type.
00163 // For scalars the special attribute is the default value.
00164 // They all have to be templated to support arbitrary data types.
00165 // </motivation>
00166 
00167 // <templating arg=T>
00168 //  <li> Default constructor
00169 //  <li> Copy constructor
00170 //  <li> Assignment operator
00171 //  <li> <src>static String dataTypeId();  // (not needed for builtin types)</src>
00172 //       This should return the unique "name" of the class.
00173 // </templating>
00174 
00175 //# <todo asof="$DATE:$">
00176 //# A List of bugs, limitations, extensions or planned refinements.
00177 //# </todo>
00178 
00179 template<class T>
00180 class ArrayColumnDesc : public BaseColumnDesc
00181 {
00182 friend class ColumnDesc;
00183 
00184 public:
00185     // Construct the column with the given name and dimensionality.
00186     // The data manager type defaults to the StandardStman storage manager.
00187     // The data manager group defaults to the data manager type.
00188     // Ndim <=0 means that the number of dimensions is free and will
00189     // be defined when creating the table (rows). Ndim>0 means that
00190     // the arrays in this column must have the given dimensionality.
00191     // The possible options are defined in ColumnDesc.h.
00192     explicit ArrayColumnDesc (const String& name, Int ndim = -1,
00193                               int options = 0);
00194 
00195     // Construct the column with the given name, dimensionality, and comment.
00196     // The data manager type defaults to the StandardStman storage manager.
00197     // The data manager group defaults to the data manager type.
00198     // Ndim <=0 means that the number of dimensions is free and will
00199     // be defined when creating the table (rows). Ndim>0 means that
00200     // the arrays in this column must have the given dimensionality.
00201     // The possible options are defined in ColumnDesc.h.
00202     ArrayColumnDesc (const String& name, const String& comment,
00203                      Int ndim = -1, int options = 0);
00204 
00205     // Construct the column with the given name, dimensionality, comment,
00206     // and default data manager type and group.
00207     // A blank data manager group defaults to the data manager type.
00208     // Ndim <=0 means that the number of dimensions is free and will
00209     // be defined when creating the table (rows). Ndim>0 means that
00210     // the arrays in this column must have the given dimensionality.
00211     // The possible options are defined in ColumnDesc.h.
00212     ArrayColumnDesc (const String& name, const String& comment,
00213                      const String& dataManName, const String& dataManGroup,
00214                      Int ndim = -1, int options = 0);
00215 
00216     // Construct the column with the given name and shape.
00217     // The data manager type defaults to the StandardStman storage manager.
00218     // The data manager group defaults to the data manager type.
00219     // The possible options are defined in ColumnDesc.h.
00220     // This constructor can only be used for FixedShape arrays, because the
00221     // shape of other arrays can only be set per row.
00222     ArrayColumnDesc (const String& name,
00223                      const IPosition& shape, int options = 0);
00224 
00225     // Construct the column with the given name, shape, and comment.
00226     // The data manager type defaults to the StandardStman storage manager.
00227     // The data manager group defaults to the data manager type.
00228     // The possible options are defined in ColumnDesc.h.
00229     // This constructor can only be used for FixedShape arrays, because the
00230     // shape of other arrays can only be set per row.
00231     ArrayColumnDesc (const String& name, const String& comment,
00232                      const IPosition& shape, int options = 0);
00233 
00234     // Construct the column with the given name, shape, comment,
00235     // and default data manager type and group.
00236     // A blank data manager group defaults to the data manager type.
00237     // The possible options are defined in ColumnDesc.h.
00238     // This constructor can only be used for FixedShape arrays, because the
00239     // shape of other arrays can only be set per row.
00240     // If both ndim and shape are given as > 0, ndim should match the length
00241     // of shape.
00242     ArrayColumnDesc (const String& name, const String& comment,
00243                      const String& dataManName, const String& dataManGroup,
00244                      const IPosition& shape, int options = 0, int ndim=-1);
00245 
00246     // Copy constructor (copy semantics);
00247     ArrayColumnDesc (const ArrayColumnDesc<T>&);
00248 
00249     ~ArrayColumnDesc();
00250 
00251     // Assignment (copy semantics);
00252     ArrayColumnDesc<T>& operator= (const ArrayColumnDesc<T>&);
00253 
00254     // Clone this column description to another.
00255     BaseColumnDesc* clone() const;
00256 
00257     // Get the name of this class. It is used by the registration process.
00258     // The template argument gets part of the name.
00259     String className() const;
00260 
00261     // Create a Column object out of this.
00262     // This is used by class ColumnSet to construct a table column object.
00263     virtual PlainColumn* makeColumn (ColumnSet*) const;
00264 
00265     // Show the column.
00266     void show (ostream& os) const;
00267 
00268     // Register the construction function of this class.
00269     void registerClass() const;
00270 
00271     // Create the object from AipsIO (this function is registered).
00272     static BaseColumnDesc* makeDesc(const String& name);
00273 
00274 protected:
00275     // Put the object.
00276     virtual void putDesc (AipsIO&) const;
00277 
00278     // Get the object.
00279     virtual void getDesc (AipsIO&);
00280 };
00281 
00282 
00283 
00284 } //# NAMESPACE CASA - END
00285 
00286 #ifndef CASACORE_NO_AUTO_TEMPLATES
00287 #include <tables/Tables/ArrColDesc.tcc>
00288 #endif //# CASACORE_NO_AUTO_TEMPLATES
00289 #endif