Geant4 Cross Reference |
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 26 // G4Event class implementation 27 // 27 // 28 // Author: M.Asai, SLAC/JLAB << 28 // Author: M.Asai, SLAC 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 31 #include "G4Event.hh" 31 #include "G4Event.hh" 32 #include "G4VVisManager.hh" 32 #include "G4VVisManager.hh" 33 #include "G4VHitsCollection.hh" 33 #include "G4VHitsCollection.hh" 34 #include "G4VDigiCollection.hh" 34 #include "G4VDigiCollection.hh" 35 #include "G4ios.hh" 35 #include "G4ios.hh" 36 #include "G4SubEvent.hh" << 37 << 38 #include "G4Threading.hh" << 39 #include "G4AutoLock.hh" << 40 namespace{ << 41 G4Mutex SubEventMutex = G4MUTEX_INITIALIZER; << 42 } << 43 36 44 G4Allocator<G4Event>*& anEventAllocator() 37 G4Allocator<G4Event>*& anEventAllocator() 45 { 38 { 46 G4ThreadLocalStatic G4Allocator<G4Event>* _i 39 G4ThreadLocalStatic G4Allocator<G4Event>* _instance = nullptr; 47 return _instance; 40 return _instance; 48 } 41 } 49 42 >> 43 G4Event::G4Event() >> 44 { >> 45 } >> 46 50 G4Event::G4Event(G4int evID) 47 G4Event::G4Event(G4int evID) 51 : eventID(evID) 48 : eventID(evID) 52 { 49 { 53 } 50 } 54 51 55 G4Event::~G4Event() 52 G4Event::~G4Event() 56 { 53 { 57 G4PrimaryVertex* nextVertex = thePrimaryVert 54 G4PrimaryVertex* nextVertex = thePrimaryVertex; 58 while(nextVertex != nullptr) 55 while(nextVertex != nullptr) 59 { 56 { 60 G4PrimaryVertex* thisVertex = nextVertex; 57 G4PrimaryVertex* thisVertex = nextVertex; 61 nextVertex = thisVertex->GetNext(); 58 nextVertex = thisVertex->GetNext(); 62 thisVertex->ClearNext(); 59 thisVertex->ClearNext(); 63 delete thisVertex; 60 delete thisVertex; 64 } 61 } 65 thePrimaryVertex = nullptr; 62 thePrimaryVertex = nullptr; 66 delete HC; 63 delete HC; 67 delete DC; 64 delete DC; 68 if(trajectoryContainer != nullptr) 65 if(trajectoryContainer != nullptr) 69 { 66 { 70 trajectoryContainer->clearAndDestroy(); 67 trajectoryContainer->clearAndDestroy(); 71 delete trajectoryContainer; 68 delete trajectoryContainer; 72 } 69 } 73 delete userInfo; 70 delete userInfo; 74 delete randomNumberStatus; 71 delete randomNumberStatus; 75 delete randomNumberStatusForProcessing; 72 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 } 73 } 125 74 126 G4bool G4Event::operator==(const G4Event& righ 75 G4bool G4Event::operator==(const G4Event& right) const 127 { 76 { 128 return ( eventID == right.eventID ); 77 return ( eventID == right.eventID ); 129 } 78 } 130 79 131 G4bool G4Event::operator!=(const G4Event& righ 80 G4bool G4Event::operator!=(const G4Event& right) const 132 { 81 { 133 return ( eventID != right.eventID ); 82 return ( eventID != right.eventID ); 134 } 83 } 135 84 136 void G4Event::Print() const 85 void G4Event::Print() const 137 { 86 { 138 G4cout << "G4Event " << eventID << G4endl; 87 G4cout << "G4Event " << eventID << G4endl; 139 } 88 } 140 89 141 void G4Event::Draw() const 90 void G4Event::Draw() const 142 { 91 { 143 G4VVisManager* pVVisManager = G4VVisManager: 92 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 144 if(pVVisManager == nullptr) return; 93 if(pVVisManager == nullptr) return; 145 94 146 if(trajectoryContainer != nullptr) << 95 if(trajectoryContainer) 147 { 96 { 148 std::size_t n_traj = trajectoryContainer-> << 97 G4int n_traj = trajectoryContainer->entries(); 149 for(std::size_t i=0; i<n_traj; ++i) << 98 for(G4int i=0; i<n_traj; ++i) 150 { (*trajectoryContainer)[i]->DrawTrajector 99 { (*trajectoryContainer)[i]->DrawTrajectory(); } 151 } 100 } 152 101 153 if(HC != nullptr) 102 if(HC != nullptr) 154 { 103 { 155 std::size_t n_HC = HC->GetCapacity(); << 104 G4int n_HC = HC->GetCapacity(); 156 for(std::size_t j=0; j<n_HC; ++j) << 105 for(G4int j=0; j<n_HC; ++j) 157 { 106 { 158 G4VHitsCollection* VHC = HC->GetHC((G4in << 107 G4VHitsCollection* VHC = HC->GetHC(j); 159 if(VHC != nullptr) VHC->DrawAllHits(); 108 if(VHC != nullptr) VHC->DrawAllHits(); 160 } 109 } 161 } 110 } 162 111 163 if(DC != nullptr) 112 if(DC != nullptr) 164 { 113 { 165 std::size_t n_DC = DC->GetCapacity(); << 114 G4int n_DC = DC->GetCapacity(); 166 for(std::size_t j=0; j<n_DC; ++j) << 115 for(G4int j=0; j<n_DC; ++j) 167 { << 168 G4VDigiCollection* VDC = DC->GetDC((G4in << 169 if(VDC != nullptr) VDC->DrawAllDigi(); << 170 } << 171 } << 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 { 116 { 200 se = sev->extract(sev->begin()).value(); << 117 G4VDigiCollection* VDC = DC->GetDC(j); 201 SpawnSubEvent(se); << 118 if(VDC) VDC->DrawAllDigi(); 202 } 119 } 203 } 120 } 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 } 121 } 287 122