Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4CSGSolid.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: G4CSGSolid.cc 83572 2014-09-01 15:23:27Z gcosmo $
28 //
29 // --------------------------------------------------------------------
30 
31 #include <cmath>
32 
33 #include "G4CSGSolid.hh"
34 #include "Randomize.hh"
35 #include "G4Polyhedron.hh"
36 
37 #include "G4AutoLock.hh"
38 
39 namespace
40 {
41  G4Mutex polyhedronMutex = G4MUTEX_INITIALIZER;
42 }
43 
45 //
46 // Constructor
47 // - Base class constructor
48 
50  G4VSolid(name), fCubicVolume(0.), fSurfaceArea(0.),
51  fRebuildPolyhedron(false), fpPolyhedron(0)
52 {
53 }
54 
56 //
57 // Fake default constructor - sets only member data and allocates memory
58 // for usage restricted to object persistency.
59 
60 G4CSGSolid::G4CSGSolid( __void__& a )
61  : G4VSolid(a), fCubicVolume(0.), fSurfaceArea(0.),
62  fRebuildPolyhedron(false), fpPolyhedron(0)
63 {
64 }
65 
67 //
68 // Destructor
69 //
70 
72 {
73  delete fpPolyhedron; fpPolyhedron = 0;
74 }
75 
77 //
78 // Copy constructor
79 //
80 
82  : G4VSolid(rhs), fCubicVolume(rhs.fCubicVolume),
83  fSurfaceArea(rhs.fSurfaceArea), fRebuildPolyhedron(false), fpPolyhedron(0)
84 {
85 }
86 
88 //
89 // Assignment operator
90 
92 {
93  // Check assignment to self
94  //
95  if (this == &rhs) { return *this; }
96 
97  // Copy base class data
98  //
100 
101  // Copy data
102  //
105  fRebuildPolyhedron = false;
106  delete fpPolyhedron; fpPolyhedron = 0;
107 
108  return *this;
109 }
110 
112 {
113  // Generate radius in annular ring according to uniform area
114  //
115  if (rmin<=0.) { return rmax*std::sqrt(G4UniformRand()); }
116  if (rmin!=rmax) { return std::sqrt(G4UniformRand()
117  * (sqr(rmax)-sqr(rmin))+sqr(rmin)); }
118  return rmin;
119 }
120 
121 std::ostream& G4CSGSolid::StreamInfo(std::ostream& os) const
122 {
123  os << "-----------------------------------------------------------\n"
124  << " *** Dump for solid - " << GetName() << " ***\n"
125  << " ===================================================\n"
126  << " Solid type: " << GetEntityType() << "\n"
127  << " Parameters: \n"
128  << " NOT available !\n"
129  << "-----------------------------------------------------------\n";
130 
131  return os;
132 }
133 
135 {
136  if (!fpPolyhedron ||
140  {
141  G4AutoLock l(&polyhedronMutex);
142  delete fpPolyhedron;
144  fRebuildPolyhedron = false;
145  l.unlock();
146  }
147  return fpPolyhedron;
148 }
G4String GetName() const
const XML_Char * name
Definition: expat.h:151
G4bool fRebuildPolyhedron
Definition: G4CSGSolid.hh:80
G4double GetRadiusInRing(G4double rmin, G4double rmax) const
Definition: G4CSGSolid.cc:111
G4double fCubicVolume
Definition: G4CSGSolid.hh:78
virtual G4GeometryType GetEntityType() const =0
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
virtual std::ostream & StreamInfo(std::ostream &os) const
Definition: G4CSGSolid.cc:121
#define G4UniformRand()
Definition: Randomize.hh:97
G4double fSurfaceArea
Definition: G4CSGSolid.hh:79
G4Polyhedron * fpPolyhedron
Definition: G4CSGSolid.hh:81
virtual G4Polyhedron * GetPolyhedron() const
Definition: G4CSGSolid.cc:134
virtual G4Polyhedron * CreatePolyhedron() const
Definition: G4VSolid.cc:660
G4CSGSolid(const G4String &pName)
Definition: G4CSGSolid.cc:49
G4int G4Mutex
Definition: G4Threading.hh:173
static G4int GetNumberOfRotationSteps()
G4VSolid & operator=(const G4VSolid &rhs)
Definition: G4VSolid.cc:111
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
T sqr(const T &x)
Definition: templates.hh:145
double G4double
Definition: G4Types.hh:76
virtual ~G4CSGSolid()
Definition: G4CSGSolid.cc:71
G4CSGSolid & operator=(const G4CSGSolid &rhs)
Definition: G4CSGSolid.cc:91