casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: 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_SSMCOLUMN_H
29 #define TABLES_SSMCOLUMN_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
39 
40 namespace casacore { //# NAMESPACE CASACORE - BEGIN
41 
42 //# Forward declarations
43 
44 
45 // <summary>
46 // A Column in the Standard Storage Manager.
47 // </summary>
48 
49 // <use visibility=local>
50 
51 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tStandardStMan.cc">
52 // </reviewed>
53 
54 // <prerequisite>
55 //# Classes you should understand before using this one.
56 // <li> <linkto class=SSMBase>SSMBase</linkto>
57 // <li> <linkto class=SSMStringHandler>SSMStringHandler</linkto>
58 // </prerequisite>
59 
60 // <etymology>
61 // SSMColumn represents a Column in the Standard Storage Manager.
62 // </etymology>
63 
64 // <synopsis>
65 // SSMColumn is the base class for access to a column stored with
66 // the Standard Storage manager. It provides some basic functionality
67 // for the derived classes handling direct and indirect arrays.
68 // <p>
69 // The main task of SSMColumn is handling the access to a column
70 // containing scalars of the various data types. The data is stored
71 // in buckets. The classes <linkto class=SSMBase>SSMBase</linkto>
72 // and <linkto class=SSMIndex>SSMIndex</linkto> keep track in which data
73 // bucket a given row is stored and at which offset the column starts.
74 // Using that information SSMColumn can access its data easily.
75 // <p>
76 // Almost all data types have a fixed length and can be handled easily.
77 // However, strings are a special case.
78 // <br>If the string is fixed length (which means it has a maximum length),
79 // the string is stored directly in the data bucket. If the string is
80 // shorter than the maximum length, its length is indicated by a
81 // trailing 0.
82 // <br>Variable strings are in principle stored in a special string bucket.
83 // The data bucket contains 3 integers telling the bucketnr, offset, and
84 // length of the string. However, it the string is short enough (ie. <=
85 // 8 characters), the string is stored directly in data bucket using
86 // the space for bucketnr and offset.
87 // <p>
88 // The class maintains a cache of the data in the bucket last read.
89 // This cache is used by the higher level table classes to get faster
90 // read access to the data.
91 // The cache is not used for strings, because they are stored differently.
92 // </synopsis>
93 
94 //# <todo asof="$DATE:$">
95 //# A List of bugs, limitations, extensions or planned refinements.
96 //# </todo>
97 
98 
99 class SSMColumn : public StManColumn
100 {
101 public:
102  // Create a SSMColumn object with the given parent.
103  // It initializes the various variables.
104  // It keeps the pointer to its parent (but does not own it).
105  SSMColumn (SSMBase* aParent, int aDataType, uInt aColNr);
106 
107  virtual ~SSMColumn();
108 
109  // Set the shape of an array in the column.
110  // It is only called (right after the constructor) if the array has
111  // a fixed shape.
112  virtual void setShapeColumn (const IPosition& aShape);
113 
114  // Set the maximum length of a 'fixed length' string.
115  // It is only called (right after the constructor) if the string has
116  // a fixed length
117  virtual void setMaxLength (uInt maxLength);
118 
119  // Get the dimensionality of the item in the given row.
120  virtual uInt ndim (uInt aRowNr);
121 
122  // Get the shape of the array in the given row.
123  virtual IPosition shape (uInt aRowNr);
124 
125  // Let the object initialize itself for a newly created table.
126  // It is meant for a derived class.
127  virtual void doCreate (uInt aNrRows);
128 
129  // Let the column object initialize itself for an existing table
130  virtual void getFile (uInt aNrRows);
131 
132  // Resync the storage manager with the new file contents.
133  // It resets the last rownr put.
134  void resync (uInt aNrRow);
135 
136  // Get the scalar value in the given row.
137  // <group>
138  virtual void getBoolV (uInt aRowNr, Bool* aDataPtr);
139  virtual void getuCharV (uInt aRowNr, uChar* aDataPtr);
140  virtual void getShortV (uInt aRowNr, Short* aDataPtr);
141  virtual void getuShortV (uInt aRowNr, uShort* aDataPtr);
142  virtual void getIntV (uInt aRowNr, Int* aDataPtr);
143  virtual void getuIntV (uInt aRowNr, uInt* aDataPtr);
144  virtual void getInt64V (uInt aRowNr, Int64* aDataPtr);
145  virtual void getfloatV (uInt aRowNr, float* aDataPtr);
146  virtual void getdoubleV (uInt aRowNr, double* aDataPtr);
147  virtual void getComplexV (uInt aRowNr, Complex* aDataPtr);
148  virtual void getDComplexV (uInt aRowNr, DComplex* aDataPtr);
149  virtual void getStringV (uInt aRowNr, String* aDataPtr);
150  // </group>
151 
152  // Put the scalar value in the given row.
153  // It updates the cache if the row is contained in the cache.
154  // <group>
155  virtual void putBoolV (uInt aRowNr, const Bool* aDataPtr);
156  virtual void putuCharV (uInt aRowNr, const uChar* aDataPtr);
157  virtual void putShortV (uInt aRowNr, const Short* aDataPtr);
158  virtual void putuShortV (uInt aRowNr, const uShort* aDataPtr);
159  virtual void putIntV (uInt aRowNr, const Int* aDataPtr);
160  virtual void putuIntV (uInt aRowNr, const uInt* aDataPtr);
161  virtual void putInt64V (uInt aRowNr, const Int64* aDataPtr);
162  virtual void putfloatV (uInt aRowNr, const float* aDataPtr);
163  virtual void putdoubleV (uInt aRowNr, const double* aDataPtr);
164  virtual void putComplexV (uInt aRowNr, const Complex* aDataPtr);
165  virtual void putDComplexV (uInt aRowNr, const DComplex* aDataPtr);
166  virtual void putStringV (uInt aRowNr, const String* aDataPtr);
167  // </group>
168 
169  // Get the scalar values of the entire column.
170  // <group>
171  virtual void getScalarColumnBoolV (Vector<Bool>* aDataPtr);
172  virtual void getScalarColumnuCharV (Vector<uChar>* aDataPtr);
173  virtual void getScalarColumnShortV (Vector<Short>* aDataPtr);
174  virtual void getScalarColumnuShortV (Vector<uShort>* aDataPtr);
175  virtual void getScalarColumnIntV (Vector<Int>* aDataPtr);
176  virtual void getScalarColumnuIntV (Vector<uInt>* aDataPtr);
177  virtual void getScalarColumnInt64V (Vector<Int64>* aDataPtr);
178  virtual void getScalarColumnfloatV (Vector<float>* aDataPtr);
179  virtual void getScalarColumndoubleV (Vector<double>* aDataPtr);
180  virtual void getScalarColumnComplexV (Vector<Complex>* aDataPtr);
181  virtual void getScalarColumnDComplexV (Vector<DComplex>* aDataPtr);
182  virtual void getScalarColumnStringV (Vector<String>* aDataPtr);
183  // </group>
184 
185  // Put the scalar values of the entire column.
186  // It invalidates the cache.
187  // <group>
188  virtual void putScalarColumnBoolV (const Vector<Bool>* aDataPtr);
189  virtual void putScalarColumnuCharV (const Vector<uChar>* aDataPtr);
190  virtual void putScalarColumnShortV (const Vector<Short>* aDataPtr);
191  virtual void putScalarColumnuShortV (const Vector<uShort>* aDataPtr);
192  virtual void putScalarColumnIntV (const Vector<Int>* aDataPtr);
193  virtual void putScalarColumnuIntV (const Vector<uInt>* aDataPtr);
194  virtual void putScalarColumnInt64V (const Vector<Int64>* aDataPtr);
195  virtual void putScalarColumnfloatV (const Vector<float>* aDataPtr);
196  virtual void putScalarColumndoubleV (const Vector<double>* aDataPtr);
197  virtual void putScalarColumnComplexV (const Vector<Complex>* aDataPtr);
198  virtual void putScalarColumnDComplexV (const Vector<DComplex>* aDataPtr);
199  virtual void putScalarColumnStringV (const Vector<String>* aDataPtr);
200  // </group>
201 
202  // Add (NewNrRows-OldNrRows) rows to the Column and initialize
203  // the new rows when needed.
204  virtual void addRow (uInt aNewNrRows, uInt anOldNrRows, Bool doInit);
205 
206  // Remove the given row from the data bucket and possibly string bucket.
207  // If needed, it also removes it from the cache.
208  virtual void deleteRow (uInt aRowNr);
209 
210  // Get the size of the dataType in bytes!!
211  uInt getExternalSizeBytes() const;
212 
213  // Get the size of the dataType in bits!!
214  uInt getExternalSizeBits() const;
215 
216  // get the sequence number of this column.
217  uInt getColNr();
218 
219  // set the sequence number of this column.
220  void setColNr (uInt aColNr);
221 
222  // If something special has to be done before removing the Column,
223  // as is the case with Strings, it can be done here.
224  void removeColumn();
225 
226 protected:
227  // Shift the rows in the bucket one to the left when removing the given row.
228  void shiftRows (char* aValue, uInt rowNr, uInt startRow, uInt endRow);
229 
230  // Fill the cache with data of the bucket containing the given row.
231  void getValue (uInt aRowNr);
232 
233  // Get the bucketnr, offset, and length of a variable length string.
234  // <src>data</src> must have 3 Ints to hold the values.
235  // It returns a pointer to the data in the bucket, which can be used
236  // for the case that the data bucket contains the (short) string.
237  Char* getRowValue (Int* data, uInt aRowNr);
238 
239  // Put the given value for the row into the correct data bucket.
240  void putValue (uInt aRowNr, const void* aValue);
241 
242  // Put the given string for the row into the correct data bucket.
243  // The argument <src>aValue></src> must be 3 Ints (for bucketnr, offset,
244  // and length). Only the length is actually used.
245  void putValueShortString (uInt aRowNr, const void* aValue,
246  const String& string);
247 
248  // Get the values for the entire column.
249  // The data from all buckets is copied to the array.
250  void getColumnValue (void* anArray, uInt aNrRows);
251 
252  // Put the values from the array in the entire column.
253  // Each data bucket is filled with the the appropriate part of the array.
254  void putColumnValue (const void* anArray, uInt aNrRows);
255 
256 
257  // Pointer to the parent storage manager.
259  // Length of column cell value in storage format (0 = variable length).
262  // Column sequence number of this column.
264  // The shape of the column.
266  // The maximum length of a 'fixed length' string.
268  // Number of elements in a value for this column.
270  // Number of values to be copied.
271  // Normally this is itsNrElem, but for complex types it is 2*itsNrElem.
272  // When local format is used, it is the number of bytes.
274  // The sizeof the datatype in local format
276  // The data in local format.
277  void* itsData;
278  // Pointer to a convert function for writing.
280  // Pointer to a convert function for reading.
282 
283 private:
284  // Forbid copy constructor.
285  SSMColumn (const SSMColumn&);
286 
287  // Forbid assignment.
288  SSMColumn& operator= (const SSMColumn&);
289 
290  // Initialize part of the object.
291  // It determines the nr of elements, the function to use to convert
292  // from local to file format, etc..
293  void init();
294 
295  // Get the pointer to the cache. It is created if not done yet.
296  char* getDataPtr();
297 };
298 
299 
301 {
302  return itsExternalSizeBytes;
303 }
304 
306 {
307  return itsExternalSizeBits;
308 }
309 
310 inline char* SSMColumn::getDataPtr()
311 {
312  if (itsData == 0) {
314  }
315  return static_cast<char*>(itsData);
316 }
317 
319 {
320  return itsColNr;
321 }
322 
323 inline void SSMColumn::setColNr (uInt aColNr)
324 {
325  itsColNr = aColNr;
326 }
327 
328 
329 
330 } //# NAMESPACE CASACORE - END
331 
332 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
uInt itsLocalSize
The sizeof the datatype in local format.
Definition: SSMColumn.h:275
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
Char * getRowValue(Int *data, uInt aRowNr)
Get the bucketnr, offset, and length of a variable length string.
int Int
Definition: aipstype.h:50
virtual void putStringV(uInt aRowNr, const String *aDataPtr)
virtual void getIntV(uInt aRowNr, Int *aDataPtr)
virtual void getInt64V(uInt aRowNr, Int64 *aDataPtr)
uInt getExternalSizeBytes() const
Get the size of the dataType in bytes!!
Definition: SSMColumn.h:300
virtual void getScalarColumnStringV(Vector< String > *aDataPtr)
virtual void putScalarColumnStringV(const Vector< String > *aDataPtr)
virtual void putIntV(uInt aRowNr, const Int *aDataPtr)
void init()
Initialize part of the object.
unsigned char uChar
Definition: aipstype.h:47
virtual void addRow(uInt aNewNrRows, uInt anOldNrRows, Bool doInit)
Add (NewNrRows-OldNrRows) rows to the Column and initialize the new rows when needed.
virtual void getStringV(uInt aRowNr, String *aDataPtr)
virtual void getScalarColumnuShortV(Vector< uShort > *aDataPtr)
uInt getExternalSizeBits() const
Get the size of the dataType in bits!!
Definition: SSMColumn.h:305
char * getDataPtr()
Get the pointer to the cache.
Definition: SSMColumn.h:310
SSMColumn(SSMBase *aParent, int aDataType, uInt aColNr)
Create a SSMColumn object with the given parent.
void getValue(uInt aRowNr)
Fill the cache with data of the bucket containing the given row.
char Char
Definition: aipstype.h:46
virtual void getScalarColumnShortV(Vector< Short > *aDataPtr)
uInt itsNrElem
Number of elements in a value for this column.
Definition: SSMColumn.h:269
virtual void putdoubleV(uInt aRowNr, const double *aDataPtr)
void putColumnValue(const void *anArray, uInt 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:323
Base class of the Standard Storage Manager.
Definition: SSMBase.h:158
uInt itsMaxLen
The maximum length of a &#39;fixed length&#39; string.
Definition: SSMColumn.h:267
virtual void putDComplexV(uInt aRowNr, const DComplex *aDataPtr)
void putValueShortString(uInt aRowNr, const void *aValue, const String &string)
Put the given string for the row into the correct data bucket.
virtual void doCreate(uInt aNrRows)
Let the object initialize itself for a newly created table.
virtual void getScalarColumnComplexV(Vector< Complex > *aDataPtr)
virtual void setShapeColumn(const IPosition &aShape)
Set the shape of an array in the column.
virtual void getScalarColumnDComplexV(Vector< DComplex > *aDataPtr)
virtual uInt ndim(uInt aRowNr)
Get the dimensionality of the item in the given row.
void removeColumn()
If something special has to be done before removing the Column, as is the case with Strings...
virtual void getfloatV(uInt aRowNr, float *aDataPtr)
short Short
Definition: aipstype.h:48
virtual void getuShortV(uInt aRowNr, uShort *aDataPtr)
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
virtual void getFile(uInt aNrRows)
Let the column object initialize itself for an existing table.
virtual void getScalarColumnuIntV(Vector< uInt > *aDataPtr)
Conversion::ValueFunction * itsWriteFunc
Pointer to a convert function for writing.
Definition: SSMColumn.h:279
virtual void getScalarColumnuCharV(Vector< uChar > *aDataPtr)
virtual void getScalarColumnBoolV(Vector< Bool > *aDataPtr)
Get the scalar values of the entire column.
virtual void getScalarColumndoubleV(Vector< double > *aDataPtr)
virtual void putScalarColumnInt64V(const Vector< Int64 > *aDataPtr)
virtual void getuIntV(uInt aRowNr, uInt *aDataPtr)
virtual void putfloatV(uInt aRowNr, const float *aDataPtr)
virtual void getuCharV(uInt aRowNr, uChar *aDataPtr)
virtual IPosition shape(uInt aRowNr)
Get the shape of the array in the given row.
void putValue(uInt aRowNr, const void *aValue)
Put the given value for the row into the correct data bucket.
void shiftRows(char *aValue, uInt rowNr, uInt startRow, uInt endRow)
Shift the rows in the bucket one to the left when removing the given row.
uInt getColNr()
get the sequence number of this column.
Definition: SSMColumn.h:318
SSMColumn & operator=(const SSMColumn &)
Forbid assignment.
uInt itsNrCopy
Number of values to be copied.
Definition: SSMColumn.h:273
virtual void getShortV(uInt aRowNr, Short *aDataPtr)
virtual void getScalarColumnIntV(Vector< Int > *aDataPtr)
uInt itsColNr
Column sequence number of this column.
Definition: SSMColumn.h:263
virtual void putScalarColumnIntV(const Vector< Int > *aDataPtr)
virtual void setMaxLength(uInt maxLength)
Set the maximum length of a &#39;fixed length&#39; string.
virtual void putScalarColumnuCharV(const Vector< uChar > *aDataPtr)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual void putuCharV(uInt aRowNr, const uChar *aDataPtr)
virtual void putScalarColumnDComplexV(const Vector< DComplex > *aDataPtr)
virtual void putScalarColumnuIntV(const Vector< uInt > *aDataPtr)
virtual void putScalarColumnfloatV(const Vector< float > *aDataPtr)
A Column in the Standard Storage Manager.
Definition: SSMColumn.h:99
virtual void putScalarColumndoubleV(const Vector< double > *aDataPtr)
virtual void getBoolV(uInt aRowNr, Bool *aDataPtr)
Get the scalar value in the given row.
virtual void putScalarColumnuShortV(const Vector< uShort > *aDataPtr)
virtual void putuIntV(uInt aRowNr, const uInt *aDataPtr)
virtual void deleteRow(uInt aRowNr)
Remove the given row from the data bucket and possibly string bucket.
IPosition itsShape
The shape of the column.
Definition: SSMColumn.h:265
void * itsData
The data in local format.
Definition: SSMColumn.h:277
Conversion::ValueFunction * itsReadFunc
Pointer to a convert function for reading.
Definition: SSMColumn.h:281
virtual void putScalarColumnShortV(const Vector< Short > *aDataPtr)
virtual void getScalarColumnfloatV(Vector< float > *aDataPtr)
uInt itsExternalSizeBytes
Length of column cell value in storage format (0 = variable length).
Definition: SSMColumn.h:260
virtual void putBoolV(uInt aRowNr, const Bool *aDataPtr)
Put the scalar value in the given row.
virtual void putShortV(uInt aRowNr, const Short *aDataPtr)
void getColumnValue(void *anArray, uInt aNrRows)
Get the values for the entire column.
virtual void putInt64V(uInt aRowNr, const Int64 *aDataPtr)
uInt getRowsPerBucket(uInt aColumn) const
Get rows per bucket for the given column.
virtual void putScalarColumnComplexV(const Vector< Complex > *aDataPtr)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual void putComplexV(uInt aRowNr, const Complex *aDataPtr)
virtual void getdoubleV(uInt aRowNr, double *aDataPtr)
Base table column storage manager class.
Definition: StManColumn.h:102
virtual void putScalarColumnBoolV(const Vector< Bool > *aDataPtr)
Put the scalar values of the entire column.
virtual void getDComplexV(uInt aRowNr, DComplex *aDataPtr)
void resync(uInt aNrRow)
Resync the storage manager with the new file contents.
virtual void putuShortV(uInt aRowNr, const uShort *aDataPtr)
virtual void getScalarColumnInt64V(Vector< Int64 > *aDataPtr)
unsigned int uInt
Definition: aipstype.h:51
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:100
SSMBase * itsSSMPtr
Pointer to the parent storage manager.
Definition: SSMColumn.h:258
unsigned short uShort
Definition: aipstype.h:49
virtual void getComplexV(uInt aRowNr, Complex *aDataPtr)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42