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
119public:
120
121//# Friends
122
123//# Enumerations
124
125//# Constructors
126 // Creates an empty holder
128 // Create from a Measure (copy made)
130 // Copy a holder (copy semantics)
132//# Destructor
134
135//# Operators
136 // Assignment (copy semantics)
138
139//# Member Functions
140 // Check the the MeasureHolder holds the specified Measure type. Return
141 // True if if does and False otherwise.
142 // <group>
143 Bool isEmpty() const;
147 Bool isMEpoch() const;
152 Bool isMuvw() const;
154 // </group>
155
156 // Get a specific Measure from the holder (with lifetime as long
157 // as holder exists).
158 // <thrown>
159 // <li> AipsError if holder empty
160 // <li> AipsError if holder contains wrong Measure
161 // </thrown>
162 // <group>
163 const Measure &asMeasure() const;
164 const MDirection &asMDirection() const;
165 const MDoppler &asMDoppler() const;
166 const MEpoch &asMEpoch() const;
167 const MFrequency &asMFrequency() const;
168 const MPosition &asMPosition() const;
170 const MBaseline &asMBaseline() const;
171 const Muvw &asMuvw() const;
173 // </group>
174 // Create a Measure from a record. An error message is generated, and False
175 // returned if an invalid record is given. A valid record will return True.
176 // A valid record contains the following fields (any additional fields are
177 // ignored):
178 // <ul>
179 // <li> type = TpString: type of Measure (direction, epoch, etc; case
180 // insensitive)
181 // <li> refer = TpString: reference type of Measure (case insensitive;
182 // enough characters to be unique (e.g. J20, j200, utc, b1950, J2000);
183 // unknown reference type will log an error message and translate into
184 // the default type for the Measure.
185 // <li> m0, m1, ... = TpRecord(Quantity): one or more Quantities giving
186 // the value(s) for this Measure (e.g. longitude and latitude for a
187 // direction). Each quantity can either be a scalar quantity or a
188 // Quantum<Vector<Double> >.
189 // <li> offset = TpRecord(Measure)--optional: an optional offset as a
190 // Measure of the same type as the main Measure (e.g. an MEpoch for an
191 // MEpoch)
192 // </ul>
193 // A Measure can be created from a string. In that case the string
194 // will only indicate the type of measure (like direction), and will
195 // create a default measure of that given type. In essence identical
196 // to the fromType() method.
197 // Error messages are postfixed to error.
198 // <group>
199 virtual Bool fromRecord(String &error, const RecordInterface &in);
200 virtual Bool fromString(String &error, const String &in);
201 // </group>
202 // Create a record from a Measure. The return will be False and an error
203 // message generated only if the MeasureHolder does not contain a Measure.
204 // Error messages are postfixed to error.
205 virtual Bool toRecord(String &error, RecordInterface &out) const;
206
207 // This version throws an exception if the conversion cannot
208 // occur. It is meant for more allow more compact calling code for callers
209 // that are content with just letting the exception proceed up the call stack
210 // so they do not have to check a return status. This is, among other things, what
211 // exceptions are for after all.
212 virtual void toRecord(RecordInterface& outRecord) const;
213
214
215 // Create a default Measure or a record with only a type from a Measure
216 // <group>
217 Bool toType(String &error, RecordInterface &out) const;
219 // </group>
220 // Get identification of record
221 virtual const String &ident() const;
222 // Do we write MeasValues to record?
223 Bool writeMV() const { return convertmv_p; }
224 // Make a block of n MeasValues
225 void makeMV(uInt n) { createMV(n); }
226 // Get number of MeasValue pointers in block
227 uInt nelements() const { return mvhold_p.nelements(); }
228 // Set a measvalue at position pos (False if illegal pos)
229 Bool setMV(uInt pos, const MeasValue &in);
230 // Get a pointer to a MeasValue (or 0)
231 MeasValue *getMV(uInt pos) const;
232
233private:
234
235 //# Data Members
236 // Pointer to a Measure
237 std::unique_ptr<Measure> hold_p;
238 // Block of pointers to measure values to make a faster interface
240 // Should the mvhold_p be converted into record?
242 //# Member functions
243 // Aid for to/from Record, String and Type
244 // <group>
245 Bool putType(String &error, RecordInterface &out) const;
246 Bool getType(String &error, const RecordInterface &in);
247 Bool getType(String &error, const String &in);
248 // </group>
249 // Make a MeasValue block of pointers of length n
250 void createMV(uInt n);
251};
252
253
254} //# NAMESPACE CASACORE - END
255
256#endif
simple 1-D array
Definition Block.h:198
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:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40