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