casacore
Loading...
Searching...
No Matches
MeasFrame.h
Go to the documentation of this file.
1// # MeasFrame.h: Container for Measure frame
2// # Copyright (C) 1996-2003,2007
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_MEASFRAME_H
27#define MEASURES_MEASFRAME_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/casa/Arrays/Vector.h>
33#include <casacore/measures/Measures/CyclicPtr.h>
34#include <casacore/measures/Measures/Measure.h>
35#include <casacore/casa/iosfwd.h>
36
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39// # Forward Declarations
40class MVEpoch;
41class MVPosition;
42class MVDirection;
44class MeasComet;
45class FrameRep;
46class MCFrame;
47template <class Qtype>
48class Quantum;
49
50// <summary> Container for Measure frame </summary>
51
52// <use visibility=export>
53
54// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasure" demos="">
55// </reviewed>
56
57// <prerequisite>
58// <li> <linkto class=Measure>Measure</linkto> class
59// <li> <linkto class=MeasRef>MeasRef</linkto> class
60// </prerequisite>
61//
62// <etymology>
63// From Measure and Frame
64// </etymology>
65//
66// <synopsis>
67// Measurements are made in a reference frame (epoch, position, direction,
68// ...).
69//
70// The class is a container for the reference frame Measures (MEpoch etc).
71// Since a frame will possibly be used by many different Measures, it behaves
72// as a smart pointer, with reference rather than copy characteristics.
73// Since it caches all its operations, it is advisable to have a 'global'
74// MeasFrame across an execution, resetting (or setting) its values
75// when appropriate. The frame can also contain other related information. At
76// the moment the orbit of a solar system body (MeasComet) can be set.
77// In future the planetary ephemeris used (e.g. DE205) and environmental
78// information like refraction data will be added.
79//
80// A MeasFrame is constructed by setting the appropriate Measures, either in
81// a constructor, or with a set(). The input to the constructors and set are
82// Measures.
83//
84// Inside the frames automatic conversion to the most appropriate usage of
85// its values is done (e.g. time to TBD time, position to astronomical
86// longitude). These conversions are done only if an explicit
87// Measure::Convert was used that needed information, e.g. the following
88// code:
89// <srcblock>
90// MeasFrame frame(obser); // obser is an MPosition
91// MEpoch::Convert conv(MEpoch(12345), MEpoch::Ref(MEpoch::LAST,obser));
92// MEpoch last = conv();
93// </srcblock>
94// will set-up a state machine to convert UTC(default) to LAST in conv; the
95// next call will do the actual conversion. During this conversion, the
96// astronomical longitude (among others) will be needed to convert to
97// local sidereal time. conv will ask (getLong()) this from the frame, which
98// will calculate it (including possible other conversions) from the
99// observatory's position specified in a frame. Any calculation done will be
100// cached (e.g. a Nutation calculation in this case for dpsi), and used in
101// subsequent conversions using the same frame.
102//
103// Furthermore, a frame will often be regularly updated (e.g. coordinate
104// conversion for a series of times). To make use of cached information, and
105// to speed up as much as possible, <src>reset...()</src> functions are
106// available. These reset functions accept the same range of input parameter
107// types as the <linkto class=MeasConvert>MeasConvert</linkto> () operator,
108// and will keep any determined conversion machines and related information
109// intact, only recalculating whatever is necessary.
110//
111// The actual frame calculations and interrogations are done in a separate
112// <linkto class=MCFrame>MCFrame</linkto> hidden class, which attaches itself
113// to MeasFrame when and if necessary (see there if you are really curious).
114//
115// get...() functions can return frame measures. Only when the frame has been
116// attached to a calculating machine *MCFrame) are these values available.
117// This attachment is done if the frame has been actively used by a
118// Measure::Convert engine, or if explicitly done by the
119// <src>MCFrame::make(MeasFrame &)</src> static method.
120//
121// Because MeasFrame uses a reference to its implementation, which can be shared
122// by multiple MeasFrame instances, it is by default not thread safe
123// when different MeasFrames are accessed from different threads. Moreover,
124// a MeasFrame contains links to other objects which may also be shared.
125// In Casacore 3.8, the referenced data entries in this class
126// have been changed so they are initialized in thread-safe ways, and thread-safe
127// conversions can be achieved by using the independentCopy() method. See
128// the help for that function for more info.
129//
130// <note role=caution> An explicit (or implicit) call to MCFrame::make will
131// load the whole conversion machinery (including Tables) into your
132// linked module).</note>
133//
134// <linkto class=Aipsrc>Aipsrc keywords</linkto> can be used for additional
135// (highly specialised) additional internal conversion parameters.
136// </synopsis>
137//
138// <example>
139// <srcblock>
140// MEpoch my_epoch(Quantity(MeasData::MJDB1950,"d")); // an epoch
141// MeasFrame frame(my_epoch); // used in a frame
142// </srcblock>
143// </example>
144//
145// <motivation>
146// To separate the frame definition from the measure type
147// </motivation>
148//
149// <todo asof="1997/04/16">
150// </todo>
151
153 public:
154 // # Friends
155 // Output a frame
156 friend ostream &operator<<(ostream &os, MeasFrame &mf);
157 // Machinery
158 // <group>
159 friend class MCFrame;
160 // </group>
161
162 // # Enumerations
163 // Enumeration for the different farme entries possible. This can be used
164 // to find out if a certain conversion needs the frame. It will be
165 // used in a registration/notify environment to enable bypassing of
166 // some new conversion settings.
167 enum FrameTypes { EPOCH = 1, POSITION = 2, DIRECTION = 4, VELOCITY = 8, COMET = 16 };
168
169 // # Constructors
170 // Default constructor
172 // Construct frame with specified measures
173 // <thrown>
174 // <li> AipsError if a non-frame Measure
175 // </thrown>
176 // <group>
177 MeasFrame(const Measure &meas1);
178 MeasFrame(const Measure &meas1, const Measure &meas2);
179 MeasFrame(const Measure &meas1, const Measure &meas2, const Measure &meas3);
180 // </group>
181 // Copy constructor (reference semantics)
182 MeasFrame(const MeasFrame &other);
184
185 // Copy assignment (reference semantics)
188 // Destructor
190
191 // # Operators
192 // Comparisons
193 // <group>
194 Bool operator==(const MeasFrame &other) const;
195 Bool operator!=(const MeasFrame &other) const;
196 // </group>
197
198 // # General member functions
199 // Test if empty (i.e. no measure filled in)
200 Bool empty() const;
201
202 // Set frame elements
203 // <thrown>
204 // <li> AipsError if a non-frame Measure
205 // <li> AipsError if illegal or non-existant MeasComet given
206 // </thrown>
207 // <group>
208 void set(const Measure &meas1);
209 void set(const Measure &meas1, const Measure &meas2);
210 void set(const Measure &meas1, const Measure &meas2, const Measure &meas3);
211 void set(const MeasComet &meas);
212 // </group>
213 // Reset a frame element and its cached derived values.
214 // <thrown>
215 // <li> AipsError if the specific Measure not yet present in frame
216 // </thrown>
217 // <group>
219 void resetEpoch(const Vector<Double> &val);
220 void resetEpoch(const Quantum<Double> &val);
222 void resetEpoch(const MVEpoch &val);
223 void resetEpoch(const Measure &val);
226 void resetPosition(const MVPosition &val);
227 void resetPosition(const Measure &val);
230 void resetDirection(const MVDirection &val);
231 void resetDirection(const Measure &val);
235 void resetRadialVelocity(const Measure &val);
236 void resetComet(const MeasComet &val);
237 // </group>
238
239 // Get the epoch pointer (0 if not present)
240 const Measure *epoch() const;
241 // Get the position pointer (0 if not present)
242 const Measure *position() const;
243 // Get the direction pointer (0 if not present)
244 const Measure *direction() const;
245 // Get the radial velocity pointer (0 if not present)
246 const Measure *radialVelocity() const;
247 // Get the comet pointer (0 if not present)
248 const MeasComet *comet() const;
249 // Get data from frame. Only available if appropriate measures are set,
250 // and the frame is in a calculating state.
251 // <group>
252 // Get TDB in days
253 Bool getTDB(Double &tdb) const;
254 // Get UT1 in days
255 Bool getUT1(Double &tdb) const;
256 // Get TT in days
257 Bool getTT(Double &tdb) const;
258 // Get the ITRF longitude (in rad)
259 Bool getLong(Double &tdb) const;
260 // Get the ITRF latitude (in rad)
261 Bool getLat(Double &tdb) const;
262 // Get the position
264 // Get the geocentric position (in m)
265 Bool getRadius(Double &tdb) const;
266 // Get the geodetic latitude
267 Bool getLatGeo(Double &tdb) const;
268 // Get the LAST (in days)
269 Bool getLAST(Double &tdb) const;
270 // Get the LAST (in rad)
271 Bool getLASTr(Double &tdb) const;
272 // Get J2000 coordinates (direction cosines) and its longitude/latitude (rad)
273 // <group>
277 // </group>
278 // Get B1950 coordinates (direction cosines)
279 // <group>
283 // </group>
284 // Get apparent coordinates (direction cosines)
285 // <group>
287 Bool getAppLong(Double &tdb) const;
288 Bool getAppLat(Double &tdb) const;
289 // </group>
290 // Get LSR radial velocity (m/s)
291 Bool getLSR(Double &tdb) const;
292 // Get the comet table reference type
293 Bool getCometType(uInt &tdb) const;
294 // Get the comet coordinates
296 // </group>
297
298 // Make a value copy of this MeasFrame, such that it contains no reference
299 // to the old MeasFrame data. This is useful for ensuring thread safety in conversions.
300 //
301 // This function is available since casacore v3.8.0.
302 //
303 // The following is an example of how a thread-safe conversion can be performed:
304 // <srcblock>
305 // void convert_example(const MDirection& shared_direction, const MeasFrame& shared_frame) {
306 // const MeasFrame frame = shared_frame.independentCopy();
307 // MDirection::Convert converter(MDirection::J2000,
308 // MDirection::Ref(MDirection::ITRF, frame));
309 // MDirection result = converter(shared_direction);
310 // </srcblock>
311 // The convert_example() function can be called from multiple threads (as long as
312 // they don't write to shared_direction or shared_frame), and performs a direction conversion
313 // from J2000 to ITRF. Any information that is shared between the threads is read-only.
315
316 private:
317 // # Data
318 // Representation of MeasFrame. See the CyclicPtr class documentation for motivation.
320
322 // # Member functions
323 // Create an instance of the MeasFrame class
324 void create();
325 // Fill a MeasFrame element
326 // <group>
327 void fill(const Measure *in);
328 void fill(const MeasComet *in);
329 // </group>
330 // Make full Epoch
331 void makeEpoch();
332 // Make full Position
334 // Make full Direction
336 // Make full RadialVelocity
338 // Make full Comet
339 void makeComet();
340 // Throw reset error
341 void errorReset(const String &txt);
342};
343
344// # Global functions
345// <summary> Global functions </summary>
346// <group name=Output>
347// Output a frame
348ostream &operator<<(ostream &os, MeasFrame &mf);
349// </group>
351} // namespace casacore
352
353#endif
const Measure * epoch() const
Get the epoch pointer (0 if not present).
Bool getCometType(uInt &tdb) const
Get the comet table reference type.
void resetEpoch(const MVEpoch &val)
Bool getTDB(Double &tdb) const
Get data from frame.
void resetPosition(const Quantum< Vector< Double > > &val)
void resetRadialVelocity(const Measure &val)
const Measure * position() const
Get the position pointer (0 if not present).
MeasFrame(MeasFrame &&other)
void resetEpoch(const Vector< Double > &val)
Bool getJ2000Long(Double &tdb) const
void resetDirection(const Measure &val)
void resetEpoch(const Quantum< Double > &val)
void resetDirection(const MVDirection &val)
Bool getLat(Double &tdb) const
Get the ITRF latitude (in rad).
friend class MCFrame
Machinery.
Definition MeasFrame.h:159
MeasFrame & operator=(MeasFrame &&other)
MeasFrame(const Measure &meas1)
Construct frame with specified measures.
void set(const Measure &meas1, const Measure &meas2)
void makeEpoch()
Make full Epoch.
void resetEpoch(Double val)
Reset a frame element and its cached derived values.
void makeRadialVelocity()
Make full RadialVelocity.
Bool getUT1(Double &tdb) const
Get UT1 in days.
MeasFrame()
Default constructor.
void resetRadialVelocity(const MVRadialVelocity &val)
void resetEpoch(const Quantum< Vector< Double > > &val)
Bool getB1950(MVDirection &tdb) const
Get B1950 coordinates (direction cosines).
const Measure * direction() const
Get the direction pointer (0 if not present).
MeasFrame(details::CyclicPtr< FrameRep > new_rep)
void resetDirection(const Vector< Double > &val)
void resetRadialVelocity(const Vector< Double > &val)
void resetRadialVelocity(const Quantum< Vector< Double > > &val)
MeasFrame(const Measure &meas1, const Measure &meas2)
Bool getTT(Double &tdb) const
Get TT in days.
void makeComet()
Make full Comet.
Bool getLAST(Double &tdb) const
Get the LAST (in days).
FrameTypes
Enumeration for the different farme entries possible.
Definition MeasFrame.h:167
Bool getLatGeo(Double &tdb) const
Get the geodetic latitude.
Bool getLong(Double &tdb) const
Get the ITRF longitude (in rad).
Bool operator==(const MeasFrame &other) const
Comparisons.
void resetEpoch(const Measure &val)
void makeDirection()
Make full Direction.
void resetPosition(const Vector< Double > &val)
Bool getB1950Lat(Double &tdb) const
void errorReset(const String &txt)
Throw reset error.
MeasFrame(const Measure &meas1, const Measure &meas2, const Measure &meas3)
void fill(const Measure *in)
Fill a MeasFrame element.
void resetPosition(const MVPosition &val)
Bool getJ2000Lat(Double &tdb) const
void set(const Measure &meas1, const Measure &meas2, const Measure &meas3)
Bool getComet(MVPosition &tdb) const
Get the comet coordinates.
~MeasFrame()
Destructor.
friend ostream & operator<<(ostream &os, MeasFrame &mf)
Output a frame.
const Measure * radialVelocity() const
Get the radial velocity pointer (0 if not present).
const MeasComet * comet() const
Get the comet pointer (0 if not present).
Bool empty() const
Test if empty (i.e.
Bool getAppLat(Double &tdb) const
void resetComet(const MeasComet &val)
void resetPosition(const Measure &val)
Bool getJ2000(MVDirection &tdb) const
Get J2000 coordinates (direction cosines) and its longitude/latitude (rad).
void set(const Measure &meas1)
Set frame elements.
void makePosition()
Make full Position.
Bool operator!=(const MeasFrame &other) const
MeasFrame(const MeasFrame &other)
Copy constructor (reference semantics).
Bool getRadius(Double &tdb) const
Get the geocentric position (in m).
void fill(const MeasComet *in)
Bool getB1950Long(Double &tdb) const
Bool getAppLong(Double &tdb) const
void set(const MeasComet &meas)
Bool getITRF(MVPosition &tdb) const
Get the position.
Bool getLSR(Double &tdb) const
Get LSR radial velocity (m/s).
MeasFrame & operator=(const MeasFrame &other)
Copy assignment (reference semantics).
details::CyclicPtr< FrameRep > rep
Representation of MeasFrame.
Definition MeasFrame.h:319
MeasFrame independentCopy() const
Make a value copy of this MeasFrame, such that it contains no reference to the old MeasFrame data.
void resetDirection(const Quantum< Vector< Double > > &val)
Bool getApp(MVDirection &tdb) const
Get apparent coordinates (direction cosines).
Bool getLASTr(Double &tdb) const
Get the LAST (in rad).
void create()
Create an instance of the MeasFrame class.
String: the storage and methods of handling collections of characters.
Definition String.h:355
A smart pointer class that allows to work with complex cycles without using weak_ptrs.
Definition CyclicPtr.h:77
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53
ostream & operator<<(ostream &os, MeasFrame &mf)
Output a frame.