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
80
82 {
83 public:
84 // Construct an empty block.
86 : itsRows (1,0),
87 itsNTable (0),
88 itsLastStRow (1),
90 {}
91
92 // Reserve the block for the given nr of tables.
94 { itsRows.resize (ntable+1); }
95
96 // Add a table with the given nr of rows.
98
99 // Give the nr of tables.
100 uInt ntable() const
101 { return itsNTable; }
102
103 // Get the total nr of rows.
104 rownr_t nrow() const
105 { return itsRows[itsNTable]; }
106
107 // Give the nr of rows for the i-th table.
109 { return itsRows[i+1]; }
110
111 // Give the offset for the i-th table.
113 { return itsRows[i]; }
114
115 // Map an overall row number to a table and row number.
116 void mapRownr (uInt& tableNr, rownr_t& tabRownr, rownr_t rownr) const
117 {
118 if (rownr < itsLastStRow || rownr >= itsLastEndRow) {
119 findRownr (rownr);
120 }
121 tableNr = itsLastTableNr;
122 tabRownr = rownr - itsLastStRow;
123 }
124
125 private:
126 // Find the row number and fill in the lastXX_p values.
127 void findRownr (rownr_t rownr) const;
128
129 //# Data members.
132 mutable rownr_t itsLastStRow; //# Cached variables to spped up
133 mutable rownr_t itsLastEndRow; //# function mapRownr().
135 };
136
137
138
139 // <summary>
140 // Class to iterate through a ConcatRows object.
141 // </summary>
142
143 // <use visibility=local>
144
145 // <reviewed reviewer="UNKNOWN" date="" tests="tConcatRows.cc">
146 // </reviewed>
147
148 // <prerequisite>
149 //# Classes you should understand before using this one.
150 // <li> <linkto class=ConcatRows>ConcatRows</linkto>
151 // </prerequisite>
152
153 // <synopsis>
154 // ConcatRowsSliceIter is useful to iterate through a
155 // <linkto class=ConcatRows>ConcatRows</linkto> object.
156 // It is possible to define for which row
157// especially if the ConcatRows object contains slices.
158// Each step in the iteration returns a Slice object containing
159// the next slice in the ConcatRows object.
160// <br>
161// It is used in Table and data manager classes (e.g. StManColumn).
162// </synopsis>
163
164// <example>
165// This example shows how to iterate through a ConcatRows object
166// (giving a slice) and through each of the slices.
167// <srcblock>
168// void somefunc (const ConcatRows& rownrs)
169// // Iterate through all slices.
170// ConcatRowsSliceIter rowiter(rownrs);
171// while (! rowiter.pastEnd()) {
172// // Get start, end, and increment for this slice.
173// rownr_t rownr = rowiter.sliceStart();
174// rownr_t end = rowiter.sliceEnd();
175// rownr_t incr = rowiter.sliceIncr();
176// // Iterate through the row numbers in the slice.
177// while (rownr <= end) {
178// rownr += incr;
179// }
180// // Go to next slice.
181// rowiter++;
182// }
183// }
184// </srcblock>
185// </example>
186
187//# <todo asof="$DATE:$">
188//# A List of bugs, limitations, extensions or planned concatinements.
189//# </todo>
190
191
193 {
194 public:
195 // Construct the iterator on a ConcatRows object.
196 // It is set to the full range.
197 explicit ConcatRowsIter (const ConcatRows&);
198
199 // Construct the iterator on a ConcatRows object for the given row range.
200 ConcatRowsIter (const ConcatRows&, rownr_t start, rownr_t end, rownr_t incr=1);
201
202 // Is the iterator past the end?
203 Bool pastEnd() const
204 { return itsPastEnd; }
205
206 // Go the next chunk.
207 // <group>
209 { next(); }
210 void operator++(int)
211 { next(); }
212 void next();
213 // </group>
214
215 // Get the current chunk.
217 { return RefRows(itsChunk, True); }
218
219 // Get the nr of the table the current chunk is in.
220 uInt tableNr() const
221 { return itsTabNr; }
222
223 private:
231 };
232
233
234} //# NAMESPACE CASACORE - END
235
236#endif
simple 1-D array
Definition Block.h:198
void resize(size_t n, Bool forceSmaller=False, Bool copyElements=True)
Resizes the Block.
Definition Block.h:375
Class to iterate through a ConcatRows object.
Definition ConcatRows.h:193
RefRows getChunk() const
Get the current chunk.
Definition ConcatRows.h:216
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:208
uInt tableNr() const
Get the nr of the table the current chunk is in.
Definition ConcatRows.h:220
const ConcatRows * itsRows
Definition ConcatRows.h:224
ConcatRowsIter(const ConcatRows &)
Construct the iterator on a ConcatRows object.
Vector< rownr_t > itsChunk
Definition ConcatRows.h:225
Bool pastEnd() const
Is the iterator past the end?
Definition ConcatRows.h:203
rownr_t operator[](uInt i) const
Give the nr of rows for the i-th table.
Definition ConcatRows.h:108
ConcatRows()
Construct an empty block.
Definition ConcatRows.h:85
void reserve(uInt ntable)
Reserve the block for the given nr of tables.
Definition ConcatRows.h:93
uInt ntable() const
Give the nr of tables.
Definition ConcatRows.h:100
rownr_t offset(uInt i) const
Give the offset for the i-th table.
Definition ConcatRows.h:112
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:116
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:104
void findRownr(rownr_t rownr) const
Find the row number and fill in the lastXX_p values.
Block< rownr_t > itsRows
Definition ConcatRows.h:130
this file contains all the compiler specific defines
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
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44