G4THitsMap< T > Class Template Reference

#include <G4THitsMap.hh>

Inheritance diagram for G4THitsMap< T >:

G4HitsCollection G4VHitsCollection

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

Detailed Description

template<typename T>
class G4THitsMap< T >

Definition at line 46 of file G4THitsMap.hh.


Constructor & Destructor Documentation

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

Definition at line 91 of file G4THitsMap.hh.

References G4HitsCollection::theCollection.

00092 { 
00093   theCollection = (void*)new std::map<G4int,T*>;
00094 }

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

Definition at line 96 of file G4THitsMap.hh.

References G4HitsCollection::theCollection.

00097     : G4HitsCollection(detName,colNam)
00098 { 
00099     theCollection = (void*)new std::map<G4int,T*>;
00100 }

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

Definition at line 102 of file G4THitsMap.hh.

References G4THitsMap< T >::GetMap().

00103 {
00104   typename std::map<G4int,T*> * theHitsMap = GetMap();
00105   typename std::map<G4int,T*>::iterator itr = theHitsMap->begin();
00106   for(; itr != theHitsMap->end(); itr++) {
00107       delete itr->second;
00108   }
00109 
00110   delete theHitsMap;
00111 }


Member Function Documentation

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

Definition at line 150 of file G4THitsMap.hh.

References G4THitsMap< T >::GetMap().

00150                                                    {
00151 
00152     typename std::map<G4int,T*> * theHitsMap = GetMap();
00153     if(theHitsMap->find(key) != theHitsMap->end()) {
00154         *(*theHitsMap)[key] += aHit;
00155     } else {
00156         T * hit = new T;
00157         *hit = aHit;
00158         (*theHitsMap)[key] = hit;
00159     }
00160 
00161     return theHitsMap->size();
00162 }

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

Definition at line 138 of file G4THitsMap.hh.

References G4THitsMap< T >::GetMap().

Referenced by G4THitsMap< T >::operator+=().

00138                                                      {
00139 
00140     typename std::map<G4int,T*> * theHitsMap = GetMap();
00141     if(theHitsMap->find(key) != theHitsMap->end()) {
00142         *(*theHitsMap)[key] += *aHit;
00143     } else {
00144         (*theHitsMap)[key] = aHit;
00145     }
00146     return theHitsMap->size();
00147 }

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

Definition at line 209 of file G4THitsMap.hh.

References G4THitsMap< T >::GetMap().

00209                                                 {
00210 
00211     std::map<G4int,T*> * theHitsMap = GetMap();
00212     typename std::map<G4int, T*>::iterator itr = theHitsMap->begin();
00213     for(; itr != theHitsMap->end(); itr++) {
00214         delete itr->second;
00215     }
00216     theHitsMap->clear();
00217 
00218 }

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

Reimplemented from G4VHitsCollection.

Definition at line 190 of file G4THitsMap.hh.

00191 {;}

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

Definition at line 79 of file G4THitsMap.hh.

Referenced by G4THitsMap< T >::PrintAllHits().

00080       { return ((std::map<G4int,T*>*)theCollection)->size(); }

template<typename T>
virtual G4VHit* G4THitsMap< T >::GetHit ( size_t   )  const [inline, virtual]

Reimplemented from G4VHitsCollection.

Definition at line 85 of file G4THitsMap.hh.

00085 {return 0;}

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

Definition at line 68 of file G4THitsMap.hh.

Referenced by G4THitsMap< T >::add(), G4GMocrenFileSceneHandler::AddCompound(), G4THitsMap< T >::clear(), G4THitsMap< T >::operator+=(), G4THitsMap< T >::operator[](), G4THitsMap< T >::set(), and G4THitsMap< T >::~G4THitsMap().

00069       { return (std::map<G4int,T*>*)theCollection; }

template<typename T>
virtual size_t G4THitsMap< T >::GetSize (  )  const [inline, virtual]

Reimplemented from G4VHitsCollection.

Definition at line 86 of file G4THitsMap.hh.

Referenced by G4VScoringMesh::Accumulate().

00087     { return ((std::map<G4int,T*>*)theCollection)->size(); }

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

Definition at line 117 of file G4THitsMap.hh.

References G4THitsMap< T >::add(), and G4THitsMap< T >::GetMap().

00118 {
00119     std::map<G4int,T*> * aHitsMap = right.GetMap();
00120     typename std::map<G4int,T*>::iterator itr = aHitsMap->begin();
00121     for(; itr != aHitsMap->end(); itr++) {
00122         add(itr->first, *(itr->second));
00123     }
00124     return (G4THitsMap<T>&)(*this);
00125 }

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

Definition at line 113 of file G4THitsMap.hh.

References G4VHitsCollection::collectionName.

00114 { return (collectionName==right.collectionName); }

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

Definition at line 128 of file G4THitsMap.hh.

References G4THitsMap< T >::GetMap().

00128                                          {
00129     std::map<G4int,T*> * theHitsMap = GetMap();
00130     if(theHitsMap->find(key) != theHitsMap->end()) {
00131         return theHitsMap->find(key)->second;
00132     } else {
00133         return 0;
00134     }
00135 }

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

Reimplemented from G4VHitsCollection.

Definition at line 193 of file G4THitsMap.hh.

References G4VHitsCollection::collectionName, G4THitsMap< T >::entries(), G4cout, G4endl, and G4VHitsCollection::SDname.

Referenced by G4VScoringMesh::Accumulate().

00194 {
00195  G4cout << "G4THitsMap " << SDname << " / " << collectionName << " --- " << entries() << " entries" << G4endl;
00196 /*----- commented out for the use-case where <T> cannot be initialized
00197         to be zero or does not support += operator.
00198  std::map<G4int,T*> * theHitsMap = GetMap();
00199  typename std::map<G4int, T*>::iterator itr = theHitsMap->begin();
00200  T sum = 0.;
00201  for(; itr != theHitsMap->end(); itr++) {
00203   sum += *(itr->second);
00204  }
00205  G4cout << "             Total : " << sum << G4endl;
00206 ----------------------------------------------------------------------*/
00207 }

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

Definition at line 176 of file G4THitsMap.hh.

References G4THitsMap< T >::GetMap().

00176                                                    {
00177                                                                                              
00178     typename std::map<G4int,T*> * theHitsMap = GetMap();
00179     if(theHitsMap->find(key) != theHitsMap->end()) {
00180         *(*theHitsMap)[key] = aHit;
00181     } else {
00182         T * hit = new T;
00183         *hit = aHit;
00184         (*theHitsMap)[key] = hit;
00185     }
00186                                                                                              
00187     return theHitsMap->size();
00188 }

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

Definition at line 165 of file G4THitsMap.hh.

References G4THitsMap< T >::GetMap().

00165                                                      {
00166                                                                                              
00167     typename std::map<G4int,T*> * theHitsMap = GetMap();
00168     if(theHitsMap->find(key) != theHitsMap->end()) {
00169         delete (*theHitsMap)[key]->second;
00170     }
00171     (*theHitsMap)[key] = aHit;
00172     return theHitsMap->size();
00173 }


The documentation for this class was generated from the following file:
Generated on Mon May 27 17:53:32 2013 for Geant4 by  doxygen 1.4.7