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