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 ] [ 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 /event/src/G4Event.cc (Version 11.3.0) and /event/src/G4Event.cc (Version 10.3.p3)


  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 // G4Event class implementation                << 
 27 //                                                 26 //
 28 // Author: M.Asai, SLAC/JLAB                   <<  27 // $Id: G4Event.cc 99158 2016-09-07 08:10:46Z gcosmo $
 29 // ------------------------------------------- <<  28 //
                                                   >>  29 
                                                   >>  30 // G4Event
 30                                                    31 
 31 #include "G4Event.hh"                              32 #include "G4Event.hh"
 32 #include "G4VVisManager.hh"                        33 #include "G4VVisManager.hh"
                                                   >>  34 //#include "G4HCofThisEvent.hh"
                                                   >>  35 //#include "G4DCofThisEvent.hh"
 33 #include "G4VHitsCollection.hh"                    36 #include "G4VHitsCollection.hh"
 34 #include "G4VDigiCollection.hh"                    37 #include "G4VDigiCollection.hh"
 35 #include "G4ios.hh"                                38 #include "G4ios.hh"
 36 #include "G4SubEvent.hh"                       << 
 37                                                    39 
 38 #include "G4Threading.hh"                      <<  40 G4ThreadLocal G4Allocator<G4Event> *anEventAllocator = nullptr;
 39 #include "G4AutoLock.hh"                       << 
 40 namespace{                                     << 
 41   G4Mutex SubEventMutex = G4MUTEX_INITIALIZER; << 
 42 }                                              << 
 43                                                    41 
 44 G4Allocator<G4Event>*& anEventAllocator()      <<  42 G4Event::G4Event()
                                                   >>  43 :eventID(0),
                                                   >>  44  thePrimaryVertex(nullptr),numberOfPrimaryVertex(0),
                                                   >>  45  HC(nullptr),DC(nullptr),trajectoryContainer(nullptr),
                                                   >>  46  eventAborted(false),userInfo(nullptr),
                                                   >>  47  randomNumberStatus(nullptr),validRandomNumberStatus(false),
                                                   >>  48  randomNumberStatusForProcessing(nullptr),validRandomNumberStatusForProcessing(false),
                                                   >>  49  keepTheEvent(false),grips(0)
 45 {                                                  50 {
 46   G4ThreadLocalStatic G4Allocator<G4Event>* _i << 
 47   return _instance;                            << 
 48 }                                                  51 }
 49                                                    52 
 50 G4Event::G4Event(G4int evID)                       53 G4Event::G4Event(G4int evID)
 51   : eventID(evID)                              <<  54 :eventID(evID),
                                                   >>  55  thePrimaryVertex(nullptr),numberOfPrimaryVertex(0),
                                                   >>  56  HC(nullptr),DC(nullptr),trajectoryContainer(nullptr),
                                                   >>  57  eventAborted(false),userInfo(nullptr),
                                                   >>  58  randomNumberStatus(nullptr),validRandomNumberStatus(false),
                                                   >>  59  randomNumberStatusForProcessing(nullptr),validRandomNumberStatusForProcessing(false),
                                                   >>  60  keepTheEvent(false),grips(0)
 52 {                                                  61 {
 53 }                                                  62 }
 54                                                    63 
 55 G4Event::~G4Event()                                64 G4Event::~G4Event()
 56 {                                                  65 {
 57   G4PrimaryVertex* nextVertex = thePrimaryVert     66   G4PrimaryVertex* nextVertex = thePrimaryVertex;
 58   while(nextVertex != nullptr)                 <<  67   while(nextVertex)
 59   {                                                68   {
 60     G4PrimaryVertex* thisVertex = nextVertex;      69     G4PrimaryVertex* thisVertex = nextVertex;
 61     nextVertex = thisVertex->GetNext();            70     nextVertex = thisVertex->GetNext();
 62     thisVertex->ClearNext();                       71     thisVertex->ClearNext();
 63     delete thisVertex;                             72     delete thisVertex;
 64   }                                                73   }
 65   thePrimaryVertex = nullptr;                      74   thePrimaryVertex = nullptr;
 66   delete HC;                                       75   delete HC;
 67   delete DC;                                       76   delete DC;
 68   if(trajectoryContainer != nullptr)           <<  77   if(trajectoryContainer)
 69   {                                                78   {
 70     trajectoryContainer->clearAndDestroy();        79     trajectoryContainer->clearAndDestroy();
 71     delete trajectoryContainer;                    80     delete trajectoryContainer;
 72   }                                                81   }
 73   delete userInfo;                                 82   delete userInfo;
 74   delete randomNumberStatus;                       83   delete randomNumberStatus;
 75   delete randomNumberStatusForProcessing;          84   delete randomNumberStatusForProcessing;
 76                                                << 
 77   // TODO (PHASE-II): count remaining subevent << 
 78   for(auto& sem : fSubEvtStackMap)             << 
 79   {                                            << 
 80     if((sem.second!=nullptr)&&!(sem.second->em << 
 81     {                                          << 
 82       for(auto& se : *(sem.second))            << 
 83       { delete se; }                           << 
 84       sem.second->clear();                     << 
 85     }                                          << 
 86   }                                            << 
 87   /* TODO (PHASE-II): Handle incorrect scoring << 
 88   if(!scoresRecorded) {                        << 
 89     G4ExceptionDescription ed;                 << 
 90     ed << "Deleting G4Event (id:" << eventID < << 
 91        << remainingSE << " sub-events un-proce << 
 92     G4Exception("G4Event::~G4Event()","SubEvt0 << 
 93   } else if(remainingSE>0) {                   << 
 94     G4ExceptionDescription ed;                 << 
 95     ed << "Deleting G4Event (id:" << eventID < << 
 96        << remainingSE << " sub-events un-proce << 
 97     G4Exception("G4Event::~G4Event()","SubEvt0 << 
 98   }                                            << 
 99   */                                           << 
100   if(!(fSubEvtVector.empty()))                 << 
101   {                                            << 
102     for(auto& se : fSubEvtVector)              << 
103     {                                          << 
104       G4cout << "SubEvent " << se << " belongs << 
105              << " (eventID=" << se->GetEvent() << 
106              << se->GetNTrack() << " stacked t << 
107     }                                          << 
108     G4ExceptionDescription ed;                 << 
109     ed << "Deleting G4Event (id:" << eventID < << 
110        << fSubEvtVector.size() << " sub-events << 
111     G4Exception("G4Event::~G4Event()","SubEvt0 << 
112     // TODO (PHASE-II): Handle deletion of sub << 
113     //for(auto& se : fSubEvtVector)            << 
114     //{ delete se; }                           << 
115     //fSubEvtVector.clear();                   << 
116   }                                            << 
117                                                << 
118   if(!(fSubEventGarbageBin.empty()))           << 
119   {                                            << 
120     for(auto& se : fSubEventGarbageBin)        << 
121     { delete se; }                             << 
122     fSubEventGarbageBin.clear();               << 
123   }                                            << 
124 }                                                  85 }
125                                                    86 
126 G4bool G4Event::operator==(const G4Event& righ <<  87 G4int G4Event::operator==(const G4Event &right) const
127 {                                                  88 {
128   return ( eventID == right.eventID );             89   return ( eventID == right.eventID );
129 }                                                  90 }
130                                                    91 
131 G4bool G4Event::operator!=(const G4Event& righ <<  92 G4int G4Event::operator!=(const G4Event &right) const
132 {                                                  93 {
133   return ( eventID != right.eventID );             94   return ( eventID != right.eventID );
134 }                                                  95 }
135                                                    96 
136 void G4Event::Print() const                        97 void G4Event::Print() const
137 {                                                  98 {
138   G4cout << "G4Event " << eventID << G4endl;       99   G4cout << "G4Event " << eventID << G4endl;
139 }                                                 100 }
140                                                   101 
141 void G4Event::Draw() const                        102 void G4Event::Draw() const
142 {                                                 103 {
143   G4VVisManager* pVVisManager = G4VVisManager:    104   G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
144   if(pVVisManager == nullptr) return;          << 105   if(!pVVisManager) return;
145                                                   106 
146   if(trajectoryContainer != nullptr)           << 107   if(trajectoryContainer)
147   {                                               108   {
148     std::size_t n_traj = trajectoryContainer-> << 109     G4int n_traj = trajectoryContainer->entries();
149     for(std::size_t i=0; i<n_traj; ++i)        << 110     for(G4int i=0;i<n_traj;i++)
150     { (*trajectoryContainer)[i]->DrawTrajector    111     { (*trajectoryContainer)[i]->DrawTrajectory(); }
151   }                                               112   }
152                                                   113 
153   if(HC != nullptr)                            << 114   if(HC)
154   {                                               115   {
155     std::size_t n_HC = HC->GetCapacity();      << 116     G4int n_HC = HC->GetCapacity();
156     for(std::size_t j=0; j<n_HC; ++j)          << 117     for(G4int j=0;j<n_HC;j++)
157     {                                             118     {
158       G4VHitsCollection* VHC = HC->GetHC((G4in << 119       G4VHitsCollection * VHC = HC->GetHC(j);
159       if(VHC != nullptr) VHC->DrawAllHits();   << 120       if(VHC) VHC->DrawAllHits();
160     }                                             121     }
161   }                                               122   }
162                                                   123 
163   if(DC != nullptr)                            << 124   if(DC)
164   {                                               125   {
165     std::size_t n_DC = DC->GetCapacity();      << 126     G4int n_DC = DC->GetCapacity();
166     for(std::size_t j=0; j<n_DC; ++j)          << 127     for(G4int j=0;j<n_DC;j++)
167     {                                             128     {
168       G4VDigiCollection* VDC = DC->GetDC((G4in << 129       G4VDigiCollection * VDC = DC->GetDC(j);
169       if(VDC != nullptr) VDC->DrawAllDigi();   << 130       if(VDC) VDC->DrawAllDigi();
170     }                                             131     }
171   }                                               132   }
172 }                                              << 
173                                                << 
174 G4int G4Event::StoreSubEvent(G4int ty,G4SubEve << 
175 {                                              << 
176   G4AutoLock lock(&SubEventMutex);             << 
177   std::set<G4SubEvent*>* sev = nullptr;        << 
178   auto ses = fSubEvtStackMap.find(ty);         << 
179   if(ses==fSubEvtStackMap.end())               << 
180   {                                            << 
181     sev = new std::set<G4SubEvent*>;           << 
182     fSubEvtStackMap[ty] = sev;                 << 
183   }                                            << 
184   else                                         << 
185   { sev = ses->second; }                       << 
186   sev->insert(se);                             << 
187   return (G4int)sev->size();                   << 
188 }                                              << 
189                                                << 
190 G4SubEvent* G4Event::PopSubEvent(G4int ty)     << 
191 {                                              << 
192   G4AutoLock lock(&SubEventMutex);             << 
193   G4SubEvent* se = nullptr;                    << 
194   auto ses = fSubEvtStackMap.find(ty);         << 
195   if(ses!=fSubEvtStackMap.end())               << 
196   {                                            << 
197     auto sev = ses->second;                    << 
198     if(!(sev->empty()))                        << 
199     {                                          << 
200       se = sev->extract(sev->begin()).value(); << 
201       SpawnSubEvent(se);                       << 
202     }                                          << 
203   }                                            << 
204   return se;                                   << 
205 }                                              << 
206                                                << 
207 G4int G4Event::SpawnSubEvent(G4SubEvent* se)   << 
208 {                                              << 
209   // Can't use same mutex here as call by PopS << 
210   // caller is PopSubEvent                     << 
211   //G4AutoLock lock(&SubEventMutex);           << 
212   auto ss = fSubEvtVector.find(se);            << 
213   if(ss!=fSubEvtVector.end())                  << 
214   {                                            << 
215     G4ExceptionDescription ed;                 << 
216     ed << "Sub-event " << se << " of type " << << 
217        << " with " << se->GetNTrack() << " tra << 
218     G4Exception("G4Event::SpawnSubEvent","SubE << 
219                 FatalException,ed);            << 
220   }                                            << 
221   fSubEvtVector.insert(se);                    << 
222   return (G4int)fSubEvtVector.size();          << 
223 }                                              << 
224                                                << 
225 void G4Event::MergeSubEventResults(const G4Eve << 
226 {                                              << 
227   // TODO (PHASE-II): Handle merging of subeve << 
228   // Note:                                     << 
229   //     - scores are merged directly to the s << 
230   //     - hits collections should be merged b << 
231   /*                                           << 
232 #ifdef G4_STORE_TRAJECTORY                     << 
233   if(se->trajectoryContainer!=nullptr && se->t << 
234   {                                            << 
235     if(trajectoryContainer==nullptr) trajector << 
236     for(auto& trj : *(se->trajectoryContainer- << 
237     { trajectoryContainer->push_back(trj); }   << 
238   }                                            << 
239 #endif                                         << 
240 */                                             << 
241 }                                              << 
242                                                << 
243 G4int G4Event::TerminateSubEvent(G4SubEvent* s << 
244 {                                              << 
245   G4AutoLock lock(&SubEventMutex);             << 
246                                                << 
247   auto ss = fSubEvtVector.find(se);            << 
248   if(ss==fSubEvtVector.end())                  << 
249   {                                            << 
250     G4ExceptionDescription ed;                 << 
251     ed << "Sub-event " << se << " of type " << << 
252        << " with " << se->GetNTrack() << " tra << 
253        << " in event " << se->GetEvent()       << 
254        << " has never been spawned.";          << 
255     G4Exception("G4Event::TerminateSubEvent"," << 
256                 FatalException,ed);            << 
257   }                                            << 
258                                                << 
259   fSubEvtVector.erase(ss);                     << 
260                                                << 
261   ss = fSubEvtVector.find(se);                 << 
262   if(ss!=fSubEvtVector.end())                  << 
263   {                                            << 
264     G4ExceptionDescription ed;                 << 
265     ed << "Sub-event " << se << " of type " << << 
266        << " with " << se->GetNTrack() << " app << 
267     G4Exception("G4Event::TerminateSubEvent"," << 
268                 FatalException,ed);            << 
269   }                                            << 
270                                                << 
271   //se->clearAndDestroy();                     << 
272   //delete se;                                 << 
273   fSubEventGarbageBin.insert(se);              << 
274   return (G4int)fSubEvtVector.size();          << 
275 }                                              << 
276                                                << 
277 G4int G4Event::GetNumberOfRemainingSubEvents() << 
278 // Number of sub-events that are either still  << 
279 // threads or sent to worker threads but not y << 
280 {                                              << 
281   G4AutoLock lock(&SubEventMutex);             << 
282   auto  tot = (G4int)fSubEvtVector.size();     << 
283   for(auto& sem : fSubEvtStackMap)             << 
284   { tot += (G4int)sem.second->size(); }        << 
285   return tot;                                  << 
286 }                                                 133 }
287                                                   134