File: BaseMappedArrayEngine.tcc

package info (click to toggle)
casacore 3.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,912 kB
  • sloc: cpp: 471,569; fortran: 16,372; ansic: 7,416; yacc: 4,714; lex: 2,346; sh: 1,865; python: 629; perl: 531; sed: 499; csh: 201; makefile: 32
file content (387 lines) | stat: -rw-r--r-- 14,039 bytes parent folder | download | duplicates (2)
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
//# BaseMappedArrayEngine.cc: Abstract virtual column engine for virtual->stored mapping
//# Copyright (C) 1995,1996,2001,2002
//# Associated Universitie 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: casa-feedback@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA

#ifndef TABLES_BASEMAPPEDARRAYENGINE_TCC
#define TABLES_BASEMAPPEDARRAYENGINE_TCC

//# Includes
#include <casacore/tables/DataMan/BaseMappedArrayEngine.h>
#include <casacore/tables/Tables/Table.h>
#include <casacore/tables/Tables/ArrayColumn.h>
#include <casacore/tables/Tables/ColumnDesc.h>
#include <casacore/tables/DataMan/DataManError.h>
#include <casacore/tables/Tables/TableRecord.h>
#include <casacore/casa/BasicSL/String.h>


namespace casacore { //# NAMESPACE CASACORE - BEGIN

template<class VirtualType, class StoredType>
BaseMappedArrayEngine<VirtualType, StoredType>::BaseMappedArrayEngine ()
: virtualName_p  (""),
  storedName_p   (""),
  isWritable_p   (True),
  tempWritable_p (False),
  initialNrrow_p (0),
  arrayIsFixed_p (False),
  column_p       (0)
{}

template<class VirtualType, class StoredType>
BaseMappedArrayEngine<VirtualType, StoredType>::BaseMappedArrayEngine
                                        (const String& virtualColumnName,
					 const String& storedColumnName)
: virtualName_p  (virtualColumnName),
  storedName_p   (storedColumnName), 
  isWritable_p   (True),
  tempWritable_p (False),
  initialNrrow_p (0),
  arrayIsFixed_p (False),
  column_p       (0)
{}

template<class VirtualType, class StoredType>
BaseMappedArrayEngine<VirtualType, StoredType>::BaseMappedArrayEngine
                   (const BaseMappedArrayEngine<VirtualType, StoredType>& that)
: VirtualColumnEngine(),
  VirtualArrayColumn<VirtualType>(),
  virtualName_p  (that.virtualName_p),
  storedName_p   (that.storedName_p),
  isWritable_p   (that.isWritable_p),
  tempWritable_p (False),
  initialNrrow_p (0),
  arrayIsFixed_p (False),
  column_p       (0)
{}

template<class VirtualType, class StoredType>
BaseMappedArrayEngine<VirtualType, StoredType>::~BaseMappedArrayEngine()
{
    delete column_p;
}


// The function prepare is called upon initialization of the virtual column.
// The initialization order of the columns is undetermined, which means
// that this function isWritable can be called before the column has been
// initialized.
// For example, suppose column A uses column B and A gets initialized
// before B. Then A will call B's isWritable(), while B has not been
// initialized yet.
// This all means that isWritable must take care of the case
// where the writable_p flag is not set yet.
template<class VirtualType, class StoredType>
Bool BaseMappedArrayEngine<VirtualType, StoredType>::isWritable() const
{
    if (tempWritable_p) {
	return True;
    }
    return isWritable_p  &&  table().isColumnWritable (storedName_p);
}


// Create the column object for the array column in this engine.
// This merely checks if the virtual column name matches.
template<class VirtualType, class StoredType>
DataManagerColumn*
          BaseMappedArrayEngine<VirtualType, StoredType>::makeIndArrColumn
                            (const String& columnName, int, const String&)
{
    //# Check if the column name matches the virtual column name.
    //# The virtual name is only filled in case of creating a new table.
    //# In case the table is read back, makeIndArrColumn is called
    //# before prepare, thus before the virtual name can be read back.
    if (virtualName_p.empty()) {
	virtualName_p = columnName;
    } else if (columnName != virtualName_p) {
	throw (DataManInvOper
	       ("BaseMappedArrayEngine with virtual column " + virtualName_p +
		" bound to column " + columnName + "; should be the same"));
    }
    return this;
}
 
template<class VirtualType, class StoredType>
TableColumn BaseMappedArrayEngine<VirtualType, StoredType>::makeTableColumn
                                                (const String& columnName)
{
    tempWritable_p = True;
    TableColumn thisCol (table(), columnName);
    tempWritable_p = False;
    return thisCol;
}


template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::create64 (rownr_t initialNrrow)
{
    //# Define the stored name as a column keyword in the virtual.
    makeTableColumn (virtualName_p).rwKeywordSet().define
	                       ("_BaseMappedArrayEngine_Name", storedName_p);
    initialNrrow_p = initialNrrow;
}

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::prepare()
{
    prepare1();
    prepare2();
}


template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::prepare1()
{
    //# Get the name of the stored column from the keywords in the
    //# virtual column.
    tempWritable_p = True;
    TableColumn thisCol (table(), virtualName_p);
    storedName_p = thisCol.keywordSet().asString
	                                    ("_BaseMappedArrayEngine_Name");
    //# Determine if the stored column is writable.
    //# Allocate an object to get from the stored column.
    //# Allocate one to put if the column is writable.
    column_p = new ArrayColumn<StoredType> (table(), storedName_p);
    tempWritable_p = False;
    //# It is not permitted to have a FixedShape stored and non-FixedShape
    //# virtual column.
    if ((! arrayIsFixed_p)  &&
              ((column_p->columnDesc().options() & ColumnDesc::FixedShape)
	                                          == ColumnDesc::FixedShape)) {
	throw (DataManInvOper ("BaseMappedArrayEngine: virtual column " +
			       virtualName_p + " is FixedShape, but stored " +
			       storedName_p + " is not"));
    }
}

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::prepare2()
{
    //# Add the initial number of rows (thus only done after create).
    //# This will set the shape of the stored arrays when needed.
    if (initialNrrow_p > 0) {
	addRowInit (0, initialNrrow_p);
    }
}

//# Add nrrow rows to the end of the table.
//# Set the shape if virtual is FixedShape and stored is non-FixedShape.
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::addRow64 (rownr_t nrrow)
{
  addRowInit (table().nrow(), nrrow);
}
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::addRowInit (rownr_t startRow,
                                                                 rownr_t nrrow)
{
    if (arrayIsFixed_p  &&
              ((column_p->columnDesc().options() & ColumnDesc::FixedShape)
	                                        != ColumnDesc::FixedShape)) {
	for (rownr_t i=0; i<nrrow; i++) {
	    column_p->setShape (startRow++, shapeFixed_p);
	}
    }
}

//# This function is called in case the virtual column has FixedShape arrays.
//# If the stored has non-FixedShape arrays this shape will be set for the
//# array in each row of the stored (by function addRow).
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::setShapeColumn
                                                   (const IPosition& shape)
{
    shapeFixed_p   = shape;
    arrayIsFixed_p = True;
}

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::setShape
                                       (rownr_t rownr, const IPosition& shape)
{
    column_p->setShape (rownr, shape);
}

template<class VirtualType, class StoredType>
Bool BaseMappedArrayEngine<VirtualType, StoredType>::isShapeDefined (rownr_t rownr)
{
    return column_p->isDefined (rownr);
}

template<class VirtualType, class StoredType>
uInt BaseMappedArrayEngine<VirtualType, StoredType>::ndim (rownr_t rownr)
{
    return column_p->ndim (rownr);
}

template<class VirtualType, class StoredType>
IPosition BaseMappedArrayEngine<VirtualType, StoredType>::shape (rownr_t rownr)
{
    return column_p->shape (rownr);
}

template<class VirtualType, class StoredType>
Bool BaseMappedArrayEngine<VirtualType, StoredType>::canChangeShape() const
{
    return (column_p == 0  ?  False : column_p->canChangeShape());
}


template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::getArray
(rownr_t rownr, Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    column().baseGet (rownr, target);
    mapOnGet (array, target);
  }
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::putArray
(rownr_t rownr, const Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    mapOnPut (array, target);
    column().basePut (rownr, target);
  }

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::getSlice
(rownr_t rownr, const Slicer& slicer, Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(rownr, array.shape()));
    column().getSlice (rownr, getStoredSlicer(slicer), target);
    mapOnGet (array, target);
  }
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::putSlice
(rownr_t rownr, const Slicer& slicer, const Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(rownr, array.shape()));
    mapOnPut (array, target);
    column().putSlice (rownr, getStoredSlicer(slicer), target);
  }

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::getArrayColumn
(Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    column().getColumn (target);
    mapOnGet (array, target);
  }
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::putArrayColumn
(const Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    mapOnPut (array, target);
    column().putColumn (target);
  }

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::getArrayColumnCells
(const RefRows& rownrs, Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    column().getColumnCells (rownrs, target);
    mapOnGet (array, target);
  }
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::putArrayColumnCells
(const RefRows& rownrs, const Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    mapOnPut (array, target);
    column().putColumnCells (rownrs, target);
  }

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::getColumnSlice
(const Slicer& slicer, Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    column().getColumn (getStoredSlicer(slicer), target);
    mapOnGet (array, target);
  }
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::putColumnSlice
(const Slicer& slicer, const Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    mapOnPut (array, target);
    column().putColumn (getStoredSlicer(slicer), target);
  }

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::getColumnSliceCells
(const RefRows& rownrs, const Slicer& slicer, Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    column().getColumnCells (rownrs, getStoredSlicer(slicer), target);
    mapOnGet (array, target);
  }
