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