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 // G4IStore implementation << 27 // 26 // 28 // Author: Michael Dressel (CERN), 2002 << 27 // $Id: G4IStore.cc 88801 2015-03-10 14:38:27Z gcosmo $ 29 // Modified: Alex Howard (CERN), 2013 - Change << 28 // >> 29 // ---------------------------------------------------------------------- >> 30 // GEANT 4 class source file >> 31 // >> 32 // G4IStore.cc >> 33 // 30 // ------------------------------------------- 34 // ---------------------------------------------------------------------- 31 35 32 #include "G4IStore.hh" 36 #include "G4IStore.hh" 33 #include "G4VPhysicalVolume.hh" 37 #include "G4VPhysicalVolume.hh" 34 #include "G4GeometryCell.hh" 38 #include "G4GeometryCell.hh" 35 #include "G4GeometryCellStepStream.hh" 39 #include "G4GeometryCellStepStream.hh" 36 #include "G4LogicalVolume.hh" 40 #include "G4LogicalVolume.hh" 37 #include "G4TransportationManager.hh" 41 #include "G4TransportationManager.hh" 38 42 39 #include "G4AutoLock.hh" << 40 << 41 namespace << 42 { << 43 G4Mutex IStoreMutex = G4MUTEX_INITIALIZER; << 44 } << 45 << 46 // ******************************************* 43 // *************************************************************************** 47 // Static class variable: ptr to single instan 44 // Static class variable: ptr to single instance of class 48 // ******************************************* 45 // *************************************************************************** 49 G4ThreadLocal G4IStore* G4IStore::fInstance = << 46 G4ThreadLocal G4IStore* G4IStore::fInstance = 0; 50 47 51 G4IStore::G4IStore() << 48 G4IStore::G4IStore() : 52 : fWorldVolume(G4TransportationManager::GetT << 49 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()) 53 ->GetNavigatorForTracking()-> << 50 {} 54 { << 55 } << 56 51 57 G4IStore::G4IStore(const G4String& ParallelWor << 52 G4IStore::G4IStore(const G4String& ParallelWorldName) : 58 : fWorldVolume(G4TransportationManager::GetT << 53 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetParallelWorld(ParallelWorldName)) 59 ->GetParallelWorld(ParallelWo << 60 { 54 { 61 #ifdef G4VERBOSE << 55 G4cout << " G4IStore:: ParallelWorldName = " << ParallelWorldName << G4endl; 62 G4cout << " G4IStore:: ParallelWorldName = " << 56 G4cout << " G4IStore:: fParallelWorldVolume = " << fWorldVolume->GetName() << G4endl; 63 << ParallelWorldName << G4endl; << 64 G4cout << " G4IStore:: fParallelWorldVolume << 65 << fWorldVolume->GetName() << G4endl; << 66 #endif << 67 } 57 } 68 58 69 G4IStore::~G4IStore() = default; << 59 G4IStore::~G4IStore() >> 60 {} 70 61 71 void G4IStore::Clear() 62 void G4IStore::Clear() 72 { 63 { 73 fGeometryCelli.clear(); 64 fGeometryCelli.clear(); 74 } 65 } 75 66 76 void G4IStore::SetWorldVolume() 67 void G4IStore::SetWorldVolume() 77 { 68 { 78 G4cout << " G4IStore:: SetWorldVolume " << G 69 G4cout << " G4IStore:: SetWorldVolume " << G4endl; 79 fWorldVolume = G4TransportationManager::GetT << 70 fWorldVolume = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume(); 80 ->GetNavigatorForTracking()-> << 81 G4cout << " World volume is: " << fWorldVolu 71 G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl; 82 // fGeometryCelli = new G4GeometryCellImport << 72 // fGeometryCelli = new G4GeometryCellImportance; 83 } 73 } 84 74 85 void G4IStore::SetParallelWorldVolume(const G4 << 75 void G4IStore::SetParallelWorldVolume(G4String paraName) 86 { 76 { 87 G4cout << " G4IStore:: SetParallelWorldVolum 77 G4cout << " G4IStore:: SetParallelWorldVolume " << G4endl; 88 fWorldVolume = G4TransportationManager::GetT << 78 fWorldVolume = G4TransportationManager::GetTransportationManager()->GetParallelWorld(paraName); 89 ->GetParallelWorld(paraName); << 90 G4cout << " ParallelWorld volume is: " << fW 79 G4cout << " ParallelWorld volume is: " << fWorldVolume->GetName() << G4endl; 91 // fGeometryCelli = new G4GeometryCellImport << 80 // fGeometryCelli = new G4GeometryCellImportance; 92 } 81 } 93 82 94 const G4VPhysicalVolume& G4IStore::GetWorldVol 83 const G4VPhysicalVolume& G4IStore::GetWorldVolume() const 95 { 84 { 96 return *fWorldVolume; 85 return *fWorldVolume; 97 } 86 } 98 87 >> 88 // const G4VPhysicalVolume& G4IStore::GetParallelWorldVolume() const >> 89 // { >> 90 // return *fParallelWorldVolume; >> 91 // } >> 92 99 const G4VPhysicalVolume* G4IStore::GetParallel 93 const G4VPhysicalVolume* G4IStore::GetParallelWorldVolumePointer() const 100 { 94 { 101 return fWorldVolume; 95 return fWorldVolume; 102 } 96 } 103 97 104 void G4IStore::SetInternalIterator(const G4Geo << 98 void G4IStore::SetInternalIterator(const G4GeometryCell &gCell) const 105 { 99 { 106 fCurrentIterator = fGeometryCelli.find(gCell 100 fCurrentIterator = fGeometryCelli.find(gCell); 107 } 101 } 108 102 109 void G4IStore::AddImportanceGeometryCell(G4dou 103 void G4IStore::AddImportanceGeometryCell(G4double importance, 110 const << 104 const G4GeometryCell &gCell) 111 { 105 { 112 if (importance < 0 ) << 106 if (importance < 0 ) { 113 { << 114 Error("AddImportanceGeometryCell() - Inval 107 Error("AddImportanceGeometryCell() - Invalid importance value given."); 115 } 108 } 116 if (!IsInWorld(gCell.GetPhysicalVolume()) ) << 109 if (!IsInWorld(gCell.GetPhysicalVolume()) ) { 117 { << 118 Error("AddImportanceGeometryCell() - Physi 110 Error("AddImportanceGeometryCell() - Physical volume not found!"); 119 } 111 } 120 SetInternalIterator(gCell); 112 SetInternalIterator(gCell); 121 if (fCurrentIterator != fGeometryCelli.cend( << 113 if (fCurrentIterator!=fGeometryCelli.end()) { 122 { << 123 Error("AddImportanceGeometryCell() - Regio 114 Error("AddImportanceGeometryCell() - Region already existing!"); 124 } 115 } 125 fGeometryCelli[gCell] = importance; 116 fGeometryCelli[gCell] = importance; 126 } 117 } 127 118 128 void G4IStore::AddImportanceGeometryCell(G4dou 119 void G4IStore::AddImportanceGeometryCell(G4double importance, 129 const << 120 const G4VPhysicalVolume &aVolume, 130 G4int << 121 G4int aRepNum) 131 { 122 { 132 AddImportanceGeometryCell(importance, G4Geom << 123 AddImportanceGeometryCell(importance, >> 124 G4GeometryCell(aVolume, aRepNum)); 133 } 125 } 134 126 135 void G4IStore::ChangeImportance(G4double impor 127 void G4IStore::ChangeImportance(G4double importance, 136 const G4Geomet << 128 const G4GeometryCell &gCell){ 137 { << 129 if (importance < 0 ) { 138 if (importance < 0 ) << 139 { << 140 Error("ChangeImportance() - Invalid import 130 Error("ChangeImportance() - Invalid importance value given."); 141 } 131 } 142 if (!IsInWorld(gCell.GetPhysicalVolume())) << 132 if (!IsInWorld(gCell.GetPhysicalVolume()) ) { 143 { << 144 Error("ChangeImportance() - Physical volum 133 Error("ChangeImportance() - Physical volume not found!"); 145 } 134 } 146 SetInternalIterator(gCell); 135 SetInternalIterator(gCell); 147 if (fCurrentIterator == fGeometryCelli.cend( << 136 if (fCurrentIterator==fGeometryCelli.end()) { 148 { << 149 Error("ChangeImportance() - Region does no 137 Error("ChangeImportance() - Region does not exist!"); 150 } 138 } 151 fGeometryCelli[gCell] = importance; 139 fGeometryCelli[gCell] = importance; 152 140 153 } 141 } 154 << 155 void G4IStore::ChangeImportance(G4double impor 142 void G4IStore::ChangeImportance(G4double importance, 156 const G4VPhysi << 143 const G4VPhysicalVolume &aVolume, 157 G4int aRepNum) << 144 G4int aRepNum) 158 { 145 { 159 ChangeImportance(importance, G4GeometryCell( 146 ChangeImportance(importance, G4GeometryCell(aVolume, aRepNum)); 160 } 147 } 161 148 162 G4double G4IStore::GetImportance(const G4VPhys << 149 G4double G4IStore::GetImportance(const G4VPhysicalVolume &aVolume, 163 G4int aRepNum << 150 G4int aRepNum) const 164 { 151 { 165 G4AutoLock l(&IStoreMutex); << 166 SetInternalIterator(G4GeometryCell(aVolume, 152 SetInternalIterator(G4GeometryCell(aVolume, aRepNum)); 167 auto gCellIterator = fCurrentIterator; << 153 G4GeometryCellImportance::const_iterator gCellIterator = fCurrentIterator; 168 if (gCellIterator == fGeometryCelli.cend()) << 154 if (gCellIterator==fGeometryCelli.end()) { 169 { << 170 Error("GetImportance() - Region does not e 155 Error("GetImportance() - Region does not exist!"); 171 return 0.; 156 return 0.; 172 } 157 } 173 G4double importance_value = (*fCurrentIterat << 158 return (*fCurrentIterator).second; 174 l.unlock(); << 175 << 176 return importance_value; << 177 } 159 } 178 160 179 G4double G4IStore::GetImportance(const G4Geome << 161 >> 162 G4double G4IStore::GetImportance(const G4GeometryCell &gCell) const 180 { 163 { 181 G4AutoLock l(&IStoreMutex); << 182 SetInternalIterator(gCell); 164 SetInternalIterator(gCell); 183 auto gCellIterator = fCurrentIterator; << 165 G4GeometryCellImportance::const_iterator gCellIterator = fCurrentIterator; 184 if (gCellIterator == fGeometryCelli.cend()) << 166 if (gCellIterator==fGeometryCelli.end()) { 185 { << 186 std::ostringstream err_mess; 167 std::ostringstream err_mess; 187 err_mess << "GetImportance() - Region does 168 err_mess << "GetImportance() - Region does not exist!" << G4endl 188 << "Geometry cell, " << gCell 169 << "Geometry cell, " << gCell 189 << ", not found in: " << fGeometr 170 << ", not found in: " << fGeometryCelli << "."; 190 Error(err_mess.str()); 171 Error(err_mess.str()); 191 return 0.; 172 return 0.; 192 } 173 } 193 G4double importance_value = (*fCurrentIterat << 174 return (*fCurrentIterator).second; 194 l.unlock(); << 195 << 196 return importance_value; << 197 } 175 } 198 176 199 G4bool G4IStore::IsKnown(const G4GeometryCell& << 177 G4bool G4IStore::IsKnown(const G4GeometryCell &gCell) const { 200 { << 201 G4AutoLock l(&IStoreMutex); << 202 G4bool inWorldKnown(IsInWorld(gCell.GetPhysi 178 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume())); 203 << 179 204 if ( inWorldKnown ) << 180 if ( inWorldKnown ) { 205 { << 206 SetInternalIterator(gCell); 181 SetInternalIterator(gCell); 207 inWorldKnown = (fCurrentIterator != fGeome << 182 inWorldKnown = (fCurrentIterator!=fGeometryCelli.end()); 208 } 183 } 209 l.unlock(); << 210 << 211 return inWorldKnown; 184 return inWorldKnown; 212 } 185 } 213 186 214 G4bool G4IStore::IsInWorld(const G4VPhysicalVo << 187 G4bool G4IStore::IsInWorld(const G4VPhysicalVolume &aVolume) const 215 { 188 { 216 G4bool isIn(true); 189 G4bool isIn(true); 217 if (!(aVolume == *fWorldVolume)) << 190 // G4cout << "G4IStore:: aVolume: " << aVolume.GetName() << G4endl; 218 { << 191 // G4cout << "G4IStore:: fWorld: " << fWorldVolume->GetName() << G4endl; 219 isIn = fWorldVolume->GetLogicalVolume()->I << 192 if (!(aVolume == *fWorldVolume)) { >> 193 isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume); 220 } 194 } 221 return isIn; 195 return isIn; 222 } 196 } 223 197 224 void G4IStore::Error(const G4String& msg) cons << 198 >> 199 >> 200 void G4IStore::Error(const G4String &msg) const 225 { 201 { 226 G4Exception("G4IStore::Error()", "GeomBias00 202 G4Exception("G4IStore::Error()", "GeomBias0002", FatalException, msg); 227 } 203 } 228 204 229 // ******************************************* 205 // *************************************************************************** 230 // Returns the instance of the singleton. 206 // Returns the instance of the singleton. 231 // Creates it in case it's called for the firs 207 // Creates it in case it's called for the first time. 232 // ******************************************* 208 // *************************************************************************** 233 // 209 // 234 G4IStore* G4IStore::GetInstance() 210 G4IStore* G4IStore::GetInstance() 235 { 211 { 236 if (fInstance == nullptr) << 212 if (!fInstance) 237 { 213 { 238 #ifdef G4VERBOSE << 239 G4cout << "G4IStore:: Creating new MASS IS 214 G4cout << "G4IStore:: Creating new MASS IStore " << G4endl; 240 #endif << 241 fInstance = new G4IStore(); 215 fInstance = new G4IStore(); 242 } 216 } 243 return fInstance; 217 return fInstance; 244 } 218 } 245 219 246 // ******************************************* 220 // *************************************************************************** 247 // Returns the instance of the singleton. 221 // Returns the instance of the singleton. 248 // Creates it in case it's called for the firs 222 // Creates it in case it's called for the first time. 249 // ******************************************* 223 // *************************************************************************** 250 // 224 // 251 G4IStore* G4IStore::GetInstance(const G4String 225 G4IStore* G4IStore::GetInstance(const G4String& ParallelWorldName) 252 { 226 { 253 if (fInstance == nullptr) << 227 if (!fInstance) 254 { 228 { 255 #ifdef G4VERBOSE << 229 G4cout << "G4IStore:: Creating new Parallel IStore " << ParallelWorldName << G4endl; 256 G4cout << "G4IStore:: Creating new Paralle << 257 << ParallelWorldName << G4endl; << 258 #endif << 259 fInstance = new G4IStore(ParallelWorldName 230 fInstance = new G4IStore(ParallelWorldName); 260 } 231 } 261 return fInstance; 232 return fInstance; 262 } 233 } >> 234 263 235