Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4ITReaction.hh
이 파일의 문서화 페이지로 가기
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  * G4ITReactionInfo.hh
28  *
29  * Created on: 1 févr. 2015
30  * Author: matkara
31  */
32 
33 #ifndef G4ITREACTIONINFO_HH_
34 #define G4ITREACTIONINFO_HH_
35 
36 #include "tls.hh"
37 #include <list>
38 #include <map>
39 #include <G4memory.hh>
40 #include "G4Track.hh"
41 #include <set>
42 
43 typedef G4shared_ptr< std::vector<G4Track*> > G4TrackVectorHandle;
44 
45 #ifndef compTrackPerID__
46 #define compTrackPerID__
48  {
49  bool operator()(G4Track* rhs, G4Track* lhs) const
50  {
51  return rhs->GetTrackID() < lhs->GetTrackID();
52  }
53  };
54 #endif
55 
56 class G4Track;
57 class G4ITReactionSet;
60 typedef G4shared_ptr<G4ITReaction> G4ITReactionPtr;
61 typedef G4shared_ptr<G4ITReactionPerTrack> G4ITReactionPerTrackPtr;
62 
63 typedef std::list<G4ITReactionPtr> G4ITReactionList;
64 typedef std::map<G4Track*,
67 typedef std::list<std::pair<G4ITReactionPerTrackPtr,
68  G4ITReactionList::iterator> > G4ReactionPerTrackIt;
69 
71 {
72  bool operator()(G4ITReactionPtr rhs,
73  G4ITReactionPtr lhs) const;
74 };
75 
76 typedef std::multiset<G4ITReactionPtr, compReactionPerTime> G4ITReactionPerTime;
77 typedef std::multiset<G4ITReactionPtr, compReactionPerTime>::iterator G4ITReactionPerTimeIt;
78 
79 class G4ITReaction : public G4enable_shared_from_this<G4ITReaction>
80 {
81  G4ITReaction(double time, G4Track*, G4Track*);
82 public:
83  static G4ITReactionPtr New(double time, G4Track* trackA, G4Track* trackB)
84  {
85  return G4ITReactionPtr(new G4ITReaction(time, trackA, trackB));
86  }
87  virtual ~G4ITReaction();
88 
90  {
91  if(fReactants.first != trackA) return fReactants.first;
92  return fReactants.second;
93  }
94 
95  std::pair<G4Track*, G4Track*> GetReactants() const{return fReactants;}
96  std::size_t GetHash() const;
97  double GetTime() { return fTime; }
98 
99  void RemoveMe();
100 
101  void AddIterator(G4ITReactionPerTrackPtr reactionPerTrack,
102  G4ITReactionList::iterator it)
103  {
104  fReactionPerTrack.push_back(std::make_pair(reactionPerTrack, it));
105  }
106 
108  {
110  }
111 
112  double fTime;
113  std::pair<G4Track*, G4Track*> fReactants;
116 
117  //static G4ThreadLocal std::set<G4ITReaction*>* gAll;
118 };
119 
120 class G4ITReactionPerTrack : public G4enable_shared_from_this<G4ITReactionPerTrack>
121 {
123 public:
125  {
127  }
128 
130  {
131  fReactions.clear();
132  }
133 
135  {
136  G4ITReactionList::iterator it =
137  fReactions.insert(fReactions.end(), reaction);
138  reaction->AddIterator(this->shared_from_this(), it);
139  }
140 
141  void AddIterator(G4ITReactionPerTrackMap::iterator it)
142  {
143  fReactionSetIt.push_back(it);
144  }
145 
146  bool RemoveThisReaction(G4ITReactionList::iterator it);
147  void RemoveMe()
148  {
149  G4ITReactionPerTrackPtr backMeUp = this->shared_from_this();
150 
151  G4ITReactionList::iterator next;
152  for(G4ITReactionList::iterator it = fReactions.begin() ;
153  it != fReactions.end() ; it = next)
154  {
155  next = it;
156  ++next;
157  (*it)->RemoveMe();
158  }
159  fReactions.clear();
160  fReactionSetIt.clear();
161  }
162 
164  {
165  return fReactions;
166  }
167 
168  std::list<G4ITReactionPerTrackMap::iterator>& GetListOfIterators()
169  {
170  return fReactionSetIt;
171  }
172 
173 protected:
175  std::list<G4ITReactionPerTrackMap::iterator> fReactionSetIt;
176 };
177 
179 {
180  G4ITReactionSet() //: fReactionPerTime(compReactionPerTime())
181  {
182  fpInstance = this;
183  fSortByTime = false;
184  }
185 public:
187  {
188  fReactionPerTrack.clear();
189  fReactionPerTime.clear();
190  }
191 
193  {
194  if(fpInstance == 0) new G4ITReactionSet();
195 
196  return fpInstance;
197  }
198 
199  //------------------------------------------------------------------------------------
200 
201  void AddReaction(double time, G4Track* trackA, G4Track* trackB)
202  {
203  G4ITReactionPtr reaction(G4ITReaction::New(time, trackA, trackB));
204  AddReaction(trackA, reaction);
205  AddReaction(trackB, reaction);
206 
207  if(fSortByTime)
208  {
209  G4ITReactionPerTime::iterator it = fReactionPerTime.insert(reaction);
210  reaction->AddIterator(it);
211  }
212  }
213 
214  void AddReactions(double time, G4Track* trackA, G4TrackVectorHandle reactants)
215  {
216  std::vector<G4Track*>::iterator it = reactants->begin();
217  for(;it != reactants->end() ; ++it)
218  {
219  AddReaction(time, trackA, *it);
220  }
221  }
222 
224  {
225  G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.find(track);
226  if(it != fReactionPerTrack.end())
227  {
228  G4ITReactionPerTrackPtr backItUp = it->second->shared_from_this();
229  backItUp->RemoveMe();
230  //fReactionPerTrack.erase(it); // not needed : once empty ==> auto-erase
231  it = fReactionPerTrack.find(track);
232  if(it != fReactionPerTrack.end())
233  {
234  fReactionPerTrack.erase(it);
235  }
236  }
237  }
238 
240  {
241  reaction->RemoveMe();
242  RemoveReactionSet(reaction->GetReactants().first);
243  RemoveReactionSet(reaction->GetReactants().second);
244  }
245 
246  G4ITReactionPerTrackMap& GetReactionMap()
247  {
248  return fReactionPerTrack;
249  }
250 
252  {
253  for(std::list<G4ITReactionPerTrackMap::iterator>::iterator it =
254  reactionPerTrack->GetListOfIterators().begin() ;
255  it != reactionPerTrack->GetListOfIterators().end() ;
256  ++it)
257  {
258  fReactionPerTrack.erase(*it);
259  }
260  reactionPerTrack->GetListOfIterators().clear();
261  reactionPerTrack->GetReactionList().clear();
262  }
263 
265  {
266  for(G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.begin();
267  it != fReactionPerTrack.end() ;
268  it = fReactionPerTrack.begin())
269  {
270  it->second->RemoveMe();
271  }
272  fReactionPerTrack.clear();
273  fReactionPerTime.clear();
274  }
275 
276  bool Empty()
277  {
278  return fReactionPerTrack.empty();
279  }
280 
282  {
283  return fReactionPerTime;
284  }
285 
286 protected:
288  {
289  G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.find(track);
290 
291  G4ITReactionPerTrackPtr reactionPerTrack;
292 
293  if(it == fReactionPerTrack.end())
294  {
295  reactionPerTrack = G4ITReactionPerTrack::New();
296  std::pair< G4ITReactionPerTrackMap::iterator,bool> pos =
297  fReactionPerTrack.insert(std::make_pair(track, reactionPerTrack));
298  reactionPerTrack->AddIterator(pos.first);
299  }
300  else
301  {
302  reactionPerTrack = it->second;
303  }
304 
305  reactionPerTrack->AddReaction(reaction);
306  }
307  G4ITReactionPerTrackMap fReactionPerTrack;
309 
312 };
313 
314 #endif /* G4ITREACTIONINFO_HH_ */
static G4ITReactionSet * Instance()
bool RemoveThisReaction(G4ITReactionList::iterator it)
G4Track * GetReactant(G4Track *trackA)
Definition: G4ITReaction.hh:89
virtual ~G4ITReaction()
Definition: G4ITReaction.cc:80
static const G4double pos
G4ITReactionPerTimeIt * fReactionPerTimeIt
G4ITReactionList & GetReactionList()
bool operator()(G4Track *rhs, G4Track *lhs) const
Definition: G4ITReaction.hh:49
void RemoveReactionSet(G4Track *track)
G4int GetTrackID() const
virtual ~G4ITReactionPerTrack()
G4ITReaction(double time, G4Track *, G4Track *)
Definition: G4ITReaction.cc:69
G4shared_ptr< G4ITReactionPerTrack > G4ITReactionPerTrackPtr
Definition: G4ITReaction.hh:61
#define G4ThreadLocal
Definition: tls.hh:69
G4shared_ptr< G4ITReaction > G4ITReactionPtr
Definition: G4ITReaction.hh:59
void AddReaction(G4Track *track, G4ITReactionPtr reaction)
void CleanAllReaction()
void RemoveReactionPerTrack(G4ITReactionPerTrackPtr reactionPerTrack)
G4ReactionPerTrackIt fReactionPerTrack
std::pair< G4Track *, G4Track * > fReactants
std::multiset< G4ITReactionPtr, compReactionPerTime >::iterator G4ITReactionPerTimeIt
Definition: G4ITReaction.hh:77
G4ITReactionPerTime fReactionPerTime
#define G4enable_shared_from_this
Definition: G4memory.hh:37
void AddReaction(G4ITReactionPtr reaction)
G4ITReactionPerTrackMap & GetReactionMap()
void AddReaction(double time, G4Track *trackA, G4Track *trackB)
std::pair< G4Track *, G4Track * > GetReactants() const
Definition: G4ITReaction.hh:95
std::map< G4Track *, G4ITReactionPerTrackPtr, compTrackPerID > G4ITReactionPerTrackMap
Definition: G4ITReaction.hh:66
void AddIterator(G4ITReactionPerTrackPtr reactionPerTrack, G4ITReactionList::iterator it)
void AddIterator(G4ITReactionPerTrackMap::iterator it)
void SelectThisReaction(G4ITReactionPtr reaction)
static G4ITReactionPtr New(double time, G4Track *trackA, G4Track *trackB)
Definition: G4ITReaction.hh:83
static G4ITReactionPerTrackPtr New()
std::list< std::pair< G4ITReactionPerTrackPtr, G4ITReactionList::iterator > > G4ReactionPerTrackIt
Definition: G4ITReaction.hh:68
std::list< G4ITReactionPtr > G4ITReactionList
Definition: G4ITReaction.hh:63
std::list< G4ITReactionPerTrackMap::iterator > & GetListOfIterators()
std::multiset< G4ITReactionPtr, compReactionPerTime > G4ITReactionPerTime
Definition: G4ITReaction.hh:76
std::size_t GetHash() const
Definition: G4ITReaction.cc:61
G4ITReactionPerTrackMap fReactionPerTrack
std::list< G4ITReactionPerTrackMap::iterator > fReactionSetIt
G4ITReactionList fReactions
double GetTime()
Definition: G4ITReaction.hh:97
void AddIterator(G4ITReactionPerTimeIt it)
virtual ~G4ITReactionSet()
static G4ThreadLocal G4ITReactionSet * fpInstance
G4ITReactionPerTime & GetReactionsPerTime()
bool operator()(G4ITReactionPtr rhs, G4ITReactionPtr lhs) const
Definition: G4ITReaction.cc:40
G4shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
Definition: G4ITReaction.hh:43
void RemoveMe()
Definition: G4ITReaction.cc:86
void AddReactions(double time, G4Track *trackA, G4TrackVectorHandle reactants)