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