casacore
MSMColumn.h
Go to the documentation of this file.
1 //# MSMColumn.h: A column in the MemoryStMan
2 //# Copyright (C) 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: aips2-request@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 //# $Id$
27 
28 #ifndef TABLES_MSMCOLUMN_H
29 #define TABLES_MSMCOLUMN_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/tables/DataMan/DataManager.h>
35 #include <casacore/tables/DataMan/StManColumn.h>
36 #include <casacore/casa/Containers/Block.h>
37 #include <casacore/casa/BasicSL/Complex.h>
38 #include <casacore/casa/Arrays/IPosition.h>
39 #include <casacore/casa/BasicSL/String.h>
40 
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42 
43 //# Forward declarations
44 class MSMBase;
45 
46 
47 // <summary>
48 // Column in the Memory table storage manager class
49 // </summary>
50 
51 // <use visibility=local>
52 
53 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
54 // </reviewed>
55 
56 // <prerequisite>
57 //# Classes you should understand before using this one.
58 // <li> <linkto class=StManColumn>StManColumn</linkto>
59 // <li> <linkto class=MemoryStMan>MemoryStMan</linkto>
60 // </prerequisite>
61 
62 // <etymology>
63 // MSMColumn handles a column for the memory-based storage manager.
64 // </etymology>
65 
66 // <synopsis>
67 // MSMColumn is used by MemoryStMan to handle the access to
68 // the data in a table column.
69 // It is an storage manager based in memory. Thus the data is lost
70 // when the table is closed.
71 // On reopen it will be initialized to the default column value.
72 // It fully supports addition and removal of rows.
73 //
74 // MSMColumn serves 2 purposes:
75 // <ol>
76 // <li> It handles a column containing scalar values.
77 // <li> It serves as a base class for MSMDirColumn and MSMIndColumn
78 // These classes handle arrays and use MSMColumn to hold a pointer
79 // to the array in each row.
80 // </ol>
81 //
82 // MSMColumn does not hold a column as a consecutive array,
83 // because extending the column (i.e. adding rows) proved be too
84 // expensive due to the repeated copying involved when creating a table
85 // (this method was used by the first version of the table system).
86 // Instead it has a number of data blocks (extensions) indexed to by a
87 // super block. Accessing a row means finding the appropriate extension
88 // via a binary search. Because there is only 1 extension when a table is
89 // read back, the overhead in finding a row is small.
90 // </synopsis>
91 
92 // <motivation>
93 // MSMColumn handles the standard data types. The class
94 // is not templated, but a switch statement is used instead.
95 // Templates would cause too many instantiations.
96 // </motivation>
97 
98 // <todo asof="$DATE:$">
99 //# A List of bugs, limitations, extensions or planned refinements.
100 // <li> StManAipsIO should use this class
101 // </todo>
102 
103 
104 class MSMColumn: public StManColumn
105 {
106 public:
107  // Create a column of the given type.
108  // It will maintain a pointer to its parent storage manager.
109  MSMColumn (MSMBase* smptr, int dataType, Bool byPtr);
110 
111  // Frees up the storage.
112  virtual ~MSMColumn();
113 
114  // Get a scalar value in the given row.
115  // The buffer pointed to by dataPtr has to have the correct length
116  // (which is guaranteed by the Scalar/ArrayColumn get function).
117  // <group>
118  void getBoolV (uInt rownr, Bool* dataPtr);
119  void getuCharV (uInt rownr, uChar* dataPtr);
120  void getShortV (uInt rownr, Short* dataPtr);
121  void getuShortV (uInt rownr, uShort* dataPtr);
122  void getIntV (uInt rownr, Int* dataPtr);
123  void getuIntV (uInt rownr, uInt* dataPtr);
124  void getfloatV (uInt rownr, float* dataPtr);
125  void getdoubleV (uInt rownr, double* dataPtr);
126  void getComplexV (uInt rownr, Complex* dataPtr);
127  void getDComplexV (uInt rownr, DComplex* dataPtr);
128  void getStringV (uInt rownr, String* dataPtr);
129  // </group>
130 
131  // Put a scalar value into the given row.
132  // The buffer pointed to by dataPtr has to have the correct length
133  // (which is guaranteed by the Scalar/ArrayColumn put function).
134  // <group>
135  void putBoolV (uInt rownr, const Bool* dataPtr);
136  void putuCharV (uInt rownr, const uChar* dataPtr);
137  void putShortV (uInt rownr, const Short* dataPtr);
138  void putuShortV (uInt rownr, const uShort* dataPtr);
139  void putIntV (uInt rownr, const Int* dataPtr);
140  void putuIntV (uInt rownr, const uInt* dataPtr);
141  void putfloatV (uInt rownr, const float* dataPtr);
142  void putdoubleV (uInt rownr, const double* dataPtr);
143  void putComplexV (uInt rownr, const Complex* dataPtr);
144  void putDComplexV (uInt rownr, const DComplex* dataPtr);
145  void putStringV (uInt rownr, const String* dataPtr);
146  // </group>
147 
148  // Get scalars from the given row on with a maximum of nrmax values.
149  // This can be used to get an entire column of scalars or to get
150  // a part of a column (for a cache for example).
151  // The buffer pointed to by dataPtr has to have the correct length
152  // (which is guaranteed by the ScalarColumn get function).
153  // <group>
154  uInt getBlockBoolV (uInt rownr, uInt nrmax, Bool* dataPtr);
155  uInt getBlockuCharV (uInt rownr, uInt nrmax, uChar* dataPtr);
156  uInt getBlockShortV (uInt rownr, uInt nrmax, Short* dataPtr);
157  uInt getBlockuShortV (uInt rownr, uInt nrmax, uShort* dataPtr);
158  uInt getBlockIntV (uInt rownr, uInt nrmax, Int* dataPtr);
159  uInt getBlockuIntV (uInt rownr, uInt nrmax, uInt* dataPtr);
160  uInt getBlockfloatV (uInt rownr, uInt nrmax, float* dataPtr);
161  uInt getBlockdoubleV (uInt rownr, uInt nrmax, double* dataPtr);
162  uInt getBlockComplexV (uInt rownr, uInt nrmax, Complex* dataPtr);
163  uInt getBlockDComplexV (uInt rownr, uInt nrmax, DComplex* dataPtr);
164  uInt getBlockStringV (uInt rownr, uInt nrmax, String* dataPtr);
165  // </group>
166 
167  // Put nrmax scalars from the given row on.
168  // This can be used to put an entire column of scalars or to put
169  // a part of a column (for a cache for example).
170  // The buffer pointed to by dataPtr has to have the correct length
171  // (which is guaranteed by the ScalarColumn put function).
172  // <group>
173  void putBlockBoolV (uInt rownr, uInt nrmax, const Bool* dataPtr);
174  void putBlockuCharV (uInt rownr, uInt nrmax, const uChar* dataPtr);
175  void putBlockShortV (uInt rownr, uInt nrmax, const Short* dataPtr);
176  void putBlockuShortV (uInt rownr, uInt nrmax, const uShort* dataPtr);
177  void putBlockIntV (uInt rownr, uInt nrmax, const Int* dataPtr);
178  void putBlockuIntV (uInt rownr, uInt nrmax, const uInt* dataPtr);
179  void putBlockfloatV (uInt rownr, uInt nrmax, const float* dataPtr);
180  void putBlockdoubleV (uInt rownr, uInt nrmax, const double* dataPtr);
181  void putBlockComplexV (uInt rownr, uInt nrmax, const Complex* dataPtr);
182  void putBlockDComplexV (uInt rownr, uInt nrmax, const DComplex* dataPtr);
183  void putBlockStringV (uInt rownr, uInt nrmax, const String* dataPtr);
184  // </group>
185 
186  // Get the scalar values in some cells of the column.
187  // The buffer pointed to by dataPtr has to have the correct length.
188  // (which is guaranteed by the ScalarColumn getColumnCells function).
189  // The default implementation loops through all rows.
190  // <group>
191  virtual void getScalarColumnCellsBoolV (const RefRows& rownrs,
192  Vector<Bool>* dataPtr);
193  virtual void getScalarColumnCellsuCharV (const RefRows& rownrs,
194  Vector<uChar>* dataPtr);
195  virtual void getScalarColumnCellsShortV (const RefRows& rownrs,
196  Vector<Short>* dataPtr);
197  virtual void getScalarColumnCellsuShortV (const RefRows& rownrs,
198  Vector<uShort>* dataPtr);
199  virtual void getScalarColumnCellsIntV (const RefRows& rownrs,
200  Vector<Int>* dataPtr);
201  virtual void getScalarColumnCellsuIntV (const RefRows& rownrs,
202  Vector<uInt>* dataPtr);
203  virtual void getScalarColumnCellsfloatV (const RefRows& rownrs,
204  Vector<float>* dataPtr);
205  virtual void getScalarColumnCellsdoubleV (const RefRows& rownrs,
206  Vector<double>* dataPtr);
207  virtual void getScalarColumnCellsComplexV (const RefRows& rownrs,
208  Vector<Complex>* dataPtr);
209  virtual void getScalarColumnCellsDComplexV (const RefRows& rownrs,
210  Vector<DComplex>* dataPtr);
211  virtual void getScalarColumnCellsStringV (const RefRows& rownrs,
212  Vector<String>* dataPtr);
213  // </group>
214 
215  // Add (newNrrow-oldNrrow) rows to the column.
216  virtual void addRow (uInt newNrrow, uInt oldNrrow);
217 
218  // Resize the data blocks.
219  // This adds an extension when needed.
220  void resize (uInt nrval);
221 
222  // Remove the given row.
223  // If no rows remain in the extension, the extension is also removed.
224  virtual void remove (uInt rownr);
225 
226  // Create the number of rows in a new table.
227  // This is used when a table gets created or opened.
228  virtual void doCreate (uInt nrrow);
229 
230  // Check if the class invariants still hold.
231  virtual Bool ok() const;
232 
233 protected:
235  // The data type (for caching purposes).
236  int dtype_p;
237  // The data is indirectly accessed via a pointer (for the derived classes).
239  // The number of allocated rows in the column.
241  // The nr of extensions in use.
243  // The assembly of all extensions (actually Block<T*>).
245  // The cumulative nr of rows in all extensions.
247 
248  // Find the extension in which the row number is.
249  // If the flag is true, it also sets the columnCache object.
250  uInt findExt (uInt rownr, Bool setCache);
251 
252  // Get the next extension.
253  // For the first iteration extnr should be zero.
254  // It returns the number of values in it until the maximum is reached.
255  // Zero means no more extensions.
256  uInt nextExt (void*& ext, uInt& extnr, uInt nrmax) const;
257 
258  // Allocate an extension with the data type of the column.
259  void* allocData (uInt nrval, Bool byPtr);
260 
261  // Delete all extensions.
262  // Possible underlying data (as used by StManArrayColumnMemory)
263  // will not be deleted and should have been deleted beforehand.
264  void deleteAll();
265 
266  // Delete an extension.
267  void deleteData (void* datap, Bool byPtr);
268 
269  // Remove an entry (i.e. a row) from an extension at the given index.
270  // It will do this by shifting the rest (nrvalAfter elements)
271  // one position to the left.
272  void removeData (void* datap, uInt inx, uInt nrvalAfter);
273 
274  // Initialize the data (after an open).
275  void initData (void* datap, uInt nrval);
276 
277  // Get the pointer for the given row.
278  // This is for the derived classes like StManArrayColumnMemory.
279  void* getArrayPtr (uInt rownr);
280 
281  // Put the pointer for the given row.
282  // This is for the derived classes like StManArrayColumnMemory.
283  void putArrayPtr (uInt rownr, void* dataPtr);
284 
285 private:
286  // Forbid copy constructor.
287  MSMColumn (const MSMColumn&);
288 
289  // Forbid assignment.
290  MSMColumn& operator= (const MSMColumn&);
291 };
292 
293 
294 
295 } //# NAMESPACE CASACORE - END
296 
297 #endif
void putArrayPtr(uInt rownr, void *dataPtr)
Put the pointer for the given row.
void putuIntV(uInt rownr, const uInt *dataPtr)
void initData(void *datap, uInt nrval)
Initialize the data (after an open).
void putuShortV(uInt rownr, const uShort *dataPtr)
void putBlockBoolV(uInt rownr, uInt nrmax, const Bool *dataPtr)
Put nrmax scalars from the given row on.
int Int
Definition: aipstype.h:50
MSMBase * stmanPtr_p
Definition: MSMColumn.h:234
uInt getBlockfloatV(uInt rownr, uInt nrmax, float *dataPtr)
void putBlockComplexV(uInt rownr, uInt nrmax, const Complex *dataPtr)
uInt nralloc_p
The number of allocated rows in the column.
Definition: MSMColumn.h:240
uInt getBlockuShortV(uInt rownr, uInt nrmax, uShort *dataPtr)
void putBlockuIntV(uInt rownr, uInt nrmax, const uInt *dataPtr)
virtual void getScalarColumnCellsuShortV(const RefRows &rownrs, Vector< uShort > *dataPtr)
uInt getBlockBoolV(uInt rownr, uInt nrmax, Bool *dataPtr)
Get scalars from the given row on with a maximum of nrmax values.
void getComplexV(uInt rownr, Complex *dataPtr)
void * allocData(uInt nrval, Bool byPtr)
Allocate an extension with the data type of the column.
void getfloatV(uInt rownr, float *dataPtr)
void putShortV(uInt rownr, const Short *dataPtr)
virtual void getScalarColumnCellsIntV(const RefRows &rownrs, Vector< Int > *dataPtr)
unsigned char uChar
Definition: aipstype.h:47
uInt findExt(uInt rownr, Bool setCache)
Find the extension in which the row number is.
uInt getBlockComplexV(uInt rownr, uInt nrmax, Complex *dataPtr)
Base class for memory-based table storage manager class.
Definition: MSMBase.h:66
MSMColumn(MSMBase *smptr, int dataType, Bool byPtr)
Create a column of the given type.
void putBlockfloatV(uInt rownr, uInt nrmax, const float *dataPtr)
virtual void getScalarColumnCellsStringV(const RefRows &rownrs, Vector< String > *dataPtr)
uInt getBlockIntV(uInt rownr, uInt nrmax, Int *dataPtr)
void putBlockdoubleV(uInt rownr, uInt nrmax, const double *dataPtr)
virtual ~MSMColumn()
Frees up the storage.
uInt getBlockStringV(uInt rownr, uInt nrmax, String *dataPtr)
Block< void * > data_p
The assembly of all extensions (actually Block<T*>).
Definition: MSMColumn.h:244
void deleteAll()
Delete all extensions.
int dataType() const
Return the data type of the column.
uInt nextExt(void *&ext, uInt &extnr, uInt nrmax) const
Get the next extension.
uInt getBlockuIntV(uInt rownr, uInt nrmax, uInt *dataPtr)
void getuIntV(uInt rownr, uInt *dataPtr)
void putBlockuCharV(uInt rownr, uInt nrmax, const uChar *dataPtr)
short Short
Definition: aipstype.h:48
void putBlockStringV(uInt rownr, uInt nrmax, const String *dataPtr)
uInt getBlockDComplexV(uInt rownr, uInt nrmax, DComplex *dataPtr)
virtual void getScalarColumnCellsuCharV(const RefRows &rownrs, Vector< uChar > *dataPtr)
uInt getBlockdoubleV(uInt rownr, uInt nrmax, double *dataPtr)
void removeData(void *datap, uInt inx, uInt nrvalAfter)
Remove an entry (i.e.
void resize(uInt nrval)
Resize the data blocks.
virtual void getScalarColumnCellsShortV(const RefRows &rownrs, Vector< Short > *dataPtr)
void putBlockuShortV(uInt rownr, uInt nrmax, const uShort *dataPtr)
void getDComplexV(uInt rownr, DComplex *dataPtr)
virtual void getScalarColumnCellsfloatV(const RefRows &rownrs, Vector< float > *dataPtr)
void putBlockDComplexV(uInt rownr, uInt nrmax, const DComplex *dataPtr)
void putfloatV(uInt rownr, const float *dataPtr)
Class holding the row numbers in a RefTable.
Definition: RefRows.h:85
void deleteData(void *datap, Bool byPtr)
Delete an extension.
Block< uInt > ncum_p
The cumulative nr of rows in all extensions.
Definition: MSMColumn.h:246
virtual void doCreate(uInt nrrow)
Create the number of rows in a new table.
void putComplexV(uInt rownr, const Complex *dataPtr)
virtual void getScalarColumnCellsComplexV(const RefRows &rownrs, Vector< Complex > *dataPtr)
virtual void addRow(uInt newNrrow, uInt oldNrrow)
Add (newNrrow-oldNrrow) rows to the column.
void putuCharV(uInt rownr, const uChar *dataPtr)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void getdoubleV(uInt rownr, double *dataPtr)
uInt nrext_p
The nr of extensions in use.
Definition: MSMColumn.h:242
virtual Bool ok() const
Check if the class invariants still hold.
Column in the Memory table storage manager class.
Definition: MSMColumn.h:104
void * getArrayPtr(uInt rownr)
Get the pointer for the given row.
virtual void getScalarColumnCellsDComplexV(const RefRows &rownrs, Vector< DComplex > *dataPtr)
MSMColumn & operator=(const MSMColumn &)
Forbid assignment.
void getuCharV(uInt rownr, uChar *dataPtr)
int dtype_p
The data type (for caching purposes).
Definition: MSMColumn.h:236
simple 1-D array
Definition: ArrayIO.h:47
void putBlockShortV(uInt rownr, uInt nrmax, const Short *dataPtr)
virtual void getScalarColumnCellsBoolV(const RefRows &rownrs, Vector< Bool > *dataPtr)
Get the scalar values in some cells of the column.
void putDComplexV(uInt rownr, const DComplex *dataPtr)
void putIntV(uInt rownr, const Int *dataPtr)
void getStringV(uInt rownr, String *dataPtr)
virtual void getScalarColumnCellsuIntV(const RefRows &rownrs, Vector< uInt > *dataPtr)
uInt getBlockShortV(uInt rownr, uInt nrmax, Short *dataPtr)
void getuShortV(uInt rownr, uShort *dataPtr)
void getIntV(uInt rownr, Int *dataPtr)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void putBoolV(uInt rownr, const Bool *dataPtr)
Put a scalar value into the given row.
void putStringV(uInt rownr, const String *dataPtr)
uInt getBlockuCharV(uInt rownr, uInt nrmax, uChar *dataPtr)
void putBlockIntV(uInt rownr, uInt nrmax, const Int *dataPtr)
void getShortV(uInt rownr, Short *dataPtr)
void putdoubleV(uInt rownr, const double *dataPtr)
void getBoolV(uInt rownr, Bool *dataPtr)
Get a scalar value in the given row.
virtual void getScalarColumnCellsdoubleV(const RefRows &rownrs, Vector< double > *dataPtr)
Base table column storage manager class.
Definition: StManColumn.h:102
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
unsigned short uShort
Definition: aipstype.h:49
Bool byPtr_p
The data is indirectly accessed via a pointer (for the derived classes).
Definition: MSMColumn.h:238