Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TrackState.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// Author: Mathieu Karamitros
27
28// The code is developed in the framework of the ESA AO7146
29//
30// We would be very happy hearing from you, send us your feedback! :)
31//
32// In order for Geant4-DNA to be maintained and still open-source,
33// article citations are crucial.
34// If you use Geant4-DNA chemistry and you publish papers about your software,
35// in addition to the general paper on Geant4-DNA:
36//
37// Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
38//
39// we would be very happy if you could please also cite the following
40// reference papers on chemistry:
41//
42// J. Comput. Phys. 274 (2014) 841-882
43// Prog. Nucl. Sci. Tec. 2 (2011) 503-508
44
45#ifndef G4TRACKSTATE_HH_
46#define G4TRACKSTATE_HH_
47
48#include <map>
49#include "G4memory.hh"
50
51//------------------------------------------------------------------------------
52
54{
55protected:
56 static int fgLastID;
57 static int Create();
58
60 virtual ~G4VTrackStateID() = default;
61};
62
63//------------------------------------------------------------------------------
64
65template<class T>
67{
68public:
69 static int GetID() { return fID; }
70
71private:
72 static const int fID;
73
75 ~G4TrackStateID() override = default;
76};
77
78template<class T>
80
81//------------------------------------------------------------------------------
82
84{
85public:
86 G4VTrackState() = default;
87 virtual ~G4VTrackState() = default;
88 virtual int GetID() = 0;
89};
90
91//------------------------------------------------------------------------------
92
93using G4VTrackStateHandle = std::shared_ptr<G4VTrackState>;
94
95//------------------------------------------------------------------------------
96//!
97template<class T>
99
100template<class T>
102{
103public:
104 ~G4TrackStateBase() override = default;
105
106 int GetID() override {
108 }
109
110 static int ID() {
112 }
113
114protected:
116};
117
118//------------------------------------------------------------------------------
119
120template<class T>
122{
123 /*
124 // friend T; // works in c++11
125 */
126 friend class G4TrackStateDependent<T>; //!
127
128public:
129 virtual ~G4TrackState() = default;
130
131 static int ID() {
133 }
134
136};
137
138//------------------------------------------------------------------------------
139
140
142{
143 std::map<int, G4VTrackStateHandle> fTrackStates;
144 std::map<void*, G4VTrackStateHandle> fMultipleTrackStates;
145
146public:
147
148 void SetTrackState(void* adress, G4VTrackStateHandle state)
149 {
150 fMultipleTrackStates[adress] = state;
151 }
152
154 {
155 auto it =
156 fMultipleTrackStates.find(adress);
157 if (it == fMultipleTrackStates.end())
158 {
159 return G4VTrackStateHandle();
160 }
161 return it->second;
162 }
163
164 template<class T>
166 {
167 auto it =
168 fMultipleTrackStates.find((void*)adress);
169 if (it == fMultipleTrackStates.end())
170 {
171 return G4VTrackStateHandle();
172 }
173 return it->second;
174 }
175
177 {
178 fTrackStates[state->GetID()] = state;
179 }
180
181 template<typename T>
183 {
184 auto it =
185 fTrackStates.find(G4TrackStateID<T>::GetID());
186 if (it == fTrackStates.end())
187 {
188 return G4VTrackStateHandle();
189 }
190 return it->second;
191 }
192};
193
194//------------------------------------------------------------------------------
195
197{
198public:
200 virtual ~G4VTrackStateDependent() = default;
201
202 virtual void NewTrackState() = 0;
207 virtual void ResetTrackState() = 0;
208};
209
210#define G4TrackStateHandle(T) G4shared_ptr<G4TrackState<T> >
211
212template<class OriginalType>
221
222template<class FinalType>
231
232//------------------------------------------------------------------------------
233//!
234template<class T>
236{
237public:
238 using ClassType = T;
240 using StateTypeHandle = std::shared_ptr<StateType>;
241
242 ~G4TrackStateDependent() override = default;
243
245 {
246 fpTrackState = state;
247 }
248
250 {
251 G4VTrackStateHandle output =
253 fpTrackState.reset();
254 return output;
255 }
256
258 {
259 G4VTrackStateHandle output =
261 return output;
262 }
263
265 {
266 return fpTrackState;
267 }
268
269 void LoadTrackState(G4TrackStateManager& manager) override
270 {
273 if (fpTrackState == nullptr)
274 {
276 SaveTrackState(manager);
277 }
278 }
279
280 void SaveTrackState(G4TrackStateManager& manager) override
281 {
283 }
284
285 void NewTrackState() override
286 {
288 }
289
291 {
292 return StateTypeHandle(new StateType());
293 }
294
295 void ResetTrackState() override
296 {
297 fpTrackState.reset();
298 }
299
300protected:
304
306};
307
308//------------------------------------------------------------------------------
309
310#if __cplusplus > 199711L
311#define RegisterTrackState(CLASS,STATE) \
312 template<> \
313 class G4TrackState<CLASS> : public G4TrackStateBase<CLASS>, \
314 public CLASS::STATE \
315 { \
316 friend class G4TrackStateDependent<CLASS>; \
317 using CLASS::STATE::STATE; \
318 public: \
319 typedef CLASS::STATE State; \
320 G4TrackState() : G4TrackStateBase<CLASS>(), CLASS::STATE(){}\
321 virtual ~G4TrackState(){}\
322 virtual int GetID()\
323 {\
324 return G4TrackStateID<CLASS>::GetID();\
325 }\
326 static int ID()\
327 {\
328 return G4TrackStateID<CLASS>::GetID();\
329 }\
330 protected:\
331 };
332#else
333#define RegisterTrackState(CLASS,STATE) \
334 template<> \
335 class G4TrackState<CLASS> : public G4TrackStateBase<CLASS>, \
336 public CLASS::STATE \
337 { \
338 friend class G4TrackStateDependent<CLASS>; \
339 public: \
340 typedef CLASS::STATE State; \
341 G4TrackState() : G4TrackStateBase<CLASS>(), CLASS::STATE(){}\
342 virtual ~G4TrackState(){}\
343 virtual int GetID()\
344 {\
345 return G4TrackStateID<CLASS>::GetID();\
346 }\
347 static int ID()\
348 {\
349 return G4TrackStateID<CLASS>::GetID();\
350 }\
351 protected:\
352 };
353#endif
354
355#endif /* G4TRACKSTATE_HH_ */
std::shared_ptr< G4VTrackState > G4VTrackStateHandle
G4shared_ptr< G4VTrackState > ConvertToAbstractTrackState(G4shared_ptr< G4TrackState< OriginalType > > state)
G4shared_ptr< G4TrackState< FinalType > > ConvertToConcreteTrackState(G4VTrackStateHandle state)
#define G4shared_ptr
Definition G4memory.hh:32
#define G4dynamic_pointer_cast
Definition G4memory.hh:36
~G4TrackStateBase() override=default
static int ID()
int GetID() override
G4TrackState< T > StateType
void LoadTrackState(G4TrackStateManager &manager) override
G4VTrackStateHandle GetTrackState() const override
virtual StateTypeHandle CreateTrackState() const
void NewTrackState() override
std::shared_ptr< StateType > StateTypeHandle
void ResetTrackState() override
virtual StateTypeHandle GetConcreteTrackState() const
virtual void SetTrackState(G4shared_ptr< StateType > state)
G4VTrackStateHandle PopTrackState() override
~G4TrackStateDependent() override=default
StateTypeHandle fpTrackState
void SaveTrackState(G4TrackStateManager &manager) override
static int GetID()
void SetTrackState(void *adress, G4VTrackStateHandle state)
G4VTrackStateHandle GetTrackState(void *adress) const
void SetTrackState(G4VTrackStateHandle state)
G4VTrackStateHandle GetTrackState() const
G4VTrackStateHandle GetTrackState(T *adress) const
virtual ~G4TrackState()=default
static int ID()
virtual G4VTrackStateHandle GetTrackState() const =0
virtual ~G4VTrackStateDependent()=default
G4VTrackStateDependent()=default
virtual void LoadTrackState(G4TrackStateManager &)=0
virtual void SaveTrackState(G4TrackStateManager &)=0
virtual void NewTrackState()=0
virtual void ResetTrackState()=0
virtual G4VTrackStateHandle PopTrackState()=0
static int Create()
virtual ~G4VTrackStateID()=default
static int fgLastID
virtual int GetID()=0
G4VTrackState()=default
virtual ~G4VTrackState()=default