casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ISMIndex.h
Go to the documentation of this file.
1 //# ISMIndex.h: The Index of the Incremental Storage Manager
2 //# Copyright (C) 1996,1997,1999,2005
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_ISMINDEX_H
29 #define TABLES_ISMINDEX_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
34 
35 namespace casacore { //# NAMESPACE CASACORE - BEGIN
36 
37 //# Forward declarations
38 class ISMBase;
39 class AipsIO;
40 
41 
42 // <summary>
43 // The Index of the Incremental Storage Manager
44 // </summary>
45 
46 // <use visibility=local>
47 
48 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
49 // </reviewed>
50 
51 // <prerequisite>
52 //# Classes you should understand before using this one.
53 // <li> <linkto class=ISMBase>ISMBase</linkto>
54 // </prerequisite>
55 
56 // <etymology>
57 // ISMIndex represents the index in the Incremental Storage Manager.
58 // </etymology>
59 
60 // <synopsis>
61 // ISMIndex maintains an index of all buckets in an ISM (Incremental Storage
62 // Manager). The index consists of the starting row number and the
63 // bucket number of each bucket in the BucketCache object of the ISM.
64 // When the ISM is opened, the entire index is read in and kept in memory.
65 // When the ISM is closed or flushed, the index is written back after
66 // all buckets in the file. A little header at the beginning of the file
67 // indicates the starting offset of the index.
68 // </synopsis>
69 
70 // <motivation>
71 // ISMIndex encapsulates all operations on the ISM index.
72 // </motivation>
73 
74 //# <todo asof="$DATE:$">
75 //# A List of bugs, limitations, extensions or planned refinements.
76 //# </todo>
77 
78 
79 class ISMIndex
80 {
81 public:
82  // Create a ISMIndex object with the given parent for a new table.
83  // It keeps the pointer to its parent (but does not own it).
84  explicit ISMIndex (ISMBase* parent);
85 
86  // The destructor closes the file (if opened).
87  ~ISMIndex();
88 
89  // Add a row.
90  void addRow (rownr_t nrrow);
91 
92  // Remove a row from the index.
93  // If the result of this is that the entire bucket gets empty,
94  // that bucketnr is returned. Otherwise -1 is returned.
95  Int removeRow (rownr_t rownr);
96 
97  // Get the bucket number for the given row.
98  // Also return the start row of the bucket and the number of rows in it.
99  uInt getBucketNr (rownr_t rownr, rownr_t& bucketStartRow,
100  rownr_t& bucketNrrow) const;
101 
102  // Read the bucket index from the AipsIO object.
103  void get (AipsIO& os);
104 
105  // Write the bucket index into the AipsIO object.
106  void put (AipsIO& os);
107 
108  // Add a bucket number to the index.
109  // Argument <src>rownr</src> gives the starting row of the bucket.
110  // It is used to add the bucket number at the correct place
111  // (such that the row numbers are kept in ascending order).
112  void addBucketNr (rownr_t rownr, uInt bucketNr);
113 
114  // Get the number of the next bucket from the index and return
115  // it in <src>bucketNr</src>. The starting row of that bucket and
116  // the number of rows in the bucket are also returned.
117  // Return status False indicates that no more buckets are available.
118  // <br>The start of the iteration is indicated by cursor=0.
119  // The first bucket returned is the bucket containing the rownr
120  // given in <src>bucketStartRow</src> (thus set bucketStartRow
121  // to 0 if you want to start at the first bucket).
122  // <br>The next iterations return the next bucket number and fill
123  // the starting row and number of rows.
124  Bool nextBucketNr (uInt& cursor, rownr_t& bucketStartRow,
125  rownr_t& bucketNrrow, uInt& bucketNr) const;
126 
127  // Show the index.
128  void show (std::ostream&) const;
129 
130 private:
131  // Forbid copy constructor.
132  ISMIndex (const ISMIndex&);
133 
134  // Forbid assignment.
135  ISMIndex& operator= (const ISMIndex&);
136 
137  // Get the index of the bucket containing the given row.
138  uInt getIndex (rownr_t rownr) const;
139 
140 
141  //# Declare member variables.
142  // Pointer to the parent storage manager.
144  // Number of entries used.
146  // Rownr index (i.e. row rows_p[i] starts in bucketNr_p[i]).
148  // Corresponding bucket number.
150 };
151 
152 
153 
154 
155 } //# NAMESPACE CASACORE - END
156 
157 #endif
void addRow(rownr_t nrrow)
Add a row.
int Int
Definition: aipstype.h:50
void addBucketNr(rownr_t rownr, uInt bucketNr)
Add a bucket number to the index.
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
The Index of the Incremental Storage Manager.
Definition: ISMIndex.h:79
Bool nextBucketNr(uInt &cursor, rownr_t &bucketStartRow, rownr_t &bucketNrrow, uInt &bucketNr) const
Get the number of the next bucket from the index and return it in bucketNr.
Base class of the Incremental Storage Manager.
Definition: ISMBase.h:87
ISMIndex & operator=(const ISMIndex &)
Forbid assignment.
ISMIndex(ISMBase *parent)
Create a ISMIndex object with the given parent for a new table.
Block< rownr_t > rows_p
Rownr index (i.e.
Definition: ISMIndex.h:147
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
uInt getBucketNr(rownr_t rownr, rownr_t &bucketStartRow, rownr_t &bucketNrrow) const
Get the bucket number for the given row.
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
uInt nused_p
Number of entries used.
Definition: ISMIndex.h:145
~ISMIndex()
The destructor closes the file (if opened).
Int removeRow(rownr_t rownr)
Remove a row from the index.
void put(AipsIO &os)
Write the bucket index into the AipsIO object.
Block< uInt > bucketNr_p
Corresponding bucket number.
Definition: ISMIndex.h:149
ISMBase * stmanPtr_p
Pointer to the parent storage manager.
Definition: ISMIndex.h:143
uInt getIndex(rownr_t rownr) const
Get the index of the bucket containing the given row.
void show(std::ostream &) const
Show the index.
unsigned int uInt
Definition: aipstype.h:51