casacore
Loading...
Searching...
No Matches
MappedArrayEngine.h
Go to the documentation of this file.
1//# MappedArrayEngine.h: Templated virtual column engine to map a table array
2//# Copyright (C) 2005
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_MAPPEDARRAYENGINE_H
27#define TABLES_MAPPEDARRAYENGINE_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/DataMan/BaseMappedArrayEngine.h>
32
33namespace casacore { //# NAMESPACE CASACORE - BEGIN
34
35
36// <summary>
37// Templated virtual column engine to map the data type of a table array
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="Gareth Hunt" date="94Nov17" tests="">
43// </reviewed>
44
45// <prerequisite>
46//# Classes you should understand before using this one.
47// <li> VirtualColumnEngine
48// <li> VirtualArrayColumn
49// </prerequisite>
50
51// <synopsis>
52// MappedArrayEngine is a virtual column engine which maps an array
53// of one type to another type (without any scaling).
54//
55// An engine object should be used for one column only, because the stored
56// column name is part of the engine. If it would be used for more than
57// one column, they would all share the same stored column.
58// When the engine is bound to a column, it is checked if the name
59// of that column matches the given virtual column name.
60//
61// The engine can be used for a column containing any kind of array
62// (thus direct or indirect, fixed or variable shaped)) as long as the
63// virtual array can be stored in the stored array. Thus a fixed shaped
64// virtual can use a variable shaped stored, but not vice versa.
65// A fixed shape indirect virtual can use a stored with direct arrays.
66// </synopsis>
67
68// <motivation>
69// For precision it is sometimes needed to store the visibility data in a
70// MeasurementSet in double precision. To be able to use other applications
71// on such data, it is needed to map them to single precision.
72//
73// Because the engine can serve only one column, it was possible to
74// combine the engine and the column functionality in one class.
75// This has been achieved using multiple inheritance.
76// The advantage of this is that only one templated class is used,
77// so less template instantiations are needed.
78// </motivation>
79
80// <example>
81// <srcblock>
82// // Create the table description and 2 columns with indirect arrays in it.
83// // The Int column will be stored, while the double will be
84// // used as virtual.
85// TableDesc tableDesc ("", TableDesc::Scratch);
86// tableDesc.addColumn (ArrayColumnDesc<Int> ("storedArray"));
87// tableDesc.addColumn (ArrayColumnDesc<double> ("virtualArray"));
88//
89// // Create a new table using the table description.
90// SetupNewTable newtab (tableDesc, "tab.data", Table::New);
91//
92// // Create the array mapping engine to map from double to Int
93// // and bind it to the double column.
94// // Create the table.
95// MappedArrayEngine<double,Int> mappingEngine("virtualArray",
96// "storedArray", 10);
97// newtab.bindColumn ("virtualArray", mappingEngine);
98// Table table (newtab);
99//
100// // Store a 3-D array (with dim. 2,3,4) into each row of the column.
101// // The shape of each array in the column is implicitly set by the put
102// // function. This will also set the shape of the underlying Int array.
103// ArrayColumn data (table, "virtualArray");
104// Array<double> someArray(IPosition(4,2,3,4));
105// someArray = 0;
106// for (rownr_t i=0, i<10; i++) { // table will have 10 rows
107// table.addRow();
108// data.put (i, someArray)
109// }
110// </srcblock>
111// </example>
112
113// <templating arg=VirtualType>
114// <li> only suited for built-in numerics data types
115// </templating>
116// <templating arg=StoredType>
117// <li> only suited for built-in numerics data types
118// </templating>
119
120template<class VirtualType, class StoredType> class MappedArrayEngine : public BaseMappedArrayEngine<VirtualType, StoredType>
121{
122 //# Make members of parent class known.
123public:
124 using BaseMappedArrayEngine<VirtualType,StoredType>::virtualName;
125protected:
126 using BaseMappedArrayEngine<VirtualType,StoredType>::storedName;
127 using BaseMappedArrayEngine<VirtualType,StoredType>::table;
128 using BaseMappedArrayEngine<VirtualType,StoredType>::column;
129 using BaseMappedArrayEngine<VirtualType,StoredType>::setNames;
130
131public:
132 // Construct an engine to map all arrays in a column.
133 // StoredColumnName is the name of the column where the mapped
134 // data will be put and must have data type StoredType.
135 // The virtual column using this engine must have data type VirtualType.
136 MappedArrayEngine (const String& virtualColumnName,
137 const String& storedColumnName);
138
139 // Construct from a record specification as created by dataManagerSpec().
141
142 // Destructor is mandatory.
144
145 // Assignment is not needed and therefore forbidden.
148
149 // Return the type name of the engine (i.e. its class name).
150 virtual String dataManagerType() const;
151
152 // Get the name given to the engine (is the virtual column name).
153 virtual String dataManagerName() const;
154
155 // Record a record containing data manager specifications.
156 virtual Record dataManagerSpec() const;
157
158 // Return the name of the class.
159 // This includes the names of the template arguments.
161
162 // Register the class name and the static makeObject "constructor".
163 // This will make the engine known to the table system.
164 // The automatically invoked registration function in DataManReg.cc
165 // contains MappedArrayEngine<double,Int>.
166 // Any other instantiation of this class must be registered "manually"
167 // (or added to DataManReg.cc).
168 static void registerClass();
169
170private:
171 // Copy constructor is only used by clone().
172 // (so it is made private).
174
175 // Clone the engine object.
177
178 // Copy the stored array to the virtual array.
180 const Array<StoredType>& stored);
181
182 // Copy the virtual array to the stored array.
183 virtual void mapOnPut (const Array<VirtualType>& array,
184 Array<StoredType>& stored);
185
186
187public:
188 // Define the "constructor" to construct this engine when a
189 // table is read back.
190 // This "constructor" has to be registered by the user of the engine.
191 // If the engine is commonly used, its registration can be added
192 // to the registerAllCtor function in DataManReg.cc.
193 // That function gets automatically invoked by the table system.
195 const Record& spec);
196};
197
198
199
200} //# NAMESPACE CASACORE - END
201
202#ifndef CASACORE_NO_AUTO_TEMPLATES
203#include <casacore/tables/DataMan/MappedArrayEngine.tcc>
204#endif //# CASACORE_NO_AUTO_TEMPLATES
205#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.
virtual String dataManagerName() const
Get the name given to the engine (is the virtual column name).
MappedArrayEngine(const Record &spec)
Construct from a record specification as created by dataManagerSpec().
~MappedArrayEngine()
Destructor is mandatory.
virtual void mapOnPut(const Array< VirtualType > &array, Array< StoredType > &stored)
Copy the virtual array to the stored array.
static void registerClass()
Register the class name and the static makeObject "constructor".
DataManager * clone() const
Clone the engine object.
virtual String dataManagerType() const
Return the type name of the engine (i.e.
virtual Record dataManagerSpec() const
Record a record containing data manager specifications.
MappedArrayEngine(const MappedArrayEngine< VirtualType, StoredType > &)
Copy constructor is only used by clone().
static String className()
Return the name of the class.
MappedArrayEngine(const String &virtualColumnName, const String &storedColumnName)
Construct an engine to map all arrays in a column.
virtual void mapOnGet(Array< VirtualType > &array, const Array< StoredType > &stored)
Copy the stored array to the virtual array.
static DataManager * makeObject(const String &dataManagerType, const Record &spec)
Define the "constructor" to construct this 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
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