Geant4  10.00.p01
G4TDigiCollection.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 //
27 // $Id: G4TDigiCollection.hh 67992 2013-03-13 10:59:57Z gcosmo $
28 //
29 
30 #ifndef G4TDigiCollection_h
31 #define G4TDigiCollection_h 1
32 
33 #include "G4VDigiCollection.hh"
34 #include "G4Allocator.hh"
35 #include "globals.hh"
36 #include <vector>
37 
38 // class description:
39 //
40 // This is a template class of digi collection and parametrized by
41 // The concrete class of G4VDigi. This is a uniform collection for
42 // a particular concrete digi class objects.
43 // An intermediate layer class G4DigiCollection appeared in this
44 // header file is used just for G4Allocator, because G4Allocator
45 // cannot be instansiated with a template class. Thus G4DigiCollection
46 // class MUST NOT be directly used by the user.
47 
49 {
50  public:
52  G4DigiCollection(G4String detName,G4String colNam);
53  virtual ~G4DigiCollection();
54  G4int operator==(const G4DigiCollection &right) const;
55 
56  protected:
58 };
59 
60 #if defined G4DIGI_ALLOC_EXPORT
62 #else
64 #endif
65 
66 template <class T> class G4TDigiCollection : public G4DigiCollection
67 {
68  public:
70  public: // with description
71  G4TDigiCollection(G4String detName,G4String colNam);
72  // Constructor.
73  public:
74  virtual ~G4TDigiCollection();
76 
77  inline void *operator new(size_t);
78  inline void operator delete(void* aDC);
79  public: // with description
80  virtual void DrawAllDigi();
81  virtual void PrintAllDigi();
82  // These two methods invokes Draw() and Print() methods of all of
83  // digit objects stored in this collection, respectively.
84 
85  public: // with description
86  inline T* operator[](size_t i) const
87  {
89  return (*((std::vector<T*>*)theCollection))[i];
90  }
91  // Returns a pointer to a concrete digi object.
92  inline std::vector<T*>* GetVector() const
93  {
95  return (std::vector<T*>*)theCollection;
96  }
97  // Returns a collection vector.
98  inline G4int insert(T* aHit)
99  {
101  std::vector<T*>*theDigiCollection
102  = (std::vector<T*>*)theCollection;
103  theDigiCollection->push_back(aHit);
104  return theDigiCollection->size();
105  }
106  // Insert a digi object. Total number of digi objects stored in this
107  // collection is returned.
108  inline G4int entries() const
109  {
111  std::vector<T*>*theDigiCollection
112  = (std::vector<T*>*)theCollection;
113  return theDigiCollection->size();
114  }
115  // Returns the number of digi objcets stored in this collection.
116 
117  public:
118  virtual G4VDigi* GetDigi(size_t i) const
119  {
121  return (*((std::vector<T*>*)theCollection))[i];
122  }
123  virtual size_t GetSize() const
124  {
126  return ((std::vector<T*>*)theCollection)->size();
127  }
128 
129 };
130 
131 template <class T> inline void* G4TDigiCollection<T>::operator new(size_t)
132 {
135  void* aDC;
136  aDC = (void*)aDCAllocator.MallocSingle();
137  return aDC;
138 }
139 
140 template <class T> inline void G4TDigiCollection<T>::operator delete(void* aDC)
141 {
144  aDCAllocator.FreeSingle((G4DigiCollection*)aDC);
145 }
146 
148 {
150  std::vector<T*> * theDigiCollection = new std::vector<T*>;
151  theCollection = (void*)theDigiCollection;
152 }
153 
155 : G4DigiCollection(detName,colNam)
156 {
158 
159  std::vector<T*> * theDigiCollection = new std::vector<T*>;
160  theCollection = (void*)theDigiCollection;
161 }
162 
164 {
166  std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
167  //theDigiCollection->clearAndDestroy();
168  for(size_t i=0;i<theDigiCollection->size();i++)
169  { delete (*theDigiCollection)[i]; }
170  theDigiCollection->clear();
171  delete theDigiCollection;
172 }
173 
175 {
177  return (collectionName==right.collectionName);
178 }
179 
180 template <class T> void G4TDigiCollection<T>::DrawAllDigi()
181 {
183  std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
184  size_t n = theDigiCollection->size();
185  for(size_t i=0;i<n;i++)
186  { (*theDigiCollection)[i]->Draw(); }
187 }
188 
189 template <class T> void G4TDigiCollection<T>::PrintAllDigi()
190 {
192  std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
193  size_t n = theDigiCollection->size();
194  for(size_t i=0;i<n;i++)
195  { (*theDigiCollection)[i]->Print(); }
196 }
197 
198 #endif
199 
Type * MallocSingle()
Definition: G4Allocator.hh:191
virtual G4VDigi * GetDigi(size_t i) const
#define G4DLLEXPORT
Definition: G4Types.hh:62
std::vector< T * > * GetVector() const
G4int insert(T *aHit)
virtual void DrawAllDigi()
#define G4DLLIMPORT
Definition: G4Types.hh:63
void FreeSingle(Type *anElement)
Definition: G4Allocator.hh:201
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
G4int operator==(const G4TDigiCollection &right) const
G4int entries() const
virtual void PrintAllDigi()
const G4int n
T * operator[](size_t i) const
G4DLLIMPORT G4ThreadLocal G4Allocator< G4DigiCollection > * aDCAllocator_G4MT_TLS_
virtual size_t GetSize() const
virtual ~G4DigiCollection()
G4int operator==(const G4DigiCollection &right) const