casacore
Loading...
Searching...
No Matches
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: 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 TABLES_MSMCOLUMN_H
27#define TABLES_MSMCOLUMN_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/DataMan/StManColumnBase.h>
33#include <casacore/casa/Containers/Block.h>
34#include <casacore/casa/BasicSL/Complex.h>
35#include <casacore/casa/Arrays/IPosition.h>
36#include <casacore/casa/BasicSL/String.h>
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40//# Forward declarations
41class MSMBase;
42
43
44// <summary>
45// Column in the Memory table storage manager class
46// </summary>
47
48// <use visibility=local>
49
50// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
51// </reviewed>
52
53// <prerequisite>
54//# Classes you should understand before using this one.
55// <li> <linkto class=StManColumn>StManColumn</linkto>
56// <li> <linkto class=MemoryStMan>MemoryStMan</linkto>
57// </prerequisite>
58
59// <etymology>
60// MSMColumn handles a column for the memory-based storage manager.
61// </etymology>
62
63// <synopsis>
64// MSMColumn is used by MemoryStMan to handle the access to
65// the data in a table column.
66// It is an storage manager based in memory. Thus the data is lost
67// when the table is closed.
68// On reopen it will be initialized to the default column value.
69// It fully supports addition and removal of rows.
70//
71// MSMColumn serves 2 purposes:
72// <ol>
73// <li> It handles a column containing scalar values.
74// <li> It serves as a base class for MSMDirColumn and MSMIndColumn
75// These classes handle arrays and use MSMColumn to hold a pointer
76// to the array in each row.
77// </ol>
78//
79// MSMColumn does not hold a column as a consecutive array,
80// because extending the column (i.e. adding rows) proved be too
81// expensive due to the repeated copying involved when creating a table
82// (this method was used by the first version of the table system).
83// Instead it has a number of data blocks (extensions) indexed to by a
84// super block. Accessing a row means finding the appropriate extension
85// via a binary search. Because there is only 1 extension when a table is
86// read back, the overhead in finding a row is small.
87// </synopsis>
88
89// <motivation>
90// MSMColumn handles the standard data types. The class
91// is not templated, but a switch statement is used instead.
92// Templates would cause too many instantiations.
93// </motivation>
94
95// <todo asof="$DATE:$">
96//# A List of bugs, limitations, extensions or planned refinements.
97// <li> StManAipsIO should use this class
98// </todo>
99
100
102{
103public:
104 // Create a column of the given type.
105 // It will maintain a pointer to its parent storage manager.
106 MSMColumn (MSMBase* smptr, int dataType, Bool byPtr);
107
108 // Frees up the storage.
109 virtual ~MSMColumn();
110
111 // Forbid copy constructor.
112 MSMColumn (const MSMColumn&) = delete;
113
114 // Forbid assignment.
115 MSMColumn& operator= (const MSMColumn&) = delete;
116
117 // Get a scalar value in the given row.
118 // The buffer pointed to by dataPtr has to have the correct length
119 // (which is guaranteed by the Scalar/ArrayColumn get function).
120 // <group>
121 virtual void getBool (rownr_t rownr, Bool* dataPtr);
122 virtual void getuChar (rownr_t rownr, uChar* dataPtr);
123 virtual void getShort (rownr_t rownr, Short* dataPtr);
124 virtual void getuShort (rownr_t rownr, uShort* dataPtr);
125 virtual void getInt (rownr_t rownr, Int* dataPtr);
126 virtual void getuInt (rownr_t rownr, uInt* dataPtr);
127 virtual void getInt64 (rownr_t rownr, Int64* dataPtr);
128 virtual void getfloat (rownr_t rownr, float* dataPtr);
129 virtual void getdouble (rownr_t rownr, double* dataPtr);
130 virtual void getComplex (rownr_t rownr, Complex* dataPtr);
131 virtual void getDComplex (rownr_t rownr, DComplex* dataPtr);
132 virtual void getString (rownr_t rownr, String* dataPtr);
133 // </group>
134
135 // Put a scalar value into the given row.
136 // The buffer pointed to by dataPtr has to have the correct length
137 // (which is guaranteed by the Scalar/ArrayColumn put function).
138 // <group>
139 virtual void putBool (rownr_t rownr, const Bool* dataPtr);
140 virtual void putuChar (rownr_t rownr, const uChar* dataPtr);
141 virtual void putShort (rownr_t rownr, const Short* dataPtr);
142 virtual void putuShort (rownr_t rownr, const uShort* dataPtr);
143 virtual void putInt (rownr_t rownr, const Int* dataPtr);
144 virtual void putuInt (rownr_t rownr, const uInt* dataPtr);
145 virtual void putInt64 (rownr_t rownr, const Int64* dataPtr);
146 virtual void putfloat (rownr_t rownr, const float* dataPtr);
147 virtual void putdouble (rownr_t rownr, const double* dataPtr);
148 virtual void putComplex (rownr_t rownr, const Complex* dataPtr);
149 virtual void putDComplex (rownr_t rownr, const DComplex* dataPtr);
150 virtual void putString (rownr_t rownr, const String* dataPtr);
151 // </group>
152
153 // Get all scalar values in the column.
154 // The vector given in <src>data</src> has to have the correct length
155 // (which is guaranteed by the ScalarColumn getColumn function).
156 virtual void getScalarColumnV (ArrayBase& data);
157
158 // Put all scalar values in the column.
159 // The vector given in <src>data</src> has to have the correct length
160 // (which is guaranteed by the ScalarColumn putColumn function).
161 virtual void putScalarColumnV (const ArrayBase& data);
162
163 // Add (newNrrow-oldNrrow) rows to the column.
164 virtual void addRow (rownr_t newNrrow, rownr_t oldNrrow);
165
166 // Resize the data blocks.
167 // This adds an extension when needed.
168 void resize (rownr_t nrval);
169
170 // Remove the given row.
171 // If no rows remain in the extension, the extension is also removed.
172 virtual void remove (rownr_t rownr);
173
174 // Create the number of rows in a new table.
175 // This is used when a table gets created or opened.
176 virtual void doCreate (rownr_t nrrow);
177
178 // Make it possible to write the column data.
179 // It is only used by derived classes.
180 virtual void putFile (rownr_t nrval, AipsIO&);
181
182 // Make it possible to read the column data.
183 // It is only used by derived classes.
184 virtual void getFile (rownr_t nrval, AipsIO&);
185
186 // Reopen the storage manager files for read/write.
187 virtual void reopenRW();
188
189 // Check if the class invariants still hold.
190 virtual Bool ok() const;
191
192protected:
194 // The data is indirectly accessed via a pointer (for the derived classes).
196 // The number of allocated rows in the column.
198 // The nr of extensions in use.
200 // The assembly of all extensions (actually Block<T*>).
202 // The cumulative nr of rows in all extensions.
204
205 // Find the extension in which the row number is.
206 // If the flag is true, it also sets the columnCache object.
207 uInt findExt (rownr_t rownr, Bool setCache);
208
209 // Allocate an extension with the data type of the column.
210 void* allocData (rownr_t nrval, Bool byPtr);
211
212 // Delete all extensions.
213 // Possible underlying data (as used by StManArrayColumnMemory)
214 // will not be deleted and should have been deleted beforehand.
215 void deleteAll();
216
217 // Delete an extension.
218 void deleteData (void* datap, Bool byPtr);
219
220 // Remove an entry (i.e. a row) from an extension at the given index.
221 // It will do this by shifting the rest (nrvalAfter elements)
222 // one position to the left.
223 void removeData (void* datap, rownr_t inx, rownr_t nrvalAfter);
224
225 // Initialize the data (after an open).
226 virtual void initData (void* datap, rownr_t nrval);
227
228 // Get the pointer for the given row.
229 // This is for the derived classes like StManArrayColumnMemory.
230 void* getArrayPtr (rownr_t rownr);
231
232 // Put the pointer for the given row.
233 // This is for the derived classes like StManArrayColumnMemory.
234 void putArrayPtr (rownr_t rownr, void* dataPtr);
235};
236
237
238
239} //# NAMESPACE CASACORE - END
240
241#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
simple 1-D array
Definition Block.h:198
virtual void getdouble(rownr_t rownr, double *dataPtr)
virtual void getComplex(rownr_t rownr, Complex *dataPtr)
virtual void putComplex(rownr_t rownr, const Complex *dataPtr)
virtual void remove(rownr_t rownr)
Remove the given row.
virtual void putuShort(rownr_t rownr, const uShort *dataPtr)
void deleteAll()
Delete all extensions.
virtual void getuShort(rownr_t rownr, uShort *dataPtr)
Bool byPtr_p
The data is indirectly accessed via a pointer (for the derived classes).
Definition MSMColumn.h:195
virtual ~MSMColumn()
Frees up the storage.
void resize(rownr_t nrval)
Resize the data blocks.
virtual void putDComplex(rownr_t rownr, const DComplex *dataPtr)
virtual void addRow(rownr_t newNrrow, rownr_t oldNrrow)
Add (newNrrow-oldNrrow) rows to the column.
MSMColumn(const MSMColumn &)=delete
Forbid copy constructor.
uInt findExt(rownr_t rownr, Bool setCache)
Find the extension in which the row number is.
Block< rownr_t > ncum_p
The cumulative nr of rows in all extensions.
Definition MSMColumn.h:203
MSMColumn(MSMBase *smptr, int dataType, Bool byPtr)
Create a column of the given type.
virtual void putString(rownr_t rownr, const String *dataPtr)
void putArrayPtr(rownr_t rownr, void *dataPtr)
Put the pointer for the given row.
virtual void initData(void *datap, rownr_t nrval)
Initialize the data (after an open).
virtual void putBool(rownr_t rownr, const Bool *dataPtr)
Put a scalar value into the given row.
virtual void getInt64(rownr_t rownr, Int64 *dataPtr)
virtual void getDComplex(rownr_t rownr, DComplex *dataPtr)
MSMColumn & operator=(const MSMColumn &)=delete
Forbid assignment.
Block< void * > data_p
The assembly of all extensions (actually Block<T*>).
Definition MSMColumn.h:201
virtual void putdouble(rownr_t rownr, const double *dataPtr)
virtual void getInt(rownr_t rownr, Int *dataPtr)
virtual void getShort(rownr_t rownr, Short *dataPtr)
virtual void putFile(rownr_t nrval, AipsIO &)
Make it possible to write the column data.
virtual void getuInt(rownr_t rownr, uInt *dataPtr)
virtual void putfloat(rownr_t rownr, const float *dataPtr)
void * getArrayPtr(rownr_t rownr)
Get the pointer for the given row.
virtual Bool ok() const
Check if the class invariants still hold.
virtual void putuInt(rownr_t rownr, const uInt *dataPtr)
virtual void getuChar(rownr_t rownr, uChar *dataPtr)
virtual void putuChar(rownr_t rownr, const uChar *dataPtr)
void * allocData(rownr_t nrval, Bool byPtr)
Allocate an extension with the data type of the column.
virtual void getScalarColumnV(ArrayBase &data)
Get all scalar values in the column.
virtual void putInt64(rownr_t rownr, const Int64 *dataPtr)
virtual void getBool(rownr_t rownr, Bool *dataPtr)
Get a scalar value in the given row.
virtual void putShort(rownr_t rownr, const Short *dataPtr)
virtual void putInt(rownr_t rownr, const Int *dataPtr)
virtual void getfloat(rownr_t rownr, float *dataPtr)
virtual void doCreate(rownr_t nrrow)
Create the number of rows in a new table.
void removeData(void *datap, rownr_t inx, rownr_t nrvalAfter)
Remove an entry (i.e.
virtual void getFile(rownr_t nrval, AipsIO &)
Make it possible to read the column data.
virtual void reopenRW()
Reopen the storage manager files for read/write.
virtual void putScalarColumnV(const ArrayBase &data)
Put all scalar values in the column.
MSMBase * stmanPtr_p
Definition MSMColumn.h:193
uInt nrext_p
The nr of extensions in use.
Definition MSMColumn.h:199
void deleteData(void *datap, Bool byPtr)
Delete an extension.
rownr_t nralloc_p
The number of allocated rows in the column.
Definition MSMColumn.h:197
virtual void getString(rownr_t rownr, String *dataPtr)
virtual int dataType() const
Return the data type of the column.
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 char uChar
Definition aipstype.h:45
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
unsigned short uShort
Definition aipstype.h:47
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
int Int
Definition aipstype.h:48
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