casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef TABLES_VIRTUALTAQLCOLUMN_H
27#define TABLES_VIRTUALTAQLCOLUMN_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/DataMan/VirtColEng.h>
32#include <casacore/tables/DataMan/DataManager.h>
33#include <casacore/casa/Arrays/IPosition.h>
34
35namespace casacore {
36//# Forward Declarations
37class TableExprNode;
38
39
40// <category lib=aips module="Tables" sect="Virtual Columns">
41// <summary> Virtual scalar column using TaQL</summary>
42// <reviewed reviewer="GvD" date="2004/07/09" tests="">
43//
44// <prerequisite>
45//# Classes you should understand before using this one.
46// <li> VirtualScalarColumn
47// </prerequisite>
48//
49// <synopsis>
50// VirtualTaQLColumn is a virtual column engine to define the contents of a
51// column as a TaQL CALC expression in which possibly other columns are used.
52// It is (of course) only possible to get data from the column; puts cannot
53// be done. See note 199 for a description of TaQL.
54// The TaQL style can be specified (such as 0- or 1-based indexing).
55// <br>
56// The expression result can be a scalar or array of the basic TaQL data types.
57// The column data type has to be conformant with that TaQL type, thus a
58// column of any integer type has to be used for an integer TaQL result.
59// <br>
60// Constant expressions are precalculated and cached making the retrieval of
61// e.g. the full column much faster (factor 4).
62// <br>
63// A possible use for a virtual TaQL column is a column in a MeasurementSet
64// containing a constant value. It could also be used for on-the-fly calculation
65// of J2000 UVW-values or HADEC using an expression such as "derivedmscal.newuvw()"
66// <note role=caution> One has to be careful with deleting columns. If in an
67// existing table a TaQL expression uses a deleted column, the expression
68// cannot be parsed anymore and the table cannot be opened anymore.
69// In the future the Table System will be made more forgiving.
70// </note>
71// </synopsis>
72//
73// <example>
74// The following example creates a table with a few columns.
75// One column is virtual and has a random value if Col3 is true.
76// Otherwise it has value 0.
77// <srcblock>
78// // Create the table description.
79// TableDesc td;
80// td.addColumn (ScalarColumnDesc<DComplex>("Col1"));
81// td.addColumn (ScalarColumnDesc<Int>("Col2"));
82// td.addColumn (ScalarColumnDesc<Bool>("Col3"));
83// td.addColumn (ScalarColumnDesc<Double>("ColVirt"));
84//
85// // Now create a new table from the description.
86// SetupNewTable newTab("tmtest", td, Table::New);
87// // Define the expression of the virtual column and bind the column to it.
88// // The other columns are by default bound to StandardStMan.
89// VirtualTaQLColumn engine("iif(Col3,rand(),0)");
90// newTab.bindColumn("ColVirt", engine);
91// Table tab(newTab);
92// </srcblock>
93// </example>
94
96{
97public:
98
99 // Construct it with the given TaQL expression.
100 VirtualTaQLColumn (const String& expr, const String& style=String());
101
102 // Construct it with the given specification.
104
105 // Destructor is mandatory.
107
108 // Copy is not needed and therefore forbidden.
110
111 // Assignment is not needed and therefore forbidden.
113
114 // Clone the engine object.
115 virtual DataManager* clone() const;
116
117 // Get the data manager specification.
118 virtual Record dataManagerSpec() const;
119
120 // Return the type name of the engine.
121 // (i.e. its class name VirtualTaQLColumn).
122 virtual String dataManagerType() const;
123
124 // Return the name of the class.
126
127 // Register the class name and the static makeObject "constructor".
128 // This will make the engine known to the table system.
129 static void registerClass();
130
131 // Define the "constructor" to construct this engine when a
132 // table is read back.
133 // This "constructor" has to be registered by the user of the engine.
134 // If the engine is commonly used, its registration can be added
135 // into the registerAllCtor function in DataManReg.cc.
136 // This function gets automatically invoked by the table system.
138 const Record& spec);
139
140 // Return the TaQL expression used.
141 const String& expression() const
142 { return itsExpr; }
143
144 // Set the shape of an array in the column.
145 // It is only called (right after the constructor) if the array has
146 // a fixed shape.
147 virtual void setShapeColumn (const IPosition& aShape);
148
149 // Set the maximum length of a 'fixed length' string.
150 // It is only called (right after the constructor) if the string has
151 // a fixed length.
152 virtual void setMaxLength (uInt maxLength);
153
154 // Functions to return column info.
155 // <group>
156 virtual int dataType() const;
157 virtual Bool isWritable() const;
158 virtual uInt ndim (rownr_t rownr);
159 virtual IPosition shape (rownr_t rownr);
160 virtual Bool isShapeDefined (rownr_t rownr);
161 // </group>
162
163private:
164 // Create the column object for the scalar column in this engine.
166 int dataType, const String&);
167
168 // Create the column object for the indirect array column in this engine.
170 int dataType,
171 const String& dataTypeId);
172
173 // Let the engine initialize the object for a new table.
174 // It defines a column keyword holding the expression.
175 virtual void create64 (rownr_t);
176
177 // Prepare compiles the expression.
178 virtual void prepare();
179
180 // Get the scalar value in the given row.
181 // <group>
182 virtual void getBool (rownr_t rownr, Bool* dataPtr);
183 virtual void getuChar (rownr_t rownr, uChar* dataPtr);
184 virtual void getShort (rownr_t rownr, Short* dataPtr);
185 virtual void getuShort (rownr_t rownr, uShort* dataPtr);
186 virtual void getInt (rownr_t rownr, Int* dataPtr);
187 virtual void getuInt (rownr_t rownr, uInt* dataPtr);
188 virtual void getInt64 (rownr_t rownr, Int64* dataPtr);
189 virtual void getfloat (rownr_t rownr, float* dataPtr);
190 virtual void getdouble (rownr_t rownr, double* dataPtr);
191 virtual void getComplex (rownr_t rownr, Complex* dataPtr);
192 virtual void getDComplex (rownr_t rownr, DComplex* dataPtr);
193 virtual void getString (rownr_t rownr, String* dataPtr);
194 // </group>
195
196 // Get the array value in the given row.
197 // The array given by <src>arr</src> has to have the correct shape
198 // (which is guaranteed by the ArrayColumn get function).
199 virtual void getArrayV (rownr_t rownr, ArrayBase& arr);
200
201 // Get the array result into itsCurArray.
202 void getResult (rownr_t rownr);
203
204 // Make the result cache.
206
207 // Get functions implemented by means of their DataManagerColumn::getXXBase
208 // counterparts, but optimized for constant expressions.
209 // <group>
210 virtual void getScalarColumnV (ArrayBase& arr);
211 virtual void getScalarColumnCellsV (const RefRows& rownrs,
212 ArrayBase& arr);
213 // </group>
214
215 // Fill the ColumnCache object with a constant scalar value.
217
218 // Fill an array with a constant scalar value.
219 void fillArray (ArrayBase& data);
220
221 //# Now define the data members.
224 Bool itsIsConst; //# Constant expression?
227 String itsExpr; //# TaQL expression
228 String itsStyle; //# TaQL style
229 TableExprNode* itsNode; //# compiled TaQL expression
230 IPosition itsShape; //# The shape of the column.
231 uInt itsMaxLen; //# The maximum length of a 'fixed length' string.
232 union {
233 Bool itsBool; //# Constant scalar values
242 };
243 Complex itsComplex;
244 DComplex itsDComplex;
246 ArrayBase* itsCurArray; //# array value (constant or in itsCurRow)
247 rownr_t itsCurRow; //# row of current array value
248};
249
250
251} //end namespace casacore
252
253#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
const String & columnName() const
Get rhe column name.
virtual String dataTypeId() const
Get the data type id of the column for dataType==TpOther.
Abstract base class for a data manager.
virtual String dataManagerName() const
Return the name of the data manager.
String: the storage and methods of handling collections of characters.
Definition String.h:223
virtual void getuInt(rownr_t rownr, uInt *dataPtr)
virtual void getScalarColumnV(ArrayBase &arr)
Get functions implemented by means of their DataManagerColumn::getXXBase counterparts,...
virtual void getInt64(rownr_t rownr, Int64 *dataPtr)
virtual void getuChar(rownr_t rownr, uChar *dataPtr)
void makeCurArray()
Make the result cache.
static DataManager * makeObject(const String &dataManagerName, const Record &spec)
Define the "constructor" to construct this engine when a table is read back.
virtual Bool isShapeDefined(rownr_t rownr)
Is the value shape defined in the given row? By default it returns True.
virtual ~VirtualTaQLColumn()
Destructor is mandatory.
virtual DataManager * clone() const
Clone the engine object.
virtual void getBool(rownr_t rownr, Bool *dataPtr)
Get the scalar value in the given row.
virtual void getfloat(rownr_t rownr, float *dataPtr)
virtual void getShort(rownr_t rownr, Short *dataPtr)
virtual void create64(rownr_t)
Let the engine initialize the object for a new table.
virtual void getString(rownr_t rownr, String *dataPtr)
virtual uInt ndim(rownr_t rownr)
Get the dimensionality of the item in the given row.
static void registerClass()
Register the class name and the static makeObject "constructor".
void getResult(rownr_t rownr)
Get the array result into itsCurArray.
virtual IPosition shape(rownr_t rownr)
Get the shape of the item in the given row.
virtual void getInt(rownr_t rownr, Int *dataPtr)
void fillArray(ArrayBase &data)
Fill an array with a constant scalar value.
VirtualTaQLColumn(const Record &spec)
Construct it with the given specification.
virtual void getdouble(rownr_t rownr, double *dataPtr)
virtual void prepare()
Prepare compiles the expression.
virtual void getuShort(rownr_t rownr, uShort *dataPtr)
static String className()
Return the name of the class.
void fillColumnCache()
Fill the ColumnCache object with a constant scalar value.
const String & expression() const
Return the TaQL expression used.
virtual String dataManagerType() const
Return the type name of the engine.
VirtualTaQLColumn & operator=(const VirtualTaQLColumn &)=delete
Assignment is not needed and therefore forbidden.
virtual void getDComplex(rownr_t rownr, DComplex *dataPtr)
virtual Bool isWritable() const
Test if data can be put into this column.
virtual void getComplex(rownr_t rownr, Complex *dataPtr)
virtual DataManagerColumn * makeIndArrColumn(const String &columnName, int dataType, const String &dataTypeId)
Create the column object for the indirect array column in this engine.
VirtualTaQLColumn(const String &expr, const String &style=String())
Construct it with the given TaQL expression.
VirtualTaQLColumn(const VirtualTaQLColumn &)=delete
Copy is not needed and therefore forbidden.
virtual void setMaxLength(uInt maxLength)
Set the maximum length of a 'fixed length' string.
virtual void getScalarColumnCellsV(const RefRows &rownrs, ArrayBase &arr)
Get some scalar values in the column.
virtual void setShapeColumn(const IPosition &aShape)
Set the shape of an array in the column.
virtual Record dataManagerSpec() const
Get the data manager specification.
virtual void getArrayV(rownr_t rownr, ArrayBase &arr)
Get the array value in the given row.
virtual int dataType() const
Functions to return column info.
virtual DataManagerColumn * makeScalarColumn(const String &columnName, int dataType, const String &)
Create the column object for the scalar column in this engine.
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
unsigned short uShort
Definition aipstype.h:47
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44