Geant4 11.2.2
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 "G4Allocator.hh"
33#include "G4VDigiCollection.hh"
34#include "globals.hh"
35
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() override = default;
53
54 G4bool operator==(const G4DigiCollection& right) const { return (this == &right); }
55
56 protected:
57 void* theCollection = nullptr;
58};
59
60#if defined G4DIGI_ALLOC_EXPORT
62#else
64#endif
65
66template <class T>
68{
69 public:
71 G4TDigiCollection(G4String detName, G4String colNam);
72 ~G4TDigiCollection() override;
73
74 G4bool operator==(const G4TDigiCollection& right) const;
75
76 inline void* operator new(size_t);
77 inline void operator delete(void* aDC);
78
79 // Invoke Draw() method on all stored digit objects in collection
80 void DrawAllDigi() override;
81
82 // Invoke Print() method on all stored digit objects in collection
83 void PrintAllDigi() override;
84
85 // Returns pointer to the concrete digi object at index i
86 // Not bounds checked
87 inline T* operator[](size_t i) const { return (*((std::vector<T*>*)theCollection))[i]; }
88
89 // Returns pointer to stored collection vector.
90 inline std::vector<T*>* GetVector() const { return (std::vector<T*>*)theCollection; }
91
92 // Insert a digit object in the collection, taking ownership
93 // Returns the total number of digi objects stored after insertion
94 inline size_t insert(T* aHit)
95 {
96 auto theDigiCollection = (std::vector<T*>*)theCollection;
97 theDigiCollection->push_back(aHit);
98 return theDigiCollection->size();
99 }
100
101 // Returns the number of digi objects stored in this collection.
102 inline size_t entries() const
103 {
104 auto theDigiCollection = (std::vector<T*>*)theCollection;
105 return theDigiCollection->size();
106 }
107
108 G4VDigi* GetDigi(size_t i) const override { return (*((std::vector<T*>*)theCollection))[i]; }
109
110 size_t GetSize() const override { return ((std::vector<T*>*)theCollection)->size(); }
111};
112
113template <class T>
114inline void* G4TDigiCollection<T>::operator new(size_t)
115{
116 if (aDCAllocator_G4MT_TLS_() == nullptr) {
118 }
119 return (void*)aDCAllocator_G4MT_TLS_()->MallocSingle();
120}
121
122template <class T>
123inline void G4TDigiCollection<T>::operator delete(void* aDC)
124{
125 aDCAllocator_G4MT_TLS_()->FreeSingle((G4DigiCollection*)aDC);
126}
127
128template <class T>
130{
131 auto theDigiCollection = new std::vector<T*>;
132 theCollection = (void*)theDigiCollection;
133}
134
135template <class T>
137 : G4DigiCollection(detName, colNam)
138{
139 auto theDigiCollection = new std::vector<T*>;
140 theCollection = (void*)theDigiCollection;
141}
142
143template <class T>
145{
146 auto theDigiCollection = (std::vector<T*>*)theCollection;
147 for (const auto* digi : *theDigiCollection) {
148 delete digi;
149 }
150 theDigiCollection->clear();
151 delete theDigiCollection;
152}
153
154template <class T>
156{
157 return (collectionName == right.collectionName);
158}
159
160template <class T>
162{
163 auto theDigiCollection = (std::vector<T*>*)theCollection;
164 for (auto* digi : *theDigiCollection) {
165 digi->Draw();
166 }
167}
168
169template <class T>
171{
172 auto theDigiCollection = (std::vector<T*>*)theCollection;
173 for (auto* digi : *theDigiCollection) {
174 digi->Print();
175 }
176}
177
178#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
~G4DigiCollection() override=default
G4bool operator==(const G4DigiCollection &right) const
void DrawAllDigi() override
G4bool operator==(const G4TDigiCollection &right) const
size_t insert(T *aHit)
void PrintAllDigi() override
size_t GetSize() const override
std::vector< T * > * GetVector() const
T * operator[](size_t i) const
G4VDigi * GetDigi(size_t i) const override
G4VDigiCollection()=default