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