LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
G4THitsCollection.hh
Go to the documentation of this file.
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 // $Id: G4THitsCollection.hh 66241 2012-12-13 18:34:42Z gunter $
31 //
32 
33 #ifndef G4THitsCollection_h
34 #define G4THitsCollection_h 1
35 
36 #include "G4VHitsCollection.hh"
37 #include "G4Allocator.hh"
38 #include "globals.hh"
39 //#include "g4rw/tpordvec.h"
40 #include <vector>
41 
42 //MSH_include_begin
43 #include "ExN04CalorimeterHit.hh"
44 #include "ExN04MuonHit.hh"
45 #include "ExN04TrackerHit.hh"
46 #include "MarshaledExN04CalorimeterHit.h"
47 #include "MarshaledExN04MuonHit.h"
48 #include "MarshaledExN04TrackerHit.h"
49 //MSH_include_end
50 
51 
52 // class description:
53 //
54 // This is a template class of hits collection and parametrized by
55 // The concrete class of G4VHit. This is a uniform collection for
56 // a particular concrete hit class objects.
57 // An intermediate layer class G4HitsCollection appeared in this
58 // header file is used just for G4Allocator, because G4Allocator
59 // cannot be instansiated with a template class. Thus G4HitsCollection
60 // class MUST NOT be directly used by the user.
61 
62 //MSH_BEGIN
64 {
65  public:
67  G4HitsCollection(G4String detName,G4String colNam);
68  virtual ~G4HitsCollection();
69  G4int operator==(const G4HitsCollection &right) const;
70 
71  protected:
72  void* theCollection; /*MSH: ptr_as_array
73  [elementType: (dynamic_cast<G4THitsCollection<ExN04CalorimeterHit>*>($THIS)!=NULL) => ExN04CalorimeterHit*
74  | (dynamic_cast<G4THitsCollection<ExN04MuonHit>*>($THIS)!=NULL) => ExN04MuonHit*
75  | true => ExN04TrackerHit*]
76  [elementCount: {
77  if(dynamic_cast<G4THitsCollection<ExN04CalorimeterHit>*>($THIS)!=NULL)
78  $ELE_COUNT = ((G4THitsCollection<ExN04CalorimeterHit>*)$THIS)->entries();
79  else if(dynamic_cast<G4THitsCollection<ExN04MuonHit>*>($THIS)!=NULL)
80  $ELE_COUNT = ((G4THitsCollection<ExN04MuonHit>*)$THIS)->entries();
81  else
82  $ELE_COUNT = ((G4THitsCollection<ExN04TrackerHit>*)$THIS)->entries();
83  }]
84  [elementGet: {
85  if(dynamic_cast<G4THitsCollection<ExN04CalorimeterHit>*>($THIS)!=NULL)
86  $ELEMENT = (*((G4THitsCollection<ExN04CalorimeterHit>*)$THIS))[$ELE_INDEX];
87  else if(dynamic_cast<G4THitsCollection<ExN04MuonHit>*>($THIS)!=NULL)
88  $ELEMENT = (*((G4THitsCollection<ExN04MuonHit>*)$THIS))[$ELE_INDEX];
89  else
90  $ELEMENT = (*((G4THitsCollection<ExN04TrackerHit>*)$THIS))[$ELE_INDEX];
91  }]
92  [elementSet: {
93  if(dynamic_cast<G4THitsCollection<ExN04CalorimeterHit>*>($THIS)!=NULL)
94  ((G4THitsCollection<ExN04CalorimeterHit>*)$THIS)->insert((ExN04CalorimeterHit*)$ELEMENT);
95  else if(dynamic_cast<G4THitsCollection<ExN04MuonHit>*>($THIS)!=NULL)
96  ((G4THitsCollection<ExN04MuonHit>*)$THIS)->insert((ExN04MuonHit*)$ELEMENT);
97  else
98  ((G4THitsCollection<ExN04TrackerHit>*)$THIS)->insert((ExN04TrackerHit*)$ELEMENT);
99  }] */
100 
101 };
102 //MSH_END
103 
104 
105 #if defined G4DIGI_ALLOC_EXPORT
106  extern G4DLLEXPORT G4Allocator<G4HitsCollection> anHCAllocator;
107 #else
108  extern G4DLLIMPORT G4Allocator<G4HitsCollection> anHCAllocator;
109 #endif
110 
111 //MSH_BEGIN
112 template <class T> class G4THitsCollection : public G4HitsCollection
113 {
114  public:
116  public: // with description
117  G4THitsCollection(G4String detName,G4String colNam);
118  // constructor.
119  public:
120  virtual ~G4THitsCollection();
121  G4int operator==(const G4THitsCollection<T> &right) const;
122 
123  inline void *operator new(size_t);
124  inline void operator delete(void* anHC);
125  public: // with description
126  virtual void DrawAllHits();
127  virtual void PrintAllHits();
128  // These two methods invokes Draw() and Print() methods of all of
129  // hit objects stored in this collection, respectively.
130 
131  public: // with description
132  inline T* operator[](size_t i) const
133  { return (*((std::vector<T*>*)theCollection))[i]; }
134  // Returns a pointer to a concrete hit object.
135  inline std::vector<T*>* GetVector() const
136  { return (std::vector<T*>*)theCollection; }
137  // Returns a collection vector.
138  inline G4int insert(T* aHit)
139  {
140  std::vector<T*>*theHitsCollection
141  = (std::vector<T*>*)theCollection;
142  theHitsCollection->push_back(aHit);
143  return theHitsCollection->size();
144  }
145  // Insert a hit object. Total number of hit objects stored in this
146  // collection is returned.
147  inline G4int entries() const
148  {
149  std::vector<T*>*theHitsCollection
150  = (std::vector<T*>*)theCollection;
151  return theHitsCollection->size();
152  }
153  // Returns the number of hit objects stored in this collection
154 
155  public:
156  virtual G4VHit* GetHit(size_t i) const
157  { return (*((std::vector<T*>*)theCollection))[i]; }
158  virtual size_t GetSize() const
159  { return ((std::vector<T*>*)theCollection)->size(); }
160 
161  // MSH_superclass : G4HitsCollection
162 
163 };
164 //MSH_END
165 
166 template <class T> inline void* G4THitsCollection<T>::operator new(size_t)
167 {
168  void* anHC;
169  anHC = (void*)anHCAllocator.MallocSingle();
170  return anHC;
171 }
172 
173 template <class T> inline void G4THitsCollection<T>::operator delete(void* anHC)
174 {
175  anHCAllocator.FreeSingle((G4HitsCollection*)anHC);
176 }
177 
178 template <class T> G4THitsCollection<T>::G4THitsCollection()
179 {
180  std::vector<T*> * theHitsCollection
181  = new std::vector<T*>;
182  theCollection = (void*)theHitsCollection;
183 }
184 
185 template <class T> G4THitsCollection<T>::G4THitsCollection(G4String detName,G4String colNam)
186 : G4HitsCollection(detName,colNam)
187 {
188  std::vector<T*> * theHitsCollection
189  = new std::vector<T*>;
190  theCollection = (void*)theHitsCollection;
191 }
192 
193 template <class T> G4THitsCollection<T>::~G4THitsCollection()
194 {
195  std::vector<T*> * theHitsCollection
196  = (std::vector<T*>*)theCollection;
197  //theHitsCollection->clearAndDestroy();
198  for(size_t i=0;i<theHitsCollection->size();i++)
199  { delete (*theHitsCollection)[i]; }
200  theHitsCollection->clear();
201  delete theHitsCollection;
202 }
203 
204 template <class T> G4int G4THitsCollection<T>::operator==(const G4THitsCollection<T> &right) const
205 { return (collectionName==right.collectionName); }
206 
207 template <class T> void G4THitsCollection<T>::DrawAllHits()
208 {
209  std::vector<T*> * theHitsCollection
210  = (std::vector<T*>*)theCollection;
211  size_t n = theHitsCollection->size();
212  for(size_t i=0;i<n;i++)
213  { (*theHitsCollection)[i]->Draw(); }
214 }
215 
216 template <class T> void G4THitsCollection<T>::PrintAllHits()
217 {
218  std::vector<T*> * theHitsCollection
219  = (std::vector<T*>*)theCollection;
220  size_t n = theHitsCollection->size();
221  for(size_t i=0;i<n;i++)
222  { (*theHitsCollection)[i]->Print(); }
223 }
224 
225 #endif
226 
T * operator[](size_t i) const
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
virtual void PrintAllHits()
virtual void DrawAllHits()
virtual ~G4HitsCollection()
virtual void PrintAllHits()
G4DLLIMPORT G4Allocator< G4HitsCollection > anHCAllocator
G4int operator==(const G4THitsCollection< T > &right) const
G4int insert(T *aHit)
virtual G4VHit * GetHit(size_t i) const
G4int operator==(const G4HitsCollection &right) const
Char_t n[5]
std::vector< T * > * GetVector() const
virtual void DrawAllHits()
virtual size_t GetSize() const
G4int entries() const