Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 //
27 // $Id: G4IStore.cc 105146 2017-07-14 07:58:24Z gcosmo $
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4IStore.cc
33 //
34 // ----------------------------------------------------------------------
35 
36 #include "G4IStore.hh"
37 #include "G4VPhysicalVolume.hh"
38 #include "G4GeometryCell.hh"
40 #include "G4LogicalVolume.hh"
42 
43 #ifdef G4MULTITHREADED
44 G4Mutex G4IStore::IStoreMutex = G4MUTEX_INITIALIZER;
45 #endif
46 
47 // ***************************************************************************
48 // Static class variable: ptr to single instance of class
49 // ***************************************************************************
50 G4ThreadLocal G4IStore* G4IStore::fInstance = 0;
51 
53 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume())
54 {}
55 
56 G4IStore::G4IStore(const G4String& ParallelWorldName) :
57 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetParallelWorld(ParallelWorldName))
58 {
59  G4cout << " G4IStore:: ParallelWorldName = " << ParallelWorldName << G4endl;
60  G4cout << " G4IStore:: fParallelWorldVolume = " << fWorldVolume->GetName() << G4endl;
61 }
62 
64 {}
65 
67 {
68  fGeometryCelli.clear();
69 }
70 
72 {
73  G4cout << " G4IStore:: SetWorldVolume " << G4endl;
75  G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
76  // fGeometryCelli = new G4GeometryCellImportance;
77 }
78 
80 {
81  G4cout << " G4IStore:: SetParallelWorldVolume " << G4endl;
83  G4cout << " ParallelWorld volume is: " << fWorldVolume->GetName() << G4endl;
84  // fGeometryCelli = new G4GeometryCellImportance;
85 }
86 
88 {
89  return *fWorldVolume;
90 }
91 
92 // const G4VPhysicalVolume& G4IStore::GetParallelWorldVolume() const
93 // {
94 // return *fParallelWorldVolume;
95 // }
96 
98 {
99  return fWorldVolume;
100 }
101 
102 void G4IStore::SetInternalIterator(const G4GeometryCell &gCell) const
103 {
104  fCurrentIterator = fGeometryCelli.find(gCell);
105 }
106 
108  const G4GeometryCell &gCell)
109 {
110  if (importance < 0 ) {
111  Error("AddImportanceGeometryCell() - Invalid importance value given.");
112  }
113  if (!IsInWorld(gCell.GetPhysicalVolume()) ) {
114  Error("AddImportanceGeometryCell() - Physical volume not found!");
115  }
116  SetInternalIterator(gCell);
117  if (fCurrentIterator!=fGeometryCelli.end()) {
118  Error("AddImportanceGeometryCell() - Region already existing!");
119  }
120  fGeometryCelli[gCell] = importance;
121 }
122 
124  const G4VPhysicalVolume &aVolume,
125  G4int aRepNum)
126 {
127  AddImportanceGeometryCell(importance,
128  G4GeometryCell(aVolume, aRepNum));
129 }
130 
132  const G4GeometryCell &gCell){
133  if (importance < 0 ) {
134  Error("ChangeImportance() - Invalid importance value given.");
135  }
136  if (!IsInWorld(gCell.GetPhysicalVolume()) ) {
137  Error("ChangeImportance() - Physical volume not found!");
138  }
139  SetInternalIterator(gCell);
140  if (fCurrentIterator==fGeometryCelli.end()) {
141  Error("ChangeImportance() - Region does not exist!");
142  }
143  fGeometryCelli[gCell] = importance;
144 
145 }
147  const G4VPhysicalVolume &aVolume,
148  G4int aRepNum)
149 {
150  ChangeImportance(importance, G4GeometryCell(aVolume, aRepNum));
151 }
152 
154  G4int aRepNum) const
155 {
156 #ifdef G4MULTITHREADED
157  G4MUTEXLOCK(&G4IStore::IStoreMutex);
158 #endif
159  SetInternalIterator(G4GeometryCell(aVolume, aRepNum));
160  G4GeometryCellImportance::const_iterator gCellIterator = fCurrentIterator;
161  if (gCellIterator==fGeometryCelli.end()) {
162  Error("GetImportance() - Region does not exist!");
163  return 0.;
164  }
165  G4double importance_value = (*fCurrentIterator).second;
166 #ifdef G4MULTITHREADED
167  G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
168 #endif
169  return importance_value;
170  // return (*fCurrentIterator).second;
171 }
172 
173 
175 {
176 #ifdef G4MULTITHREADED
177  G4MUTEXLOCK(&G4IStore::IStoreMutex);
178 #endif
179  SetInternalIterator(gCell);
180  G4GeometryCellImportance::const_iterator gCellIterator = fCurrentIterator;
181  if (gCellIterator==fGeometryCelli.end()) {
182  std::ostringstream err_mess;
183  err_mess << "GetImportance() - Region does not exist!" << G4endl
184  << "Geometry cell, " << gCell
185  << ", not found in: " << fGeometryCelli << ".";
186  Error(err_mess.str());
187  return 0.;
188  }
189  G4double importance_value = (*fCurrentIterator).second;
190 #ifdef G4MULTITHREADED
191  G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
192 #endif
193  return importance_value;
194  // return (*fCurrentIterator).second;
195 }
196 
198 #ifdef G4MULTITHREADED
199  G4MUTEXLOCK(&G4IStore::IStoreMutex);
200 #endif
201  G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
202 
203  if ( inWorldKnown ) {
204  SetInternalIterator(gCell);
205  inWorldKnown = (fCurrentIterator!=fGeometryCelli.end());
206  }
207 #ifdef G4MULTITHREADED
208  G4MUTEXUNLOCK(&G4IStore::IStoreMutex);
209 #endif
210  return inWorldKnown;
211 }
212 
213 G4bool G4IStore::IsInWorld(const G4VPhysicalVolume &aVolume) const
214 {
215  G4bool isIn(true);
216  // G4cout << "G4IStore:: aVolume: " << aVolume.GetName() << G4endl;
217  // G4cout << "G4IStore:: fWorld: " << fWorldVolume->GetName() << G4endl;
218  if (!(aVolume == *fWorldVolume)) {
219  isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
220  }
221  return isIn;
222 }
223 
224 
225 
226 void G4IStore::Error(const G4String &msg) const
227 {
228  G4Exception("G4IStore::Error()", "GeomBias0002", FatalException, msg);
229 }
230 
231 // ***************************************************************************
232 // Returns the instance of the singleton.
233 // Creates it in case it's called for the first time.
234 // ***************************************************************************
235 //
237 {
238  if (!fInstance)
239  {
240  G4cout << "G4IStore:: Creating new MASS IStore " << G4endl;
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 //
251 G4IStore* G4IStore::GetInstance(const G4String& ParallelWorldName)
252 {
253  if (!fInstance)
254  {
255  G4cout << "G4IStore:: Creating new Parallel IStore " << ParallelWorldName << G4endl;
256  fInstance = new G4IStore(ParallelWorldName);
257  }
258  return fInstance;
259 }
260 
void SetParallelWorldVolume(G4String paraName)
Definition: G4IStore.cc:79
#define G4MUTEXUNLOCK
Definition: G4Threading.hh:180
~G4IStore()
Definition: G4IStore.cc:63
void ChangeImportance(G4double importance, const G4GeometryCell &gCell)
Definition: G4IStore.cc:131
G4bool IsAncestor(const G4VPhysicalVolume *p) const
void SetWorldVolume()
Definition: G4IStore.cc:71
G4Navigator * GetNavigatorForTracking() const
#define G4ThreadLocal
Definition: tls.hh:89
G4IStore()
Definition: G4IStore.cc:52
int G4int
Definition: G4Types.hh:78
virtual const G4VPhysicalVolume * GetParallelWorldVolumePointer() const
Definition: G4IStore.cc:97
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
virtual G4bool IsKnown(const G4GeometryCell &gCell) const
Definition: G4IStore.cc:197
virtual G4double GetImportance(const G4GeometryCell &gCell) const
Definition: G4IStore.cc:174
bool G4bool
Definition: G4Types.hh:79
virtual const G4VPhysicalVolume & GetWorldVolume() const
Definition: G4IStore.cc:87
void AddImportanceGeometryCell(G4double importance, const G4GeometryCell &gCell)
Definition: G4IStore.cc:107
#define G4MUTEXLOCK
Definition: G4Threading.hh:179
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
const G4VPhysicalVolume & GetPhysicalVolume() const
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
G4int G4Mutex
Definition: G4Threading.hh:173
static G4IStore * GetInstance()
Definition: G4IStore.cc:236
G4LogicalVolume * GetLogicalVolume() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void Clear()
Definition: G4IStore.cc:66
G4VPhysicalVolume * GetWorldVolume() const