Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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() {}
61};
62
63//------------------------------------------------------------------------------
64
65template<class T>
67{
68public:
69 static int GetID() { return fID; }
70
71private:
72 static const int fID;
73
76};
77
78template<class T>
80
81//------------------------------------------------------------------------------
82
84{
85public:
87 virtual ~G4VTrackState() {}
88 virtual int GetID() = 0;
89};
90
91//------------------------------------------------------------------------------
92
93typedef G4shared_ptr<G4VTrackState> G4VTrackStateHandle;
94
95//------------------------------------------------------------------------------
96//!
97template<class T>
99
100template<class T>
102{
103public:
104 virtual ~G4TrackStateBase() {}
105
106 virtual int GetID() {
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() {}
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 std::map<void*, G4VTrackStateHandle>::const_iterator 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 std::map<void*, G4VTrackStateHandle>::const_iterator 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 std::map<int, G4VTrackStateHandle>::const_iterator 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:
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>
213G4shared_ptr<G4VTrackState>
215{
216
217 G4shared_ptr<G4VTrackState> output =
218 G4dynamic_pointer_cast<G4VTrackState>(state);
219 return output;
220}
221
222template<class FinalType>
223G4shared_ptr<G4TrackState<FinalType> >
225{
226
227 G4shared_ptr<G4TrackState<FinalType> > output =
228 G4dynamic_pointer_cast<G4TrackState<FinalType>>(state);
229 return output;
230}
231
232//------------------------------------------------------------------------------
233//!
234template<class T>
236{
237public:
238 typedef T ClassType;
240 typedef G4shared_ptr<StateType> StateTypeHandle;
241
243
244 virtual void SetTrackState(G4shared_ptr<StateType> state)
245 {
246 fpTrackState = state;
247 }
248
250 {
251 G4VTrackStateHandle output =
252 G4dynamic_pointer_cast<G4VTrackState>(fpTrackState);
253 fpTrackState.reset();
254 return output;
255 }
256
258 {
259 G4VTrackStateHandle output =
260 G4dynamic_pointer_cast<G4VTrackState>(fpTrackState);
261 return output;
262 }
263
265 {
266 return fpTrackState;
267 }
268
269 virtual void LoadTrackState(G4TrackStateManager& manager)
270 {
272 ConvertToConcreteTrackState<ClassType>(manager.GetTrackState(this));
273 if (fpTrackState == nullptr)
274 {
276 SaveTrackState(manager);
277 }
278 }
279
280 virtual void SaveTrackState(G4TrackStateManager& manager)
281 {
283 }
284
285 virtual void NewTrackState()
286 {
288 }
289
291 {
292 return StateTypeHandle(new StateType());
293 }
294
295 virtual void ResetTrackState()
296 {
297 fpTrackState.reset();
298 }
299
300protected:
303 {}
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_ */
G4shared_ptr< G4VTrackState > G4VTrackStateHandle
Definition: G4TrackState.hh:93
G4shared_ptr< G4VTrackState > ConvertToAbstractTrackState(G4shared_ptr< G4TrackState< OriginalType > > state)
G4shared_ptr< G4TrackState< FinalType > > ConvertToConcreteTrackState(G4VTrackStateHandle state)
#define G4shared_ptr
Definition: G4memory.hh:32
virtual ~G4TrackStateBase()
static int ID()
virtual int GetID()
virtual StateTypeHandle CreateTrackState() const
virtual void NewTrackState()
virtual StateTypeHandle GetConcreteTrackState() const
virtual void SetTrackState(G4shared_ptr< StateType > state)
virtual G4VTrackStateHandle PopTrackState()
virtual void SaveTrackState(G4TrackStateManager &manager)
virtual ~G4TrackStateDependent()
virtual void LoadTrackState(G4TrackStateManager &manager)
G4shared_ptr< StateType > StateTypeHandle
G4TrackState< T > StateType
virtual void ResetTrackState()
StateTypeHandle fpTrackState
virtual G4VTrackStateHandle GetTrackState() const
static int GetID()
Definition: G4TrackState.hh:69
void SetTrackState(void *adress, G4VTrackStateHandle state)
G4VTrackStateHandle GetTrackState(void *adress) const
void SetTrackState(G4VTrackStateHandle state)
G4VTrackStateHandle GetTrackState() const
G4VTrackStateHandle GetTrackState(T *adress) const
static int ID()
virtual ~G4TrackState()
virtual ~G4VTrackStateDependent()
virtual G4VTrackStateHandle GetTrackState() const =0
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()
Definition: G4TrackState.cc:38
static int fgLastID
Definition: G4TrackState.hh:56
virtual ~G4VTrackStateID()
Definition: G4TrackState.hh:60
virtual ~G4VTrackState()
Definition: G4TrackState.hh:87
virtual int GetID()=0