Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4Event class implementation << 27 // 23 // 28 // Author: M.Asai, SLAC/JLAB << 24 // $Id: G4Event.cc,v 1.6 2003/09/09 20:09:18 asaim Exp $ 29 // ------------------------------------------- << 25 // GEANT4 tag $Name: geant4-06-00 $ >> 26 // >> 27 >> 28 // G4Event 30 29 31 #include "G4Event.hh" 30 #include "G4Event.hh" 32 #include "G4VVisManager.hh" 31 #include "G4VVisManager.hh" >> 32 //#include "G4HCofThisEvent.hh" >> 33 //#include "G4DCofThisEvent.hh" 33 #include "G4VHitsCollection.hh" 34 #include "G4VHitsCollection.hh" 34 #include "G4VDigiCollection.hh" 35 #include "G4VDigiCollection.hh" 35 #include "G4ios.hh" 36 #include "G4ios.hh" 36 #include "G4SubEvent.hh" << 37 37 38 #include "G4Threading.hh" << 38 G4Allocator<G4Event> anEventAllocator; 39 #include "G4AutoLock.hh" << 40 namespace{ << 41 G4Mutex SubEventMutex = G4MUTEX_INITIALIZER; << 42 } << 43 39 44 G4Allocator<G4Event>*& anEventAllocator() << 40 G4Event::G4Event() 45 { << 41 :eventID(0), 46 G4ThreadLocalStatic G4Allocator<G4Event>* _i << 42 thePrimaryVertex(0),numberOfPrimaryVertex(0), 47 return _instance; << 43 HC(0),DC(0),trajectoryContainer(0),eventAborted(false),userInfo(0) 48 } << 44 {;} 49 45 50 G4Event::G4Event(G4int evID) 46 G4Event::G4Event(G4int evID) 51 : eventID(evID) << 47 :eventID(evID), 52 { << 48 thePrimaryVertex(0),numberOfPrimaryVertex(0), 53 } << 49 HC(0),DC(0),trajectoryContainer(0),eventAborted(false),userInfo(0) >> 50 {;} 54 51 55 G4Event::~G4Event() 52 G4Event::~G4Event() 56 { << 53 { 57 G4PrimaryVertex* nextVertex = thePrimaryVert << 54 if(thePrimaryVertex) delete thePrimaryVertex; 58 while(nextVertex != nullptr) << 55 if(HC) delete HC; 59 { << 56 if(DC) delete DC; 60 G4PrimaryVertex* thisVertex = nextVertex; << 57 if(trajectoryContainer) 61 nextVertex = thisVertex->GetNext(); << 62 thisVertex->ClearNext(); << 63 delete thisVertex; << 64 } << 65 thePrimaryVertex = nullptr; << 66 delete HC; << 67 delete DC; << 68 if(trajectoryContainer != nullptr) << 69 { 58 { 70 trajectoryContainer->clearAndDestroy(); 59 trajectoryContainer->clearAndDestroy(); 71 delete trajectoryContainer; 60 delete trajectoryContainer; 72 } 61 } 73 delete userInfo; << 62 if(userInfo) delete userInfo; 74 delete randomNumberStatus; << 75 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 } 63 } 125 64 126 G4bool G4Event::operator==(const G4Event& righ << 65 G4int G4Event::operator==(const G4Event &right) const 127 { 66 { 128 return ( eventID == right.eventID ); 67 return ( eventID == right.eventID ); 129 } 68 } 130 69 131 G4bool G4Event::operator!=(const G4Event& righ << 70 G4int G4Event::operator!=(const G4Event &right) const 132 { 71 { 133 return ( eventID != right.eventID ); 72 return ( eventID != right.eventID ); 134 } 73 } 135 74 136 void G4Event::Print() const 75 void G4Event::Print() const 137 { 76 { 138 G4cout << "G4Event " << eventID << G4endl; 77 G4cout << "G4Event " << eventID << G4endl; 139 } 78 } 140 79 141 void G4Event::Draw() const 80 void G4Event::Draw() const 142 { 81 { 143 G4VVisManager* pVVisManager = G4VVisManager: 82 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 144 if(pVVisManager == nullptr) return; << 83 if(!pVVisManager) return; 145 84 146 if(trajectoryContainer != nullptr) << 85 if(trajectoryContainer) 147 { 86 { 148 std::size_t n_traj = trajectoryContainer-> << 87 G4int n_traj = trajectoryContainer->entries(); 149 for(std::size_t i=0; i<n_traj; ++i) << 88 for(G4int i=0;i<n_traj;i++) 150 { (*trajectoryContainer)[i]->DrawTrajector 89 { (*trajectoryContainer)[i]->DrawTrajectory(); } 151 } 90 } 152 91 153 if(HC != nullptr) << 92 if(HC) 154 { 93 { 155 std::size_t n_HC = HC->GetCapacity(); << 94 G4int n_HC = HC->GetCapacity(); 156 for(std::size_t j=0; j<n_HC; ++j) << 95 for(G4int j=0;j<n_HC;j++) 157 { 96 { 158 G4VHitsCollection* VHC = HC->GetHC((G4in << 97 G4VHitsCollection * VHC = HC->GetHC(j); 159 if(VHC != nullptr) VHC->DrawAllHits(); << 98 if(VHC) VHC->DrawAllHits(); 160 } 99 } 161 } 100 } 162 101 163 if(DC != nullptr) << 102 if(DC) 164 { 103 { 165 std::size_t n_DC = DC->GetCapacity(); << 104 G4int n_DC = DC->GetCapacity(); 166 for(std::size_t j=0; j<n_DC; ++j) << 105 for(G4int j=0;j<n_DC;j++) 167 { 106 { 168 G4VDigiCollection* VDC = DC->GetDC((G4in << 107 G4VDigiCollection * VDC = DC->GetDC(j); 169 if(VDC != nullptr) VDC->DrawAllDigi(); << 108 if(VDC) VDC->DrawAllDigi(); 170 } 109 } 171 } 110 } 172 } 111 } 173 112 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 } << 287 113