source: trunk/source/geometry/volumes/src/G4PVReplica.cc @ 1058

Last change on this file since 1058 was 1058, checked in by garnier, 15 years ago

file release beta

File size: 7.7 KB
Line 
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,v 1.7 2006/06/29 18:58:14 gunter Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30//
31// class G4PVReplica Implementation
32//
33// ----------------------------------------------------------------------
34
35#include "G4PVReplica.hh"
36#include "G4LogicalVolume.hh"
37
38G4PVReplica::G4PVReplica( const G4String& pName,
39                                G4LogicalVolume* pLogical,
40                                G4VPhysicalVolume* pMother,
41                          const EAxis pAxis,
42                          const G4int nReplicas,
43                          const G4double width,
44                          const G4double offset )
45  : G4VPhysicalVolume(0, G4ThreeVector(), pName, pLogical, pMother),
46    fcopyNo(-1), fRegularVolsId(0)
47{
48  if ((!pMother) || (!pMother->GetLogicalVolume()))
49  {
50    G4cerr << "ERROR - NULL pointer specified as mother volume." << G4endl
51           << "        The world volume cannot be sliced or parameterised !"
52           << G4endl;
53    G4Exception("G4PVReplica::G4PVReplica()", "InvalidSetup", FatalException,
54                "NULL pointer to mother. World volume cannot be sliced !");
55  }
56  G4LogicalVolume* motherLogical = pMother->GetLogicalVolume();
57  if (pLogical == motherLogical)
58    G4Exception("G4PVReplica::G4PVReplica()", "InvalidSetup",
59                FatalException, "Cannot place a volume inside itself!");
60  SetMotherLogical(motherLogical);
61  motherLogical->AddDaughter(this);
62  if (motherLogical->GetNoDaughters() != 1)
63  {
64    G4cerr << "ERROR - A replica or parameterised volume must be" << G4endl
65           << "        the only daughter of a given mother volume !" << G4endl
66           << "           Mother physical volume: " << pMother->GetName() << G4endl
67           << "           Replicated volume: " << pName << G4endl;
68    G4Exception("G4PVReplica::G4PVReplica()", "InvalidSetup", FatalException,
69                "Replica or parameterised volume must be the only daughter !");
70  }
71  CheckAndSetParameters (pAxis, nReplicas, width, offset);
72}
73
74G4PVReplica::G4PVReplica( const G4String& pName,
75                                G4LogicalVolume* pLogical,
76                                G4LogicalVolume* pMotherLogical,
77                          const EAxis pAxis,
78                          const G4int nReplicas,
79                          const G4double width,
80                          const G4double offset )
81  : G4VPhysicalVolume(0,G4ThreeVector(),pName,pLogical,0),
82    fcopyNo(-1), fRegularVolsId(0)
83{
84  if (!pMotherLogical)
85  {
86    G4cerr << "ERROR - NULL pointer specified as mother volume for "
87           << pName << "." << G4endl;
88    G4Exception("G4PVReplica::G4PVReplica()", "NullPointer", FatalException,
89                "Invalid setup. NULL pointer specified as mother !");
90  }
91  if (pLogical == pMotherLogical)
92    G4Exception("G4PVReplica::G4PVReplica()", "InvalidSetup",
93                FatalException, "Cannot place a volume inside itself!");
94  pMotherLogical->AddDaughter(this);
95  SetMotherLogical(pMotherLogical);
96  if (pMotherLogical->GetNoDaughters() != 1)
97  {
98    G4cerr << "ERROR - A replica or parameterised volume must be" << G4endl
99           << "        the only daughter of a given mother volume !" << G4endl
100           << "           Mother logical volume: " << pMotherLogical->GetName() << G4endl
101           << "           Replicated volume: " << pName << G4endl;
102    G4Exception("G4PVReplica::G4PVReplica()", "InvalidSetup", FatalException,
103                "Replica or parameterised volume must be the only daughter !");
104  }
105  CheckAndSetParameters (pAxis, nReplicas, width, offset);
106}
107
108void G4PVReplica::CheckAndSetParameters( const EAxis pAxis,
109                                         const G4int nReplicas,
110                                         const G4double width,
111                                         const G4double offset)
112{   
113  if (nReplicas<1)
114  {
115    G4Exception("G4PVReplica::CheckAndSetParameters()", "WrongArgumentValue",
116                FatalException, "Illegal number of replicas.");
117  }
118  fnReplicas=nReplicas;
119  if (width<0)
120  {
121    G4Exception("G4PVReplica::CheckAndSetParameters()", "WrongArgumentValue",
122                FatalException, "Width must be positive.");
123  }
124  fwidth  = width;
125  foffset = offset;
126  faxis   = pAxis;
127
128  // Create rotation matrix for phi axis case & check axis is valid
129  //
130  G4RotationMatrix* pRMat=0;
131  switch (faxis)
132  {
133    case kPhi:
134      pRMat=new G4RotationMatrix();
135      if (!pRMat)
136      {
137        G4Exception("G4PVReplica::CheckAndSetParameters()", "FatalError",
138                    FatalException, "Rotation matrix allocation failed.");
139      }
140      SetRotation(pRMat);
141      break;
142    case kRho:
143    case kXAxis:
144    case kYAxis:
145    case kZAxis:
146    case kUndefined:
147      break;
148    default:
149      G4Exception("G4PVReplica::CheckAndSetParameters()", "WrongArgumentValue",
150                  FatalException, "Unknown axis of replication.");
151      break;
152  }
153}
154
155G4PVReplica::G4PVReplica( __void__& a )
156  : G4VPhysicalVolume(a), fRegularVolsId(0)
157{
158}
159
160G4PVReplica::~G4PVReplica()
161{
162  if ( faxis==kPhi )
163  {
164    delete GetRotation();
165  }
166}
167
168G4bool G4PVReplica::IsMany() const
169{
170  return false; 
171}
172
173G4int G4PVReplica::GetCopyNo() const
174{
175  return fcopyNo;
176}
177
178void  G4PVReplica::SetCopyNo(G4int newCopyNo)
179{
180  fcopyNo = newCopyNo;
181}
182
183G4bool G4PVReplica::IsReplicated() const
184{
185  return true;
186}
187
188G4bool G4PVReplica::IsParameterised() const
189{
190  return false;
191}
192
193G4VPVParameterisation* G4PVReplica::GetParameterisation() const
194{
195  return 0;
196}
197
198G4int G4PVReplica::GetMultiplicity() const
199{
200  return fnReplicas;
201}
202
203
204
205void G4PVReplica::GetReplicationData( EAxis& axis,
206                                      G4int& nReplicas,
207                                      G4double& width,
208                                      G4double& offset,
209                                      G4bool& consuming ) const
210{
211  axis = faxis;
212  nReplicas = fnReplicas;
213  width = fwidth;
214  offset = foffset;
215  consuming = true;
216}
217
218G4bool G4PVReplica::IsRegularStructure() const
219{
220  return (fRegularVolsId!=0); 
221}
222
223G4int  G4PVReplica::GetRegularStructureId() const
224{
225  return fRegularVolsId; 
226}
227
228void   G4PVReplica::SetRegularStructureId( G4int Code )
229{
230  fRegularVolsId= Code; 
231} 
Note: See TracBrowser for help on using the repository browser.