casacore
Loading...
Searching...
No Matches
ArrayColumnBase.h
Go to the documentation of this file.
1//# ArrayColumnBase.h: base class for access to an array table column
2//# Copyright (C) 2013
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_ARRAYCOLUMNBASE_H
27#define TABLES_ARRAYCOLUMNBASE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/Tables/TableColumn.h>
33#include <casacore/casa/Arrays/Vector.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37//# Forward Declarations
38class BaseSlicesFunctor;
39class RefRows;
40class ColumnSlicer;
41class IPosition;
42class Slice;
43class Slicer;
44class String;
45
46
47// <summary>
48// Read and write access to an array table column with arbitrary data type
49// </summary>
50
51// <use visibility=export>
52
53// <reviewed reviewer="dschieb" date="1994/08/10" tests="none">
54// </reviewed>
55
56// <prerequisite>
57// <li> Table
58// <li> TableColumn
59// </prerequisite>
60
61// <etymology>
62// ArrayColumn<T> gives read and write access to an column in a table
63// containing an array with data type T.
64// </etymology>
65
66// <synopsis>
67// ArrayColumnBase is the base class of the templated class ArrayColumn
68// which allows readonly access to a column containing arrays with an
69// arbitrary data type. It can handle direct as well as indirect arrays.
70//
71// All get and put functions are implemented in this base class as
72// non-templated functions. Type-specific operations are done by means
73// of virtual functions in the Array classes.
74// </synopsis>
75
76// <example>
77// See module <linkto module="Tables#open">Tables</linkto>.
78// </example>
79
80
82 {
83 public:
84 // The default constructor creates a null object, i.e. it
85 // does not reference a table column.
87
88 // Construct for the given column in the given table.
89 ArrayColumnBase (const Table&, const String& columnName);
90
91 // Construct from the given table column.
92 // This constructor is useful if first a table column was constructed,
93 // its type is determined and thereafter used to construct the
94 // correct column object.
96
97 // Copy constructor (reference semantics).
99
101
102 // Assignment uses reference semantics, thus works the same
103 // as function reference.
105
106 // Change the reference to another column.
107 // This is in fact an assignment operator with reference semantics.
108 // It removes the reference to the current column and creates
109 // a reference to the column referenced in the other object.
110 // It will handle null objects correctly.
112
113 // Get the #dimensions of an array in a particular cell.
114 // If the cell does not contain an array, 0 is returned.
115 // Use the function isDefined to test if the cell contains an array.
116 uInt ndim (rownr_t rownr) const
117 { TABLECOLUMNCHECKROW(rownr); return baseColPtr_p->ndim (rownr); }
118
119 // Get the shape of an array in a particular cell.
120 // If the cell does not contain an array, a 0-dim shape is returned.
121 // Use the function isDefined to test if the cell contains an array.
122 IPosition shape (rownr_t rownr) const
123 { TABLECOLUMNCHECKROW(rownr); return baseColPtr_p->shape (rownr); }
124
125 // Counterparts of the acbGet() functions below not checking shapes, etc.
126 // They are faster and can be used for performance reasons if one
127 // knows for sure that the arguments are correct.
128 // E.g., they are used internally in virtual column engines.
129 // <group>
130 void baseGet (rownr_t rownr, ArrayBase& array) const
131 { baseColPtr_p->getArray (rownr, array); }
132 void baseGetSlice (rownr_t rownr, const Slicer& arraySection,
133 ArrayBase& array) const
134 { baseColPtr_p->getSlice (rownr, arraySection, array); }
135 // </group>
136
137 // Get the array value in a particular cell (i.e. table row).
138 // The row numbers count from 0 until #rows-1.
139 void acbGet (rownr_t rownr, ArrayBase& array, Bool resize) const;
140
141 // Get a slice of an N-dimensional array in a particular cell
142 // (i.e. table row).
143 // The row numbers count from 0 until #rows-1.
144 // The dimensionality of the slice must match the dimensionality
145 // of the table array and the slice definition should not exceed
146 // the shape of the table array.
147 void acbGetSlice (rownr_t rownr, const Slicer& arraySection, ArrayBase& array,
148 Bool resize) const;
149
150 // Get an irregular slice of an N-dimensional array in a particular cell
151 // (i.e. table row) as given by the vectors of Slice objects.
152 // The outer vector represents the array axes.
153 // A missing or empty axis means the entire axis.
154 // The inner vector represents the slices to take for each axis.
155 // For example, to get slices from 2-dim arrays:
156 // <srcblock>
157 // Vector<Vector<Slice> > slices(2); // 2-dim
158 // slices[1].resize (3); // 3 slices in 2nd dim
159 // slices[1][0] = Slice(100,20);
160 // slices[1][1] = Slice(200,18);
161 // slices[1][2] = Slice(538,30,2);
162 // // Get data. Vector of first axis is empty, thus entire axis is read.
163 // Array<Complex> data = dataCol.getColumn (slices);
164 // </srcblock>
165 // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
166 // with the last dimension representing the number of rows and the
167 // other dimensions representing the shape of the slice.
168 // The arrays in the column must have the same shape in all cells.
169 void acbGetSlice (rownr_t rownr,
170 const Vector<Vector<Slice> >& arraySlices,
171 ArrayBase& arr, Bool resize) const;
172
173 // Get the array of all values in a column.
174 // If the column contains n-dim arrays, the resulting array is (n+1)-dim
175 // with the last dimension representing the number of rows.
176 // The arrays in the column must have the same shape in all cells.
177 void acbGetColumn (ArrayBase& array, Bool resize) const;
178
179 // Get regular slices from all arrays in the column.
180 // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
181 // with the last dimension representing the number of rows and the
182 // other dimensions representing the shape of the slice.
183 // The arrays in the column must have the same shape in all cells.
184 void acbGetColumn (const Slicer& arraySection, ArrayBase& array,
185 Bool resize) const;
186
187 // Get irregular slices from all arrays in the column as given by the
188 // vectors of Slice objects. The outer vector represents the array axes.
189 // A missing or empty axis means the entire axis.
190 // The inner vector represents the slices to take for each axis.
191 // For example, to get slices from 2-dim arrays:
192 // <srcblock>
193 // Vector<Vector<Slice> > slices(2); // 2-dim
194 // slices[1].resize (3); // 3 slices in 2nd dim
195 // slices[1][0] = Slice(100,20);
196 // slices[1][1] = Slice(200,18);
197 // slices[1][2] = Slice(538,30,2);
198 // // Get data. Vector of first axis is empty, thus entire axis is read.
199 // Array<Complex> data = dataCol.getColumn (slices);
200 // </srcblock>
201 // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
202 // with the last dimension representing the number of rows and the
203 // other dimensions representing the shape of the slice.
204 // The arrays in the column must have the same shape in all cells.
205 void acbGetColumn (const Vector<Vector<Slice> >& arraySection,
207 Bool resize) const;
208
209 // Get the array of some values in a column.
210 // The Slicer object can be used to specify start, end (or length),
211 // and stride of the rows to get.
212 // If the column contains n-dim arrays, the resulting array is (n+1)-dim
213 // with the last dimension representing the number of rows in the slicer.
214 // The arrays in the column must have the same shape in all those cells.
215 void acbGetColumnRange (const Slicer& rowRange, ArrayBase& arr,
216 Bool resize) const;
217 void acbGetColumnCells (const RefRows& rownrs, ArrayBase& arr,
218 Bool resize) const;
219
220 // Get slices from some arrays in a column.
221 // The first Slicer object can be used to specify start, end (or length),
222 // and stride of the rows to get. The second Slicer object can be
223 // used to specify the slice to take from each array.
224 // If the column contains n-dim arrays, the resulting array is (n+1)-dim
225 // with the last dimension representing the number of rows in the slicer.
226 // The arrays in the column must have the same shape in all those cells.
227 // <group>
228 void acbGetColumnRange (const Slicer& rowRange,
229 const Slicer& arraySection, ArrayBase& arr,
230 Bool resize) const;
231 void acbGetColumnCells (const RefRows& rownrs,
232 const Slicer& arraySection, ArrayBase& arr,
233 Bool resize) const;
234 // </group>
235
236 // Get various slices from the given rows.
237 void acbGetColumnCells (const RefRows& rows,
238 const ColumnSlicer& columnSlicer,
239 ArrayBase& destination,
240 Bool resize) const;
241
242 // Set the shape of the array in the given row.
243 // Setting the shape is needed if the array is put in slices,
244 // otherwise the table system would not know the shape.
245 // <group>
246 void setShape (rownr_t rownr, const IPosition& shape);
247
248 // Try to store the array in a tiled way using the given tile shape.
249 void setShape (rownr_t rownr, const IPosition& shape,
250 const IPosition& tileShape);
251 // </group>
252
253 // Counterparts of the acbPut() functions below not checking shapes, etc.
254 // They are faster and can be used for performance reasons if one
255 // knows for sure that the arguments are correct.
256 // E.g., they are used internally in virtual column engines.
257 // <group>
258 void basePut (rownr_t rownr, const ArrayBase& array)
259 { baseColPtr_p->putArray (rownr, array); }
260 void basePutSlice (rownr_t rownr, const Slicer& arraySection,
261 const ArrayBase& array)
262 { baseColPtr_p->putSlice (rownr, arraySection, array); }
263 // </group>
264
265 // Put the array in a particular cell (i.e. table row).
266 // The row numbers count from 0 until #rows-1.
267 // If the shape of the table array in that cell has not already been
268 // defined, it will be defined implicitly.
269 void acbPut (rownr_t rownr, const ArrayBase& array);
270
271 // Put into a slice of an N-dimensional array in a particular cell.
272 // The row numbers count from 0 until #rows-1.
273 // The shape of the table array must have been defined.
274 // The dimensionality of the slice must match the dimensionality
275 // of the table array and the slice definition should not exceed
276 // the shape of the table array.
277 void acbPutSlice (rownr_t rownr, const Slicer& arraySection,
278 const ArrayBase& array);
279
280 void acbPutSlice (rownr_t rownr, const Vector<Vector<Slice> >& arraySlices,
281 const ArrayBase& arr);
282
283 // Put the array of all values in the column.
284 // If the column contains n-dim arrays, the source array must be (n+1)-dim
285 // with the last dimension representing the number of rows.
287
288 // Put into subsections of the table arrays in the entire column.
289 // If the column contains n-dim arrays, the source array is (n+1)-dim
290 // with the last dimension representing the number of rows and
291 // other dimensions representing the shape of the slice.
292 // The dimensionality of the slice must match the dimensionality
293 // of the table array, thus must be n-dim. Also the slice definition
294 // should not exceed the shape of the table arrays.
295 void acbPutColumn (const Slicer& arraySection, const ArrayBase& array);
296
297 void acbPutColumn (const Vector<Vector<Slice> >& arraySlices,
298 const ArrayBase& arr);
299
300 // Put the array of some values in the column.
301 // The Slicer object can be used to specify start, end (or length),
302 // and stride of the rows to put.
303 // If the column contains n-dim arrays, the source array must be (n+1)-dim
304 // with the last dimension representing the number of rows in the slicer.
305 // <group>
306 void acbPutColumnRange (const Slicer& rowRange, const ArrayBase& arr);
307 void acbPutColumnCells (const RefRows& rownrs, const ArrayBase& arr);
308 // </group>
309
310 // Put into subsection of the table arrays in some rows of the column.
311 // The first Slicer object can be used to specify start, end (or length),
312 // and stride of the rows to put. The second Slicer object can be
313 // used to specify the slice to take from each array.
314 // If the column contains n-dim arrays, the source array must be (n+1)-dim
315 // with the last dimension representing the number of rows in the slicer.
316 // <group>
317 void acbPutColumnRange (const Slicer& rowRange,
318 const Slicer& arraySection, const ArrayBase& arr);
319 void acbPutColumnCells (const RefRows& rownrs,
320 const Slicer& arraySection, const ArrayBase& arr);
321 // </group>
322
323 // Put various slices in the given rows.
324 // <group>
325 void acbPutColumnCells (const RefRows& rows,
326 const Vector<Vector<Slice> >& arraySlices,
327 const ArrayBase& source);
328 void acbPutColumnCells (const RefRows& rows,
329 const ColumnSlicer& columnSlicer,
330 const ArrayBase& source);
331 // </group>
332
333 // Put the same value in all cells of the column.
335
336 // Put the contents of that column into this one.
337 void acbPutColumn (const ArrayColumnBase& that);
338
339 // Adapt the shape of the array if possible. If the array is empty or
340 // if <src>resize=True</src>, the array is resized if needed.
341 // Otherwise checkShape is used to throw an exception if not conforming.
342 void adaptShape (const IPosition& shp,
343 ArrayBase& arr, Bool resize,
344 Int64 rownr, const String& where) const;
345
346 // Throw an exception if the array does not have the expected shape.
347 // However, False is returned if noSlicing and canChangeShape_p are True
348 // (meaning no slices are put and the shape of a full row can change).
349 // The column name is made part of the error message, as well as the rownr
350 // if it is not negative (meaning a put of a column).
351 Bool checkShape (const IPosition& expShape, const IPosition& arrShape,
352 Bool noSlicing, Int64 rownr, const String& where) const;
353
354 // A common function used by all functions that can get or put irregular
355 // array slices. The functor performs the get or put operation.
356 void handleSlices (const Vector<Vector<Slice> >& slices,
357 BaseSlicesFunctor& functor,
358 const Slicer& slicer,
359 const ArrayBase& array) const;
360 };
361
362
363
364
365// <synopsis>
366// ColumnSlicer is used in one of the ArrayColumn::getColumnCells functions.
367// That method takes a potentially complex/ selection of data out of a
368// column cell (e.g., multiple slices along each axis) and then puts them
369// into a selection of a destination array.
370// This is most easily represented as a set of source,destination slicers
371// where one is applied to the cell and the other to the destination array.
372// </synopsis>
374{
375public:
376
377 // Construct the object.
378 // It takes over the pointers to the Slicer objects and deletes them
379 // in the destructor.
380 // The shape parameter is the shape of the destination array excluding
381 // the row axis.
383 const Vector<Slicer*>& dataSlicers,
384 const Vector<Slicer*>& destinationSlicers);
385
386 // The destructor deletes all Slicer objects.
388
389 // Get the data slicers.
391 { return dataSlicers_p; }
392
393 // Get the desintation slicers.
396
397 // Get the shape.
398 const IPosition& shape() const
399 { return shape_p; }
400
401private:
402 // Delete all Slicer objects.
404
405 // Check if the slicers match the array shape.
407
408 //# Data members.
412};
413
414
415
416} //# NAMESPACE CASACORE - END
417
418#endif
#define TABLECOLUMNCHECKROW(ROWNR)
Definition TableColumn.h:49
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
void acbPutSlice(rownr_t rownr, const Vector< Vector< Slice > > &arraySlices, const ArrayBase &arr)
void reference(const ArrayColumnBase &)
Change the reference to another column.
void acbGetColumnCells(const RefRows &rownrs, const Slicer &arraySection, ArrayBase &arr, Bool resize) const
void acbGetColumn(const Vector< Vector< Slice > > &arraySection, ArrayBase &array, Bool resize) const
Get irregular slices from all arrays in the column as given by the vectors of Slice objects.
void baseGetSlice(rownr_t rownr, const Slicer &arraySection, ArrayBase &array) const
void acbGetColumn(ArrayBase &array, Bool resize) const
Get the array of all values in a column.
void acbPutColumn(const ArrayBase &array)
Put the array of all values in the column.
void acbPutColumnCells(const RefRows &rownrs, const Slicer &arraySection, const ArrayBase &arr)
void acbGetColumnRange(const Slicer &rowRange, ArrayBase &arr, Bool resize) const
Get the array of some values in a column.
void handleSlices(const Vector< Vector< Slice > > &slices, BaseSlicesFunctor &functor, const Slicer &slicer, const ArrayBase &array) const
A common function used by all functions that can get or put irregular array slices.
void setShape(rownr_t rownr, const IPosition &shape, const IPosition &tileShape)
Try to store the array in a tiled way using the given tile shape.
Bool checkShape(const IPosition &expShape, const IPosition &arrShape, Bool noSlicing, Int64 rownr, const String &where) const
Throw an exception if the array does not have the expected shape.
void acbGetColumnRange(const Slicer &rowRange, const Slicer &arraySection, ArrayBase &arr, Bool resize) const
Get slices from some arrays in a column.
ArrayColumnBase(const Table &, const String &columnName)
Construct for the given column in the given table.
void acbPutColumn(const Slicer &arraySection, const ArrayBase &array)
Put into subsections of the table arrays in the entire column.
void acbGetColumnCells(const RefRows &rownrs, ArrayBase &arr, Bool resize) const
void acbGetColumnCells(const RefRows &rows, const ColumnSlicer &columnSlicer, ArrayBase &destination, Bool resize) const
Get various slices from the given rows.
void acbPutColumn(const ArrayColumnBase &that)
Put the contents of that column into this one.
ArrayColumnBase(const ArrayColumnBase &)
Copy constructor (reference semantics).
void acbPutColumnCells(const RefRows &rows, const Vector< Vector< Slice > > &arraySlices, const ArrayBase &source)
Put various slices in the given rows.
ArrayColumnBase(const TableColumn &column)
Construct from the given table column.
void acbPutColumnRange(const Slicer &rowRange, const Slicer &arraySection, const ArrayBase &arr)
Put into subsection of the table arrays in some rows of the column.
void acbPutColumnCells(const RefRows &rows, const ColumnSlicer &columnSlicer, const ArrayBase &source)
void baseGet(rownr_t rownr, ArrayBase &array) const
Counterparts of the acbGet() functions below not checking shapes, etc.
void basePut(rownr_t rownr, const ArrayBase &array)
Counterparts of the acbPut() functions below not checking shapes, etc.
void acbGetSlice(rownr_t rownr, const Slicer &arraySection, ArrayBase &array, Bool resize) const
Get a slice of an N-dimensional array in a particular cell (i.e.
void acbPut(rownr_t rownr, const ArrayBase &array)
Put the array in a particular cell (i.e.
void basePutSlice(rownr_t rownr, const Slicer &arraySection, const ArrayBase &array)
void adaptShape(const IPosition &shp, ArrayBase &arr, Bool resize, Int64 rownr, const String &where) const
Adapt the shape of the array if possible.
void acbGet(rownr_t rownr, ArrayBase &array, Bool resize) const
Get the array value in a particular cell (i.e.
ArrayColumnBase & operator=(const ArrayColumnBase &)
Assignment uses reference semantics, thus works the same as function reference.
void acbGetSlice(rownr_t rownr, const Vector< Vector< Slice > > &arraySlices, ArrayBase &arr, Bool resize) const
Get an irregular slice of an N-dimensional array in a particular cell (i.e.
ArrayColumnBase()
The default constructor creates a null object, i.e.
void acbFillColumn(const ArrayBase &value)
Put the same value in all cells of the column.
void acbGetColumn(const Slicer &arraySection, ArrayBase &array, Bool resize) const
Get regular slices from all arrays in the column.
void setShape(rownr_t rownr, const IPosition &shape)
Set the shape of the array in the given row.
uInt ndim(rownr_t rownr) const
Get the #dimensions of an array in a particular cell.
void acbPutColumnCells(const RefRows &rownrs, const ArrayBase &arr)
void acbPutColumnRange(const Slicer &rowRange, const ArrayBase &arr)
Put the array of some values in the column.
IPosition shape(rownr_t rownr) const
Get the shape of an array in a particular cell.
void acbPutSlice(rownr_t rownr, const Slicer &arraySection, const ArrayBase &array)
Put into a slice of an N-dimensional array in a particular cell.
void acbPutColumn(const Vector< Vector< Slice > > &arraySlices, const ArrayBase &arr)
virtual void getArray(rownr_t rownr, ArrayBase &dataPtr) const
Get an array from a particular cell.
virtual void getSlice(rownr_t rownr, const Slicer &, ArrayBase &dataPtr) const
Get a slice of an N-dimensional array in a particular cell.
virtual uInt ndim(rownr_t rownr) const
Get the #dimensions of an array in a particular cell.
virtual IPosition shape(rownr_t rownr) const
Get the shape of an array in a particular cell.
virtual void putArray(rownr_t rownr, const ArrayBase &dataPtr)
Put the array value in a particular cell.
virtual void putSlice(rownr_t rownr, const Slicer &, const ArrayBase &dataPtr)
Put a slice of an N-dimensional array in a particular cell.
String validateParameters() const
Check if the slicers match the array shape.
const Vector< Slicer * > & getDestinationSlicers() const
Get the desintation slicers.
Vector< Slicer * > destinationSlicers_p
const IPosition & shape() const
Get the shape.
void freeSlicers()
Delete all Slicer objects.
const Vector< Slicer * > & getDataSlicers() const
Get the data slicers.
ColumnSlicer(const IPosition &shape, const Vector< Slicer * > &dataSlicers, const Vector< Slicer * > &destinationSlicers)
Construct the object.
Vector< Slicer * > dataSlicers_p
~ColumnSlicer()
The destructor deletes all Slicer objects.
String: the storage and methods of handling collections of characters.
Definition String.h:223
IPosition tileShape(rownr_t rownr) const
Get the tile shape of an array in a particular cell.
BaseColumn * baseColPtr_p
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition ExprNode.h:1933
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44