Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions
G4GeometryWorkspace Class Reference

#include <G4GeometryWorkspace.hh>

Public Member Functions

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

Protected Member Functions

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

Detailed Description

Definition at line 57 of file G4GeometryWorkspace.hh.

Constructor & Destructor Documentation

G4GeometryWorkspace::G4GeometryWorkspace ( )

Definition at line 43 of file G4GeometryWorkspace.cc.

References G4GeomSplitter< T >::GetOffset(), G4PVReplica::GetSubInstanceManager(), G4VPhysicalVolume::GetSubInstanceManager(), G4Region::GetSubInstanceManager(), G4LogicalVolume::GetSubInstanceManager(), and InitialiseWorkspace().

44  : fVerbose(false)
45 {
46  fpLogicalVolumeSIM=
48  fpPhysicalVolumeSIM=
50  fpReplicaSIM=
52  fpRegionSIM=
54 
55  // Create a work area for Logical Volumes in this thread - then capture its address
57 
58  fLogicalVolumeOffset= fpLogicalVolumeSIM->GetOffset();
59 
60  fPhysicalVolumeOffset= fpPhysicalVolumeSIM->GetOffset();
61 
62  fReplicaOffset= fpReplicaSIM->GetOffset();
63 
64  fRegionOffset= fpRegionSIM->GetOffset();
65 }
static const G4LVManager & GetSubInstanceManager()
static const G4PVRManager & GetSubInstanceManager()
Definition: G4PVReplica.cc:275
static const G4PVManager & GetSubInstanceManager()
static const G4RegionManager & GetSubInstanceManager()
Definition: G4Region.cc:58
G4GeometryWorkspace::~G4GeometryWorkspace ( )

Definition at line 67 of file G4GeometryWorkspace.cc.

68 {
69 
70 }

Member Function Documentation

G4bool G4GeometryWorkspace::CloneParameterisedSolids ( G4PVParameterised paramVol)
protected

Definition at line 194 of file G4GeometryWorkspace.cc.

References G4VSolid::Clone(), G4VPVParameterisation::ComputeSolid(), FatalException, G4endl, G4Exception(), G4VSolid::GetEntityType(), G4VPhysicalVolume::GetLogicalVolume(), G4PVReplica::GetMultiplicity(), G4PVParameterised::GetParameterisation(), G4LogicalVolume::GetSolid(), G4LogicalVolume::InitialiseWorker(), and G4TemplateAutoLock< M, L, U >::unlock().

Referenced by InitialisePhysicalVolumes().

