casa
$Rev:20696$
|
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: BucketMapped.h 20859 2010-02-03 13:14:15Z gervandiepen $ 00027 00028 #ifndef CASA_BUCKETMAPPED_H 00029 #define CASA_BUCKETMAPPED_H 00030 00031 //# Includes 00032 #include <casa/IO/BucketBase.h> 00033 #include <casa/IO/MMapfdIO.h> 00034 00035 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 // <summary> 00039 // Use file mapping for buckets in a part of a file 00040 // </summary> 00041 00042 // <use visibility=export> 00043 00044 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos=""> 00045 // </reviewed> 00046 00047 // <prerequisite> 00048 //# Classes you should understand before using this one. 00049 // <li> <linkto class=BucketFile>BucketFile</linkto> 00050 // </prerequisite> 00051 00052 // <etymology> 00053 // BucketMapped uses memory-mapped files for bucket access. 00054 // </etymology> 00055 00056 // <synopsis> 00057 // BucketMapped is similar to class 00058 // <linkto class=BucketCache>BucketCache</linkto> and is meant to be used by 00059 // the storage managers of the Table System. 00060 // 00061 // It gives access to buckets in a file by means of memory-mapped files. 00062 // However, its functionality is a subset of BucketCache and is only meant 00063 // to be used by the Tiled Storage Managers. If The Standard and Incremental 00064 // Storage Manager also want to use it, functions like <src>extend</src> 00065 // needs to be added to this class. Also support for a free bucket list needs 00066 // to be added. 00067 // </synopsis> 00068 00069 // <motivation> 00070 // Use of BucketCache is sub-optimal when having large buckets and more or 00071 // less random IO. Memory-mapping behaves much better. 00072 // </motivation> 00073 00074 00075 class BucketMapped: public BucketBase 00076 { 00077 public: 00078 // Create the cache for (part of) a file. 00079 // The file part mapped into memory starts at startOffset. Its length is 00080 // bucketSize*nrOfBuckets bytes. 00081 // If the file is smaller, the remainder is indicated as an extension 00082 // similarly to the behaviour of function extend. 00083 BucketMapped (BucketFile* file, Int64 startOffset, uInt bucketSize, 00084 uInt nrOfBuckets); 00085 00086 // Unmap the file 00087 ~BucketMapped(); 00088 00089 // Get a readonly pointer to the given bucket in memory. 00090 const char* getBucket (uInt bucketNr); 00091 00092 // Get a writable pointer to the given bucket in memory. 00093 // It sets the hasWritten flag. 00094 char* getrwBucket (uInt bucketNr) 00095 { 00096 itsHasWritten = True; 00097 return const_cast<char*>(getBucket(bucketNr)); 00098 } 00099 00100 private: 00101 // Copy constructor is not possible. 00102 BucketMapped (const BucketMapped&); 00103 00104 // Assignment is not possible. 00105 BucketMapped& operator= (const BucketMapped&); 00106 00107 // Flush the file. 00108 virtual void doFlush(); 00109 00110 // Do the actual resync-ing. 00111 virtual void doResync(); 00112 00113 // Extend the file with the given number of buckets. 00114 virtual void doExtend (uInt nrBucket); 00115 00116 // Initialize the bucket buffer. 00117 // The uninitialized buckets before this bucket are also initialized. 00118 virtual void initializeBuckets (uInt bucketNr); 00119 }; 00120 00121 00122 } //# NAMESPACE CASA - END 00123 00124 #endif