Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
G4TAtomicHitsMap< T > Class Template Reference

This is an implementation of G4THitsMap<T> where the underlying type is G4atomic<T>, not just T. More...

#include <Doxymodules_parallel.h>

Inheritance diagram for G4TAtomicHitsMap< T >:
G4VHitsCollection

Public Types

typedef G4atomic< T > value_type
 
typedef value_typemapped_type
 
typedef std::map< G4int, mapped_typecontainer_type
 
typedef container_type::iterator iterator
 
typedef container_type::const_iterator const_iterator
 

Public Member Functions

 G4TAtomicHitsMap ()
 
 G4TAtomicHitsMap (G4String detName, G4String colNam)
 
virtual ~G4TAtomicHitsMap ()
 
G4bool operator== (const G4TAtomicHitsMap< T > &right) const
 
G4TAtomicHitsMap< T > & operator+= (const G4TAtomicHitsMap< T > &right) const
 
G4TAtomicHitsMap< T > & operator+= (const G4THitsMap< T > &right) const
 
virtual void DrawAllHits ()
 
virtual void PrintAllHits ()
 
value_typeoperator[] (G4int key) const
 
container_typeGetMap () const
 
G4int add (const G4int &key, value_type *&aHit) const
 
G4int add (const G4int &key, T &aHit) const
 
G4int set (const G4int &key, value_type *&aHit) const
 
G4int set (const G4int &key, T &aHit) const
 
G4int entries () const
 
void clear ()
 
virtual G4VHitGetHit (size_t) const
 
virtual size_t GetSize () const
 
virtual size_t size () const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
iterator find (G4int p)
 
const_iterator find (G4int p) const
 

Private Attributes

container_typetheCollection
 
G4Mutex fMutex
 

Detailed Description

template<typename T>
class G4TAtomicHitsMap< T >

This is an implementation of G4THitsMap<T> where the underlying type is G4atomic<T>, not just T.

A static assert is provided to ensure that T is fundamental. This class should be used in lieu of G4THitsMap<T> when memory is a concern. Atomics are thread-safe and generally faster that mutexes (as long as the STL implementation is lock-free) but the synchronization does not come without a cost. If performance is the primary concern, use G4THitsMap<T> in thread-local instances.

Definition at line 142 of file Doxymodules_parallel.h.

Member Typedef Documentation

◆ value_type

template<typename T >
typedef G4atomic<T> G4TAtomicHitsMap< T >::value_type

Definition at line 76 of file G4TAtomicHitsMap.hh.

◆ mapped_type

template<typename T >
typedef value_type* G4TAtomicHitsMap< T >::mapped_type

Definition at line 77 of file G4TAtomicHitsMap.hh.

◆ container_type

template<typename T >
typedef std::map<G4int, mapped_type> G4TAtomicHitsMap< T >::container_type

Definition at line 78 of file G4TAtomicHitsMap.hh.

◆ iterator

template<typename T >
typedef container_type::iterator G4TAtomicHitsMap< T >::iterator

Definition at line 79 of file G4TAtomicHitsMap.hh.

◆ const_iterator

template<typename T >
typedef container_type::const_iterator G4TAtomicHitsMap< T >::const_iterator

Definition at line 80 of file G4TAtomicHitsMap.hh.

Constructor & Destructor Documentation

◆ G4TAtomicHitsMap() [1/2]

template<typename T >
G4TAtomicHitsMap< T >::G4TAtomicHitsMap ( )

Definition at line 145 of file G4TAtomicHitsMap.hh.

147{}
container_type * theCollection
std::map< G4int, mapped_type > container_type

◆ G4TAtomicHitsMap() [2/2]

template<typename T >
G4TAtomicHitsMap< T >::G4TAtomicHitsMap ( G4String  detName,
G4String  colNam 
)

Definition at line 150 of file G4TAtomicHitsMap.hh.

151 : G4VHitsCollection(detName, colNam)
153{}

◆ ~G4TAtomicHitsMap()

template<typename T >
G4TAtomicHitsMap< T >::~G4TAtomicHitsMap ( )
virtual

Definition at line 156 of file G4TAtomicHitsMap.hh.

157{
158 for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
159 delete itr->second;
160
161 delete theCollection;
162}

Member Function Documentation

