casacore
Loading...
Searching...
No Matches
IncrementalStMan.h
Go to the documentation of this file.
1// # IncrementalStMan.h: The Incremental Storage Manager
2// # Copyright (C) 1996,1997,1999
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_INCREMENTALSTMAN_H
27#define TABLES_INCREMENTALSTMAN_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/DataMan/ISMBase.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// <summary>
36// The Incremental Storage Manager
37// </summary>
38
39// <use visibility=export>
40
41// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tIncrementalStMan.cc">
42// </reviewed>
43
44// <prerequisite>
45// # Classes you should understand before using this one.
46// <li> The Table Data Managers concept as described in module file
47// <linkto module="Tables:Data Managers">Tables.h</linkto>
48// <li> <linkto class=ROIncrementalStManAccessor>
49// ROIncrementalStManAccessor</linkto>
50// for a discussion of the cache size
51// </prerequisite>
52
53// <etymology>
54// IncrementalStMan is the data manager storing values in an incremental way
55// (similar to an incremental backup). A value is only stored when it
56// differs from the previous value.
57// </etymology>
58
59// <synopsis>
60// IncrementalStMan stores the data in a way that a value is only stored
61// when it is different from the value in the previous row. This storage
62// manager is very well suited for columns with slowly changing values,
63// because the resulting file can be much smaller. It is not suited at
64// all for columns with continuously changing data.
65// <p>
66// In general it can be advantageous to use this storage manager when
67// a value changes at most every 4 rows (although it depends on the length
68// of the data values themselves). The following simple example
69// shows the approximate savings that can be achieved when storing a column
70// with double values changing every CH rows.
71// <srcblock>
72// #rows CH normal length ISM length compress ratio
73// 50000 5 4000000 1606000 2.5
74// 50000 50 4000000 164000 24.5
75// 50000 500 4000000 32800 122
76// </srcblock>
77// There is a special test program <src>nISMBucket</src> in the Tables module
78// doing a simple, but usually adequate, simulation of the amount of
79// storage needed for a scenario.
80// <p>
81// IncrementalStMan stores the values (and associated indices) in
82// fixed-length buckets. A <linkto class=BucketCache>BucketCache</linkto>
83// object is used to read/write
84// the buckets. The default cache size is 1 bucket (which is fine for
85// sequential access), but for random access it can make sense to
86// increase the size of the cache. This can be done using
87// the class <linkto class=ROIncrementalStManAccessor>
88// ROIncrementalStManAccessor</linkto>.
89// <p>
90// The IncrementalStMan can hold values of any standard data type (thus
91// from Bool to String). It can handle scalars, direct and indirect
92// arrays. It can support an arbitrary number of columns. The values in
93// each of them can vary at its own speed.
94// <br>
95// A bucket contains the values of several consecutive rows.
96// At the beginning of a bucket the values of the starting row of all
97// columns for this storage manager are repeated. In this way the value
98// of a cell can always be found in the bucket and no references
99// to previous buckets are needed.
100// <br>A bucket should be big enough to hold all starting values and
101// a reasonable number of other values. As a rule of thumb it should be
102// big enough to hold at least 100 values of each column. In general the
103// default bucket size will do. Only in special cases (e.g. when storing
104// large variable length strings) the bucket size should be set explicitly.
105// Giving a zero bucket size means that a suitale default bucket size
106// will be calculated.
107// <br>
108// When a table is filled sequentially each bucket can be filled as
109// much as possible. When writing in a random way, buckets can contain
110// some unused space, because a bucket in the middle of the file
111// has to be split when a new value has to be put in it.
112// <p>
113// Each column in the IncrementalStMan has the following properties to
114// achieve the "store-different-values-only" behaviour.
115// <ul>
116// <li> When a row is not explicitly put, it has the same value as the
117// previous row.
118// The first row gets the standard undefined values when not put.
119// The order of put's and addRow's is not important.
120// <br>E.g. when a table has N rows and row N and the following M rows
121// have the same value, the following schematic code has the same effect:
122// <br><src> add 1 row; put value in row N; add M rows;</src>
123// <br><src> add M+1 rows; put value in row N;</src>
124// <li> When putting a scalar or direct array, it is tested if it matches
125// the previous row. If so, it is not stored again.
126// This test is not done for indirect arrays, because those can
127// be (very) big and it would be too time-consuming. So the only
128// way to save space for indirect arrays is by not putting them
129// as explained in the previous item.
130// <li> For indirect arrays the buckets contain a pointer only. The
131// arrays themselves are stored in a separate file.
132// <li> When a value of an existing row is updated, only that one row is
133// updated. The next row(s) keep their value, even if it was
134// shared with the row being updated.
135// <br>For scalars and direct arrays it will be tested if the
136// new value matches the value in the previous and/or next row.
137// If so, those rows will be combined to save storage.
138// <li> The IncrementalStMan is optimized for sequential access to a table.
139// <br>- A bucket is accessed only once, because a bucket contains
140// consecutive rows.
141// <br>- For each column a copy is kept of the last value read.
142// So the value for the next rows (with that same value)
143// is immediately available.
144// <br>For random access the performance can be improved by setting
145// the cache size using class
146// <linkto class=ROIncrementalStManAccessor>
147// ROIncrementalStManAccessor</linkto>.
148// </ul>
149//
150// <note>This class contains many public functions which are only used
151// by other ISM classes. The only useful function for the user is the
152// constructor.
153// </note>
154
155// <motivation>
156// IncrementalStMan can save a lot of storage space.
157// Unlike the old StManMirAIO it stores the values directly in the
158// file to save on memory usage.
159// </motivation>
160
161// <example>
162// This example shows how to create a table and how to attach
163// the storage manager to some columns.
164// <srcblock>
165// SetupNewTable newtab("name.data", tableDesc, Table::New);
166// IncrementalStMan stman; // define storage manager
167// newtab.bindColumn ("column1", stman); // bind column to st.man.
168// newtab.bindColumn ("column2", stman); // bind column to st.man.
169// Table tab(newtab); // actually create table
170// </srcblock>
171// </example>
172
173// # <todo asof="$DATE:$">
174// # A List of bugs, limitations, extensions or planned refinements.
175// # </todo>
176
177class IncrementalStMan : public ISMBase {
178 public:
179 // Create an incremental storage manager with the given name.
180 // If no name is used, it is set to an empty string.
181 // The name can be used to construct a
182 // <linkto class=ROIncrementalStManAccessor>ROIncrementalStManAccessor
183 // </linkto> object (e.g. to set the cache size).
184 // <br>
185 // The bucket size has to be given in bytes and the cache size in buckets.
186 // Bucket size 0 means that the storage manager will set the bucket
187 // size such that it can contain about 100 rows
188 // (with a minimum size of 32768 bytes). However, if that results
189 // in a very large bucket size (>327680) it'll make it smaller.
190 // Note it uses 32 bytes for the size of variable length strings,
191 // so this heuristic may fail when a column contains large strings.
192 // When <src>checkBucketSize</src> is set and Bucket size > 0
193 // the storage manager throws an exception
194 // when the size is too small to hold the values of at least 2 rows.
195 // For this check it uses 0 for the length of variable length strings.
196 // <group>
197 explicit IncrementalStMan(uInt bucketSize = 0, Bool checkBucketSize = True, uInt cacheSize = 1);
199 Bool checkBucketSize = True, uInt cacheSize = 1);
200 // </group>
201
203
204 // Copy constructor cannot be used.
206
207 // Assignment cannot be used.
209};
210
211} // namespace casacore
212
213#endif
uInt bucketSize() const
Get the bucket size (in bytes).
Definition ISMBase.h:374
virtual String dataManagerName() const
Get the name given to the storage manager (in the constructor).
uInt cacheSize() const
Get the current cache size (in buckets).
Definition ISMBase.h:368
ISMBase(uInt bucketSize=0, Bool checkBucketSize=True, uInt cacheSize=1)
Create an incremental storage manager without a name.
IncrementalStMan(const IncrementalStMan &)=delete
Copy constructor cannot be used.
IncrementalStMan & operator=(const IncrementalStMan &)=delete
Assignment cannot be used.
IncrementalStMan(uInt bucketSize=0, Bool checkBucketSize=True, uInt cacheSize=1)
Create an incremental storage manager with the given name.
IncrementalStMan(const String &dataManagerName, uInt bucketSize=0, Bool checkBucketSize=True, uInt cacheSize=1)
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41