casacore
Loading...
Searching...
No Matches
ConcatRows.h
Go to the documentation of this file.
1// # ConcatRows.h: Class holding the row numbers in a ConcatTable
2// # Copyright (C) 2008
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_CONCATROWS_H
27#define TABLES_CONCATROWS_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/RefRows.h>
32#include <casacore/casa/Containers/Block.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Class holding the row numbers in a ConcatTable
38// </summary>
39
40// <use visibility=local>
41
42// <reviewed reviewer="UNKNOWN" date="" tests="tConcatRows.cc">
43// </reviewed>
44
45// <prerequisite>
46// # Classes you should understand before using this one.
47// <li> <linkto class=Block>Block</linkto>
48// </prerequisite>
49
50// <synopsis>
51// ConcatRows is used to hold the row numbers forming the concatenation
52// of oher tables.
53// table. It contains a vector which can hold the row numbers in 2 ways:
54// <ol>
55// <li> As a normal series of row numbers. This is used by e.g. class
56// <linkto class=ConcatTable>ConcatTable</linkto>
57// <li> As a series of Slices. In this case 3 subsequent entries
58// in the vector are used to represent start, end, and increment.
59// This is used by a function like <src>ScalarColumn::getColumnRange</src>.
60// </ol>
61// Class <linkto class=ConcatRowsIter>ConcatRowsIter</linkto> can be
62// used to iterate through a ConcatRows object. Each step in the iteration
63// goes to the next slice. If the ConcatRows object contains a simple series
64// of row numbers, each slice contains only one row number.
65// This can degrade performance, so it is possible to use shortcuts by
66// testing if the object contains slices (using <src>isSliced()</src>)
67// and getting the row number vector directly (using <src>rowVector()</src>).
68// </synopsis>
69
70// <motivation>
71// ConcatRows is meant to have one class representing the various ways
72// of picking row numbers. This simplifies the interface of the table
73// and data manager classes dealing with getting/putting the data.
74// </motivation>
75
76// # <todo asof="$DATE:$">
77// # A List of bugs, limitations, extensions or planned concatinements.
78// # </todo>
79
81 public:
82 // Construct an empty block.
84
85 // Reserve the block for the given nr of tables.
86 void reserve(uInt ntable) { itsRows.resize(ntable + 1); }
87
88 // Add a table with the given nr of rows.
90
91 // Give the nr of tables.
92 uInt ntable() const { return itsNTable; }
93
94 // Get the total nr of rows.
95 rownr_t nrow() const { return itsRows[itsNTable]; }
96
97 // Give the nr of rows for the i-th table.
98 rownr_t operator[](uInt i) const { return itsRows[i + 1]; }
99
100 // Give the offset for the i-th table.
101 rownr_t offset(uInt i) const { return itsRows[i]; }
102
103 // Map an overall row number to a table and row number.
104 void mapRownr(uInt& tableNr, rownr_t& tabRownr, rownr_t rownr) const {
105 if (rownr < itsLastStRow || rownr >= itsLastEndRow) {
106 findRownr(rownr);
107 }
108 tableNr = itsLastTableNr;
109 tabRownr = rownr - itsLastStRow;
110 }
111
112 private:
113 // Find the row number and fill in the lastXX_p values.
114 void findRownr(rownr_t rownr) const;
115
116 // # Data members.
119 mutable rownr_t itsLastStRow; // # Cached variables to spped up
120 mutable rownr_t itsLastEndRow; // # function mapRownr().
122};
123
124// <summary>
125// Class to iterate through a ConcatRows object.
126// </summary>
127
128// <use visibility=local>
129
130// <reviewed reviewer="UNKNOWN" date="" tests="tConcatRows.cc">
131// </reviewed>
132
133// <prerequisite>
134// # Classes you should understand before using this one.
135// <li> <linkto class=ConcatRows>ConcatRows</linkto>
136// </prerequisite>
137
138// <synopsis>
139// ConcatRowsSliceIter is useful to iterate through a
140// <linkto class=ConcatRows>ConcatRows</linkto> object.
141// It is possible to define for which row
142// especially if the ConcatRows object contains slices.
143// Each step in the iteration returns a Slice object containing
144// the next slice in the ConcatRows object.
145// <br>
146// It is used in Table and data manager classes (e.g. StManColumn).
147// </synopsis>
148
149// <example>
150// This example shows how to iterate through a ConcatRows object
151// (giving a slice) and through each of the slices.
152// <srcblock>
153// void somefunc (const ConcatRows& rownrs)
154// // Iterate through all slices.
155// ConcatRowsSliceIter rowiter(rownrs);
156// while (! rowiter.pastEnd()) {
157// // Get start, end, and increment for this slice.
158// rownr_t rownr = rowiter.sliceStart();
159// rownr_t end = rowiter.sliceEnd();
160// rownr_t incr = rowiter.sliceIncr();
161// // Iterate through the row numbers in the slice.
162// while (rownr <= end) {
163// rownr += incr;
164// }
165// // Go to next slice.
166// rowiter++;
167// }
168// }
169// </srcblock>
170// </example>
171
172// # <todo asof="$DATE:$">
173// # A List of bugs, limitations, extensions or planned concatinements.
174// # </todo>
175
177 public:
178 // Construct the iterator on a ConcatRows object.
179 // It is set to the full range.
180 explicit ConcatRowsIter(const ConcatRows&);
181
182 // Construct the iterator on a ConcatRows object for the given row range.
184
185 // Is the iterator past the end?
186 Bool pastEnd() const { return itsPastEnd; }
187
188 // Go the next chunk.
189 // <group>
190 void operator++() { next(); }
191 void operator++(int) { next(); }
192 void next();
193 // </group>
194
195 // Get the current chunk.
196 RefRows getChunk() const { return RefRows(itsChunk, True); }
197
198 // Get the nr of the table the current chunk is in.
199 uInt tableNr() const { return itsTabNr; }
200
201 private:
209};
210
211} // namespace casacore
212
213#endif
RefRows getChunk() const
Get the current chunk.
Definition ConcatRows.h:196
ConcatRowsIter(const ConcatRows &, rownr_t start, rownr_t end, rownr_t incr=1)
Construct the iterator on a ConcatRows object for the given row range.
void operator++()
Go the next chunk.
Definition ConcatRows.h:190
uInt tableNr() const
Get the nr of the table the current chunk is in.
Definition ConcatRows.h:199
const ConcatRows * itsRows
Definition ConcatRows.h:202
ConcatRowsIter(const ConcatRows &)
Construct the iterator on a ConcatRows object.
Vector< rownr_t > itsChunk
Definition ConcatRows.h:203
Bool pastEnd() const
Is the iterator past the end?
Definition ConcatRows.h:186
rownr_t operator[](uInt i) const
Give the nr of rows for the i-th table.
Definition ConcatRows.h:98
ConcatRows()
Construct an empty block.
Definition ConcatRows.h:83
void reserve(uInt ntable)
Reserve the block for the given nr of tables.
Definition ConcatRows.h:86
uInt ntable() const
Give the nr of tables.
Definition ConcatRows.h:92
rownr_t offset(uInt i) const
Give the offset for the i-th table.
Definition ConcatRows.h:101
void mapRownr(uInt &tableNr, rownr_t &tabRownr, rownr_t rownr) const
Map an overall row number to a table and row number.
Definition ConcatRows.h:104
void add(rownr_t nrow)
Add a table with the given nr of rows.
rownr_t nrow() const
Get the total nr of rows.
Definition ConcatRows.h:95
void findRownr(rownr_t rownr) const
Find the row number and fill in the lastXX_p values.
Block< rownr_t > itsRows
Definition ConcatRows.h:117
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
iterator end()
Definition Block.h:601
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44