195 {
196  // Each G4PVParameterised instance, has associated with it at least one
197  // solid for each worker thread.
198  // *Simple* Parameterisations have a single type of solid, and the
199  // pointer points to the same instance of a solid during the simulation.
200  // For this case, it is possible to adapt automatically to
201  // multi-threading, simply by cloning the solid - so long
202  // as all solids support the Clone() method.
203 
204  // Check whether it is a simple parameterisation or not
205  G4VPVParameterisation *param= paramVol->GetParameterisation();
206  unsigned int numCopies= paramVol->GetMultiplicity();
207  unsigned int numDifferent= 0;
208 
209  G4LogicalVolume *logicalV= paramVol->GetLogicalVolume();
210  // assert( logicalV != 0);
211  G4VSolid *solid= logicalV->GetSolid();
212 
213  for( unsigned int i=0; i< numCopies; i++)
214  {
215  G4VSolid *solidChk= param->ComputeSolid(i, paramVol);
216  if( solidChk != solid)
217  {
218  numDifferent++;
219  }
220  }
221  if( numDifferent>0 )
222  {
224 
225  ed << " Parameterisation is implemented using several instances of Solids "
226  << " - potentially to support different types of solids. " << G4endl;
227  ed << " The current implementation of Geant4-MT does not support "
228  << " this type of Parameterisation" << G4endl;
229  G4Exception("G4GeometryWorkspace::CloneParameterisedVolume", "GeometryNotSupportedInMT-01",
230  FatalException, ed);
231  }
232 
233  // Threads may attempt to clone a solids simultaneously. Those cloned solids will be
234  // registered into a shared solid store (C++ container). Need a lock to
235  // guarantee thread safety
236  G4AutoLock aLock(&solidclone);
237  G4VSolid *workerSolid = solid->Clone();
238  aLock.unlock();
239  if( workerSolid )
240  {
241  logicalV->InitialiseWorker(logicalV,workerSolid,0);
242  }else{
243  // In the case that not all solids support(ed) the Clone()
244  // method, we do similar thing here to dynamically cast
245  // and then get the clone method.
247  ed << " ERROR: Unable to initialise geometry for worker node." << G4endl;
248  ed << " A solid lacks the Clone() method - or Clone() failed." << G4endl;
249  ed << " Type of solid: " << solid->GetEntityType() << G4endl;
250  ed << " Parameters: " << *solid << G4endl;
251  G4Exception(" G4GeometryWorkspace::CloneParameterisedVolume", "MT-BuildGeometry001",
252  FatalException, ed);
253  }
254  return true; // It Worked
255 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
virtual G4VSolid * ComputeSolid(const G4int, G4VPhysicalVolume *)
virtual G4GeometryType GetEntityType() const =0
void InitialiseWorker(G4LogicalVolume *ptrMasterObject, G4VSolid *pSolid, G4VSensitiveDetector *pSDetector)
G4VPVParameterisation * GetParameterisation() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4LogicalVolume * GetLogicalVolume() const
virtual G4int GetMultiplicity() const
Definition: G4PVReplica.cc:229
#define G4endl
Definition: G4ios.hh:61
virtual G4VSolid * Clone() const
Definition: G4VSolid.cc:324
G4VSolid * GetSolid() const
G4bool G4GeometryWorkspace::CloneReplicaSolid ( G4PVReplica replicaPV)
protected

Definition at line 161 of file G4GeometryWorkspace.cc.

References G4VSolid::Clone(), FatalException, G4endl, G4Exception(), G4VSolid::GetEntityType(), G4VPhysicalVolume::GetLogicalVolume(), G4LogicalVolume::GetSolid(), G4LogicalVolume::InitialiseWorker(), and G4TemplateAutoLock< M, L, U >::unlock().

Referenced by InitialisePhysicalVolumes().

162 {
163  // Create a clone of the solid for this replica in this thread
164 
165  // Check that it is not a parameterisation ?
166 
167  // The solid Ptr is in the Logical Volume
168  G4LogicalVolume *logicalV= replicaPV ->GetLogicalVolume();
169  G4VSolid *solid= logicalV->GetSolid();
170 
171  G4AutoLock aLock(&solidclone);
172  G4VSolid *workerSolid = solid->Clone();
173  aLock.unlock();
174 
175  if( workerSolid )
176  {
177  logicalV->InitialiseWorker(logicalV,workerSolid,0);
178  }else{
179  // In the case that not all solids support(ed) the Clone()
180  // method, we do similar thing here to dynamically cast
181  // and then get the clone method.
183  ed << " ERROR: Unable to initialise geometry for worker node." << G4endl;
184  ed << " A solid lacks the Clone() method - or Clone() failed." << G4endl;
185  ed << " Type of solid: " << solid->GetEntityType() << G4endl;
186  ed << " Parameters: " << *solid << G4endl;
187  G4Exception(" G4GeometryWorkspace::CloneParameterisedVolume", "MT-BuildGeometry001",
188  FatalException, ed);
189  return false;
190  }
191  return true; // It Worked
192 }
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
virtual G4GeometryType GetEntityType() const =0
void InitialiseWorker(G4LogicalVolume *ptrMasterObject, G4VSolid *pSolid, G4VSensitiveDetector *pSDetector)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4LogicalVolume * GetLogicalVolume() const
#define G4endl
Definition: G4ios.hh:61
virtual G4VSolid * Clone() const
Definition: G4VSolid.cc:324
G4VSolid * GetSolid() const
void G4GeometryWorkspace::DestroyWorkspace ( )

Definition at line 283 of file G4GeometryWorkspace.cc.

References G4GeomSplitter< T >::FreeSlave(), G4PhysicalVolumeStore::GetInstance(), G4VPhysicalVolume::GetLogicalVolume(), G4PVReplica::TerminateWorker(), and G4LogicalVolume::TerminateWorker().

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

284 {
286  for (size_t ip=0; ip<physVolStore->size(); ip++)
287  {
288  G4VPhysicalVolume* physVol = (*physVolStore)[ip];
289  G4LogicalVolume *logicalVol = physVol->GetLogicalVolume();
290  G4PVReplica *g4PVReplica = 0;
291  g4PVReplica = dynamic_cast<G4PVReplica*>(physVol);
292  if (g4PVReplica)
293  {
294  g4PVReplica->TerminateWorker(g4PVReplica);
295  G4PVParameterised *paramVol = 0;
296  paramVol = dynamic_cast<G4PVParameterised*>(physVol);
297  if (paramVol)
298  {
299  // G4VSolid *solid = logicalVol->fSolid;
300  logicalVol->TerminateWorker(logicalVol);
301  // if( solid->IsClone() ) delete solid;
302  }
303  else
304  {
305  logicalVol->TerminateWorker(logicalVol);
306  }
307  }
308  else
309  {
310  logicalVol->TerminateWorker(logicalVol);
311  }
312  }
313 
314  fpLogicalVolumeSIM->FreeSlave();
315  fpPhysicalVolumeSIM->FreeSlave();
316  fpReplicaSIM->FreeSlave();
317  fpRegionSIM->FreeSlave();
318 }
void TerminateWorker(G4PVReplica *pMasterObject)
Definition: G4PVReplica.cc:300
static G4PhysicalVolumeStore * GetInstance()
void TerminateWorker(G4LogicalVolume *ptrMasterObject)
G4LogicalVolume * GetLogicalVolume() const
G4bool G4GeometryWorkspace::GetVerbose ( )
inline

Definition at line 71 of file G4GeometryWorkspace.hh.

71 { return fVerbose; }
void G4GeometryWorkspace::InitialisePhysicalVolumes ( )
protected

Definition at line 115 of file G4GeometryWorkspace.cc.

References CloneParameterisedSolids(), CloneReplicaSolid(), FatalException, G4cout, G4endl, G4Exception(), G4PhysicalVolumeStore::GetInstance(), G4VPhysicalVolume::GetLogicalVolume(), G4LogicalVolume::GetMasterSolid(), G4PVReplica::InitialiseWorker(), G4LogicalVolume::InitialiseWorker(), and G4PVReplica::IsParameterised().

Referenced by InitialiseWorkspace().

116  {
118  for (size_t ip=0; ip<physVolStore->size(); ip++)
119  {
120  G4VPhysicalVolume* physVol = (*physVolStore)[ip];
121  G4LogicalVolume *logicalVol = physVol->GetLogicalVolume();
122  //use shadow pointer
123  G4VSolid *solid = logicalVol->GetMasterSolid();
124  G4PVReplica *g4PVReplica = 0;
125  g4PVReplica = dynamic_cast<G4PVReplica*>(physVol);
126  if (!g4PVReplica)
127  {
128  // Placement volume
129  logicalVol->InitialiseWorker(logicalVol,solid,0);
130  }
131  else
132  {
133  //g4PVReplica->SlaveG4PVReplica(g4PVReplica);
134  g4PVReplica->InitialiseWorker(g4PVReplica);
135  if( ! g4PVReplica->IsParameterised() )
136  {
137  logicalVol->InitialiseWorker(logicalVol,solid,0);
138  // If the replica's solid (in LV) is changed during navigation, it must be thread-private
139  CloneReplicaSolid( g4PVReplica );
140  }
141  else
142  {
143  G4PVParameterised *paramVol
144  = dynamic_cast<G4PVParameterised*>(physVol);
145  if (!paramVol)
146  {
147  G4Exception("G4GeometryWorkspace::CreateAndUseWorkspace", "Runtime Error PV01",
149  "Cannot find Parameterisation for G4PVParameterised object.");
150  }
151  CloneParameterisedSolids( paramVol );
152  }
153  }
154  }
155  if( fVerbose )
156  G4cout << "G4GeometryWorkspace::InitialisePhysicalVolumes: "
157  << "Copying geometry - Done!" << G4endl;
158 }
G4VSolid * GetMasterSolid() const
void InitialiseWorker(G4LogicalVolume *ptrMasterObject, G4VSolid *pSolid, G4VSensitiveDetector *pSDetector)
static G4PhysicalVolumeStore * GetInstance()
virtual G4bool IsParameterised() const
Definition: G4PVReplica.cc:219
G4GLOB_DLL std::ostream G4cout
void InitialiseWorker(G4PVReplica *pMasterObject)
Definition: G4PVReplica.cc:287
G4bool CloneReplicaSolid(G4PVReplica *)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4LogicalVolume * GetLogicalVolume() const
G4bool CloneParameterisedSolids(G4PVParameterised *paramVol)
#define G4endl
Definition: G4ios.hh:61
void G4GeometryWorkspace::InitialiseWorkspace ( )

Definition at line 259 of file G4GeometryWorkspace.cc.

References G4cout, G4endl, InitialisePhysicalVolumes(), G4GeomSplitter< T >::SlaveCopySubInstanceArray(), and G4GeomSplitter< T >::SlaveInitializeSubInstance().

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

260 {
261  if( fVerbose )
262  G4cout << "G4GeometryWorkspace::InitialiseWorkspace: Copying geometry - Start " << G4endl;
263 
264  // Implementation copied from G4WorkerThread::BuildGeometryAndPhysicsVector()
265  // and improved for G4PVParamaterised
266  // John Apostolakis, May 30, 2013
267 
268  //Geometry related, split classes mechanism:
269  // Do *NOT* instantiate sub-instance for this thread,
270  // just copy the contents !!
271  fpLogicalVolumeSIM->SlaveCopySubInstanceArray();
272  fpPhysicalVolumeSIM->SlaveCopySubInstanceArray();
273  fpReplicaSIM->SlaveCopySubInstanceArray();
274  fpRegionSIM->SlaveInitializeSubInstance();
275 
277 
278  if( fVerbose )
279  G4cout << "G4GeometryWorkspace::InitialiseWorkspace: "
280  << "Copying geometry - Done!" << G4endl;
281 }
G4GLOB_DLL std::ostream G4cout
void SlaveCopySubInstanceArray()
#define G4endl
Definition: G4ios.hh:61
void SlaveInitializeSubInstance()
void G4GeometryWorkspace::ReleaseWorkspace ( )

Definition at line 102 of file G4GeometryWorkspace.cc.

References G4GeomSplitter< T >::UseWorkArea().

Referenced by G4GeometryWorkspacePool::Recycle().

104 {
105  fpLogicalVolumeSIM->UseWorkArea(0);
106  fpPhysicalVolumeSIM->UseWorkArea(0);
107 
108  fpReplicaSIM->UseWorkArea(0);
109  fpRegionSIM->UseWorkArea(0);
110 }
void UseWorkArea(T *newOffset)
void G4GeometryWorkspace::SetVerbose ( G4bool  v)
inline

Definition at line 70 of file G4GeometryWorkspace.hh.

References test::v.

70 { fVerbose=v; }
void G4GeometryWorkspace::UseWorkspace ( )

Definition at line 76 of file G4GeometryWorkspace.cc.

References G4cout, G4endl, and G4GeomSplitter< T >::UseWorkArea().

Referenced by G4GeometryWorkspacePool::FindOrCreateWorkspace().

77 {
78  if( fVerbose )
79  G4cout << "G4GeometryWorkspace::UseWorkspace: Start " << G4endl;
80 
81  // Implementation copied from G4WorkerThread::BuildGeometryAndPhysicsVector()
82  // and improved for G4PVParamaterised
83  // John Apostolakis, May 30, 2013
84 
85  //Geometry related, split classes mechanism: instantiate sub-instance for this thread
86  fpLogicalVolumeSIM->UseWorkArea(fLogicalVolumeOffset);
87  fpPhysicalVolumeSIM->UseWorkArea(fPhysicalVolumeOffset);
88 
89  fpReplicaSIM->UseWorkArea(fReplicaOffset);
90  fpRegionSIM->UseWorkArea(fRegionOffset);
91 
92  // When recycling a workspace
93  // - it must be a lightweight operation, to reuse a valid work area
94  // - so it must NOT Initialise anything!
95  // Do not call InitialisePhysicalVolumes();
96 
97  if( fVerbose )
98  G4cout << "G4GeometryWorkspace::UseWorkspace: End " << G4endl;
99 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void UseWorkArea(T *newOffset)

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