casacore
Loading...
Searching...
No Matches
ForwardColRow.h
Go to the documentation of this file.
1//# ForwardColRow.h: Virtual Column Engine to forward to other rows/columns
2//# Copyright (C) 1995,1996,1997,2001
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_FORWARDCOLROW_H
27#define TABLES_FORWARDCOLROW_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/DataMan/ForwardCol.h>
32#include <casacore/tables/Tables/ScalarColumn.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward Declarations
37class ForwardColumnIndexedRowEngine;
38
39
40// <summary>
41// Virtual column forwarding to another row/column
42// </summary>
43
44// <reviewed reviewer="Paul Shannon" date="1995/05/22" tests="tForwardColRow.cc">
45// </reviewed>
46
47// <use visibility=local>
48
49// <prerequisite>
50//# Classes you should understand before using this one.
51// <li> ForwardColumnIndexedRowEngine
52// <li> ForwardColumn
53// </prerequisite>
54
55// <etymology>
56// ForwardColumnIndexedRow handles the forwarding of the gets and puts
57// for an individual row/column on behalf of the virtual column engine
58// ForwardColumnIndexedRowEngine. It forwards them to a row/column in
59// another table. The row forwarding is done using a special column
60// containing row numbers indexing the referenced table.
61// </etymology>
62
63// <synopsis>
64// ForwardColumnIndexedRow represents a virtual column which forwards the
65// gets and puts to a column with the same name in another table.
66// It is, in fact, a reference to the other column.
67// The row numbers in the column are mapped to row numbers in the referenced
68// column using a special column containing the mapping.
69// The name of the other table is stored as a keyword in the
70// forwarding column. When the referenced column is in its turn a
71// ForwardColumn (note: not a ForwardColumnIndexedRow), the table
72// mentioned in there will be used. In this way, the length of the
73// forwarding chain is kept to a minimum.
74//
75// An object of this class is created (and deleted) by the virtual column
76// engine
77// <linkto class="ForwardColumnIndexedRowEngine:description">
78// ForwardColumnIndexedRowEngine</linkto>
79// which creates a ForwardColumnIndexedRow object for each column being
80// forwarded.
81// </synopsis>
82
83
85{
86public:
87
88 // Construct it for the given column.
90 const String& columnName,
91 int dataType,
92 const String& dataTypeId,
93 const Table& referencedTable);
94
95 // Destructor is mandatory.
97
98 // Copy constructor is not needed and therefore forbidden.
100
101 // Assignment is not needed and therefore forbidden.
103
104 // Initialize the object.
105 // This means binding the column to the column with the same name
106 // in the original table.
107 // It checks if the description of both columns is the same.
108 void prepare (const Table& thisTable);
109
110private:
111 // This data manager cannot handle changing array shapes.
113
114 // Set the shape of an (indirect) array in the given row.
115 // This throws an exception, because putting is not supported.
116 void setShape (rownr_t rownr, const IPosition& shape);
117
118 // Is the value shape defined in the given row?
120
121 // Get the dimensionality of the item in the given row.
123
124 // Get the shape of the item in the given row.
126
127 // Get the scalar value with a standard data type in the given row.
128 // <group>
129 virtual void getBool (rownr_t rownr, Bool* dataPtr);
130 virtual void getuChar (rownr_t rownr, uChar* dataPtr);
131 virtual void getShort (rownr_t rownr, Short* dataPtr);
132 virtual void getuShort (rownr_t rownr, uShort* dataPtr);
133 virtual void getInt (rownr_t rownr, Int* dataPtr);
134 virtual void getuInt (rownr_t rownr, uInt* dataPtr);
135 virtual void getInt64 (rownr_t rownr, Int64* dataPtr);
136 virtual void getfloat (rownr_t rownr, float* dataPtr);
137 virtual void getdouble (rownr_t rownr, double* dataPtr);
138 virtual void getComplex (rownr_t rownr, Complex* dataPtr);
139 virtual void getDComplex (rownr_t rownr, DComplex* dataPtr);
140 virtual void getString (rownr_t rownr, String* dataPtr);
141 // </group>
142
143 // Get the scalar value with a non-standard data type in the given row.
144 virtual void getOther (rownr_t rownr, void* dataPtr);
145
146 // Put the scalar value with a standard data type into the given row.
147 // This throws an exception, because putting is not supported.
148 // <group>
149 virtual void putBool (rownr_t rownr, const Bool* dataPtr);
150 virtual void putuChar (rownr_t rownr, const uChar* dataPtr);
151 virtual void putShort (rownr_t rownr, const Short* dataPtr);
152 virtual void putuShort (rownr_t rownr, const uShort* dataPtr);
153 virtual void putInt (rownr_t rownr, const Int* dataPtr);
154 virtual void putuInt (rownr_t rownr, const uInt* dataPtr);
155 virtual void putInt64 (rownr_t rownr, const Int64* dataPtr);
156 virtual void putfloat (rownr_t rownr, const float* dataPtr);
157 virtual void putdouble (rownr_t rownr, const double* dataPtr);
158 virtual void putComplex (rownr_t rownr, const Complex* dataPtr);
159 virtual void putDComplex (rownr_t rownr, const DComplex* dataPtr);
160 virtual void putString (rownr_t rownr, const String* dataPtr);
161 // </group>
162
163 // Put the scalar value with a non-standard data type into the given row.
164 // This throws an exception, because putting is not supported.
165 virtual void putOther (rownr_t rownr, const void* dataPtr);
166
167 // Get the array value in the given row.
168 // The argument dataPtr is in fact a Array<T>&, but a ArrayBase&
169 // is needed to be generic.
170 // The array pointed to by dataPtr has to have the correct shape
171 // (which is guaranteed by the ArrayColumn get function).
172 void getArrayV (rownr_t rownr, ArrayBase& dataPtr);
173
174 // Put the array value into the given row.
175 // This throws an exception, because putting is not supported.
176 void putArrayV (rownr_t rownr, const ArrayBase& dataPtr);
177
178 // Get a section of the array in the given row.
179 // The argument dataPtr is in fact a Array<T>&, but a ArrayBase&
180 // is needed to be generic.
181 // The array pointed to by dataPtr has to have the correct shape
182 // (which is guaranteed by the ArrayColumn getSlice function).
183 void getSliceV (rownr_t rownr, const Slicer& slicer, ArrayBase& dataPtr);
184
185 // Put into a section of the array in the given row.
186 // This throws an exception, because putting is not supported.
187 void putSliceV (rownr_t rownr, const Slicer& slicer, const ArrayBase& dataPtr);
188
189 // Convert the rownr to the rownr in the underlying table.
191
192 //# Now define the data members.
193 ForwardColumnIndexedRowEngine* enginePtr_p; //# pointer to parent engine
194};
195
196
197
198
199// <summary>
200// Virtual column engine forwarding to other columns/rows.
201// </summary>
202
203// <reviewed reviewer="" date="" tests="">
204// </reviewed>
205
206// <use visibility=export>
207
208// <prerequisite>
209//# Classes you should understand before using this one.
210// <li> VirtualColumnEngine
211// </prerequisite>
212
213// <etymology>
214// ForwardColumnIndexedRowEngine is a virtual column engine which
215// forwards the gets and puts of columns to corresponding columns
216// in another table. Furthermore it maps the row number by indexing
217// the row number in the referenced table.
218// </etymology>
219
220// <synopsis>
221// ForwardColumnIndexedRowEngine is a data manager which forwards
222// the gets and puts of columns to columns with the same names in
223// another table. In that sense it is the same as the virtual column engine
224// <linkto class="ForwardColumnEngine:description">
225// ForwardColumnEngine</linkto>.
226// However, it also forwards the row number. That is, it uses a column
227// containing row numbers to index the correct row in the referenced table.
228// The name of this column and the name of the referenced table have to
229// be given when constructing the engine.
230//
231// For example:<br>
232// Table TABA contains columns A, B and C and consists of N rows.
233// Table TABF uses ForwardColumnIndexedRowEngine to forward its columns
234// A, B and C to the corresponding columns in TABA. Furthermore it
235// contains a column ROW containing row numbers in TABA. This column is
236// the mapping of row numbers in TABF to rows in TABA. E.g. if ROW has
237// the value 25 in row 10, row 10 of TABF is forwarded to row 25 in TABA.
238//
239// Actually, puts are not possible. When multiple rows map to the same row
240// in the referenced table, putting a value in one row would also change
241// the value in another row referencing the same underlying row. This
242// could result in unexpected behaviour.
243//
244// The engine consists of a set of
245// <linkto class="ForwardColumnIndexedRow:description">
246// ForwardColumnIndexedRow</linkto>
247// objects, which handle the actual gets.
248// </synopsis>
249
250// <motivation>
251// In some ways it overlaps the functionality of the storage manager
252// StManMirAIO. They both allow to have the same value used by multiple
253// rows. However, StManMirAIO only allows that for consecutive rows,
254// while this engine allows it for any row. On the other side,
255// StManMirAIO is faster.
256// </motivation>
257
258// <example>
259// <srcblock>
260// // The original table.
261// Table tab("someTable");
262// // Create another table with the same description.
263// SetupNewTable newtab("tForwardColRow.data", tab.tableDesc(), Table::New);
264// // Create an engine which forwards to the original table and uses
265// // column rowColumn to get the row number in the referenced table.
266// // Bind all columns in the new table to the forwarding engine.
267// ForwardColumnIndexedRowEngine fce(tab, "rowColumn");
268// newtab.bindAll (fce);
269// // Create the new table.
270// // Every get and put on this table is forwarded to the original table.
271// // NB. Puts cannot be done here, because the original table was
272// // opened as readonly.
273// // Of course, some columns could have been bound to another
274// // data manager (storage manager, calibration engine, ...).
275// Table forwTab(newtab);
276// </srcblock>
277// </example>
278
280{
281public:
282
283 // The default constructor is required for reconstruction of the
284 // engine when a table is read back.
286 const Record& spec);
287
288 // Create the engine.
289 // The columns using this engine will reference the given table.
290 // The column with the given name contains the row number mapping,
291 // i.e. a row number in a get or put is converted to a row number
292 // in the referenced table using the value in this column.
293 // The data manager gets the given name.
294 ForwardColumnIndexedRowEngine (const Table& referencedTable,
295 const String& rowColumnName,
296 const String& dataManagerName);
297
298 // Create the engine.
299 // The columns using this engine will reference the given table.
300 // The column with the given name contains the row number mapping,
301 // i.e. a row number in a get or put is converted to a row number
302 // in the referenced table using the value in this column.
303 // The data manager has no name.
304 ForwardColumnIndexedRowEngine (const Table& referencedTable,
305 const String& rowColumnName);
306
307 // Destructor is mandatory.
309
310 // The copy constructor is forbidden.
312
313 // Assignment is forbidden.
315 (const ForwardColumnIndexedRowEngine&) = delete;
316
317 // Clone the engine object.
319
320 // Return the type name of the engine
321 // (i.e. its class name ForwardColumnIndexedRowEngine).
323
324 // Record a record containing data manager specifications.
325 virtual Record dataManagerSpec() const;
326
327 // Return the name of the class.
329
330 // Register the class name and the static makeObject "constructor".
331 // This will make the engine known to the table system.
332 static void registerClass();
333
334private:
335 // Create the column object for the scalar column in this engine.
337 int dataType,
338 const String& dataTypeId);
339
340 // Create the column object for the indirect array column in this engine.
342 int dataType,
343 const String& dataTypeId);
344
345 // Initialize the object for a new table.
346 // It defines the column keywords containing the name of the
347 // original table, which can be the parent of the referenced table.
348 // It also defines a keyword containing the row column name.
349 void create64 (rownr_t initialNrrow);
350
351 // Initialize the engine.
352 // It gets the name of the original table(s) from the column keywords,
353 // opens those tables and attaches the ForwardColumnIndexedRow objects
354 // to the columns in those tables.
355 void prepare();
356
357 // Reopen the engine for read/write access.
358 // This cannot be done, so all columns remain readonly.
359 // The function is needed to override the behaviour of its base class.
360 void reopenRW();
361
362
363 // Define the column with the row numbers (must have data type uInt).
366 // Define the various engine column objects.
368 // Cache of last row used to get row number.
371
372
373public:
374 // Define the "constructor" to construct this engine when a
375 // table is read back.
376 // This "constructor" has to be registered by the user of the engine.
377 // If the engine is commonly used, its registration can be added
378 // into the registerAllCtor function in DataManReg.cc.
379 // This function gets automatically invoked by the table system.
381 const Record& spec);
382
383 // Convert the rownr to the rownr in the underlying table.
385};
386
387
389{
390 if (Int64(rownr) != lastRow_p) {
391 rowNumber_p = rowColumn_p(rownr);
392 lastRow_p = rownr;
393 }
394 return rowNumber_p;
395}
396
399
400
401
402} //# NAMESPACE CASACORE - END
403
404#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
const String & columnName() const
Get rhe column name.
Abstract base class for a data manager.
Virtual column engine forwarding to other columns.
Definition ForwardCol.h:402
String dataManagerName() const
Return the name of the data manager.
Virtual column engine forwarding to other columns/rows.
ForwardColumnIndexedRowEngine(const String &dataManagerName, const Record &spec)
The default constructor is required for reconstruction of the engine when a table is read back.
DataManagerColumn * makeIndArrColumn(const String &columnName, int dataType, const String &dataTypeId)
Create the column object for the indirect array column in this engine.
PtrBlock< ForwardColumnIndexedRow * > refColumns_p
Define the various engine column objects.
static void registerClass()
Register the class name and the static makeObject "constructor".
virtual Record dataManagerSpec() const
Record a record containing data manager specifications.
void reopenRW()
Reopen the engine for read/write access.
void prepare()
Initialize the engine.
~ForwardColumnIndexedRowEngine()
Destructor is mandatory.
void create64(rownr_t initialNrrow)
Initialize the object for a new table.
Int64 lastRow_p
Cache of last row used to get row number.
ForwardColumnIndexedRowEngine(const ForwardColumnIndexedRowEngine &)=delete
The copy constructor is forbidden.
static String className()
Return the name of the class.
ForwardColumnIndexedRowEngine(const Table &referencedTable, const String &rowColumnName)
Create the engine.
ForwardColumnIndexedRowEngine(const Table &referencedTable, const String &rowColumnName, const String &dataManagerName)
Create the engine.
DataManagerColumn * makeScalarColumn(const String &columnName, int dataType, const String &dataTypeId)
Create the column object for the scalar column in this engine.
String rowColumnName_p
Define the column with the row numbers (must have data type uInt).
rownr_t convertRownr(rownr_t rownr)
Convert the rownr to the rownr in the underlying table.
static DataManager * makeObject(const String &dataManagerName, const Record &spec)
Define the "constructor" to construct this engine when a table is read back.
String dataManagerType() const
Return the type name of the engine (i.e.
DataManager * clone() const
Clone the engine object.
virtual void getString(rownr_t rownr, String *dataPtr)
virtual void putOther(rownr_t rownr, const void *dataPtr)
Put the scalar value with a non-standard data type into the given row.
virtual void getBool(rownr_t rownr, Bool *dataPtr)
Get the scalar value with a standard data type in the given row.
virtual void putuChar(rownr_t rownr, const uChar *dataPtr)
void getArrayV(rownr_t rownr, ArrayBase &dataPtr)
Get the array value in the given row.
virtual void putuShort(rownr_t rownr, const uShort *dataPtr)
virtual void putBool(rownr_t rownr, const Bool *dataPtr)
Put the scalar value with a standard data type into the given row.
virtual void getInt(rownr_t rownr, Int *dataPtr)
void putSliceV(rownr_t rownr, const Slicer &slicer, const ArrayBase &dataPtr)
Put into a section of the array in the given row.
void getSliceV(rownr_t rownr, const Slicer &slicer, ArrayBase &dataPtr)
Get a section of the array in the given row.
virtual void putInt(rownr_t rownr, const Int *dataPtr)
virtual void getOther(rownr_t rownr, void *dataPtr)
Get the scalar value with a non-standard data type in the given row.
void prepare(const Table &thisTable)
Initialize the object.
virtual void putuInt(rownr_t rownr, const uInt *dataPtr)
virtual void putString(rownr_t rownr, const String *dataPtr)
virtual void getInt64(rownr_t rownr, Int64 *dataPtr)
virtual void getfloat(rownr_t rownr, float *dataPtr)
ForwardColumnIndexedRow(ForwardColumnIndexedRowEngine *enginePtr, const String &columnName, int dataType, const String &dataTypeId, const Table &referencedTable)
Construct it for the given column.
void putArrayV(rownr_t rownr, const ArrayBase &dataPtr)
Put the array value into the given row.
virtual void putShort(rownr_t rownr, const Short *dataPtr)
IPosition shape(rownr_t rownr)
Get the shape of the item in the given row.
virtual void putComplex(rownr_t rownr, const Complex *dataPtr)
ForwardColumnIndexedRow & operator=(const ForwardColumnIndexedRow &)=delete
Assignment is not needed and therefore forbidden.
ForwardColumnIndexedRow(const ForwardColumnIndexedRow &)=delete
Copy constructor is not needed and therefore forbidden.
virtual void getuInt(rownr_t rownr, uInt *dataPtr)
virtual void getuChar(rownr_t rownr, uChar *dataPtr)
ForwardColumnIndexedRowEngine * enginePtr_p
rownr_t convertRownr(rownr_t rownr)
Convert the rownr to the rownr in the underlying table.
virtual void getDComplex(rownr_t rownr, DComplex *dataPtr)
virtual void getuShort(rownr_t rownr, uShort *dataPtr)
virtual void putfloat(rownr_t rownr, const float *dataPtr)
Bool isShapeDefined(rownr_t rownr)
Is the value shape defined in the given row?
~ForwardColumnIndexedRow()
Destructor is mandatory.
void setShape(rownr_t rownr, const IPosition &shape)
Set the shape of an (indirect) array in the given row.
virtual void getComplex(rownr_t rownr, Complex *dataPtr)
virtual void putDComplex(rownr_t rownr, const DComplex *dataPtr)
uInt ndim(rownr_t rownr)
Get the dimensionality of the item in the given row.
Bool canChangeShape() const
This data manager cannot handle changing array shapes.
virtual void getShort(rownr_t rownr, Short *dataPtr)
virtual void putdouble(rownr_t rownr, const double *dataPtr)
virtual void getdouble(rownr_t rownr, double *dataPtr)
virtual void putInt64(rownr_t rownr, const Int64 *dataPtr)
int dataType() const
Get the data type of the column as defined in DataType.h.
String dataTypeId() const
Get the data type id of the column for dataType==TpOther.
A drop-in replacement for Block<T*>.
Definition Block.h:812
String: the storage and methods of handling collections of characters.
Definition String.h:223
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
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44