template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::putColumnSliceCells
(const RefRows& rownrs, const Slicer& slicer, const Array<VirtualType>& array)
  {
    Array<StoredType> target(getStoredShape(0, array.shape()));
    mapOnPut (array, target);
    column().putColumnCells (rownrs, getStoredSlicer(slicer), target);
  }

template<class VirtualType, class StoredType>
IPosition BaseMappedArrayEngine<VirtualType, StoredType>::getStoredShape
(rownr_t, const IPosition& virtualShape)
{
  return virtualShape;
}

template<class VirtualType, class StoredType>
Slicer BaseMappedArrayEngine<VirtualType, StoredType>::getStoredSlicer
(const Slicer& virtualSlicer) const
{
  return virtualSlicer;
}

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::mapOnGet
(Array<VirtualType>&, const Array<StoredType>&)
{
  throw DataManInvOper("BaseMappedArrayEngine::mapOnGet not implemented "
                       "for column " + virtualName());
}

template<class VirtualType, class StoredType>
void BaseMappedArrayEngine<VirtualType, StoredType>::mapOnPut
(const Array<VirtualType>&, Array<StoredType>&)
{
  throw DataManInvOper("BaseMappedArrayEngine::mapOnPut not implemented "
                       "for column " + virtualName());
}


} //# NAMESPACE CASACORE - END

#endif