VTK
vtkExodusIICache.h
Go to the documentation of this file.
1 #ifndef vtkExodusIICache_h
2 #define vtkExodusIICache_h
3 
4 // ============================================================================
5 // The following classes define an LRU cache for data arrays
6 // loaded by the Exodus reader. Here's how they work:
7 //
8 // The actual cache consists of two STL containers: a set of
9 // cache entries (vtkExodusIICacheEntry) and a list of
10 // cache references (vtkExodusIICacheRef). The entries in
11 // these containers are sorted for fast retrieval:
12 // 1. The cache entries are indexed by the timestep, the
13 // object type (edge block, face set, ...), and the
14 // object ID (if one exists). When you call Find() to
15 // retrieve a cache entry, you provide a key containing
16 // this information and the array is returned if it exists.
17 // 2. The list of cache references are stored in "least-recently-used"
18 // order. The least recently referenced array is the first in
19 // the list. Whenever you request an entry with Find(), it is
20 // moved to the back of the list if it exists.
21 // This makes retrieving arrays O(n log n) and popping LRU
22 // entries O(1). Each cache entry stores an iterator into
23 // the list of references so that it can be located quickly for
24 // removal.
25 
26 #include "vtkIOExodusModule.h" // For export macro
27 #include "vtkObject.h"
28 
29 #include <map> // used for cache storage
30 #include <list> // use for LRU ordering
31 
32 //BTX
34 {
35 public:
36  int Time;
38  int ObjectId;
39  int ArrayId;
41  {
42  Time = -1;
43  ObjectType = -1;
44  ObjectId = -1;
45  ArrayId = -1;
46  }
47  vtkExodusIICacheKey( int time, int objType, int objId, int arrId )
48  {
49  Time = time;
50  ObjectType = objType;
51  ObjectId = objId;
52  ArrayId = arrId;
53  }
55  {
56  Time = src.Time;
57  ObjectType = src.ObjectType;
58  ObjectId = src.ObjectId;
59  ArrayId = src.ArrayId;
60  }
61  vtkExodusIICacheKey& operator = ( const vtkExodusIICacheKey& src )
62  {
63  Time = src.Time;
64  ObjectType = src.ObjectType;
65  ObjectId = src.ObjectId;
66  ArrayId = src.ArrayId;
67  return *this;
68  }
69  bool match( const vtkExodusIICacheKey&other, const vtkExodusIICacheKey& pattern ) const
70  {
71  if ( pattern.Time && this->Time != other.Time )
72  return false;
73  if ( pattern.ObjectType && this->ObjectType != other.ObjectType )
74  return false;
75  if ( pattern.ObjectId && this->ObjectId != other.ObjectId )
76  return false;
77  if ( pattern.ArrayId && this->ArrayId != other.ArrayId )
78  return false;
79  return true;
80  }
81  bool operator < ( const vtkExodusIICacheKey& other ) const
82  {
83  if ( this->Time < other.Time )
84  return true;
85  else if ( this->Time > other.Time )
86  return false;
87  if ( this->ObjectType < other.ObjectType )
88  return true;
89  else if ( this->ObjectType > other.ObjectType )
90  return false;
91  if ( this->ObjectId < other.ObjectId )
92  return true;
93  else if ( this->ObjectId > other.ObjectId )
94  return false;
95  if ( this->ArrayId < other.ArrayId )
96  return true;
97  return false;
98  }
99 };
100 
102 class vtkExodusIICache;
104 
105 typedef std::map<vtkExodusIICacheKey,vtkExodusIICacheEntry*> vtkExodusIICacheSet;
106 typedef std::map<vtkExodusIICacheKey,vtkExodusIICacheEntry*>::iterator vtkExodusIICacheRef;
107 typedef std::list<vtkExodusIICacheRef> vtkExodusIICacheLRU;
108 typedef std::list<vtkExodusIICacheRef>::iterator vtkExodusIICacheLRURef;
109 
111 {
112 public:
116 
118 
119  vtkDataArray* GetValue() { return this->Value; }
120 
121 protected:
124 
125  friend class vtkExodusIICache;
126 };
127 //ETX
128 
130 {
131 public:
132  static vtkExodusIICache* New();
134  void PrintSelf( ostream& os, vtkIndent indent );
135 
137  void Clear();
138 
140  void SetCacheCapacity( double sizeInMiB );
141 
146  double GetSpaceLeft()
147  { return this->Capacity - this->Size; }
148 
152  int ReduceToSize( double newSize );
153 
154  //BTX
156  void Insert( vtkExodusIICacheKey& key, vtkDataArray* value );
157 
162 
167  int Invalidate( vtkExodusIICacheKey key );
168 
178  int Invalidate( vtkExodusIICacheKey key, vtkExodusIICacheKey pattern );
179  //ETX
180 
181 protected:
184 
186  ~vtkExodusIICache();
187 
188 
190  void RecomputeSize();
191 
193  double Capacity;
194 
196  double Size;
197 
198  //BTX
206 
209  //ETX
210 
211 private:
212  vtkExodusIICache( const vtkExodusIICache& ); // Not implemented
213  void operator = ( const vtkExodusIICache& ); // Not implemented
214 };
215 #endif // vtkExodusIICache_h
std::list< vtkExodusIICacheRef >::iterator vtkExodusIICacheLRURef
bool match(const vtkExodusIICacheKey &other, const vtkExodusIICacheKey &pattern) const
vtkExodusIICacheSet Cache
A least-recently-used (LRU) cache to hold arrays.
abstract base class for most VTK objects
Definition: vtkObject.h:61
double Size
The current size of the cache (i.e., the size of the all the arrays it currently contains) in MiB...
std::list< vtkExodusIICacheRef > vtkExodusIICacheLRU
double GetSpaceLeft()
See how much cache space is left.
vtkExodusIICacheLRURef LRUEntry
double Capacity
The capacity of the cache (i.e., the maximum size of all arrays it contains) in MiB.
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
std::map< vtkExodusIICacheKey, vtkExodusIICacheEntry * > vtkExodusIICacheSet
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkExodusIICacheKey(int time, int objType, int objId, int arrId)
vtkExodusIICacheLRU LRU
The actual LRU list (indices into the cache ordered least to most recently used). ...
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
#define VTKIOEXODUS_EXPORT
vtkDataArray * GetValue()
vtkExodusIICacheKey(const vtkExodusIICacheKey &src)
static vtkObject * New()
std::map< vtkExodusIICacheKey, vtkExodusIICacheEntry * >::iterator vtkExodusIICacheRef