ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4IStore.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4IStore.cc
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
40 G4Mutex G4IStore::IStoreMutex = G4MUTEX_INITIALIZER;
41 #endif
42 
43 // ***************************************************************************
44 // Static class variable: ptr to single instance of class
45 // ***************************************************************************
47 
49  : fWorldVolume(G4TransportationManager::GetTransportationManager()
50  ->GetNavigatorForTracking()->GetWorldVolume())
51 {
52 }
53 
54 G4IStore::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 
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 
224 {
225  G4bool isIn(true);
226  if (!(aVolume == *fWorldVolume))
227  {
228  isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
229  }
230  return isIn;
231 }
232 
233 void 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 //
260 G4IStore* 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 }