source: trunk/examples/extended/parallel/ParN04/AnnotatedFiles/G4THitsCollection.hh@ 1036

Last change on this file since 1036 was 807, checked in by garnier, 17 years ago

update

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