casacore
Loading...
Searching...
No Matches
ISMColumn.h
Go to the documentation of this file.
1//# ISMColumn.h: A Column in the Incremental Storage Manager
2//# Copyright (C) 1996,1997,1998,1999,2002
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_ISMCOLUMN_H
27#define TABLES_ISMCOLUMN_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/DataMan/StManColumnBase.h>
33#include <casacore/tables/DataMan/ISMBase.h>
34#include <casacore/casa/Arrays/IPosition.h>
35#include <casacore/casa/Containers/Block.h>
36#include <casacore/casa/Utilities/Compare.h>
37#include <casacore/casa/OS/Conversion.h>
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41//# Forward declarations
42class ISMBucket;
43
44
45// <summary>
46// A Column in the Incremental Storage Manager.
47// </summary>
48
49// <use visibility=local>
50
51// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
52// </reviewed>
53
54// <prerequisite>
55//# Classes you should understand before using this one.
56// <li> <linkto class=ISMBase>ISMBase</linkto>
57// </prerequisite>
58
59// <etymology>
60// ISMColumn represents a Column in the Incremental Storage Manager.
61// </etymology>
62
63// <synopsis>
64// ISMColumn handles the access to a column containing scalars or direct
65// arrays of the various data types. It uses class <linkto class=ISMBucket>
66// ISMBucket</linkto> to get and put the data into the correct bucket.
67// When the value does not fit in the bucket, the bucket is split
68// and the new bucket is added to the storage manager.
69// <p>
70// The object maintains a variable indicating the last row ever put.
71// This is used to decide if a put of a value is valid until the
72// end of the table or for that one row only. In this way it does not
73// make any difference if rows are added before or after a value is put
74// <br>
75// A value put before or at the last row ever put will only affect that
76// one row. The rows before and after it keep their original value. If
77// needed that value is copied.
78// <p>
79// To optimize (especially sequential) access to the column, ISMColumn
80// maintains the last value gotten and the rows for which it is valid.
81// In this way a get does not need to access the data in the bucket.
82// <p>
83// ISMColumn use the static conversion functions in the
84// <linkto class=Conversion>Conversion</linkto> framework to
85// get/put the data in external format (be it canonical or local).
86// Most data types are fixed length, but some are variable length
87// (e.g. String). In external format variable length data is preceeded
88// by its total length (which includes the length itself). This makes
89// it possible to get the length of a data value without having to
90// interpret it, which is easy when (re)moving a value. For this reason
91// ISMColumn contains its own conversion functions for Strings.
92// <p>
93// ISMColumn also acts as the base class for more specialized ISM
94// column classes (i.e. <linkto class=ISMIndColumn>ISMIndColumn</linkto>
95// for indirect columns).
96// In this way <linkto class=ISMBase>ISMBase</linkto> can hold a
97// block of <src>ISMColumn*</src> for any column. Furthermore
98// <src>ISMColumn</src> contains the hooks to allow a derived class
99// to use other ISMColumn functions (e.g. there are "action" functions
100// for a derived class to react on the duplication or removal of
101// a data value (e.g. due to a bucket split).
102// </synopsis>
103
104// <motivation>
105// ISMColumn encapsulates all operations on an ISM Column.
106// </motivation>
107
108//# <todo asof="$DATE:$">
109//# A List of bugs, limitations, extensions or planned refinements.
110//# </todo>
111
112
114{
115public:
116 // Create a ISMColumn object with the given parent.
117 // It initializes the various variables.
118 // It keeps the pointer to its parent (but does not own it).
119 ISMColumn (ISMBase* parent, int dataType, uInt colnr);
120
122
123 // Forbid copy constructor.
124 ISMColumn (const ISMColumn&) = delete;
125
126 // Forbid assignment.
127 ISMColumn& operator= (const ISMColumn&) = delete;
128
129 // Set the shape of an array in the column.
130 virtual void setShapeColumn (const IPosition& shape);
131
132 // Get the dimensionality of the item in the given row.
133 // This is the same for all rows.
134 virtual uInt ndim (rownr_t rownr);
135
136 // Get the shape of the array in the given row.
137 // This is the same for all rows.
138 virtual IPosition shape (rownr_t rownr);
139
140 // Let the column object initialize itself for a newly created table.
141 // This is meant for a derived class.
142 virtual void doCreate (ISMBucket*);
143
144 // Let the column object initialize itself for an existing table.
145 virtual void getFile (rownr_t nrrow);
146
147 // Flush and optionally fsync the data.
148 // This is meant for a derived class.
149 virtual Bool flush (rownr_t nrrow, Bool fsync);
150
151 // Resync the storage manager with the new file contents.
152 // It resets the last rownr put.
153 void resync (rownr_t nrrow);
154
155 // Let the column reopen its data files for read/write access.
156 virtual void reopenRW();
157
158 // Get a scalar value in the given row.
159 // <group>
160 virtual void getBool (rownr_t rownr, Bool* dataPtr);
161 virtual void getuChar (rownr_t rownr, uChar* dataPtr);
162 virtual void getShort (rownr_t rownr, Short* dataPtr);
163 virtual void getuShort (rownr_t rownr, uShort* dataPtr);
164 virtual void getInt (rownr_t rownr, Int* dataPtr);
165 virtual void getuInt (rownr_t rownr, uInt* dataPtr);
166 virtual void getInt64 (rownr_t rownr, Int64* dataPtr);
167 virtual void getfloat (rownr_t rownr, float* dataPtr);
168 virtual void getdouble (rownr_t rownr, double* dataPtr);
169 virtual void getComplex (rownr_t rownr, Complex* dataPtr);
170 virtual void getDComplex (rownr_t rownr, DComplex* dataPtr);
171 virtual void getString (rownr_t rownr, String* dataPtr);
172 // </group>
173
174 // Put a scalar value in the given row.
175 // <group>
176 virtual void putBool (rownr_t rownr, const Bool* dataPtr);
177 virtual void putuChar (rownr_t rownr, const uChar* dataPtr);
178 virtual void putShort (rownr_t rownr, const Short* dataPtr);
179 virtual void putuShort (rownr_t rownr, const uShort* dataPtr);
180 virtual void putInt (rownr_t rownr, const Int* dataPtr);
181 virtual void putuInt (rownr_t rownr, const uInt* dataPtr);
182 virtual void putInt64 (rownr_t rownr, const Int64* dataPtr);
183 virtual void putfloat (rownr_t rownr, const float* dataPtr);
184 virtual void putdouble (rownr_t rownr, const double* dataPtr);
185 virtual void putComplex (rownr_t rownr, const Complex* dataPtr);
186 virtual void putDComplex (rownr_t rownr, const DComplex* dataPtr);
187 virtual void putString (rownr_t rownr, const String* dataPtr);
188 // </group>
189
190 // Get the scalar values in the entire column.
191 // The buffer pointed to by dataPtr has to have the correct length.
192 // (which is guaranteed by the ScalarColumn getColumn function).
193 virtual void getScalarColumnV (ArrayBase& dataPtr);
194
195 // Put the scalar values into the entire column.
196 // The buffer pointed to by dataPtr has to have the correct length.
197 // (which is guaranteed by the ScalarColumn putColumn function).
198 virtual void putScalarColumnV (const ArrayBase& dataPtr);
199
200 // Get the scalar values in some cells of the column.
201 // The buffer pointed to by dataPtr has to have the correct length.
202 // (which is guaranteed by the ScalarColumn getColumnCells function).
203 virtual void getScalarColumnCellsV (const RefRows& rownrs,
204 ArrayBase& dataPtr);
205
206 // Get an array value in the given row.
207 virtual void getArrayV (rownr_t rownr, ArrayBase& dataPtr);
208
209 // Put an array value in the given row.
210 virtual void putArrayV (rownr_t rownr, const ArrayBase& dataPtr);
211
212 // Add (newNrrow-oldNrrow) rows to the column and initialize
213 // the new rows when needed.
214 virtual void addRow (rownr_t newNrrow, rownr_t oldNrrow);
215
216 // Remove the given row in the bucket from the column.
217 void remove (rownr_t bucketRownr, ISMBucket* bucket, rownr_t bucketNrrow,
218 rownr_t newNrrow);
219
220 // Get the function needed to read/write a uInt and rownr from/to
221 // external format. This is used by other classes to read the length
222 // of a variable data value.
223 // <group>
228 // </group>
229
230 // Give a derived class the opportunity to react on the duplication
231 // of a value. It is used by ISMIndColumn.
232 virtual void handleCopy (rownr_t rownr, const char* value);
233
234 // Give a derived class the opportunity to react on the removal
235 // of a value. It is used by ISMIndColumn.
236 virtual void handleRemove (rownr_t rownr, const char* value);
237
238 // Get the fixed length of the data value in a cell of this column
239 // (0 = variable length).
240 uInt getFixedLength() const;
241
242 // Get the nr of elements in this data value.
243 uInt nelements() const;
244
245
246protected:
247 // Test if the last value is invalid for this row.
249
250 // Get the value for this row.
251 // Set the cache if the flag is set.
252 void getValue (rownr_t rownr, void* value, Bool setCache);
253
254 // Put the value for this row.
255 void putValue (rownr_t rownr, const void* value);
256
257 //# Declare member variables.
258 // Pointer to the parent storage manager.
260 // Length of column cell value in storage format (0 = variable length).
261 // If 0, the value is always preceeded by a uInt giving the length.
263 // Column sequence number of this column.
265 // The shape of the column.
267 // Number of elements in a value for this column.
269 // Number of values to be copied.
270 // Normally this is nrelem_p, but for complex types it is 2*nrelem_p.
271 // When local format is used, it is the number of bytes.
273 // Cache for interval for which last value read is valid.
274 // The last value is valid for startRow_p till endRow_p (inclusive).
278 // The last row for which a value has been put.
280 // The size of the data type in local format.
282 // Pointer to a convert function for writing.
284 // Pointer to a convert function for reading.
286 // Pointer to a compare function.
287 ObjCompareFunc* compareFunc_p;
288
289
290private:
291 // Initialize part of the object.
292 // It is used by doCreate and getFile.
293 void init();
294
295 // Clear the object (used by destructor and init).
296 void clear();
297
298 // Put the value in all buckets from the given row on.
299 void putFromRow (rownr_t rownr, const char* data, uInt lenData);
300
301 // Put a data value into the bucket.
302 // When it is at the first row of the bucket, it replaces the value.
303 // Otherwise it is added.
304 void putData (ISMBucket* bucket, rownr_t bucketStartRow,
305 rownr_t bucketNrrow, rownr_t bucketRownr,
306 const char* data, uInt lenData,
307 Bool afterLastRow, Bool canSplit);
308
309 // Replace a value at the given offset in the bucket.
310 // If the bucket is too small, it will be split (if allowed).
311 void replaceData (ISMBucket* bucket, rownr_t bucketStartRow,
312 rownr_t bucketNrrow, rownr_t bucketRownr, uInt& offset,
313 const char* data, uInt lenData, Bool canSplit = True);
314
315 // Add a value at the given index in the bucket.
316 // If the bucket is too small, it will be split (if allowed).
317 Bool addData (ISMBucket* bucket, rownr_t bucketStartRow,
318 rownr_t bucketNrrow, rownr_t bucketRownr, uInt inx,
319 const char* data, uInt lenData,
320 Bool afterLastRow = False, Bool canSplit = True);
321
322 // Handle the duplicated values after a bucket split.
323 void handleSplit (ISMBucket& bucket, const Block<Bool>& duplicated);
324
325 // Compare the values.
326 virtual Bool compareValue (const void* val1, const void* val2) const;
327
328 // Handle a String in copying to/from external format.
329 // <group>
330 static size_t fromString (void* out, const void* in, size_t n,
331 Conversion::ValueFunction* writeLeng);
332 static size_t toString (void* out, const void* in, size_t n,
333 Conversion::ValueFunction* readLeng);
334 static size_t writeStringBE (void* out, const void* in, size_t n);
335 static size_t readStringBE (void* out, const void* in, size_t n);
336 static size_t writeStringLE (void* out, const void* in, size_t n);
337 static size_t readStringLE (void* out, const void* in, size_t n);
338 // </group>
339
352
365
366 void putScaCol (const Vector<Bool>&);
370 void putScaCol (const Vector<Int>&);
371 void putScaCol (const Vector<uInt>&);
378};
379
380
382{
383 return rownr < startRow_p || rownr > endRow_p;
384}
385
387{
388 return fixedLength_p;
389}
390
392{
393 return nrelem_p;
394}
395
396
397
398} //# NAMESPACE CASACORE - END
399
400#endif
Non-templated base class for templated Array class.
Definition ArrayBase.h:71
simple 1-D array
Definition Block.h:198
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
virtual void putDComplex(rownr_t rownr, const DComplex *dataPtr)
ObjCompareFunc * compareFunc_p
Pointer to a compare function.
Definition ISMColumn.h:287
static size_t writeStringLE(void *out, const void *in, size_t n)
void resync(rownr_t nrrow)
Resync the storage manager with the new file contents.
void getScaCol(Vector< uInt > &)
IPosition shape_p
The shape of the column.
Definition ISMColumn.h:266
static Conversion::ValueFunction * getWriteRownr(Bool asCanonical)
virtual void getShort(rownr_t rownr, Short *dataPtr)
uInt getFixedLength() const
Get the fixed length of the data value in a cell of this column (0 = variable length).
Definition ISMColumn.h:386
void getScaCol(Vector< Short > &)
virtual Bool compareValue(const void *val1, const void *val2) const
Compare the values.
void getScaColCells(const RefRows &, Vector< uInt > &)
static size_t writeStringBE(void *out, const void *in, size_t n)
void getScaCol(Vector< uChar > &)
void getScaCol(Vector< Int > &)
void getScaCol(Vector< double > &)
void getScaColCells(const RefRows &, Vector< Complex > &)
virtual void putfloat(rownr_t rownr, const float *dataPtr)
virtual void putScalarColumnV(const ArrayBase &dataPtr)
Put the scalar values into the entire column.
void getScaCol(Vector< float > &)
void getScaCol(Vector< String > &)
void putScaCol(const Vector< Int > &)
void putValue(rownr_t rownr, const void *value)
Put the value for this row.
virtual void getArrayV(rownr_t rownr, ArrayBase &dataPtr)
Get an array value in the given row.
Conversion::ValueFunction * writeFunc_p
Pointer to a convert function for writing.
Definition ISMColumn.h:283
virtual void handleRemove(rownr_t rownr, const char *value)
Give a derived class the opportunity to react on the removal of a value.
ISMColumn(ISMBase *parent, int dataType, uInt colnr)
Create a ISMColumn object with the given parent.
virtual void putArrayV(rownr_t rownr, const ArrayBase &dataPtr)
Put an array value in the given row.
rownr_t lastRowPut_p
The last row for which a value has been put.
Definition ISMColumn.h:279
virtual void getScalarColumnCellsV(const RefRows &rownrs, ArrayBase &dataPtr)
Get the scalar values in some cells of the column.
void getScaColCells(const RefRows &, Vector< Short > &)
void replaceData(ISMBucket *bucket, rownr_t bucketStartRow, rownr_t bucketNrrow, rownr_t bucketRownr, uInt &offset, const char *data, uInt lenData, Bool canSplit=True)
Replace a value at the given offset in the bucket.
virtual void putBool(rownr_t rownr, const Bool *dataPtr)
Put a scalar value in the given row.
void putScaCol(const Vector< Int64 > &)
void getScaCol(Vector< uShort > &)
virtual Bool flush(rownr_t nrrow, Bool fsync)
Flush and optionally fsync the data.
virtual void getScalarColumnV(ArrayBase &dataPtr)
Get the scalar values in the entire column.
void getScaColCells(const RefRows &, Vector< double > &)
virtual void putuShort(rownr_t rownr, const uShort *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)
void putScaCol(const Vector< uShort > &)
void getScaCol(Vector< Int64 > &)
static Conversion::ValueFunction * getReaduInt(Bool asCanonical)
Get the function needed to read/write a uInt and rownr from/to external format.
uInt nrelem_p
Number of elements in a value for this column.
Definition ISMColumn.h:268
void putScaCol(const Vector< Bool > &)
void getScaColCells(const RefRows &, Vector< Bool > &)
void remove(rownr_t bucketRownr, ISMBucket *bucket, rownr_t bucketNrrow, rownr_t newNrrow)
Remove the given row in the bucket from the column.
void getScaCol(Vector< Complex > &)
void putScaCol(const Vector< DComplex > &)
void getScaColCells(const RefRows &, Vector< uChar > &)
virtual void getString(rownr_t rownr, String *dataPtr)
virtual void doCreate(ISMBucket *)
Let the column object initialize itself for a newly created table.
Bool addData(ISMBucket *bucket, rownr_t bucketStartRow, rownr_t bucketNrrow, rownr_t bucketRownr, uInt inx, const char *data, uInt lenData, Bool afterLastRow=False, Bool canSplit=True)
Add a value at the given index in the bucket.
static Conversion::ValueFunction * getReadRownr(Bool asCanonical)
static size_t fromString(void *out, const void *in, size_t n, Conversion::ValueFunction *writeLeng)
Handle a String in copying to/from external format.
virtual void getuShort(rownr_t rownr, uShort *dataPtr)
static size_t readStringLE(void *out, const void *in, size_t n)
uInt colnr_p
Column sequence number of this column.
Definition ISMColumn.h:264
virtual void getComplex(rownr_t rownr, Complex *dataPtr)
virtual void getdouble(rownr_t rownr, double *dataPtr)
void getScaColCells(const RefRows &, Vector< float > &)
void putData(ISMBucket *bucket, rownr_t bucketStartRow, rownr_t bucketNrrow, rownr_t bucketRownr, const char *data, uInt lenData, Bool afterLastRow, Bool canSplit)
Put a data value into the bucket.
virtual void getuChar(rownr_t rownr, uChar *dataPtr)
void handleSplit(ISMBucket &bucket, const Block< Bool > &duplicated)
Handle the duplicated values after a bucket split.
void getScaColCells(const RefRows &, Vector< String > &)
void putScaCol(const Vector< uChar > &)
void init()
Initialize part of the object.
void putScaCol(const Vector< float > &)
void putScaCol(const Vector< Short > &)
virtual void putInt(rownr_t rownr, const Int *dataPtr)
void getScaColCells(const RefRows &, Vector< DComplex > &)
void getScaColCells(const RefRows &, Vector< Int64 > &)
uInt nelements() const
Get the nr of elements in this data value.
Definition ISMColumn.h:391
void putScaCol(const Vector< String > &)
void clear()
Clear the object (used by destructor and init).
virtual IPosition shape(rownr_t rownr)
Get the shape of the array in the given row.
rownr_t startRow_p
Cache for interval for which last value read is valid.
Definition ISMColumn.h:275
virtual void getfloat(rownr_t rownr, float *dataPtr)
Conversion::ValueFunction * readFunc_p
Pointer to a convert function for reading.
Definition ISMColumn.h:285
void putScaCol(const Vector< double > &)
virtual void putString(rownr_t rownr, const String *dataPtr)
virtual void getFile(rownr_t nrrow)
Let the column object initialize itself for an existing table.
static size_t toString(void *out, const void *in, size_t n, Conversion::ValueFunction *readLeng)
Bool isLastValueInvalid(rownr_t rownr)
Test if the last value is invalid for this row.
Definition ISMColumn.h:381
ISMBase * stmanPtr_p
Pointer to the parent storage manager.
Definition ISMColumn.h:259
void getValue(rownr_t rownr, void *value, Bool setCache)
Get the value for this row.
virtual void getuInt(rownr_t rownr, uInt *dataPtr)
uInt fixedLength_p
Length of column cell value in storage format (0 = variable length).
Definition ISMColumn.h:262
virtual void setShapeColumn(const IPosition &shape)
Set the shape of an array in the column.
static Conversion::ValueFunction * getWriteuInt(Bool asCanonical)
virtual void getInt(rownr_t rownr, Int *dataPtr)
ISMColumn & operator=(const ISMColumn &)=delete
Forbid assignment.
virtual void putInt64(rownr_t rownr, const Int64 *dataPtr)
void getScaCol(Vector< DComplex > &)
virtual void putuChar(rownr_t rownr, const uChar *dataPtr)
virtual void reopenRW()
Let the column reopen its data files for read/write access.
void getScaColCells(const RefRows &, Vector< Int > &)
void putScaCol(const Vector< uInt > &)
void putFromRow(rownr_t rownr, const char *data, uInt lenData)
Put the value in all buckets from the given row on.
virtual void getInt64(rownr_t rownr, Int64 *dataPtr)
ISMColumn(const ISMColumn &)=delete
Forbid copy constructor.
virtual uInt ndim(rownr_t rownr)
Get the dimensionality of the item in the given row.
virtual void getDComplex(rownr_t rownr, DComplex *dataPtr)
virtual void addRow(rownr_t newNrrow, rownr_t oldNrrow)
Add (newNrrow-oldNrrow) rows to the column and initialize the new rows when needed.
static size_t readStringBE(void *out, const void *in, size_t n)
void getScaColCells(const RefRows &, Vector< uShort > &)
void getScaCol(Vector< Bool > &)
uInt typeSize_p
The size of the data type in local format.
Definition ISMColumn.h:281
uInt nrcopy_p
Number of values to be copied.
Definition ISMColumn.h:272
virtual void putdouble(rownr_t rownr, const double *dataPtr)
virtual void putuInt(rownr_t rownr, const uInt *dataPtr)
void putScaCol(const Vector< Complex > &)
virtual void handleCopy(rownr_t rownr, const char *value)
Give a derived class the opportunity to react on the duplication of a value.
virtual void putComplex(rownr_t rownr, const Complex *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
const Bool False
Definition aipstype.h:42
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
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
const Bool True
Definition aipstype.h:41
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44