Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
28
29#ifndef G4TDigiCollection_h
30#define G4TDigiCollection_h 1
31
32#include "G4VDigiCollection.hh"
33#include "G4Allocator.hh"
34#include "globals.hh"
35#include <vector>
36
37// class description:
38//
39// This is a template class of digi collection and parametrized by
40// The concrete class of G4VDigi. This is a uniform collection for
41// a particular concrete digi class objects.
42// An intermediate layer class G4DigiCollection appeared in this
43// header file is used just for G4Allocator, because G4Allocator
44// cannot be instansiated with a template class. Thus G4DigiCollection
45// class MUST NOT be directly used by the user.
46
48{
49 public:
51 G4DigiCollection(G4String detName,G4String colNam);
52 virtual ~G4DigiCollection();
53 G4bool operator==(const G4DigiCollection &right) const;
54
55 protected:
57};
58
59#if defined G4DIGI_ALLOC_EXPORT
61#else
63#endif
64
65template <class T> class G4TDigiCollection : public G4DigiCollection
66{
67 public:
69 public: // with description
70 G4TDigiCollection(G4String detName,G4String colNam);
71 // Constructor.
72 public:
73 virtual ~G4TDigiCollection();
74 G4bool operator==(const G4TDigiCollection &right) const;
75
76 inline void *operator new(size_t);
77 inline void operator delete(void* aDC);
78 public: // with description
79 virtual void DrawAllDigi();
80 virtual void PrintAllDigi();
81 // These two methods invokes Draw() and Print() methods of all of
82 // digit objects stored in this collection, respectively.
83
84 public: // with description
85 inline T* operator[](size_t i) const
86 {
88 return (*((std::vector<T*>*)theCollection))[i];
89 }
90 // Returns a pointer to a concrete digi object.
91 inline std::vector<T*>* GetVector() const
92 {
94 return (std::vector<T*>*)theCollection;
95 }
96 // Returns a collection vector.
97 inline size_t insert(T* aHit)
98 {
100 std::vector<T*>*theDigiCollection
101 = (std::vector<T*>*)theCollection;
102 theDigiCollection->push_back(aHit);
103 return theDigiCollection->size();
104 }
105 // Insert a digi object. Total number of digi objects stored in this
106 // collection is returned.
107 inline size_t entries() const
108 {
110 std::vector<T*>*theDigiCollection
111 = (std::vector<T*>*)theCollection;
112 return theDigiCollection->size();
113 }
114 // Returns the number of digi objcets stored in this collection.
115
116 public:
117 virtual G4VDigi* GetDigi(size_t i) const
118 {
120 return (*((std::vector<T*>*)theCollection))[i];
121 }
122 virtual size_t GetSize() const
123 {
125 return ((std::vector<T*>*)theCollection)->size();
126 }
127
128};
129
130template <class T> inline void* G4TDigiCollection<T>::operator new(size_t)
131{
134 void* aDC;
135 aDC = (void*)aDCAllocator.MallocSingle();
136 return aDC;
137}
138
139template <class T> inline void G4TDigiCollection<T>::operator delete(void* aDC)
140{
143 aDCAllocator.FreeSingle((G4DigiCollection*)aDC);
144}
145
147{
149 std::vector<T*> * theDigiCollection = new std::vector<T*>;
150 theCollection = (void*)theDigiCollection;
151}
152
154: G4DigiCollection(detName,colNam)
155{
157
158 std::vector<T*> * theDigiCollection = new std::vector<T*>;
159 theCollection = (void*)theDigiCollection;
160}
161
163{
165 std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
166 //theDigiCollection->clearAndDestroy();
167 for(size_t i=0;i<theDigiCollection->size();i++)
168 { delete (*theDigiCollection)[i]; }
169 theDigiCollection->clear();
170 delete theDigiCollection;
171}
172
174{
176 return (collectionName==right.collectionName);
177}
178
179template <class T> void G4TDigiCollection<T>::DrawAllDigi()
180{
182 std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
183 size_t n = theDigiCollection->size();
184 for(size_t i=0;i<n;i++)
185 { (*theDigiCollection)[i]->Draw(); }
186}
187
188template <class T> void G4TDigiCollection<T>::PrintAllDigi()
189{
191 std::vector<T*> * theDigiCollection = (std::vector<T*>*)theCollection;
192 size_t n = theDigiCollection->size();
193 for(size_t i=0;i<n;i++)
194 { (*theDigiCollection)[i]->Print(); }
195}
196
197#endif
198
G4DLLIMPORT G4Allocator< G4DigiCollection > *& aDCAllocator_G4MT_TLS_()
#define G4DLLIMPORT
Definition: G4Types.hh:69
#define G4DLLEXPORT
Definition: G4Types.hh:68
bool G4bool
Definition: G4Types.hh:86
void FreeSingle(Type *anElement)
Definition: G4Allocator.hh:206
Type * MallocSingle()
Definition: G4Allocator.hh:196
virtual ~G4DigiCollection()
G4bool operator==(const G4DigiCollection &right) const
virtual size_t GetSize() const
virtual void PrintAllDigi()
G4bool operator==(const G4TDigiCollection &right) const
size_t entries() const
size_t insert(T *aHit)
std::vector< T * > * GetVector() const
T * operator[](size_t i) const
virtual G4VDigi * GetDigi(size_t i) const
virtual void DrawAllDigi()