Geant4  10.02.p03
G4THitsMap< T > Class Template Reference

#include <G4THitsMap.hh>

Inheritance diagram for G4THitsMap< T >:
Collaboration diagram for G4THitsMap< T >:

Public Member Functions

 G4THitsMap ()
 
 G4THitsMap (G4String detName, G4String colNam)
 
virtual ~G4THitsMap ()
 
G4int operator== (const G4THitsMap< T > &right) const
 
G4THitsMap< T > & operator+= (const G4THitsMap< T > &right) const
 
virtual void DrawAllHits ()
 
virtual void PrintAllHits ()
 
T * operator[] (G4int key) const
 
std::map< G4int, T * > * GetMap () const
 
G4int add (const G4int &key, T *&aHit) const
 
G4int add (const G4int &key, T &aHit) const
 
G4int set (const G4int &key, T *&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
 
- Public Member Functions inherited from G4HitsCollection
 G4HitsCollection ()
 
 G4HitsCollection (G4String detName, G4String colNam)
 
virtual ~G4HitsCollection ()
 
G4int operator== (const G4HitsCollection &right) const
 
 G4HitsCollection ()
 
 G4HitsCollection (G4String detName, G4String colNam)
 
virtual ~G4HitsCollection ()
 
G4int operator== (const G4HitsCollection &right) const
 
 G4HitsCollection ()
 
 G4HitsCollection (G4String detName, G4String colNam)
 
virtual ~G4HitsCollection ()
 
G4int operator== (const G4HitsCollection &right) const
 
- Public Member Functions inherited from G4VHitsCollection
 G4VHitsCollection ()
 
 G4VHitsCollection (G4String detName, G4String colNam)
 
virtual ~G4VHitsCollection ()
 
G4int operator== (const G4VHitsCollection &right) const
 
G4String GetName ()
 
G4String GetSDname ()
 
 G4VHitsCollection ()
 
 G4VHitsCollection (G4String detName, G4String colNam)
 
virtual ~G4VHitsCollection ()
 
G4int operator== (const G4VHitsCollection &right) const
 
G4String GetName ()
 
G4String GetSDname ()
 
 G4VHitsCollection ()
 
 G4VHitsCollection (G4String detName, G4String colNam)
 
virtual ~G4VHitsCollection ()
 
G4int operator== (const G4VHitsCollection &right) const
 
G4StringGetName ()
 
G4StringGetSDname ()
 
void SetColID (G4int i)
 
G4int GetColID () const
 

Additional Inherited Members

- Protected Attributes inherited from G4HitsCollection
void * theCollection
 
- Protected Attributes inherited from G4VHitsCollection
G4String collectionName
 
G4String SDname
 
G4int colID
 

Detailed Description

template<typename T>
class G4THitsMap< T >

Definition at line 46 of file G4THitsMap.hh.

Constructor & Destructor Documentation

◆ G4THitsMap() [1/2]

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

Definition at line 91 of file G4THitsMap.hh.

92 {
93  theCollection = (void*)new std::map<G4int,T*>;
94 }

◆ G4THitsMap() [2/2]

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

Definition at line 96 of file G4THitsMap.hh.

97  : G4HitsCollection(detName,colNam)
98 {
99  theCollection = (void*)new std::map<G4int,T*>;
100 }

◆ ~G4THitsMap()

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

Definition at line 102 of file G4THitsMap.hh.

103 {
104  typename std::map<G4int,T*> * theHitsMap = GetMap();
105  typename std::map<G4int,T*>::iterator itr = theHitsMap->begin();
106  for(; itr != theHitsMap->end(); itr++) {
107  delete itr->second;
108  }
109 
110  delete theHitsMap;
111 }
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68

Member Function Documentation

◆ add() [1/2]

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

Definition at line 138 of file G4THitsMap.hh.

138  {
139 
140  typename std::map<G4int,T*> * theHitsMap = GetMap();
141  if(theHitsMap->find(key) != theHitsMap->end()) {
142  *(*theHitsMap)[key] += *aHit;
143  } else {
144  (*theHitsMap)[key] = aHit;
145  }
146  return theHitsMap->size();
147 }
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
Here is the caller graph for this function:

◆ add() [2/2]

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

Definition at line 150 of file G4THitsMap.hh.

150  {
151 
152  typename std::map<G4int,T*> * theHitsMap = GetMap();
153  if(theHitsMap->find(key) != theHitsMap->end()) {
154  *(*theHitsMap)[key] += aHit;
155  } else {
156  T * hit = new T;
157  *hit = aHit;
158  (*theHitsMap)[key] = hit;
159  }
160 
161  return theHitsMap->size();
162 }
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68

◆ clear()

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

Definition at line 209 of file G4THitsMap.hh.

209  {
210 
211  std::map<G4int,T*> * theHitsMap = GetMap();
212  typename std::map<G4int, T*>::iterator itr = theHitsMap->begin();
213  for(; itr != theHitsMap->end(); itr++) {
214  delete itr->second;
215  }
216  theHitsMap->clear();
217 
218 }
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
Here is the caller graph for this function:

◆ DrawAllHits()

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

Reimplemented from G4VHitsCollection.

Definition at line 190 of file G4THitsMap.hh.

191 {;}

◆ entries()

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

Definition at line 79 of file G4THitsMap.hh.

80  { return ((std::map<G4int,T*>*)theCollection)->size(); }
Here is the caller graph for this function:

◆ GetHit()

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

Reimplemented from G4VHitsCollection.

Definition at line 85 of file G4THitsMap.hh.

85 {return 0;}

◆ GetMap()

template<typename T>
std::map<G4int,T*>* G4THitsMap< T >::GetMap ( ) const
inline

Definition at line 68 of file G4THitsMap.hh.

◆ GetSize()

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

Reimplemented from G4VHitsCollection.

Definition at line 86 of file G4THitsMap.hh.

87  { return ((std::map<G4int,T*>*)theCollection)->size(); }
Here is the caller graph for this function:

◆ operator+=()

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

Definition at line 117 of file G4THitsMap.hh.

118 {
119  std::map<G4int,T*> * aHitsMap = right.GetMap();
120  typename std::map<G4int,T*>::iterator itr = aHitsMap->begin();
121  for(; itr != aHitsMap->end(); itr++) {
122  add(itr->first, *(itr->second));
123  }
124  return (G4THitsMap<T>&)(*this);
125 }
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
G4int add(const G4int &key, T *&aHit) const
Definition: G4THitsMap.hh:138

◆ operator==()

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

◆ operator[]()

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

Definition at line 128 of file G4THitsMap.hh.

128  {
129  std::map<G4int,T*> * theHitsMap = GetMap();
130  if(theHitsMap->find(key) != theHitsMap->end()) {
131  return theHitsMap->find(key)->second;
132  } else {
133  return 0;
134  }
135 }
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68

◆ PrintAllHits()

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

Reimplemented from G4VHitsCollection.

Definition at line 193 of file G4THitsMap.hh.

194 {
195  G4cout << "G4THitsMap " << SDname << " / " << collectionName << " --- " << entries() << " entries" << G4endl;
196 /*----- commented out for the use-case where <T> cannot be initialized
197  to be zero or does not support += operator.
198  std::map<G4int,T*> * theHitsMap = GetMap();
199  typename std::map<G4int, T*>::iterator itr = theHitsMap->begin();
200  T sum = 0.;
201  for(; itr != theHitsMap->end(); itr++) {
203  sum += *(itr->second);
204  }
205  G4cout << " Total : " << sum << G4endl;
206 ----------------------------------------------------------------------*/
207 }
G4GLOB_DLL std::ostream G4cout
G4int entries() const
Definition: G4THitsMap.hh:79
#define G4endl
Definition: G4ios.hh:61
Here is the caller graph for this function:

◆ set() [1/2]

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

Definition at line 165 of file G4THitsMap.hh.

165  {
166 
167  typename std::map<G4int,T*> * theHitsMap = GetMap();
168  if(theHitsMap->find(key) != theHitsMap->end()) {
169  delete (*theHitsMap)[key]->second;
170  }
171  (*theHitsMap)[key] = aHit;
172  return theHitsMap->size();
173 }
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68
Here is the caller graph for this function:

◆ set() [2/2]

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

Definition at line 176 of file G4THitsMap.hh.

176  {
177 
178  typename std::map<G4int,T*> * theHitsMap = GetMap();
179  if(theHitsMap->find(key) != theHitsMap->end()) {
180  *(*theHitsMap)[key] = aHit;
181  } else {
182  T * hit = new T;
183  *hit = aHit;
184  (*theHitsMap)[key] = hit;
185  }
186 
187  return theHitsMap->size();
188 }
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:68

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