00001 //# BucketMapped.h: File buckets by means of file mapping 00002 //# Copyright (C) 2009 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef CASA_BUCKETMAPPED_H 00029 #define CASA_BUCKETMAPPED_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/casa/IO/BucketBase.h> 00034 #include <casacore/casa/IO/MMapfdIO.h> 00035 00036 00037 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00038 00039 // <summary> 00040 // Use file mapping for buckets in a part of a file 00041 // </summary> 00042 00043 // <use visibility=export> 00044 00045 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos=""> 00046 // </reviewed> 00047 00048 // <prerequisite> 00049 //# Classes you should understand before using this one. 00050 // <li> <linkto class=BucketFile>BucketFile</linkto> 00051 // </prerequisite> 00052 00053 // <etymology> 00054 // BucketMapped uses memory-mapped files for bucket access. 00055 // </etymology> 00056 00057 // <synopsis> 00058 // BucketMapped is similar to class 00059 // <linkto class=BucketCache>BucketCache</linkto> and is meant to be used by 00060 // the storage managers of the Table System. 00061 // 00062 // It gives access to buckets in a file by means of memory-mapped files. 00063 // However, its functionality is a subset of BucketCache and is only meant 00064 // to be used by the Tiled Storage Managers. If The Standard and Incremental 00065 // Storage Manager also want to use it, functions like <src>extend</src> 00066 // needs to be added to this class. Also support for a free bucket list needs 00067 // to be added. 00068 // </synopsis> 00069 00070 // <motivation> 00071 // Use of BucketCache is sub-optimal when having large buckets and more or 00072 // less random IO. Memory-mapping behaves much better. 00073 // </motivation> 00074 00075 00076 class BucketMapped: public BucketBase 00077 { 00078 public: 00079 // Create the cache for (part of) a file. 00080 // The file part mapped into memory starts at startOffset. Its length is 00081 // bucketSize*nrOfBuckets bytes. 00082 // If the file is smaller, the remainder is indicated as an extension 00083 // similarly to the behaviour of function extend. 00084 BucketMapped (BucketFile* file, Int64 startOffset, uInt bucketSize, 00085 uInt nrOfBuckets); 00086 00087 // Unmap the file 00088 ~BucketMapped(); 00089 00090 // Get a readonly pointer to the given bucket in memory. 00091 const char* getBucket (uInt bucketNr); 00092 00093 // Get a writable pointer to the given bucket in memory. 00094 // It sets the hasWritten flag. 00095 char* getrwBucket (uInt bucketNr) 00096 { 00097 itsHasWritten = True; 00098 return const_cast<char*>(getBucket(bucketNr)); 00099 } 00100 00101 private: 00102 // Copy constructor is not possible. 00103 BucketMapped (const BucketMapped&); 00104 00105 // Assignment is not possible. 00106 BucketMapped& operator= (const BucketMapped&); 00107 00108 // Flush the file. 00109 virtual void doFlush(); 00110 00111 // Do the actual resync-ing. 00112 virtual void doResync(); 00113 00114 // Extend the file with the given number of buckets. 00115 virtual void doExtend (uInt nrBucket); 00116 00117 // Initialize the bucket buffer. 00118 // The uninitialized buckets before this bucket are also initialized. 00119 virtual void initializeBuckets (uInt bucketNr); 00120 }; 00121 00122 00123 } //# NAMESPACE CASACORE - END 00124 00125 #endif