casacore
Loading...
Searching...
No Matches
MeasureHolder.h
Go to the documentation of this file.
1// # MeasureHolder.h: A holder for Measures to enable record conversions
2// # Copyright (C) 1998,1999,2000,2003
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_MEASUREHOLDER_H
27#define MEASURES_MEASUREHOLDER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Utilities/RecordTransformable.h>
32#include <casacore/casa/Containers/Block.h>
33#include <memory>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward Declarations
38class Measure;
39class MDirection;
40class MDoppler;
41class MEpoch;
42class MFrequency;
43class MPosition;
44class MRadialVelocity;
45class Muvw;
46class MBaseline;
47class MEarthMagnetic;
48class MeasValue;
49
50// <summary> A holder for Measures to enable record conversions </summary>
51
52// <use visibility=export>
53
54// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tMeasureHolder" demos="">
55// </reviewed>
56
57// <prerequisite>
58// <li> <linkto class=RecordInterface>RecordInterface</linkto> class
59// <li> <linkto class=Measure>Measure</linkto> class
60// </prerequisite>
61//
62// <etymology>
63// A Holder of general Measures
64// </etymology>
65//
66// <synopsis>
67// This class can be used to handle heterogeneous collections of Measures, e.g.
68// as a <src>Vector<MeasureHolder></src>. With the aid of the
69// toRecord() and fromRecord() functions it can be used
70// to convert a Measure object into or from a record.
71// A MeasureHolder is created from a Measure, or can be empty.
72//
73// Checks on the contents can be made with functions like
74// <src>isMDirection</src> and the contents can be obtained with
75// functions like <src>asMDirection</src>. It is an error to try and
76// retrieve a measure of the wrong type and doing so will generate an
77// exception (AipsError).
78//
79// The MeasureHolder can, in addition to the Measure it is holding, also hold
80// a block of MeasValues. This is especially useful for intertask
81// communication (e.g. with Glish), for reasons of speed. In general the
82// additional values will be created when the record used to create
83// a Holder contains a <src>Quantity<Vector></src> rather than a quantity in
84// the m0, m1 and/or m2 fields. The <src>getMV()</src> method can be used to
85// access the <src>nelements()</src> additional information. They can be
86// (re-)set with the <src>setMV()</src> method (after a possible creation
87// of the extra block if not already there, or of the wrong length,
88// with <src>makeMV()</src>. If any value is set they will be used in
89// creating records, with the first value always overwriting the actual
90// Measure value.
91//
92// </synopsis>
93//
94// <example>
95// <srcblock>
96// TableRecord rec;
97// MDirection dir(MVDirection(Quantity(12.5, 'deg'), Quantity(-2, 'deg')),
98// MDirection::J2000);
99// String error; // error message
100// if (!MeasureHolder(dir).toRecord(error, rec)) {
101// cout << error << endl;
102// }
103// Record grec; // a Record
104// if (!MeasureHolder(dir).toRecord(error, grec)) { // make record
105// cout << error << endl;
106// }
107// // Note that for GlishRecords use can be made of the
108// // GlishRecord::to/fromrecord() methods.
109// </srcblock>
110// </example>
111//
112// <motivation>
113// To make general conversions between Measures and records, without knowing
114// the actual Measure being converted.
115// </motivation>
116
118 public:
119 // # Friends
120
121 // # Enumerations
122
123 // # Constructors
124 // Creates an empty holder
126 // Create from a Measure (copy made)
128 // Copy a holder (copy semantics)
130 // # Destructor
132
133 // # Operators
134 // Assignment (copy semantics)
136
137 // # Member Functions
138 // Check the the MeasureHolder holds the specified Measure type. Return
139 // True if if does and False otherwise.
140 // <group>
141 Bool isEmpty() const;
145 Bool isMEpoch() const;
150 Bool isMuvw() const;
152 // </group>
153
154 // Get a specific Measure from the holder (with lifetime as long
155 // as holder exists).
156 // <thrown>
157 // <li> AipsError if holder empty
158 // <li> AipsError if holder contains wrong Measure
159 // </thrown>
160 // <group>
161 const Measure &asMeasure() const;
162 const MDirection &asMDirection() const;
163 const MDoppler &asMDoppler() const;
164 const MEpoch &asMEpoch() const;
165 const MFrequency &asMFrequency() const;
166 const MPosition &asMPosition() const;
168 const MBaseline &asMBaseline() const;
169 const Muvw &asMuvw() const;
171 // </group>
172 // Create a Measure from a record. An error message is generated, and False
173 // returned if an invalid record is given. A valid record will return True.
174 // A valid record contains the following fields (any additional fields are
175 // ignored):
176 // <ul>
177 // <li> type = TpString: type of Measure (direction, epoch, etc; case
178 // insensitive)
179 // <li> refer = TpString: reference type of Measure (case insensitive;
180 // enough characters to be unique (e.g. J20, j200, utc, b1950, J2000);
181 // unknown reference type will log an error message and translate into
182 // the default type for the Measure.
183 // <li> m0, m1, ... = TpRecord(Quantity): one or more Quantities giving
184 // the value(s) for this Measure (e.g. longitude and latitude for a
185 // direction). Each quantity can either be a scalar quantity or a
186 // Quantum<Vector<Double> >.
187 // <li> offset = TpRecord(Measure)--optional: an optional offset as a
188 // Measure of the same type as the main Measure (e.g. an MEpoch for an
189 // MEpoch)
190 // </ul>
191 // A Measure can be created from a string. In that case the string
192 // will only indicate the type of measure (like direction), and will
193 // create a default measure of that given type. In essence identical
194 // to the fromType() method.
195 // Error messages are postfixed to error.
196 // <group>
197 virtual Bool fromRecord(String &error, const RecordInterface &in);
198 virtual Bool fromString(String &error, const String &in);
199 // </group>
200 // Create a record from a Measure. The return will be False and an error
201 // message generated only if the MeasureHolder does not contain a Measure.
202 // Error messages are postfixed to error.
203 virtual Bool toRecord(String &error, RecordInterface &out) const;
204
205 // This version throws an exception if the conversion cannot
206 // occur. It is meant for more allow more compact calling code for callers
207 // that are content with just letting the exception proceed up the call stack
208 // so they do not have to check a return status. This is, among other things, what
209 // exceptions are for after all.
210 virtual void toRecord(RecordInterface &outRecord) const;
211
212 // Create a default Measure or a record with only a type from a Measure
213 // <group>
214 Bool toType(String &error, RecordInterface &out) const;
216 // </group>
217 // Get identification of record
218 virtual const String &ident() const;
219 // Do we write MeasValues to record?
220 Bool writeMV() const { return convertmv_p; }
221 // Make a block of n MeasValues
222 void makeMV(uInt n) { createMV(n); }
223 // Get number of MeasValue pointers in block
224 uInt nelements() const { return mvhold_p.nelements(); }
225 // Set a measvalue at position pos (False if illegal pos)
226 Bool setMV(uInt pos, const MeasValue &in);
227 // Get a pointer to a MeasValue (or 0)
228 MeasValue *getMV(uInt pos) const;
229
230 private:
231 // # Data Members
232 // Pointer to a Measure
233 std::unique_ptr<Measure> hold_p;
234 // Block of pointers to measure values to make a faster interface
236 // Should the mvhold_p be converted into record?
238 // # Member functions
239 // Aid for to/from Record, String and Type
240 // <group>
241 Bool putType(String &error, RecordInterface &out) const;
242 Bool getType(String &error, const RecordInterface &in);
243 Bool getType(String &error, const String &in);
244 // </group>
245 // Make a MeasValue block of pointers of length n
246 void createMV(uInt n);
247};
248
249} // namespace casacore
250
251#endif
Block< MeasValue * > mvhold_p
Block of pointers to measure values to make a faster interface.
Bool fromType(String &error, const RecordInterface &in)
Bool isMFrequency() const
MeasureHolder(const MeasureHolder &other)
Copy a holder (copy semantics).
const Muvw & asMuvw() const
const MEpoch & asMEpoch() const
Bool getType(String &error, const RecordInterface &in)
MeasValue * getMV(uInt pos) const
Get a pointer to a MeasValue (or 0).
Bool isMDirection() const
Bool toType(String &error, RecordInterface &out) const
Create a default Measure or a record with only a type from a Measure.
const MDoppler & asMDoppler() const
const MRadialVelocity & asMRadialVelocity() const
Bool isMBaseline() const
virtual Bool toRecord(String &error, RecordInterface &out) const
Create a record from a Measure.
const MFrequency & asMFrequency() const
virtual Bool fromString(String &error, const String &in)
Initialise the class from a String representation.
Bool getType(String &error, const String &in)
void makeMV(uInt n)
Make a block of n MeasValues.
virtual void toRecord(RecordInterface &outRecord) const
This version throws an exception if the conversion cannot occur.
MeasureHolder()
Creates an empty holder.
MeasureHolder(const Measure &in)
Create from a Measure (copy made).
Bool isEmpty() const
Check the the MeasureHolder holds the specified Measure type.
void createMV(uInt n)
Make a MeasValue block of pointers of length n.
Bool convertmv_p
Should the mvhold_p be converted into record?
Bool isMPosition() const
uInt nelements() const
Get number of MeasValue pointers in block.
const MBaseline & asMBaseline() const
Bool setMV(uInt pos, const MeasValue &in)
Set a measvalue at position pos (False if illegal pos).
const Measure & asMeasure() const
Get a specific Measure from the holder (with lifetime as long as holder exists).
const MDirection & asMDirection() const
MeasureHolder & operator=(const MeasureHolder &other)
Assignment (copy semantics).
Bool isMRadialVelocity() const
Bool writeMV() const
Do we write MeasValues to record?
std::unique_ptr< Measure > hold_p
Pointer to a Measure.
Bool isMEarthMagnetic() const
const MEarthMagnetic & asMEarthMagnetic() const
virtual Bool fromRecord(String &error, const RecordInterface &in)
Create a Measure from a record.
virtual const String & ident() const
Get identification of record.
Bool putType(String &error, RecordInterface &out) const
Aid for to/from Record, String and Type.
const MPosition & asMPosition() const
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
unsigned int uInt
Definition aipstype.h:49
RecordInterface()
The default constructor creates an empty record with a variable structure.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40