00001 //# ConcatRows.h: Class holding the row numbers in a ConcatTable 00002 //# Copyright (C) 2008 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef TABLES_CONCATROWS_H 00029 #define TABLES_CONCATROWS_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/tables/Tables/RefRows.h> 00034 #include <casacore/casa/Containers/Block.h> 00035 00036 namespace casacore { //# NAMESPACE CASACORE - BEGIN 00037 00038 // <summary> 00039 // Class holding the row numbers in a ConcatTable 00040 // </summary> 00041 00042 // <use visibility=local> 00043 00044 // <reviewed reviewer="UNKNOWN" date="" tests="tConcatRows.cc"> 00045 // </reviewed> 00046 00047 // <prerequisite> 00048 //# Classes you should understand before using this one. 00049 // <li> <linkto class=Block>Block</linkto> 00050 // </prerequisite> 00051 00052 // <synopsis> 00053 // ConcatRows is used to hold the row numbers forming the concatenation 00054 // of oher tables. 00055 // table. It contains a vector which can hold the row numbers in 2 ways: 00056 // <ol> 00057 // <li> As a normal series of row numbers. This is used by e.g. class 00058 // <linkto class=ConcatTable>ConcatTable</linkto> 00059 // <li> As a series of Slices. In this case 3 subsequent entries 00060 // in the vector are used to represent start, end, and increment. 00061 // This is used by a function like <src>ScalarColumn::getColumnRange</src>. 00062 // </ol> 00063 // Class <linkto class=ConcatRowsIter>ConcatRowsIter</linkto> can be 00064 // used to iterate through a ConcatRows object. Each step in the iteration 00065 // goes to the next slice. If the ConcatRows object contains a simple series 00066 // of row numbers, each slice contains only one row number. 00067 // This can degrade performance, so it is possible to use shortcuts by 00068 // testing if the object contains slices (using <src>isSliced()</src>) 00069 // and getting the row number vector directly (using <src>rowVector()</src>). 00070 // </synopsis> 00071 00072 // <motivation> 00073 // ConcatRows is meant to have one class representing the various ways 00074 // of picking row numbers. This simplifies the interface of the table 00075 // and data manager classes dealing with getting/putting the data. 00076 // </motivation> 00077 00078 //# <todo asof="$DATE:$"> 00079 //# A List of bugs, limitations, extensions or planned concatinements. 00080 //# </todo> 00081 00082 00083 class ConcatRows 00084 { 00085 public: 00086 // Construct an empty block. 00087 ConcatRows() 00088 : itsRows (1,0), 00089 itsNTable (0), 00090 itsLastStRow (1), 00091 itsLastEndRow (0) 00092 {} 00093 00094 // Reserve the block for the given nr of tables. 00095 void reserve (uInt ntable) 00096 { itsRows.resize (ntable+1); } 00097 00098 // Add a table with the given nr of rows. 00099 void add (uInt nrow); 00100 00101 // Give the nr of tables. 00102 uInt ntable() const 00103 { return itsNTable; } 00104 00105 // Get the total nr of rows. 00106 uInt nrow() const 00107 { return itsRows[itsNTable]; } 00108 00109 // Give the nr of rows for the i-th table. 00110 uInt operator[] (uInt i) const 00111 { return itsRows[i+1]; } 00112 00113 // Give the offset for the i-th table. 00114 uInt offset (uInt i) const 00115 { return itsRows[i]; } 00116 00117 // Map an overall row number to a table and row number. 00118 void mapRownr (uInt& tableNr, uInt& tabRownr, uInt rownr) const 00119 { 00120 if (rownr < itsLastStRow || rownr >= itsLastEndRow) { 00121 findRownr (rownr); 00122 } 00123 tableNr = itsLastTableNr; 00124 tabRownr = rownr - itsLastStRow; 00125 } 00126 00127 private: 00128 // Find the row number and fill in the lastXX_p values. 00129 void findRownr (uInt rownr) const; 00130 00131 //# Data members. 00132 Block<uInt> itsRows; 00133 uInt itsNTable; 00134 mutable uInt itsLastStRow; //# Cached variables to spped up 00135 mutable uInt itsLastEndRow; //# function mapRownr(). 00136 mutable uInt itsLastTableNr; 00137 }; 00138 00139 00140 00141 // <summary> 00142 // Class to iterate through a ConcatRows object. 00143 // </summary> 00144 00145 // <use visibility=local> 00146 00147 // <reviewed reviewer="UNKNOWN" date="" tests="tConcatRows.cc"> 00148 // </reviewed> 00149 00150 // <prerequisite> 00151 //# Classes you should understand before using this one. 00152 // <li> <linkto class=ConcatRows>ConcatRows</linkto> 00153 // </prerequisite> 00154 00155 // <synopsis> 00156 // ConcatRowsSliceIter is useful to iterate through a 00157 // <linkto class=ConcatRows>ConcatRows</linkto> object. 00158 // It is possible to define for which row 00159 // especially if the ConcatRows object contains slices. 00160 // Each step in the iteration returns a Slice object containing 00161 // the next slice in the ConcatRows object. 00162 // <br> 00163 // It is used in Table and data manager classes (e.g. StManColumn). 00164 // </synopsis> 00165 00166 // <example> 00167 // This example shows how to iterate through a ConcatRows object 00168 // (giving a slice) and through each of the slices. 00169 // <srcblock> 00170 // void somefunc (const ConcatRows& rownrs) 00171 // // Iterate through all slices. 00172 // ConcatRowsSliceIter rowiter(rownrs); 00173 // while (! rowiter.pastEnd()) { 00174 // // Get start, end, and increment for this slice. 00175 // uInt rownr = rowiter.sliceStart(); 00176 // uInt end = rowiter.sliceEnd(); 00177 // uInt incr = rowiter.sliceIncr(); 00178 // // Iterate through the row numbers in the slice. 00179 // while (rownr <= end) { 00180 // rownr += incr; 00181 // } 00182 // // Go to next slice. 00183 // rowiter++; 00184 // } 00185 // } 00186 // </srcblock> 00187 // </example> 00188 00189 //# <todo asof="$DATE:$"> 00190 //# A List of bugs, limitations, extensions or planned concatinements. 00191 //# </todo> 00192 00193 00194 class ConcatRowsIter 00195 { 00196 public: 00197 // Construct the iterator on a ConcatRows object. 00198 // It is set to the full range. 00199 explicit ConcatRowsIter (const ConcatRows&); 00200 00201 // Construct the iterator on a ConcatRows object for the given row range. 00202 ConcatRowsIter (const ConcatRows&, uInt start, uInt end, uInt incr=1); 00203 00204 // Is the iterator past the end? 00205 Bool pastEnd() const 00206 { return itsPastEnd; } 00207 00208 // Go the next chunk. 00209 // <group> 00210 void operator++() 00211 { next(); } 00212 void operator++(int) 00213 { next(); } 00214 void next(); 00215 // </group> 00216 00217 // Get the current chunk. 00218 RefRows getChunk() const 00219 { return RefRows(itsChunk, True); } 00220 00221 // Get the nr of the table the current chunk is in. 00222 uInt tableNr() const 00223 { return itsPos; } 00224 00225 private: 00226 const ConcatRows* itsRows; 00227 Vector<uInt> itsChunk; 00228 uInt itsStart; 00229 uInt itsEnd; 00230 uInt itsIncr; 00231 uInt itsPos; 00232 Bool itsPastEnd; 00233 }; 00234 00235 00236 } //# NAMESPACE CASACORE - END 00237 00238 #endif