casacore
VirtualTaQLColumn.h
Go to the documentation of this file.
1 //# VirtualTaQLColumn.h: Virtual column engine based on TaQL
2 //# Copyright (C) 2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef TABLES_VIRTUALTAQLCOLUMN_H
29 #define TABLES_VIRTUALTAQLCOLUMN_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/DataMan/VirtColEng.h>
34 #include <casacore/tables/DataMan/DataManager.h>
35 #include <casacore/casa/Arrays/IPosition.h>
36 
37 namespace casacore {
38 //# Forward Declarations
39 class TableExprNode;
40 
41 
42 // <category lib=aips module="Tables" sect="Virtual Columns">
43 // <summary> Virtual scalar column using TaQL</summary>
44 // <reviewed reviewer="GvD" date="2004/07/09" tests="">
45 //
46 // <prerequisite>
47 //# Classes you should understand before using this one.
48 // <li> VirtualScalarColumn
49 // </prerequisite>
50 //
51 // <synopsis>
52 // VirtualTaQLColumn is a virtual column engine to define the contents of a
53 // column as a TaQL expression in which possibly other columns are used.
54 // It is (of course) only possible to get data from the column; puts cannot
55 // be done.
56 // <br>
57 // The expression result can be a scalar or array of the basic TaQL data types.
58 // The column data type has to be conformant with that TaQL type, thus a
59 // column of any integer type has to be used for an integer TaQL result.
60 // <note role=caution> One has to be careful with deleting columns. If in an
61 // existing table a TaQL expression uses a deleted column, the expression
62 // cannot be parsed anymore and the table cannot be opened anymore.
63 // In the future the Table System will be made more forgiving.
64 // </note>
65 // </synopsis>
66 //
67 // <example>
68 // The following example creates a table with a few columns.
69 // One column is virtual and has a random value if Col3 is true.
70 // Otherwise it has value 0.
71 // <srcblock>
72 // // Create the table description.
73 // TableDesc td;
74 // td.addColumn (ScalarColumnDesc<DComplex>("Col1"));
75 // td.addColumn (ScalarColumnDesc<Int>("Col2"));
76 // td.addColumn (ScalarColumnDesc<Bool>("Col3"));
77 // td.addColumn (ScalarColumnDesc<Double>("ColVirt"));
78 //
79 // // Now create a new table from the description.
80 // SetupNewTable newTab("tmtest", td, Table::New);
81 // // Define the expression of the virtual column and bind the column to it.
82 // // The other columns are by default bound to StandardStMan.
83 // VirtualTaQLColumn engine("iif(Col3,rand(),0)");
84 // newTab.bindColumn("ColVirt", engine);
85 // Table tab(newTab);
86 // </srcblock>
87 // </example>
88 
90 {
91 public:
92 
93  // Construct it with the given TaQL expression.
94  VirtualTaQLColumn (const String& expr);
95 
96  // Construct it with the given specification.
97  VirtualTaQLColumn (const Record& spec);
98 
99  // Destructor is mandatory.
101 
102  // Clone the engine object.
103  virtual DataManager* clone() const;
104 
105  // Get the data manager specification.
106  virtual Record dataManagerSpec() const;
107 
108  // Return the type name of the engine.
109  // (i.e. its class name VirtualTaQLColumn).
110  virtual String dataManagerType() const;
111 
112  // Return the name of the class.
113  static String className();
114 
115  // Register the class name and the static makeObject "constructor".
116  // This will make the engine known to the table system.
117  static void registerClass();
118 
119  // Define the "constructor" to construct this engine when a
120  // table is read back.
121  // This "constructor" has to be registered by the user of the engine.
122  // If the engine is commonly used, its registration can be added
123  // into the registerAllCtor function in DataManReg.cc.
124  // This function gets automatically invoked by the table system.
126  const Record& spec);
127 
128  // Return the TaQL expression used.
129  const String& expression() const
130  { return itsExpr; }
131 
132  // Functions to return column info.
133  // <group>
134  virtual int dataType() const;
135  virtual Bool isWritable() const;
136  virtual uInt ndim (uInt rownr);
137  virtual IPosition shape (uInt rownr);
138  virtual Bool isShapeDefined (uInt rownr);
139  // </group>
140 
141 private:
142  // Copy is not needed and therefore forbidden (so it is made private).
144 
145  // Assignment is not needed and therefore forbidden (so it is made private).
147 
148  // Create the column object for the scalar column in this engine.
150  int dataType, const String&);
151 
152  // Create the column object for the indirect array column in this engine.
154  int dataType,
155  const String& dataTypeId);
156 
157  // Let the engine initialize the object for a new table.
158  // It defines a column keyword holding the expression.
159  virtual void create (uInt);
160 
161  // Prepare compiles the expression.
162  virtual void prepare();
163 
164  //# We could also define the getBlockXXV functions, but
165  //# that is not required. The default implementation gets
166  //# one value. Possible optimization can be done by
167  //# implementing it here.
168  //# The same is true for getColumn.
169 
170  // Get the scalar value in the given row.
171  // The default implementation throws an "invalid operation" exception.
172  // <group>
173  virtual void getBoolV (uInt rownr, Bool* dataPtr);
174  virtual void getuCharV (uInt rownr, uChar* dataPtr);
175  virtual void getShortV (uInt rownr, Short* dataPtr);
176  virtual void getuShortV (uInt rownr, uShort* dataPtr);
177  virtual void getIntV (uInt rownr, Int* dataPtr);
178  virtual void getuIntV (uInt rownr, uInt* dataPtr);
179  virtual void getInt64V (uInt rownr, Int64* dataPtr);
180  virtual void getfloatV (uInt rownr, float* dataPtr);
181  virtual void getdoubleV (uInt rownr, double* dataPtr);
182  virtual void getComplexV (uInt rownr, Complex* dataPtr);
183  virtual void getDComplexV (uInt rownr, DComplex* dataPtr);
184  virtual void getStringV (uInt rownr, String* dataPtr);
185  // </group>
186 
187  // Get the array value in the given row.
188  // The argument dataPtr is in fact an Array<T>*, but a void*
189  // is needed to be generic.
190  // The array pointed to by dataPtr has to have the correct shape
191  // (which is guaranteed by the ArrayColumn get function).
192  // The default implementation throws an "invalid operation" exception.
193  virtual void getArrayV (uInt rownr, void* dataPtr);
194 
195  // Get the array result into itsCurResult.
197 
198  // Make the result cache.
200 
201  // Clear the result cache.
203 
204 
205  //# Now define the data members.
209  String itsExpr; //# TaQL expression
210  TableExprNode* itsNode; //# compiled TaQL expression
212  Int itsCurRow; //# Currently evaluated row
213  void* itsCurResult; //# result in itsCurRow
214  IPosition itsCurShape; //# shape in itsCurRow
215 };
216 
217 
218 } //end namespace casacore
219 
220 #endif
casacore::VirtualTaQLColumn::itsExpr
String itsExpr
Definition: VirtualTaQLColumn.h:209
casacore::VirtualTaQLColumn::makeIndArrColumn
virtual DataManagerColumn * makeIndArrColumn(const String &columnName, int dataType, const String &dataTypeId)
Create the column object for the indirect array column in this engine.
casacore::IPosition
Definition: IPosition.h:120
casacore::VirtualTaQLColumn::itsCurRow
Int itsCurRow
Definition: VirtualTaQLColumn.h:212
casacore::VirtualTaQLColumn::getArrayV
virtual void getArrayV(uInt rownr, void *dataPtr)
Get the array value in the given row.
casacore::VirtualTaQLColumn::isWritable
virtual Bool isWritable() const
Test if data can be put into this column.
casacore::DataManager
Abstract base class for a data manager.
Definition: DataManager.h:225
casacore::VirtualTaQLColumn::makeScalarColumn
virtual DataManagerColumn * makeScalarColumn(const String &columnName, int dataType, const String &)
Create the column object for the scalar column in this engine.
casacore::VirtualTaQLColumn::itsCurResult
void * itsCurResult
Definition: VirtualTaQLColumn.h:213
casacore::VirtualTaQLColumn::getComplexV
virtual void getComplexV(uInt rownr, Complex *dataPtr)
Complexfwd_global_functions_Complexfwd::casacore::DComplex
std::complex< Double > DComplex
Definition: Complexfwd.h:50
casacore::VirtualTaQLColumn::operator=
VirtualTaQLColumn & operator=(const VirtualTaQLColumn &)
Assignment is not needed and therefore forbidden (so it is made private).
casacore::VirtualTaQLColumn::VirtualTaQLColumn
VirtualTaQLColumn(const VirtualTaQLColumn &)
Copy is not needed and therefore forbidden (so it is made private).
casacore::uChar
unsigned char uChar
Definition: aipstype.h:47
casacore::VirtualTaQLColumn::getIntV
virtual void getIntV(uInt rownr, Int *dataPtr)
casacore::VirtualTaQLColumn::itsNode
TableExprNode * itsNode
Definition: VirtualTaQLColumn.h:210
casacore::VirtualTaQLColumn::itsCurShape
IPosition itsCurShape
Definition: VirtualTaQLColumn.h:214
casacore::VirtualTaQLColumn::getShortV
virtual void getShortV(uInt rownr, Short *dataPtr)
casacore::VirtualTaQLColumn::itsDataType
int itsDataType
Definition: VirtualTaQLColumn.h:206
casacore::DataManagerColumn
Abstract base class for a column in a data manager.
Definition: DataManager.h:612
casacore::VirtualTaQLColumn::dataManagerType
virtual String dataManagerType() const
Return the type name of the engine.
casacore::VirtualTaQLColumn::VirtualTaQLColumn
VirtualTaQLColumn(const String &expr)
Construct it with the given TaQL expression.
casacore::DataManagerColumn::dataTypeId
virtual String dataTypeId() const
Get the data type id of the column for dataType==TpOther.
casacore::VirtualTaQLColumn::getuCharV
virtual void getuCharV(uInt rownr, uChar *dataPtr)
casacore::VirtualTaQLColumn::shape
virtual IPosition shape(uInt rownr)
Get the shape of the item in the given row.
casacore::DataManagerColumn::columnName
const String & columnName() const
Get rhe column name.
Definition: DataManager.h:1003
casacore::VirtualTaQLColumn::clone
virtual DataManager * clone() const
Clone the engine object.
casacore::VirtualTaQLColumn::getResult
IPosition getResult(uInt rownr)
Get the array result into itsCurResult.
casacore::VirtualTaQLColumn::itsColumnName
String itsColumnName
Definition: VirtualTaQLColumn.h:208
casacore::uShort
unsigned short uShort
Definition: aipstype.h:49
casacore::VirtualTaQLColumn::getStringV
virtual void getStringV(uInt rownr, String *dataPtr)
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51
casacore::VirtualTaQLColumn::itsTempWritable
Bool itsTempWritable
Definition: VirtualTaQLColumn.h:211
casacore::VirtualColumnEngine
Definition: VirtColEng.h:112
casacore::VirtualTaQLColumn::isShapeDefined
virtual Bool isShapeDefined(uInt rownr)
Is the value shape defined in the given row? By default it returns True.
casacore::VirtualTaQLColumn::getdoubleV
virtual void getdoubleV(uInt rownr, double *dataPtr)
casacore::Int
int Int
Definition: aipstype.h:50
casacore
this file contains all the compiler specific defines
Definition: mainpage.dox:28
casacore::VirtualTaQLColumn::ndim
virtual uInt ndim(uInt rownr)
Get the dimensionality of the item in the given row.
casacore::VirtualTaQLColumn::VirtualTaQLColumn
VirtualTaQLColumn(const Record &spec)
Construct it with the given specification.
casacore::VirtualTaQLColumn::dataManagerSpec
virtual Record dataManagerSpec() const
Get the data manager specification.
casacore::VirtualTaQLColumn::getuShortV
virtual void getuShortV(uInt rownr, uShort *dataPtr)
casacore::VirtualTaQLColumn::registerClass
static void registerClass()
Register the class name and the static makeObject "constructor".
casacore::VirtualTaQLColumn::getfloatV
virtual void getfloatV(uInt rownr, float *dataPtr)
casacore::TableExprNode
Definition: ExprNode.h:156
casacore::VirtualTaQLColumn::getuIntV
virtual void getuIntV(uInt rownr, uInt *dataPtr)
casacore::Int64
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
casacore::VirtualTaQLColumn::getDComplexV
virtual void getDComplexV(uInt rownr, DComplex *dataPtr)
casacore::VirtualTaQLColumn::prepare
virtual void prepare()
Prepare compiles the expression.
casacore::VirtualTaQLColumn::expression
const String & expression() const
Return the TaQL expression used.
Definition: VirtualTaQLColumn.h:129
casacore::String
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Complexfwd_global_functions_Complexfwd::casacore::Complex
std::complex< Float > Complex
Definition: Complexfwd.h:49
casacore::VirtualTaQLColumn::dataType
virtual int dataType() const
Functions to return column info.
casacore::Record
Definition: Record.h:181
casacore::VirtualTaQLColumn::className
static String className()
Return the name of the class.
casacore::Short
short Short
Definition: aipstype.h:48
casacore::VirtualTaQLColumn::makeCurResult
void makeCurResult()
Make the result cache.
casacore::VirtualTaQLColumn::~VirtualTaQLColumn
virtual ~VirtualTaQLColumn()
Destructor is mandatory.
casacore::VirtualTaQLColumn::getInt64V
virtual void getInt64V(uInt rownr, Int64 *dataPtr)
casacore::VirtualTaQLColumn
Definition: VirtualTaQLColumn.h:90
casacore::VirtualTaQLColumn::create
virtual void create(uInt)
Let the engine initialize the object for a new table.
casacore::VirtualTaQLColumn::makeObject
static DataManager * makeObject(const String &dataManagerName, const Record &spec)
Define the "constructor" to construct this engine when a table is read back.
casacore::VirtualTaQLColumn::itsIsArray
Bool itsIsArray
Definition: VirtualTaQLColumn.h:207
casacore::VirtualTaQLColumn::clearCurResult
void clearCurResult()
Clear the result cache.
casacore::VirtualTaQLColumn::getBoolV
virtual void getBoolV(uInt rownr, Bool *dataPtr)
Get the scalar value in the given row.
casacore::DataManager::dataManagerName
virtual String dataManagerName() const
Return the name of the data manager.