Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4IStore.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4IStore implementation
27//
28// Author: Michael Dressel (CERN), 2002
29// Modified: Alex Howard (CERN), 2013 - Changed class to a 'singleton'
30// ----------------------------------------------------------------------
31
32#include "G4IStore.hh"
33#include "G4VPhysicalVolume.hh"
34#include "G4GeometryCell.hh"
36#include "G4LogicalVolume.hh"
38
39#include "G4AutoLock.hh"
40
41namespace
42{
43 G4Mutex IStoreMutex = G4MUTEX_INITIALIZER;
44}
45
46// ***************************************************************************
47// Static class variable: ptr to single instance of class
48// ***************************************************************************
49G4ThreadLocal G4IStore* G4IStore::fInstance = nullptr;
50
52 : fWorldVolume(G4TransportationManager::GetTransportationManager()
53 ->GetNavigatorForTracking()->GetWorldVolume())
54{
55}
56
57G4IStore::G4IStore(const G4String& ParallelWorldName)
58 : fWorldVolume(G4TransportationManager::GetTransportationManager()
59 ->GetParallelWorld(ParallelWorldName))
60{
61#ifdef G4VERBOSE
62 G4cout << " G4IStore:: ParallelWorldName = "
63 << ParallelWorldName << G4endl;
64 G4cout << " G4IStore:: fParallelWorldVolume = "
65 << fWorldVolume->GetName() << G4endl;
66#endif
67}
68
69G4IStore::~G4IStore() = default;
70
72{
73 fGeometryCelli.clear();
74}
75
77{
78 G4cout << " G4IStore:: SetWorldVolume " << G4endl;
81 G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
82 // fGeometryCelli = new G4GeometryCellImportance;
83}
84
86{
87 G4cout << " G4IStore:: SetParallelWorldVolume " << G4endl;
89 ->GetParallelWorld(paraName);
90 G4cout << " ParallelWorld volume is: " << fWorldVolume->GetName() << G4endl;
91 // fGeometryCelli = new G4GeometryCellImportance;
92}
93
95{
96 return *fWorldVolume;
97}
98
100{
101 return fWorldVolume;
102}
103
104void G4IStore::SetInternalIterator(const G4GeometryCell& gCell) const
105{
106 fCurrentIterator = fGeometryCelli.find(gCell);
107}
108
110 const G4GeometryCell& gCell)
111{
112 if (importance < 0 )
113 {
114 Error("AddImportanceGeometryCell() - Invalid importance value given.");
115 }
116 if (!IsInWorld(gCell.GetPhysicalVolume()) )
117 {
118 Error("AddImportanceGeometryCell() - Physical volume not found!");
119 }
120 SetInternalIterator(gCell);
121 if (fCurrentIterator != fGeometryCelli.cend())
122 {
123 Error("AddImportanceGeometryCell() - Region already existing!");
124 }
125 fGeometryCelli[gCell] = importance;
126}
127
129 const G4VPhysicalVolume& aVolume,
130 G4int aRepNum)
131{
132 AddImportanceGeometryCell(importance, G4GeometryCell(aVolume, aRepNum));
133}
134
136 const G4GeometryCell& gCell)
137{
138 if (importance < 0 )
139 {
140 Error("ChangeImportance() - Invalid importance value given.");
141 }
142 if (!IsInWorld(gCell.GetPhysicalVolume()))
143 {
144 Error("ChangeImportance() - Physical volume not found!");
145 }
146 SetInternalIterator(gCell);
147 if (fCurrentIterator == fGeometryCelli.cend())
148 {
149 Error("ChangeImportance() - Region does not exist!");
150 }
151 fGeometryCelli[gCell] = importance;
152
153}
154
156 const G4VPhysicalVolume& aVolume,
157 G4int aRepNum)
158{
159 ChangeImportance(importance, G4GeometryCell(aVolume, aRepNum));
160}
161
163 G4int aRepNum) const
164{
165 G4AutoLock l(&IStoreMutex);
166 SetInternalIterator(G4GeometryCell(aVolume, aRepNum));
167 auto gCellIterator = fCurrentIterator;
168 if (gCellIterator == fGeometryCelli.cend())
169 {
170 Error("GetImportance() - Region does not exist!");
171 return 0.;
172 }
173 G4double importance_value = (*fCurrentIterator).second;
174 l.unlock();
175
176 return importance_value;
177}
178
180{
181 G4AutoLock l(&IStoreMutex);
182 SetInternalIterator(gCell);
183 auto gCellIterator = fCurrentIterator;
184 if (gCellIterator == fGeometryCelli.cend())
185 {
186 std::ostringstream err_mess;
187 err_mess << "GetImportance() - Region does not exist!" << G4endl
188 << "Geometry cell, " << gCell
189 << ", not found in: " << fGeometryCelli << ".";
190 Error(err_mess.str());
191 return 0.;
192 }
193 G4double importance_value = (*fCurrentIterator).second;
194 l.unlock();
195
196 return importance_value;
197}
198
200{
201 G4AutoLock l(&IStoreMutex);
202 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
203
204 if ( inWorldKnown )
205 {
206 SetInternalIterator(gCell);
207 inWorldKnown = (fCurrentIterator != fGeometryCelli.cend());
208 }
209 l.unlock();
210
211 return inWorldKnown;
212}
213
214G4bool G4IStore::IsInWorld(const G4VPhysicalVolume& aVolume) const
215{
216 G4bool isIn(true);
217 if (!(aVolume == *fWorldVolume))
218 {
219 isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
220 }
221 return isIn;
222}
223
224void G4IStore::Error(const G4String& msg) const
225{
226 G4Exception("G4IStore::Error()", "GeomBias0002", FatalException, msg);
227}
228
229// ***************************************************************************
230// Returns the instance of the singleton.
231// Creates it in case it's called for the first time.
232// ***************************************************************************
233//
235{
236 if (fInstance == nullptr)
237 {
238#ifdef G4VERBOSE
239 G4cout << "G4IStore:: Creating new MASS IStore " << G4endl;
240#endif
241 fInstance = new G4IStore();
242 }
243 return fInstance;
244}
245
246// ***************************************************************************
247// Returns the instance of the singleton.
248// Creates it in case it's called for the first time.
249// ***************************************************************************
250//
251G4IStore* G4IStore::GetInstance(const G4String& ParallelWorldName)
252{
253 if (fInstance == nullptr)
254 {
255#ifdef G4VERBOSE
256 G4cout << "G4IStore:: Creating new Parallel IStore "
257 << ParallelWorldName << G4endl;
258#endif
259 fInstance = new G4IStore(ParallelWorldName);
260 }
261 return fInstance;
262}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define G4MUTEX_INITIALIZER
std::mutex G4Mutex
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
const G4VPhysicalVolume & GetPhysicalVolume() const
G4double GetImportance(const G4GeometryCell &gCell) const override
Definition G4IStore.cc:179
void AddImportanceGeometryCell(G4double importance, const G4GeometryCell &gCell)
Definition G4IStore.cc:109
const G4VPhysicalVolume & GetWorldVolume() const override
Definition G4IStore.cc:94
G4bool IsKnown(const G4GeometryCell &gCell) const override
Definition G4IStore.cc:199
static G4IStore * GetInstance()
Definition G4IStore.cc:234
void Clear()
Definition G4IStore.cc:71
void ChangeImportance(G4double importance, const G4GeometryCell &gCell)
Definition G4IStore.cc:135
void SetParallelWorldVolume(const G4String &paraName)
Definition G4IStore.cc:85
~G4IStore() override
virtual const G4VPhysicalVolume * GetParallelWorldVolumePointer() const
Definition G4IStore.cc:99
void SetWorldVolume()
Definition G4IStore.cc:76
G4bool IsAncestor(const G4VPhysicalVolume *p) const
G4VPhysicalVolume * GetWorldVolume() const
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
#define G4ThreadLocal
Definition tls.hh:77