casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TSMOption.h
Go to the documentation of this file.
00001 //# TSMOption.h: Options for the Tiled Storage Manager Access
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 receied 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: TSMOption.h 20859 2010-02-03 13:14:15Z gervandiepen $
00027 
00028 #ifndef TABLES_TSMOPTION_H
00029 #define TABLES_TSMOPTION_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary>
00038 // Options for the Tiled Storage Manager Access
00039 // </summary>
00040 
00041 // <use visibility=export>
00042 
00043 // <reviewed reviewer="TPPR" date="08.11.94" tests="tTiledShapeStMan.cc">
00044 // </reviewed>
00045 
00046 // <prerequisite>
00047 //# Classes you should understand before using this one.
00048 //   <li> <linkto class=TiledStMan>TiledStMan</linkto>
00049 // </prerequisite>
00050 
00051 // <synopsis>
00052 // This class can be used to define how the Tiled Storage Manager accesses
00053 // its data. There are three ways:
00054 // <ol>
00055 //  <li> Using a cache of its own. The cache size is derived using the hinted
00056 //       access pattern. The cache can be (too) large when using large tables
00057 //       with bad access patterns.
00058 //       A maximum cache size can be defined to overcome this problem, but
00059 //       that may result in poor caching behaviour.
00060 //       Until January 2010 this was the only way to access the data.
00061 //  <li> Use memory-mapped IO (mmap); the operating system take care of caching.
00062 //       On 32-bit systems mmap cannot be used for larger tables due to the
00063 //       4 GB address space limit.
00064 //       When creating or extending files, mmap can be disadvantageous because
00065 //       extending the file requires remapping it.
00066 //  <li> Use buffered IO; the kernel's file cache should avoid unnecessary IO.
00067 //       Its performance is less than mmap, but it works well on 32-bit systems.
00068 //       The buffer size to be used can be defined.
00069 // </ol>
00070 //
00071 // The constructor of the class can be used to define the options or
00072 // to read options from the aipsrc file.
00073 // <ul>
00074 //  <li> <src>TSMOption::Cache</src>
00075 //       Use unbuffered file IO with internal TSM caching. This is the old
00076 //       behaviour.
00077 //       The maximum cache size can be given as a constructor argument.
00078 //  <li> <src>TSMOption::MMap</src>
00079 //       Use memory-mapped IO.
00080 //  <li> <src>TSMOption::Buffer</src>
00081 //       Use buffered file IO without.
00082 //       The buffer size can be given as a constructor argument.
00083 //  <li> <src>TSMOption::Default</src>
00084 //       Use default. This is MMap for existing files on 64-bit systems,
00085 //       otherwise Buffer.
00086 //  <li> <src>TSMOption::Aipsrc</src>
00087 //       Use the option as defined in the aipsrc file.
00088 // </ul>
00089 // The aipsrc variables are:
00090 // <ul>
00091 //  <li> <src>tables.tsm.option</src> gives the option as the case-insensitive
00092 //       string value:
00093 //   <ul>
00094 //    <li> <src>cache</src> means TSMCache.
00095 //    <li> <src>mmap</src> (or <src>map</src>) means TSMMap.
00096 //    <li> <src>mmapold</src> (or <src>mapold</src>) means TSMMap for existing
00097 //         tables and TSMDefault for new tables.
00098 //    <li> <src>buffer</src> means TSMBuffer.
00099 //    <li> <src>default</src> means TSMDefault.
00100 //   </ul>
00101 //       It defaults to value <src>default</src>.
00102 //       Note that <src>mmapold</src> is almost the same as <src>default</src>.
00103 //       Only on 32-bit systems it is different.
00104 //  <li> <src>tables.tsm.maxcachesizemb</src> gives the maximum cache size in MB
00105 //       for option <src>TSMOption::Cache</src>. A value -1 means that
00106 //       the system determines the maximum. A value 0 means unlimited.
00107 //       It defaults to -1.
00108 //       Note it can always be overridden using class ROTiledStManAccessor.
00109 //  <li> <src>tables.tsm.buffersize</src> gives the buffer size for option
00110 //       <src>TSMOption::Buffer</src>. A value <=0 means use the default 4096.
00111 //       It defaults to 0.
00112 // </ul>
00113 // </synopsis>
00114 
00115 
00116   class TSMOption
00117   {
00118   public:
00119     // Define the possible options how the TiledStMan accesses its data.
00120     enum Option {
00121       // Use unbuffered file IO with internal TSM caching.
00122       Cache,
00123       // Use buffered file IO without internal TSM caching.
00124       Buffer,
00125       // Use memory-mapped IO.
00126       MMap,
00127       // Use default.
00128       Default,
00129       // Use as defined in the aipsrc file.
00130       Aipsrc
00131     };
00132 
00133     // Create an option object.
00134     // The parameter values are described in the synopsis.
00135     // A size value -2 means reading that size from the aipsrc file.
00136     TSMOption (Option option=Aipsrc, Int bufferSize=-2,
00137                Int maxCacheSizeMB=-2);
00138 
00139     // Fill the option in case Aipsrc or Default was given.
00140     // It is done as explained in the synopsis.
00141     void fillOption (Bool newFile);
00142 
00143     // Get the option.
00144     Option option() const
00145       { return itsOption; }
00146 
00147     // Get the buffer size.
00148     Int bufferSize() const
00149       { return itsBufferSize; }
00150 
00151     // Get the maximum cache size. -1 means undefined.
00152     Int maxCacheSizeMB() const
00153       { return itsMaxCacheSize; }
00154 
00155   private:
00156     Option itsOption;
00157     Int    itsBufferSize;
00158     Int    itsMaxCacheSize;
00159   };
00160 
00161 } //# NAMESPACE CASA - END
00162 
00163 #endif