ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4THitsCollection.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4THitsCollection.hh
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 //
28 //
29 //
30 //
31 
32 #ifndef G4THitsCollection_h
33 #define G4THitsCollection_h 1
34 
35 #include "G4VHitsCollection.hh"
36 #include "G4Allocator.hh"
37 #include "globals.hh"
38 //#include "g4rw/tpordvec.h"
39 #include <vector>
40 
41 // class description:
42 //
43 // This is a template class of hits collection and parametrized by
44 // The concrete class of G4VHit. This is a uniform collection for
45 // a particular concrete hit class objects.
46 // An intermediate layer class G4HitsCollection appeared in this
47 // header file is used just for G4Allocator, because G4Allocator
48 // cannot be instansiated with a template class. Thus G4HitsCollection
49 // class MUST NOT be directly used by the user.
50 
51 //MSH_BEGIN
53 {
54  public:
56  G4HitsCollection(G4String detName,G4String colNam);
57  virtual ~G4HitsCollection();
59 
60  protected:
61  void* theCollection; /*MSH: ptr_as_array
62  [elementType: ExN02TrackerHit* ]
63  [elementCount: { $ELE_COUNT = ((G4THitsCollection<ExN02TrackerHit>*)$THIS)->entries(); }]
64  [elementGet: { $ELEMENT = (*((G4THitsCollection<ExN02TrackerHit>*)$THIS))[$ELE_INDEX]; }]
65  [elementSet: { ((G4THitsCollection<ExN02TrackerHit>*)$THIS)->insert((ExN02TrackerHit*)$ELEMENT); }]
66  */
67 
68 };
69 //MSH_END
70 
71 #if defined G4DIGI_ALLOC_EXPORT
73 #else
75 #endif
76 
77 //MSH_BEGIN
78 template <class T> class G4THitsCollection : public G4HitsCollection
79 {
80  public:
82  public: // with description
83  G4THitsCollection(G4String detName,G4String colNam);
84  // constructor.
85  public:
86  virtual ~G4THitsCollection();
88 
89  inline void *operator new(size_t);
90  inline void operator delete(void* anHC);
91  public: // with description
92  virtual void DrawAllHits();
93  virtual void PrintAllHits();
94  // These two methods invokes Draw() and Print() methods of all of
95  // hit objects stored in this collection, respectively.
96 
97  public: // with description
98  inline T* operator[](size_t i) const
99  { return (*((std::vector<T*>*)theCollection))[i]; }
100  // Returns a pointer to a concrete hit object.
101  inline std::vector<T*>* GetVector() const
102  { return (std::vector<T*>*)theCollection; }
103  // Returns a collection vector.
104  inline G4int insert(T* aHit)
105  {
106  std::vector<T*>*theHitsCollection
107  = (std::vector<T*>*)theCollection;
108  theHitsCollection->push_back(aHit);
109  return theHitsCollection->size();
110  }
111  // Insert a hit object. Total number of hit objects stored in this
112  // collection is returned.
113  inline G4int entries() const
114  {
115  std::vector<T*>*theHitsCollection
116  = (std::vector<T*>*)theCollection;
117  return theHitsCollection->size();
118  }
119  // Returns the number of hit objects stored in this collection
120 
121  public:
122  virtual G4VHit* GetHit(size_t i) const
123  { return (*((std::vector<T*>*)theCollection))[i]; }
124  virtual size_t GetSize() const
125  { return ((std::vector<T*>*)theCollection)->size(); }
126 
127  // MSH_superclass : G4HitsCollection
128 
129 };
130 //MSH_END
131 
132 template <class T> inline void* G4THitsCollection<T>::operator new(size_t)
133 {
134  void* anHC;
135  anHC = (void*)anHCAllocator.MallocSingle();
136  return anHC;
137 }
138 
139 template <class T> inline void G4THitsCollection<T>::operator delete(void* anHC)
140 {
141  anHCAllocator.FreeSingle((G4HitsCollection*)anHC);
142 }
143 
145 {
146  std::vector<T*> * theHitsCollection
147  = new std::vector<T*>;
148  theCollection = (void*)theHitsCollection;
149 }
150 
152 : G4HitsCollection(detName,colNam)
153 {
154  std::vector<T*> * theHitsCollection
155  = new std::vector<T*>;
156  theCollection = (void*)theHitsCollection;
157 }
158 
160 {
161  std::vector<T*> * theHitsCollection
162  = (std::vector<T*>*)theCollection;
163  //theHitsCollection->clearAndDestroy();
164  for(size_t i=0;i<theHitsCollection->size();i++)
165  { delete (*theHitsCollection)[i]; }
166  theHitsCollection->clear();
167  delete theHitsCollection;
168 }
169 
171 { return (collectionName==right.collectionName); }
172 
173 template <class T> void G4THitsCollection<T>::DrawAllHits()
174 {
175  std::vector<T*> * theHitsCollection
176  = (std::vector<T*>*)theCollection;
177  size_t n = theHitsCollection->size();
178  for(size_t i=0;i<n;i++)
179  { (*theHitsCollection)[i]->Draw(); }
180 }
181 
182 template <class T> void G4THitsCollection<T>::PrintAllHits()
183 {
184  std::vector<T*> * theHitsCollection
185  = (std::vector<T*>*)theCollection;
186  size_t n = theHitsCollection->size();
187  for(size_t i=0;i<n;i++)
188  { (*theHitsCollection)[i]->Print(); }
189 }
190 
191 #endif
192