//# 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: aips2-request@nrao.edu. //# Postal address: AIPS++ Project Office //# National Radio Astronomy Observatory //# 520 Edgemont Road //# Charlottesville, VA 22903-2475 USA //# //# $Id$ #ifndef TABLES_BASEMAPPEDARRAYENGINE_TCC #define TABLES_BASEMAPPEDARRAYENGINE_TCC //# Includes #include #include #include #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN template BaseMappedArrayEngine::BaseMappedArrayEngine () : virtualName_p (""), storedName_p (""), isWritable_p (True), tempWritable_p (False), initialNrrow_p (0), arrayIsFixed_p (False), column_p (0) {} template BaseMappedArrayEngine::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 BaseMappedArrayEngine::BaseMappedArrayEngine (const BaseMappedArrayEngine& that) : VirtualColumnEngine(), VirtualArrayColumn(), 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 BaseMappedArrayEngine::~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 Bool BaseMappedArrayEngine::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 DataManagerColumn* BaseMappedArrayEngine::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 TableColumn BaseMappedArrayEngine::makeTableColumn (const String& columnName) { tempWritable_p = True; TableColumn thisCol (table(), columnName); tempWritable_p = False; return thisCol; } template void BaseMappedArrayEngine::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 void BaseMappedArrayEngine::prepare() { prepare1(); prepare2(); } template void BaseMappedArrayEngine::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 (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 void BaseMappedArrayEngine::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 void BaseMappedArrayEngine::addRow64 (rownr_t nrrow) { addRowInit (table().nrow(), nrrow); } template void BaseMappedArrayEngine::addRowInit (rownr_t startRow, rownr_t nrrow) { if (arrayIsFixed_p && ((column_p->columnDesc().options() & ColumnDesc::FixedShape) != ColumnDesc::FixedShape)) { for (rownr_t i=0; isetShape (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 void BaseMappedArrayEngine::setShapeColumn (const IPosition& shape) { shapeFixed_p = shape; arrayIsFixed_p = True; } template void BaseMappedArrayEngine::setShape (rownr_t rownr, const IPosition& shape) { column_p->setShape (rownr, shape); } template Bool BaseMappedArrayEngine::isShapeDefined (rownr_t rownr) { return column_p->isDefined (rownr); } template uInt BaseMappedArrayEngine::ndim (rownr_t rownr) { return column_p->ndim (rownr); } template IPosition BaseMappedArrayEngine::shape (rownr_t rownr) { return column_p->shape (rownr); } template Bool BaseMappedArrayEngine::canChangeShape() const { return (column_p == 0 ? False : column_p->canChangeShape()); } template void BaseMappedArrayEngine::getArray (rownr_t rownr, Array& array) { Array target(getStoredShape(0, array.shape())); column().baseGet (rownr, target); mapOnGet (array, target); } template void BaseMappedArrayEngine::putArray (rownr_t rownr, const Array& array) { Array target(getStoredShape(0, array.shape())); mapOnPut (array, target); column().basePut (rownr, target); } template void BaseMappedArrayEngine::getSlice (rownr_t rownr, const Slicer& slicer, Array& array) { Array target(getStoredShape(rownr, array.shape())); column().getSlice (rownr, getStoredSlicer(slicer), target); mapOnGet (array, target); } template void BaseMappedArrayEngine::putSlice (rownr_t rownr, const Slicer& slicer, const Array& array) { Array target(getStoredShape(rownr, array.shape())); mapOnPut (array, target); column().putSlice (rownr, getStoredSlicer(slicer), target); } template void BaseMappedArrayEngine::getArrayColumn (Array& array) { Array target(getStoredShape(0, array.shape())); column().getColumn (target); mapOnGet (array, target); } template void BaseMappedArrayEngine::putArrayColumn (const Array& array) { Array target(getStoredShape(0, array.shape())); mapOnPut (array, target); column().putColumn (target); } template void BaseMappedArrayEngine::getArrayColumnCells (const RefRows& rownrs, Array& array) { Array target(getStoredShape(0, array.shape())); column().getColumnCells (rownrs, target); mapOnGet (array, target); } template void BaseMappedArrayEngine::putArrayColumnCells (const RefRows& rownrs, const Array& array) { Array target(getStoredShape(0, array.shape())); mapOnPut (array, target); column().putColumnCells (rownrs, target); } template void BaseMappedArrayEngine::getColumnSlice (const Slicer& slicer, Array& array) { Array target(getStoredShape(0, array.shape())); column().getColumn (getStoredSlicer(slicer), target); mapOnGet (array, target); } template void BaseMappedArrayEngine::putColumnSlice (const Slicer& slicer, const Array& array) { Array target(getStoredShape(0, array.shape())); mapOnPut (array, target); column().putColumn (getStoredSlicer(slicer), target); } template void BaseMappedArrayEngine::getColumnSliceCells (const RefRows& rownrs, const Slicer& slicer, Array& array) { Array target(getStoredShape(0, array.shape())); column().getColumnCells (rownrs, getStoredSlicer(slicer), target); mapOnGet (array, target); } template void BaseMappedArrayEngine::putColumnSliceCells (const RefRows& rownrs, const Slicer& slicer, const Array& array) { Array target(getStoredShape(0, array.shape())); mapOnPut (array, target); column().putColumnCells (rownrs, getStoredSlicer(slicer), target); } template IPosition BaseMappedArrayEngine::getStoredShape (rownr_t, const IPosition& virtualShape) { return virtualShape; } template Slicer BaseMappedArrayEngine::getStoredSlicer (const Slicer& virtualSlicer) const { return virtualSlicer; } template void BaseMappedArrayEngine::mapOnGet (Array&, const Array&) { throw DataManInvOper("BaseMappedArrayEngine::mapOnGet not implemented " "for column " + virtualName()); } template void BaseMappedArrayEngine::mapOnPut (const Array&, Array&) { throw DataManInvOper("BaseMappedArrayEngine::mapOnPut not implemented " "for column " + virtualName()); } } //# NAMESPACE CASACORE - END #endif