Geant4  10.01.p03
G4ITReaction.hh
Go to the documentation of this file.
1 /*
2  * G4ITReactionInfo.hh
3  *
4  * Created on: 1 févr. 2015
5  * Author: matkara
6  */
7 
8 #ifndef G4ITREACTIONINFO_HH_
9 #define G4ITREACTIONINFO_HH_
10 
11 #include "tls.hh"
12 #include <list>
13 #include <map>
14 #include <G4memory.hh>
15 #include "G4Track.hh"
16 #include <set>
17 
18 typedef G4shared_ptr< std::vector<G4Track*> > G4TrackVectorHandle;
19 
20 #ifndef compTrackPerID__
21 #define compTrackPerID__
23  {
24  bool operator()(G4Track* rhs, G4Track* lhs) const
25  {
26  return rhs->GetTrackID() < lhs->GetTrackID();
27  }
28  };
29 #endif
30 
31 class G4Track;
32 class G4ITReactionSet;
35 typedef G4shared_ptr<G4ITReaction> G4ITReactionPtr;
36 typedef G4shared_ptr<G4ITReactionPerTrack> G4ITReactionPerTrackPtr;
37 
38 typedef std::list<G4ITReactionPtr> G4ITReactionList;
39 typedef std::map<G4Track*,
42 typedef std::list<std::pair<G4ITReactionPerTrackPtr,
43  G4ITReactionList::iterator> > G4ReactionPerTrackIt;
44 
45 class G4ITReaction : public G4enable_shared_from_this<G4ITReaction>
46 {
47  G4ITReaction(double time, G4Track*, G4Track*);
48 public:
49  static G4ITReactionPtr New(double time, G4Track* trackA, G4Track* trackB)
50  {
51  return G4ITReactionPtr(new G4ITReaction(time, trackA, trackB));
52  }
53  virtual ~G4ITReaction();
54 
56  {
57  if(fReactants.first != trackA) return fReactants.first;
58  return fReactants.second;
59  }
60 
61  std::pair<G4Track*, G4Track*> GetReactants() const{
62  return fReactants;
63  }
64 
65  void RemoveMe(G4ITReactionSet* reactionSet);
66 
67  void AddIterator(G4ITReactionPerTrackPtr reactionPerTrack,
68  G4ITReactionList::iterator it)
69  {
70  fReactionPerTrack.push_back(std::make_pair(reactionPerTrack, it));
71  }
72 
73  double fTime;
74  std::pair<G4Track*, G4Track*> fReactants;
76  //static G4ThreadLocal std::set<G4ITReaction*>* gAll;
77 };
78 
79 class G4ITReactionPerTrack : public G4enable_shared_from_this<G4ITReactionPerTrack>
80 {
82 public:
84  {
86  }
87 
89  {
90  fReactions.clear();
91  }
92 
94  {
95  G4ITReactionList::iterator it =
96  fReactions.insert(fReactions.end(), reaction);
97  reaction->AddIterator(this->shared_from_this(), it);
98  }
99 
100  void AddIterator(G4ITReactionPerTrackMap::iterator it)
101  {
102  fReactionSetIt.push_back(it);
103  }
104 
105  bool RemoveReaction(G4ITReactionList::iterator it,
106  G4ITReactionSet* reactionSet);
107  void RemoveMe(G4ITReactionSet* reactionSet)
108  {
109  G4ITReactionList::iterator next;
110  G4ITReactionPerTrackPtr backMeUp = this->shared_from_this();
111  for(G4ITReactionList::iterator it = fReactions.begin() ;
112  it != fReactions.end() ; it = next)
113  {
114  next = it;
115  ++next;
116  (*it)->RemoveMe(reactionSet);
117  }
118  fReactions.clear();
119  fReactionSetIt.clear();
120  }
121 
123  {
124  return fReactions;
125  }
126 
127  std::list<G4ITReactionPerTrackMap::iterator>& GetListOfIterators()
128  {
129  return fReactionSetIt;
130  }
131 
132 protected:
134  std::list<G4ITReactionPerTrackMap::iterator> fReactionSetIt;
135 };
136 
138 {
139 public:
142 
143  void AddReaction(double time, G4Track* trackA, G4Track* trackB)
144  {
145  G4ITReactionPtr reaction(G4ITReaction::New(time, trackA, trackB));
146  AddReaction(trackA, reaction);
147  AddReaction(trackB, reaction);
148  }
149 
150  void AddReactions(double time, G4Track* trackA, G4TrackVectorHandle reactants)
151  {
152  std::vector<G4Track*>::iterator it = reactants->begin();
153  for(;it != reactants->end() ; ++it)
154  {
155  AddReaction(time, trackA, *it);
156  }
157  }
158 
160  {
161  G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.find(track);
162  if(it != fReactionPerTrack.end())
163  {
164  G4ITReactionPerTrackPtr backItUp = it->second->shared_from_this();
165  backItUp->RemoveMe(this);
166  //fReactionPerTrack.erase(it); // not needed : once empty ==> auto-erase
167  it = fReactionPerTrack.find(track);
168  if(it != fReactionPerTrack.end())
169  {
170  fReactionPerTrack.erase(it);
171  }
172  }
173  }
174 
176  {
177  reaction->RemoveMe(this);
178  RemoveReactionSet(reaction->GetReactants().first);
179  RemoveReactionSet(reaction->GetReactants().second);
180  }
181 
182  G4ITReactionPerTrackMap& GetReactionMap()
183  {
184  return fReactionPerTrack;
185  }
186 
188  {
189  for(std::list<G4ITReactionPerTrackMap::iterator>::iterator it =
190  reactionPerTrack->GetListOfIterators().begin() ;
191  it != reactionPerTrack->GetListOfIterators().end() ;
192  ++it)
193  {
194  fReactionPerTrack.erase(*it);
195  }
196  reactionPerTrack->GetListOfIterators().clear();
197  reactionPerTrack->GetReactionList().clear();
198  }
199 
201  {
202  for(G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.begin();
203  it != fReactionPerTrack.end() ;
204  it = fReactionPerTrack.begin())
205  {
206  it->second->RemoveMe(this);
207  }
208  fReactionPerTrack.clear();
209  }
210 
211  bool Empty()
212  {
213  return fReactionPerTrack.empty();
214  }
215 
216 protected:
217  void AddReaction(G4Track* track, G4ITReactionPtr reaction)
218  {
219  G4ITReactionPerTrackMap::iterator it = fReactionPerTrack.find(track);
220 
221  G4ITReactionPerTrackPtr reactionPerTrack;
222 
223  if(it == fReactionPerTrack.end())
224  {
225  reactionPerTrack = G4ITReactionPerTrack::New();
226  std::pair< G4ITReactionPerTrackMap::iterator,bool> pos =
227  fReactionPerTrack.insert(std::make_pair(track, reactionPerTrack));
228  reactionPerTrack->AddIterator(pos.first);
229  }
230  else
231  {
232  reactionPerTrack = it->second;
233  }
234 
235  reactionPerTrack->AddReaction(reaction);
236  }
237  G4ITReactionPerTrackMap fReactionPerTrack;
238 };
239 
240 #endif /* G4ITREACTIONINFO_HH_ */
bool RemoveReaction(G4ITReactionList::iterator it, G4ITReactionSet *reactionSet)
Definition: G4ITReaction.cc:41
G4ITReactionPerTrackMap fReactionPerTrack
virtual ~G4ITReactionSet()
G4ITReaction(double time, G4Track *, G4Track *)
Definition: G4ITReaction.cc:14
virtual ~G4ITReaction()
Definition: G4ITReaction.cc:23
#define G4enable_shared_from_this
Definition: G4memory.hh:48
G4ITReactionList & GetReactionList()
std::list< G4ITReactionPerTrackMap::iterator > fReactionSetIt
void RemoveReactionSet(G4Track *track)
void AddReaction(G4Track *track, G4ITReactionPtr reaction)
G4shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
Definition: G4ITReaction.hh:18
void AddReactions(double time, G4Track *trackA, G4TrackVectorHandle reactants)
G4shared_ptr< G4ITReaction > G4ITReactionPtr
Definition: G4ITReaction.hh:34
static G4ITReactionPerTrackPtr New()
Definition: G4ITReaction.hh:83
void AddReaction(double time, G4Track *trackA, G4Track *trackB)
std::map< G4Track *, G4ITReactionPerTrackPtr, compTrackPerID > G4ITReactionPerTrackMap
Definition: G4ITReaction.hh:41
G4ITReactionPerTrackMap & GetReactionMap()
void SelectThisReaction(G4ITReactionPtr reaction)
void RemoveMe(G4ITReactionSet *reactionSet)
void AddReaction(G4ITReactionPtr reaction)
Definition: G4ITReaction.hh:93
std::list< G4ITReactionPerTrackMap::iterator > & GetListOfIterators()
std::list< G4ITReactionPtr > G4ITReactionList
Definition: G4ITReaction.hh:38
G4Track * GetReactant(G4Track *trackA)
Definition: G4ITReaction.hh:55
std::pair< G4Track *, G4Track * > GetReactants() const
Definition: G4ITReaction.hh:61
G4int GetTrackID() const
void RemoveReactionPerTrack(G4ITReactionPerTrackPtr reactionPerTrack)
static G4ITReactionPtr New(double time, G4Track *trackA, G4Track *trackB)
Definition: G4ITReaction.hh:49
G4shared_ptr< G4ITReactionPerTrack > G4ITReactionPerTrackPtr
Definition: G4ITReaction.hh:36
std::pair< G4Track *, G4Track * > fReactants
Definition: G4ITReaction.hh:74
G4ITReactionList fReactions
void AddIterator(G4ITReactionPerTrackPtr reactionPerTrack, G4ITReactionList::iterator it)
Definition: G4ITReaction.hh:67
void CleanAllReaction()
void AddIterator(G4ITReactionPerTrackMap::iterator it)
std::list< std::pair< G4ITReactionPerTrackPtr, G4ITReactionList::iterator > > G4ReactionPerTrackIt
Definition: G4ITReaction.hh:43
void RemoveMe(G4ITReactionSet *reactionSet)
Definition: G4ITReaction.cc:28
G4ReactionPerTrackIt fReactionPerTrack
Definition: G4ITReaction.hh:75
bool operator()(G4Track *rhs, G4Track *lhs) const
Definition: G4ITReaction.hh:24
static const G4double pos
virtual ~G4ITReactionPerTrack()
Definition: G4ITReaction.hh:88