ForwardCol.h

Go to the documentation of this file.
00001 //# ForwardCol.h: Virtual Column Engine to forward to other columns
00002 //# Copyright (C) 1995,1996,1997,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$
00027 
00028 #ifndef TABLES_FORWARDCOL_H
00029 #define TABLES_FORWARDCOL_H
00030 
00031 //# Includes
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/tables/DataMan/VirtColEng.h>
00034 #include <casacore/tables/DataMan/DataManager.h>
00035 #include <casacore/tables/Tables/Table.h>
00036 #include <casacore/tables/Tables/TableColumn.h>
00037 #include <casacore/casa/Containers/Block.h>
00038 #include <casacore/casa/BasicSL/String.h>
00039 
00040 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00041 
00042 //# Forward Declarations
00043 class ForwardColumnEngine;
00044 class BaseColumn;
00045 
00046 
00047 // <summary>
00048 // Virtual column forwarding to another column
00049 // </summary>
00050 
00051 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00052 // </reviewed>
00053 
00054 // <use visibility=local>
00055 
00056 // <prerequisite>
00057 //# Classes you should understand before using this one.
00058 //   <li> ForwardColumnEngine
00059 //   <li> DataManagerColumn
00060 // </prerequisite>
00061 
00062 // <synopsis>
00063 // ForwardColumn represents a virtual column which forwards the
00064 // gets and puts to a column with the same name in another table.
00065 // It is, in fact, a reference to the other column.
00066 // The name of the other table is stored as a keyword in the
00067 // forwarding column. When there is a forwarding chain (i.e.
00068 // forwarding to a forwarding column), the name of the last
00069 // table in the chain is stored in the keyword. In this way, the
00070 // length of the chain is kept to a minimum. Otherwise a very long
00071 // chain could occur, which would slow things down.
00072 //
00073 // Addition and deletion of rows is allowed, but the functions addRow and
00074 // removeRow do not do anything at all. They are implemented to override
00075 // the default "throw exception" implementation. Because the engine
00076 // allows this, it can be used in a table supporting addition and removal
00077 // of rows.
00078 //
00079 // An object of this class is created (and deleted) by
00080 // <linkto class="ForwardColumnEngine:description">ForwardColumnEngine</linkto>
00081 // which creates a ForwardColumn object for each column being forwarded.
00082 // </synopsis> 
00083 
00084 // <motivation>
00085 // This class will be used by the calibration software.
00086 // Most columns in a measurement table will be forwarded, while
00087 // a few (i.e. the data themselves) will be calculated by a dedicated
00088 // calibration engine.
00089 // </motivation>
00090 
00091 class ForwardColumn : public DataManagerColumn
00092 {
00093 public:
00094 
00095     // Construct it for the given column.
00096     ForwardColumn (ForwardColumnEngine* enginePtr,
00097                    const String& columnName,
00098                    int dataType,
00099                    const String& dataTypeId,
00100                    const Table& referencedTable);
00101 
00102     // Destructor is mandatory.
00103     virtual ~ForwardColumn();
00104 
00105     // Define the special keyword containing the name of the original table.
00106     // If the column in the referenced table contains that special keyword,
00107     // it is in its turn a forwarding column. In that case the special
00108     // keyword value will be copied over to shortcut the forwarding chain.
00109     // The suffix is appended to the keyword name when defining it.
00110     // This makes this function usable for derived classes.
00111     void fillTableName (const Table& thisTable, const Table& referencedTable);
00112 
00113     // Initialize the object.
00114     // This means binding the column to the column with the same name
00115     // in the original table.
00116     // It checks if the description of both columns is the same.
00117     // It also determines if the column is writable.
00118     virtual void prepare (const Table& thisTable);
00119 
00120     // Set the column to writable if its underlying table is writable.
00121     void setRW();
00122 
00123 protected:
00124     // Do the preparation of the base class column object.
00125     void basePrepare (const Table& thisTable, Bool writable);
00126 
00127     BaseColumn* colPtr() const
00128         { return colPtr_p; }
00129 
00130 private:
00131     // Copy constructor is not needed and therefore forbidden
00132     // (so make it private).
00133     ForwardColumn (const ForwardColumn&);
00134 
00135     // Assignment is not needed and therefore forbidden (so make it private).
00136     ForwardColumn& operator= (const ForwardColumn&);
00137 
00138     // Create a SetupNewTable object with the given name and option
00139     // and with the description from the given table.
00140     // The SetupNewTable object will use a single ForwardColumn
00141     // engine which forwards all columns to the given table.
00142     // Later the SetupNewTable::bind functions can be used to bind one
00143     // or more columns to another data manager.
00144     static SetupNewTable setupNewTable (const Table& table,
00145                                         const String& tableName,
00146                                         Table::TableOption option);
00147 
00148     // This data manager may be able to handle changing array shapes.
00149     Bool canChangeShape() const;
00150 
00151     // This data manager may be able to do get/putScalarColumn.
00152     Bool canAccessScalarColumn (Bool& reask) const;
00153 
00154     // This data manager may be able to do get/putArrayColumn.
00155     Bool canAccessArrayColumn (Bool& reask) const;
00156 
00157     // This data manager may be able to do get/putSlice.
00158     Bool canAccessSlice (Bool& reask) const;
00159 
00160     // This data manager may be able to do get/putColumnSlice.
00161     Bool canAccessColumnSlice (Bool& reask) const;
00162 
00163     // Get the data type of the column as defined in DataType.h.
00164     int dataType() const;
00165 
00166     // Get the data type id of the column for dataType==TpOther.
00167     // This function is required for virtual column engines handling
00168     // non-standard data types. It is used to check the data type.
00169     String dataTypeId() const;
00170 
00171     // Test if data can be put into this column.
00172     Bool isWritable() const;
00173 
00174     // Set the shape of an direct array.
00175     // This only checks if the shape matches the referenced column.
00176     void setShapeColumn (const IPosition& shape);
00177 
00178     // Set the shape of an (indirect) array in the given row.
00179     void setShape (uInt rownr, const IPosition& shape);
00180 
00181     // Is the value shape defined in the given row?
00182     Bool isShapeDefined (uInt rownr);
00183 
00184     // Get the dimensionality of the item in the given row.
00185     uInt ndim (uInt rownr);
00186 
00187     // Get the shape of the item in the given row.
00188     IPosition shape (uInt rownr);
00189 
00190     // Get the scalar value with a standard data type in the given row.
00191     // <group>
00192     void getBoolV     (uInt rownr, Bool* dataPtr);
00193     void getuCharV    (uInt rownr, uChar* dataPtr);
00194     void getShortV    (uInt rownr, Short* dataPtr);
00195     void getuShortV   (uInt rownr, uShort* dataPtr);
00196     void getIntV      (uInt rownr, Int* dataPtr);
00197     void getuIntV     (uInt rownr, uInt* dataPtr);
00198     void getfloatV    (uInt rownr, float* dataPtr);
00199     void getdoubleV   (uInt rownr, double* dataPtr);
00200     void getComplexV  (uInt rownr, Complex* dataPtr);
00201     void getDComplexV (uInt rownr, DComplex* dataPtr);
00202     void getStringV   (uInt rownr, String* dataPtr);
00203     // </group>
00204 
00205     // Get the scalar value with a non-standard data type in the given row.
00206     void getOtherV    (uInt rownr, void* dataPtr);
00207 
00208     // Put the scalar value with a standard data type into the given row.
00209     // <group>
00210     void putBoolV     (uInt rownr, const Bool* dataPtr);
00211     void putuCharV    (uInt rownr, const uChar* dataPtr);
00212     void putShortV    (uInt rownr, const Short* dataPtr);
00213     void putuShortV   (uInt rownr, const uShort* dataPtr);
00214     void putIntV      (uInt rownr, const Int* dataPtr);
00215     void putuIntV     (uInt rownr, const uInt* dataPtr);
00216     void putfloatV    (uInt rownr, const float* dataPtr);
00217     void putdoubleV   (uInt rownr, const double* dataPtr);
00218     void putComplexV  (uInt rownr, const Complex* dataPtr);
00219     void putDComplexV (uInt rownr, const DComplex* dataPtr);
00220     void putStringV   (uInt rownr, const String* dataPtr);
00221     // </group>
00222 
00223     // Put the scalar value with a non-standard data type into the given row.
00224     void putOtherV    (uInt rownr, const void* dataPtr);
00225 
00226     // Get all scalar values in the column.
00227     // The argument dataPtr is in fact a Vector<T>*, but a void*
00228     // is needed to be generic.
00229     // The vector pointed to by dataPtr has to have the correct length
00230     // (which is guaranteed by the ScalarColumn getColumn function).
00231     void getScalarColumnV (void* dataPtr);
00232 
00233     // Put all scalar values in the column.
00234     // The argument dataPtr is in fact a const Vector<T>*, but a const void*
00235     // is needed to be generic.
00236     // The vector pointed to by dataPtr has to have the correct length
00237     // (which is guaranteed by the ScalarColumn putColumn function).
00238     void putScalarColumnV (const void* dataPtr);
00239 
00240     // Get some scalar values in the column.
00241     // The argument dataPtr is in fact a Vector<T>*, but a void*
00242     // is needed to be generic.
00243     // The vector pointed to by dataPtr has to have the correct length
00244     // (which is guaranteed by the ScalarColumn getColumn function).
00245     virtual void getScalarColumnCellsV (const RefRows& rownrs,
00246                                         void* dataPtr);
00247 
00248     // Put some scalar values in the column.
00249     // The argument dataPtr is in fact a const Vector<T>*, but a const void*
00250     // is needed to be generic.
00251     // The vector pointed to by dataPtr has to have the correct length
00252     // (which is guaranteed by the ScalarColumn getColumn function).
00253     virtual void putScalarColumnCellsV (const RefRows& rownrs,
00254                                         const void* dataPtr);
00255 
00256     // Get the array value in the given row.
00257     // The argument dataPtr is in fact a Array<T>*, but a void*
00258     // is needed to be generic.
00259     // The array pointed to by dataPtr has to have the correct shape
00260     // (which is guaranteed by the ArrayColumn get function).
00261     void getArrayV (uInt rownr, void* dataPtr);
00262 
00263     // Put the array value into the given row.
00264     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00265     // is needed to be generic.
00266     // The array pointed to by dataPtr has to have the correct shape
00267     // (which is guaranteed by the ArrayColumn put function).
00268     void putArrayV (uInt rownr, const void* dataPtr);
00269 
00270     // Get a section of the array in the given row.
00271     // The argument dataPtr is in fact a Array<T>*, but a void*
00272     // is needed to be generic.
00273     // The array pointed to by dataPtr has to have the correct shape
00274     // (which is guaranteed by the ArrayColumn getSlice function).
00275     void getSliceV (uInt rownr, const Slicer& slicer, void* dataPtr);
00276 
00277     // Put into a section of the array in the given row.
00278     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00279     // is needed to be generic.
00280     // The array pointed to by dataPtr has to have the correct shape
00281     // (which is guaranteed by the ArrayColumn putSlice function).
00282     void putSliceV (uInt rownr, const Slicer& slicer, const void* dataPtr);
00283 
00284     // Get all scalar values in the column.
00285     // The argument dataPtr is in fact a Vector<T>*, but a void*
00286     // is needed to be generic.
00287     // The vector pointed to by dataPtr has to have the correct length
00288     // (which is guaranteed by the ScalarColumn getColumn function).
00289     void getArrayColumnV (void* dataPtr);
00290 
00291     // Put all scalar values in the column.
00292     // The argument dataPtr is in fact a const Vector<T>*, but a const void*
00293     // is needed to be generic.
00294     // The vector pointed to by dataPtr has to have the correct length
00295     // (which is guaranteed by the ScalarColumn putColumn function).
00296     void putArrayColumnV (const void* dataPtr);
00297 
00298     // Get some array values in the column.
00299     // The argument dataPtr is in fact an Array<T>*, but a void*
00300     // is needed to be generic.
00301     // The vector pointed to by dataPtr has to have the correct length
00302     // (which is guaranteed by the ArrayColumn getColumn function).
00303     virtual void getArrayColumnCellsV (const RefRows& rownrs,
00304                                        void* dataPtr);
00305 
00306     // Put some array values in the column.
00307     // The argument dataPtr is in fact an const Array<T>*, but a const void*
00308     // is needed to be generic.
00309     // The vector pointed to by dataPtr has to have the correct length
00310     // (which is guaranteed by the ArrayColumn getColumn function).
00311     virtual void putArrayColumnCellsV (const RefRows& rownrs,
00312                                        const void* dataPtr);
00313 
00314     // Get a section of all arrays in the column.
00315     // The argument dataPtr is in fact a Array<T>*, but a void*
00316     // is needed to be generic.
00317     // The array pointed to by dataPtr has to have the correct shape
00318     // (which is guaranteed by the ArrayColumn getColumn function).
00319     void getColumnSliceV (const Slicer& slicer, void* dataPtr);
00320 
00321     // Put a section into all arrays in the column.
00322     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00323     // is needed to be generic.
00324     // The array pointed to by dataPtr has to have the correct shape
00325     // (which is guaranteed by the ArrayColumn putColumn function).
00326     void putColumnSliceV (const Slicer& slicer, const void* dataPtr);
00327 
00328     // Get a section of some arrays in the column.
00329     // The argument dataPtr is in fact an Array<T>*, but a void*
00330     // is needed to be generic.
00331     // The array pointed to by dataPtr has to have the correct shape
00332     // (which is guaranteed by the ArrayColumn getColumn function).
00333     virtual void getColumnSliceCellsV (const RefRows& rownrs,
00334                                        const Slicer& slicer, void* dataPtr);
00335 
00336     // Put into a section of some arrays in the column.
00337     // The argument dataPtr is in fact a const Array<T>*, but a const void*
00338     // is needed to be generic.
00339     // The array pointed to by dataPtr has to have the correct shape
00340     // (which is guaranteed by the ArrayColumn putColumn function).
00341     virtual void putColumnSliceCellsV (const RefRows& rownrs,
00342                                        const Slicer& slicer,
00343                                        const void* dataPtr);
00344 
00345 
00346     //# Now define the data members.
00347     ForwardColumnEngine* enginePtr_p;  //# pointer to parent engine
00348     String        colName_p;           //# The name of the column
00349     int           dataType_p;          //# data type of the column
00350     String        dataTypeId_p;        //# data type Id of the column
00351     TableColumn   refCol_p;            //# Column in referenced table
00352     //#                                    This is only filled in when
00353     //#                                    a new table is created.
00354     Bool          writable_p;          //# True = column is writable
00355     Table         origTable_p;         //# The original table for this column
00356     BaseColumn*   colPtr_p;            //# pointer to column in original table
00357 };
00358 
00359 
00360 
00361 
00362 // <summary>
00363 // Virtual column engine forwarding to other columns
00364 // </summary>
00365 
00366 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00367 // </reviewed>
00368 
00369 // <use visibility=export>
00370 
00371 // <prerequisite>
00372 //# Classes you should understand before using this one.
00373 //   <li> VirtualColumnEngine
00374 // </prerequisite>
00375 
00376 // <synopsis>
00377 // ForwardColumnEngine is a data manager which forwards
00378 // the gets and puts of columns to columns with the same names in
00379 // another table.
00380 // It is, in fact, a reference to the other table columns.
00381 // The engine consists of a set of
00382 // <linkto class="ForwardColumn:description">ForwardColumn</linkto>
00383 // objects, which handle the actual gets and puts.
00384 // </synopsis> 
00385 
00386 // <motivation>
00387 // This class will be used by the calibration software.
00388 // Most columns in a measurement table will be forwarded
00389 // (thus bound to a ForwardColumnEngine object), while
00390 // a few (i.e. the data themselves) will be calculated by a dedicated
00391 // calibration engine.
00392 // </motivation>
00393 
00394 // <example>
00395 // <srcblock>
00396 //    // The original table.
00397 //    Table tab("someTable");
00398 //    // Create another table with the same description.
00399 //    SetupNewTable newtab("tForwardCol1.data", tab.tableDesc(), Table::New);
00400 //    // Create an engine which forwards to the original table.
00401 //    // Bind all columns in the new table to the forwarding engine.
00402 //    ForwardColumnEngine fce(tab);
00403 //    newtab.bindAll (fce);
00404 //    // Create the new table.
00405 //    // Every get and put on this table is forwarded to the original table.
00406 //    // NB. Puts cannot be done here, because the original table was
00407 //    //     opened as readonly.
00408 //    // Of course, some columns could have been bound to another
00409 //    // data manager (storage manager, calibration engine, ...).
00410 //    Table forwTab(newtab);
00411 // </srcblock>
00412 // </example>
00413 
00414 class ForwardColumnEngine : public VirtualColumnEngine
00415 {
00416 public:
00417 
00418     // The default constructor is required for reconstruction of the
00419     // engine when a table is read back.
00420     ForwardColumnEngine (const String& dataManagerName, const Record& spec);
00421 
00422     // Create the engine.
00423     // The columns using this engine will reference the given table.
00424     // The data manager gets the given name.
00425     ForwardColumnEngine (const Table& referencedTable,
00426                          const String& dataManagerName);
00427 
00428     // Create the engine.
00429     // The columns using this engine will reference the given table.
00430     // The data manager has no name.
00431     ForwardColumnEngine (const Table& referencedTable);
00432 
00433     // Destructor is mandatory.
00434     ~ForwardColumnEngine();
00435 
00436     // Clone the engine object.
00437     DataManager* clone() const;
00438 
00439     // Return the name of the data manager. This is the name of this
00440     // instantiation of the data manager, thus not its type name.
00441     String dataManagerName() const;
00442 
00443     // Return the type of the engine (i.e. its class name ForwardColumnEngine).
00444     String dataManagerType() const;
00445 
00446     // Record a record containing data manager specifications.
00447     virtual Record dataManagerSpec() const;
00448 
00449     // Get the suffix to be used for names.
00450     const String& suffix() const;
00451 
00452     // Return the name of the class.
00453     static String className();
00454 
00455     // Register the class name and the static makeObject "constructor".
00456     // This will make the engine known to the table system.
00457     static void registerClass();
00458 
00459 protected:
00460     // Set the suffix.
00461     void setSuffix (const String& suffix);
00462 
00463     // Add a ForwardColumn object to the block.
00464     void addForwardColumn (ForwardColumn* colp);
00465 
00466     // Get access to the refTable_p data member.
00467     const Table& refTable() const
00468         { return refTable_p; }
00469 
00470     // Do the creation (i.e. initialization) of the engine.
00471     void baseCreate();
00472 
00473     // Do the preparation of the engine by preparing all columns.
00474     void basePrepare();
00475 
00476 private:
00477     // The copy constructor is forbidden (so it is private).
00478     ForwardColumnEngine (const ForwardColumnEngine&);
00479 
00480     // Assignment is forbidden (so it is private).
00481     ForwardColumnEngine& operator= (const ForwardColumnEngine&);
00482 
00483     // This data manager allows to add rows.
00484     Bool canAddRow() const;
00485 
00486     // This data manager allows to delete rows.
00487     Bool canRemoveRow() const;
00488 
00489     // Add rows to all columns.
00490     // This is not doing anything (but needed to override the default).
00491     void addRow (uInt nrrow);
00492 
00493     // Delete a row from all columns.
00494     // This is not doing anything (but needed to override the default).
00495     void removeRow (uInt rownr);
00496 
00497     // This data manager allows to add columns.
00498     Bool canAddColumn() const;
00499 
00500     // This data manager allows to delete columns.
00501     Bool canRemoveColumn() const;
00502 
00503     // Add a column.
00504     void addColumn (DataManagerColumn*);
00505 
00506     // Delete a column.
00507     void removeColumn (DataManagerColumn*);
00508 
00509     // Create the column object for the scalar column in this engine.
00510     DataManagerColumn* makeScalarColumn (const String& columnName,
00511                                          int dataType,
00512                                          const String& dataTypeId);
00513 
00514     // Create the column object for the indirect array column in this engine.
00515     DataManagerColumn* makeIndArrColumn (const String& columnName,
00516                                          int dataType,
00517                                          const String& dataTypeId);
00518 
00519     // Initialize the object for a new table.
00520     // It defines the column keywords containing the name of the
00521     // original table, which can be the parent of the referenced table.
00522     void create (uInt initialNrrow);
00523 
00524     // Initialize the engine.
00525     // It gets the name of the original table(s) from the column keywords,
00526     // opens those tables and attaches the ForwardColumn objects to the
00527     // columns in those tables.
00528     void prepare();
00529 
00530     // Reopen the engine for read/write access.
00531     // It makes all its columns writable if their underlying table is writable.
00532     void reopenRW();
00533 
00534 
00535     // Define the various engine column objects.
00536     PtrBlock<ForwardColumn*> refColumns_p;
00537     // The referenced table.
00538     // For newly created tables this is filled in by the constructor.
00539     // For existing tables this is filled in by the first ForwardColumn
00540     // object being constructed.
00541     Table refTable_p;
00542     // The name of the data manager.
00543     String dataManName_p;
00544     // The suffix to be used in names.
00545     String suffix_p;
00546 
00547 
00548 public:
00549     // Set RefTable_p if not set yet.
00550     // This is done by ForwardColumn to cover the case for existing
00551     // tables where the default constructor of ForwardColumnEngine
00552     // is used and refTable_p is not filled in.
00553     void setRefTable (const Table& refTable);
00554 
00555     // Define the "constructor" to construct this engine when a
00556     // table is read back.
00557     // This "constructor" has to be registered by the user of the engine.
00558     // If the engine is commonly used, its registration can be added
00559     // into the registerAllCtor function in DataManReg.cc. 
00560     // This function gets automatically invoked by the table system.
00561     static DataManager* makeObject (const String& dataManagerType,
00562                                     const Record& spec);
00563 };
00564 
00565 
00566 
00567 inline const String& ForwardColumnEngine::suffix() const
00568     { return suffix_p; }
00569 
00570 inline void ForwardColumnEngine::setSuffix (const String& suffix)
00571     { suffix_p = suffix; }
00572 
00573 
00574 
00575 } //# NAMESPACE CASACORE - END
00576 
00577 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1