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