casacore
Loading...
Searching...
No Matches
MeasurementSet.h
Go to the documentation of this file.
1//# MeasurementSet.h: A Table to hold astronomical data (a set of Measurements)
2//# Copyright (C) 1996,1997,1999,2000,2001,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 MS_MEASUREMENTSET_H
27#define MS_MEASUREMENTSET_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/ms/MeasurementSets/MSTable.h>
31#include <casacore/ms/MeasurementSets/MSMainEnums.h>
32#include <casacore/ms/MeasurementSets/MSAntenna.h>
33#include <casacore/ms/MeasurementSets/MSDataDescription.h>
34#include <casacore/ms/MeasurementSets/MSDoppler.h>
35#include <casacore/ms/MeasurementSets/MSFeed.h>
36#include <casacore/ms/MeasurementSets/MSField.h>
37#include <casacore/ms/MeasurementSets/MSFlagCmd.h>
38#include <casacore/ms/MeasurementSets/MSFreqOffset.h>
39#include <casacore/ms/MeasurementSets/MSHistory.h>
40#include <casacore/ms/MeasurementSets/MSObservation.h>
41#include <casacore/ms/MeasurementSets/MSPointing.h>
42#include <casacore/ms/MeasurementSets/MSPolarization.h>
43#include <casacore/ms/MeasurementSets/MSProcessor.h>
44#include <casacore/ms/MeasurementSets/MSSource.h>
45#include <casacore/ms/MeasurementSets/MSSpectralWindow.h>
46#include <casacore/ms/MeasurementSets/MSState.h>
47#include <casacore/ms/MeasurementSets/MSSysCal.h>
48#include <casacore/ms/MeasurementSets/MSWeather.h>
49#include <set>
50
51
52namespace casacore { //# NAMESPACE CASACORE - BEGIN
53
54class MrsEligibility { // Memory Resident Subtable (Mrs) Eligibility (no pun intended)
55
56public:
57
59
60 friend MrsEligibility operator- (const MrsEligibility & a, SubtableId subtableId);
61 friend MrsEligibility operator+ (const MrsEligibility & a, SubtableId subtableId);
64
65 // Returns true if the specified subtable is in the set of subtables
66 // eligible for memory residency.
67 Bool isEligible (SubtableId subtableId) const;
68
69 // Factory methods to create MrsEligibility sets. The two variable argument methods
70 // require that the list be terminated by using the id MSMainEnums::UNDEFINED_KEYWORD.
71 //
76 static MrsEligibility allButTheseSubtables (SubtableId ineligibleSubtableId, ...);
77
78private:
79
80 typedef std::set<MSMainEnums::PredefinedKeywords> Eligible;
81
83
85
86 static Bool isSubtable (SubtableId subtableId);
87};
88
89// Creates a new MrsEligibilitySet by adding or removing the specified subtable or
90// the specified set of subtables.
95
96//# Forward Declarations, more could be if they weren't part of the
97//# static classes
98class SetupNewTable;
99template <class T> class Block;
100class MDirection;
101class MEpoch;
102class MFrequency;
103class MPosition;
104class Record;
105
106//# forward declared so that the following typedef is up-front
107class MeasurementSet;
108
109// MeasurementSet is too cumbersome for a number of common uses,
110// so we give a typedef here.
112
113// <summary>
114// A Table intended to hold astronomical data (a set of Measurements).
115// </summary>
116
117// <use visibility=export>
118
119// <reviewed reviewer="Bob Garwood" date="1997/02/01" tests="tMeasurementSet.cc" demos="">
120
121// <prerequisite>
122// <li> <linkto module="Tables:description">Tables</linkto> module
123// <li> <linkto class="MSTable">MSTable</linkto>
124// </prerequisite>
125//
126// <etymology>
127// The MeasurementSet is where all data are ultimately to be found
128// in Casacore. Since, this is a collection of
129// measurements (either actual or simulated), the term MeasurementSet
130// seems appropriate.
131// </etymology>
132//
133// <synopsis>
134// A MeasurementSet is a Table. Most operations on a MeasurementSet are
135// Table operations. See the <linkto module="Tables:description">Tables</linkto>
136// module for a list of those operations. The member functions provided by this
137// class are primarily convenience functions to help users follow the
138// agreed upon column and keyword naming conventions. They are useful when
139// creating a Table following the MeasurementSet conventions from
140// scratch as well as when creating the column objects to access those
141// columns.
142//
143// The standard way of accessing
144// table columns is through Strings. Mistakes in typing the column
145// name will not be caught at compile time (and may not be caught at
146// run time). We have therefore decided to use an enumeration
147// to specify columns so that many mistakes will be caught at compile
148// time. This requires functions to map to and from this enumeration
149// to the strings that are ultimately used.
150//
151// Upon destruction, the table is checked to see that the
152// MeasurementSet remains valid, i.e., all required columns are present
153// An exception is thrown if not all required columns are present
154// Nevertheless, the table will be flushed to disk if it is writable -
155// preserving its state.
156//
157// A MeasurementSet has a number of required subtables. These are stored
158// as keywords in the Table. Access to these subtables is provided via
159// member functions (e.g. antenna() for the ANTENNA table). All subtables
160// have associated MeasurementSet-like classes defined for them (MSAntenna
161// for the ANTENNA table) which provide analogous column and keyword mapping
162// as provided here.
163//
164// While the class name, MeasurementSet, is descriptive, it is often
165// too long for many common uses. The typedef MS is provided as
166// a convenient shorthand for MeasurementSet. The example below uses this
167// typedef.
168//
169// Due to the inheritance scheme, it was necessary to separate the enumerations
170// used by MeasurementSet into a separate class,
171// <linkto class=MSMainEnums>MSMainEnums</linkto>.
172//
173// </synopsis>
174//
175// <example>
176// This example illustrates a simple use of the MeasurementSet class.
177// <srcblock>
178// // create the table descriptor
179// TableDesc simpleDesc = MS::requiredTableDesc();
180// // set up a new table
181// SetupNewTable newTab("simpleTab", simpleDesc, Table::New);
182// // create the MeasurementSet
183// MeasurementSet simpleMS(newTab);
184// // now we need to define all required subtables
185// // the following call does this for us if we don't need to
186// // specify details of Storage Managers for columns.
187// simpleMS.createDefaultSubtables(Table::New);
188// // fill MeasurementSet via its Table interface
189// // For example, construct one of the columns
190// TableColumn feed(simpleMS, MS::columnName(MS::FEED1));
191// rownr_t rownr = 0;
192// // add a row
193// simpleMS.addRow();
194// // set the values in that row, e.g. the feed column
195// feed.putScalar(rownr,1);
196// // Access a subtable
197// ArrayColumn<Double> antpos(simpleMS.antenna(),
198// MSAntenna::columnName(MSAntenna::POSITION));
199// simpleMS.antenna().addRow();
200// Array<Double> position(3);
201// position(0)=1.; position(1)=2.; position(2)=3.;
202// antpos.put(0,position);
203// // etc.
204// </srcblock>
205//
206// </example>
207//
208// <motivation>
209// The Table module is more than adequate as a container of data.
210// However, in order for applications to be useful with data from
211// different sources, some conventions need to be adopted in the use
212// of Tables to store data. The MeasurementSet is
213// where those conventions are defined and, to some extent, enforced.
214//
215// There are a number of reasons why MeasurementSet is more
216// than just a Table.
217// <ul>
218// <li> To provide one location where the column and keyword names, data
219// types, and table comment strings are found.
220// <li> To provide one location where the required table descriptor for
221// the MeasurementSet is found.
222// <li> To provide a means of verifying the validity of a MeasurementSet
223// at construction and destruction.
224// <li> To allow application programmers to catch name or data type
225// mistakes at compile time rather than at run time.
226// </ul>
227//
228// </motivation>
229//
230// <todo asof="1996/2/22">
231// <li> referenceCopy() should be more flexible with the storage managers used
232// for the columns which are not merely references.
233// <li> When ForwardColumnEngine is fixed so that it can deal with
234// tables already in the cache, modify the test program. It may also
235// be necessary to modify referenceCopy().
236// </todo>
237
238class MeasurementSet : public MSTable<MSMainEnums>,
239 public MSMainEnums
240{
241
242public:
243 // This constructs an empty MeasurementSet, only useful to assign to
244 // (it is not a valid MS yet).
246
247 // These constructors mirror the Table ones with additional checking
248 // on validity (verifying that the MS will have the required columns
249 // and keywords)
250 // An exception is thrown if the constructed Table is not a valid MS
251 // <thrown>
252 // <li> AipsError
253 // </thrown>
254 // <group name=tableLikeConstructors>
255
259
261 bool doNotLockSubtables, TableOption = Table::Old);
262 // Allows keeping subtables unlocked/read-locked independent of lock
263 // mode of main table.
264
265 MeasurementSet (const String &tableName, const String &tableDescName,
267 MeasurementSet (const String &tableName, const String &tableDescName,
270 Bool initialize = False);
272 rownr_t nrrow = 0, Bool initialize = False);
273 MeasurementSet (const Table &table, const MeasurementSet * otherMs = NULL);
274
275#ifdef HAVE_MPI
276 MeasurementSet (MPI_Comm comm, SetupNewTable &newTab, rownr_t nrrow = 0,
277 Bool initialize = False);
278 MeasurementSet (MPI_Comm comm, SetupNewTable &newTab, const TableLock& lockOptions,
279 rownr_t nrrow = 0, Bool initialize = False);
280#endif // HAVE_MPI
281
283 // </group>
284
285 // As with tables, the destructor writes the table if necessary.
286 // Additional checking is done here to verify that all required
287 // columns are still present.
288 // If it is NOT valid, it will write the table and then throw an exception.
289 // <thrown>
290 // <li> AipsError
291 // </thrown>
293
294 // Assignment operator, reference semantics
296
297 // Make a special copy of this MS which references all columns from
298 // this MS except those mentioned; those are empty and writable.
299 // Each forwarded column has the same writable status as the underlying
300 // column. The mentioned columns all use the AipsIO storage manager.
301 // The main use of this is for the synthesis package where corrected and
302 // model visibilities are stored as new DATA columns in an MS which
303 // references the raw MS for the other columns. Except for these special
304 // cases, the use of this function will be rare.
306 const Block<String>& writableColumns) const;
307
308 // Converts the MS to make the specified set of subtables memory resident.
309 void
311
312 // Return the name of each of the subtables. This should be used by the
313 // filler to create the subtables in the correct location.
314 // <group>
332 // </group>
333
334 // Access functions for the subtables, using the MS-like interface for each
335 // <group>
339 MSFeed& feed() {return feed_p;}
340 MSField& field() {return field_p;}
350 MSState& state() {return state_p;}
353 const MSAntenna& antenna() const {return antenna_p;}
355 const MSDoppler& doppler() const {return doppler_p;}
356 const MSFeed& feed() const {return feed_p;}
357 const MSField& field() const {return field_p;}
358 const MSFlagCmd& flagCmd() const {return flagCmd_p;}
359 const MSFreqOffset& freqOffset() const {return freqOffset_p;}
360 const MSHistory& history() const {return history_p;}
361 const MSObservation& observation() const {return observation_p;}
362 const MSPointing& pointing() const {return pointing_p;}
364 const MSProcessor& processor() const {return processor_p;}
365 const MSSource& source() const {return source_p;}
367 const MSState& state() const {return state_p;}
368 const MSSysCal& sysCal() const {return sysCal_p;}
369 const MSWeather& weather() const {return weather_p;}
370 // </group>
371
373
374 // Initialize the references to the subtables. You need to call
375 // this only if you assign new subtables to the table keywords.
376 // This also checks for validity of the table and its subtables.
377 // Set clear to True to clear the subtable references (used in assignment)
378 void initRefs(Bool clear=False);
379
380 // Create default subtables: fills the required subtable keywords with
381 // tables of the correct type, mainly for testing and as an example of
382 // how to do this for specific fillers. In practice these tables will
383 // often have more things specified, like dimensions of arrays and
384 // storage managers for the various columns.
386#ifdef HAVE_MPI
388#endif // HAVE_MPI
389
390 // Initialize the statics appropriately. This does not need to be
391 // called by users, it is called by the implementation class
392 // MSTableImpl.
394
395 // Create DATA column from existing FLOAT_DATA column. Noop if DATA already
396 // exists or neither exists (returns False in that case).
398
399 // Validate Measure references - check that all Measure columns have their
400 // reference value set, report the ones that don't.
402
403 // Flush all the tables and subtables associated with this
404 // MeasurementSet. This function calls the Table::flush() function on the
405 // main table and all the standard subtables including optional
406 // subtables. See the Table class for a description of the sync argument.
407 void flush(Bool sync=False);
408
409 // Return a record of the indices that the msselection selection selected
410 Record msseltoindex(const String& spw="", const String& field="",
411 const String& baseline="", const String& time="",
412 const String& scan="", const String& uvrange="",
413 const String& observation="", const String& poln="",
414 const String& taql="");
415
416protected:
417
418
419 // Clears all of the subtable components of this object (i.e., set to
420 // value of subtable's default constructor).
422
423 // Assigns one subtable to another if the original subtable (otherSubtable)
424 // is not null and is also memory resident
425 void copySubtable (const Table & otherSubtable, Table & subTable);
426
427 // Copies (assigns) all of the non-null subtables from the other MS into this one.
428 void copySubtables (const MeasurementSet & other);
429
430 // Returns true if the named subtable is eligible for memory residency.
431 Bool isEligibleForMemoryResidency (const String & subtableName) const;
432
433 // Opens all of the eligible subtables in memory resident form
435
436 // The top level name for MRS related CASARC settings
438 {
439 return "MemoryResidentSubtables";
440 }
441
442private:
443
444 // temporary function to add the CATEGORY keyword to the FLAG_CATEGORY
445 // column if it isn't there yet. 2000/08/22
446 // remove this and the calls next MS update
447 void addCat();
448
449 // check that the MS is the latest version (2.0)
451
452 // Creates subtables using an explicit MPI communicator (if MPI support
453 // is enabled)
454 template<typename T>
456
457 // Opens a single subtable as memory resident (if permitted).
458 template <typename Subtable>
459 void
460 openMrSubtable (Subtable & subtable, const String & subtableName);
461
462 // Opens a single subtable if not present in MS object but defined in on-disk MS
463 template <typename Subtable>
464 void
465 openSubtable (Subtable & subtable, const String & subtableName, Bool useLock);
466
467 // keep references to the subtables
480 MSSource source_p; //optional
483 MSSysCal sysCal_p; //optional
485
486 bool doNotLockSubtables_p; // used to prevent subtable locking to allow parallel interprocess sharing
487 int mrsDebugLevel_p; // logging level currently enabled
488 Bool hasBeenDestroyed_p; // required by the need to throw an exception in the destructor
490 Bool memoryResidentSubtables_p; // true if memory resident subtables are enabled
491 MrsEligibility mrsEligibility_p; // subtables which can be made memory resident
492
493};
494
495
496} //# NAMESPACE CASACORE - END
497
498#endif
simple 1-D array
Definition Block.h:198
Enums for the MeasurementSet main table.
Definition MSMainEnums.h:59
PredefinedKeywords
Keywords with a predefined meaning.
A Table intended to hold astronomical data
Definition MSTable.h:143
void openSubtable(Subtable &subtable, const String &subtableName, Bool useLock)
Opens a single subtable if not present in MS object but defined in on-disk MS.
MSAntenna & antenna()
Access functions for the subtables, using the MS-like interface for each.
void createDefaultSubtables(MPI_Comm comm, Table::TableOption option=Table::Scratch)
MeasurementSet(const Table &table, const MeasurementSet *otherMs=NULL)
const MSFreqOffset & freqOffset() const
String fieldTableName() const
MSObservation & observation()
void copySubtables(const MeasurementSet &other)
Copies (assigns) all of the non-null subtables from the other MS into this one.
MrsEligibility getMrsEligibility() const
const MSObservation & observation() const
String stateTableName() const
MSFreqOffset & freqOffset()
const MSAntenna & antenna() const
String freqOffsetTableName() const
String processorTableName() const
const MSSource & source() const
MeasurementSet(const String &tableName, const String &tableDescName, TableOption=Table::Old)
Allows keeping subtables unlocked/read-locked independent of lock mode of main table.
const MSWeather & weather() const
void copySubtable(const Table &otherSubtable, Table &subTable)
Assigns one subtable to another if the original subtable (otherSubtable) is not null and is also memo...
Bool isEligibleForMemoryResidency(const String &subtableName) const
Returns true if the named subtable is eligible for memory residency.
MSDataDescription dataDesc_p
MeasurementSet(const String &tableName, const TableLock &lockOptions, TableOption=Table::Old)
const MSSpectralWindow & spectralWindow() const
const MSSysCal & sysCal() const
const MSHistory & history() const
MeasurementSet()
This constructs an empty MeasurementSet, only useful to assign to (it is not a valid MS yet).
Record msseltoindex(const String &spw="", const String &field="", const String &baseline="", const String &time="", const String &scan="", const String &uvrange="", const String &observation="", const String &poln="", const String &taql="")
Return a record of the indices that the msselection selection selected.
MeasurementSet(MPI_Comm comm, SetupNewTable &newTab, const TableLock &lockOptions, rownr_t nrrow=0, Bool initialize=False)
const MSState & state() const
MSAntenna antenna_p
keep references to the subtables
const MSField & field() const
void createDefaultSubtables(Table::TableOption option=Table::Scratch)
Create default subtables: fills the required subtable keywords with tables of the correct type,...
String flagCmdTableName() const
String spectralWindowTableName() const
String dopplerTableName() const
String historyTableName() const
String feedTableName() const
MSSpectralWindow & spectralWindow()
MeasurementSet(SetupNewTable &newTab, rownr_t nrrow=0, Bool initialize=False)
String sysCalTableName() const
void setMemoryResidentSubtables(const MrsEligibility &mrsEligibility)
Converts the MS to make the specified set of subtables memory resident.
const MSFeed & feed() const
MeasurementSet(const String &tableName, const String &tableDescName, const TableLock &lockOptions, TableOption=Table::Old)
virtual ~MeasurementSet()
As with tables, the destructor writes the table if necessary.
void flush(Bool sync=False)
Flush all the tables and subtables associated with this MeasurementSet.
const MSDataDescription & dataDescription() const
String sourceTableName() const
void openMrSubtables()
Opens all of the eligible subtables in memory resident form.
void createDefaultSubtables_impl(Table::TableOption option, T comm)
Creates subtables using an explicit MPI communicator (if MPI support is enabled)
void openMrSubtable(Subtable &subtable, const String &subtableName)
Opens a single subtable as memory resident (if permitted).
void initRefs(Bool clear=False)
Initialize the references to the subtables.
MSPolarization polarization_p
MSSpectralWindow spectralWindow_p
String observationTableName() const
String dataDescriptionTableName() const
MeasurementSet(const String &tableName, TableOption=Table::Old)
These constructors mirror the Table ones with additional checking on validity (verifying that the MS ...
Bool validateMeasureRefs()
Validate Measure references - check that all Measure columns have their reference value set,...
MeasurementSet(SetupNewTable &newTab, const TableLock &lockOptions, rownr_t nrrow=0, Bool initialize=False)
static String getMrsAipsRcBase()
The top level name for MRS related CASARC settings.
Bool makeComplexData()
Create DATA column from existing FLOAT_DATA column.
const MSFlagCmd & flagCmd() const
static MSTableMaps initMaps()
Initialize the statics appropriately.
String weatherTableName() const
String antennaTableName() const
Return the name of each of the subtables.
void addCat()
temporary function to add the CATEGORY keyword to the FLAG_CATEGORY column if it isn't there yet.
String polarizationTableName() const
MeasurementSet(MPI_Comm comm, SetupNewTable &newTab, rownr_t nrrow=0, Bool initialize=False)
MeasurementSet & operator=(const MeasurementSet &)
Assignment operator, reference semantics.
const MSProcessor & processor() const
const MSPolarization & polarization() const
MeasurementSet(const MeasurementSet &other)
void checkVersion()
check that the MS is the latest version (2.0)
MrsEligibility mrsEligibility_p
MSDataDescription & dataDescription()
const MSPointing & pointing() const
MeasurementSet referenceCopy(const String &newTableName, const Block< String > &writableColumns) const
Make a special copy of this MS which references all columns from this MS except those mentioned; thos...
void clearSubtables()
Clears all of the subtable components of this object (i.e., set to value of subtable's default constr...
MSPolarization & polarization()
String pointingTableName() const
MeasurementSet(const String &tableName, const TableLock &lockOptions, bool doNotLockSubtables, TableOption=Table::Old)
const MSDoppler & doppler() const
std::set< MSMainEnums::PredefinedKeywords > Eligible
Bool isEligible(SubtableId subtableId) const
Returns true if the specified subtable is in the set of subtables eligible for memory residency.
static MrsEligibility noneEligible()
static Bool isSubtable(SubtableId subtableId)
friend MrsEligibility operator+(const MrsEligibility &a, SubtableId subtableId)
static MrsEligibility defaultEligible()
static const MrsEligibility allSubtables_p
static MrsEligibility allEligible()
Factory methods to create MrsEligibility sets.
friend MrsEligibility operator-(const MrsEligibility &a, SubtableId subtableId)
Creates a new MrsEligibilitySet by adding or removing the specified subtable or the specified set of ...
static MrsEligibility eligibleSubtables(SubtableId subtableId,...)
static MrsEligibility allButTheseSubtables(SubtableId ineligibleSubtableId,...)
MSMainEnums::PredefinedKeywords SubtableId
Create a new table - define shapes, data managers, etc.
String: the storage and methods of handling collections of characters.
Definition String.h:223
const TableLock & lockOptions() const
Get the locking options.
Definition Table.h:1115
const String & tableName() const
Get the table name.
Definition Table.h:1192
TableOption
Define the possible options how a table can be opened.
Definition Table.h:171
@ Scratch
new table, which gets marked for delete
Definition Table.h:179
@ Old
existing table
Definition Table.h:173
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
TableExprNode time(const TableExprNode &node)
Definition ExprNode.h:1584
LatticeExprNode operator+(const LatticeExprNode &expr)
Global functions operating on a LatticeExprNode.
LatticeExprNode operator-(const LatticeExprNode &expr)
MeasurementSet MS
MeasurementSet is too cumbersome for a number of common uses, so we give a typedef here.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44