File: SSMColumn.cc

package info (click to toggle)
casacore 3.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 51,680 kB
  • sloc: cpp: 462,815; fortran: 16,372; ansic: 7,403; yacc: 4,626; lex: 2,340; sh: 1,786; python: 629; perl: 531; sed: 499; csh: 34; makefile: 31
file content (634 lines) | stat: -rw-r--r-- 19,004 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
//# SSMColumn.cc: The Column of the Standard Storage Manager
//# Copyright (C) 2000,2001,2002
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//#        Internet email: aips2-request@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA
//#
//# $Id$

#include <casacore/tables/DataMan/SSMColumn.h>
#include <casacore/tables/DataMan/SSMBase.h>
#include <casacore/tables/DataMan/SSMStringHandler.h>
#include <casacore/tables/Tables/RefRows.h>
#include <casacore/casa/Arrays/Array.h>
#include <casacore/casa/Arrays/Vector.h>
#include <casacore/casa/Utilities/ValType.h>
#include <casacore/casa/Utilities/Assert.h>
#include <casacore/casa/Utilities/Copy.h>
#include <casacore/casa/BasicMath/Math.h>
#include <casacore/casa/OS/CanonicalConversion.h>
#include <casacore/casa/OS/LECanonicalConversion.h>


namespace casacore { //# NAMESPACE CASACORE - BEGIN

SSMColumn::SSMColumn (SSMBase* aParent, int aDataType, uInt aColNr)
: StManColumnBase(aDataType),
  itsSSMPtr      (aParent),
  itsExternalSizeBytes(0),
  itsExternalSizeBits (0),
  itsColNr       (aColNr),
  itsMaxLen      (0),
  itsNrElem      (1),
  itsNrCopy      (0),
  itsData        (0)
{
  init();
}

SSMColumn::~SSMColumn()
{
  delete [] static_cast<char*>(itsData);
}

void SSMColumn::setShapeColumn (const IPosition& aShape)
{
    itsNrElem = aShape.product();
    itsShape  = aShape;
    init();
}

void SSMColumn::setMaxLength (uInt maxLength)
{
    itsMaxLen = maxLength;
    init();
}

uInt SSMColumn::ndim (rownr_t)
{
    return itsShape.nelements();
}

IPosition SSMColumn::shape (rownr_t)
{
    return itsShape;
}

void SSMColumn::doCreate(rownr_t)
{
}

void SSMColumn::getFile(rownr_t)
{
}

void SSMColumn::addRow (rownr_t aNewNrRows, rownr_t, Bool doInit)
{
  if (doInit  &&  dataType() == TpString) {
    rownr_t aRowNr=0;
    rownr_t aNrRows=aNewNrRows;
    
    while (aNrRows > 0) {
      rownr_t aStartRow;
      rownr_t anEndRow;
      char*   aValPtr;
      aValPtr = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                                 columnName());
      aRowNr = anEndRow+1;
      rownr_t aNr = anEndRow-aStartRow+1;
      aNrRows -= aNr;
      memset(aValPtr, 0, aNr * itsExternalSizeBytes);
      itsSSMPtr->setBucketDirty();
    }
  }
}

void SSMColumn::deleteRow(rownr_t aRowNr)
{
  char*   aValue;
  rownr_t aSRow;
  rownr_t anERow;
  int aDT = dataType();

  if (aDT == TpString  &&  itsMaxLen == 0) {
    Int buf[3];
    getRowValue(buf, aRowNr);
    if (buf[2] > 8 ) {
      itsSSMPtr->getStringHandler()->remove(buf[0], buf[1], buf[2]);
      aValue = itsSSMPtr->find (aRowNr, itsColNr, aSRow, anERow,
                                columnName());
      shiftRows(aValue,aRowNr,aSRow,anERow);
      itsSSMPtr->setBucketDirty();
      return;
    }
  }

  aValue = itsSSMPtr->find (aRowNr, itsColNr, aSRow, anERow, columnName());

  // For bools be sure that cache is actual
  Bool isBool = (aDT == TpBool);

  if (isBool  && aRowNr < anERow) {
    Bool aVal;
    getBool(aRowNr,&aVal);
  }

  // first check if aRowNr is in cache, if not, fill cache
  // In both cases remove row from cache
  rownr_t aStartRow = columnCache().start();
  rownr_t anEndRow  = columnCache().end();

  // Remove from cache if needed
  if (aRowNr >= aStartRow  &&  aRowNr <= anEndRow) {
    //  remove the row in itsData if not last
    if (aRowNr < anEndRow) {
      char* aToPtr   = getDataPtr() + (aRowNr-aStartRow) * itsLocalSize;
      char* aFromPtr = getDataPtr() + (aRowNr+1-aStartRow) * itsLocalSize;

      // decrement anEndrow
      uInt64 aLength = (anEndRow - aRowNr) * itsLocalSize;
      memmove(aToPtr,aFromPtr,aLength);
    }
    // Fill cache again with actual itsData.
    if (aStartRow == anEndRow) {
      columnCache().invalidate();
    } else {
      columnCache().set (aStartRow, anEndRow-1, getDataPtr());
    }
  }
  
  if (aRowNr < anERow) {
    // remove from bucket

    // first check if type is a bool
    if (isBool) {
      itsWriteFunc (aValue,itsData, (anERow-aSRow) * itsNrCopy);
    } else {
      shiftRows(aValue,aRowNr,aSRow,anERow);
    }
    itsSSMPtr->setBucketDirty();
  }
}

