[807] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4THitsCollection.hh,v 1.3 2006/06/29 17:33:58 gunter Exp $ |
---|
[1230] | 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
[807] | 29 | // |
---|
| 30 | |
---|
| 31 | #ifndef G4THitsCollection_h |
---|
| 32 | #define G4THitsCollection_h 1 |
---|
| 33 | |
---|
| 34 | #include "G4VHitsCollection.hh" |
---|
| 35 | #include "G4Allocator.hh" |
---|
| 36 | #include "globals.hh" |
---|
| 37 | //#include "g4rw/tpordvec.h" |
---|
| 38 | #include <vector> |
---|
| 39 | |
---|
| 40 | // class description: |
---|
| 41 | // |
---|
| 42 | // This is a template class of hits collection and parametrized by |
---|
| 43 | // The concrete class of G4VHit. This is a uniform collection for |
---|
| 44 | // a particular concrete hit class objects. |
---|
| 45 | // An intermediate layer class G4HitsCollection appeared in this |
---|
| 46 | // header file is used just for G4Allocator, because G4Allocator |
---|
| 47 | // cannot be instansiated with a template class. Thus G4HitsCollection |
---|
| 48 | // class MUST NOT be directly used by the user. |
---|
| 49 | |
---|
| 50 | //MSH_BEGIN |
---|
| 51 | class G4HitsCollection : public G4VHitsCollection |
---|
| 52 | { |
---|
| 53 | public: |
---|
| 54 | G4HitsCollection(); |
---|
| 55 | G4HitsCollection(G4String detName,G4String colNam); |
---|
| 56 | virtual ~G4HitsCollection(); |
---|
| 57 | G4int operator==(const G4HitsCollection &right) const; |
---|
| 58 | |
---|
| 59 | protected: |
---|
| 60 | void* theCollection; /*MSH: ptr_as_array |
---|
| 61 | [elementType: ExN02TrackerHit* ] |
---|
| 62 | [elementCount: { $ELE_COUNT = ((G4THitsCollection<ExN02TrackerHit>*)$THIS)->entries(); }] |
---|
| 63 | [elementGet: { $ELEMENT = (*((G4THitsCollection<ExN02TrackerHit>*)$THIS))[$ELE_INDEX]; }] |
---|
| 64 | [elementSet: { ((G4THitsCollection<ExN02TrackerHit>*)$THIS)->insert((ExN02TrackerHit*)$ELEMENT); }] |
---|
| 65 | */ |
---|
| 66 | |
---|
| 67 | }; |
---|
| 68 | //MSH_END |
---|
| 69 | |
---|
| 70 | #if defined G4DIGI_ALLOC_EXPORT |
---|
| 71 | extern G4DLLEXPORT G4Allocator<G4HitsCollection> anHCAllocator; |
---|
| 72 | #else |
---|
| 73 | extern G4DLLIMPORT G4Allocator<G4HitsCollection> anHCAllocator; |
---|
| 74 | #endif |
---|
| 75 | |
---|
| 76 | //MSH_BEGIN |
---|
| 77 | template <class T> class G4THitsCollection : public G4HitsCollection |
---|
| 78 | { |
---|
| 79 | public: |
---|
| 80 | G4THitsCollection(); |
---|
| 81 | public: // with description |
---|
| 82 | G4THitsCollection(G4String detName,G4String colNam); |
---|
| 83 | // constructor. |
---|
| 84 | public: |
---|
| 85 | virtual ~G4THitsCollection(); |
---|
| 86 | G4int operator==(const G4THitsCollection<T> &right) const; |
---|
| 87 | |
---|
| 88 | inline void *operator new(size_t); |
---|
| 89 | inline void operator delete(void* anHC); |
---|
| 90 | public: // with description |
---|
| 91 | virtual void DrawAllHits(); |
---|
| 92 | virtual void PrintAllHits(); |
---|
| 93 | // These two methods invokes Draw() and Print() methods of all of |
---|
| 94 | // hit objects stored in this collection, respectively. |
---|
| 95 | |
---|
| 96 | public: // with description |
---|
| 97 | inline T* operator[](size_t i) const |
---|
| 98 | { return (*((std::vector<T*>*)theCollection))[i]; } |
---|
| 99 | // Returns a pointer to a concrete hit object. |
---|
| 100 | inline std::vector<T*>* GetVector() const |
---|
| 101 | { return (std::vector<T*>*)theCollection; } |
---|
| 102 | // Returns a collection vector. |
---|
| 103 | inline G4int insert(T* aHit) |
---|
| 104 | { |
---|
| 105 | std::vector<T*>*theHitsCollection |
---|
| 106 | = (std::vector<T*>*)theCollection; |
---|
| 107 | theHitsCollection->push_back(aHit); |
---|
| 108 | return theHitsCollection->size(); |
---|
| 109 | } |
---|
| 110 | // Insert a hit object. Total number of hit objects stored in this |
---|
| 111 | // collection is returned. |
---|
| 112 | inline G4int entries() const |
---|
| 113 | { |
---|
| 114 | std::vector<T*>*theHitsCollection |
---|
| 115 | = (std::vector<T*>*)theCollection; |
---|
| 116 | return theHitsCollection->size(); |
---|
| 117 | } |
---|
| 118 | // Returns the number of hit objects stored in this collection |
---|
| 119 | |
---|
| 120 | public: |
---|
| 121 | virtual G4VHit* GetHit(size_t i) const |
---|
| 122 | { return (*((std::vector<T*>*)theCollection))[i]; } |
---|
| 123 | virtual size_t GetSize() const |
---|
| 124 | { return ((std::vector<T*>*)theCollection)->size(); } |
---|
| 125 | |
---|
| 126 | // MSH_superclass : G4HitsCollection |
---|
| 127 | |
---|
| 128 | }; |
---|
| 129 | //MSH_END |
---|
| 130 | |
---|
| 131 | template <class T> inline void* G4THitsCollection<T>::operator new(size_t) |
---|
| 132 | { |
---|
| 133 | void* anHC; |
---|
| 134 | anHC = (void*)anHCAllocator.MallocSingle(); |
---|
| 135 | return anHC; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | template <class T> inline void G4THitsCollection<T>::operator delete(void* anHC) |
---|
| 139 | { |
---|
| 140 | anHCAllocator.FreeSingle((G4HitsCollection*)anHC); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | template <class T> G4THitsCollection<T>::G4THitsCollection() |
---|
| 144 | { |
---|
| 145 | std::vector<T*> * theHitsCollection |
---|
| 146 | = new std::vector<T*>; |
---|
| 147 | theCollection = (void*)theHitsCollection; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | template <class T> G4THitsCollection<T>::G4THitsCollection(G4String detName,G4String colNam) |
---|
| 151 | : G4HitsCollection(detName,colNam) |
---|
| 152 | { |
---|
| 153 | std::vector<T*> * theHitsCollection |
---|
| 154 | = new std::vector<T*>; |
---|
| 155 | theCollection = (void*)theHitsCollection; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | template <class T> G4THitsCollection<T>::~G4THitsCollection() |
---|
| 159 | { |
---|
| 160 | std::vector<T*> * theHitsCollection |
---|
| 161 | = (std::vector<T*>*)theCollection; |
---|
| 162 | //theHitsCollection->clearAndDestroy(); |
---|
| 163 | for(size_t i=0;i<theHitsCollection->size();i++) |
---|
| 164 | { delete (*theHitsCollection)[i]; } |
---|
| 165 | theHitsCollection->clear(); |
---|
| 166 | delete theHitsCollection; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | template <class T> G4int G4THitsCollection<T>::operator==(const G4THitsCollection<T> &right) const |
---|
| 170 | { return (collectionName==right.collectionName); } |
---|
| 171 | |
---|
| 172 | template <class T> void G4THitsCollection<T>::DrawAllHits() |
---|
| 173 | { |
---|
| 174 | std::vector<T*> * theHitsCollection |
---|
| 175 | = (std::vector<T*>*)theCollection; |
---|
| 176 | size_t n = theHitsCollection->size(); |
---|
| 177 | for(size_t i=0;i<n;i++) |
---|
| 178 | { (*theHitsCollection)[i]->Draw(); } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | template <class T> void G4THitsCollection<T>::PrintAllHits() |
---|
| 182 | { |
---|
| 183 | std::vector<T*> * theHitsCollection |
---|
| 184 | = (std::vector<T*>*)theCollection; |
---|
| 185 | size_t n = theHitsCollection->size(); |
---|
| 186 | for(size_t i=0;i<n;i++) |
---|
| 187 | { (*theHitsCollection)[i]->Print(); } |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | #endif |
---|
| 191 | |
---|