casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArrayColumn.h
Go to the documentation of this file.
1 //# ArrayColumn.h: access to an array table column with arbitrary data type
2 //# Copyright (C) 1994,1995,1996,1997,1998,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: aips2-request@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 //# $Id: ArrayColumn.h 21521 2014-12-10 08:06:42Z gervandiepen $
27 
28 #ifndef TABLES_ARRAYCOLUMN_H
29 #define TABLES_ARRAYCOLUMN_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward Declarations
41 class ColumnSlicer;
42 
43 
44 // <summary>
45 // Read and write access to an array table column with arbitrary data type
46 // </summary>
47 
48 // <use visibility=export>
49 
50 // <reviewed reviewer="dschieb" date="1994/08/10" tests="none">
51 // </reviewed>
52 
53 // <prerequisite>
54 // <li> Table
55 // <li> ArrayColumnBase
56 // </prerequisite>
57 
58 // <etymology>
59 // ArrayColumn<T> gives read and write access to an column in a table
60 // containing an array with data type T.
61 // </etymology>
62 
63 // <synopsis>
64 // The class ArrayColumn allows readonly access to a column
65 // containing arrays with an arbitrary data type. It can handle direct
66 // as well as indirect arrays.
67 // It is possible to get the data in an individual cell (i.e. table row);
68 // either the whole array or a slice of the array can be accessed.
69 // It is also possible to get the column as a whole if the arrays
70 // in all cells of the column have the same shape (which is always true
71 // for direct arrays). As in the case of individual cells it is possible
72 // to get the entire arrays or a slice of the arrays.
73 //
74 // A default constructor is defined to allow construction of an array
75 // of ArrayColumn objects. However, this constructs an object not
76 // referencing a column. Functions like get, etc. will fail (i.e. result
77 // in a segmentation fault) when used on such objects. The functions
78 // isNull and throwIfNull can be used to test on this.
79 // The functions attach and reference can fill in the object.
80 //
81 // The assignment operator is not defined for this class, because it was
82 // felt it would be too confusing. Instead the function reference can
83 // be used to do assignment with reference semantics. An assignment
84 // with copy semantics makes no sense for a readonly column.
85 // </synopsis>
86 
87 // <templating arg=T>
88 // <li> Default constructor
89 // <li> Copy constructor
90 // <li> Assignment operator
91 // </templating>
92 
93 // <example>
94 // See module <linkto module="Tables#open">Tables</linkto>.
95 // </example>
96 
97 
98 template<class T>
99 class ArrayColumn : public ArrayColumnBase
100 {
101 public:
102 
103  // The default constructor creates a null object, i.e. it
104  // does not reference a table column.
105  // The sole purpose of this constructor is to allow construction
106  // of an array of ArrayColumn objects.
107  // The functions reference and attach can be used to make a null object
108  // reference a column.
109  // Note that get functions, etc. will cause a segmentation fault
110  // when operating on a null object. It was felt it was too expensive
111  // to test on null over and over again. The user should use the isNull
112  // or throwIfNull function in case of doubt.
113  ArrayColumn();
114 
115  // Construct for the given column in the given table.
116  ArrayColumn (const Table&, const String& columnName);
117 
118  // Construct from the given table column.
119  // This constructor is useful if first a table column was constructed,
120  // its type is determined and thereafter used to construct the
121  // correct column object.
122  explicit ArrayColumn (const TableColumn&);
123 
124  // Copy constructor (reference semantics).
125  ArrayColumn (const ArrayColumn<T>&);
126 
127  ~ArrayColumn();
128 
129  // Clone the object.
130  virtual TableColumn* clone() const;
131 
132  // Assignment uses reference semantics, thus works the same
133  // as function reference.
134  ArrayColumn<T>& operator= (const ArrayColumn<T>&);
135 
136  // Change the reference to another column.
137  // This is in fact an assignment operator with reference semantics.
138  // It removes the reference to the current column and creates
139  // a reference to the column referenced in the other object.
140  // It will handle null objects correctly.
141  void reference (const ArrayColumn<T>&);
142 
143  // Attach a column to the object.
144  // This is in fact only a shorthand for
145  // <br><src> reference (ArrayColumn<T> (table, columnName)); </src>
146  void attach (const Table& table, const String& columnName)
147  { reference (ArrayColumn<T> (table, columnName)); }
148 
149  // Get the #dimensions of an array in a particular cell.
150  // If the cell does not contain an array, 0 is returned.
151  // Use the function isDefined to test if the cell contains an array.
152  uInt ndim (rownr_t rownr) const
153  { TABLECOLUMNCHECKROW(rownr); return baseColPtr_p->ndim (rownr); }
154 
155  // Get the shape of an array in a particular cell.
156  // If the cell does not contain an array, a 0-dim shape is returned.
157  // Use the function isDefined to test if the cell contains an array.
158  IPosition shape (rownr_t rownr) const
159  { TABLECOLUMNCHECKROW(rownr); return baseColPtr_p->shape (rownr); }
160 
161  // Get the array value in a particular cell (i.e. table row).
162  // The row numbers count from 0 until #rows-1.
163  // <group>
164  // According to the assignment rules of class Array, the destination
165  // array must be empty or its shape must conform the table array shape.
166  // However, if the resize flag is set the destination array will be
167  // resized if not conforming.
168  void get (rownr_t rownr, Array<T>& array, Bool resize = False) const;
169  Array<T> get (rownr_t rownr) const;
170  Array<T> operator() (rownr_t rownr) const;
171  // </group>
172 
173  // Get a slice of an N-dimensional array in a particular cell
174  // (i.e. table row).
175  // The row numbers count from 0 until #rows-1.
176  // The dimensionality of the slice must match the dimensionality
177  // of the table array and the slice definition should not exceed
178  // the shape of the table array.
179  // <group>
180  // According to the assignment rules of class Array, the destination
181  // array must be empty or its shape must conform the shape of the
182  // table array slice.
183  // However, if the resize flag is set the destination array will be
184  // resized if not conforming.
185  void getSlice (rownr_t rownr, const Slicer& arraySection, Array<T>& array,
186  Bool resize = False) const;
187  Array<T> getSlice (rownr_t rownr, const Slicer& arraySection) const;
188  // </group>
189 
190  // Get an irregular slice of an N-dimensional array in a particular cell
191  // (i.e. table row) as given by the vectors of Slice objects.
192  // The outer vector represents the array axes.
193  // A missing or empty axis means the entire axis.
194  // The inner vector represents the slices to take for each axis.
195  // For example, to get slices from 2-dim arrays:
196  // <srcblock>
197  // Vector<Vector<Slice> > slices(2); // 2-dim
198  // slices[1].resize (3); // 3 slices in 2nd dim
199  // slices[1][0] = Slice(100,20);
200  // slices[1][1] = Slice(200,18);
201  // slices[1][2] = Slice(538,30,2);
202  // // Get data. Vector of first axis is empty, thus entire axis is read.
203  // Array<Complex> data = dataCol.getColumn (slices);
204  // </srcblock>
205  // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
206  // with the last dimension representing the number of rows and the
207  // other dimensions representing the shape of the slice.
208  // The arrays in the column must have the same shape in all cells.
209  // <group>
210  // According to the assignment rules of class Array, the destination
211  // array must be empty or its shape must conform the resulting (n+1)-dim
212  // array.
213  // However, if the resize flag is set the destination array will be
214  // resized if not conforming.
215  void getSlice (rownr_t rownr,
216  const Vector<Vector<Slice> >& arraySlices,
217  Array<T>& arr, Bool resize = False) const;
218  Array<T> getSlice (rownr_t rownr,
219  const Vector<Vector<Slice> >& arraySlices) const;
220  // </group>
221 
222  // Get the array of all values in a column.
223  // If the column contains n-dim arrays, the resulting array is (n+1)-dim
224  // with the last dimension representing the number of rows.
225  // The arrays in the column must have the same shape in all cells.
226  // <group>
227  // According to the assignment rules of class Array, the destination
228  // array must be empty or its shape must conform the resulting (n+1)-dim
229  // array.
230  // However, if the resize flag is set the destination array will be
231  // resized if not conforming.
232  void getColumn (Array<T>& array, Bool resize = False) const;
233  Array<T> getColumn() const;
234  // </group>
235 
236  // Get regular slices from all arrays in the column.
237  // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
238  // with the last dimension representing the number of rows and the
239  // other dimensions representing the shape of the slice.
240  // The arrays in the column must have the same shape in all cells.
241  // <group>
242  // According to the assignment rules of class Array, the destination
243  // array must be empty or its shape must conform the resulting (n+1)-dim
244  // array.
245  // However, if the resize flag is set the destination array will be
246  // resized if not conforming.
247  void getColumn (const Slicer& arraySection, Array<T>& array,
248  Bool resize = False) const;
249  Array<T> getColumn (const Slicer& arraySection) const;
250  // </group>
251 
252  // Get irregular slices from all arrays in the column as given by the
253  // vectors of Slice objects. The outer vector represents the array axes.
254  // A missing or empty axis means the entire axis.
255  // The inner vector represents the slices to take for each axis.
256  // For example, to get slices from 2-dim arrays:
257  // <srcblock>
258  // Vector<Vector<Slice> > slices(2); // 2-dim
259  // slices[1].resize (3); // 3 slices in 2nd dim
260  // slices[1][0] = Slice(100,20);
261  // slices[1][1] = Slice(200,18);
262  // slices[1][2] = Slice(538,30,2);
263  // // Get data. Vector of first axis is empty, thus entire axis is read.
264  // Array<Complex> data = dataCol.getColumn (slices);
265  // </srcblock>
266  // If the column contains n-dim arrays, the resulting array is (n+1)-dim.
267  // with the last dimension representing the number of rows and the
268  // other dimensions representing the shape of the slice.
269  // The arrays in the column must have the same shape in all cells.
270  // <group>
271  // According to the assignment rules of class Array, the destination
272  // array must be empty or its shape must conform the resulting (n+1)-dim
273  // array.
274  // However, if the resize flag is set the destination array will be
275  // resized if not conforming.
276  void getColumn (const Vector<Vector<Slice> >& arraySection, Array<T>& array,
277  Bool resize = False) const;
278  Array<T> getColumn (const Vector<Vector<Slice> >& arraySection) const;
279  // </group>
280 
281  // Get the array of some values in a column.
282  // The Slicer object can be used to specify start, end (or length),
283  // and stride of the rows to get.
284  // If the column contains n-dim arrays, the resulting array is (n+1)-dim
285  // with the last dimension representing the number of rows in the slicer.
286  // The arrays in the column must have the same shape in all those cells.
287  // According to the assignment rules of class Array, the destination
288  // array must be empty or its shape must conform the resulting (n+1)-dim
289  // array.
290  // However, if the resize flag is set the destination array will be
291  // resized if not conforming.
292  // <group>
293  void getColumnRange (const Slicer& rowRange, Array<T>& arr,
294  Bool resize = False) const;
295  Array<T> getColumnRange (const Slicer& rowRange) const;
296  void getColumnCells (const RefRows& rownrs, Array<T>& arr,
297  Bool resize = False) const;
298  Array<T> getColumnCells (const RefRows& rownrs) const;
299  // </group>
300 
301  // Get slices from some arrays in a column.
302  // The first Slicer object can be used to specify start, end (or length),
303  // and stride of the rows to get. The second Slicer object can be
304  // used to specify the slice to take from each array.
305  // If the column contains n-dim arrays, the resulting array is (n+1)-dim
306  // with the last dimension representing the number of rows in the slicer.
307  // The arrays in the column must have the same shape in all those cells.
308  // According to the assignment rules of class Array, the destination
309  // array must be empty or its shape must conform the resulting (n+1)-dim
310  // array.
311  // However, if the resize flag is set the destination array will be
312  // resized if not conforming.
313  // <group>
314  void getColumnRange (const Slicer& rowRange,
315  const Slicer& arraySection, Array<T>& arr,
316  Bool resize = False) const;
317  Array<T> getColumnRange (const Slicer& rowRange,
318  const Slicer& arraySection) const;
319  void getColumnCells (const RefRows& rownrs,
320  const Slicer& arraySection, Array<T>& arr,
321  Bool resize = False) const;
322  Array<T> getColumnCells (const RefRows& rownrs,
323  const Slicer& arraySection) const;
324  // </group>
325 
326  // Similar to getColumn (arraySlices, arr, resize) except it
327  // gets the slices for the given rows instead of all rows.
328  void getColumnCells (const RefRows& rows,
329  const ColumnSlicer & slicerSet,
330  Array<T>& destination,
331  Bool resize = False) const;
332 
333  // Set the shape of the array in the given row.
334  // Setting the shape is needed if the array is put in slices,
335  // otherwise the table system would not know the shape.
336  // <group>
337  void setShape (rownr_t rownr, const IPosition& shape);
338 
339  // Try to store the array in a tiled way using the given tile shape.
340  void setShape (rownr_t rownr, const IPosition& shape,
341  const IPosition& tileShape);
342  // </group>
343 
344  // Put the array in a particular cell (i.e. table row).
345  // The row numbers count from 0 until #rows-1.
346  // If the shape of the table array in that cell has not already been
347  // defined, it will be defined implicitly.
348  void put (rownr_t rownr, const Array<T>& array);
349 
350  // Copy the value of a cell of that column to a cell of this column.
351  // This function uses a generic TableColumn object as input.
352  // The data types of both columns must be the same, otherwise an
353  // exception is thrown.
354  // <group>
355  // Use the same row numbers for both cells.
356  void put (rownr_t rownr, const TableColumn& that,
357  Bool preserveTileShape=False)
358  { put (rownr, that, rownr, preserveTileShape); }
359  // Use possibly different row numbers for that (i.e. input) and
360  // and this (i.e. output) cell.
361  void put (rownr_t thisRownr, const TableColumn& that, rownr_t thatRownr,
362  Bool preserveTileShape=False);
363  // For backward compatibility (otherwise ambigious with put taking Bool).
364  void put (uInt thisRownr, const TableColumn& that, uInt thatRownr,
365  Bool preserveTileShape=False)
366  { put (rownr_t(thisRownr), that, rownr_t(thatRownr), preserveTileShape); }
367  // </group>
368 
369  // Put into a slice of an N-dimensional array in a particular cell.
370  // The row numbers count from 0 until #rows-1.
371  // The shape of the table array must have been defined.
372  // The dimensionality of the slice must match the dimensionality
373  // of the table array and the slice definition should not exceed
374  // the shape of the table array.
375  void putSlice (rownr_t rownr, const Slicer& arraySection,
376  const Array<T>& array);
377 
378  void putSlice (rownr_t rownr, const Vector<Vector<Slice> >& arraySlices,
379  const Array<T>& arr);
380 
381  // Put the array of all values in the column.
382  // If the column contains n-dim arrays, the source array must be (n+1)-dim
383  // with the last dimension representing the number of rows.
384  void putColumn (const Array<T>& array);
385 
386  // Put into subsections of the table arrays in the entire column.
387  // If the column contains n-dim arrays, the source array is (n+1)-dim
388  // with the last dimension representing the number of rows and
389  // other dimensions representing the shape of the slice.
390  // The dimensionality of the slice must match the dimensionality
391  // of the table array, thus must be n-dim. Also the slice definition
392  // should not exceed the shape of the table arrays.
393  void putColumn (const Slicer& arraySection, const Array<T>& array);
394 
395  void putColumn (const Vector<Vector<Slice> >& arraySlices,
396  const Array<T>& arr);
397 
398  // Put the array of some values in the column.
399  // The Slicer object can be used to specify start, end (or length),
400  // and stride of the rows to put.
401  // If the column contains n-dim arrays, the source array must be (n+1)-dim
402  // with the last dimension representing the number of rows in the slicer.
403  // <group>
404  void putColumnRange (const Slicer& rowRange, const Array<T>& arr);
405  void putColumnCells (const RefRows& rownrs, const Array<T>& arr);
406  // </group>
407 
408  // Put into subsection of the table arrays in some rows of the column.
409  // The first Slicer object can be used to specify start, end (or length),
410  // and stride of the rows to put. The second Slicer object can be
411  // used to specify the slice to take from each array.
412  // If the column contains n-dim arrays, the source array must be (n+1)-dim
413  // with the last dimension representing the number of rows in the slicer.
414  // <group>
415  void putColumnRange (const Slicer& rowRange,
416  const Slicer& arraySection, const Array<T>& arr);
417  void putColumnCells (const RefRows& rownrs,
418  const Slicer& arraySection, const Array<T>& arr);
419  // </group>
420 
421  // Same as putColumn(arraySlices, arr) except that it puts for the given
422  // rows instead of all rows.
423  // <group>
424  void putColumnCells (const RefRows& rows,
425  const Vector<Vector<Slice> >& arraySlices,
426  const Array<T>& arr);
427  void putSliceFromRows (const RefRows& rows,
428  const Vector<Vector<Slice> >& arraySlices,
429  const Array<T>& source)
430  { putColumnCells (rows, arraySlices, source); }
431  void putColumnCells (const RefRows& rows,
432  const ColumnSlicer & columnSlicer,
433  const Array<T>& source);
434  // </group>
435 
436  // Put the same value in all cells of the column.
437  void fillColumn (const Array<T>& value);
438 
439  // Put the contents of a column with the same data type into this column.
440  // To put the contents of a column with a different data type into
441  // this column, the function TableColumn::putColumn can be used
442  // (provided the data type promotion is possible).
443  // In fact, this function is an assignment operator with copy semantics.
444  void putColumn (const ArrayColumn<T>& that);
445 
446 private:
447  // Check if the data type matches the column data type.
448  void checkDataType() const;
449 };
450 
451 
452 
453 //# Explicitly instantiate these templates in ArrayColumn_tmpl.cc
454  extern template class ArrayColumn<Bool>;
455  extern template class ArrayColumn<Char>;
456  extern template class ArrayColumn<Short>;
457  extern template class ArrayColumn<uShort>;
458  extern template class ArrayColumn<Int>;
459  extern template class ArrayColumn<uInt>;
460  extern template class ArrayColumn<Int64>;
461  extern template class ArrayColumn<Float>;
462  extern template class ArrayColumn<Double>;
463  extern template class ArrayColumn<Complex>;
464  extern template class ArrayColumn<DComplex>;
465  extern template class ArrayColumn<String>;
466 
467 
468 } //# NAMESPACE CASACORE - END
469 
470 
471 //# Make old name ROArrayColumn still available.
472 #define ROArrayColumn ArrayColumn
473 
474 
475 #ifndef CASACORE_NO_AUTO_TEMPLATES
476 #include <casacore/tables/Tables/ArrayColumn.tcc>
477 #endif //# CASACORE_NO_AUTO_TEMPLATES
478 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:118
A 1-D Specialization of the Array class.
Definition: ArrayFwd.h:9
#define TABLECOLUMNCHECKROW(ROWNR)
Definition: TableColumn.h:51
void setShape(rownr_t rownr, const IPosition &shape)
Set the shape of the array in the given row.
ArrayColumn< T > & operator=(const ArrayColumn< T > &)
Assignment uses reference semantics, thus works the same as function reference.
Array< T > getColumn() const
Main interface class to a read/write table.
Definition: Table.h:157
IPosition shape(rownr_t rownr) const
Get the shape of an array in a particular cell.
Definition: ArrayColumn.h:158
IPosition tileShape(rownr_t rownr) const
Get the tile shape of an array in a particular cell.
Definition: TableColumn.h:235
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1929
void checkDataType() const
Check if the data type matches the column data type.
void reference(const ArrayColumn< T > &)
Change the reference to another column.
virtual uInt ndim(rownr_t rownr) const
Get the #dimensions of an array in a particular cell.
void putColumn(const Array< T > &array)
Put the array of all values in the column.
TableColumn()
The default constructor creates a null object, i.e.
BaseColumn * baseColPtr_p
Definition: TableColumn.h:388
Table table() const
Get the Table object this column belongs to.
ArrayColumn()
The default constructor creates a null object, i.e.
uInt ndim(rownr_t rownr) const
Get the #dimensions of an array in a particular cell.
Definition: ArrayColumn.h:152
void putSliceFromRows(const RefRows &rows, const Vector< Vector< Slice > > &arraySlices, const Array< T > &source)
Definition: ArrayColumn.h:427
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
void putColumnRange(const Slicer &rowRange, const Array< T > &arr)
Put the array of some values in the column.
void fillColumn(const Array< T > &value)
Put the same value in all cells of the column.
void put(rownr_t rownr, const Array< T > &array)
Put the array in a particular cell (i.e.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void attach(const Table &table, const String &columnName)
Attach a column to the object.
Definition: ArrayColumn.h:146
void putSlice(rownr_t rownr, const Slicer &arraySection, const Array< T > &array)
Put into a slice of an N-dimensional array in a particular cell.
Read and write access to an array table column with arbitrary data type.
Definition: CopyRecord.h:48
void put(uInt thisRownr, const TableColumn &that, uInt thatRownr, Bool preserveTileShape=False)
For backward compatibility (otherwise ambigious with put taking Bool).
Definition: ArrayColumn.h:364
Read/write access to a table column.
Definition: TableColumn.h:98
const Bool False
Definition: aipstype.h:44
void putColumnCells(const RefRows &rownrs, const Array< T > &arr)
void getColumnCells(const RefRows &rownrs, Array< T > &arr, Bool resize=False) const
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:288
Array< T > operator()(rownr_t rownr) const
void put(rownr_t rownr, const TableColumn &that, Bool preserveTileShape=False)
Copy the value of a cell of that column to a cell of this column.
Definition: ArrayColumn.h:356
virtual IPosition shape(rownr_t rownr) const
Get the shape of an array in a particular cell.
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
void getSlice(rownr_t rownr, const Slicer &arraySection, Array< T > &array, Bool resize=False) const
Get a slice of an N-dimensional array in a particular cell (i.e.
void getColumnRange(const Slicer &rowRange, Array< T > &arr, Bool resize=False) const
Get the array of some values in a column.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
virtual TableColumn * clone() const
Clone the object.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
unsigned int uInt
Definition: aipstype.h:51