casacore
Loading...
Searching...
No Matches
TableCache.h
Go to the documentation of this file.
1//# TableCache.h: Cache of open tables
2//# Copyright (C) 1994,1995,1997,1999
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_TABLECACHE_H
27#define TABLES_TABLECACHE_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/casa/IO/FileLocker.h>
33
34#include <map>
35#include <mutex>
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39//# Forward Declarations
40class PlainTable;
41class TableLock;
42
43// <summary>
44// Cache of open tables
45// </summary>
46
47// <use visibility=local>
48
49// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
50// </reviewed>
51
52// <prerequisite>
53//# Classes you should understand before using this one.
54// </prerequisite>
55
56// <etymology>
57// TableCache represents a cache of open tables.
58// </etymology>
59
60// <synopsis>
61// A TableCache object keeps track of the tables which have already
62// been opened in a program. It maps the name of a table to its
63// PlainTable object.
64// In principle only one TableCache object (statically defined in
65// class PlainTable) exists in a process.
66// The cache is used to prevent a table from being opened more than
67// once, which is not only a waste of space, but more importantly,
68// may give rise to synchronization problems.
69// Synchronization between the same table in multiple processes must
70// be done by a locking mechanism.
71//
72// TableCache is used by class Table and PlainTable.
73// Before opening a table, Table will first look in the cache.
74// Newly opened or created tables will be added to the cache.
75// When a table is actually closed, it will be removed from the cache.
76// </synopsis>
77
78// <motivation>
79// When a RefTable is read back, it will also read back the table it
80// references. However, that table may have been opened before and
81// it is bad to have a table open more than once in the same program.
82// The TableCache class catches this and will not reopen the table.
83// </motivation>
84
85// <todo asof="$DATE:$">
86//# A List of bugs, limitations, extensions or planned refinements.
87// <li> Currently only PlainTables are taken into account.
88// Maybe RefTables should be too.
89// </todo>
90
91
93{
94public:
95
96 // Construct an empty cache of open tables.
98
100
101 // The copy constructor is forbidden.
102 TableCache (const TableCache&) = delete;
103
104 // The assignment operator is forbidden.
106
107 // Try to find a table with the given name in the cache.
108 // Return a pointer to a table if found (thus if already open).
109 // Return a zero pointer if not found.
110 PlainTable* operator() (const String& tableName) const;
111
112 // Add an open table to the cache.
113 void define (const String& tableName, PlainTable*);
114
115 // Remove an open table.
116 void remove (const String& tableName);
117
118 // Rename an open table.
119 // If oldName is not in the cache, nothing will be done.
120 void rename (const String& newName, const String& oldName);
121
122 // Determine the number of locked tables opened with the AutoLock option
123 // (Locked table means locked for read and/or write).
125
126 // Unlock locked tables opened with the AutoLock option.
127 // If <src>all=True</src> all such tables will be unlocked.
128 // If <src>all=False</src> only tables requested by another process
129 // will be unlocked.
131
132 // Get the names of the tables in the cache.
134
135 // Get the names of tables locked in this process.
136 // By default all locked tables are given (note that a write lock
137 // implies a read lock), but it is possible to select on lock type
138 // FileLocker::Write and on option (TableLock::AutoLocking,
139 // TableLock::ReadLocking, or TableLock::PermanentLocking).
141 int lockOption);
142
143 // Flush a possibly cached Table.
144 void flushTable (const String& tableName,
145 Bool fsync, Bool recursive);
146
147 // Look in the cache if the table is already open.
148 // If so, check if table option matches.
149 // If needed reopen the table for read/write and merge the lock options.
150 PlainTable* lookCache (const String& name, int tableOption,
151 const TableLock& tableInfo);
152
153private:
154 // Get the table without doing a mutex lock (for operator()).
155 PlainTable* getTable (const String& tableName) const;
156
157 //# void* iso. PlainTable* is used in the map declaration
158 //# to reduce the number of template instantiations.
159 //# The .cc file will use (fully safe) casts.
160 std::map<String,void*> tableMap_p;
161 //# A mutex to synchronize access to the cache.
162 mutable std::mutex itsMutex;
163};
164
165
166
167} //# NAMESPACE CASACORE - END
168
169#endif
LockType
Define the possible lock types.
Definition FileLocker.h:93
String: the storage and methods of handling collections of characters.
Definition String.h:223
PlainTable * operator()(const String &tableName) const
Try to find a table with the given name in the cache.
void relinquishAutoLocks(Bool all)
Unlock locked tables opened with the AutoLock option.
TableCache & operator=(const TableCache &)=delete
The assignment operator is forbidden.
PlainTable * getTable(const String &tableName) const
Get the table without doing a mutex lock (for operator()).
Vector< String > getLockedTables(FileLocker::LockType, int lockOption)
Get the names of tables locked in this process.
Vector< String > getTableNames() const
Get the names of the tables in the cache.
TableCache()
Construct an empty cache of open tables.
std::map< String, void * > tableMap_p
Definition TableCache.h:160
uInt nAutoLocks()
Determine the number of locked tables opened with the AutoLock option (Locked table means locked for ...
void rename(const String &newName, const String &oldName)
Rename an open table.
PlainTable * lookCache(const String &name, int tableOption, const TableLock &tableInfo)
Look in the cache if the table is already open.
TableCache(const TableCache &)=delete
The copy constructor is forbidden.
void define(const String &tableName, PlainTable *)
Add an open table to the cache.
void flushTable(const String &tableName, Bool fsync, Bool recursive)
Flush a possibly cached Table.
void remove(const String &tableName)
Remove an open table.
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
LatticeExprNode all(const LatticeExprNode &expr)