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