Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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#ifdef G4MULTITHREADED
40G4Mutex G4IStore::IStoreMutex = G4MUTEX_INITIALIZER;
41#endif
42
43// ***************************************************************************
44// Static class variable: ptr to single instance of class
45// ***************************************************************************
46G4ThreadLocal G4IStore* G4IStore::fInstance = nullptr;
47
49 : fWorldVolume(G4TransportationManager::GetTransportationManager()
50 ->GetNavigatorForTracking()->GetWorldVolume())
51{
52}
53
54G4IStore::G4IStore(const G4String& ParallelWorldName)
55 : fWorldVolume(G4TransportationManager::GetTransportationManager()
56 ->GetParallelWorld(ParallelWorldName))
57{
58#ifdef G4VERBOSE
59 G4cout << " G4IStore:: ParallelWorldName = "
60 << ParallelWorldName << G4endl;
61 G4cout << " G4IStore:: fParallelWorldVolume = "
62 << fWorldVolume->GetName() << G4endl;
63#endif
64}
65
67{
68}
69
71{
72 fGeometryCelli.clear();
73}
74
76{
77 G4cout << " G4IStore:: SetWorldVolume " << G4endl;
80 G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
81 // fGeometryCelli = new G4GeometryCellImportance;
82}
83
85{
86 G4cout << " G4IStore:: SetParallelWorldVolume " << G4endl;
88 ->GetParallelWorld(paraName);
89 G4cout << " ParallelWorld volume is: " << fWorldVolume->GetName() << G4endl;
90 // fGeometryCelli = new G4GeometryCellImportance;
91}
92
94{
95 return *fWorldVolume;
96}
97
99{
100 return fWorldVolume;
101}
102
103void G4IStore::SetInternalIterator(const G4GeometryCell& gCell) const
104{
105 fCurrentIterator = fGeometryCelli.find(gCell);
106}
107
109 const G4GeometryCell& gCell)
110{
111 if (importance < 0 )
112 {
113 Error("AddImportanceGeometryCell() - Invalid importance value given.");
114 }
115 if (!IsInWorld(gCell.GetPhysicalVolume()) )
116 {
117 Error("AddImportanceGeometryCell() - Physical volume not found!");
118 }
119 SetInternalIterator(gCell);
120 if (fCurrentIterator != fGeometryCelli.cend())
121 {
122 Error("AddImportanceGeometryCell() - Region already existing!");
123 }
124 fGeometryCelli[gCell] = importance;
125}
126
128 const G4VPhysicalVolume& aVolume,
129 G4int aRepNum)
130{
131 AddImportanceGeometryCell(importance, G4GeometryCell(aVolume, aRepNum));
132}
133
135 const G4GeometryCell& gCell)
136{
137 if (importance < 0 )
138 {
139 Error("ChangeImportance() - Invalid importance value given.");
140 }
141 if (!IsInWorld(gCell.GetPhysicalVolume()))
142 {
143 Error("ChangeImportance() - Physical volume not found!");
144 }
145 SetInternalIterator(gCell);
146 if (fCurrentIterator == fGeometryCelli.cend())
147 {
148 Error("ChangeImportance() - Region does not exist!");
149 }
150 fGeometryCelli[gCell] = importance;
151
152}
153
155 const G4VPhysicalVolume& aVolume,
156 G4int aRepNum)
157{
158 ChangeImportance(importance, G4GeometryCell(aVolume, aRepNum));
159}
160
162 G4int aRepNum) const
163{
164#ifdef G4MULTITHREADED
165 G4MUTEXLOCK(&G4IStore::IStoreMutex);
166#endif
167 SetInternalIterator(G4GeometryCell(aVolume, aRepNum));
168 auto gCellIterator = fCurrentIterator;
169 if (gCellIterator == fGeometryCelli.cend())
170 {
171 Error("GetImportance() - Region does not exist!");
172 return 0.;
173 }
174 G4double importance_value = (*fCurrentIterator).second;
175#ifdef G4MULTITHREADED
176 G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
177#endif
178 return importance_value;
179}
180
182{
183#ifdef G4MULTITHREADED
184 G4MUTEXLOCK(&G4IStore::IStoreMutex);
185#endif
186 SetInternalIterator(gCell);
187 auto gCellIterator = fCurrentIterator;
188 if (gCellIterator == fGeometryCelli.cend())
189 {
190 std::ostringstream err_mess;
191 err_mess << "GetImportance() - Region does not exist!" << G4endl
192 << "Geometry cell, " << gCell
193 << ", not found in: " << fGeometryCelli << ".";
194 Error(err_mess.str());
195 return 0.;
196 }
197 G4double importance_value = (*fCurrentIterator).second;
198#ifdef G4MULTITHREADED
199 G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
200#endif
201 return importance_value;
202 // return (*fCurrentIterator).second;
203}
204
206{
207#ifdef G4MULTITHREADED
208 G4MUTEXLOCK(&G4IStore::IStoreMutex);
209#endif
210 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
211
212 if ( inWorldKnown )
213 {
214 SetInternalIterator(gCell);
215 inWorldKnown = (fCurrentIterator != fGeometryCelli.cend());
216 }
217#ifdef G4MULTITHREADED
218 G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
219#endif
220 return inWorldKnown;
221}
222
223G4bool G4IStore::IsInWorld(const G4VPhysicalVolume& aVolume) const
224{
225 G4bool isIn(true);
226 if (!(aVolume == *fWorldVolume))
227 {
228 isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
229 }
230 return isIn;
231}
232
233void G4IStore::Error(const G4String& msg) const
234{
235 G4Exception("G4IStore::Error()", "GeomBias0002", FatalException, msg);
236}
237
238// ***************************************************************************
239// Returns the instance of the singleton.
240// Creates it in case it's called for the first time.
241// ***************************************************************************
242//
244{
245 if (fInstance == nullptr)
246 {
247#ifdef G4VERBOSE
248 G4cout << "G4IStore:: Creating new MASS IStore " << G4endl;
249#endif
250 fInstance = new G4IStore();
251 }
252 return fInstance;
253}
254
255// ***************************************************************************
256// Returns the instance of the singleton.
257// Creates it in case it's called for the first time.
258// ***************************************************************************
259//
260G4IStore* G4IStore::GetInstance(const G4String& ParallelWorldName)
261{
262 if (fInstance == nullptr)
263 {
264#ifdef G4VERBOSE
265 G4cout << "G4IStore:: Creating new Parallel IStore "
266 << ParallelWorldName << G4endl;
267#endif
268 fInstance = new G4IStore(ParallelWorldName);
269 }
270 return fInstance;
271}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
#define G4MUTEXLOCK(mutex)
Definition: G4Threading.hh:251
#define G4MUTEXUNLOCK(mutex)
Definition: G4Threading.hh:254
std::mutex G4Mutex
Definition: G4Threading.hh:81
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
const G4VPhysicalVolume & GetPhysicalVolume() const
virtual G4double GetImportance(const G4GeometryCell &gCell) const
Definition: G4IStore.cc:181
void AddImportanceGeometryCell(G4double importance, const G4GeometryCell &gCell)
Definition: G4IStore.cc:108
virtual const G4VPhysicalVolume & GetWorldVolume() const
Definition: G4IStore.cc:93
static G4IStore * GetInstance()
Definition: G4IStore.cc:243
void Clear()
Definition: G4IStore.cc:70
void ChangeImportance(G4double importance, const G4GeometryCell &gCell)
Definition: G4IStore.cc:134
~G4IStore()
Definition: G4IStore.cc:66
void SetParallelWorldVolume(const G4String &paraName)
Definition: G4IStore.cc:84
virtual G4bool IsKnown(const G4GeometryCell &gCell) const
Definition: G4IStore.cc:205
virtual const G4VPhysicalVolume * GetParallelWorldVolumePointer() const
Definition: G4IStore.cc:98
G4IStore()
Definition: G4IStore.cc:48
void SetWorldVolume()
Definition: G4IStore.cc:75
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