casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DataManager.h
Go to the documentation of this file.
00001 //# DataManager.h: Abstract base classes for a data manager
00002 //# Copyright (C) 1994,1995,1996,1997,1998,1999,2001,2002
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: DataManager.h 21295 2012-11-30 16:00:01Z gervandiepen $
00027 
00028 #ifndef TABLES_DATAMANAGER_H
00029 #define TABLES_DATAMANAGER_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/ColumnCache.h>
00035 #include <tables/Tables/TSMOption.h>
00036 #include <casa/BasicSL/String.h>
00037 #include <casa/BasicSL/Complex.h>
00038 #include <casa/Containers/SimOrdMap.h>
00039 #include <casa/IO/ByteIO.h>
00040 #include <casa/OS/Mutex.h>
00041 #include<iosfwd>
00042 
00043 namespace casa { //# NAMESPACE CASA - BEGIN
00044 
00045 //# Forward Declarations
00046 class DataManager;
00047 class DataManagerColumn;
00048 class SetupNewTable;
00049 class Table;
00050 class Record;
00051 class IPosition;
00052 class Slicer;
00053 class RefRows;
00054 template<class T> class Array;
00055 class AipsIO;
00056 
00057 
00058 // <summary>
00059 // Define the type of the static "constructor" function.
00060 // </summary>
00061 // <use visibility=local>
00062 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
00063 // </reviewed>
00064 
00065 // <synopsis>
00066 // Class names of data managers and pointers to their associated constructor
00067 // function are registered in a static map to be able to create the correct
00068 // data manager object from a string giving the type name of the data manager.
00069 // DataManagerCtor is the type of the constructor functions.
00070 // </synopsis>
00071 // <group name=DataManagerCtor>
00072 typedef DataManager* (*DataManagerCtor) (const String& dataManagerType,
00073                                          const Record& spec);
00074 // </group>
00075 
00076 
00077 // <summary>
00078 // Abstract base class for a data manager
00079 // </summary>
00080 
00081 // <use visibility=local>
00082 
00083 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
00084 // </reviewed>
00085 
00086 // <prerequisite>
00087 //# Classes you should understand before using this one.
00088 // </prerequisite>
00089 
00090 // <synopsis> 
00091 // DataManager is the abstract base class for all kind of table data managers.
00092 // There are currently 2 classes of data managers:
00093 // <ul>
00094 //  <li> Storage managers handling the storage of data. These classes
00095 //         have to be derived from DataManager.
00096 //         StManAipsIO is an example of a storage manager.
00097 //  <li> Virtual column engines handling the on-the-fly calculation
00098 //         of data, which are not stored as such. The base class for
00099 //         these is VirtualColumnEngine (which is derived from DataManager),
00100 //         from which all virtual columns engine must be derived from.
00101 // </ul>
00102 // DataManager contains some common data and defines several virtual
00103 // functions, which usually have to be implemented in the derived classes.
00104 // It also contains some helper functions for the derived classes
00105 // (like fileName().
00106 //
00107 // The actual handling of a column by the data manager is defined in
00108 // the abstract base class
00109 // <linkto class="DataManagerColumn:description">DataManagerColumn</linkto>.
00110 // Each data manager must
00111 // have an associated class (derived from DataManagerColumn) to
00112 // handle the columns.
00113 //
00114 // There is a protocol defined how a data manager is created and
00115 // initialized. For a new table it is:
00116 // <ul>
00117 //  <li>
00118 //   The user creates data managers and binds them to columns. For example:
00119 //   <srcblock>
00120 //   SetupNewTable newtab("name.data", Table::New);  // set up new table
00121 //   StManAipsIO stman;                       // define storage manager
00122 //   newtab.bindColumn ("column1", stman);    // bind column to st.man.
00123 //   newtab.bindColumn ("column2", stman);    // bind column to st.man.
00124 //   Table tab(newtab);                       // actually create table
00125 //   </srcblock>
00126 //   When the given data manager object is used for the first time in a bind
00127 //   function, a copy of the object is made using the clone function.
00128 //   Thus in the above example column1 and column2 share the same data
00129 //   manager; only at the first bind the stman object is cloned.
00130 //   Columns not explicitly bound to a data manager get implicitly bound
00131 //   to the default data manager (as defined in the column description)
00132 //   by the Table constructor (as used in line 5).
00133 //  <li>
00134 //   After binding the unbound columns, the PlainTable constructor sets up
00135 //   the data managers. For each column it asks the data manager to
00136 //   construct a DataManagerColumn object (in fact, an object of a class
00137 //   derived from DataManagerColumn). This is done by the functions
00138 //   createScalarColumn, createIndArrColumn and createDirArrColumn.
00139 //   For each data manager the create function is called. This allows
00140 //   them to initialize themselves and/or to call an initialization
00141 //   function in their column objects.
00142 //   This is, for instance, used by the storage managers to create files.
00143 //   Thereafter the prepare function is called to allow the data managers
00144 //   to do further initialization possibly requiring information from
00145 //   other columns.
00146 //  <li>
00147 //   When the table gets written (by the PlainTable destructor),
00148 //   the flush function is called for each data manager. This allows
00149 //   the data manager or their column objects to write or flush their data.
00150 //   The table system takes care of storing the information required
00151 //   to reconstruct the data managers. It uses the function dataManagerType
00152 //   to store the (unique) type name of the data manager class.
00153 //  <li>
00154 //   Finally each data manager object gets deleted. Their destructors
00155 //   must delete their column objects (if any and if needed).
00156 // </ul>
00157 // For an existing table the procedure is slightly different:
00158 // <ul>
00159 //  <li>
00160 //   The statement
00161 //   <br><src> Table tab("name.data"); </src>
00162 //   will create a table object for an existing table. This has the effect
00163 //   that the given table file will be read to reconstruct the Table object
00164 //   and the data managers.
00165 //  <li>
00166 //   The stored data manager class names are used to reconstruct
00167 //   the data managers. This uses the static registration map, which
00168 //   maps the class name to a static class constructor function (usually
00169 //   called makeObject). This requires that the type name and constructor
00170 //   for each possible data manager are registered before the table
00171 //   is opened. The DataManager function registerMainCtor (implemented
00172 //   in DataManager.cc) is called before a table is opened, so registration
00173 //   of data managers should, in principle, be done there.
00174 //   <br>However, for unknown data managers it is tried to load a shared
00175 //   library whose name is the lowercase version of the data manager without a
00176 //   possible template argument (e.g. <src>bitflagsengine</src> for
00177 //   data manager <src>BitFlagsEngine<Int></src>).
00178 //   It can be preceeded by lib or libcasa_ and followed by .so or .dylib.
00179 //   The shared library has to have a function with a name like
00180 //   <src>register_bitflagsengine</src> that must register the data manager(s).
00181 //   The function must be declared as <src>extern "C"</src>, otherwise its
00182 //   name gets mangled.
00183 //  <li>
00184 //   Each table column is bound to the correct data manager. The sequence
00185 //   number stored in the table file is used for that purpose.
00186 //  <li>
00187 //   The DataManager createXXXColumn functions are called for each table
00188 //   column to let the data manager construct a data manager column object.
00189 //  <li>
00190 //   For each data manager the open function is called to allow it and
00191 //   its column objects to read back the information stored in the
00192 //   flush function.
00193 //   Thereafter the prepare function is called for each data manager
00194 //   to allow it to initialize some variables.
00195 //   The reason that open and prepare are separated is that in order to
00196 //   initialize variables it may be required to use other columns.
00197 //   So it may be needed that all columns are read back before they
00198 //   get initialized.
00199 //  <li>
00200 //   Similar to a new table the flush functions gets called when the
00201 //   table gets written. Destruction is also the same as sketched
00202 //   for new tables.
00203 // </ul>
00204 // </synopsis> 
00205 
00206 // <motivation>
00207 // An abstract base class is needed to support data managers and
00208 // virtual column engines in the table system in a transparant way.
00209 // </motivation>
00210 
00211 // <todo asof="$DATE:$">
00212 //# A List of bugs, limitations, extensions or planned refinements.
00213 //  <li> Handle unregistered data managers in a better way.
00214 //         Instead of throwing an exception a subprocess could be
00215 //         started which represents the data manager.
00216 // </todo>
00217 
00218 
00219 class DataManager
00220 {
00221 friend class SetupNewTable;
00222 friend class ColumnSet;
00223 
00224 public:
00225 
00226     // Default constructor.
00227     DataManager();
00228 
00229     virtual ~DataManager();
00230 
00231     // Make a clone of the derived object.
00232     virtual DataManager* clone() const = 0;
00233 
00234     // Return the name of the data manager. This is the name of this
00235     // instantiation of the data manager, thus not its type name.
00236     // By default it returns an empty string.
00237     virtual String dataManagerName() const;
00238 
00239     // Return the type name of the data manager (in fact its class name).
00240     // It has to be a unique name, thus if the class is templated
00241     // the template parameter has to be part of the name.
00242     // This is used by the open/flush mechanism to be able to reconstruct
00243     // the correct data manager.
00244     virtual String dataManagerType() const = 0;
00245 
00246     // Add SEQNR and SPEC (the DataManagerSpec subrecord) to the info.
00247     void dataManagerInfo (Record& info) const;
00248 
00249     // Return a record containing data manager specifications.
00250     // The default implementation returns an empty record.
00251     virtual Record dataManagerSpec() const;
00252 
00253     // Get data manager properties that can be modified.
00254     // It is a subset of the data manager specification.
00255     // The default implementation returns an empty record.
00256     virtual Record getProperties() const;
00257 
00258     // Modify data manager properties given in record fields. Only the
00259     // properties as returned by getProperties are used, others are ignored.
00260     // The default implementation does nothing.
00261     virtual void setProperties (const Record& spec);
00262 
00263     // Is the data manager a storage manager?
00264     // The default is yes.
00265     virtual Bool isStorageManager() const;
00266 
00267     // Tell if the data manager wants to reallocate the data manager
00268     // column objects.
00269     // This is used by the tiling storage manager.
00270     // By default it returns False.
00271     virtual Bool canReallocateColumns() const;
00272 
00273     // Reallocate the column object if it is part of this data manager.
00274     // It returns a pointer to the new column object.
00275     // This function is used by the tiling storage manager.
00276     // By default it does nothing and returns the input pointer.
00277     virtual DataManagerColumn* reallocateColumn (DataManagerColumn* column);
00278     
00279     // Get the (unique) sequence nr of this data manager.
00280     uInt sequenceNr() const
00281         { return seqnr_p; }
00282 
00283     // Get the nr of columns in this data manager (can be zero).
00284     uInt ncolumn() const
00285         { return nrcol_p; }
00286 
00287     // Have the data to be stored in big or little endian canonical format?
00288     Bool asBigEndian() const
00289       { return asBigEndian_p; }
00290 
00291     // Get the TSM option.
00292     const TSMOption& tsmOption() const
00293       { return tsmOption_p; }
00294 
00295     // Compose a keyword name from the given keyword appended with the
00296     // sequence number (e.g. key_0).
00297     // This makes the keyword name unique if multiple data managers
00298     // are used with the same type.
00299     String keywordName (const String& keyword) const;
00300 
00301     // Compose a unique filename from the table name and sequence number.
00302     String fileName() const;
00303 
00304     // Get the AipsIO option of the underlying file.
00305     ByteIO::OpenOption fileOption() const;
00306 
00307     // Is this a regular storage manager?
00308     // It is regular if it allows addition of rows and writing dara in them.
00309     // <br>The default implementation returns True.
00310     virtual Bool isRegular() const;
00311 
00312     // Get the table this object is associated with.
00313     Table& table() const
00314         { return *table_p; }
00315 
00316     // Reopen the data manager for read/write access.
00317     // By default it is assumed that a reopen for read/write does
00318     // not have to do anything.
00319     virtual void reopenRW();
00320 
00321     // Does the data manager allow to add rows? (default no)
00322     virtual Bool canAddRow() const;
00323 
00324     // Does the data manager allow to delete rows? (default no)
00325     virtual Bool canRemoveRow() const;
00326 
00327     // Does the data manager allow to add columns? (default no)
00328     virtual Bool canAddColumn() const;
00329 
00330     // Does the data manager allow to delete columns? (default no)
00331     virtual Bool canRemoveColumn() const;
00332 
00333     // Set the maximum cache size (in bytes) to be used by a storage manager.
00334     // The default implementation does nothing.
00335     virtual void setMaximumCacheSize (uInt nbytes);
00336 
00337     // Show the data manager's IO statistics. By default it does nothing.
00338     virtual void showCacheStatistics (std::ostream&) const;
00339 
00340     // Create a column in the data manager on behalf of a table column.
00341     // It calls makeXColumn and checks the data type.
00342     // <group>
00343     // Create a scalar column.
00344     // The <src>dataTypeId</src> argument is gives the id (i.e. name)
00345     // of the data type of the column. It is only used for virtual
00346     // columns of a non-standard data type to be able to check if
00347     // the correctness of the column data type.
00348     // <br>Storage managers only handle standard data types and
00349     // can readily ignore this argument.
00350     DataManagerColumn* createScalarColumn (const String& columnName,
00351                                            int dataType,
00352                                            const String& dataTypeId);
00353     // Create a direct array column.
00354     DataManagerColumn* createDirArrColumn (const String& columnName,
00355                                            int dataType,
00356                                            const String& dataTypeId);
00357     // Create an indirect array column.
00358     DataManagerColumn* createIndArrColumn (const String& columnName,
00359                                            int dataType,
00360                                            const String& dataTypeId);
00361     // </group>
00362 
00363     // The data manager will be deleted (because all its columns are
00364     // requested to be deleted).
00365     // So clean up the things needed (e.g. delete files).
00366     virtual void deleteManager() = 0;
00367 
00368 
00369 protected:
00370     // Decrement number of columns (in case a column is deleted).
00371     void decrementNcolumn()
00372         { nrcol_p--; }
00373 
00374     // Tell the data manager if big or little endian format is needed.
00375     void setEndian (Bool bigEndian)
00376       { asBigEndian_p = bigEndian; }
00377 
00378     // Tell the data manager which TSM option to use.
00379     void setTsmOption (const TSMOption& tsmOption)
00380       { tsmOption_p = tsmOption; }
00381 
00382     // Throw an exception in case data type is TpOther, because the
00383     // storage managers (and maybe other data managers) do not support
00384     // such columns.
00385     void throwDataTypeOther (const String& columnName, int dataType) const;
00386 
00387 
00388 private:
00389     uInt         nrcol_p;            //# #columns in this st.man.
00390     uInt         seqnr_p;            //# Unique nr of this st.man. in a Table
00391     Bool         asBigEndian_p;      //# store data in big or little endian
00392     TSMOption    tsmOption_p;
00393     Table*       table_p;            //# Table this data manager belongs to
00394     mutable DataManager* clone_p;    //# Pointer to clone (used by SetupNewTab)
00395 
00396 
00397     // The copy constructor cannot be used for this base class.
00398     // The clone function should be used instead.
00399     // The private declaration of this constructor makes it unusable.
00400     DataManager (const DataManager&);
00401 
00402     // Assignment cannot be used for this base class.
00403     // The private declaration of this operator makes it unusable.
00404     DataManager& operator= (const DataManager&);
00405 
00406     // Create a column in the data manager on behalf of a table column.
00407     //# Should be private, but has to be public because friend
00408     //# declaration gave internal CFront error.
00409     // <group>
00410     // Create a scalar column.
00411     virtual DataManagerColumn* makeScalarColumn (const String& columnName,
00412                                                  int dataType,
00413                                                  const String& dataTypeId) = 0;
00414     // Create a direct array column.
00415     virtual DataManagerColumn* makeDirArrColumn (const String& columnName,
00416                                                  int dataType,
00417                                                  const String& dataTypeId) = 0;
00418     // Create an indirect array column.
00419     virtual DataManagerColumn* makeIndArrColumn (const String& columnName,
00420                                                  int dataType,
00421                                                  const String& dataTypeId) = 0;
00422     // </group>
00423 
00424     // Check if the data type of the created data manager column is correct.
00425     void checkDataType (const DataManagerColumn* colPtr,
00426                         const String& columnName,
00427                         int dataType, const String& dataTypeId) const;
00428 
00429     // Add rows to all columns.
00430     // The default implementation throws a "not possible" exception.
00431     virtual void addRow (uInt nrrow);
00432 
00433     // Delete a row from all columns.
00434     // The default implementation throws a "not possible" exception.
00435     virtual void removeRow (uInt rownr);
00436 
00437     // Add a column.
00438     // The default implementation throws a "not possible" exception.
00439     virtual void addColumn (DataManagerColumn*);
00440 
00441     // Delete a column.
00442     // The default implementation throws a "not possible" exception.
00443     virtual void removeColumn (DataManagerColumn*);
00444 
00445     // Set the sequence number of this data manager.
00446     void setSeqnr (uInt nr)
00447         { seqnr_p = nr; }
00448 
00449     // Link the data manager to the Table object.
00450     void linkToTable (Table& tab);
00451 
00452     // Flush and optionally fsync the data.
00453     // The AipsIO stream represents the main table file and can be
00454     // used by virtual column engines to store SMALL amounts of data.
00455     // It returns a True status if it had to flush (i.e. if data have changed).
00456     virtual Bool flush (AipsIO& ios, Bool fsync) = 0;
00457 
00458     // Let the data manager initialize itself for a new table.
00459     virtual void create (uInt nrrow) = 0;
00460 
00461     // Let the data manager initialize itself for an existing table.
00462     // The AipsIO stream represents the main table file and must be
00463     // used by virtual column engines to retrieve the data stored
00464     // in the flush function.
00465     virtual void open (uInt nrrow, AipsIO& ios) = 0;
00466 
00467     // Open as above.
00468     // The data manager can return the number of rows it thinks there are.
00469     // This is particularly useful for data managers like LofarStMan whose
00470     // data are written outside the table system, thus for which no rows
00471     // have been added.
00472     // <br>By default it calls open and returns <src>nrrow</src>.
00473     virtual uInt open1 (uInt nrrow, AipsIO& ios);
00474 
00475     // Resync the data by rereading cached data from the file.
00476     // This is called when a lock is acquired on the file and it appears 
00477     // that data in this data manager has been changed by another process.
00478     virtual void resync (uInt nrrow) = 0;
00479 
00480     // Resync as above.
00481     // The data manager can return the number of rows it thinks there are.
00482     // This is particularly useful for data managers like LofarStMan whose
00483     // data are written outside the table system, thus for which no rows
00484     // have been added.
00485     // <br>By default it calls resync and returns <src>nrrow</src>.
00486     virtual uInt resync1 (uInt nrrow);
00487 
00488     // Let the data manager initialize itself further.
00489     // Prepare is called after create/open has been called for all
00490     // columns. In this way one can be sure that referenced columns
00491     // are read back and partly initialized.
00492     // The default implementation does nothing.
00493     virtual void prepare();
00494 
00495     // Declare the mapping of the data manager type name to a static
00496     // "makeObject" function.
00497     static SimpleOrderedMap<String,DataManagerCtor> theirRegisterMap;
00498     static MutexedInit theirMutexedInit;
00499 
00500 public:
00501     // Has the object already been cloned?
00502     DataManager* getClone() const
00503         { return clone_p; }
00504 
00505     // Set the pointer to the clone.
00506     void setClone (DataManager* clone) const
00507         { clone_p = clone; }
00508 
00509     // Register a mapping of a data manager type to its static construction
00510     // function. It is fully thread-safe.
00511     static void registerCtor (const String& type, DataManagerCtor func);
00512 
00513     // Get the "constructor" of a data manager (thread-safe).
00514     static DataManagerCtor getCtor (const String& dataManagerType);
00515 
00516     // Test if a data manager is registered (thread-safe).
00517     static Bool isRegistered (const String& dataManagerType);
00518 
00519     // Register the main data managers (if not done yet).
00520     // It is fully thread-safe.
00521     static void registerMainCtor()
00522       { theirMutexedInit.exec(); }
00523 
00524     // Serve as default function for theirRegisterMap, which catches all
00525     // unknown data manager types.
00526     // <thrown>
00527     //   <li> TableUnknownDataManager
00528     // </thrown>
00529     static DataManager* unknownDataManager (const String& dataManagerType,
00530                                             const Record& spec);
00531 
00532 private:
00533     // Register a data manager constructor.
00534     static void unlockedRegisterCtor (const String& type,
00535                                       DataManagerCtor func)
00536       { theirRegisterMap.define (type, func); }
00537 
00538     // Do the actual (thread-safe) registration of the main data managers.
00539     static void doRegisterMainCtor (void*);
00540 };
00541 
00542 
00543 
00544 
00545 // <summary>
00546 // Abstract base class for a column in a data manager
00547 // </summary>
00548 
00549 // <use visibility=local>
00550 
00551 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
00552 // </reviewed>
00553 
00554 // <prerequisite>
00555 //# Classes you should understand before using this one.
00556 //   <li> DataManager
00557 // </prerequisite>
00558 
00559 // <etymology>
00560 // DataManagerColumn handles a column for a data manager.
00561 // </etymology>
00562 
00563 // <synopsis> 
00564 // DataManagerColumn is the abstract base class to handle a column in
00565 // a data manager. Each data manager class must have one or more associated
00566 // classes derived from DataManagerColumn to handle the columns.
00567 // For example, storage manager StManAipsIO has columns classes
00568 // StManColumnAipsIO, StManColumnArrayAipsIO and StManColumnIndArrayAipsIO
00569 // to handle scalars, direct arrays and indirect arrays, resp..
00570 // However, using multiple inheritance it is possible that the derived
00571 // DataManager and DataManagerColumn classes are the same. This is used
00572 // in class ScaledArrayEngine<S,T> which represents both the data manager
00573 // and its column class. It can do that, because the virtual column engine
00574 // <linkto class="ScaledArrayEngine:description">ScaledArrayEngine</linkto>
00575 // can handle only one column.
00576 //
00577 // In the synopsis of class DataManager it is described how the (derived)
00578 // DataManagerColumn objects gets created and deleted.
00579 // 
00580 // DataManagerColumn defines various virtual functions to get or put (slices)
00581 // of data in a column. These functions are called by the table column
00582 // classes ScalarColumnData and ArrayColumnData.
00583 // It does not define functions create, open, flush and prepare like
00584 // those defined in DataManager. It is left to the derived classes to
00585 // define those as needed and to interact properly with their
00586 // data manager object.
00587 // </synopsis> 
00588 
00589 // <motivation>
00590 // An abstract base class is needed to support multiple data
00591 // managers in the table system
00592 // </motivation>
00593 
00594 // <todo asof="$DATE:$">
00595 //# A List of bugs, limitations, extensions or planned refinements.
00596 // </todo>
00597 
00598 
00599 class DataManagerColumn
00600 {
00601 public:
00602 
00603     // Create a column.
00604     DataManagerColumn()
00605         : isFixedShape_p(False) {;}
00606 
00607     // Frees up the storage.
00608     virtual ~DataManagerColumn();
00609 
00610     // Set the isFixedShape flag.
00611     void setIsFixedShape (Bool isFixedShape)
00612         { isFixedShape_p = isFixedShape; }
00613 
00614     // Is this a fixed shape column?
00615     Bool isFixedShape() const
00616         { return isFixedShape_p; }
00617 
00618     // Get the data type of the column as defined in DataType.h.
00619     virtual int dataType() const = 0;
00620 
00621     // Get the data type id of the column for dataType==TpOther.
00622     // The default implementation returns an emptry string.
00623     // This function is required for virtual column engines handling
00624     // non-standard data types. It is used to check the data type.
00625     virtual String dataTypeId() const;
00626 
00627     // Test if data can be put into this column.
00628     // This does not test if the data file is writable, only if
00629     // it is in principle allowed to store data into the column.
00630     // (It may not be allowed for virtual columns).
00631     // The default is True.
00632     virtual Bool isWritable() const;
00633 
00634     // Set the maximum length of the value (can be used for strings).
00635     // By default the maximum length is ignored.
00636     virtual void setMaxLength (uInt maxLength);
00637 
00638     // Set the shape of all (fixed-shaped) arrays in the column.
00639     // Effectively it is the same as setShapeColumn, but it also sets
00640     // the isFixedShape_p flag.
00641     void setFixedShapeColumn (const IPosition& shape)
00642         { setShapeColumn (shape); isFixedShape_p = True; }
00643 
00644     // Set the shape of an (variable-shaped) array in the given row.
00645     // By default it throws a "not possible" exception.
00646     virtual void setShape (uInt rownr, const IPosition& shape);
00647 
00648     // Set the shape and tile shape of an (variable-shaped) array
00649     // in the given row.
00650     // By default it ignores the tile shape (thus only sets the shape).
00651     virtual void setShapeTiled (uInt rownr, const IPosition& shape,
00652                                 const IPosition& tileShape);
00653 
00654     // Is the value shape defined in the given row?
00655     // By default it returns True.
00656     virtual Bool isShapeDefined (uInt rownr);
00657 
00658     // Get the dimensionality of the item in the given row.
00659     // By default it returns shape(rownr).nelements().
00660     virtual uInt ndim (uInt rownr);
00661 
00662     // Get the shape of the item in the given row.
00663     // By default it returns a zero-length IPosition (for a scalar value).
00664     virtual IPosition shape (uInt rownr);
00665 
00666     // Can the data manager handle chaging the shape of an existing array?
00667     // Default is no.
00668     virtual Bool canChangeShape() const;
00669 
00670     // Can the column data manager handle access to a scalar column?
00671     // If not, the caller should access the column by looping through
00672     // all cells in the column.
00673     // Default is no.
00674     // <br>
00675     // The returned reask switch determines if the information is
00676     // permanent. False indicates it is permanent; True indicates it
00677     // will be reasked for the next get/putColumn.
00678     // By default reask is set to False.
00679     virtual Bool canAccessScalarColumn (Bool& reask) const;
00680 
00681     // Can the column data manager handle access to a clooection of cells
00682     // in a scalar column?
00683     // If not, the caller should access the column cells by looping through
00684     // the cells in the column.
00685     // Default is no.
00686     // <br>
00687     // The returned reask switch determines if the information is
00688     // permanent. False indicates it is permanent; True indicates it
00689     // will be reasked for the next get/putColumn.
00690     // By default reask is set to False.
00691     virtual Bool canAccessScalarColumnCells (Bool& reask) const;
00692 
00693     // Can the column data manager handle access to a scalar column?
00694     // If not, the caller should access the column by looping through
00695     // all cells in the column.
00696     // Default is no.
00697     // <br>
00698     // The returned reask switch determines if the information is
00699     // permanent. False indicates it is permanent; True indicates it
00700     // will be reasked for the next get/putColumn.
00701     // By default reask is set to False.
00702     virtual Bool canAccessArrayColumn (Bool& reask) const;
00703 
00704     // Can the column data manager handle access to a collection of cells
00705     // in an array column?
00706     // If not, the caller should access the column cells by looping through
00707     // the cells in the column.
00708     // Default is no.
00709     // <br>
00710     // The returned reask switch determines if the information is
00711     // permanent. False indicates it is permanent; True indicates it
00712     // will be reasked for the next get/putColumn.
00713     // By default reask is set to False.
00714     virtual Bool canAccessArrayColumnCells (Bool& reask) const;
00715 
00716     // Can the column data manager handle access to a cell slice?
00717     // If not, the caller should do slicing itself (by accessing the
00718     // entire array and slicing it).
00719     // Default is no.
00720     // <br>
00721     // The returned reask switch determines if the information is
00722     // permanent. False indicates it is permanent; True indicates it
00723     // will be reasked for the next get/putColumn.
00724     // By default reask is set to False.
00725     virtual Bool canAccessSlice (Bool& reask) const;
00726 
00727     // Can the column data manager handle access to a column slice?
00728     // If not, the caller should access the column slice by looping through
00729     // all cell slices in the column.
00730     // Default is no.
00731     // <br>
00732     // The returned reask switch determines if the information is
00733     // permanent. False indicates it is permanent; True indicates it
00734     // will be reasked for the next get/putColumn.
00735     // By default reask is set to False.
00736     virtual Bool canAccessColumnSlice (Bool& reask) const;
00737 
00738     // Get access to the ColumnCache object.
00739     // <group>
00740     ColumnCache& columnCache()
00741         { return colCache_p; }
00742     const ColumnCache* columnCachePtr() const
00743         { return &colCache_p; }
00744     // </group>
00745 
00746     // Get the scalar value in the given row.
00747     // These functions are non-virtual and are converted to their
00748     // virtual getV equivalent to achieve that a derived templated class
00749     //(like VirtualScalarColumn) does not have to declare and implement
00750     // all these functions.
00751     // The compiler complains about hiding virtual functions if you do not
00752     // declare all virtual functions with the same name in a derived class.
00753     // <group>
00754     void get (uInt rownr, Bool* dataPtr)
00755         { getBoolV (rownr, dataPtr); }
00756     void get (uInt rownr, uChar* dataPtr)
00757         { getuCharV (rownr, dataPtr); }
00758     void get (uInt rownr, Short* dataPtr)
00759         { getShortV (rownr, dataPtr); }
00760     void get (uInt rownr, uShort* dataPtr)
00761         { getuShortV (rownr, dataPtr); }
00762     void get (uInt rownr, Int* dataPtr)
00763         { getIntV (rownr, dataPtr); }
00764     void get (uInt rownr, uInt* dataPtr)
00765         { getuIntV (rownr, dataPtr); }
00766     void get (uInt rownr, float* dataPtr)
00767         { getfloatV (rownr, dataPtr); } 
00768    void get (uInt rownr, double* dataPtr)
00769         { getdoubleV (rownr, dataPtr); }
00770     void get (uInt rownr, Complex* dataPtr)
00771         { getComplexV (rownr, dataPtr); }
00772     void get (uInt rownr, DComplex* dataPtr)
00773         { getDComplexV (rownr, dataPtr); }
00774     void get (uInt rownr, String* dataPtr)
00775         { getStringV (rownr, dataPtr); }
00776     // This function is the get for all non-standard data types.
00777     void get (uInt rownr, void* dataPtr)
00778         { getOtherV (rownr, dataPtr); }
00779     // </group>
00780 
00781     // Put the scalar value into the given row.
00782     // These functions are non-virtual and are converted to their
00783     // virtual putV equivalent to achieve that a derived templated class
00784     //(like VirtualScalarColumn) does not have to declare and implement
00785     // all these functions.
00786     // The compiler complains about hiding virtual functions if you do not
00787     // declare all virtual functions with the same name in a derived class.
00788     // <group>
00789     void put (uInt rownr, const Bool* dataPtr)
00790         { putBoolV (rownr, dataPtr); }
00791     void put (uInt rownr, const uChar* dataPtr)
00792         { putuCharV (rownr, dataPtr); }
00793     void put (uInt rownr, const Short* dataPtr)
00794         { putShortV (rownr, dataPtr); }
00795     void put (uInt rownr, const uShort* dataPtr)
00796         { putuShortV (rownr, dataPtr); }
00797     void put (uInt rownr, const Int* dataPtr)
00798         { putIntV (rownr, dataPtr); }
00799     void put (uInt rownr, const uInt* dataPtr)
00800         { putuIntV (rownr, dataPtr); }
00801     void put (uInt rownr, const float* dataPtr)
00802         { putfloatV (rownr, dataPtr); }
00803     void put (uInt rownr, const double* dataPtr)
00804         { putdoubleV (rownr, dataPtr); }
00805     void put (uInt rownr, const Complex* dataPtr)
00806         { putComplexV (rownr, dataPtr); }
00807     void put (uInt rownr, const DComplex* dataPtr)
00808         { putDComplexV (rownr, dataPtr); }
00809     void put (uInt rownr, const String* dataPtr)
00810         { putStringV (rownr, dataPtr); }
00811     // This function is the put for all non-standard data types.
00812     void put (uInt rownr, const void* dataPtr)
00813         { putOtherV (rownr, dataPtr); }
00814     // </group>
00815 
00816     // Get all scalar values in the column.
00817     // The argument dataPtr is in fact a Vector<T>*, but a void*
00818     // is needed to be generic.
00819     // The vector pointed to by dataPtr has to have the correct length
00820     // (which is guaranteed by the ScalarColumn getColumn function).
00821     // The default implementation throws an "invalid operation" exception.
00822     virtual void getScalarColumnV (void* dataPtr);
00823 
00824     // Put all scalar values in the column.
00825     // The argument dataPtr is in fact a const Vector<T>*, but a const void*
00826     // is needed to be generic.
00827     // The vector pointed to by dataPtr has to have the correct length
00828     // (which is guaranteed by the ScalarColumn putColumn function).
00829     // The default implementation throws an "invalid operation" exception.
00830     virtual void putScalarColumnV (const void* dataPtr);
00831 
00832     // Get some scalar values in the column.
00833     // The argument dataPtr is in fact a Vector<T>*, but a void*
00834     // is needed to be generic.
00835     // The vector pointed to by dataPtr has to have the correct length
00836     // (which is guaranteed by the ScalarColumn getColumn function).
00837     // The default implementation throws an "invalid operation" exception.
00838     virtual void getScalarColumnCellsV (const RefRows& rownrs,
00839                                         void* dataPtr);
00840 
00841     // Put some scalar values in the column.
00842     // The argument dataPtr is in fact a const Vector<T>*, but a const void*
00843     // is needed to be generic.
00844     // The vector pointed to by dataPtr has to have the correct length
00845     // (which is guaranteed by the ScalarColumn getColumn function).
00846     // The default implementation throws an "invalid operation" exception.
00847     virtual void putScalarColumnCellsV (const RefRows& rownrs,
00848                                         const void* dataPtr);
00849 
00850     // Get scalars from the given row on with a maximum of nrmax values.
00851     // It returns the actual number of values got.
00852     // This can be used to get an entire column of scalars or to get
00853     // a part of a column (for a cache for example).
00854     // The argument dataPtr is in fact a T*, but a void*
00855     // is needed to be generic.
00856     // The default implementation throws an "invalid operation" exception.
00857     virtual uInt getBlockV (uInt rownr, uInt nrmax, void* dataPtr);
00858 
00859     // Put nrmax scalars from the given row on.
00860     // It returns the actual number of values put.
00861     // This can be used to put an entire column of scalars or to put
00862     // a part of a column (for a cache for example).
00863     // The argument dataPtr is in fact a const T*, but a const void*
00864     // is needed to be generic.
00865     // The default implementation throws an "invalid operation" exception.
00866     virtual void putBlockV (uInt rownr, uInt nrmax, const void* dataPtr);
00867 
00868     // Get the array value in the given row.
00869     // The argument dataPtr is in fact an Array<T>*, but a void*
00870     // is needed to be generic.
00871     // The array pointed to by dataPtr has to have the correct shape
00872     // (which is guaranteed by the ArrayColumn get function).
00873     // The default implementation throws an "invalid operation" exception.
00874     virtual void getArrayV (uInt rownr, void* dataPtr);
00875 
00876     // Put the array value into the given row.
00877     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00878     // is needed to be generic.
00879     // The array pointed to by dataPtr has to have the correct shape
00880     // (which is guaranteed by the ArrayColumn put function).
00881     // The default implementation throws an "invalid operation" exception.
00882     virtual void putArrayV (uInt rownr, const void* dataPtr);
00883 
00884     // Get all array values in the column.
00885     // The argument dataPtr is in fact an Array<T>*, but a void*
00886     // is needed to be generic.
00887     // The vector pointed to by dataPtr has to have the correct length
00888     // (which is guaranteed by the ArrayColumn getColumn function).
00889     // The default implementation throws an "invalid operation" exception.
00890     virtual void getArrayColumnV (void* dataPtr);
00891 
00892     // Put all array values in the column.
00893     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00894     // is needed to be generic.
00895     // The vector pointed to by dataPtr has to have the correct length
00896     // (which is guaranteed by the ArrayColumn putColumn function).
00897     // The default implementation throws an "invalid operation" exception.
00898     virtual void putArrayColumnV (const void* dataPtr);
00899 
00900     // Get some array values in the column.
00901     // The argument dataPtr is in fact an Array<T>*, but a void*
00902     // is needed to be generic.
00903     // The vector pointed to by dataPtr has to have the correct length
00904     // (which is guaranteed by the ArrayColumn getColumn function).
00905     // The default implementation throws an "invalid operation" exception.
00906     virtual void getArrayColumnCellsV (const RefRows& rownrs,
00907                                        void* dataPtr);
00908 
00909     // Put some array values in the column.
00910     // The argument dataPtr is in fact an const Array<T>*, but a const void*
00911     // is needed to be generic.
00912     // The vector pointed to by dataPtr has to have the correct length
00913     // (which is guaranteed by the ArrayColumn getColumn function).
00914     // The default implementation throws an "invalid operation" exception.
00915     virtual void putArrayColumnCellsV (const RefRows& rownrs,
00916                                        const void* dataPtr);
00917 
00918     // Get a section of the array in the given row.
00919     // The argument dataPtr is in fact an Array<T>*, but a void*
00920     // is needed to be generic.
00921     // The array pointed to by dataPtr has to have the correct shape
00922     // (which is guaranteed by the ArrayColumn getSlice function).
00923     // The default implementation throws an "invalid operation" exception.
00924     virtual void getSliceV (uInt rownr, const Slicer& slicer, void* dataPtr);
00925 
00926     // Put into a section of the array in the given row.
00927     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00928     // is needed to be generic.
00929     // The array pointed to by dataPtr has to have the correct shape
00930     // (which is guaranteed by the ArrayColumn putSlice function).
00931     // The default implementation throws an "invalid operation" exception.
00932     virtual void putSliceV (uInt rownr, const Slicer& slicer,
00933                             const void* dataPtr);
00934 
00935     // Get a section of all arrays in the column.
00936     // The argument dataPtr is in fact an Array<T>*, but a void*
00937     // is needed to be generic.
00938     // The array pointed to by dataPtr has to have the correct shape
00939     // (which is guaranteed by the ArrayColumn getColumn function).
00940     // The default implementation throws an "invalid operation" exception.
00941     virtual void getColumnSliceV (const Slicer& slicer, void* dataPtr);
00942 
00943     // Put into a section of all arrays in the column.
00944     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00945     // is needed to be generic.
00946     // The array pointed to by dataPtr has to have the correct shape
00947     // (which is guaranteed by the ArrayColumn putColumn function).
00948     // The default implementation throws an "invalid operation" exception.
00949     virtual void putColumnSliceV (const Slicer& slicer, const void* dataPtr);
00950 
00951     // Get a section of some arrays in the column.
00952     // The argument dataPtr is in fact an Array<T>*, but a void*
00953     // is needed to be generic.
00954     // The array pointed to by dataPtr has to have the correct shape
00955     // (which is guaranteed by the ArrayColumn getColumn function).
00956     // The default implementation throws an "invalid operation" exception.
00957     virtual void getColumnSliceCellsV (const RefRows& rownrs,
00958                                        const Slicer& slicer, void* dataPtr);
00959 
00960     // Put into a section of some arrays in the column.
00961     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00962     // is needed to be generic.
00963     // The array pointed to by dataPtr has to have the correct shape
00964     // (which is guaranteed by the ArrayColumn putColumn function).
00965     // The default implementation throws an "invalid operation" exception.
00966     virtual void putColumnSliceCellsV (const RefRows& rownrs,
00967                                        const Slicer& slicer,
00968                                        const void* dataPtr);
00969 
00970     // Throw an "invalid operation" exception for the default
00971     // implementation of get.
00972     void throwGet() const;
00973 
00974     // Throw an "invalid operation" exception for the default
00975     // implementation of put.
00976     void throwPut() const;
00977 
00978     // Set the column name.
00979     void setColumnName (const String& colName)
00980       { colName_p = colName; }
00981 
00982     // Get rhe column name.
00983     const String& columnName() const
00984       { return colName_p; }
00985 
00986 protected:
00987     // Get the scalar value in the given row.
00988     // The default implementation throws an "invalid operation" exception.
00989     // <group>
00990     virtual void getBoolV     (uInt rownr, Bool* dataPtr);
00991     virtual void getuCharV    (uInt rownr, uChar* dataPtr);
00992     virtual void getShortV    (uInt rownr, Short* dataPtr);
00993     virtual void getuShortV   (uInt rownr, uShort* dataPtr);
00994     virtual void getIntV      (uInt rownr, Int* dataPtr);
00995     virtual void getuIntV     (uInt rownr, uInt* dataPtr);
00996     virtual void getfloatV    (uInt rownr, float* dataPtr);
00997     virtual void getdoubleV   (uInt rownr, double* dataPtr);
00998     virtual void getComplexV  (uInt rownr, Complex* dataPtr);
00999     virtual void getDComplexV (uInt rownr, DComplex* dataPtr);
01000     virtual void getStringV   (uInt rownr, String* dataPtr);
01001     // This function is the get for all non-standard data types.
01002     virtual void getOtherV    (uInt rownr, void* dataPtr);
01003     // </group>
01004 
01005     // Put the scalar value into the given row.
01006     // The default implementation throws an "invalid operation" exception.
01007     // <group>
01008     virtual void putBoolV     (uInt rownr, const Bool* dataPtr);
01009     virtual void putuCharV    (uInt rownr, const uChar* dataPtr);
01010     virtual void putShortV    (uInt rownr, const Short* dataPtr);
01011     virtual void putuShortV   (uInt rownr, const uShort* dataPtr);
01012     virtual void putIntV      (uInt rownr, const Int* dataPtr);
01013     virtual void putuIntV     (uInt rownr, const uInt* dataPtr);
01014     virtual void putfloatV    (uInt rownr, const float* dataPtr);
01015     virtual void putdoubleV   (uInt rownr, const double* dataPtr);
01016     virtual void putComplexV  (uInt rownr, const Complex* dataPtr);
01017     virtual void putDComplexV (uInt rownr, const DComplex* dataPtr);
01018     virtual void putStringV   (uInt rownr, const String* dataPtr);
01019     // This function is the put for all non-standard data types.
01020     virtual void putOtherV    (uInt rownr, const void* dataPtr);
01021     // </group>
01022 
01023 private:
01024     Bool        isFixedShape_p;
01025     String      colName_p;
01026     ColumnCache colCache_p;
01027 
01028     // Set the shape of all (fixed-shaped) arrays in the column.
01029     // By default it throws a "not possible" exception.
01030     virtual void setShapeColumn (const IPosition& shape);
01031 
01032     // The copy constructor cannot be used for this base class.
01033     // The private declaration of this constructor makes it unusable.
01034     DataManagerColumn (const DataManagerColumn&);
01035 
01036     // Assignment cannot be used for this base class.
01037     // The private declaration of this operator makes it unusable.
01038     DataManagerColumn& operator= (const DataManagerColumn&);
01039 };
01040 
01041 
01042 
01043 } //# NAMESPACE CASA - END
01044 
01045 #endif