◆ operator==()

template<typename T >
G4bool G4TAtomicHitsMap< T >::operator== ( const G4TAtomicHitsMap< T > &  right) const

Definition at line 165 of file G4TAtomicHitsMap.hh.

166{
167 return (collectionName == right.collectionName);
168}

◆ operator+=() [1/2]

template<typename T >
G4TAtomicHitsMap< T > & G4TAtomicHitsMap< T >::operator+= ( const G4TAtomicHitsMap< T > &  right) const

Definition at line 171 of file G4TAtomicHitsMap.hh.

173{
174 for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
175 add(itr->first, *(itr->second));
176
177 return (G4TAtomicHitsMap<T>&) (*this);
178}
This is an implementation of G4THitsMap<T> where the underlying type is G4atomic<T>,...
G4int add(const G4int &key, value_type *&aHit) const

◆ operator+=() [2/2]

template<typename T >
G4TAtomicHitsMap< T > & G4TAtomicHitsMap< T >::operator+= ( const G4THitsMap< T > &  right) const

Definition at line 181 of file G4TAtomicHitsMap.hh.

183{
184 for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
185 add(itr->first, *(itr->second));
186
187 return (G4TAtomicHitsMap<T>&) (*this);
188}

◆ DrawAllHits()

template<typename T >
void G4TAtomicHitsMap< T >::DrawAllHits ( )
virtual

Definition at line 268 of file G4TAtomicHitsMap.hh.

269{}

◆ PrintAllHits()

template<typename T >
void G4TAtomicHitsMap< T >::PrintAllHits ( )
virtual

Definition at line 272 of file G4TAtomicHitsMap.hh.

273{
274 G4cout << "G4TAtomicHitsMap " << SDname << " / " << collectionName << " --- "
275 << entries() << " entries" << G4endl;
276}
G4int entries() const

◆ operator[]()

template<typename T >
G4TAtomicHitsMap< T >::value_type * G4TAtomicHitsMap< T >::operator[] ( G4int  key) const
inline

Definition at line 192 of file G4TAtomicHitsMap.hh.

194{
195 if(theCollection->find(key) != theCollection->end())
196 return theCollection->find(key)->second;
197 else
198 {
199 G4AutoLock l(&fMutex);
200 if(theCollection->find(key) == theCollection->end())
201 {
202 value_type* ptr = new value_type;
203 (*theCollection)[key] = ptr;
204 return ptr;
205 }
206 else
207 return theCollection->find(key)->second;
208 }
209}
G4atomic< T > value_type

◆ GetMap()

template<typename T >
container_type * G4TAtomicHitsMap< T >::GetMap ( ) const
inline

Definition at line 105 of file G4TAtomicHitsMap.hh.

105{ return theCollection; }

◆ add() [1/2]

template<typename T >
G4int G4TAtomicHitsMap< T >::add ( const G4int &  key,
value_type *&  aHit 
) const
inline

Definition at line 212 of file G4TAtomicHitsMap.hh.

213{
214 if(theCollection->find(key) != theCollection->end())
215 *(*theCollection)[key] += *aHit;
216 else
217 {
218 G4AutoLock l(&fMutex);
219 (*theCollection)[key] = aHit;
220 }
221 G4AutoLock l(&fMutex);
222 return theCollection->size();
223}

◆ add() [2/2]

template<typename T >
G4int G4TAtomicHitsMap< T >::add ( const G4int &  key,
T &  aHit 
) const
inline

Definition at line 226 of file G4TAtomicHitsMap.hh.

227{
228 if(theCollection->find(key) != theCollection->end())
229 *(*theCollection)[key] += aHit;
230 else
231 {
232 value_type* hit = new value_type;
233 *hit = aHit;
234 G4AutoLock l(&fMutex);
235 (*theCollection)[key] = hit;
236 }
237 G4AutoLock l(&fMutex);
238 return theCollection->size();
239}

◆ set() [1/2]

template<typename T >
G4int G4TAtomicHitsMap< T >::set ( const G4int &  key,
value_type *&  aHit 
) const
inline

Definition at line 242 of file G4TAtomicHitsMap.hh.

