//# TiledFileAccess.cc: Tiled access to an array in a file //# Copyright (C) 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 #include #include #include #include #include #include #include #include namespace casacore { //# NAMESPACE CASACORE - BEGIN TiledFileAccess::TiledFileAccess (const String& fileName, Int64 fileOffset, const IPosition& shape, const IPosition& tileShape, DataType dataType, const TSMOption& tsmOpt, Bool writable) : itsCube (0), itsTSM (0), itsWritable (writable), itsDataType (dataType) { itsLocalPixelSize = ValType::getTypeSize (dataType); itsTSM = new TiledFileHelper (fileName, shape, dataType, tsmOpt, writable, HostInfo::bigEndian()); itsCube = itsTSM->makeTSMCube (itsTSM->file(), shape, tileShape, Record(), fileOffset); } TiledFileAccess::TiledFileAccess (const String& fileName, Int64 fileOffset, const IPosition& shape, const IPosition& tileShape, DataType dataType, const TSMOption& tsmOpt, Bool writable, Bool bigEndian) : itsCube (0), itsTSM (0), itsWritable (writable), itsDataType (dataType) { itsLocalPixelSize = ValType::getTypeSize (dataType); itsTSM = new TiledFileHelper (fileName, shape, dataType, tsmOpt, writable, bigEndian); itsCube = itsTSM->makeTSMCube (itsTSM->file(), shape, tileShape, Record(), fileOffset); } TiledFileAccess::~TiledFileAccess() { delete itsCube; delete itsTSM; } Array TiledFileAccess::getBool (const Slicer& section) { Array arr; get (arr, section); return arr; } Array TiledFileAccess::getUChar (const Slicer& section) { Array arr; get (arr, section); return arr; } Array TiledFileAccess::getShort (const Slicer& section) { Array arr; get (arr, section); return arr; } Array TiledFileAccess::getInt (const Slicer& section) { Array arr; get (arr, section); return arr; } Array TiledFileAccess::getFloat (const Slicer& section) { Array arr; get (arr, section); return arr; } Array TiledFileAccess::getDouble (const Slicer& section) { Array arr; get (arr, section); return arr; } Array TiledFileAccess::getComplex (const Slicer& section) { Array arr; get (arr, section); return arr; } Array TiledFileAccess::getDComplex (const Slicer& section) { Array arr; get (arr, section); return arr; } void TiledFileAccess::get (Array& buffer, const Slicer& section) { AlwaysAssert (itsDataType == TpBool, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); buffer.resize (shp); Bool deleteIt; Bool* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, False); buffer.putStorage (dataPtr, deleteIt); } void TiledFileAccess::get (Array& buffer, const Slicer& section) { AlwaysAssert (itsDataType == TpUChar, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); buffer.resize (shp); Bool deleteIt; uChar* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, False); buffer.putStorage (dataPtr, deleteIt); } void TiledFileAccess::get (Array& buffer, const Slicer& section) { AlwaysAssert (itsDataType == TpShort, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); buffer.resize (shp); Bool deleteIt; Short* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, False); buffer.putStorage (dataPtr, deleteIt); } void TiledFileAccess::get (Array& buffer, const Slicer& section) { AlwaysAssert (itsDataType == TpInt, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); buffer.resize (shp); Bool deleteIt; Int* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, False); buffer.putStorage (dataPtr, deleteIt); } void TiledFileAccess::get (Array& buffer, const Slicer& section) { AlwaysAssert (itsDataType == TpFloat, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); buffer.resize (shp); Bool deleteIt; Float* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, False); buffer.putStorage (dataPtr, deleteIt); } void TiledFileAccess::get (Array& buffer, const Slicer& section) { AlwaysAssert (itsDataType == TpDouble, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); buffer.resize (shp); Bool deleteIt; Double* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, False); buffer.putStorage (dataPtr, deleteIt); } void TiledFileAccess::get (Array& buffer, const Slicer& section) { AlwaysAssert (itsDataType == TpComplex, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); buffer.resize (shp); Bool deleteIt; Complex* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, False); buffer.putStorage (dataPtr, deleteIt); } void TiledFileAccess::get (Array& buffer, const Slicer& section) { AlwaysAssert (itsDataType == TpDComplex, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); buffer.resize (shp); Bool deleteIt; DComplex* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, False); buffer.putStorage (dataPtr, deleteIt); } Array TiledFileAccess::getFloat (const Slicer& section, Float scale, Float offset, uChar deleteValue, Bool examineForDeleteValues) { Array arr; get (arr, section, scale, offset, deleteValue, examineForDeleteValues); return arr; } Array TiledFileAccess::getFloat (const Slicer& section, Float scale, Float offset, Short deleteValue, Bool examineForDeleteValues) { Array arr; get (arr, section, scale, offset, deleteValue, examineForDeleteValues); return arr; } Array TiledFileAccess::getFloat (const Slicer& section, Float scale, Float offset, Int deleteValue, Bool examineForDeleteValues) { Array arr; get (arr, section, scale, offset, deleteValue, examineForDeleteValues); return arr; } void TiledFileAccess::get (Array& buffer, const Slicer& section, Float scale, Float offset, uChar deleteValue, Bool examineForDeleteValues) { Array arr = getUChar (section); buffer.resize (arr.shape()); Bool deleteArr, deleteBuf; const uChar* arrPtr = arr.getStorage (deleteArr); Float* bufPtr = buffer.getStorage (deleteBuf); uInt64 n = arr.nelements(); if (examineForDeleteValues) { for (uInt64 i=0; i& buffer, const Slicer& section, Float scale, Float offset, Short deleteValue, Bool examineForDeleteValues) { Array arr = getShort (section); buffer.resize (arr.shape()); Bool deleteArr, deleteBuf; const Short* arrPtr = arr.getStorage (deleteArr); Float* bufPtr = buffer.getStorage (deleteBuf); uInt64 n = arr.nelements(); if (examineForDeleteValues) { for (uInt64 i=0; i& buffer, const Slicer& section, Float scale, Float offset, Int deleteValue, Bool examineForDeleteValues) { Array arr = getInt (section); buffer.resize (arr.shape()); Bool deleteArr, deleteBuf; const Int* arrPtr = arr.getStorage (deleteArr); Float* bufPtr = buffer.getStorage (deleteBuf); uInt64 n = arr.nelements(); if (examineForDeleteValues) { for (uInt64 i=0; i& buffer, const Slicer& section) { AlwaysAssert (isWritable(), AipsError); AlwaysAssert (itsDataType == TpBool, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); AlwaysAssert (shp.isEqual (buffer.shape()), AipsError); Bool deleteIt; const Bool* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, True); buffer.freeStorage (dataPtr, deleteIt); } void TiledFileAccess::put (const Array& buffer, const Slicer& section) { AlwaysAssert (isWritable(), AipsError); AlwaysAssert (itsDataType == TpShort, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); AlwaysAssert (shp.isEqual (buffer.shape()), AipsError); Bool deleteIt; const uChar* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, True); buffer.freeStorage (dataPtr, deleteIt); } void TiledFileAccess::put (const Array& buffer, const Slicer& section) { AlwaysAssert (isWritable(), AipsError); AlwaysAssert (itsDataType == TpShort, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); AlwaysAssert (shp.isEqual (buffer.shape()), AipsError); Bool deleteIt; const Short* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, True); buffer.freeStorage (dataPtr, deleteIt); } void TiledFileAccess::put (const Array& buffer, const Slicer& section) { AlwaysAssert (isWritable(), AipsError); AlwaysAssert (itsDataType == TpInt, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); AlwaysAssert (shp.isEqual (buffer.shape()), AipsError); Bool deleteIt; const Int* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, True); buffer.freeStorage (dataPtr, deleteIt); } void TiledFileAccess::put (const Array& buffer, const Slicer& section) { AlwaysAssert (isWritable(), AipsError); AlwaysAssert (itsDataType == TpFloat, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); AlwaysAssert (shp.isEqual (buffer.shape()), AipsError); Bool deleteIt; const Float* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, True); buffer.freeStorage (dataPtr, deleteIt); } void TiledFileAccess::put (const Array& buffer, const Slicer& section) { AlwaysAssert (isWritable(), AipsError); AlwaysAssert (itsDataType == TpDouble, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); AlwaysAssert (shp.isEqual (buffer.shape()), AipsError); Bool deleteIt; const Double* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, True); buffer.freeStorage (dataPtr, deleteIt); } void TiledFileAccess::put (const Array& buffer, const Slicer& section) { AlwaysAssert (isWritable(), AipsError); AlwaysAssert (itsDataType == TpComplex, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); AlwaysAssert (shp.isEqual (buffer.shape()), AipsError); Bool deleteIt; const Complex* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, True); buffer.freeStorage (dataPtr, deleteIt); } void TiledFileAccess::put (const Array& buffer, const Slicer& section) { AlwaysAssert (isWritable(), AipsError); AlwaysAssert (itsDataType == TpDComplex, AipsError); IPosition start, end, stride; IPosition shp = section.inferShapeFromSource (itsCube->cubeShape(), start, end, stride); AlwaysAssert (shp.isEqual (buffer.shape()), AipsError); Bool deleteIt; const DComplex* dataPtr = buffer.getStorage (deleteIt); itsCube->accessStrided (start, end, stride, (char*)dataPtr, 0, itsLocalPixelSize, itsLocalPixelSize, True); buffer.freeStorage (dataPtr, deleteIt); } void TiledFileAccess::setMaximumCacheSize (uInt64 nbytes) { itsTSM->setMaximumCacheSize (nbytes); } uInt64 TiledFileAccess::maximumCacheSize() const { return itsTSM->maximumCacheSize(); } IPosition TiledFileAccess::makeTileShape (const IPosition& arrayShape, uInt nrPixelsPerTile) { Float nrPixels = nrPixelsPerTile; uInt ndim = arrayShape.nelements(); IPosition tileShape (ndim, 1); for (uInt i=0; i 0, AipsError); } break; } } return tileShape; } } //# NAMESPACE CASACORE - END