casacore
Loading...
Searching...
No Matches
MeasConvert.h
Go to the documentation of this file.
1// # MeasConvert.h: Conversion of Measures
2// # Copyright (C) 1995,1996,1997,1998,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 MEASURES_MEASCONVERT_H
27#define MEASURES_MEASCONVERT_H
28
29// # Includes
30#include <memory>
31#include <vector>
32
33#include <casacore/casa/aips.h>
34#include <casacore/measures/Measures/MConvertBase.h>
35#include <casacore/casa/Quanta/Quantum.h>
36#include <casacore/measures/Measures/Measure.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40// # Forward Declarations
41class MCBase;
42class MeasVal;
43
44// # Typedefs
45
46// # Constants
47
48// <summary> Conversion of Measures </summary>
49
50// <use visibility=export>
51
52// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasure" demos="">
53// </reviewed>
54
55// <prerequisite>
56// <li> <linkto class=Measure>Measure</linkto> class
57// <li> <linkto class=MRBase>MeasRef</linkto> base class
58// <li> <linkto class=MConvertBase>MConvertBase</linkto> class
59// <li> <linkto class=Quantum>Quantum</linkto> class
60// </prerequisite>
61//
62// <etymology>
63// </etymology>
64//
65// <synopsis>
66// MeasConvert can convert a Measure to the same type of Measure in a
67// different reference frame. The MeasConvert is a templated class, but
68// has typedefs, which are strongly recommended to be used,
69// for the allowed conversions, like <src>MEpoch::Convert.</src><br>
70// The basic operation is to create a MeasConvert with either of:
71// <ul>
72// <li> MEpoch::Convert(MEpoch, MEpoch::Ref), where the
73// <linkto class=MEpoch>MEpoch</linkto> is a template for subsequent
74// conversions, i.e. it will remember the value (with its reference) and
75// the <linkto class=MeasRef>MeasRef</linkto> output reference.
76// <li> MEpoch::Convert(MEpoch) with a subsequent setOut(MEpoch::Ref)
77// <li> MEpoch::Convert(MEpoch::Ref in, MEpoch::Ref out) is a template for
78// conversions from the input reference to the output reference. The
79// 'template' model used is the default value for the Measure, with
80// no units.
81// <li> MEpoch::Convert(Unit, MEpoch::Ref in, MEpoch::Ref out) is a
82// template for
83// conversions from the input reference to the output reference. The
84// 'template' model used is the default value for the Measure, with
85// the default units as specified.
86// <li> MEpoch::Convert() with a setModel(MEpoch) and setOut().
87// </ul>
88// An empty MeasRef argument indicates no conversion will be attempted<br>.
89// The constructor, and set functions, analyse the 'template' Measure and the
90// output reference frame, and construct a pointer (in practice a list
91// of pointers to bypass the necessity of creating too many conversion
92// functions) to a conversion routine.
93//
94// An <src>isNOP()</src> function is available to test if the created
95// conversion engine is empty.
96//
97// Actual conversions are done with the () operator, which produces a new
98// MEpoch (or other appropiate Measure).<br>
99// Possible arguments are (MVEpoch is used here generic, and indicates the
100// internal format of a Measure; possibly, to make sure distinction between
101// values with and without units possible, even simple Measures will
102// have their own internal class format, e.g. MVDouble.
103// The possible arguments to the () conversion operator are (again Epoch
104// is used for the generic Measure):
105// <ul>
106// <li> (MEpoch, MEpoch::Ref): will create a new conversion method, and use
107// it to produce the result of converting the MEpoch to the specified
108// frame
109// <li> (MEpoch): will create a new conversion method from the
110// MEpoch to the MeasRef belonging to the MeasConvert
111// <li> (Quantity): will use the conversion chain deduced from the
112// MEpoch model in the definition of MeasConvert, and will convert the
113// Quantity
114// <li> (Quantum<Vector<Double> >) as previous
115// <li> (Double): will use the units (if present) as specified in the
116// MeasConvert object to construct the internal value
117// to be converted
118// <li> (Vector<Double> >): as previous
119// </ul>
120// Float versions will be produced if necessary.<br>
121// The conversion analyser expects that all Measure classes have a set
122// of routines to do the actual analysing and conversion.
123// (see <linkto class=MCBase>MCBase</linkto> class for how this is done in
124// practice).<br>
125// If the standard conversion is not sufficient, additional methods can be
126// added at the end of the list with the <src>addMethod()</src> member
127// function (for real pros).<br>
128// </synopsis>
129//
130// <example>
131// See <linkto class=Measure>Measure</linkto> for an example
132// </example>
133//
134// <motivation>
135// Conversion of Measures will in general be done on a series of values.
136// Separating the analysis of the calculations necessary for the conversion
137// from the actual conversion could speed up the process.
138// </motivation>
139//
140// <todo asof="1999/09/24">
141// </todo>
142
143template <class M>
144class MeasConvert : public MConvertBase {
145 public:
146 // # Friends
147
148 // # Constructors
149 // <note role=tip> In the following constructors and other functions, all
150 // <em>MeasRef</em> can be replaced with simple <src>Measure::TYPE</src>
151 // where no offsets or frames are needed in the reference.</note>
152 // Construct an empty MeasConvert. It is not usable, unless a setModel, and
153 // probably a setOut has been done.
155 // Copy constructor
157 // Copy assignment
159
160 // Construct a conversion for the specified Measure and reference
161 // <group>
162 MeasConvert(const M &ep);
163 MeasConvert(const M &ep, const typename M::Ref &mr);
164 MeasConvert(const Measure &ep, const typename M::Ref &mr);
165 MeasConvert(const M &ep, typename M::Types mr);
166 MeasConvert(const Measure &ep, typename M::Types mr);
167 MeasConvert(const typename M::Ref &mrin, const typename M::Ref &mr);
168 MeasConvert(const typename M::Ref &mrin, typename M::Types mr);
169 MeasConvert(typename M::Types mrin, const typename M::Ref &mr);
170 MeasConvert(typename M::Types mrin, typename M::Types mr);
171 MeasConvert(const Unit &inunit, const typename M::Ref &mrin, const typename M::Ref &mr);
172 MeasConvert(const Unit &inunit, const typename M::Ref &mrin, typename M::Types mr);
173 MeasConvert(const Unit &inunit, typename M::Types mrin, const typename M::Ref &mr);
174 MeasConvert(const Unit &inunit, typename M::Types mrin, typename M::Types mr);
175 // </group>
176
177 // # Destructor
179
180 // # Operators
181 // The actual conversion operations
182 // <group>
183 // Convert model Measure to output frame
184 const M &operator()();
185 const M &operator()(Double val);
186 const M &operator()(const Vector<Double> &val);
187 const M &operator()(const Quantum<Double> &val);
188 const M &operator()(const Quantum<Vector<Double>> &val);
189 const M &operator()(const typename M::MVType &val);
190 const M &operator()(const MeasVal *val);
191 const M &operator()(const M &val);
192 const M &operator()(const M &val, const typename M::Ref &mr);
193 const M &operator()(const M &val, typename M::Types mr);
194 const M &operator()(const typename M::Ref &mr);
195 const M &operator()(typename M::Types mr);
196 // </group>
197
198 // # General Member Functions
199 // Set a new model for the conversion
200 virtual void setModel(const Measure &val);
201 // Set a new output reference
202 // <group>
203 void setOut(const typename M::Ref &mr);
204 void setOut(typename M::Types mr);
205 // </group>
206 // Set a new model and reference
207 // <group>
208 void set(const M &val, const typename M::Ref &mr);
209 void set(const M &val, typename M::Types mr);
210 // </group>
211 // Set a new model value only
212 virtual void set(const MeasValue &val);
213 // Set a new model unit only
214 virtual void set(const Unit &inunit);
215
216 // Add a method (Note: uInt should be an enum from the appropiate Measure)
217 virtual void addMethod(uInt method);
218 // Add the frame type (Note: tp should be an MeasFrame::FrameType)
219 virtual void addFrameType(uInt tp);
220 // Get number of methods
221 virtual Int nMethod() const;
222 // Get method
223 virtual uInt getMethod(uInt which) const;
224 // Is the conversion engine empty?
225 Bool isNOP() { return crout.empty(); }
226 // Print conversion engine
227 virtual void print(ostream &os) const;
228
229 private:
230 // # Data
231 // The model template Measure
232 std::unique_ptr<Measure> model;
233 // The model unit to be used in conversions
235 // The output reference
236 typename M::Ref outref;
237 // The input offset
238 std::unique_ptr<typename M::MVType> offin;
239 // The output offset
240 std::unique_ptr<typename M::MVType> offout;
241 // Vector of conversion routines (length variable)
242 std::vector<uInt> crout;
243 // Coded (with MeasFrame::FrameTypes) frames used in conversion
245 // Local conversion data
246 std::unique_ptr<MCBase> cvdat;
247 // Cyclic buffer for return values
248 // <group>
249 // Current pointer
251 std::unique_ptr<M> result[4];
252 // </group>
253 // Local variables that can be used in conversion
254 // <group>
255 std::unique_ptr<typename M::MVType> locres;
256 // </group>
257
258 // # Member functions
259 // Initialise pointers
260 void init();
261 // Copy a MeasConvert
262 void copy(const MeasConvert<M> &other);
263 // Clear self
264 void clear();
265 // Create the conversion routine chain
266 void create();
267 // Convert a value
268 // <group>
269 const typename M::MVType &convert();
270 const typename M::MVType &convert(const typename M::MVType &val);
271 // </group>
272};
273
274// # Global functions
275
276} // namespace casacore
277
278#ifndef CASACORE_NO_AUTO_TEMPLATES
279#include <casacore/measures/Measures/MeasConvert.tcc>
280#endif // # CASACORE_NO_AUTO_TEMPLATES
281#endif
virtual void addMethod(uInt method)
Add a method (Note: uInt should be an enum from the appropiate Measure).
virtual void print(ostream &os) const
Print conversion engine.
const M::MVType & convert(const typename M::MVType &val)
const M & operator()(Double val)
const M & operator()(const typename M::MVType &val)
MeasConvert(const Unit &inunit, typename M::Types mrin, const typename M::Ref &mr)
virtual uInt getMethod(uInt which) const
Get method.
Bool isNOP()
Is the conversion engine empty?
void set(const M &val, const typename M::Ref &mr)
Set a new model and reference.
const M & operator()(const Quantum< Double > &val)
MeasConvert(const M &ep, const typename M::Ref &mr)
virtual void set(const MeasValue &val)
Set a new model value only.
const M & operator()(const MeasVal *val)
const M & operator()(typename M::Types mr)
void init()
Initialise pointers.
const M & operator()(const Vector< Double > &val)
std::unique_ptr< Measure > model
std::unique_ptr< MCBase > cvdat
void setOut(const typename M::Ref &mr)
Set a new output reference.
MeasConvert(const Unit &inunit, const typename M::Ref &mrin, const typename M::Ref &mr)
MeasConvert(const Unit &inunit, const typename M::Ref &mrin, typename M::Types mr)
MeasConvert(const Measure &ep, const typename M::Ref &mr)
MeasConvert(const typename M::Ref &mrin, const typename M::Ref &mr)
MeasConvert()
Tip: In the following constructors and other functions, all MeasRef can be replaced with simple Measu...
virtual void addFrameType(uInt tp)
Add the frame type (Note: tp should be an MeasFrame::FrameType).
std::unique_ptr< MBaseline > result[4]
MeasConvert(const Unit &inunit, typename M::Types mrin, typename M::Types mr)
const M & operator()(const M &val, typename M::Types mr)
MeasConvert(typename M::Types mrin, typename M::Types mr)
std::unique_ptr< typename MBaseline::MVType > locres
void setOut(typename M::Types mr)
void clear()
Clear self.
MeasConvert< M > & operator=(const MeasConvert< M > &other)
Copy assignment.
void copy(const MeasConvert< M > &other)
Copy a MeasConvert.
virtual void setModel(const Measure &val)
Set a new model for the conversion.
const M & operator()(const M &val)
MeasConvert(const typename M::Ref &mrin, typename M::Types mr)
void set(const M &val, typename M::Types mr)
MeasConvert(const M &ep)
Construct a conversion for the specified Measure and reference.
const M & operator()(const Quantum< Vector< Double > > &val)
std::unique_ptr< typename MBaseline::MVType > offout
MeasConvert(typename M::Types mrin, const typename M::Ref &mr)
MeasConvert(const Measure &ep, typename M::Types mr)
const M & operator()(const M &val, const typename M::Ref &mr)
virtual Int nMethod() const
Get number of methods.
const M::MVType & convert()
Convert a value.
void create()
Create the conversion routine chain.
MeasConvert(const MeasConvert< M > &other)
Copy constructor.
MeasConvert(const M &ep, typename M::Types mr)
const M & operator()(const typename M::Ref &mr)
const M & operator()()
The actual conversion operations.
virtual void set(const Unit &inunit)
Set a new model unit only.
std::unique_ptr< typename MBaseline::MVType > offin
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53