casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AsdmStMan.h
Go to the documentation of this file.
1 //# AsdmStMan.h: Storage Manager for the main table of a raw ASDM casacore::MS
2 //# Copyright (C) 2012
3 //# Associated Universities, Inc. Washington DC, USA.
4 //# (c) European Southern Observatory, 2012
5 //# Copyright by ESO (in the framework of the ALMA collaboration)
6 //#
7 //# This library is free software; you can redistribute it and/or modify it
8 //# under the terms of the GNU Library General Public License as published by
9 //# the Free Software Foundation; either version 2 of the License, or (at your
10 //# option) any later version.
11 //#
12 //# This library is distributed in the hope that it will be useful, but WITHOUT
13 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15 //# License for more details.
16 //#
17 //# You should have received a copy of the GNU Library General Public License
18 //# along with this library; if not, write to the Free Software Foundation,
19 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20 //#
21 //# Correspondence concerning AIPS++ should be addressed as follows:
22 //# Internet email: aips2-request@nrao.edu.
23 //# Postal address: AIPS++ Project Office
24 //# National Radio Astronomy Observatory
25 //# 520 Edgemont Road
26 //# Charlottesville, VA 22903-2475 USA
27 //#
28 //# $Id: AsdmStMan.h 18108 2011-05-27 07:52:39Z broekema $
29 
30 #ifndef ASDM_ASDMSTMAN_H
31 #define ASDM_ASDMSTMAN_H
32 
33 //# Includes
34 #include <asdmstman/AsdmIndex.h>
36 #include <casa/IO/FiledesIO.h>
37 #include <casa/Containers/Block.h>
38 #include <casa/Containers/Record.h>
39 
40 namespace casa {
41 
42 //# Forward Declarations.
43 class AsdmColumn;
44 
45 // <summary>
46 // The Storage Manager for the main table of a raw ASDM casacore::MS
47 // </summary>
48 
49 // <use visibility=export>
50 
51 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tAsdmStMan.cc">
52 // </reviewed>
53 
54 // <prerequisite>
55 //# Classes you should understand before using this one.
56 // <li> The casacore::Table casacore::Data Managers concept as described in module file
57 // <linkto module="Tables:Data Managers">Tables.h</linkto>
58 // </prerequisite>
59 
60 // <etymology>
61 // AsdmStMan is the data manager which stores the data for a ASDM MS.
62 // </etymology>
63 
64 // <synopsis>
65 // AsdmStMan is a specific storage manager for the main table of a ASDM MS.
66 // For performance purposes the raw data from the correlator is directly
67 // written to a disk file. However, to be able to use the data directly as a
68 // casacore::MeasurementSet, this specific storage manager is created offering access to
69 // all mandatory columns in the main table of the MS.
70 //
71 // Similar to other storage managers, the AsdmStMan files need to be part of
72 // the table directory. There are two files:
73 // <ul>
74 // <li> The meta file contains the meta data describing baselines, start time,
75 // integration time, etc. It needs to be written as an casacore::AipsIO file.
76 // The meta info should also tell the endianness of the data file.
77 // <li> The data file consists of NSEQ data blocks each containing:
78 // <ul>
79 // <li> 4-byte sequence number defining the time stamp.
80 // <li> casacore::Complex data with shape [npol,nchan,nbasel].
81 // <li> Unsigned short nr of samples used in each data point. It has shape
82 // [nchan,nbasel]. It defines WEIGHT_SPECTRUM and FLAG.
83 // <li> Filler bytes to align the blocks as given in the meta info.
84 // </ul>
85 // The sequence numbers are ascending, but there can be holes due to
86 // missing time stamps.
87 // </ul>
88 // The first versions of the data file can only handle regularly shaped data
89 // with equal integration times. A future version might be able to deal with
90 // varying integration times (depending on baseline length).
91 //
92 // Most of the casacore::MS columns (like DATA_DESC_ID) are not stored in the data file;
93 // usually they map to the value 0. This is also true for the UVW column, so
94 // the UVW coordinates need to be added to the table in a separate step because
95 // the online system does not have the resources to do it.
96 //
97 // All columns are readonly with the exception of DATA.
98 // </synopsis>
99 
100 // <motivation>
101 // The common casacore::Table storage managers are too slow for the possibly high
102 // output rate of the ASDM correlator.
103 // </motivation>
104 
105 // <example>
106 // The following example shows how to create a table and how to attach
107 // the storage manager to some columns.
108 // <srcblock>
109 // casacore::SetupNewTable newtab("name.data", tableDesc, casacore::Table::New);
110 // AsdmStMan stman; // define storage manager
111 // newtab.bindColumn ("DATA", stman); // bind column to st.man.
112 // newtab.bindColumn ("FLAG", stman); // bind column to st.man.
113 // casacore::Table tab(newtab); // actually create table
114 // </srcblock>
115 // </example>
116 
117 //# <todo asof="$DATE:$">
118 //# A casacore::List of bugs, limitations, extensions or planned refinements.
119 //# </todo>
120 
121 
123 {
124 public:
125  // Create a Asdm storage manager with the given name.
126  // If no name is used, it is set to "AsdmStMan"
127  explicit AsdmStMan (const casacore::String& dataManagerName = "AsdmStMan");
128 
129  // Create a Asdm storage manager with the given name.
130  // The specifications are part of the record (as created by dataManagerSpec).
132 
133  ~AsdmStMan();
134 
135  // Clone this object.
136  virtual casacore::DataManager* clone() const;
137 
138  // Get the type name of the data manager (i.e. AsdmStMan).
139  virtual casacore::String dataManagerType() const;
140 
141  // Get the name given to the storage manager (in the constructor).
142  virtual casacore::String dataManagerName() const;
143 
144  // casacore::Record a record containing data manager specifications.
145  virtual casacore::Record dataManagerSpec() const;
146 
147  // Is this a regular storage manager?
148  // It is regular if it allows addition of rows and writing dara in them.
149  // <br>We need to return false here.
150  virtual casacore::Bool isRegular() const;
151 
152  // The storage manager can add rows, but does nothing.
153  virtual casacore::Bool canAddRow() const;
154 
155  // The storage manager cannot delete rows.
156  virtual casacore::Bool canRemoveRow() const;
157 
158  // The storage manager can add columns, which does not really do something.
159  virtual casacore::Bool canAddColumn() const;
160 
161  // Columns can be removed, but it does not do anything at all.
162  virtual casacore::Bool canRemoveColumn() const;
163 
164  // Make the object from the type name string.
165  // This function gets registered in the casacore::DataManager "constructor" map.
166  // The caller has to delete the object.
167  static casacore::DataManager* makeObject (const casacore::String& aDataManType,
168  const casacore::Record& spec);
169 
170  // Register the class name and the static makeObject "constructor".
171  // This will make the engine known to the table system.
172  static void registerClass();
173 
174 
175  // Get the data shape.
177 
178  // Get data.
179  void getData (casacore::uInt rownr, casacore::Complex* buf);
180 
181  // Get float data
182  void getData (casacore::uInt rownr, casacore::Float* buf);
183 
185  { return itsVersion; }
186 
187  // access the references to the ASDM BDFs
189 
190  // overwrite the BDFNames (casacore::Block needs to have same size as original,
191  // returns false otherwise)
193 
194  // overwrite the index with the information presently stored in the
195  // data manager
196  void writeIndex();
197 
198 private:
199  // Copy constructor cannot be used.
200  AsdmStMan (const AsdmStMan& that);
201 
202  // Assignment cannot be used.
203  AsdmStMan& operator= (const AsdmStMan& that);
204 
205  // Flush and optionally fsync the data.
206  // It does nothing, and returns false.
208 
209  // Let the storage manager create files as needed for a new table.
210  // This allows a column with an indirect array to create its file.
211  virtual void create (casacore::uInt nrrow);
212 
213  // Open the storage manager file for an existing table.
214  virtual void open (casacore::uInt nrrow, casacore::AipsIO&); //# should never be called
215 
216  // Prepare the columns (needed for UvwColumn).
217  virtual void prepare();
218 
219  // Resync the storage manager with the new file contents.
220  // It does nothing.
221  virtual void resync (casacore::uInt nrrow);
222 
223  // Reopen the storage manager files for read/write.
224  // It does nothing.
225  virtual void reopenRW();
226 
227  // The data manager will be deleted (because all its columns are
228  // requested to be deleted).
229  // So clean up the things needed (e.g. delete files).
230  virtual void deleteManager();
231 
232  // Add rows to the storage manager.
233  // It cannot do it, so it does nothing.
234  // This function will be called, because this storage manager is not the
235  // only one used in an ASDM MS.
236  virtual void addRow (casacore::uInt nrrow);
237 
238  // Delete a row from all columns.
239  // It cannot do it, so throws an exception.
240  virtual void removeRow (casacore::uInt rowNr);
241 
242  // Do the final addition of a column.
243  // It won't do anything.
244  virtual void addColumn (casacore::DataManagerColumn*);
245 
246  // Remove a column from the data file.
247  // It won't do anything.
249 
250  // Create a column in the storage manager on behalf of a table column.
251  // The caller has to delete the newly created object.
252  // <group>
253  // Create a scalar column.
255  int aDataType,
256  const casacore::String& aDataTypeID);
257  // Create a direct array column.
259  int aDataType,
260  const casacore::String& aDataTypeID);
261  // Create an indirect array column.
263  int aDataType,
264  const casacore::String& aDataTypeID);
265  // </group>
266 
267  // Initialize by reading the index file and opening the BDFs.
268  void init();
269 
270  // Close the currently open BDF file.
271  void closeBDF();
272 
273  // Return the entry number in the index containing the row.
275 
276  // Return the index block containing the row.
277  // It sets itsIndexEntry to that block.
278  const AsdmIndex& findIndex (casacore::Int64 rownr);
279 
280  // Get data from the buffer.
281  // <group>
283  void getInt (const AsdmIndex&, casacore::Complex* buf, casacore::uInt bl, casacore::uInt spw);
285  void getAuto (const AsdmIndex&, casacore::Complex* buf, casacore::uInt bl);
286  void getAuto (const AsdmIndex&, casacore::Float* buf, casacore::uInt bl);
287  // </group>
288 
289 
290  // set transposeBLNum_v
292 
293  //# Declare member variables.
294  // Name of data manager.
296  // The column objects.
297  std::vector<AsdmColumn*> itsColumns;
300  int itsFD;
301  int itsOpenBDF;
303  casacore::Bool itsDoSwap; //# true = byte-swapping is needed
304  casacore::Record itsSpec; //# casacore::Data manager properties
305  casacore::uInt itsVersion; //# Version of AsdmStMan casacore::MeasurementSet
306  //# Fields to keep track of last block accessed.
307  casacore::Int64 itsStartRow; //# First row of data block
308  casacore::Int64 itsEndRow; //# First row of next data block
309  casacore::uInt itsIndexEntry; //# Index entry number of current data block
310  std::vector<char> itsData;
311  std::vector<AsdmIndex> itsIndex;
312  std::vector<casacore::Int64> itsIndexRows;
313 
315  std::vector<casacore::uInt> itsTransposeBLNum_v;
316 };
317 
318 
319 } //# end namespace
320 
321 #endif
322 
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
casacore::FiledesIO * itsBDF
Definition: AsdmStMan.h:342
virtual casacore::DataManagerColumn * makeDirArrColumn(const casacore::String &aName, int aDataType, const casacore::String &aDataTypeID)
Create a direct array column.
virtual void reopenRW()
Reopen the storage manager files for read/write.
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
Abstract base class for a column in a data manager.
Definition: DataManager.h:611
virtual casacore::DataManagerColumn * makeIndArrColumn(const casacore::String &aName, int aDataType, const casacore::String &aDataTypeID)
Create an indirect array column.
static casacore::DataManager * makeObject(const casacore::String &aDataManType, const casacore::Record &spec)
Make the object from the type name string.
casacore::Bool itsDoSwap
Definition: AsdmStMan.h:346
virtual casacore::Bool canRemoveRow() const
The storage manager cannot delete rows.
casacore::String itsDataManName
Name of data manager.
Definition: AsdmStMan.h:337
AsdmStMan(const casacore::String &dataManagerName="AsdmStMan")
Create a Asdm storage manager with the given name.
void writeIndex()
overwrite the index with the information presently stored in the data manager
AsdmStMan & operator=(const AsdmStMan &that)
Assignment cannot be used.
static void registerClass()
Register the class name and the static makeObject &quot;constructor&quot;.
virtual void deleteManager()
The data manager will be deleted (because all its columns are requested to be deleted).
casacore::Bool setBDFNames(casacore::Block< casacore::String > &bDFNames)
overwrite the BDFNames (casacore::Block needs to have same size as original, returns false otherwise)...
void getData(casacore::uInt rownr, casacore::Complex *buf)
Get data.
virtual void open(casacore::uInt nrrow, casacore::AipsIO &)
Open the storage manager file for an existing table.
virtual void removeRow(casacore::uInt rowNr)
Delete a row from all columns.
void getInt(const AsdmIndex &, casacore::Complex *buf, casacore::uInt bl, casacore::uInt spw)
casacore::Record itsSpec
Definition: AsdmStMan.h:347
casacore::Block< casacore::String > itsBDFNames
Definition: AsdmStMan.h:341
Class for unbuffered IO on a file.
Definition: FiledesIO.h:88
The Storage Manager for the main table of a raw ASDM casacore::MS.
Definition: AsdmStMan.h:122
virtual casacore::Bool isRegular() const
Is this a regular storage manager? It is regular if it allows addition of rows and writing dara in th...
casacore::uInt searchIndex(casacore::Int64 rownr)
Return the entry number in the index containing the row.
An index entry for the ASDM Storage Manager.
Definition: AsdmIndex.h:70
virtual casacore::Bool flush(casacore::AipsIO &, casacore::Bool doFsync)
Flush and optionally fsync the data.
const AsdmIndex & findIndex(casacore::Int64 rownr)
Return the index block containing the row.
void closeBDF()
Close the currently open BDF file.
casacore::Int64 itsStartRow
Definition: AsdmStMan.h:350
std::vector< casacore::uInt > itsTransposeBLNum_v
Definition: AsdmStMan.h:358
std::vector< AsdmIndex > itsIndex
Definition: AsdmStMan.h:354
virtual casacore::Record dataManagerSpec() const
casacore::Record a record containing data manager specifications.
casacore::uInt getAsdmStManVersion() const
Definition: AsdmStMan.h:200
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual void addColumn(casacore::DataManagerColumn *)
Do the final addition of a column.
casacore::uInt itsNBl
Definition: AsdmStMan.h:357
float Float
Definition: aipstype.h:54
casacore::IPosition getShape(casacore::uInt rownr)
Get the data shape.
std::vector< AsdmColumn * > itsColumns
The column objects.
Definition: AsdmStMan.h:340
virtual void create(casacore::uInt nrrow)
Let the storage manager create files as needed for a new table.
std::vector< casacore::Int64 > itsIndexRows
Definition: AsdmStMan.h:355
virtual void resync(casacore::uInt nrrow)
Resync the storage manager with the new file contents.
void getAuto(const AsdmIndex &, casacore::Complex *buf, casacore::uInt bl)
casacore::uInt itsVersion
Definition: AsdmStMan.h:348
std::vector< char > itsData
Definition: AsdmStMan.h:353
virtual void addRow(casacore::uInt nrrow)
Add rows to the storage manager.
void getFloat(const AsdmIndex &, casacore::Complex *buf, casacore::uInt bl, casacore::uInt spw)
virtual casacore::String dataManagerName() const
Get the name given to the storage manager (in the constructor).
Abstract base class for a data manager.
Definition: DataManager.h:224
virtual casacore::DataManager * clone() const
Clone this object.
void getBDFNames(casacore::Block< casacore::String > &bDFNames)
access the references to the ASDM BDFs
virtual void removeColumn(casacore::DataManagerColumn *)
Remove a column from the data file.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void getShort(const AsdmIndex &, casacore::Complex *buf, casacore::uInt bl, casacore::uInt spw)
Get data from the buffer.
casacore::Int64 itsFileOffset
Definition: AsdmStMan.h:345
virtual casacore::String dataManagerType() const
Get the type name of the data manager (i.e.
virtual casacore::Bool canAddRow() const
The storage manager can add rows, but does nothing.
void setTransposeBLNum(casacore::uInt nBl)
set transposeBLNum_v
virtual void prepare()
Prepare the columns (needed for UvwColumn).
virtual casacore::Bool canRemoveColumn() const
Columns can be removed, but it does not do anything at all.
casacore::Int64 itsEndRow
Definition: AsdmStMan.h:351
void init()
Initialize by reading the index file and opening the BDFs.
casacore::uInt itsIndexEntry
Definition: AsdmStMan.h:352
virtual casacore::DataManagerColumn * makeScalarColumn(const casacore::String &aName, int aDataType, const casacore::String &aDataTypeID)
Create a column in the storage manager on behalf of a table column.
unsigned int uInt
Definition: aipstype.h:51
virtual casacore::Bool canAddColumn() const
The storage manager can add columns, which does not really do something.