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