BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Event/GeneratorObject/include/DataModel/DataPool.h
Go to the documentation of this file.
1#ifndef DATAMODEL_DATAPOOL_H
2#define DATAMODEL_DATAPOOL_H
3/** @class DataPool
4 * @brief a typed memory pool that saves time spent
5 * allocation small object. This is typically used
6 * by container such as DataVector and DataList
7 * @author Srini Rajagopalan - ATLAS Collaboration
8 *$Id: DataPool.h,v 1.5 2003/08/19 23:52:06 calaf Exp $
9 */
10
11#ifndef _CPP_VECTOR
12# include <vector>
13#endif
14#ifndef _CPP_STRING
15# include <string>
16#endif
17#ifndef GAUDIKERNEL_SYSTEM_H
18# include "GaudiKernel/System.h"
19#endif
20#ifndef INTERFACES_IINCIDENTSVC_H
21# include "GaudiKernel/IIncidentSvc.h"
22#endif
23#ifndef KERNEL_STATUSCODES_H
24# include "GaudiKernel/StatusCode.h"
25#endif
26#ifndef GAUDIKERNEL_IINCIDENTLISTENER_H
27# include "GaudiKernel/IIncidentListener.h"
28#endif
29
30template <typename VALUE> class DataPool : virtual public IIncidentListener {
31public:
32 typedef std::vector<VALUE*> Pool; // FIXME should be DataVector!
33 typedef typename Pool::size_type size_type;
34 typedef typename Pool::pointer pointer;
35 typedef typename Pool::reference reference;
36 typedef typename Pool::iterator iterator;
37 typedef typename Pool::const_iterator const_iterator;
38
39 //////////////////////////////////////////////////////////////////////
40 /// Constructors:
41 //////////////////////////////////////////////////////////////////////
42
43 /// default constructor will initialize the pool with m_minRefCount
45
47
48 DataPool<VALUE>( int n );
49
50 virtual ~DataPool<VALUE>();
51 ///////////////////////////////////////////////////////
52
53 /// set size of pool:
54 void setSize( unsigned int size );
55
56 /// reset refCount... but not maxRefCount.
57 void reset();
58
59 /// erase the pool and initializes m_minRefCount default elements
60 void erase();
61
62 /// return capacity of pool
63 unsigned int capacity() { return m_pool.capacity(); }
64
65 /// return size already allocated
66 unsigned int allocated() { return m_refCount; }
67
68 /// begin iterators over pool
71
72 /// the end() method will allow looping over only valid elements
73 /// and not over ALL elements of the pool
76
77 /// obtain the next available element in pool by pointer
78 /// return as void* to minimize misuse, client usage is:
79 /// MyElement* m = new(pool->mem) MyElement(...); // pool is ptr
80 void* mem();
81
82 /// can also say:
83 /// MyElement* m = new ((*pool)()) MyElement(...); // pool = pointer
84 /// MyElement* m = new (pool()) MyElement(...); // pool = value
85 void* operator()();
86
87 /// typename of pool
88 static const std::string& typeName();
89
90 /// initialization
91 void initialize();
92
93 /// incident service handle
94 void handle( const Incident& );
95
96 /// methods to adhere to IInterface:
97 virtual unsigned long addRef();
98 virtual unsigned long release();
99 virtual StatusCode queryInterface( const InterfaceID& riid, void** ppvInterface );
100 //-----------------------------------------------------------//
101
102protected:
103 /// should we allow clients to get a reference?
104 /// obtain the next available element in pool by reference
105 /// pool is resized if reached its limit
107
108 /// resize pool if usage exceeds capacity:
110
111 //-----------------------------------------------------------//
112
113private:
114 /// minimum number of elements in pool
115 static const unsigned int m_minRefCount = 1024;
116
117 /// maximum elements in pool... can grow.
118 unsigned int m_maxRefCount;
119
120 /// refCount how many pool elements are in use
121 unsigned int m_refCount;
122
123 /// Pool:
124 Pool m_pool;
125
126 /// Incident Service
127 IIncidentSvc* m_pIncSvc;
128
129 /// reference counting to satisfy IInterface
130 unsigned long m_instanceCount;
131};
132
133#include "DataModel/DataPool.icc"
134
135#endif
const Int_t n
void * mem()
reference nextElementRef()
iterator begin()
begin iterators over pool
iterator end()
static const std::string & typeName()
typename of pool
DataPool()
Constructors:
void * operator()()
virtual unsigned long addRef()
methods to adhere to IInterface:
const_iterator end() const
void handle(const Incident &)
incident service handle
virtual unsigned long release()
unsigned int capacity()
return capacity of pool
virtual ~DataPool()
void initialize()
initialization
unsigned int allocated()
return size already allocated
void reset()
reset refCount... but not maxRefCount.
void resizePool()
resize pool if usage exceeds capacity:
void erase()
erase the pool and initializes m_minRefCount default elements
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
const_iterator begin() const
void setSize(unsigned int size)
set size of pool: