Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GeometryWorkspace Class Reference

#include <G4GeometryWorkspace.hh>

Public Types

using pool_type = G4TWorkspacePool< G4GeometryWorkspace >
 

Public Member Functions

 G4GeometryWorkspace ()
 
 ~G4GeometryWorkspace ()
 
void UseWorkspace ()
 
void ReleaseWorkspace ()
 
void DestroyWorkspace ()
 
void InitialiseWorkspace ()
 
void SetVerbose (G4bool v)
 
G4bool GetVerbose ()
 

Static Public Member Functions

static pool_typeGetPool ()
 

Protected Member Functions

void InitialisePhysicalVolumes ()
 
G4bool CloneParameterisedSolids (G4PVParameterised *paramVol)
 
G4bool CloneReplicaSolid (G4PVReplica *)
 

Detailed Description

Definition at line 58 of file G4GeometryWorkspace.hh.

Member Typedef Documentation

◆ pool_type

Constructor & Destructor Documentation

◆ G4GeometryWorkspace()

G4GeometryWorkspace::G4GeometryWorkspace ( )

Definition at line 60 of file G4GeometryWorkspace.cc.

61{
62 fpLogicalVolumeSIM=
64 fpPhysicalVolumeSIM=
66 fpReplicaSIM=
68 fpRegionSIM=
70
71 // Create a work area for Logical Volumes in this thread
72 // then capture its address
74
75 fLogicalVolumeOffset = fpLogicalVolumeSIM->GetOffset();
76
77 fPhysicalVolumeOffset = fpPhysicalVolumeSIM->GetOffset();
78
79 fReplicaOffset = fpReplicaSIM->GetOffset();
80
81 fRegionOffset = fpRegionSIM->GetOffset();
82}
static const G4LVManager & GetSubInstanceManager()
static const G4PVRManager & GetSubInstanceManager()
Definition: G4PVReplica.cc:327
static const G4RegionManager & GetSubInstanceManager()
Definition: G4Region.cc:55
static const G4PVManager & GetSubInstanceManager()

◆ ~G4GeometryWorkspace()

G4GeometryWorkspace::~G4GeometryWorkspace ( )

Definition at line 86 of file G4GeometryWorkspace.cc.

87{
88}

Member Function Documentation

◆ CloneParameterisedSolids()

G4bool G4GeometryWorkspace::CloneParameterisedSolids ( G4PVParameterised paramVol)
protected

Definition at line 231 of file G4GeometryWorkspace.cc.

233{
234 // Check whether it is a simple parameterisation or not
235 //
236 // G4VPVParameterisation *param= paramVol->GetParameterisation();
237 // unsigned int numCopies= paramVol->GetMultiplicity();
238 // unsigned int numDifferent= 0;
239
240 G4LogicalVolume* logicalV= paramVol->GetLogicalVolume();
241 G4VSolid* solid= logicalV->GetSolid();
242
243 // for( unsigned int i=0; i< numCopies; ++i)
244 // {
245 // G4VSolid *solidChk= param->ComputeSolid(i, paramVol);
246 // if( solidChk != solid)
247 // {
248 // ++numDifferent;
249 // }
250 // }
251 // if( numDifferent>0 )
252 // {
253 // G4ExceptionDescription ed;
254 // ed << "ERROR - Parameterisation using several instances of Solids \n"
255 // << "potentially to support different types of solids. \n"
256 // << "Geant4-MT currently does not support this type of \n"
257 // << "parameterisation, sorry !";
258 // G4Exception("G4GeometryWorkspace::CloneParameterisedVolume()",
259 // "GeomVol0001", FatalException, ed);
260 // }
261
262 // Threads may attempt to clone a solids simultaneously.
263 // Those cloned solids will be registered into a shared solid
264 // store (C++ container). Need a lock to guarantee thread safety
265 //
266 G4AutoLock aLock(&solidclone);
267 G4VSolid *workerSolid = solid->Clone();
268 aLock.unlock();
269 if( workerSolid != nullptr )
270 {
271 logicalV->InitialiseWorker(logicalV,workerSolid,0);
272 }
273 else
274 {
275 // In the case that not all solids support(ed) the Clone()
276 // method, we do similar thing here to dynamically cast
277 // and then get the clone method
278 //
280 ed << "ERROR - Unable to initialise geometry for worker node. \n"
281 << "A solid lacks the Clone() method - or Clone() failed. \n"
282 << " Type of solid: " << solid->GetEntityType() << "\n"
283 << " Parameters: " << *solid;
284 G4Exception("G4GeometryWorkspace::CloneParameterisedVolume()",
285 "GeomVol0003", FatalException, ed);
286 }
287 return true; // It Worked
288}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4VSolid * GetSolid() const
void InitialiseWorker(G4LogicalVolume *ptrMasterObject, G4VSolid *pSolid, G4VSensitiveDetector *pSDetector)
G4LogicalVolume * GetLogicalVolume() const
virtual G4VSolid * Clone() const
Definition: G4VSolid.cc:379
virtual G4GeometryType GetEntityType() const =0

