Geant4-11
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 {
92 return (*((std::vector<T*>*) theCollection))[i];
93 }
94 // Returns a pointer to a concrete digi object.
95 inline std::vector<T*>* GetVector() const
96 {
99 return (std::vector<T*>*) theCollection;
100 }
101 // Returns a collection vector.
102 inline size_t insert(T* aHit)
103 {
106 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
107 theDigiCollection->push_back(aHit);
108 return theDigiCollection->size();
109 }
110 // Insert a digi object. Total number of digi objects stored in this
111 // collection is returned.
112 inline size_t entries() const
113 {
116 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
117 return theDigiCollection->size();
118 }
119 // Returns the number of digi objcets stored in this collection.
120
121 public:
122 virtual G4VDigi* GetDigi(size_t i) const
123 {
126 return (*((std::vector<T*>*) theCollection))[i];
127 }
128 virtual size_t GetSize() const
129 {
132 return ((std::vector<T*>*) theCollection)->size();
133 }
134};
135
136template <class T>
137inline void* G4TDigiCollection<T>::operator new(size_t)
138{
142 void* aDC;
143 aDC = (void*) aDCAllocator.MallocSingle();
144 return aDC;
145}
146
147template <class T>
148inline void G4TDigiCollection<T>::operator delete(void* aDC)
149{
153 ;
154 ;
155 ;
156 aDCAllocator.FreeSingle((G4DigiCollection*) aDC);
157}
158
159template <class T>
161{
164 std::vector<T*>* theDigiCollection = new std::vector<T*>;
165 theCollection = (void*) theDigiCollection;
166}
167
168template <class T>
170 : G4DigiCollection(detName, colNam)
171{
174
175 std::vector<T*>* theDigiCollection = new std::vector<T*>;
176 theCollection = (void*) theDigiCollection;
177}
178
179template <class T>
181{
184 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
185 // theDigiCollection->clearAndDestroy();
186 for(size_t i = 0; i < theDigiCollection->size(); i++)
187 {
188 delete(*theDigiCollection)[i];
189 }
190 theDigiCollection->clear();
191 delete theDigiCollection;
192}
193
194template <class T>
196{
199 return (collectionName == right.collectionName);
200}
201
202template <class T>
204{
207 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
208 size_t n = theDigiCollection->size();
209 for(size_t i = 0; i < n; i++)
210 {
211 (*theDigiCollection)[i]->Draw();
212 }
213}
214
215template <class T>
217{
220 std::vector<T*>* theDigiCollection = (std::vector<T*>*) theCollection;
221 size_t n = theDigiCollection->size();
222 for(size_t i = 0; i < n; i++)
223 {
224 (*theDigiCollection)[i]->Print();
225 }
226}
227
228#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
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()