casacore
Loading...
Searching...
No Matches
ISMBase.h
Go to the documentation of this file.
1//# ISMBase.h: Base class of the Incremental Storage Manager
2//# Copyright (C) 1996,1997,1999,2000,2001,2002
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_ISMBASE_H
27#define TABLES_ISMBASE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/DataMan/DataManager.h>
33#include <casacore/casa/Containers/Block.h>
34#include <casacore/casa/iosfwd.h>
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38//# Forward declarations
39class BucketCache;
40class BucketFile;
41class ISMBucket;
42class ISMIndex;
43class ISMColumn;
44class StManArrayFile;
45
46// <summary>
47// Base class of the Incremental Storage Manager
48// </summary>
49
50// <use visibility=local>
51
52// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tIncrementalStMan.cc">
53// </reviewed>
54
55// <prerequisite>
56//# Classes you should understand before using this one.
57// <li> <linkto class=IncrementalStMan>IncrementalStMan</linkto>
58// <li> <linkto class=ISMColumn>ISMColumn</linkto>
59// </prerequisite>
60
61// <etymology>
62// ISMBase is the base class of the Incremental Storage Manager.
63// </etymology>
64
65// <synopsis>
66// The behaviour of this class is described in
67// <linkto class="IncrementalStMan:description">IncrementalStMan</linkto>.
68
69// <motivation>
70// The public interface of ISMBase is quite large, because the other
71// internal ISM classes need these functions. To have a class with a
72// minimal interface for the normal user, class <src>IncrementalStMan</src>
73// is derived from it.
74// <br>IncrementalStMan needs an isA- instead of hasA-relation to be
75// able to bind columns to it in class <linkto class=SetupNewTable>
76// SetupNewTable</linkto>.
77// </motivation>
78
79// <todo asof="$DATE:$">
80//# A List of bugs, limitations, extensions or planned refinements.
81// <li> Removed AipsIO argument from open and close.
82// </todo>
83
84
85class ISMBase: public DataManager
86{
87public:
88 // Create an incremental storage manager without a name.
89 // The bucket size has to be given in bytes and the cache size in buckets.
90 // The bucket size is checked or calculated (if 0) as described in
91 // IncrementalStMan.h.
92 explicit ISMBase (uInt bucketSize = 0, Bool checkBucketSize = True,
93 uInt cacheSize = 1);
94
95 // Create an incremental storage manager with the given name.
96 // The bucket size has to be given in bytes and the cache size in buckets.
97 // The bucket size is checked or calculated (if 0) as described in
98 // IncrementalStMan.h.
100 uInt bucketSize, Bool checkBucketSize, uInt cacheSize);
101
102 // Create an incremental storage manager with the given name.
103 // The specifications are in the record (as created by dataManagerSpec).
104 ISMBase (const String& aDataManName,
105 const Record& spec);
106
108
109 // Assignment cannot be used.
110 ISMBase& operator= (const ISMBase& that) = delete;
111
112 // Clone this object.
113 // It does not clone ISMColumn objects possibly used.
114 // The caller has to delete the newly created object.
115 virtual DataManager* clone() const;
116
117 // Get the type name of the data manager (i.e. IncrementalStMan).
118 virtual String dataManagerType() const;
119
120 // Get the name given to the storage manager (in the constructor).
121 virtual String dataManagerName() const;
122
123 // Record a record containing data manager specifications.
124 virtual Record dataManagerSpec() const;
125
126 // Get data manager properties that can be modified.
127 // It is only ActualCacheSize (the actual cache size in buckets).
128 // It is a subset of the data manager specification.
129 virtual Record getProperties() const;
130
131 // Modify data manager properties.
132 // Only MaxCacheSize can be used. It is similar to function setCacheSize
133 // with <src>canExceedNrBuckets=False</src>.
134 virtual void setProperties (const Record& spec);
135
136 // Get the version of the class.
137 uInt version() const;
138
139 // Set the cache size (in buckets).
140 // If <src>canExceedNrBuckets=True</src>, the given cache size can be
141 // larger than the nr of buckets in the file. In this way the cache can
142 // be made large enough for a future file extnsion.
143 // Otherwise, it is limited to the actual number of buckets. This is useful
144 // if one wants the entire file to be cached.
145 void setCacheSize (uInt cacheSize, Bool canExceedNrBuckets);
146
147 // Get the current cache size (in buckets).
148 uInt cacheSize() const;
149
150 // Clear the cache used by this storage manager.
151 // It will flush the cache as needed and remove all buckets from it.
153
154 // Show the statistics of all caches used.
155 virtual void showCacheStatistics (ostream& os) const;
156
157 // Show the index statistics.
158 void showIndexStatistics (ostream& os);
159
160 // Show the layout of the buckets
161 void showBucketLayout (ostream& os);
162
163 // Get the bucket size (in bytes).
164 uInt bucketSize() const;
165
166 // Get the size of a uInt in external format (can be canonical or local).
167 uInt uIntSize() const;
168
169 // Get the size of a rownr in external format (can be canonical or local).
170 uInt rownrSize() const;
171
172 // Get the bucket containing the given row.
173 // Also return the first and last row of that bucket.
174 // The bucket object is created and deleted by the caching mechanism.
175 ISMBucket* getBucket (rownr_t rownr, rownr_t& bucketStartRow,
176 rownr_t& bucketNrrow);
177
178 // Get the next bucket.
179 // cursor=0 indicates the start of the iteration.
180 // The first bucket returned is the bucket containing the rownr
181 // given in bucketStartRow.
182 // After each iteration BucketStartRow and bucketNrrow are set.
183 // A 0 is returned when no more buckets.
184 // The bucket object is created and deleted by the caching mechanism.
185 ISMBucket* nextBucket (uInt& cursor, rownr_t& bucketStartRow,
186 rownr_t& bucketNrrow);
187
188 // Get access to the temporary buffer.
189 char* tempBuffer() const;
190
191 // Get a unique column number for the column
192 // (it is only unique for this storage manager).
193 // This is used by ISMColumnIndArr to create a unique file name.
194 uInt uniqueNr();
195
196 // Get the number of rows in this storage manager.
197 rownr_t nrow() const;
198
199 // Can the storage manager add rows? (yes)
200 virtual Bool canAddRow() const;
201
202 // Can the storage manager delete rows? (yes)
203 virtual Bool canRemoveRow() const;
204
205 // Can the storage manager add columns? (not yet)
206 virtual Bool canAddColumn() const;
207
208 // Can the storage manager delete columns? (not yet)
209 virtual Bool canRemoveColumn() const;
210
211 // Make the object from the type name string.
212 // This function gets registered in the DataManager "constructor" map.
213 // The caller has to delete the object.
215 const Record& spec);
216
217 // Get access to the given column.
218 ISMColumn& getColumn (uInt colnr);
219
220 // Add a bucket to the storage manager (i.e. to the cache).
221 // The pointer is taken over.
222 void addBucket (rownr_t rownr, ISMBucket* bucket);
223
224 // Make the current bucket in the cache dirty (i.e. something has been
225 // changed in it and it needs to be written when removed from the cache).
226 // (used by ISMColumn::putValue).
228
229 // Open (if needed) the file for indirect arrays with the given mode.
230 // Return a pointer to the object.
232
233 // Check that there are no repeated rowIds in the buckets comprising this ISM.
234 Bool checkBucketLayout (uInt& offendingCursor,
235 rownr_t& offendingBucketStartRow,
236 uInt& offendingBucketNrow,
237 uInt& offendingBucketNr,
238 uInt& offendingCol,
239 uInt& ffendingIndex,
240 rownr_t& offendingRow,
241 rownr_t& offendingPrevRow);
242
243private:
244 // Copy constructor (only meant for clone function).
245 ISMBase (const ISMBase& that);
246
247 // (Re)create the index, file, and cache object.
248 void recreate();
249
250 // The data manager supports use of MultiFile.
251 virtual Bool hasMultiFileSupport() const;
252
253 // Flush and optionally fsync the data.
254 // It returns a True status if it had to flush (i.e. if data have changed).
255 virtual Bool flush (AipsIO&, Bool fsync);
256
257 // Let the storage manager create files as needed for a new table.
258 // This allows a column with an indirect array to create its file.
259 virtual void create64 (rownr_t nrrow);
260
261 // Open the storage manager file for an existing table, read in
262 // the data, and let the ISMColumn objects read their data.
263 virtual rownr_t open64 (rownr_t nrrow, AipsIO&);
264
265 // Resync the storage manager with the new file contents.
266 // This is done by clearing the cache.
267 virtual rownr_t resync64 (rownr_t nrrow);
268
269 // Reopen the storage manager files for read/write.
270 virtual void reopenRW();
271
272 // The data manager will be deleted (because all its columns are
273 // requested to be deleted).
274 // So clean up the things needed (e.g. delete files).
275 virtual void deleteManager();
276
277 // Let the storage manager initialize itself.
278 // It is used by create and open.
279 void init();
280
281 // Add rows to the storage manager.
282 // Per column it extends the interval for which the last value written
283 // is valid.
284 virtual void addRow64 (rownr_t nrrow);
285
286 // Delete a row from all columns.
287 virtual void removeRow64 (rownr_t rownr);
288
289 // Do the final addition of a column.
290 // The <src>DataManagerColumn</src> object has already been created
291 // (by the <src>makeXXColumn</src> function) and added to
292 // <src>colSet_p</src>. However, it still has to be added to the
293 // data files, which is done by this function. It uses the
294 // pointer to find the correct column in the <src>colSet_p</src>.
296
297 // Remove a column from the data file and the <src>colSet_p</src>.
298 // The <src>DataManagerColumn</src> object gets deleted..
300
301 // Create a column in the storage manager on behalf of a table column.
302 // The caller has to delete the newly created object.
303 // <group>
304 // Create a scalar column.
306 int dataType,
307 const String& dataTypeID);
308 // Create a direct array column.
310 int dataType,
311 const String& dataTypeID);
312 // Create an indirect array column.
314 int dataType,
315 const String& dataTypeID);
316 // </group>
317
318 // Get the cache object.
319 // This will construct the cache object if not present yet.
320 // The cache object will be deleted by the destructor.
322
323 // Get the index object.
324 // This will construct the index object if not present yet.
325 // The index object will be deleted by the destructor.
327
328 // Construct the cache object (if not constructed yet).
329 void makeCache();
330
331 // Construct the index object (if not constructed yet) and read it.
332 void makeIndex();
333
334 // Read the index (at the end of the file).
335 void readIndex();
336
337 // Write the index (at the end of the file).
339
340
341 //# Declare member variables.
342 // Name of data manager.
344 // The version of the class.
346 // The file containing the indirect arrays.
348 // Unique nr for column in this storage manager.
350 // The number of rows in the columns.
352 // The assembly of all columns.
354 // The cache with the ISM buckets.
356 // The file containing all data.
358 // The ISM bucket index.
360 // The persistent cache size.
362 // The actual cache size.
364 // The initial number of buckets in the cache.
366 // The nr of free buckets.
368 // The first free bucket.
370 // The bucket size.
372 // Check a positive bucketsize?
374 // Has the data changed since the last flush?
376 // The size of a uInt in external format (local or canonical).
378 // The size of a rownr in external format (local or canonical).
380 // A temporary read/write buffer (also for other classes).
382};
383
384
385inline uInt ISMBase::version() const
386{
387 return version_p;
388}
389
391{
392 return cacheSize_p;
393}
394
396{
397 return uniqnr_p++;
398}
399
400inline rownr_t ISMBase::nrow() const
401{
402 return nrrow_p;
403}
404
406{
407 return bucketSize_p;
408}
409
411{
412 return uIntSize_p;
413}
414
416{
417 return rownrSize_p;
418}
419
420inline char* ISMBase::tempBuffer() const
421{
422 return tempBuffer_p;
423}
424
426{
427 if (cache_p == 0) {
428 makeCache();
429 }
430 return *cache_p;
431}
432
434{
435 if (index_p == 0) {
436 makeIndex();
437 }
438 return *index_p;
439}
440
442{
443 return *(colSet_p[colnr]);
444}
445
446
447
448} //# NAMESPACE CASACORE - END
449
450#endif
Cache for buckets in a part of a file.
OpenOption
Define the possible ByteIO open options.
Definition ByteIO.h:63
Abstract base class for a data manager.
rownr_t nrrow_p
The number of rows in the columns.
Definition ISMBase.h:351
virtual Record getProperties() const
Get data manager properties that can be modified.
virtual void create64(rownr_t nrrow)
Let the storage manager create files as needed for a new table.
PtrBlock< ISMColumn * > colSet_p
The assembly of all columns.
Definition ISMBase.h:353
void readIndex()
Read the index (at the end of the file).
virtual void setProperties(const Record &spec)
Modify data manager properties.
ISMBase(const ISMBase &that)
Copy constructor (only meant for clone function).
virtual rownr_t open64(rownr_t nrrow, AipsIO &)
Open the storage manager file for an existing table, read in the data, and let the ISMColumn objects ...
virtual void addColumn(DataManagerColumn *)
Do the final addition of a column.
StManArrayFile * openArrayFile(ByteIO::OpenOption opt)
Open (if needed) the file for indirect arrays with the given mode.
char * tempBuffer() const
Get access to the temporary buffer.
Definition ISMBase.h:420
char * tempBuffer_p
A temporary read/write buffer (also for other classes).
Definition ISMBase.h:381
uInt uniqnr_p
Unique nr for column in this storage manager.
Definition ISMBase.h:349
ISMIndex * index_p
The ISM bucket index.
Definition ISMBase.h:359
virtual Bool flush(AipsIO &, Bool fsync)
Flush and optionally fsync the data.
Bool checkBucketLayout(uInt &offendingCursor, rownr_t &offendingBucketStartRow, uInt &offendingBucketNrow, uInt &offendingBucketNr, uInt &offendingCol, uInt &ffendingIndex, rownr_t &offendingRow, rownr_t &offendingPrevRow)
Check that there are no repeated rowIds in the buckets comprising this ISM.
uInt bucketSize_p
The bucket size.
Definition ISMBase.h:371
virtual Bool canAddRow() const
Can the storage manager add rows? (yes)
uInt bucketSize() const
Get the bucket size (in bytes).
Definition ISMBase.h:405
rownr_t nrow() const
Get the number of rows in this storage manager.
Definition ISMBase.h:400
virtual DataManager * clone() const
Clone this object.
virtual String dataManagerName() const
Get the name given to the storage manager (in the constructor).
ISMColumn & getColumn(uInt colnr)
Get access to the given column.
Definition ISMBase.h:441
ISMIndex & getIndex()
Get the index object.
Definition ISMBase.h:433
void setCacheSize(uInt cacheSize, Bool canExceedNrBuckets)
Set the cache size (in buckets).
void showIndexStatistics(ostream &os)
Show the index statistics.
void setBucketDirty()
Make the current bucket in the cache dirty (i.e.
uInt rownrSize() const
Get the size of a rownr in external format (can be canonical or local).
Definition ISMBase.h:415
virtual String dataManagerType() const
Get the type name of the data manager (i.e.
uInt nbucketInit_p
The initial number of buckets in the cache.
Definition ISMBase.h:365
uInt persCacheSize_p
The persistent cache size.
Definition ISMBase.h:361
virtual Record dataManagerSpec() const
Record a record containing data manager specifications.
uInt version_p
The version of the class.
Definition ISMBase.h:345
virtual void reopenRW()
Reopen the storage manager files for read/write.
void recreate()
(Re)create the index, file, and cache object.
Bool checkBucketSize_p
Check a positive bucketsize?
Definition ISMBase.h:373
virtual void removeColumn(DataManagerColumn *)
Remove a column from the data file and the colSet_p.
StManArrayFile * iosfile_p
The file containing the indirect arrays.
Definition ISMBase.h:347
void init()
Let the storage manager initialize itself.
BucketCache & getCache()
Get the cache object.
Definition ISMBase.h:425
static DataManager * makeObject(const String &dataManagerType, const Record &spec)
Make the object from the type name string.
virtual void showCacheStatistics(ostream &os) const
Show the statistics of all caches used.
uInt uniqueNr()
Get a unique column number for the column (it is only unique for this storage manager).
Definition ISMBase.h:395
void makeIndex()
Construct the index object (if not constructed yet) and read it.
virtual DataManagerColumn * makeIndArrColumn(const String &name, int dataType, const String &dataTypeID)
Create an indirect array column.
uInt nFreeBucket_p
The nr of free buckets.
Definition ISMBase.h:367
uInt uIntSize_p
The size of a uInt in external format (local or canonical).
Definition ISMBase.h:377
Bool dataChanged_p
Has the data changed since the last flush?
Definition ISMBase.h:375
String dataManName_p
Name of data manager.
Definition ISMBase.h:343
virtual rownr_t resync64(rownr_t nrrow)
Resync the storage manager with the new file contents.
virtual Bool canRemoveColumn() const
Can the storage manager delete columns? (not yet)
virtual DataManagerColumn * makeDirArrColumn(const String &name, int dataType, const String &dataTypeID)
Create a direct array column.
virtual DataManagerColumn * makeScalarColumn(const String &name, int dataType, const String &dataTypeID)
Create a column in the storage manager on behalf of a table column.
ISMBase & operator=(const ISMBase &that)=delete
Assignment cannot be used.
ISMBase(const String &aDataManName, const Record &spec)
Create an incremental storage manager with the given name.
uInt rownrSize_p
The size of a rownr in external format (local or canonical).
Definition ISMBase.h:379
virtual void deleteManager()
The data manager will be deleted (because all its columns are requested to be deleted).
uInt cacheSize_p
The actual cache size.
Definition ISMBase.h:363
void clearCache()
Clear the cache used by this storage manager.
uInt version() const
Get the version of the class.
Definition ISMBase.h:385
void addBucket(rownr_t rownr, ISMBucket *bucket)
Add a bucket to the storage manager (i.e.
virtual Bool hasMultiFileSupport() const
The data manager supports use of MultiFile.
uInt cacheSize() const
Get the current cache size (in buckets).
Definition ISMBase.h:390
void writeIndex()
Write the index (at the end of the file).
Int firstFree_p
The first free bucket.
Definition ISMBase.h:369
BucketFile * file_p
The file containing all data.
Definition ISMBase.h:357
ISMBucket * nextBucket(uInt &cursor, rownr_t &bucketStartRow, rownr_t &bucketNrrow)
Get the next bucket.
virtual Bool canAddColumn() const
Can the storage manager add columns? (not yet)
BucketCache * cache_p
The cache with the ISM buckets.
Definition ISMBase.h:355
ISMBucket * getBucket(rownr_t rownr, rownr_t &bucketStartRow, rownr_t &bucketNrrow)
Get the bucket containing the given row.
ISMBase(const String &dataManagerName, uInt bucketSize, Bool checkBucketSize, uInt cacheSize)
Create an incremental storage manager with the given name.
void makeCache()
Construct the cache object (if not constructed yet).
uInt uIntSize() const
Get the size of a uInt in external format (can be canonical or local).
Definition ISMBase.h:410
virtual void addRow64(rownr_t nrrow)
Add rows to the storage manager.
ISMBase(uInt bucketSize=0, Bool checkBucketSize=True, uInt cacheSize=1)
Create an incremental storage manager without a name.
virtual Bool canRemoveRow() const
Can the storage manager delete rows? (yes)
void showBucketLayout(ostream &os)
Show the layout of the buckets.
virtual void removeRow64(rownr_t rownr)
Delete a row from all columns.
A drop-in replacement for Block<T*>.
Definition Block.h:812
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44