Referenced by InitialisePhysicalVolumes().

◆ CloneReplicaSolid()

G4bool G4GeometryWorkspace::CloneReplicaSolid ( G4PVReplica replicaPV)
protected

Definition at line 189 of file G4GeometryWorkspace.cc.

190{
191 // The solid Ptr is in the Logical Volume
192 //
193 G4LogicalVolume* logicalV = replicaPV->GetLogicalVolume();
194 G4VSolid* solid = logicalV->GetSolid();
195
196 G4AutoLock aLock(&solidclone);
197 G4VSolid* workerSolid = solid->Clone();
198 aLock.unlock();
199
200 if( workerSolid != nullptr )
201 {
202 logicalV->InitialiseWorker(logicalV,workerSolid,0);
203 }
204 else
205 {
206 // In the case that not all solids support(ed) the Clone()
207 // method, we do similar thing here to dynamically cast
208 // and then get the clone method.
209 //
211 ed << "ERROR - Unable to initialise geometry for worker node." << "\n"
212 << "A solid lacks the Clone() method - or Clone() failed." << "\n"
213 << " Type of solid: " << solid->GetEntityType() << "\n"
214 << " Parameters: " << *solid;
215 G4Exception("G4GeometryWorkspace::CloneParameterisedVolume()",
216 "GeomVol0003", FatalException, ed);
217 return false;
218 }
219 return true; // It Worked
220}

Referenced by InitialisePhysicalVolumes().

◆ DestroyWorkspace()

void G4GeometryWorkspace::DestroyWorkspace ( )

Definition at line 323 of file G4GeometryWorkspace.cc.

324{
326 for (size_t ip=0; ip<physVolStore->size(); ++ip)
327 {
328 G4VPhysicalVolume* physVol = (*physVolStore)[ip];
329 G4LogicalVolume* logicalVol = physVol->GetLogicalVolume();
330 G4PVReplica* g4PVReplica = nullptr;
331 g4PVReplica = dynamic_cast<G4PVReplica*>(physVol);
332 if (g4PVReplica != nullptr)
333 {
334 g4PVReplica->TerminateWorker(g4PVReplica);
335 G4PVParameterised* paramVol = nullptr;
336 paramVol = dynamic_cast<G4PVParameterised*>(physVol);
337 if (paramVol != nullptr)
338 {
339 // G4VSolid* solid = logicalVol->fSolid;
340 logicalVol->TerminateWorker(logicalVol);
341 // if( solid->IsClone() ) delete solid;
342 }
343 else
344 {
345 logicalVol->TerminateWorker(logicalVol);
346 }
347 }
348 else
349 {
350 logicalVol->TerminateWorker(logicalVol);
351 }
352 }
353 fpLogicalVolumeSIM->FreeSlave();
354 fpPhysicalVolumeSIM->FreeSlave();
355 fpReplicaSIM->FreeSlave();
356 fpRegionSIM->FreeSlave();
357}
void TerminateWorker(G4LogicalVolume *ptrMasterObject)
void TerminateWorker(G4PVReplica *pMasterObject)
Definition: G4PVReplica.cc:383
static G4PhysicalVolumeStore * GetInstance()

Referenced by G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster().

◆ GetPool()

◆ GetVerbose()

G4bool G4GeometryWorkspace::GetVerbose ( )
inline

Definition at line 75 of file G4GeometryWorkspace.hh.

75{ return fVerbose; }

◆ InitialisePhysicalVolumes()

void G4GeometryWorkspace::InitialisePhysicalVolumes ( )
protected

Definition at line 136 of file G4GeometryWorkspace.cc.

