casacore
Loading...
Searching...
No Matches
SSMColumn.h
Go to the documentation of this file.
1//# SSMColumn.h: A Column in the Standard Storage Manager
2//# Copyright (C) 2000
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_SSMCOLUMN_H
27#define TABLES_SSMCOLUMN_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/DataMan/StManColumnBase.h>
33#include <casacore/tables/DataMan/SSMBase.h>
34#include <casacore/casa/Arrays/IPosition.h>
35#include <casacore/casa/Containers/Block.h>
36#include <casacore/casa/OS/Conversion.h>
37
38namespace casacore { //# NAMESPACE CASACORE - BEGIN
39
40//# Forward declarations
41
42
43// <summary>
44// A Column in the Standard Storage Manager.
45// </summary>
46
47// <use visibility=local>
48
49// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tStandardStMan.cc">
50// </reviewed>
51
52// <prerequisite>
53//# Classes you should understand before using this one.
54// <li> <linkto class=SSMBase>SSMBase</linkto>
55// <li> <linkto class=SSMStringHandler>SSMStringHandler</linkto>
56// </prerequisite>
57
58// <etymology>
59// SSMColumn represents a Column in the Standard Storage Manager.
60// </etymology>
61
62// <synopsis>
63// SSMColumn is the base class for access to a column stored with
64// the Standard Storage manager. It provides some basic functionality
65// for the derived classes handling direct and indirect arrays.
66// <p>
67// The main task of SSMColumn is handling the access to a column
68// containing scalars of the various data types. The data is stored
69// in buckets. The classes <linkto class=SSMBase>SSMBase</linkto>
70// and <linkto class=SSMIndex>SSMIndex</linkto> keep track in which data
71// bucket a given row is stored and at which offset the column starts.
72// Using that information SSMColumn can access its data easily.
73// <p>
74// Almost all data types have a fixed length and can be handled easily.
75// However, strings are a special case.
76// <br>If the string is fixed length (which means it has a maximum length),
77// the string is stored directly in the data bucket. If the string is
78// shorter than the maximum length, its length is indicated by a
79// trailing 0.
80// <br>Variable strings are in principle stored in a special string bucket.
81// The data bucket contains 3 integers telling the bucketnr, offset, and
82// length of the string. However, it the string is short enough (ie. <=
83// 8 characters), the string is stored directly in data bucket using
84// the space for bucketnr and offset.
85// <p>
86// The class maintains a cache of the data in the bucket last read.
87// This cache is used by the higher level table classes to get faster
88// read access to the data.
89// The cache is not used for strings, because they are stored differently.
90// </synopsis>
91
92//# <todo asof="$DATE:$">
93//# A List of bugs, limitations, extensions or planned refinements.
94//# </todo>
95
96
98{
99public:
100 // Create a SSMColumn object with the given parent.
101 // It initializes the various variables.
102 // It keeps the pointer to its parent (but does not own it).
103 SSMColumn (SSMBase* aParent, int aDataType, uInt aColNr);
104
105 virtual ~SSMColumn();
106
107 // Forbid copy constructor.
108 SSMColumn (const SSMColumn&) = delete;
109
110 // Forbid assignment.
111 SSMColumn& operator= (const SSMColumn&) = delete;
112
113 // Set the shape of an array in the column.
114 // It is only called (right after the constructor) if the array has
115 // a fixed shape.
116 virtual void setShapeColumn (const IPosition& aShape);
117
118 // Set the maximum length of a 'fixed length' string.
119 // It is only called (right after the constructor) if the string has
120 // a fixed length.
121 virtual void setMaxLength (uInt maxLength);
122
123 // Get the dimensionality of the item in the given row.
124 virtual uInt ndim (rownr_t aRowNr);
125
126 // Get the shape of the array in the given row.
127 virtual IPosition shape (rownr_t aRowNr);
128
129 // Let the object initialize itself for a newly created table.
130 // It is meant for a derived class.
131 virtual void doCreate (rownr_t aNrRows);
132
133 // Let the column object initialize itself for an existing table
134 virtual void getFile (rownr_t aNrRows);
135
136 // Resync the storage manager with the new file contents.
137 // It resets the last rownr put.
138 void resync (rownr_t aNrRow);
139
140 // Get the scalar value in the given row.
141 // <group>
142 virtual void getBool (rownr_t aRowNr, Bool* aDataPtr);
143 virtual void getuChar (rownr_t aRowNr, uChar* aDataPtr);
144 virtual void getShort (rownr_t aRowNr, Short* aDataPtr);
145 virtual void getuShort (rownr_t aRowNr, uShort* aDataPtr);
146 virtual void getInt (rownr_t aRowNr, Int* aDataPtr);
147 virtual void getuInt (rownr_t aRowNr, uInt* aDataPtr);
148 virtual void getInt64 (rownr_t aRowNr, Int64* aDataPtr);
149 virtual void getfloat (rownr_t aRowNr, float* aDataPtr);
150 virtual void getdouble (rownr_t aRowNr, double* aDataPtr);
151 virtual void getComplex (rownr_t aRowNr, Complex* aDataPtr);
152 virtual void getDComplex (rownr_t aRowNr, DComplex* aDataPtr);
153 virtual void getString (rownr_t aRowNr, String* aDataPtr);
154 // </group>
155
156 // Put the scalar value in the given row.
157 // It updates the cache if the row is contained in the cache.
158 // <group>
159 virtual void putBool (rownr_t aRowNr, const Bool* aDataPtr);
160 virtual void putuChar (rownr_t aRowNr, const uChar* aDataPtr);
161 virtual void putShort (rownr_t aRowNr, const Short* aDataPtr);
162 virtual void putuShort (rownr_t aRowNr, const uShort* aDataPtr);
163 virtual void putInt (rownr_t aRowNr, const Int* aDataPtr);
164 virtual void putuInt (rownr_t aRowNr, const uInt* aDataPtr);
165 virtual void putInt64 (rownr_t aRowNr, const Int64* aDataPtr);
166 virtual void putfloat (rownr_t aRowNr, const float* aDataPtr);
167 virtual void putdouble (rownr_t aRowNr, const double* aDataPtr);
168 virtual void putComplex (rownr_t aRowNr, const Complex* aDataPtr);
169 virtual void putDComplex (rownr_t aRowNr, const DComplex* aDataPtr);
170 virtual void putString (rownr_t aRowNr, const String* aDataPtr);
171 // </group>
172
173 // Get the scalar values of the entire column.
174 virtual void getScalarColumnV (ArrayBase& aDataPtr);
175
176 // Put the scalar values of the entire column.
177 // It invalidates the cache.
178 virtual void putScalarColumnV (const ArrayBase& aDataPtr);
179
180 // Add (NewNrRows-OldNrRows) rows to the Column and initialize
181 // the new rows when needed.
182 virtual void addRow (rownr_t aNewNrRows, rownr_t anOldNrRows, Bool doInit);
183
184 // Remove the given row from the data bucket and possibly string bucket.
185 // If needed, it also removes it from the cache.
186 virtual void deleteRow (rownr_t aRowNr);
187
188 // Get the size of the dataType in bytes!!
190
191 // Get the size of the dataType in bits!!
193
194 // get the sequence number of this column.
195 uInt getColNr();
196
197 // set the sequence number of this column.
198 void setColNr (uInt aColNr);
199
200 // If something special has to be done before removing the Column,
201 // as is the case with Strings, it can be done here.
203
204protected:
205 // Shift the rows in the bucket one to the left when removing the given row.
206 void shiftRows (char* aValue, rownr_t rowNr, rownr_t startRow, rownr_t endRow);
207
208 // Fill the cache with data of the bucket containing the given row.
209 void getValue (rownr_t aRowNr);
210
211 // Get the bucketnr, offset, and length of a variable length string.
212 // <src>data</src> must have 3 Ints to hold the values.
213 // It returns a pointer to the data in the bucket, which can be used
214 // for the case that the data bucket contains the (short) string.
215 Char* getRowValue (Int* data, rownr_t aRowNr);
216
217 // Put the given value for the row into the correct data bucket.
218 void putValue (rownr_t aRowNr, const void* aValue);
219
220 // Put the given string for the row into the correct data bucket.
221 // The argument <src>aValue></src> must be 3 Ints (for bucketnr, offset,
222 // and length). Only the length is actually used.
223 void putValueShortString (rownr_t aRowNr, const void* aValue,
224 const String& string);
225
226 // Get the values for the entire column.
227 // The data from all buckets is copied to the array.
228 void getColumnValue (void* anArray, rownr_t aNrRows);
229
230 // Put the values from the array in the entire column.
231 // Each data bucket is filled with the the appropriate part of the array.
232 void putColumnValue (const void* anArray, rownr_t aNrRows);
233
234
235 // Pointer to the parent storage manager.
237 // Length of column cell value in storage format (0 = variable length).
240 // Column sequence number of this column.
242 // The shape of the column.
244 // The maximum length of a 'fixed length' string.
246 // Number of elements in a value for this column.
248 // Number of values to be copied.
249 // Normally this is itsNrElem, but for complex types it is 2*itsNrElem.
250 // When local format is used, it is the number of bytes.
252 // The sizeof the datatype in local format
254 // The data in local format.
255 void* itsData;
256 // Pointer to a convert function for writing.
258 // Pointer to a convert function for reading.
260
261private:
262 // Initialize part of the object.
263 // It determines the nr of elements, the function to use to convert
264 // from local to file format, etc..
265 void init();
266
267 // Get the pointer to the cache. It is created if not done yet.
268 char* getDataPtr();
269};
270
271
273{
275}
276
278{
279 return itsExternalSizeBits;
280}
281
283{
284 if (itsData == 0) {
286 }
287 return static_cast<char*>(itsData);
288}
289
291{
292 return itsColNr;
293}
294
295inline void SSMColumn::setColNr (uInt aColNr)
296{
297 itsColNr = aColNr;
298}
299
300
301
302} //# NAMESPACE CASACORE - END
303
304#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
size_t ValueFunction(void *to, const void *from, size_t nvalues)
Define the signature of a function converting nvalues values from internal to external format or vice...
Definition Conversion.h:98
uInt getRowsPerBucket(uInt aColumn) const
Get rows per bucket for the given column.
uInt itsLocalSize
The sizeof the datatype in local format.
Definition SSMColumn.h:253
uInt getExternalSizeBytes() const
Get the size of the dataType in bytes!!
Definition SSMColumn.h:272
uInt itsExternalSizeBytes
Length of column cell value in storage format (0 = variable length).
Definition SSMColumn.h:238
virtual uInt ndim(rownr_t aRowNr)
Get the dimensionality of the item in the given row.
uInt itsNrCopy
Number of values to be copied.
Definition SSMColumn.h:251
SSMBase * itsSSMPtr
Pointer to the parent storage manager.
Definition SSMColumn.h:236
virtual void getShort(rownr_t aRowNr, Short *aDataPtr)
virtual void putInt64(rownr_t aRowNr, const Int64 *aDataPtr)
Char * getRowValue(Int *data, rownr_t aRowNr)
Get the bucketnr, offset, and length of a variable length string.
virtual void deleteRow(rownr_t aRowNr)
Remove the given row from the data bucket and possibly string bucket.
virtual void getFile(rownr_t aNrRows)
Let the column object initialize itself for an existing table.
void removeColumn()
If something special has to be done before removing the Column, as is the case with Strings,...
SSMColumn(SSMBase *aParent, int aDataType, uInt aColNr)
Create a SSMColumn object with the given parent.
virtual void putScalarColumnV(const ArrayBase &aDataPtr)
Put the scalar values of the entire column.
virtual void putdouble(rownr_t aRowNr, const double *aDataPtr)
char * getDataPtr()
Get the pointer to the cache.
Definition SSMColumn.h:282
virtual void putDComplex(rownr_t aRowNr, const DComplex *aDataPtr)
uInt itsColNr
Column sequence number of this column.
Definition SSMColumn.h:241
void init()
Initialize part of the object.
virtual void putBool(rownr_t aRowNr, const Bool *aDataPtr)
Put the scalar value in the given row.
virtual void getBool(rownr_t aRowNr, Bool *aDataPtr)
Get the scalar value in the given row.
uInt getColNr()
get the sequence number of this column.
Definition SSMColumn.h:290
virtual void putInt(rownr_t aRowNr, const Int *aDataPtr)
virtual void getDComplex(rownr_t aRowNr, DComplex *aDataPtr)
virtual void setMaxLength(uInt maxLength)
Set the maximum length of a 'fixed length' string.
void * itsData
The data in local format.
Definition SSMColumn.h:255
virtual void setShapeColumn(const IPosition &aShape)
Set the shape of an array in the column.
void putValue(rownr_t aRowNr, const void *aValue)
Put the given value for the row into the correct data bucket.
virtual void putfloat(rownr_t aRowNr, const float *aDataPtr)
virtual void putuShort(rownr_t aRowNr, const uShort *aDataPtr)
void getValue(rownr_t aRowNr)
Fill the cache with data of the bucket containing the given row.
SSMColumn & operator=(const SSMColumn &)=delete
Forbid assignment.
virtual void getInt64(rownr_t aRowNr, Int64 *aDataPtr)
virtual void getuInt(rownr_t aRowNr, uInt *aDataPtr)
uInt itsMaxLen
The maximum length of a 'fixed length' string.
Definition SSMColumn.h:245
Conversion::ValueFunction * itsWriteFunc
Pointer to a convert function for writing.
Definition SSMColumn.h:257
virtual void putString(rownr_t aRowNr, const String *aDataPtr)
IPosition itsShape
The shape of the column.
Definition SSMColumn.h:243
void shiftRows(char *aValue, rownr_t rowNr, rownr_t startRow, rownr_t endRow)
Shift the rows in the bucket one to the left when removing the given row.
SSMColumn(const SSMColumn &)=delete
Forbid copy constructor.
uInt itsNrElem
Number of elements in a value for this column.
Definition SSMColumn.h:247
virtual void putComplex(rownr_t aRowNr, const Complex *aDataPtr)
virtual void getComplex(rownr_t aRowNr, Complex *aDataPtr)
virtual void getInt(rownr_t aRowNr, Int *aDataPtr)
void putValueShortString(rownr_t aRowNr, const void *aValue, const String &string)
Put the given string for the row into the correct data bucket.
Conversion::ValueFunction * itsReadFunc
Pointer to a convert function for reading.
Definition SSMColumn.h:259
virtual void getString(rownr_t aRowNr, String *aDataPtr)
virtual void putuInt(rownr_t aRowNr, const uInt *aDataPtr)
virtual void getdouble(rownr_t aRowNr, double *aDataPtr)
virtual void getfloat(rownr_t aRowNr, float *aDataPtr)
virtual void getuShort(rownr_t aRowNr, uShort *aDataPtr)
virtual void addRow(rownr_t aNewNrRows, rownr_t anOldNrRows, Bool doInit)
Add (NewNrRows-OldNrRows) rows to the Column and initialize the new rows when needed.
virtual void getuChar(rownr_t aRowNr, uChar *aDataPtr)
void resync(rownr_t aNrRow)
Resync the storage manager with the new file contents.
virtual void putShort(rownr_t aRowNr, const Short *aDataPtr)
virtual void getScalarColumnV(ArrayBase &aDataPtr)
Get the scalar values of the entire column.
virtual void putuChar(rownr_t aRowNr, const uChar *aDataPtr)
virtual void doCreate(rownr_t aNrRows)
Let the object initialize itself for a newly created table.
void putColumnValue(const void *anArray, rownr_t aNrRows)
Put the values from the array in the entire column.
void setColNr(uInt aColNr)
set the sequence number of this column.
Definition SSMColumn.h:295
virtual IPosition shape(rownr_t aRowNr)
Get the shape of the array in the given row.
void getColumnValue(void *anArray, rownr_t aNrRows)
Get the values for the entire column.
uInt getExternalSizeBits() const
Get the size of the dataType in bits!!
Definition SSMColumn.h:277
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
char Char
Definition aipstype.h:44