Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/parallel/TopC/ParN02/AnnotatedFiles/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 //
26 /// \file parallel/ParN02/AnnotatedFiles/G4THitsCollection.hh
27 /// \brief Definition of the G4THitsCollection class
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 // class description:
43 //
44 // This is a template class of hits collection and parametrized by
45 // The concrete class of G4VHit. This is a uniform collection for
46 // a particular concrete hit class objects.
47 // An intermediate layer class G4HitsCollection appeared in this
48 // header file is used just for G4Allocator, because G4Allocator
49 // cannot be instansiated with a template class. Thus G4HitsCollection
50 // class MUST NOT be directly used by the user.
51 
52 //MSH_BEGIN
54 {
55  public:
57  G4HitsCollection(G4String detName,G4String colNam);
58  virtual ~G4HitsCollection();
59  G4int operator==(const G4HitsCollection &right) const;
60 
61  protected:
62  void* theCollection; /*MSH: ptr_as_array
63  [elementType: ExN02TrackerHit* ]
64  [elementCount: { $ELE_COUNT = ((G4THitsCollection<ExN02TrackerHit>*)$THIS)->entries(); }]
65  [elementGet: { $ELEMENT = (*((G4THitsCollection<ExN02TrackerHit>*)$THIS))[$ELE_INDEX]; }]
66  [elementSet: { ((G4THitsCollection<ExN02TrackerHit>*)$THIS)->insert((ExN02TrackerHit*)$ELEMENT); }]
67  */
68 
69 };
70 //MSH_END
71 
72 #if defined G4DIGI_ALLOC_EXPORT
74 #else
76 #endif
77 
78 //MSH_BEGIN
79 template <class T> class G4THitsCollection : public G4HitsCollection
80 {
81  public:
83  public: // with description
84  G4THitsCollection(G4String detName,G4String colNam);
85  // constructor.
86  public:
87  virtual ~G4THitsCollection();
89 
90  inline void *operator new(size_t);
91  inline void operator delete(void* anHC);
92  public: // with description
93  virtual void DrawAllHits();
94  virtual void PrintAllHits();
95  // These two methods invokes Draw() and Print() methods of all of
96  // hit objects stored in this collection, respectively.
97 
98  public: // with description
99  inline T* operator[](size_t i) const
100  { return (*((std::vector<T*>*)theCollection))[i]; }
101  // Returns a pointer to a concrete hit object.
102  inline std::vector<T*>* GetVector() const
103  { return (std::vector<T*>*)theCollection; }
104  // Returns a collection vector.
105  inline G4int insert(T* aHit)
106  {
107  std::vector<T*>*theHitsCollection
108  = (std::vector<T*>*)theCollection;
109  theHitsCollection->push_back(aHit);
110  return theHitsCollection->size();
111  }
112  // Insert a hit object. Total number of hit objects stored in this
113  // collection is returned.
114  inline G4int entries() const
115  {
116  std::vector<T*>*theHitsCollection
117  = (std::vector<T*>*)theCollection;
118  return theHitsCollection->size();
119  }
120  // Returns the number of hit objects stored in this collection
121 
122  public:
123  virtual G4VHit* GetHit(size_t i) const
124  { return (*((std::vector<T*>*)theCollection))[i]; }
125  virtual size_t GetSize() const
126  { return ((std::vector<T*>*)theCollection)->size(); }
127 
128  // MSH_superclass : G4HitsCollection
129 
130 };
131 //MSH_END
132 
133 template <class T> inline void* G4THitsCollection<T>::operator new(size_t)
134 {
135  void* anHC;
136  anHC = (void*)anHCAllocator.MallocSingle();
137  return anHC;
138 }
139 
140 template <class T> inline void G4THitsCollection<T>::operator delete(void* anHC)
141 {
142  anHCAllocator.FreeSingle((G4HitsCollection*)anHC);
143 }
144 
146 {
147  std::vector<T*> * theHitsCollection
148  = new std::vector<T*>;
149  theCollection = (void*)theHitsCollection;
150 }
151 
153 : G4HitsCollection(detName,colNam)
154 {
155  std::vector<T*> * theHitsCollection
156  = new std::vector<T*>;
157  theCollection = (void*)theHitsCollection;
158 }
159 
161 {
162  std::vector<T*> * theHitsCollection
163  = (std::vector<T*>*)theCollection;
164  //theHitsCollection->clearAndDestroy();
165  for(size_t i=0;i<theHitsCollection->size();i++)
166  { delete (*theHitsCollection)[i]; }
167  theHitsCollection->clear();
168  delete theHitsCollection;
169 }
170 
172 { return (collectionName==right.collectionName); }
173 
174 template <class T> void G4THitsCollection<T>::DrawAllHits()
175 {
176  std::vector<T*> * theHitsCollection
177  = (std::vector<T*>*)theCollection;
178  size_t n = theHitsCollection->size();
179  for(size_t i=0;i<n;i++)
180  { (*theHitsCollection)[i]->Draw(); }
181 }
182 
183 template <class T> void G4THitsCollection<T>::PrintAllHits()
184 {
185  std::vector<T*> * theHitsCollection
186  = (std::vector<T*>*)theCollection;
187  size_t n = theHitsCollection->size();
188  for(size_t i=0;i<n;i++)
189  { (*theHitsCollection)[i]->Print(); }
190 }
191 
192 #endif
193 
#define G4DLLEXPORT
Definition: G4Types.hh:62
G4int operator==(const G4THitsCollection< T > &right) const
#define G4DLLIMPORT
Definition: G4Types.hh:63
virtual ~G4HitsCollection()
Definition: G4VHit.hh:48
int G4int
Definition: G4Types.hh:78
const G4int n
G4int operator==(const G4HitsCollection &right) const
G4DLLIMPORT G4Allocator< G4HitsCollection > anHCAllocator