casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ScaledComplexData.h
Go to the documentation of this file.
1 //# ScaledComplexData.h: Templated virtual column engine to scale a complex table array
2 //# Copyright (C) 1999,2000,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$
27 
28 #ifndef TABLES_SCALEDCOMPLEXDATA_H
29 #define TABLES_SCALEDCOMPLEXDATA_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward Declarations
39 template<class T> class ScalarColumn;
40 
41 
42 // <summary>
43 // Templated virtual column engine to scale a complex table array
44 // </summary>
45 
46 // <use visibility=export>
47 
48 // <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
49 // </reviewed>
50 
51 // <prerequisite>
52 //# Classes you should understand before using this one.
53 // <li> VirtualColumnEngine
54 // <li> VirtualArrayColumn
55 // </prerequisite>
56 
57 // <synopsis>
58 // ScaledComplexData is a virtual column engine which scales an array
59 // of a complex type to 2 values of another type (to save disk storage).
60 // For example, <src>ScaledComplexData<Complex,Short></src> resembles the
61 // classic AIPS compress method which scales the data from float to short.
62 // The (complex) scale factor and offset value can be given in two ways:
63 // <ul>
64 // <li> As a fixed value which is used for all arrays in the column.
65 // <li> As the name of a column. In this way each array in a
66 // column can have its own scale and offset value.
67 // The scale and offset value in a row must be put before
68 // the array is put and should not be changed anymore.
69 // </ul>
70 // It is also possible to have a variable scale factor with a fixed offset
71 // value.
72 // As in FITS the scale and offset values are used as:
73 // <br><src> True_value = Stored_value * scale + offset; </src>
74 //
75 // An engine object should be used for one column only, because the stored
76 // column name is part of the engine. If it would be used for more than
77 // one column, they would all share the same stored column.
78 // When the engine is bound to a column, it is checked if the name
79 // of that column matches the given virtual column name.
80 //
81 // The engine can be used for a column containing any kind of array
82 // (thus direct or indirect, fixed or variable shaped)) as long as the
83 // virtual array can be stored in the stored array. Thus a fixed shaped
84 // virtual can use a variable shaped stored, but not vice versa.
85 // A fixed shape indirect virtual can use a stored with direct arrays.
86 //
87 // This class can also serve as an example of how to implement
88 // a virtual column engine.
89 // </synopsis>
90 
91 // <motivation>
92 // This class allows to store data in a smaller representation.
93 // It is needed to resemble the classic AIPS compress option.
94 // It adds the scale and offset value on a per row basis.
95 //
96 // Because the engine can serve only one column, it was possible to
97 // combine the engine and the column functionality in one class.
98 // This has been achieved using multiple inheritance.
99 // The advantage of this is that only one templated class is used,
100 // so less template instantiations are needed.
101 //
102 // Class ScaledArrayEngine could not be used, because complex integer
103 // types are not supported in the tabe system.
104 // </motivation>
105 
106 // <example>
107 // <srcblock>
108 // // Create the table description and 2 columns with indirect arrays in it.
109 // // The Int column will be stored, while the double will be
110 // // used as virtual.
111 // TableDesc tableDesc ("", TableDesc::Scratch);
112 // tableDesc.addColumn (ArrayColumnDesc<Short> ("storedArray"));
113 // tableDesc.addColumn (ArrayColumnDesc<Complex> ("virtualArray"));
114 //
115 // // Create a new table using the table description.
116 // SetupNewTable newtab (tableDesc, "tab.data", Table::New);
117 //
118 // // Create the array scaling engine to scale from double to Int
119 // // and bind it to the double column.
120 // // Create the table.
121 // ScaledComplexData<Complex,Short> scalingEngine("virtualArray",
122 // "storedArray", 10);
123 // newtab.bindColumn ("virtualArray", scalingEngine);
124 // Table table (newtab);
125 //
126 // // Store a 2-D array (with dim. 3,4) into each row of the column.
127 // // The shape of each array in the column is implicitly set by the put
128 // // function. This will also set the shape of the underlying Int array
129 // // (as a 3-D array with shape 2,3,4).
130 // ArrayColumn data (table, "virtualArray");
131 // Array<DComplex> someArray(IPosition(2,3,4));
132 // someArray = 0;
133 // for (uInt i=0, i<10; i++) { // table will have 10 rows
134 // table.addRow();
135 // data.put (i, someArray)
136 // }
137 // </srcblock>
138 // </example>
139 
140 // <templating arg=VirtualType>
141 // <li> only complex data types
142 // </templating>
143 // <templating arg=StoredType>
144 // <li> only built-in numerics data types
145 // </templating>
146 
147 template<class VirtualType, class StoredType>
148 class ScaledComplexData : public BaseMappedArrayEngine<VirtualType, StoredType>
149 {
150  //# Make members of parent class known.
151 public:
153 protected:
158 
159 public:
160  // Construct an engine to scale all arrays in a column with
161  // the given offset and scale factor.
162  // StoredColumnName is the name of the column where the scaled
163  // data will be put and must have data type StoredType.
164  // The virtual column using this engine must have data type VirtualType.
165  ScaledComplexData (const String& virtualColumnName,
166  const String& storedColumnName,
167  VirtualType scale,
168  VirtualType offset = 0);
169 
170  // Construct an engine to scale the arrays in a column.
171  // The scale and offset values are taken from a column with
172  // the given names. In that way each array has its own scale factor
173  // and offset value.
174  // An exception is thrown if these columns do not exist.
175  // VirtualColumnName is the name of the virtual column and is used to
176  // check if the engine gets bound to the correct column.
177  // StoredColumnName is the name of the column where the scaled
178  // data will be put and must have data type StoredType.
179  // The virtual column using this engine must have data type VirtualType.
180  // <group>
181  ScaledComplexData (const String& virtualColumnName,
182  const String& storedColumnName,
183  const String& scaleColumnName,
184  VirtualType offset = 0);
185  ScaledComplexData (const String& virtualColumnName,
186  const String& storedColumnName,
187  const String& scaleColumnName,
188  const String& offsetColumnName);
189  // </group>
190 
191  // Construct from a record specification as created by getmanagerSpec().
192  ScaledComplexData (const Record& spec);
193 
194  // Destructor is mandatory.
196 
197  // Return the type name of the engine (i.e. its class name).
198  String dataManagerType() const;
199 
200  // Record a record containing data manager specifications.
201  virtual Record dataManagerSpec() const;
202 
203  // Return the name of the class.
204  // This includes the names of the template arguments.
205  static String className();
206 
207  // The engine can access column cells.
208  virtual Bool canAccessArrayColumnCells (Bool& reask) const;
209 
210  // Register the class name and the static makeObject "constructor".
211  // This will make the engine known to the table system.
212  // The automatically invoked registration function in DataManReg.cc
213  // contains ScaledComplexData<double,Int>.
214  // Any other instantiation of this class must be registered "manually"
215  // (or added to DataManReg.cc).
216  static void registerClass();
217 
218 private:
219  // The default constructor is required for reconstruction of the
220  // engine when a table is read back.
222 
223  // Copy constructor is only used by clone().
224  // (so it is made private).
226 
227  // Assignment is not needed and therefore forbidden
228  // (so it is made private and not implemented).
231 
232  // Clone the engine object.
233  virtual DataManager* clone() const;
234 
235  // Initialize the object for a new table.
236  // It defines the keywords containing the engine parameters.
237  virtual void create (uInt initialNrrow);
238 
239  // Preparing consists of setting the writable switch and
240  // adding the initial number of rows in case of create.
241  // Furthermore it reads the keywords containing the engine parameters.
242  virtual void prepare();
243 
244  // Set the shape of the FixedShape arrays in the column.
245  // This function only gets called if the column has FixedShape arrays.
246  // The shape gets saved and used to set the shape of the arrays
247  // in the stored in case the stored has non-FixedShape arrays.
248  virtual void setShapeColumn (const IPosition& shape);
249 
250  // Define the shape of the array in the given row.
251  // When the shape of the (underlying) stored array has already been
252  // defined, it checks whether its latter dimensions match the given
253  // virtual shape. When matching, nothing will be done.
254  // When mismatching or when the stored shape has not been defined
255  // yet, the stored shape will be defined from the virtual shape and
256  // the virtual element shape.
257  // E.g. in case of a StokesVector a virtual shape of (512,512)
258  // results in a stored shape of (4,512,512).
259  virtual void setShape (uInt rownr, const IPosition& shape);
260 
261  // Get the dimensionality of the array in the given row.
262  virtual uInt ndim (uInt rownr);
263 
264  // Get the shape of the array in the given row.
265  // This is done by stripping the first dimension from the shape
266  // of the underlying stored array.
267  virtual IPosition shape (uInt rownr);
268 
269  // Get an array in the given row.
270  // This will scale and offset from the underlying array.
271  virtual void getArray (uInt rownr, Array<VirtualType>& array);
272 
273  // Put an array in the given row.
274  // This will scale and offset to the underlying array.
275  virtual void putArray (uInt rownr, const Array<VirtualType>& array);
276 
277  // Get a section of the array in the given row.
278  // This will scale and offset from the underlying array.
279  virtual void getSlice (uInt rownr, const Slicer& slicer,
280  Array<VirtualType>& array);
281 
282  // Put into a section of the array in the given row.
283  // This will scale and offset to the underlying array.
284  virtual void putSlice (uInt rownr, const Slicer& slicer,
285  const Array<VirtualType>& array);
286 
287  // Get an entire column.
288  // This will scale and offset from the underlying array.
289  virtual void getArrayColumn (Array<VirtualType>& array);
290 
291  // Put an entire column.
292  // This will scale and offset to the underlying array.
293  virtual void putArrayColumn (const Array<VirtualType>& array);
294 
295  // Get some array values in the column.
296  // This will scale and offset from the underlying array.
297  virtual void getArrayColumnCells (const RefRows& rownrs,
299 
300  // Put some array values in the column.
301  // This will scale and offset to the underlying array.
302  virtual void putArrayColumnCells (const RefRows& rownrs,
303  const Array<VirtualType>& data);
304 
305  // Get a section of all arrays in the column.
306  // This will scale and offset from the underlying array.
307  virtual void getColumnSlice (const Slicer& slicer,
308  Array<VirtualType>& array);
309 
310  // Put a section of all arrays in the column.
311  // This will scale and offset to the underlying array.
312  virtual void putColumnSlice (const Slicer& slicer,
313  const Array<VirtualType>& array);
314 
315  // Get a section of some arrays in the column.
316  // This will scale and offset from the underlying array.
317  virtual void getColumnSliceCells (const RefRows& rownrs,
318  const Slicer& slicer,
319  Array<VirtualType>& data);
320 
321  // Put into a section of some arrays in the column.
322  // This will scale and offset to the underlying array.
323  virtual void putColumnSliceCells (const RefRows& rownrs,
324  const Slicer& slicer,
325  const Array<VirtualType>& data);
326 
327  // Scale and/or offset stored to array.
328  // This is meant when reading an array from the stored column.
329  // It optimizes for scale=1 and/or offset=0.
330  void scaleOnGet (VirtualType scale, VirtualType offset,
331  Array<VirtualType>& array,
332  const Array<StoredType>& stored);
333 
334  // Scale and/or offset array to stored.
335  // This is meant when writing an array into the stored column.
336  // It optimizes for scale=1 and/or offset=0.
337  void scaleOnPut (VirtualType scale, VirtualType offset,
338  const Array<VirtualType>& array,
339  Array<StoredType>& stored);
340 
341  // Scale and/or offset stored to array for the entire column.
342  // When the scale and offset are fixed, it will do the entire array.
343  // Otherwise it iterates through the array and applies the scale
344  // and offset per row.
346  const Array<StoredType>& stored);
347 
348  // Scale and/or offset array to stored for the entire column.
349  // When the scale and offset are fixed, it will do the entire array.
350  // Otherwise it iterates through the array and applies the scale
351  // and offset per row.
352  void scaleColumnOnPut (const Array<VirtualType>& array,
353  Array<StoredType>& stored);
354 
355  // Scale and/or offset stored to array for some cells in the column.
356  // When the scale and offset are fixed, it will do the entire array.
357  // Otherwise it iterates through the array and applies the scale
358  // and offset per row.
359  void scaleCellsOnGet (Array<VirtualType>& array,
360  const Array<StoredType>& stored,
361  const RefRows& rownrs);
362 
363  // Scale and/or offset array to stored for some cells in the column.
364  // When the scale and offset are fixed, it will do the entire array.
365  // Otherwise it iterates through the array and applies the scale
366  // and offset per row.
367  void scaleCellsOnPut (const Array<VirtualType>& array,
368  Array<StoredType>& stored,
369  const RefRows& rownrs);
370 
371  // Determine the shape of an array in the stored column.
372  IPosition storedShape (const IPosition& virtualShape) const
373  { return IPosition(1,2).concatenate (virtualShape); }
374 
375  // Convert the Slicer for a virtual to a Slicer for the stored.
376  Slicer storedSlicer (const Slicer& virtualSlicer) const;
377 
378  //# Now define the data members.
379  String scaleName_p; //# name of scale column
380  String offsetName_p; //# name of offset column
381  VirtualType scale_p; //# scale factor
382  VirtualType offset_p; //# offset value
383  Bool fixedScale_p; //# scale is a fixed column
384  Bool fixedOffset_p; //# offset is a fixed column
385  ScalarColumn<VirtualType>* scaleColumn_p; //# column with scale value
386  ScalarColumn<VirtualType>* offsetColumn_p; //# column with offset value
387 
388  // Get the scale value for this row.
389  VirtualType getScale (uInt rownr);
390 
391  // Get the offset value for this row.
392  VirtualType getOffset (uInt rownr);
393 
394 public:
395  // Define the "constructor" to construct this engine when a
396  // table is read back.
397  // This "constructor" has to be registered by the user of the engine.
398  // If the engine is commonly used, its registration can be added
399  // to the registerAllCtor function in DataManReg.cc.
400  // That function gets automatically invoked by the table system.
401  static DataManager* makeObject (const String& dataManagerType,
402  const Record& spec);
403 };
404 
405 
406 
407 } //# NAMESPACE CASACORE - END
408 
409 #ifndef CASACORE_NO_AUTO_TEMPLATES
410 #include <casacore/tables/DataMan/ScaledComplexData.tcc>
411 #endif //# CASACORE_NO_AUTO_TEMPLATES
412 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
void scaleOnGet(VirtualType scale, VirtualType offset, Array< VirtualType > &array, const Array< StoredType > &stored)
Scale and/or offset stored to array.
virtual void putArray(uInt rownr, const Array< VirtualType > &array)
Put an array in the given row.
virtual void getArray(uInt rownr, Array< VirtualType > &array)
Get an array in the given row.
VirtualType getOffset(uInt rownr)
Get the offset value for this row.
static DataManager * makeObject(const String &dataManagerType, const Record &spec)
Define the &quot;constructor&quot; to construct this engine when a table is read back.
virtual void prepare()
Preparing consists of setting the writable switch and adding the initial number of rows in case of cr...
virtual void putColumnSlice(const Slicer &slicer, const Array< VirtualType > &array)
Put a section of all arrays in the column.
void scaleColumnOnPut(const Array< VirtualType > &array, Array< StoredType > &stored)
Scale and/or offset array to stored for the entire column.
IPosition concatenate(const IPosition &other) const
Return an IPosition as the concetanation of this and another IPosition.
TableExprNode array(const TableExprNode &values, const TableExprNodeSet &shape)
Create an array of the given shape and fill it with the values.
Definition: ExprNode.h:1886
Templated virtual column engine for a table array of any type.
virtual void putSlice(uInt rownr, const Slicer &slicer, const Array< VirtualType > &array)
Put into a section of the array in the given row.
ScalarColumn< VirtualType > * offsetColumn_p
virtual void getSlice(uInt rownr, const Slicer &slicer, Array< VirtualType > &array)
Get a section of the array in the given row.
~ScaledComplexData()
Destructor is mandatory.
virtual void getArrayColumn(Array< VirtualType > &array)
Get an entire column.
virtual Bool canAccessArrayColumnCells(Bool &reask) const
The engine can access column cells.
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
void scaleOnPut(VirtualType scale, VirtualType offset, const Array< VirtualType > &array, Array< StoredType > &stored)
Scale and/or offset array to stored.
virtual void putColumnSliceCells(const RefRows &rownrs, const Slicer &slicer, const Array< VirtualType > &data)
Put into a section of some arrays in the column.
Slicer storedSlicer(const Slicer &virtualSlicer) const
Convert the Slicer for a virtual to a Slicer for the stored.
virtual uInt ndim(uInt rownr)
Get the dimensionality of the array in the given row.
virtual void putArrayColumn(const Array< VirtualType > &array)
Put an entire column.
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
String dataManagerType() const
Return the type name of the engine (i.e.
IPosition storedShape(const IPosition &virtualShape) const
Determine the shape of an array in the stored column.
void scaleColumnOnGet(Array< VirtualType > &array, const Array< StoredType > &stored)
Scale and/or offset stored to array for the entire column.
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual void getColumnSlice(const Slicer &slicer, Array< VirtualType > &array)
Get a section of all arrays in the column.
void scaleCellsOnGet(Array< VirtualType > &array, const Array< StoredType > &stored, const RefRows &rownrs)
Scale and/or offset stored to array for some cells in the column.
ScaledComplexData()
The default constructor is required for reconstruction of the engine when a table is read back...
Templated virtual column engine to scale a complex table array.
virtual DataManager * clone() const
Clone the engine object.
virtual void putArrayColumnCells(const RefRows &rownrs, const Array< VirtualType > &data)
Put some array values in the column.
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
virtual void setShape(uInt rownr, const IPosition &shape)
Define the shape of the array in the given row.
static String className()
Return the name of the class.
virtual void getColumnSliceCells(const RefRows &rownrs, const Slicer &slicer, Array< VirtualType > &data)
Get a section of some arrays in the column.
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:289
virtual void getArrayColumnCells(const RefRows &rownrs, Array< VirtualType > &data)
Get some array values in the column.
ScalarColumn< VirtualType > * scaleColumn_p
static void registerClass()
Register the class name and the static makeObject &quot;constructor&quot;.
virtual void create(uInt initialNrrow)
Initialize the object for a new table.
VirtualType getScale(uInt rownr)
Get the scale value for this row.
Abstract base class for a data manager.
Definition: DataManager.h:224
void scaleCellsOnPut(const Array< VirtualType > &array, Array< StoredType > &stored, const RefRows &rownrs)
Scale and/or offset array to stored for some cells in the column.
virtual Record dataManagerSpec() const
Record a record containing data manager specifications.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual IPosition shape(uInt rownr)
Get the shape of the array in the given row.
virtual void setShapeColumn(const IPosition &shape)
Set the shape of the FixedShape arrays in the column.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42