Geant4_10
G4PVReplica.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: G4PVReplica.cc 73250 2013-08-22 13:22:23Z gcosmo $
28 //
29 //
30 // class G4PVReplica Implementation
31 //
32 // ----------------------------------------------------------------------
33 
34 #include "G4PVReplica.hh"
35 #include "G4LogicalVolume.hh"
36 
37 // This static member is thread local. For each thread, it points to the
38 // array of G4ReplicaData instances.
39 //
40 template <class G4ReplicaData> G4ThreadLocal
42 G4PVRManager G4PVReplica::subInstanceManager;
43 // This new field helps to use the class G4PVRManager.
44 
46  G4LogicalVolume* pLogical,
47  G4VPhysicalVolume* pMother,
48  const EAxis pAxis,
49  const G4int nReplicas,
50  const G4double width,
51  const G4double offset )
52  : G4VPhysicalVolume(0, G4ThreeVector(), pName, pLogical, pMother), fRegularVolsId(0)
53 {
54 
55  instanceID = subInstanceManager.CreateSubInstance();
56 
57  G4MT_copyNo = -1;
58 
59  if ((!pMother) || (!pMother->GetLogicalVolume()))
60  {
61  std::ostringstream message;
62  message << "NULL pointer specified as mother volume." << G4endl
63  << "The world volume cannot be sliced or parameterised !";
64  G4Exception("G4PVReplica::G4PVReplica()", "GeomVol0002",
65  FatalException, message);
66  return;
67  }
68  G4LogicalVolume* motherLogical = pMother->GetLogicalVolume();
69  if (pLogical == motherLogical)
70  {
71  G4Exception("G4PVReplica::G4PVReplica()", "GeomVol0002",
72  FatalException, "Cannot place a volume inside itself!");
73  return;
74  }
75  SetMotherLogical(motherLogical);
76  motherLogical->AddDaughter(this);
77  if (motherLogical->GetNoDaughters() != 1)
78  {
79  std::ostringstream message;
80  message << "Replica or parameterised volume must be the only daughter !"
81  << G4endl
82  << " Mother physical volume: " << pMother->GetName() << G4endl
83  << " Replicated volume: " << pName;
84  G4Exception("G4PVReplica::G4PVReplica()", "GeomVol0002",
85  FatalException, message);
86  return;
87  }
88  CheckAndSetParameters (pAxis, nReplicas, width, offset);
89 }
90 
92  G4LogicalVolume* pLogical,
93  G4LogicalVolume* pMotherLogical,
94  const EAxis pAxis,
95  const G4int nReplicas,
96  const G4double width,
97  const G4double offset )
98  : G4VPhysicalVolume(0,G4ThreeVector(),pName,pLogical,0), fRegularVolsId(0)
99 {
100 
101  instanceID = subInstanceManager.CreateSubInstance();
102  G4MT_copyNo = -1;
103 
104  if (!pMotherLogical)
105  {
106  std::ostringstream message;
107  message << "NULL pointer specified as mother volume for "
108  << pName << ".";
109  G4Exception("G4PVReplica::G4PVReplica()", "GeomVol0002",
110  FatalException, message);
111  return;
112  }
113  if (pLogical == pMotherLogical)
114  {
115  G4Exception("G4PVReplica::G4PVReplica()", "GeomVol0002",
116  FatalException, "Cannot place a volume inside itself!");
117  return;
118  }
119  pMotherLogical->AddDaughter(this);
120  SetMotherLogical(pMotherLogical);
121  if (pMotherLogical->GetNoDaughters() != 1)
122  {
123  std::ostringstream message;
124  message << "Replica or parameterised volume must be the only daughter !"
125  << G4endl
126  << " Mother logical volume: " << pMotherLogical->GetName()
127  << G4endl
128  << " Replicated volume: " << pName;
129  G4Exception("G4PVReplica::G4PVReplica()", "GeomVol0002",
130  FatalException, message);
131  return;
132  }
133  CheckAndSetParameters (pAxis, nReplicas, width, offset);
134 }
135 
136 void G4PVReplica::CheckAndSetParameters( const EAxis pAxis,
137  const G4int nReplicas,
138  const G4double width,
139  const G4double offset)
140 {
141  if (nReplicas<1)
142  {
143  G4Exception("G4PVReplica::CheckAndSetParameters()", "GeomVol0002",
144  FatalException, "Illegal number of replicas.");
145  }
146  fnReplicas=nReplicas;
147  if (width<0)
148  {
149  G4Exception("G4PVReplica::CheckAndSetParameters()", "GeomVol0002",
150  FatalException, "Width must be positive.");
151  }
152  fwidth = width;
153  foffset = offset;
154  faxis = pAxis;
155 
156  // Create rotation matrix for phi axis case & check axis is valid
157  //
158  G4RotationMatrix* pRMat=0;
159  switch (faxis)
160  {
161  case kPhi:
162  pRMat=new G4RotationMatrix();
163  if (!pRMat)
164  {
165  G4Exception("G4PVReplica::CheckAndSetParameters()", "GeomVol0003",
166  FatalException, "Rotation matrix allocation failed.");
167  }
168  SetRotation(pRMat);
169  break;
170  case kRho:
171  case kXAxis:
172  case kYAxis:
173  case kZAxis:
174  case kUndefined:
175  break;
176  default:
177  G4Exception("G4PVReplica::CheckAndSetParameters()", "GeomVol0002",
178  FatalException, "Unknown axis of replication.");
179  break;
180  }
181 }
182 
184  : G4VPhysicalVolume(a), faxis(kZAxis), fnReplicas(0), fwidth(0.),
185  foffset(0.), fRegularStructureCode(0), fRegularVolsId(0)
186 {
187  instanceID = subInstanceManager.CreateSubInstance();
188  G4MT_copyNo = -1;
189 }
190 
192 {
193  if ( faxis==kPhi )
194  {
195  delete GetRotation();
196  }
197 }
198 
200 {
201  return false;
202 }
203 
205 {
206  return G4MT_copyNo;
207 }
208 
210 {
211  G4MT_copyNo = newCopyNo;
212 }
213 
215 {
216  return true;
217 }
218 
220 {
221  return false;
222 }
223 
225 {
226  return 0;
227 }
228 
230 {
231  return fnReplicas;
232 }
233 
234 
235 
237  G4int& nReplicas,
238  G4double& width,
239  G4double& offset,
240  G4bool& consuming ) const
241 {
242  axis = faxis;
243  nReplicas = fnReplicas;
244  width = fwidth;
245  offset = foffset;
246  consuming = true;
247 }
248 
250 {
251  return (fRegularVolsId!=0);
252 }
253 
255 {
256  return fRegularVolsId;
257 }
258 
260 {
261  fRegularVolsId= Code;
262 }
263 
264 
265 
266 
267 
268 //
269 
270 // ********************************************************************
271 // GetSubInstanceManager
272 //
273 // Returns the private data instance manager.
274 // *******************************************************************
276 {
277  return subInstanceManager;
278 }
279 
280 
281 // This method is similar to the constructor. It is used by each worker
282 // thread to achieve the same effect as that of the master thread exept
283 // to register the new created instance. This method is invoked explicitly.
284 // It does not create a new G4PVReplica instance. It only assigns the value
285 // for the fields encapsulated by the class G4ReplicaData.
286 //
288 {
289 
291  subInstanceManager.SlaveCopySubInstanceArray();
292  G4MT_copyNo = -1;
293  CheckAndSetParameters (faxis, fnReplicas, fwidth, foffset);
294 }
295 
296 // This method is similar to the destructor. It is used by each worker
297 // thread to achieve the partial effect as that of the master thread.
298 // For G4PVReplica instances, it destories the rotation matrix.
299 //
301 {
302  if ( faxis==kPhi )
303  {
304  delete GetRotation();
305  }
306 }
307 
308 
309 
Definition: geomdefs.hh:54
void TerminateWorker(G4PVReplica *pMasterObject)
Definition: G4PVReplica.cc:300
G4PVReplica(const G4String &pName, G4LogicalVolume *pLogical, G4LogicalVolume *pMother, const EAxis pAxis, const G4int nReplicas, const G4double width, const G4double offset=0)
Definition: G4PVReplica.cc:91
tuple a
Definition: test.py:11
virtual ~G4PVReplica()
Definition: G4PVReplica.cc:191
G4String GetName() const
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const
Definition: G4PVReplica.cc:236
virtual void SetRegularStructureId(G4int Code)
Definition: G4PVReplica.cc:259
#define width
G4double fwidth
Definition: G4PVReplica.hh:194
G4bool IsRegularStructure() const
Definition: G4PVReplica.cc:249
#define G4ThreadLocal
Definition: tls.hh:52
G4int CreateSubInstance()
int G4int
Definition: G4Types.hh:78
virtual G4int GetCopyNo() const
Definition: G4PVReplica.cc:204
G4bool IsReplicated() const
Definition: G4PVReplica.cc:214
void SetRotation(G4RotationMatrix *)
static const G4PVRManager & GetSubInstanceManager()
Definition: G4PVReplica.cc:275
virtual G4bool IsParameterised() const
Definition: G4PVReplica.cc:219
G4double foffset
Definition: G4PVReplica.hh:194
void InitialiseWorker(G4VPhysicalVolume *pMasterObject, G4RotationMatrix *pRot, const G4ThreeVector &tlate)
const G4String & GetName() const
void InitialiseWorker(G4PVReplica *pMasterObject)
Definition: G4PVReplica.cc:287
#define Code
Definition: deflate.h:77
virtual G4VPVParameterisation * GetParameterisation() const
Definition: G4PVReplica.cc:224
G4int fnReplicas
Definition: G4PVReplica.hh:193
bool G4bool
Definition: G4Types.hh:79
void SlaveCopySubInstanceArray()
G4bool IsMany() const
Definition: G4PVReplica.cc:199
G4int GetNoDaughters() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4LogicalVolume * GetLogicalVolume() const
EAxis
Definition: geomdefs.hh:54
virtual G4int GetMultiplicity() const
Definition: G4PVReplica.cc:229
const G4RotationMatrix * GetRotation() const
virtual void SetCopyNo(G4int CopyNo)
Definition: G4PVReplica.cc:209
#define G4endl
Definition: G4ios.hh:61
void SetMotherLogical(G4LogicalVolume *pMother)
double G4double
Definition: G4Types.hh:76
Definition: geomdefs.hh:54
#define G4MT_copyNo
Definition: G4PVReplica.hh:117
void AddDaughter(G4VPhysicalVolume *p)
G4int GetRegularStructureId() const
Definition: G4PVReplica.cc:254