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