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