casacore
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: 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 //#
27 //# $Id$
28 
29 #ifndef MEASURES_MEASCONVERT_H
30 #define MEASURES_MEASCONVERT_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/Containers/Block.h>
35 #include <casacore/measures/Measures/MConvertBase.h>
36 #include <casacore/casa/Quanta/Quantum.h>
37 #include <casacore/measures/Measures/Measure.h>
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward Declarations
41 class MCBase;
42 class 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 
143 template<class M> class MeasConvert : public MConvertBase {
144 
145 public:
146 
147  //# Friends
148 
149  //# Constructors
150  // <note role=tip> In the following constructors and other functions, all
151  // <em>MeasRef</em> can be replaced with simple <src>Measure::TYPE</src>
152  // where no offsets or frames are needed in the reference.</note>
153  // Construct an empty MeasConvert. It is not usable, unless a setModel, and
154  // probably a setOut has been done.
156  // Copy constructor
158  // Copy assignment
160 
161  // Construct a conversion for the specified Measure and reference
162  // <group>
163  MeasConvert(const M &ep);
164  MeasConvert(const M &ep, const typename M::Ref &mr);
165  MeasConvert(const Measure &ep, const typename M::Ref &mr);
166  MeasConvert(const M &ep, typename M::Types mr);
167  MeasConvert(const Measure &ep, typename M::Types mr);
168  MeasConvert(const typename M::Ref &mrin, const typename M::Ref &mr);
169  MeasConvert(const typename M::Ref &mrin, typename M::Types mr);
170  MeasConvert(typename M::Types mrin, const typename M::Ref &mr);
171  MeasConvert(typename M::Types mrin, typename M::Types mr);
172  MeasConvert(const Unit &inunit, const typename M::Ref &mrin,
173  const typename M::Ref &mr);
174  MeasConvert(const Unit &inunit, const typename M::Ref &mrin,
175  typename M::Types mr);
176  MeasConvert(const Unit &inunit, typename M::Types mrin,
177  const typename M::Ref &mr);
178  MeasConvert(const Unit &inunit, typename M::Types mrin,
179  typename M::Types mr);
180  // </group>
181 
182  //# Destructor
184 
185  //# Operators
186  // The actual conversion operations
187  // <group>
188  // Convert model Measure to output frame
189  const M &operator()();
190  const M &operator()(Double val);
191  const M &operator()(const Vector<Double> &val);
192  const M &operator()(const Quantum<Double> &val);
193  const M &operator()(const Quantum<Vector<Double> > &val);
194  const M &operator()(const typename M::MVType &val);
195  const M &operator()(const MeasVal *val);
196  const M &operator()(const M &val);
197  const M &operator()(const M &val, const typename M::Ref &mr);
198  const M &operator()(const M &val, typename M::Types mr);
199  const M &operator()(const typename M::Ref &mr);
200  const M &operator()(typename M::Types mr);
201  // </group>
202 
203  //# General Member Functions
204  // Set a new model for the conversion
205  virtual void setModel(const Measure &val);
206  // Set a new output reference
207  // <group>
208  void setOut(const typename M::Ref &mr);
209  void setOut(typename M::Types mr);
210  // </group>
211  // Set a new model and reference
212  // <group>
213  void set(const M &val, const typename M::Ref &mr);
214  void set(const M &val, typename M::Types mr);
215  // </group>
216  // Set a new model value only
217  virtual void set(const MeasValue &val);
218  // Set a new model unit only
219  virtual void set(const Unit &inunit);
220 
221  // Add a method (Note: uInt should be an enum from the appropiate Measure)
222  virtual void addMethod(uInt method);
223  // Add the frame type (Note: tp should be an MeasFrame::FrameType)
224  virtual void addFrameType(uInt tp);
225  // Get number of methods
226  virtual Int nMethod() const;
227  // Get method
228  virtual uInt getMethod(uInt which) const;
229  // Is the conversion engine empty?
230  Bool isNOP() { return crout.nelements() == 0; }
231  // Print conversion engine
232  virtual void print(ostream &os) const;
233 
234 private:
235  //# Data
236  // The model template Measure
238  // The model unit to be used in conversions
240  // The output reference
241  typename M::Ref outref;
242  // The input offset
243  typename M::MVType *offin;
244  // The output offset
245  typename M::MVType *offout;
246  // Vector of conversion routines (length variable)
248  // Coded (with MeasFrame::FrameTypes) frames used in conversion
250  // Local conversion data
252  // Cyclic buffer for return values
253  // <group>
254  // Current pointer
256  M *result[4];
257  // </group>
258  // Local variables that can be used in conversion
259  // <group>
260  typename M::MVType *locres;
261  // </group>
262 
263  //# Member functions
264  // Initialise pointers
265  void init();
266  // Copy a MeasConvert
267  void copy(const MeasConvert<M> &other);
268  // Clear self
269  void clear();
270  // Create the conversion routine chain
271  void create();
272  // Convert a value
273  // <group>
274  const typename M::MVType &convert();
275  const typename M::MVType &convert(const typename M::MVType &val);
276  // </group>
277 };
278 
279 //# Global functions
280 
281 
282 } //# NAMESPACE CASACORE - END
283 
284 #ifndef CASACORE_NO_AUTO_TEMPLATES
285 #include <casacore/measures/Measures/MeasConvert.tcc>
286 #endif //# CASACORE_NO_AUTO_TEMPLATES
287 #endif
size_t nelements() const
The number of elements contained in this Block<T>.
Definition: Block.h:611
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.
MeasConvert(const Unit &inunit, typename M::Types mrin, const typename M::Ref &mr)
virtual uInt getMethod(uInt which) const
Get method.
const M & operator()(Double val)
Bool isNOP()
Is the conversion engine empty?
Definition: MeasConvert.h:230
void set(const M &val, const typename M::Ref &mr)
Set a new model and reference.
MeasConvert(const M &ep, const typename M::Ref &mr)
virtual void set(const MeasValue &val)
Set a new model value only.
M::MVType * offin
The input offset.
Definition: MeasConvert.h:243
void init()
Initialise pointers.
void setOut(const typename M::Ref &mr)
Set a new output reference.
const M & operator()(const M &val, const typename M::Ref &mr)
const M & operator()()
The actual conversion operations.
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)
const M & operator()(const Quantum< Vector< Double > > &val)
const M::MVType & convert(const typename M::MVType &val)
M::MVType * offout
The output offset.
Definition: MeasConvert.h:245
M::Ref outref
The output reference.
Definition: MeasConvert.h:241
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...
MeasConvert< M > & operator=(const MeasConvert< M > &other)
Copy assignment.
virtual void addFrameType(uInt tp)
Add the frame type (Note: tp should be an MeasFrame::FrameType)
const M & operator()(const Vector< Double > &val)
const M & operator()(const typename M::MVType &val)
MeasConvert(const Unit &inunit, typename M::Types mrin, typename M::Types mr)
Unit unit
The model unit to be used in conversions.
Definition: MeasConvert.h:239
MeasConvert(typename M::Types mrin, typename M::Types mr)
const M & operator()(const typename M::Ref &mr)
Int lres
Cyclic buffer for return values.
Definition: MeasConvert.h:255
void setOut(typename M::Types mr)
void clear()
Clear self.
void copy(const MeasConvert< M > &other)
Copy a MeasConvert.
virtual void setModel(const Measure &val)
Set a new model for the conversion.
MeasConvert(const typename M::Ref &mrin, typename M::Types mr)
uInt crtype
Coded (with MeasFrame::FrameTypes) frames used in conversion.
Definition: MeasConvert.h:249
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 MeasVal *val)
Block< uInt > crout
Vector of conversion routines (length variable)
Definition: MeasConvert.h:247
MeasConvert(typename M::Types mrin, const typename M::Ref &mr)
Measure * model
The model template Measure.
Definition: MeasConvert.h:237
const M & operator()(const Quantum< Double > &val)
MeasConvert(const Measure &ep, typename M::Types mr)
const M & operator()(const M &val, typename M::Types mr)
virtual Int nMethod() const
Get number of methods.
void create()
Create the conversion routine chain.
MCBase * cvdat
Local conversion data.
Definition: MeasConvert.h:251
const M & operator()(typename M::Types mr)
MeasConvert(const MeasConvert< M > &other)
Copy constructor.
const M::MVType & convert()
Convert a value.
MeasConvert(const M &ep, typename M::Types mr)
M::MVType * locres
Local variables that can be used in conversion.
Definition: MeasConvert.h:260
const M & operator()(const M &val)
virtual void set(const Unit &inunit)
Set a new model unit only.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
double Double
Definition: aipstype.h:55