Geant4 11.1.1
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>
67{
68 public:
70
71 public: // with description
72 G4TDigiCollection(G4String detName, G4String colNam);
73 // Constructor.
74 public:
75 virtual ~G4TDigiCollection();
76 G4bool operator==(const G4TDigiCollection& right) const;
77
78 inline void* operator new(size_t);
79 inline void operator delete(void* aDC);
80
81 public: // with description
82 virtual void DrawAllDigi();
83 virtual void PrintAllDigi();
84 // These two methods invokes Draw() and Print() methods of all of
85 // digit objects stored in this collection, respectively.
86
87 public: // with description
88 inline T* operator[](size_t i) const
89 {
90 return (*((std::vector<T*>*) theCollection))[i];
91 }
92 // Returns a pointer to a concrete digi object.
93 inline std::vector<T*>* GetVector() const
94 {
95 return (std::vector<T*>*) theCollection;
96 }
97 // Returns a collection vector.
98 inline size_t insert(T* aHit)
99 {
100 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
101 theDigiCollection->push_back(aHit);
102 return theDigiCollection->size();
103 }
104 // Insert a digi object. Total number of digi objects stored in this
105 // collection is returned.
106 inline size_t entries() const
107 {
108 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
109 return theDigiCollection->size();
110 }
111 // Returns the number of digi objcets stored in this collection.
112
113 public:
114 virtual G4VDigi* GetDigi(size_t i) const
115 {
116 return (*((std::vector<T*>*) theCollection))[i];
117 }
118 virtual size_t GetSize() const
119 {
120 return ((std::vector<T*>*) theCollection)->size();
121 }
122};
123
124template <class T>
125inline void* G4TDigiCollection<T>::operator new(size_t)
126{
127 if(aDCAllocator_G4MT_TLS_() == nullptr)
128 {
130 }
131 return (void*) aDCAllocator_G4MT_TLS_()->MallocSingle();
132}
133
134template <class T>
135inline void G4TDigiCollection<T>::operator delete(void* aDC)
136{
137 aDCAllocator_G4MT_TLS_()->FreeSingle((G4DigiCollection*) aDC);
138}
139
140template <class T>
142{
143 std::vector<T*>* theDigiCollection = new std::vector<T*>;
144 theCollection = (void*) theDigiCollection;
145}
146
147template <class T>
149 : G4DigiCollection(detName, colNam)
150{
151 std::vector<T*>* theDigiCollection = new std::vector<T*>;
152 theCollection = (void*) theDigiCollection;
153}
154
155template <class T>
157{
158 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
159
160 for(size_t i = 0; i < theDigiCollection->size(); i++)
161 {
162 delete(*theDigiCollection)[i];
163 }
164 theDigiCollection->clear();
165 delete theDigiCollection;
166}
167
168template <class T>
170{
171 return (collectionName == right.collectionName);
172}
173
174template <class T>
176{
177 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
178 size_t n = theDigiCollection->size();
179 for(size_t i = 0; i < n; i++)
180 {
181 (*theDigiCollection)[i]->Draw();
182 }
183}
184
185template <class T>
187{
188 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
189 size_t n = theDigiCollection->size();
190 for(size_t i = 0; i < n; i++)
191 {
192 (*theDigiCollection)[i]->Print();
193 }
194}
195
196#endif
G4DLLIMPORT G4Allocator< G4DigiCollection > *& aDCAllocator_G4MT_TLS_()
#define G4DLLIMPORT
Definition: G4Types.hh:69
#define G4DLLEXPORT
Definition: G4Types.hh:68
bool G4bool
Definition: G4Types.hh:86
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()