Geant4 11.4.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#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
51G4IStore::G4IStore()
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
70{
71 fGeometryCelli.clear();
72}
73
75{
76 G4cout << " G4IStore:: SetWorldVolume " << G4endl;
79 G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
80 // fGeometryCelli = new G4GeometryCellImportance;
81}
82
84{
85 G4cout << " G4IStore:: SetParallelWorldVolume " << G4endl;
87 ->GetParallelWorld(paraName);
88 G4cout << " ParallelWorld volume is: " << fWorldVolume->GetName() << G4endl;
89 // fGeometryCelli = new G4GeometryCellImportance;
90}
91
93{
94 return *fWorldVolume;
95}
96
98{
99 return fWorldVolume;
100}
101
102void G4IStore::SetInternalIterator(const G4GeometryCell& gCell) const
103{
104 fCurrentIterator = fGeometryCelli.find(gCell);
105}
106
108 const G4GeometryCell& gCell)
109{
110 if (importance < 0 )
111 {
112 Error("AddImportanceGeometryCell() - Invalid importance value given.");
113 }
114 if (!IsInWorld(gCell.GetPhysicalVolume()) )
115 {
116 Error("AddImportanceGeometryCell() - Physical volume not found!");
117 }
118 SetInternalIterator(gCell);
119 if (fCurrentIterator != fGeometryCelli.cend())
120 {
121 Error("AddImportanceGeometryCell() - Region already existing!");
122 }
123 fGeometryCelli[gCell] = importance;
124}
125
127 const G4VPhysicalVolume& aVolume,
128 G4int aRepNum)
129{
130 AddImportanceGeometryCell(importance, G4GeometryCell(aVolume, aRepNum));
131}
132
134 const G4GeometryCell& gCell)
135{
136 if (importance < 0 )
137 {
138 Error("ChangeImportance() - Invalid importance value given.");
139 }
140 if (!IsInWorld(gCell.GetPhysicalVolume()))
141 {
142 Error("ChangeImportance() - Physical volume not found!");
143 }
144 SetInternalIterator(gCell);
145 if (fCurrentIterator == fGeometryCelli.cend())
146 {
147 Error("ChangeImportance() - Region does not exist!");
148 }
149 fGeometryCelli[gCell] = importance;
150
151}
152
154 const G4VPhysicalVolume& aVolume,
155 G4int aRepNum)
156{
157 ChangeImportance(importance, G4GeometryCell(aVolume, aRepNum));
158}
159
161 G4int aRepNum) const
162{
163 G4AutoLock l(&IStoreMutex);
164 SetInternalIterator(G4GeometryCell(aVolume, aRepNum));
165 auto gCellIterator = fCurrentIterator;
166 if (gCellIterator == fGeometryCelli.cend())
167 {
168 Error("GetImportance() - Region does not exist!");
169 return 0.;
170 }
171 G4double importance_value = (*fCurrentIterator).second;
172 l.unlock();
173
174 return importance_value;
175}
176
178{
179 G4AutoLock l(&IStoreMutex);
180 SetInternalIterator(gCell);
181 auto gCellIterator = fCurrentIterator;
182 if (gCellIterator == fGeometryCelli.cend())
183 {
184 std::ostringstream err_mess;
185 err_mess << "GetImportance() - Region does not exist!" << G4endl
186 << "Geometry cell, " << gCell
187 << ", not found in: " << fGeometryCelli << ".";
188 Error(err_mess.str());
189 return 0.;
190 }
191 G4double importance_value = (*fCurrentIterator).second;
192 l.unlock();
193
194 return importance_value;
195}
196
198{
199 G4AutoLock l(&IStoreMutex);
200 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
201
202 if ( inWorldKnown )
203 {
204 SetInternalIterator(gCell);
205 inWorldKnown = (fCurrentIterator != fGeometryCelli.cend());
206 }
207 l.unlock();
208
209 return inWorldKnown;
210}
211
212G4bool G4IStore::IsInWorld(const G4VPhysicalVolume& aVolume) const
213{
214 G4bool isIn(true);
215 if (!(aVolume == *fWorldVolume))
216 {
217 isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
218 }
219 return isIn;
220}
221
222void G4IStore::Error(const G4String& msg) const
223{
224 G4Exception("G4IStore::Error()", "GeomBias0002", FatalException, msg);
225}
226
227// ***************************************************************************
228// Returns the instance of the singleton.
229// Creates it in case it's called for the first time.
230// ***************************************************************************
231//
233{
234 if (fInstance == nullptr)
235 {
236#ifdef G4VERBOSE
237 G4cout << "G4IStore:: Creating new MASS IStore " << G4endl;
238#endif
239 fInstance = new G4IStore();
240 }
241 return fInstance;
242}
243
244// ***************************************************************************
245// Returns the instance of the singleton.
246// Creates it in case it's called for the first time.
247// ***************************************************************************
248//
249G4IStore* G4IStore::GetInstance(const G4String& ParallelWorldName)
250{
251 if (fInstance == nullptr)
252 {
253#ifdef G4VERBOSE
254 G4cout << "G4IStore:: Creating new Parallel IStore "
255 << ParallelWorldName << G4endl;
256#endif
257 fInstance = new G4IStore(ParallelWorldName);
258 }
259 return fInstance;
260}
G4TemplateAutoLock< G4Mutex > G4AutoLock
@ 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
G4GeometryCell is used for scoring and importance sampling. It defines a "cell", which,...
const G4VPhysicalVolume & GetPhysicalVolume() const
G4IStore is a concrete implementation of an "importance store", as derived from G4VIStore....
Definition G4IStore.hh:60
G4double GetImportance(const G4GeometryCell &gCell) const override
Definition G4IStore.cc:177
void AddImportanceGeometryCell(G4double importance, const G4GeometryCell &gCell)
Definition G4IStore.cc:107
const G4VPhysicalVolume & GetWorldVolume() const override
Definition G4IStore.cc:92
G4bool IsKnown(const G4GeometryCell &gCell) const override
Definition G4IStore.cc:197
static G4IStore * GetInstance()
Definition G4IStore.cc:232
void Clear()
Definition G4IStore.cc:69
void ChangeImportance(G4double importance, const G4GeometryCell &gCell)
Definition G4IStore.cc:133
void SetParallelWorldVolume(const G4String &paraName)
Definition G4IStore.cc:83
const G4VPhysicalVolume * GetParallelWorldVolumePointer() const
Definition G4IStore.cc:97
void SetWorldVolume()
Definition G4IStore.cc:74
G4bool IsAncestor(const G4VPhysicalVolume *p) const
G4VPhysicalVolume * GetWorldVolume() const
G4TransportationManager is a singleton class which stores the navigator used by the transportation pr...
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4LogicalVolume * GetLogicalVolume() const
#define G4ThreadLocal
Definition tls.hh:77