137{
139 for (size_t ip=0; ip<physVolStore->size(); ++ip)
140 {
141 G4VPhysicalVolume* physVol = (*physVolStore)[ip];
142 G4LogicalVolume *logicalVol = physVol->GetLogicalVolume();
143
144 // Use shadow pointer
145 //
146 G4VSolid* solid = logicalVol->GetMasterSolid();
147 G4PVReplica* g4PVReplica = nullptr;
148 g4PVReplica = dynamic_cast<G4PVReplica*>(physVol);
149 if (g4PVReplica == nullptr)
150 {
151 // Placement volume
152 logicalVol->InitialiseWorker(logicalVol,solid,0);
153 }
154 else
155 {
156 g4PVReplica->InitialiseWorker(g4PVReplica);
157 if( !g4PVReplica->IsParameterised() )
158 {
159 logicalVol->InitialiseWorker(logicalVol,solid,0);
160
161 // If the replica's solid (in LV) is changed during navigation,
162 // it must be thread-private
163 //
164 CloneReplicaSolid( g4PVReplica );
165 }
166 else
167 {
168 G4PVParameterised *paramVol = dynamic_cast<G4PVParameterised*>(physVol);
169 if (paramVol == nullptr)
170 {
171 G4Exception("G4GeometryWorkspace::CreateAndUseWorkspace()",
172 "GeomVol0003", FatalException,
173 "Cannot find Parameterisation for parameterised volume.");
174 }
175 CloneParameterisedSolids( paramVol );
176 }
177 }
178 }
179 if( fVerbose )
180 {
181 G4cout << "G4GeometryWorkspace::InitialisePhysicalVolumes: "
182 << "Copying geometry - Done!" << G4endl;
183 }
184}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool CloneReplicaSolid(G4PVReplica *)
G4bool CloneParameterisedSolids(G4PVParameterised *paramVol)
G4VSolid * GetMasterSolid() const
virtual G4bool IsParameterised() const
Definition: G4PVReplica.cc:277
void InitialiseWorker(G4PVReplica *pMasterObject)
Definition: G4PVReplica.cc:338

Referenced by InitialiseWorkspace().

◆ InitialiseWorkspace()

void G4GeometryWorkspace::InitialiseWorkspace ( )

Definition at line 292 of file G4GeometryWorkspace.cc.

293{
294 if( fVerbose )
295 {
296 G4cout << "G4GeometryWorkspace::InitialiseWorkspace():"
297 << " Copying geometry - Start " << G4endl;
298 }
299
300 // Implementation originally in:
301 // G4WorkerThread::BuildGeometryAndPhysicsVector()
302 // and improved for G4PVParamaterised
303
304 // Geometry related, split classes mechanism:
305 // Do *NOT* instantiate sub-instance for this thread, just copy the contents!
306 //
307 fpLogicalVolumeSIM->SlaveCopySubInstanceArray();
308 fpPhysicalVolumeSIM->SlaveCopySubInstanceArray();
309 fpReplicaSIM->SlaveCopySubInstanceArray();
310 fpRegionSIM->SlaveInitializeSubInstance();
311
313
314 if( fVerbose )
315 {
316 G4cout << "G4GeometryWorkspace::InitialiseWorkspace: "
317 << "Copying geometry - Done!" << G4endl;
318 }
319}
void SlaveInitializeSubInstance()
void SlaveCopySubInstanceArray()

Referenced by G4GeometryWorkspace(), and G4WorkerThread::UpdateGeometryAndPhysicsVectorFromMaster().

◆ ReleaseWorkspace()

void G4GeometryWorkspace::ReleaseWorkspace ( )

Definition at line 125 of file G4GeometryWorkspace.cc.

126{
127 fpLogicalVolumeSIM->UseWorkArea(0);
128 fpPhysicalVolumeSIM->UseWorkArea(0);
129
130 fpReplicaSIM->UseWorkArea(0);
131 fpRegionSIM->UseWorkArea(0);
132}
void UseWorkArea(T *newOffset)

◆ SetVerbose()

void G4GeometryWorkspace::SetVerbose ( G4bool  v)
inline

Definition at line 74 of file G4GeometryWorkspace.hh.

74{ fVerbose = v; }

◆ UseWorkspace()

void G4GeometryWorkspace::UseWorkspace ( )

Definition at line 93 of file G4GeometryWorkspace.cc.

94{
95 if( fVerbose )
96 {
97 G4cout << "G4GeometryWorkspace::UseWorkspace: Start " << G4endl;
98 }
99
100 // Implementation originally in:
101 // G4WorkerThread::BuildGeometryAndPhysicsVector()
102 // and improved for G4PVParamaterised
103
104 // Geometry related, split classes mechanism: instantiate sub-instance
105 // for this thread
106 fpLogicalVolumeSIM->UseWorkArea(fLogicalVolumeOffset);
107 fpPhysicalVolumeSIM->UseWorkArea(fPhysicalVolumeOffset);
108
109 fpReplicaSIM->UseWorkArea(fReplicaOffset);
110 fpRegionSIM->UseWorkArea(fRegionOffset);
111
112 // When recycling a workspace
113 // - it must be a lightweight operation, to reuse a valid work area
114 // - so it must NOT Initialise anything!
115 // Do not call InitialisePhysicalVolumes();
116
117 if( fVerbose )
118 {
119 G4cout << "G4GeometryWorkspace::UseWorkspace: End " << G4endl;
120 }
121}

The documentation for this class was generated from the following files: