49 #ifndef G4TAtomicHitsCollection_h
50 #define G4TAtomicHitsCollection_h 1
52 #include "G4VHitsCollection.hh"
60 #include <type_traits>
89 static_assert(std::is_fundamental<T>::value,
90 "G4TAtomicHitsCollection must use fundamental type");
95 typedef typename std::deque<value_type*> container_type;
119 inline value_type* operator[](
size_t i)
const
121 return (*theCollection)[i];
124 inline container_type* GetVector()
const
126 return theCollection;
129 inline G4int insert(T* aHit)
132 theCollection->push_back(aHit);
133 return theCollection->size();
137 inline G4int entries()
const
140 return theCollection->size();
147 return (*theCollection)[i];
152 return theCollection->size();
156 container_type* theCollection;
171 theCollection(new container_type),
177 for(
size_t i = 0; i < theCollection->size(); i++)
178 delete (*theCollection)[i];
179 theCollection->clear();
180 delete theCollection;
195 for(
size_t i = 0; i < theCollection->size(); i++)
196 (*theCollection)[i]->Draw();
203 for(
size_t i = 0; i < theCollection->size(); i++)
204 (*theCollection)[i]->Print();
virtual size_t GetSize() const
virtual void PrintAllHits()
G4int operator==(const G4VHitsCollection &right) const
This is an implementation of G4THitsCollection where the underlying type is G4atomic, not just T. A static assert is provided to ensure that T is fundamental. This class should be used in lieu of G4THitsCollection 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 G4THitsCollection in thread-local instances.
virtual G4VHit * GetHit(size_t) const
virtual void DrawAllHits()
#define G4MUTEX_INITIALIZER
#define G4MUTEXDESTROY(mutex)
_Tp G4atomic
This is an friendly implementation of the STL atomic class. This class has the same interface as the ...