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