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