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