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