casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
BucketBuffered.h
Go to the documentation of this file.
00001 //# BucketBuffered.h: Use buffered file IO for buckets in a part of a file
00002 //# Copyright (C) 2010
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: BucketBuffered.h 20859 2010-02-03 13:14:15Z gervandiepen $
00027 
00028 #ifndef CASA_BUCKETBUFFERED_H
00029 #define CASA_BUCKETBUFFERED_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/IO/BucketBase.h>
00034 
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038   //# Forward Declarations.
00039   class FilebufIO;
00040 
00041 
00042   // <summary>
00043   // Use buffered file IO for buckets in a part of a file
00044   // </summary>
00045 
00046   // <use visibility=export>
00047 
00048   // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00049   // </reviewed>
00050 
00051   // <prerequisite>
00052   //# Classes you should understand before using this one.
00053   //   <li> <linkto class=BucketFile>BucketFile</linkto>
00054   // </prerequisite>
00055 
00056   // <synopsis>
00057   // BucketBuffered 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-buffered 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-buffering behaves much better.
00072   // </motivation>
00073 
00074 
00075   class BucketBuffered: public BucketBase
00076   {
00077   public:
00078     // Create the object for (part of) a file.
00079     // The file part buffered 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     BucketBuffered (BucketFile* file, Int64 startOffset, uInt bucketSize,
00084                     uInt nrOfBuckets);
00085 
00086     virtual ~BucketBuffered();
00087 
00088     // Get a pointer to the buffer.
00089     char* getBuffer()
00090       { return itsBuffer; }
00091 
00092     // Read the given part into the internal buffer at the given offset.
00093     void read (uInt bucketNr, uInt bucketOffset, uInt nbytes,
00094                uInt bufferOffset=0);
00095 
00096     // Write the given part from the internal buffer.
00097     void write (uInt bucketNr, uInt bucketOffset, uInt nbytes);
00098 
00099 private:
00100     // Copy constructor is not possible.
00101     BucketBuffered (const BucketBuffered&);
00102 
00103     // Assignment is not possible.
00104     BucketBuffered& operator= (const BucketBuffered&);
00105 
00106     // Flush the file.
00107     virtual void doFlush();
00108 
00109     // Do the actual resync-ing.
00110     virtual void doResync();
00111 
00112     // Extend the file with the given number of buckets.
00113     virtual void doExtend (uInt nrBucket);
00114 
00115     // Initialize the bucket buffer.
00116     // The uninitialized buckets before this bucket are also initialized.
00117     virtual void initializeBuckets (uInt bucketNr);
00118 
00119 
00120     // Data buffer.
00121     char* itsBuffer;
00122 };
00123 
00124 
00125 } //# NAMESPACE CASA - END
00126 
00127 #endif