void SSMColumn::shiftRows(char* aValue, rownr_t aRowNr,
                          rownr_t aSRow, rownr_t anERow)
{
  // Shift from aRrowNr on 1 to the left.
  char* aToPtr = aValue + (aRowNr-aSRow) * itsExternalSizeBytes;
  char* aFromPtr = aToPtr + itsExternalSizeBytes;
  uInt64 aLength = (anERow - aRowNr) * itsExternalSizeBytes;
  memmove(aToPtr,aFromPtr,aLength);
  // Clear last entry (so a putString on a new row finds zeroes).
  memset (aToPtr + aLength, 0, itsExternalSizeBytes);
}


void SSMColumn::getBool (rownr_t aRowNr, Bool* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<Bool*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getuChar (rownr_t aRowNr, uChar* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<uChar*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getShort (rownr_t aRowNr, Short* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<Short*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getuShort (rownr_t aRowNr, uShort* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<uShort*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getInt (rownr_t aRowNr, Int* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<Int*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getuInt (rownr_t aRowNr, uInt* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<uInt*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getInt64 (rownr_t aRowNr, Int64* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<Int64*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getfloat (rownr_t aRowNr, float* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<float*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getdouble (rownr_t aRowNr, double* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<double*>(itsData)[aRowNr-columnCache().start()];
}
void SSMColumn::getComplex (rownr_t aRowNr, Complex* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<Complex*>(itsData)[aRowNr-columnCache().start()];
}

void SSMColumn::getDComplex (rownr_t aRowNr,DComplex* aValue)
{
  getValue(aRowNr);
  *aValue = static_cast<DComplex*>(itsData)[aRowNr-columnCache().start()];
}

void SSMColumn::getString (rownr_t aRowNr, String* aValue)
{
  if (itsMaxLen > 0) {
    // Allocate the maximum number of characters needed
    // The +1 is to correct for the incorrect use of the chars() function
    // Should be changed to use real Char*
    aValue->alloc(itsMaxLen+1);
    char* sp = const_cast<char*>(aValue->chars());
    rownr_t aStartRow;
    rownr_t anEndRow;
    char* buf = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                                 columnName());
    itsReadFunc (sp, buf+(aRowNr-aStartRow)*itsExternalSizeBytes,
		 itsNrCopy);
    // Append a trailing zero (in case needed).
    // Note that if shorter, the string already contains a trailing zero.
    // Set the string to its actual length.
    sp[itsMaxLen] = '\0';
    uInt len = 0;
    while (*sp++ != '\0') {
      len++;
    }
    aValue->alloc(len);
  } else {

    // The string is probably stored indirectly in a string bucket.
    // Get bucketnr, offset, and length.
    Int buf[3];
    char* strbuf = getRowValue(buf, aRowNr);

    // if length <= 8 chars the string can be found in de data bucket
    // instead of the string bucket.

    if (buf[2] <= 8) {
      aValue->resize (buf[2]);       // resize storage which adds trailing 0
      char* sp = &((*aValue)[0]);    // get actual string
      memcpy (sp, strbuf, buf[2]);
#ifdef USE_OLD_STRING
      sp[buf[2]] = '\0';
#endif
    } else {
      itsSSMPtr->getStringHandler()->get(*aValue, buf[0], buf[1], buf[2]);
    }
  }
}

Char* SSMColumn::getRowValue(Int* data, rownr_t aRowNr)
{
  rownr_t aStartRow;
  rownr_t anEndRow;
  char*   aValue;
  aValue = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                            columnName());
  itsReadFunc (data, aValue+(aRowNr-aStartRow)*itsExternalSizeBytes,
	       itsNrCopy);
  return aValue+(aRowNr-aStartRow)*itsExternalSizeBytes;
}

void SSMColumn::getValue(rownr_t aRowNr)
{
  if (aRowNr < columnCache().start()  ||  aRowNr > columnCache().end()) {
    rownr_t aStartRow;
    rownr_t anEndRow;
    char*   aValue;
    aValue = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                              columnName());
    itsReadFunc (getDataPtr(), aValue, (anEndRow-aStartRow+1) * itsNrCopy);
    columnCache().set (aStartRow, anEndRow, getDataPtr());
  }
}

void SSMColumn::putBool (rownr_t aRowNr, const Bool* aValue)
{
  rownr_t aStartRow;
  rownr_t anEndRow;
  char*   aDummy;

  aDummy = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                            columnName());

  uInt64 anOff    = aRowNr-aStartRow;

  Conversion::boolToBit(aDummy+(anOff/8),
			aValue,anOff%8,1);
  itsSSMPtr->setBucketDirty();

  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    getDataPtr()[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putuChar (rownr_t aRowNr, const uChar* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<uChar*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putShort (rownr_t aRowNr, const Short* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<Short*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putuShort (rownr_t aRowNr, const uShort* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<uShort*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putInt (rownr_t aRowNr, const Int* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<Int*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putuInt (rownr_t aRowNr, const uInt* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<uInt*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putInt64 (rownr_t aRowNr, const Int64* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<Int64*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putfloat (rownr_t aRowNr, const float* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<float*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putdouble (rownr_t aRowNr, const double* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<double*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}
void SSMColumn::putComplex (rownr_t aRowNr, const Complex* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<Complex*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}

void SSMColumn::putDComplex (rownr_t aRowNr, const DComplex* aValue)
{
  putValue(aRowNr,aValue);
  if (aRowNr >= columnCache().start()  &&  aRowNr <= columnCache().end()) {
    static_cast<DComplex*>(itsData)[aRowNr-columnCache().start()] = 
      *aValue;
  }
}

void SSMColumn::putString (rownr_t aRowNr, const String* aValue)
{
  // Fixed length strings are written directly.
  if (itsMaxLen > 0) {
    rownr_t aStartRow;
    rownr_t anEndRow;
    char*   aDummy = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                                      columnName());
    itsWriteFunc (aDummy+(aRowNr-aStartRow)*itsExternalSizeBytes,
		  aValue->chars(), min(itsMaxLen, aValue->length()+1));
    itsSSMPtr->setBucketDirty();
  } else { 

    Int buf[3];
    // Try to find out if this value was filled before, in that case we use
    // an overwrite.
    getRowValue(buf, aRowNr);

    // if String <= 8 chars it is written into the data bucket
    // instead of the string bucket.
    if (aValue->length() <= 8) {
      // if string was written before, but longer then 8 chars it has to 
      // be removed from the stringbucket
      if (buf[2] > 8 ) {
	itsSSMPtr->getStringHandler()->remove(buf[0], buf[1], buf[2]);
      }
      buf[2] = aValue->length();
      putValueShortString (aRowNr, buf, *aValue);
    } else {
      // Maybe it was there earlier, but smaller.
      if (buf[2] <= 8) {
	buf[0] = 0;
	buf[1] = 0;
	buf[2] = 0;
      }
      itsSSMPtr->getStringHandler()->put (buf[0], buf[1], buf[2], *aValue);
      putValue (aRowNr, buf);
    }
  }
}

void SSMColumn::putValue(rownr_t aRowNr, const void* aValue)
{
  rownr_t aStartRow;
  rownr_t anEndRow;
  char*   aDummy = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                                    columnName());
  itsWriteFunc (aDummy+(aRowNr-aStartRow)*itsExternalSizeBytes,
  		aValue, itsNrCopy);
  itsSSMPtr->setBucketDirty();
}

void SSMColumn::putValueShortString(rownr_t aRowNr, const void* aValue,
				    const String& string)
{
  rownr_t aStartRow;
  rownr_t anEndRow;
  char*   aDummy;

  aDummy = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                            columnName());

  itsWriteFunc (aDummy+(aRowNr-aStartRow)*itsExternalSizeBytes,
  		aValue, itsNrCopy);
  memcpy (aDummy+(aRowNr-aStartRow)*itsExternalSizeBytes, string.chars(),
	  string.length());
  itsSSMPtr->setBucketDirty();
}

void SSMColumn::getScalarColumnV (ArrayBase& aDataPtr)
{
  if (dtype() == TpString) {
    Vector<String>& vec = static_cast<Vector<String>&>(aDataPtr);
    for (uInt64 i=0; i<aDataPtr.nelements(); i++) {
      getString (i, &(vec[i]));
    }
  } else {
    Bool deleteIt;
    void* anArray = aDataPtr.getVStorage(deleteIt);
    getColumnValue(anArray, aDataPtr.nelements());
    aDataPtr.putVStorage(anArray, deleteIt);
  }
}

void SSMColumn::getColumnValue(void* anArray,rownr_t aNrRows)
{
  char*   aDataPtr = static_cast<char*>(anArray);
  rownr_t aRowNr=0;
  rownr_t rowsToDo = aNrRows;
  
  while (rowsToDo > 0) {
    rownr_t aStartRow;
    rownr_t anEndRow;
    char*   aValue;
    aValue = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                              columnName());
    aRowNr = anEndRow+1;
    rownr_t aNr = anEndRow-aStartRow+1;
    rowsToDo -= aNr;
    itsReadFunc (aDataPtr, aValue, aNr * itsNrCopy);
    aDataPtr += aNr * itsLocalSize;
  }
}

void SSMColumn::putScalarColumnV (const ArrayBase& aDataPtr)
{
  if (dtype() == TpString) {
    const Vector<String>& vec = static_cast<const Vector<String>&>(aDataPtr);
    for (uInt64 i=0 ; i<aDataPtr.nelements(); i++) {
      putString (i, &(vec[i]));
    }
  } else {
    Bool deleteIt;
    const void* anArray = aDataPtr.getVStorage(deleteIt);
    putColumnValue (anArray, aDataPtr.nelements());
    aDataPtr.freeVStorage(anArray, deleteIt);
  }
}

void SSMColumn::putColumnValue(const void* anArray,rownr_t aNrRows)
{
  const char* aDataPtr = static_cast<const char*>(anArray);
  rownr_t aRowNr=0;
  rownr_t rowsToDo=aNrRows;

  while (rowsToDo > 0) {
    rownr_t aStartRow;
    rownr_t anEndRow;
    char*   aValPtr;
    aValPtr = itsSSMPtr->find (aRowNr, itsColNr, aStartRow, anEndRow,
                               columnName());
    aRowNr = anEndRow+1;
    rownr_t aNr = anEndRow-aStartRow+1;
    rowsToDo -= aNr;
    itsWriteFunc (aValPtr, aDataPtr, aNr * itsNrCopy);
    aDataPtr += aNr * itsLocalSize;
    itsSSMPtr->setBucketDirty();
  }

  // Be sure cache will be emptied
  columnCache().invalidate();
}

void SSMColumn::removeColumn()
{
  if (dataType() == TpString  &&  itsMaxLen == 0) {
    Int buf[3];
    for (rownr_t i=0; i<itsSSMPtr->getNRow(); i++) {
      getRowValue(buf, i);
      if (buf[2] > 8 ) {
	itsSSMPtr->getStringHandler()->remove(buf[0], buf[1], buf[2]);
      }
    }
  }
}
  
void SSMColumn::init()
{
  DataType aDT = static_cast<DataType>(dataType());
  itsLocalSize = ValType::getTypeSize(aDT);
  Bool asBigEndian = itsSSMPtr->asBigEndian();
  itsNrCopy = itsNrElem;
  if (aDT == TpString) {
    // Fixed length strings are written directly.
    if (itsMaxLen > 0) {
      itsNrCopy = itsMaxLen;
      itsLocalSize = itsNrCopy;
      itsExternalSizeBytes = itsNrCopy;
      itsReadFunc = itsWriteFunc = Conversion::valueCopy;
    } else {
      // Variable length strings are written indirectly.
      // They have 3 Ints (bucketnr, offset, length) telling where
      // the strings are.
      itsNrCopy=1;
      itsLocalSize = ValType::getTypeSize(TpInt);
      itsExternalSizeBytes = ValType::getCanonicalSize (TpInt, asBigEndian);
      uInt aNRel;
      ValType::getCanonicalFunc (TpInt, itsReadFunc, itsWriteFunc, aNRel,
				 asBigEndian);
      itsNrCopy *= aNRel;
      itsExternalSizeBytes *= 3;
      itsLocalSize         *= 3;
      itsNrCopy            *= 3;
    }
    itsExternalSizeBits   = 8*itsExternalSizeBytes;
  } else if (aDT == TpBool) {
    itsExternalSizeBytes = (itsNrElem + 7) / 8;
    itsExternalSizeBits  = itsNrElem;
    itsReadFunc  = &Conversion::bitToBool;
    itsWriteFunc = &Conversion::boolToBit;
  } else {
    itsExternalSizeBytes = ValType::getCanonicalSize (aDT, asBigEndian);
    uInt aNRel;
    ValType::getCanonicalFunc (aDT, itsReadFunc, itsWriteFunc, aNRel,
			       asBigEndian);
    itsNrCopy *= aNRel;
    itsExternalSizeBytes *= itsNrElem;
    itsLocalSize         *= itsNrElem;
    itsExternalSizeBits   = 8*itsExternalSizeBytes;
  }
}

void SSMColumn::resync (rownr_t)
{
    // Invalidate the last value read.
    columnCache().invalidate();
}

} //# NAMESPACE CASACORE - END