Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/electromagnetic/dna/management/src/G4ITTrackHolder.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/electromagnetic/dna/management/src/G4ITTrackHolder.cc (Version 11.3.0) and /processes/electromagnetic/dna/management/src/G4ITTrackHolder.cc (Version 11.2.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 /*                                                 26 /*
 27  * G4MIMolecularTracks.cc                          27  * G4MIMolecularTracks.cc
 28  *                                                 28  *
 29  *  Created on: 17 sept. 2014                      29  *  Created on: 17 sept. 2014
 30  *      Author: kara                               30  *      Author: kara
 31  */                                                31  */
 32                                                    32 
 33 #include <G4Scheduler.hh>                          33 #include <G4Scheduler.hh>
 34 #include <G4VScheduler.hh>                         34 #include <G4VScheduler.hh>
 35 #include "G4ITTrackHolder.hh"                      35 #include "G4ITTrackHolder.hh"
 36 #include "G4IT.hh"                                 36 #include "G4IT.hh"
 37 #include "G4Track.hh"                              37 #include "G4Track.hh"
 38 #include "G4UnitsTable.hh"                         38 #include "G4UnitsTable.hh"
 39 #include "G4AutoLock.hh"                           39 #include "G4AutoLock.hh"
 40 #include "G4Threading.hh"                          40 #include "G4Threading.hh"
 41                                                    41 
 42 using namespace std;                               42 using namespace std;
 43                                                    43 
 44 PriorityList::PriorityList() :                     44 PriorityList::PriorityList() :
 45      fpMainList(nullptr), fpWaitingList(nullpt     45      fpMainList(nullptr), fpWaitingList(nullptr)
 46 {                                                  46 {
 47 }                                                  47 }
 48                                                    48 
 49 PriorityList::PriorityList(G4TrackManyList& al     49 PriorityList::PriorityList(G4TrackManyList& allMainList):
 50      fpMainList(nullptr), fpWaitingList(nullpt     50      fpMainList(nullptr), fpWaitingList(nullptr)
 51 {                                                  51 {
 52   NewMainList(allMainList);                        52   NewMainList(allMainList);
 53 }                                                  53 }
 54                                                    54 
 55 PriorityList::PriorityList(const PriorityList&     55 PriorityList::PriorityList(const PriorityList& right) :
 56                                                    56     
 57     fpMainList(right.fpMainList),                  57     fpMainList(right.fpMainList),
 58     fpWaitingList(right.fpWaitingList)             58     fpWaitingList(right.fpWaitingList)
 59 {                                                  59 {
 60 }                                                  60 }
 61                                                    61 
 62 PriorityList::~PriorityList()                      62 PriorityList::~PriorityList()
 63 {                                                  63 {
 64   if (fpMainList != nullptr)                       64   if (fpMainList != nullptr)
 65   {                                                65   {
 66     delete fpMainList;                             66     delete fpMainList;
 67     fpMainList = nullptr;                          67     fpMainList = nullptr;
 68   }                                                68   }
 69   if (fpWaitingList != nullptr)                    69   if (fpWaitingList != nullptr)
 70   {                                                70   {
 71     delete fpWaitingList;                          71     delete fpWaitingList;
 72     fpWaitingList = nullptr;                       72     fpWaitingList = nullptr;
 73   }                                                73   }
 74 }                                                  74 }
 75                                                    75 
 76 void PriorityList::NotifyDeletingList(G4TrackL     76 void PriorityList::NotifyDeletingList(G4TrackList* __list)
 77 {                                                  77 {
 78   if (__list == fpMainList)                        78   if (__list == fpMainList)
 79   {                                                79   {
 80 //    StopWatching(fpMainList);                    80 //    StopWatching(fpMainList);
 81     fpMainList = nullptr;                          81     fpMainList = nullptr;
 82   }                                                82   }
 83   else if (__list == fpWaitingList)                83   else if (__list == fpWaitingList)
 84   {                                                84   {
 85 //    StopWatching(fpWaitingList);                 85 //    StopWatching(fpWaitingList);
 86     fpWaitingList = nullptr;                       86     fpWaitingList = nullptr;
 87   }                                                87   }
 88 }                                                  88 }
 89                                                    89 
 90 void PriorityList::NewMainList(G4TrackList* __     90 void PriorityList::NewMainList(G4TrackList* __list,
 91                                G4TrackManyList     91                                G4TrackManyList& allMainList)
 92 {                                                  92 {
 93   fpMainList = __list;                             93   fpMainList = __list;
 94   allMainList.Add(__list);                         94   allMainList.Add(__list);
 95   Watch(fpMainList);                               95   Watch(fpMainList);
 96 }                                                  96 }
 97                                                    97 
 98 G4TrackList* PriorityList::NewMainList(G4Track     98 G4TrackList* PriorityList::NewMainList(G4TrackManyList& allMainList)
 99 {                                                  99 {
100   auto  trackList = new G4TrackList();            100   auto  trackList = new G4TrackList();
101   NewMainList(trackList, allMainList);            101   NewMainList(trackList, allMainList);
102   return fpMainList;                              102   return fpMainList;
103 }                                                 103 }
104                                                   104 
105 void PriorityList::PushToMainList(G4Track* __t    105 void PriorityList::PushToMainList(G4Track* __track,
106                                   G4TrackManyL    106                                   G4TrackManyList& allMainList)
107 {                                                 107 {
108   if (fpMainList == nullptr)                      108   if (fpMainList == nullptr)
109   {                                               109   {
110     NewMainList(allMainList);                     110     NewMainList(allMainList);
111   }                                               111   }
112   fpMainList->push_back(__track);                 112   fpMainList->push_back(__track);
113 }                                                 113 }
114                                                   114 
115 void PriorityList::TransferToMainList(G4TrackL    115 void PriorityList::TransferToMainList(G4TrackList*& __list,
116                                       G4TrackM    116                                       G4TrackManyList& allMainList)
117 {                                                 117 {
118   if (fpMainList != nullptr)                      118   if (fpMainList != nullptr)
119   {                                               119   {
120     __list->transferTo(fpMainList);               120     __list->transferTo(fpMainList);
121     delete __list;                                121     delete __list;
122     __list = nullptr;                             122     __list = nullptr;
123   }                                               123   }
124   else                                            124   else
125   {                                               125   {
126     NewMainList(__list, allMainList);             126     NewMainList(__list, allMainList);
127   }                                               127   }
128 }                                                 128 }
129                                                   129 
130 void PriorityList::PushToListOfSecondaries(G4T    130 void PriorityList::PushToListOfSecondaries(G4Track* __track,
131                                            G4T    131                                            G4TrackManyList& listOfAllSecondaries)
132 {                                                 132 {
133   //      if (priorityList->fSecondaries.empty    133   //      if (priorityList->fSecondaries.empty())
134   if (fSecondaries.GetListNode() != nullptr)      134   if (fSecondaries.GetListNode() != nullptr)
135   {                                               135   {
136     listOfAllSecondaries.Add(&fSecondaries);      136     listOfAllSecondaries.Add(&fSecondaries);
137   }                                               137   }
138   fSecondaries.push_back(__track);                138   fSecondaries.push_back(__track);
139 }                                                 139 }
140                                                   140 
141 void PriorityList::PushToWaitingList(G4Track*     141 void PriorityList::PushToWaitingList(G4Track* __track)
142 {                                                 142 {
143   if (fpWaitingList == nullptr)                   143   if (fpWaitingList == nullptr)
144   {                                               144   {
145     fpWaitingList = new G4TrackList();            145     fpWaitingList = new G4TrackList();
146   }                                               146   }
147   fpWaitingList->push_back(__track);              147   fpWaitingList->push_back(__track);
148 }                                                 148 }
149                                                   149 
150 void PriorityList::TransferSecondariesToMainLi    150 void PriorityList::TransferSecondariesToMainList()
151 {                                                 151 {
152   fSecondaries.transferTo(fpMainList);            152   fSecondaries.transferTo(fpMainList);
153 }                                                 153 }
154                                                   154 
155 void PriorityList::PushToMainList(G4Track* tra    155 void PriorityList::PushToMainList(G4Track* track)
156 {                                                 156 {
157   if (fpMainList == nullptr) fpMainList = new     157   if (fpMainList == nullptr) fpMainList = new G4TrackList();
158   fpMainList->push_back(track);                   158   fpMainList->push_back(track);
159 }                                                 159 }
160                                                   160 
161 void PriorityList::MergeWithMainList(G4TrackLi    161 void PriorityList::MergeWithMainList(G4TrackList* trackList)
162 {                                                 162 {
163   if (fpMainList == nullptr) fpMainList = new     163   if (fpMainList == nullptr) fpMainList = new G4TrackList();
164   trackList->transferTo(trackList);               164   trackList->transferTo(trackList);
165 }                                                 165 }
166                                                   166 
167 int PriorityList::GetNTracks()                    167 int PriorityList::GetNTracks()
168 {                                                 168 {
169   int nTracks = 0;                                169   int nTracks = 0;
170                                                   170 
171   if (fpMainList != nullptr)                      171   if (fpMainList != nullptr)
172   {                                               172   {
173     nTracks += fpMainList->size();                173     nTracks += fpMainList->size();
174   }                                               174   }
175                                                   175 
176   if (fpWaitingList != nullptr)                   176   if (fpWaitingList != nullptr)
177   {                                               177   {
178     nTracks += fpWaitingList->size();             178     nTracks += fpWaitingList->size();
179   }                                               179   }
180                                                   180 
181   nTracks += fSecondaries.size();                 181   nTracks += fSecondaries.size();
182                                                   182 
183   return nTracks;                                 183   return nTracks;
184 }                                                 184 }
185                                                   185 
186 //============================================    186 //=============================================================================
187 // G4ITTrackHolder                                187 // G4ITTrackHolder
188 //============================================    188 //=============================================================================
189                                                   189 
190 G4ThreadLocal G4ITTrackHolder* G4ITTrackHolder    190 G4ThreadLocal G4ITTrackHolder* G4ITTrackHolder::fgInstance(nullptr);
191 G4ITTrackHolder* G4ITTrackHolder::fgMasterInst    191 G4ITTrackHolder* G4ITTrackHolder::fgMasterInstance(nullptr);
192                                                   192 
193 G4Mutex creationOfTheMasterInstance;              193 G4Mutex creationOfTheMasterInstance;
194 G4Mutex pushToTheMasterInstance;                  194 G4Mutex pushToTheMasterInstance;
195                                                   195 
196 G4ITTrackHolder* G4ITTrackHolder::Instance()      196 G4ITTrackHolder* G4ITTrackHolder::Instance()
197 {                                                 197 {
198   if (fgInstance == nullptr)                      198   if (fgInstance == nullptr)
199   {                                               199   {
200     fgInstance = new G4ITTrackHolder();           200     fgInstance = new G4ITTrackHolder();
201     if(G4Threading::IsMasterThread() ||           201     if(G4Threading::IsMasterThread() ||
202        !G4Threading::IsMultithreadedApplicatio    202        !G4Threading::IsMultithreadedApplication() 
203     )                                             203     ) 
204     {                                             204     {
205       fgMasterInstance = fgInstance;              205       fgMasterInstance = fgInstance;
206     }                                             206     }
207                                                   207     
208   }                                               208   }
209   return fgInstance;                              209   return fgInstance;
210 }                                                 210 }
211                                                   211 
212 G4ITTrackHolder* G4ITTrackHolder::MasterInstan    212 G4ITTrackHolder* G4ITTrackHolder::MasterInstance()
213 {                                                 213 {
214   G4AutoLock lock(&creationOfTheMasterInstance    214   G4AutoLock lock(&creationOfTheMasterInstance);
215   if (fgMasterInstance == nullptr)                215   if (fgMasterInstance == nullptr)
216   {                                               216   {
217     fgMasterInstance = new G4ITTrackHolder();     217     fgMasterInstance = new G4ITTrackHolder();
218   }                                               218   }
219   lock.unlock();                                  219   lock.unlock();
220   return fgMasterInstance;                        220   return fgMasterInstance;
221 }                                                 221 }
222                                                   222 
223 G4ITTrackHolder::G4ITTrackHolder()                223 G4ITTrackHolder::G4ITTrackHolder()
224 {                                                 224 {
225   fNbTracks = -1;                                 225   fNbTracks = -1;
226   fMainListHaveBeenSet = false;                   226   fMainListHaveBeenSet = false;
227   fVerbose = 0;                                   227   fVerbose = 0;
228                                                   228 
229   fPostActivityGlobalTime = -1;                   229   fPostActivityGlobalTime = -1;
230 //  fPreActivityGlobalTime = -1;                  230 //  fPreActivityGlobalTime = -1;
231 }                                                 231 }
232                                                   232 
233 G4ITTrackHolder::~G4ITTrackHolder()               233 G4ITTrackHolder::~G4ITTrackHolder()
234 {                                                 234 {
235   auto end = fLists.end();                        235   auto end = fLists.end();
236                                                   236 
237   for (auto it = fLists.begin(); it != end;       237   for (auto it = fLists.begin(); it != end;
238       it++)                                       238       it++)
239   {                                               239   {
240     delete it->second;                            240     delete it->second;
241     it->second = 0;                               241     it->second = 0;
242   }                                               242   }
243                                                   243 
244   if (!fDelayedList.empty())                      244   if (!fDelayedList.empty())
245   {                                               245   {
246     auto fDelayedList_i = fDelayedList.begin()    246     auto fDelayedList_i = fDelayedList.begin();
247     auto fDelayedList_end = fDelayedList.end()    247     auto fDelayedList_end = fDelayedList.end();
248                                                   248 
249     for (; fDelayedList_i != fDelayedList_end;    249     for (; fDelayedList_i != fDelayedList_end; fDelayedList_i++)
250     {                                             250     {
251       auto it = fDelayedList_i->second.begin()    251       auto it = fDelayedList_i->second.begin();
252       auto __end =                                252       auto __end =
253           fDelayedList_i->second.end();           253           fDelayedList_i->second.end();
254                                                   254 
255       for (; it != __end; it++)                   255       for (; it != __end; it++)
256       {                                           256       {
257         delete (it->second);                      257         delete (it->second);
258         it->second = 0;                           258         it->second = 0;
259       }                                           259       }
260     }                                             260     }
261     fDelayedList.clear();                         261     fDelayedList.clear();
262   }                                               262   }
263                                                   263 
264   fAllMainList.RemoveLists();                     264   fAllMainList.RemoveLists();
265   fAllSecondariesList.RemoveLists();              265   fAllSecondariesList.RemoveLists();
266   fNbTracks = -1;                                 266   fNbTracks = -1;
267 }                                                 267 }
268                                                   268 
269 /*                                                269 /*
270  void G4MIMolecularTracks::Decide()               270  void G4MIMolecularTracks::Decide()
271  {                                                271  {
272  cout << "G4MIMolecularTracks::Decide" << endl    272  cout << "G4MIMolecularTracks::Decide" << endl;
273                                                   273 
274  if (fDelayedList.empty())                        274  if (fDelayedList.empty())
275  {                                                275  {
276  cout << "fDelayedList.empty()" << endl;          276  cout << "fDelayedList.empty()" << endl;
277  return;                                          277  return;
278  }                                                278  }
279  fPostActivityGlobalTime = GetNextTime();         279  fPostActivityGlobalTime = GetNextTime();
280  //  PushActivity(workspace->GetScheduler(), t    280  //  PushActivity(workspace->GetScheduler(), this);
281  }                                                281  }
282  */                                               282  */
283                                                   283 
284 /*                                                284 /*
285  * param time = time of the merged list           285  * param time = time of the merged list
286  * returned = was there actually merged data ?    286  * returned = was there actually merged data ?
287  */                                               287  */
288 bool G4ITTrackHolder::MergeNextTimeToMainList(    288 bool G4ITTrackHolder::MergeNextTimeToMainList(double& time)
289 {                                                 289 {
290 //  G4cout << "G4ITTrackHolder::MergeNextTimeT    290 //  G4cout << "G4ITTrackHolder::MergeNextTimeToMainList" << G4endl;
291   if (fDelayedList.empty())                       291   if (fDelayedList.empty())
292   {                                               292   {
293     return false;                                 293     return false;
294   }                                               294   }
295                                                   295 
296 //  G4cout << "fDelayedList.size = " << fDelay    296 //  G4cout << "fDelayedList.size = " << fDelayedList.size() <<G4endl;
297                                                   297 
298   auto it =                                       298   auto it =
299       fDelayedList.begin()->second.begin();       299       fDelayedList.begin()->second.begin();
300   auto end =                                      300   auto end =
301       fDelayedList.begin()->second.end();         301       fDelayedList.begin()->second.end();
302   if (it == end) return false;                    302   if (it == end) return false;
303                                                   303 
304   bool output = false;                            304   bool output = false;
305   for (; it != end; it++)                         305   for (; it != end; it++)
306   {                                               306   {
307     PriorityList* right_listUnion(nullptr);       307     PriorityList* right_listUnion(nullptr);
308                                                   308 
309     auto it_listUnion = fLists.find(              309     auto it_listUnion = fLists.find(
310         it->first);                               310         it->first);
311     if (it_listUnion == fLists.end())             311     if (it_listUnion == fLists.end())
312     {                                             312     {
313       right_listUnion = (fLists[it->first] = n    313       right_listUnion = (fLists[it->first] = new PriorityList());
314     }                                             314     }
315     else                                          315     else
316     {                                             316     {
317       if (it_listUnion->second == 0)              317       if (it_listUnion->second == 0)
318       {                                           318       {
319         it_listUnion->second = new PriorityLis    319         it_listUnion->second = new PriorityList();
320       }                                           320       }
321       right_listUnion = it_listUnion->second;     321       right_listUnion = it_listUnion->second;
322     }                                             322     }
323                                                   323 
324     if (it->second == 0) continue;                324     if (it->second == 0) continue;
325                                                   325 
326     /*                                            326     /*
327      if (right_listUnion->GetMainList() == 0)     327      if (right_listUnion->GetMainList() == 0)
328      {                                            328      {
329      //      right_listUnion->fpMainList = new    329      //      right_listUnion->fpMainList = new G4TrackList();
330      //      if(it->second)                       330      //      if(it->second)
331      //      {                                    331      //      {
332      right_listUnion->NewMainList(it->second,     332      right_listUnion->NewMainList(it->second, fAllMainList);
333      //      }                                    333      //      }
334      }                                            334      }
335      else                                         335      else
336      {                                            336      {
337      right_listUnion->TransferToMainList(it->s    337      right_listUnion->TransferToMainList(it->second);
338      delete it->second;                           338      delete it->second;
339      }*/                                          339      }*/
340                                                   340 
341     right_listUnion->TransferToMainList(it->se    341     right_listUnion->TransferToMainList(it->second, fAllMainList);
342                                                   342 
343     if (!output)                                  343     if (!output)
344     {                                             344     {
345       if (static_cast<int>(!right_listUnion->G    345       if (static_cast<int>(!right_listUnion->GetMainList()->empty()) != 0)
346       {                                           346       {
347         output = true;                            347         output = true;
348       }                                           348       }
349     }                                             349     }
350     it->second = 0;                               350     it->second = 0;
351   }                                               351   }
352                                                   352 
353   if (output) time = fDelayedList.begin()->fir    353   if (output) time = fDelayedList.begin()->first;
354   fDelayedList.erase(fDelayedList.begin());       354   fDelayedList.erase(fDelayedList.begin());
355   return output;                                  355   return output;
356 }                                                 356 }
357                                                   357 
358 void G4ITTrackHolder::MergeSecondariesWithMain    358 void G4ITTrackHolder::MergeSecondariesWithMainList()
359 {                                                 359 {
360   auto it = fLists.begin();                       360   auto it = fLists.begin();
361   auto end = fLists.end();                        361   auto end = fLists.end();
362                                                   362 
363   for (; it != end; it++)                         363   for (; it != end; it++)
364   {                                               364   {
365     if (it->second->GetMainList() == nullptr)     365     if (it->second->GetMainList() == nullptr)
366     {                                             366     {
367       it->second->NewMainList(fAllMainList);      367       it->second->NewMainList(fAllMainList);
368     }                                             368     }
369                                                   369 
370     it->second->TransferSecondariesToMainList(    370     it->second->TransferSecondariesToMainList();
371   }                                               371   }
372 }                                                 372 }
373                                                   373 
374 //____________________________________________    374 //_________________________________________________________________________
375                                                   375 
376 void G4ITTrackHolder::AddTrackID(G4Track* trac    376 void G4ITTrackHolder::AddTrackID(G4Track* track)
377 {                                                 377 {
378   //if(fNbTracks == 0) fNbTracks = -1;            378   //if(fNbTracks == 0) fNbTracks = -1;
379   track->SetTrackID(fNbTracks);                   379   track->SetTrackID(fNbTracks);
380   fNbTracks--;                                    380   fNbTracks--;
381 }                                                 381 }
382                                                   382 
383 //____________________________________________    383 //_________________________________________________________________________
384                                                   384 
385 void G4ITTrackHolder::Push(G4Track* track)        385 void G4ITTrackHolder::Push(G4Track* track)
386 {                                                 386 {
387 //  if (G4VScheduler::Instance()->IsRunning())    387 //  if (G4VScheduler::Instance()->IsRunning())
388 //  {                                             388 //  {
389 //    G4ExceptionDescription exceptionDescript    389 //    G4ExceptionDescription exceptionDescription;
390 //    exceptionDescription                        390 //    exceptionDescription
391 //        << "G4ITTrackHolder::PushTrack : You    391 //        << "G4ITTrackHolder::PushTrack : You are trying to push tracks while the "
392 //        "ITStepManager is running";             392 //        "ITStepManager is running";
393 //    G4Exception("G4ITTrackHolder::PushTrack"    393 //    G4Exception("G4ITTrackHolder::PushTrack", "ITStepManager012",
394 //                FatalErrorInArgument, except    394 //                FatalErrorInArgument, exceptionDescription);
395 //  }                                             395 //  }
396   _PushTrack(track);                              396   _PushTrack(track);
397                                                   397 
398 //  G4MIConstituent::NotifyEntityAdded(track);    398 //  G4MIConstituent::NotifyEntityAdded(track);
399 }                                                 399 }
400 //____________________________________________    400 //_________________________________________________________________________
401 void G4ITTrackHolder::PushTo(G4Track* track, P    401 void G4ITTrackHolder::PushTo(G4Track* track, PriorityList::Type type)
402 {                                                 402 {
403   int moleculeID = GetIT(track)->GetITSubType(    403   int moleculeID = GetIT(track)->GetITSubType();
404   auto it = fLists.find(moleculeID);              404   auto it = fLists.find(moleculeID);
405                                                   405 
406   PriorityList* priorityList(nullptr);            406   PriorityList* priorityList(nullptr);
407                                                   407 
408   if (it == fLists.end())                         408   if (it == fLists.end())
409   {                                               409   {
410     priorityList = new PriorityList(fAllMainLi    410     priorityList = new PriorityList(fAllMainList);
411     fLists[moleculeID] = priorityList;            411     fLists[moleculeID] = priorityList;
412   }                                               412   }
413   else                                            413   else
414   {                                               414   {
415     priorityList = it->second;                    415     priorityList = it->second;
416   }                                               416   }
417                                                   417 
418   switch (type)                                   418   switch (type)
419   {                                               419   {
420     case PriorityList::MainList:                  420     case PriorityList::MainList:
421     {                                             421     {
422       priorityList->PushToMainList(track, fAll    422       priorityList->PushToMainList(track, fAllMainList);
423       break;                                      423       break;
424     }                                             424     }
425     case PriorityList::SecondariesList:           425     case PriorityList::SecondariesList:
426     {                                             426     {
427       priorityList->PushToListOfSecondaries(tr    427       priorityList->PushToListOfSecondaries(track, fAllSecondariesList);
428       break;                                      428       break;
429     }                                             429     }
430     case PriorityList::WaitingList:               430     case PriorityList::WaitingList:
431     {                                             431     {
432       priorityList->PushToWaitingList(track);     432       priorityList->PushToWaitingList(track);
433       return;                                     433       return;
434       break;                                      434       break;
435     }                                             435     }
436                                                   436 
437     default:                                      437     default:
438     {                                             438     {
439       return;                                     439       return;
440       break;                                      440       break;
441     }                                             441     }
442   }                                               442   }
443 }                                                 443 }
444 //____________________________________________    444 //_________________________________________________________________________
445                                                   445 
446 void G4ITTrackHolder::_PushTrack(G4Track* trac    446 void G4ITTrackHolder::_PushTrack(G4Track* track)
447 {                                                 447 {
448   if (track == nullptr)                           448   if (track == nullptr)
449   {                                               449   {
450     G4ExceptionDescription exceptionDescriptio    450     G4ExceptionDescription exceptionDescription;
451     exceptionDescription                          451     exceptionDescription
452         << "You are trying to push a non-exist    452         << "You are trying to push a non-existing track (track pointer is null)"
453         << G4endl;                                453         << G4endl;
454                                                   454 
455     G4Exception("G4ITTrackHolder::_PushTrack",    455     G4Exception("G4ITTrackHolder::_PushTrack", "ITStepManager014",
456                 FatalErrorInArgument, exceptio    456                 FatalErrorInArgument, exceptionDescription);
457   }                                               457   }
458                                                   458 
459   G4double globalTime = track->GetGlobalTime()    459   G4double globalTime = track->GetGlobalTime();
460                                                   460 
461   if (track->GetTrackID() == 0)                   461   if (track->GetTrackID() == 0)
462   {                                               462   {
463     // Set track ID                               463     // Set track ID
464     AddTrackID(track);                            464     AddTrackID(track);
465   }                                               465   }
466                                                   466 
467   double currentGlobalTime = G4Scheduler::Inst    467   double currentGlobalTime = G4Scheduler::Instance()->GetGlobalTime();
468                                                   468 
469 #ifdef G4VERBOSE                                  469 #ifdef G4VERBOSE
470   if (fVerbose != 0)                              470   if (fVerbose != 0)
471   {                                               471   {
472     G4cout << G4endl;                             472     G4cout << G4endl;
473     G4cout << "\t"<< ">> Pushing a track -->      473     G4cout << "\t"<< ">> Pushing a track -->  ";
474     G4cout << GetIT(track)->GetName() << " ("     474     G4cout << GetIT(track)->GetName() << " (" << track->GetTrackID() <<")"
475     << " -- ";                                    475     << " -- ";
476     G4cout << "Global current time: " << G4Bes    476     G4cout << "Global current time: " << G4BestUnit(currentGlobalTime,"Time")
477     << "\t";                                      477     << "\t";
478     G4cout << "Track's time: " << G4BestUnit(t    478     G4cout << "Track's time: " << G4BestUnit(track->GetGlobalTime(),"Time")
479     << G4endl;                                    479     << G4endl;
480   }                                               480   }
481 #endif                                            481 #endif
482                                                   482 
483   if (!G4Scheduler::Instance()->IsRunning())      483   if (!G4Scheduler::Instance()->IsRunning())
484   {                                               484   {
485     if (globalTime < currentGlobalTime)           485     if (globalTime < currentGlobalTime)
486     {                                             486     {
487       G4ExceptionDescription exceptionDescript    487       G4ExceptionDescription exceptionDescription;
488       exceptionDescription                        488       exceptionDescription
489           << "You are trying to push a track w    489           << "You are trying to push a track with a global time"
490           << " inferior to the current simulat    490           << " inferior to the current simulation time." << G4endl<< "The time is going back : " << G4endl
491       << "The time in the step manager : "        491       << "The time in the step manager : "
492       << G4BestUnit(currentGlobalTime,"Time")     492       << G4BestUnit(currentGlobalTime,"Time")
493       << G4endl                                   493       << G4endl
494       << "The time of the track : "               494       << "The time of the track : "
495       << G4BestUnit(globalTime,"Time")            495       << G4BestUnit(globalTime,"Time")
496       << G4endl                                   496       << G4endl
497       << "(ITStepManager is not yet running)"     497       << "(ITStepManager is not yet running)"
498       << G4endl;                                  498       << G4endl;
499                                                   499 
500       G4Exception("G4ITTrackHolder::_PushTrack    500       G4Exception("G4ITTrackHolder::_PushTrack", "ITStepManager014",
501                   FatalErrorInArgument, except    501                   FatalErrorInArgument, exceptionDescription);
502     }                                             502     }
503                                                   503 
504     // Push the track to the rigth track list     504     // Push the track to the rigth track list :
505     // If the track time is the same as the ma    505     // If the track time is the same as the main track list,
506     // it will be push to the main track list     506     // it will be push to the main track list
507     // otherwise, it will be pushed to the del    507     // otherwise, it will be pushed to the delayed track list.
508     if (!fMainListHaveBeenSet)                    508     if (!fMainListHaveBeenSet)
509     {                                             509     {
510       PushDelayed(track);                         510       PushDelayed(track);
511     }                                             511     }
512     else                                          512     else
513     {                                             513     {
514       if (globalTime == currentGlobalTime)        514       if (globalTime == currentGlobalTime)
515       {                                           515       {
516         #ifdef G4VERBOSE                          516         #ifdef G4VERBOSE
517           if (fVerbose != 0)                      517           if (fVerbose != 0)
518           {                                       518           {
519             G4cout << G4endl;                     519             G4cout << G4endl;
520             G4cout << "\t"<< ">> Pushing to *m    520             G4cout << "\t"<< ">> Pushing to *main* list -->  ";
521             G4cout << GetIT(track)->GetName()     521             G4cout << GetIT(track)->GetName() << " (" << track->GetTrackID() <<")"
522             << " -- ";                            522             << " -- ";
523             G4cout << "Global current time: "     523             G4cout << "Global current time: " << G4BestUnit(currentGlobalTime,"Time")
524             << "\t";                              524             << "\t";
525             G4cout << "Track's time: " << G4Be    525             G4cout << "Track's time: " << G4BestUnit(track->GetGlobalTime(),"Time")
526             << G4endl;                            526             << G4endl;
527           }                                       527           }
528         #endif                                    528         #endif
529         PushTo(track, PriorityList::MainList);    529         PushTo(track, PriorityList::MainList);
530       }                                           530       }
531       else                                        531       else
532       {                                           532       {
533         // if(currentGlobalTime > 1*CLHEP::pic    533         // if(currentGlobalTime > 1*CLHEP::picosecond) abort();
534         #ifdef G4VERBOSE                          534         #ifdef G4VERBOSE
535           if (fVerbose != 0)                      535           if (fVerbose != 0)
536           {                                       536           {
537             G4cout << G4endl;                     537             G4cout << G4endl;
538             G4cout << "\t"<< ">> Pushing to *d    538             G4cout << "\t"<< ">> Pushing to *delayed* list -->  ";
539             G4cout << GetIT(track)->GetName()     539             G4cout << GetIT(track)->GetName() << " (" << track->GetTrackID() <<")"
540             << " -- ";                            540             << " -- ";
541             G4cout << "Global current time: "     541             G4cout << "Global current time: " << G4BestUnit(currentGlobalTime,"Time")
542             << "\t";                              542             << "\t";
543             G4cout << "Track's time: " << G4Be    543             G4cout << "Track's time: " << G4BestUnit(track->GetGlobalTime(),"Time")
544             << G4endl;                            544             << G4endl;
545           }                                       545           }
546         #endif                                    546         #endif
547         PushDelayed(track);                       547         PushDelayed(track);
548       }                                           548       }
549     }                                             549     }
550   }                                               550   }
551   else // Is running                              551   else // Is running
552   {                                               552   {
553     double timeDifference = globalTime - curre    553     double timeDifference = globalTime - currentGlobalTime;
554     double timeTolerance = G4Scheduler::Instan    554     double timeTolerance = G4Scheduler::Instance()->GetTimeTolerance();
555                                                   555 
556     if (timeDifference < -1 * timeTolerance)      556     if (timeDifference < -1 * timeTolerance)
557     {                                             557     {
558       G4ExceptionDescription exceptionDescript    558       G4ExceptionDescription exceptionDescription;
559       exceptionDescription                        559       exceptionDescription
560           << "You are trying to push a track w    560           << "You are trying to push a track with a global time"
561           << " inferior to the current simulat    561           << " inferior to the current simulation time." << G4endl<< "The time is going back : "
562       << G4endl                                   562       << G4endl
563       << "The time in the step manager : "        563       << "The time in the step manager : "
564       << G4BestUnit(timeDifference,"Time")        564       << G4BestUnit(timeDifference,"Time")
565       << G4endl                                   565       << G4endl
566       << "The time of the track : " << G4BestU    566       << "The time of the track : " << G4BestUnit(globalTime,"Time")
567       << G4endl                                   567       << G4endl
568       << "(ITStepManager is running)"             568       << "(ITStepManager is running)"
569       << G4endl;                                  569       << G4endl;
570                                                   570 
571       G4Exception("G4ITTrackHolder::_PushTrack    571       G4Exception("G4ITTrackHolder::_PushTrack", "ITStepManager015",
572                   FatalErrorInArgument, except    572                   FatalErrorInArgument, exceptionDescription);
573     }                                             573     }
574                                                   574 
575     // Push the track to the rigth track list     575     // Push the track to the rigth track list :
576     // If the track time is the same as the ma    576     // If the track time is the same as the main track list,
577     // it will be push to the secondary list      577     // it will be push to the secondary list
578     // otherwise, it will be pushed to the del    578     // otherwise, it will be pushed to the delayed track list.
579     if (fabs(timeDifference) < timeTolerance)     579     if (fabs(timeDifference) < timeTolerance)
580     {                                             580     {
581 //      G4cout << "Is pushing " << GetIT(track    581 //      G4cout << "Is pushing " << GetIT(track)->GetName() << G4endl;
582                                                   582 
583       #ifdef G4VERBOSE                            583       #ifdef G4VERBOSE
584         if (fVerbose != 0)                        584         if (fVerbose != 0)
585         {                                         585         {
586           G4cout << G4endl;                       586           G4cout << G4endl;
587           G4cout << "\t"<< ">> Pushing to *sec    587           G4cout << "\t"<< ">> Pushing to *secondary* list -->  ";
588           G4cout << GetIT(track)->GetName() <<    588           G4cout << GetIT(track)->GetName() << " (" << track->GetTrackID() <<")"
589           << " -- ";                              589           << " -- ";
590           G4cout << "Global current time: " <<    590           G4cout << "Global current time: " << G4BestUnit(currentGlobalTime,"Time")
591           << "\t";                                591           << "\t";
592           G4cout << "Track's time: " << G4Best    592           G4cout << "Track's time: " << G4BestUnit(track->GetGlobalTime(),"Time")
593           << G4endl;                              593           << G4endl;
594         }                                         594         }
595       #endif                                      595       #endif
596       PushTo(track, PriorityList::SecondariesL    596       PushTo(track, PriorityList::SecondariesList);
597     }                                             597     }
598     else // globalTime < fGlobalTime already t    598     else // globalTime < fGlobalTime already taken into account above
599     {                                             599     {
600       G4ExceptionDescription exceptionDescript    600       G4ExceptionDescription exceptionDescription;
601       exceptionDescription                        601       exceptionDescription
602           << "While running you cannot push a     602           << "While running you cannot push a track"
603           << " with a bigger global time than     603           << " with a bigger global time than the current global time" << G4endl<< "The time in the step manager : "
604       << G4BestUnit(currentGlobalTime,"Time")     604       << G4BestUnit(currentGlobalTime,"Time")
605       << G4endl                                   605       << G4endl
606       << "The time of the track : " << G4BestU    606       << "The time of the track : " << G4BestUnit(globalTime,"Time")
607       << G4endl                                   607       << G4endl
608       << "(ITStepManager is running)"             608       << "(ITStepManager is running)"
609       << G4endl;                                  609       << G4endl;
610                                                   610 
611       G4Exception("G4ITTrackHolder::_PushTrack    611       G4Exception("G4ITTrackHolder::_PushTrack", "ITStepManager016",
612                   FatalErrorInArgument, except    612                   FatalErrorInArgument, exceptionDescription);
613       // PushDelayed(track, globalTime);          613       // PushDelayed(track, globalTime);
614     }                                             614     }
615   }                                               615   }
616 }                                                 616 }
617                                                   617 
618 //____________________________________________    618 //_________________________________________________________________________
619                                                   619 
620 void G4ITTrackHolder::PushDelayed(G4Track* tra    620 void G4ITTrackHolder::PushDelayed(G4Track* track)
621 {                                                 621 {
622 #ifdef G4VERBOSE                                  622 #ifdef G4VERBOSE
623   if (fVerbose != 0)                              623   if (fVerbose != 0)
624   {                                               624   {
625     G4cout << "\t" << ">> Pushing a delayed tr    625     G4cout << "\t" << ">> Pushing a delayed track" << G4endl;
626   }                                               626   }
627 #endif                                            627 #endif
628                                                   628 
629   int moleculeID = GetIT(track)->GetITSubType(    629   int moleculeID = GetIT(track)->GetITSubType();
630   //  std::map<int, PriorityList>::iterator it    630   //  std::map<int, PriorityList>::iterator it = fLists.find(moleculeID);
631                                                   631 
632   G4double globalTime = track->GetGlobalTime()    632   G4double globalTime = track->GetGlobalTime();
633                                                   633 
634   auto it_delayed =                               634   auto it_delayed =
635   fDelayedList.find(globalTime);                  635   fDelayedList.find(globalTime);
636                                                   636 
637   if (it_delayed == fDelayedList.end())           637   if (it_delayed == fDelayedList.end())
638   {                                               638   {
639     (fDelayedList[globalTime][moleculeID] = ne    639     (fDelayedList[globalTime][moleculeID] = new G4TrackList())->push_back(
640         track);                                   640         track);
641   }                                               641   }
642   else                                            642   else
643   {                                               643   {
644     auto it_trackList =                           644     auto it_trackList =
645     it_delayed->second.find(moleculeID);          645     it_delayed->second.find(moleculeID);
646                                                   646 
647     if (it_trackList == it_delayed->second.end    647     if (it_trackList == it_delayed->second.end())
648     {                                             648     {
649       (it_delayed->second[moleculeID] = new G4    649       (it_delayed->second[moleculeID] = new G4TrackList())->push_back(track);
650     }                                             650     }
651     else                                          651     else
652     {                                             652     {
653       if (it_trackList->second != 0)              653       if (it_trackList->second != 0)
654       {                                           654       {
655         it_trackList->second->push_back(track)    655         it_trackList->second->push_back(track);
656       }                                           656       }
657     }                                             657     }
658   }                                               658   }
659                                                   659 
660   //  fDelayedList[globalTime][moleculeID]        660   //  fDelayedList[globalTime][moleculeID]
661                                                   661 
662   /*                                              662   /*
663    std::map<double,std::map<int, G4TrackList*     663    std::map<double,std::map<int, G4TrackList* > >::iterator it_delayed =
664    fDelayedList.begin();                          664    fDelayedList.begin();
665                                                   665 
666    std::map<double,std::map<int, G4TrackList*     666    std::map<double,std::map<int, G4TrackList* > >::iterator end_delayed =
667    fDelayedList.end();                            667    fDelayedList.end();
668                                                   668 
669    for(it_delayed != end_delayed ; it_delayed+    669    for(it_delayed != end_delayed ; it_delayed++)
670    {                                              670    {
671    std::map<int, G4TrackList*> & trackListMap     671    std::map<int, G4TrackList*> & trackListMap = it->second;
672                                                   672 
673                                                   673 
674    }                                              674    }
675    */                                             675    */
676   /*                                              676   /*
677    std::map<double,G4TrackList* > :: iterator     677    std::map<double,G4TrackList* > :: iterator
678    fDelayedList_i = fDelayedList.find(globalTi    678    fDelayedList_i = fDelayedList.find(globalTime) ;
679                                                   679 
680    if(fDelayedList_i == fDelayedList.end())       680    if(fDelayedList_i == fDelayedList.end())
681    {                                              681    {
682                                                   682 
683    G4TrackList* newList = new G4TrackList ;       683    G4TrackList* newList = new G4TrackList ;
684    newList -> push_back(track);                   684    newList -> push_back(track);
685    fDelayedList[globalTime] = newList ;           685    fDelayedList[globalTime] = newList ;
686    }                                              686    }
687    else                                           687    else
688    {                                              688    {
689    fDelayedList_i->second-> push_back(track);     689    fDelayedList_i->second-> push_back(track);
690    }                                              690    }
691    */                                             691    */
692 }                                                 692 }
693 //____________________________________________    693 //______________________________________________________________________________
694                                                   694 
695 void G4ITTrackHolder::KillTracks()                695 void G4ITTrackHolder::KillTracks()
696 {                                                 696 {
697   if (fToBeKilledList.empty()) return;            697   if (fToBeKilledList.empty()) return;
698 #ifdef G4VERBOSE                                  698 #ifdef G4VERBOSE
699   if (fVerbose > 1)                               699   if (fVerbose > 1)
700   {                                               700   {
701     G4cout << "*** G4ITTrackHolder::KillTracks    701     G4cout << "*** G4ITTrackHolder::KillTracks , step #"
702            << G4VScheduler::Instance()->GetNbS    702            << G4VScheduler::Instance()->GetNbSteps()
703            << " ***" << G4endl;                   703            << " ***" << G4endl;
704     G4cout << "Nb of tracks to kill "<< fToBeK    704     G4cout << "Nb of tracks to kill "<< fToBeKilledList.size() << G4endl;
705     G4cout << setw(25) << left << "#Name"         705     G4cout << setw(25) << left << "#Name"
706            << setw(25) << "track ID"<< G4endl;    706            << setw(25) << "track ID"<< G4endl;
707                                                   707 
708     G4TrackList::iterator it = fToBeKilledList    708     G4TrackList::iterator it = fToBeKilledList.begin();
709     for(; it != fToBeKilledList.end();)           709     for(; it != fToBeKilledList.end();)
710     {                                             710     {
711       G4Track* toBeErased = *it;                  711       G4Track* toBeErased = *it;
712                                                   712 
713       G4cout << setw(25) << GetIT(toBeErased)-    713       G4cout << setw(25) << GetIT(toBeErased)->GetName()
714       << setw(25) << toBeErased->GetTrackID()     714       << setw(25) << toBeErased->GetTrackID()
715       << G4endl;                                  715       << G4endl;
716                                                   716 
717       it = fToBeKilledList.erase(toBeErased);     717       it = fToBeKilledList.erase(toBeErased);
718     }                                             718     }
719   }                                               719   }
720   else                                            720   else
721 #endif                                            721 #endif
722   fToBeKilledList.erase(fToBeKilledList.begin(    722   fToBeKilledList.erase(fToBeKilledList.begin(), fToBeKilledList.end());
723 }                                                 723 }
724                                                   724 
725 void G4ITTrackHolder::Clear()                     725 void G4ITTrackHolder::Clear()
726 {                                                 726 {
727   fAllMainList.ClearLists();                      727   fAllMainList.ClearLists();
728   fAllSecondariesList.ClearLists();               728   fAllSecondariesList.ClearLists();
729 //  fAllMainList.RemoveLists();                   729 //  fAllMainList.RemoveLists();
730 //  fAllSecondariesList.RemoveLists();            730 //  fAllSecondariesList.RemoveLists();
731                                                   731 
732   auto it = fLists.begin();                       732   auto it = fLists.begin();
733                                                   733 
734   for (; it != fLists.end(); it++)                734   for (; it != fLists.end(); it++)
735   {                                               735   {
736     delete it->second;                            736     delete it->second;
737     it->second = 0;                               737     it->second = 0;
738   }                                               738   }
739   fLists.clear();                                 739   fLists.clear();
740                                                   740 
741   auto it1 = fDelayedList.begin();                741   auto it1 = fDelayedList.begin();
742                                                   742 
743   for (; it1 != fDelayedList.end(); it1++)        743   for (; it1 != fDelayedList.end(); it1++)
744   {                                               744   {
745     auto it2 = it1->second.begin();               745     auto it2 = it1->second.begin();
746                                                   746 
747     for (; it2 != it1->second.end(); it2++)       747     for (; it2 != it1->second.end(); it2++)
748     {                                             748     {
749       delete it2->second;                         749       delete it2->second;
750       it2->second = 0;                            750       it2->second = 0;
751     }                                             751     }
752   }                                               752   }
753                                                   753 
754   fDelayedList.clear();                           754   fDelayedList.clear();
755                                                   755 
756 //  fAllMainList.ClearLists();                    756 //  fAllMainList.ClearLists();
757 //  fAllSecondariesList.ClearLists();             757 //  fAllSecondariesList.ClearLists();
758   fAllMainList.RemoveLists();                     758   fAllMainList.RemoveLists();
759   fAllSecondariesList.RemoveLists();              759   fAllSecondariesList.RemoveLists();
760   KillTracks();                                   760   KillTracks();
761                                                   761 
762   fNbTracks = -1;                                 762   fNbTracks = -1;
763 }                                                 763 }
764                                                   764 
765 PriorityList* G4ITTrackHolder::GetPriorityList    765 PriorityList* G4ITTrackHolder::GetPriorityList(Key i)
766 {                                                 766 {
767   auto it = fLists.find(i);                       767   auto it = fLists.find(i);
768   if (it == fLists.end()) return nullptr;         768   if (it == fLists.end()) return nullptr;
769   return it->second;                              769   return it->second;
770 }                                                 770 }
771                                                   771 
772 G4TrackList* G4ITTrackHolder::GetMainList(G4in    772 G4TrackList* G4ITTrackHolder::GetMainList(G4int i)
773 {                                                 773 {
774   PriorityList* priorityList = GetPriorityList    774   PriorityList* priorityList = GetPriorityList(i);
775   if (priorityList != nullptr)                    775   if (priorityList != nullptr)
776   {                                               776   {
777     return priorityList->GetMainList();           777     return priorityList->GetMainList();
778   }                                               778   }
779   return nullptr;                                 779   return nullptr;
780 }                                                 780 }
781                                                   781 
782 bool G4ITTrackHolder::AddWatcher(Key id,          782 bool G4ITTrackHolder::AddWatcher(Key id,
783                                  G4TrackList::    783                                  G4TrackList::Watcher* watcher,
784                                  PriorityList:    784                                  PriorityList::Type type)
785 {                                                 785 {
786   auto it = fLists.find(id);                      786   auto it = fLists.find(id);
787   if (it == fLists.end()) return false;           787   if (it == fLists.end()) return false;
788                                                   788 
789   G4TrackList* trackList = it->second->Get(typ    789   G4TrackList* trackList = it->second->Get(type);
790   if (trackList == nullptr) return false;         790   if (trackList == nullptr) return false;
791   trackList->AddWatcher(watcher);                 791   trackList->AddWatcher(watcher);
792   return true;                                    792   return true;
793 }                                                 793 }
794                                                   794 
795 void G4ITTrackHolder::AddWatcherForMainList(G4    795 void G4ITTrackHolder::AddWatcherForMainList(G4TrackList::Watcher* watcher)
796 {                                                 796 {
797   fAllMainList.AddGlobalWatcher(watcher);         797   fAllMainList.AddGlobalWatcher(watcher);
798 }                                                 798 }
799                                                   799 
800 void G4ITTrackHolder::AddWatcherForKillList(G4    800 void G4ITTrackHolder::AddWatcherForKillList(G4TrackList::Watcher* watcher)
801 {                                                 801 {
802   watcher->Watch(&fToBeKilledList);               802   watcher->Watch(&fToBeKilledList);
803 }                                                 803 }
804                                                   804 
805 void G4ITTrackHolder::PushToMaster(G4Track* tr    805 void G4ITTrackHolder::PushToMaster(G4Track* track)
806 {                                                 806 {
807   G4ITTrackHolder* trackHolder = MasterInstanc    807   G4ITTrackHolder* trackHolder = MasterInstance();
808                                                   808 
809   G4AutoLock lock(&pushToTheMasterInstance);      809   G4AutoLock lock(&pushToTheMasterInstance);
810   trackHolder->PushDelayed(track);                810   trackHolder->PushDelayed(track);
811   lock.unlock();                                  811   lock.unlock();
812 }                                                 812 }
813                                                   813 
814 size_t G4ITTrackHolder::GetNTracks()              814 size_t G4ITTrackHolder::GetNTracks()
815 {                                                 815 {
816   size_t nTracks(0);                              816   size_t nTracks(0);
817   nTracks += fAllMainList.size();                 817   nTracks += fAllMainList.size();
818   nTracks += fAllSecondariesList.size();          818   nTracks += fAllSecondariesList.size();
819                                                   819 
820   //    G4cout << "nTracks = " << nTracks << G    820   //    G4cout << "nTracks = " << nTracks << G4endl;
821                                                   821 
822   auto delayedmap_it = fDelayedList.begin();      822   auto delayedmap_it = fDelayedList.begin();
823   auto delayedmap_end = fDelayedList.end();       823   auto delayedmap_end = fDelayedList.end();
824                                                   824 
825   for (; delayedmap_it != delayedmap_end; dela    825   for (; delayedmap_it != delayedmap_end; delayedmap_it++)
826   {                                               826   {
827     auto it = delayedmap_it->second.begin();      827     auto it = delayedmap_it->second.begin();
828     auto end = delayedmap_it->second.end();       828     auto end = delayedmap_it->second.end();
829                                                   829 
830     for (; it != end; it++)                       830     for (; it != end; it++)
831     {                                             831     {
832       if (it->second != nullptr) nTracks += it    832       if (it->second != nullptr) nTracks += it->second->size();
833     }                                             833     }
834   }                                               834   }
835                                                   835 
836   //    G4cout << "nTracks = " << nTracks << G    836   //    G4cout << "nTracks = " << nTracks << G4endl;
837                                                   837 
838   return nTracks;                                 838   return nTracks;
839 }                                                 839 }
840                                                   840 
841 void G4ITTrackHolder::MoveMainToWaitingList()     841 void G4ITTrackHolder::MoveMainToWaitingList()
842 {                                                 842 {
843   auto it = fLists.begin();                       843   auto it = fLists.begin();
844   auto end = fLists.end();                        844   auto end = fLists.end();
845   for (; it != end; it++)                         845   for (; it != end; it++)
846   {                                               846   {
847     if (PriorityList* lists = it->second)         847     if (PriorityList* lists = it->second)
848     {                                             848     {
849       lists->SetWaitingList(lists->GetMainList    849       lists->SetWaitingList(lists->GetMainList());
850       //TODO                                      850       //TODO
851     }                                             851     }
852   }                                               852   }
853   fAllMainList.RemoveLists();                     853   fAllMainList.RemoveLists();
854 }                                                 854 }
855                                                   855 
856 bool G4ITTrackHolder::DelayListsNOTEmpty()        856 bool G4ITTrackHolder::DelayListsNOTEmpty()
857 {                                                 857 {
858   auto __it = fDelayedList.begin();               858   auto __it = fDelayedList.begin();
859   auto __end = fDelayedList.end();                859   auto __end = fDelayedList.end();
860   for (; __it != __end; __it++)                   860   for (; __it != __end; __it++)
861   {                                               861   {
862     std::map<Key, G4TrackList*>& mapOfLists =     862     std::map<Key, G4TrackList*>& mapOfLists = __it->second;
863     if (!mapOfLists.empty())                      863     if (!mapOfLists.empty())
864     {                                             864     {
865       auto it = mapOfLists.begin();               865       auto it = mapOfLists.begin();
866       auto end = mapOfLists.end();                866       auto end = mapOfLists.end();
867       for (; it != end; it++)                     867       for (; it != end; it++)
868       {                                           868       {
869         if (G4TrackList* mainList = it->second    869         if (G4TrackList* mainList = it->second)
870         {                                         870         {
871           if (!(mainList->empty())) return tru    871           if (!(mainList->empty())) return true;
872         }                                         872         }
873       }                                           873       }
874     }                                             874     }
875   }                                               875   }
876   return false;                                   876   return false;
877 }                                                 877 }
878                                                   878 
879 bool G4ITTrackHolder::CheckMapIsNOTEmpty(MapOf    879 bool G4ITTrackHolder::CheckMapIsNOTEmpty(MapOfPriorityLists& mapOfLists,
880                                          Prior    880                                          PriorityList::Type type)
881 {                                                 881 {
882   auto it = mapOfLists.begin();                   882   auto it = mapOfLists.begin();
883   auto end = mapOfLists.end();                    883   auto end = mapOfLists.end();
884   for (; it != end; it++)                         884   for (; it != end; it++)
885   {                                               885   {
886     if (PriorityList* lists = it->second)         886     if (PriorityList* lists = it->second)
887     {                                             887     {
888       if (G4TrackList* trackList = lists->Get(    888       if (G4TrackList* trackList = lists->Get(type))
889       {                                           889       {
890         if (!(trackList->empty())) return true    890         if (!(trackList->empty())) return true;
891       }                                           891       }
892     }                                             892     }
893   }                                               893   }
894   return false;                                   894   return false;
895 }                                                 895 }
896                                                   896