243{
244 if(theCollection->find(key) != theCollection->end())
245 delete(*theCollection)[key]->second;
246
247 (*theCollection)[key] = aHit;
248 G4AutoLock l(&fMutex);
249 return theCollection->size();
250}

◆ set() [2/2]

template<typename T >
G4int G4TAtomicHitsMap< T >::set ( const G4int &  key,
T &  aHit 
) const
inline

Definition at line 253 of file G4TAtomicHitsMap.hh.

254{
255 if(theCollection->find(key) != theCollection->end())
256 *(*theCollection)[key] = aHit;
257 else
258 {
259 value_type* hit = new value_type;
260 *hit = aHit;
261 (*theCollection)[key] = hit;
262 }
263 G4AutoLock l(&fMutex);
264 return theCollection->size();
265}

◆ entries()

template<typename T >
G4int G4TAtomicHitsMap< T >::entries ( ) const
inline

Definition at line 115 of file G4TAtomicHitsMap.hh.

115{ return theCollection->size(); }

◆ clear()

template<typename T >
void G4TAtomicHitsMap< T >::clear ( )
inline

Definition at line 279 of file G4TAtomicHitsMap.hh.

280{
281 G4AutoLock l(&fMutex);
282
283 for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
284 delete itr->second;
285
286 theCollection->clear();
287}

◆ GetHit()

template<typename T >
virtual G4VHit * G4TAtomicHitsMap< T >::GetHit ( size_t  ) const
inlinevirtual

Definition at line 120 of file G4TAtomicHitsMap.hh.

120{ return 0; }

◆ GetSize()

template<typename T >
virtual size_t G4TAtomicHitsMap< T >::GetSize ( ) const
inlinevirtual

Definition at line 121 of file G4TAtomicHitsMap.hh.

121{ return theCollection->size(); }

◆ size()

template<typename T >
virtual size_t G4TAtomicHitsMap< T >::size ( ) const
inlinevirtual

Definition at line 123 of file G4TAtomicHitsMap.hh.

123{ return theCollection->size(); }

◆ begin() [1/2]

template<typename T >
iterator G4TAtomicHitsMap< T >::begin ( )
inline

Definition at line 126 of file G4TAtomicHitsMap.hh.

126{ return theCollection->begin(); }

◆ end() [1/2]

template<typename T >
iterator G4TAtomicHitsMap< T >::end ( )
inline

Definition at line 127 of file G4TAtomicHitsMap.hh.

127{ return theCollection->end(); }

◆ begin() [2/2]

template<typename T >
const_iterator G4TAtomicHitsMap< T >::begin ( ) const
inline

Definition at line 129 of file G4TAtomicHitsMap.hh.

129{ return theCollection->begin(); }

◆ end() [2/2]

template<typename T >
const_iterator G4TAtomicHitsMap< T >::end ( ) const
inline

Definition at line 130 of file G4TAtomicHitsMap.hh.

130{ return theCollection->end(); }

◆ cbegin()

template<typename T >
const_iterator G4TAtomicHitsMap< T >::cbegin ( ) const
inline

Definition at line 132 of file G4TAtomicHitsMap.hh.

132{ return theCollection->cbegin(); }

◆ cend()

template<typename T >
const_iterator G4TAtomicHitsMap< T >::cend ( ) const
inline

Definition at line 133 of file G4TAtomicHitsMap.hh.

133{ return theCollection->cend(); }

◆ find() [1/2]

template<typename T >
iterator G4TAtomicHitsMap< T >::find ( G4int  p)
inline

Definition at line 135 of file G4TAtomicHitsMap.hh.

135{ return theCollection->find(p); }

◆ find() [2/2]

template<typename T >
const_iterator G4TAtomicHitsMap< T >::find ( G4int  p) const
inline

Definition at line 136 of file G4TAtomicHitsMap.hh.

136{ return theCollection->find(p); }

Member Data Documentation

◆ theCollection

template<typename T >
container_type* G4TAtomicHitsMap< T >::theCollection
private

Definition at line 139 of file G4TAtomicHitsMap.hh.

◆ fMutex

template<typename T >
G4Mutex G4TAtomicHitsMap< T >::fMutex
mutableprivate

Definition at line 140 of file G4TAtomicHitsMap.hh.


The documentation for this class was generated from the following files:

Applications | User Support | Publications | Collaboration