casacore
Loading...
Searching...
No Matches
ColumnCache.h
Go to the documentation of this file.
1//# ColumnCache.h: A caching object for a table column
2//# Copyright (C) 1997
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_COLUMNCACHE_H
27#define TABLES_COLUMNCACHE_H
28
29
30//# Includes
31#include <cassert>
32#include <limits>
33
34#include <casacore/casa/aips.h>
35
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39// <summary>
40// A caching object for a table column.
41// </summary>
42
43// <use visibility=local>
44
45// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
46// </reviewed>
47
48// <prerequisite>
49//# Classes you should understand before using this one.
50// <li> <linkto class=ScalarColumn>ScalarColumn</linkto>
51// </prerequisite>
52
53// <synopsis>
54// ColumnCache acts as a cache for a table column.
55// It contains a pointer to data and the start and end row number
56// for which these data are valid. An increment is part of the object
57// and is usually 0 or 1. The value 0 is used for data which is
58// valid for multiple rows (as used in
59// <linkto class=IncrementalStMan>IncrementalStMan</linkto>).
60// The value 1 is used for data stored consecutevily in a buffer for
61// each row (as used in <linkto class=StManAipsIO>StManAipsIO</linkto>).
62// <p>
63// The ColumnCache object is created and updated by the data manager.
64// The top level <linkto class=ScalarColumn>ScalarColumn</linkto> object
65// contains a pointer to the cache object. In this way the
66// <src>ScalarColumn::get</src> can often be executed by a few inlined
67// statements which improves performance considerably.
68// <p>
69// The <src>invalidate</src> function can be used to invalidate the
70// cache. This is for instance needed when a table lock is acquired
71// or released to be sure that the cache gets refreshed.
72// </synopsis>
73
74// <motivation>
75// This class was developed to improve the performance for getting a scalar.
76// </motivation>
77
78// <todo asof="$DATE:$">
79// <li>For ConcatColumn add the ability to have other ColumnCache objects
80// using this one and invalidate them as well.
81// </todo>
82
83
85{
86public:
87 // Constructor.
88 // It sets the increment to 1 and calls invalidate.
90
91 // Set the increment to the given value.
92 void setIncrement (rownr_t increment);
93
94 // Set the start and end row number for which the given data pointer
95 // is valid.
96 void set (rownr_t startRow, rownr_t endRow, const void* dataPtr);
97
98 // Invalidate the cache.
99 // This clears the data pointer and sets startRow>endRow.
100 void invalidate();
101
102 // Calculate the offset in the cached data for the given row.
103 // -1 is returned if the row is not within the cached rows.
104 Int64 offset (rownr_t rownr) const;
105
106 // Give a pointer to the data.
107 // The calling function has to do a proper cast after which the
108 // calculated offset can be added to get the proper data.
109 const void* dataPtr() const;
110
111 // Give the start, end (including), and increment row number
112 // of the cached column values.
114 { return itsStart; }
115 rownr_t end() const
116 { return itsEnd; }
117 rownr_t incr() const
118 { return itsIncr; }
119
120private:
124 const void* itsData;
125};
126
127
128inline void ColumnCache::setIncrement (rownr_t increment)
129{
130 itsIncr = increment;
131}
132
134{
135 set (1, 0, 0);
136}
137
139{
140 if (rownr < itsStart || rownr > itsEnd) {
141 return -1;
142 }
143 const rownr_t offset = (rownr - itsStart) * itsIncr;
144 assert(offset <= static_cast<rownr_t>(std::numeric_limits<Int64>::max()));
145 return Int64(offset);
146}
147
148inline const void* ColumnCache::dataPtr() const
149{
150 return itsData;
151}
152
153
154} //# NAMESPACE CASACORE - END
155
156#endif
Int64 offset(rownr_t rownr) const
Calculate the offset in the cached data for the given row.
rownr_t end() const
void setIncrement(rownr_t increment)
Set the increment to the given value.
const void * dataPtr() const
Give a pointer to the data.
rownr_t start() const
Give the start, end (including), and increment row number of the cached column values.
rownr_t incr() const
void invalidate()
Invalidate the cache.
void set(rownr_t startRow, rownr_t endRow, const void *dataPtr)
Set the start and end row number for which the given data pointer is valid.
ColumnCache()
Constructor.
this file contains all the compiler specific defines
Definition mainpage.dox:28
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44