Geant4  10.00.p01
G4tgrVolume.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: G4tgrVolume.cc 66363 2012-12-18 09:12:54Z gcosmo $
28 //
29 //
30 // class G4tgrVolume
31 
32 // History:
33 // - Created. P.Arce, CIEMAT (November 2007)
34 // -------------------------------------------------------------------------
35 
36 #include "G4tgrVolume.hh"
37 #include "G4tgrUtils.hh"
38 #include "G4tgrSolid.hh"
39 #include "G4tgrVolumeMgr.hh"
40 #include "G4tgrPlace.hh"
41 #include "G4tgrPlaceSimple.hh"
42 #include "G4tgrPlaceDivRep.hh"
44 #include "G4tgrFileReader.hh"
45 #include "G4tgrMessenger.hh"
46 #include "G4UIcommand.hh"
47 
48 //-------------------------------------------------------------
50  : theName(""), theType(""),
51  theMaterialName(""), theSolid(0), theVisibility(false),
52  theRGBColour(0), theCheckOverlaps(false)
53 {
54 }
55 
56 
57 //-------------------------------------------------------------
59 {
60  delete [] theRGBColour;
61 }
62 
63 
64 //-------------------------------------------------------------
65 G4tgrVolume::G4tgrVolume( const std::vector<G4String>& wl)
66 {
67  theType = "VOLSimple";
68 
69  //---------- set name
70  theName = G4tgrUtils::GetString( wl[1] );
71 
72  theVisibility = 1;
73  theRGBColour = new G4double[4];
74  for(size_t ii=0; ii<4; ii++) { theRGBColour[ii] = -1.; }
75  theCheckOverlaps = 0;
76 
77  if( wl.size() != 4 )
78  {
79  //:VOLU tag to build a volume creating solid and material
80  //---------- set material name
81  theMaterialName = G4tgrUtils::GetString( wl[wl.size()-1] );
82 
83  //---------- create only vector<double> of theSolidParams
85 
86 #ifdef G4VERBOSE
88  {
89  G4cout << "Created from new solid: "
90  << *this << G4endl;
91  }
92 #endif
93  }
94  else
95  {
96  //:VOLU tag to build a volume assigning material to solid
97  //---------- set material name
100 
101 #ifdef G4VERBOSE
103  {
104  G4cout << "Created from existing solid: "
105  << *this << G4endl;
106  }
107 #endif
108  }
109 }
110 
111 
112 //-------------------------------------------------------------------------
114 {
115  theName = vol.GetName();
116  theType = vol.GetType();
118  theSolid = vol.GetSolid();
121  theRGBColour = vol.GetRGBColour();
123 }
124 
125 
126 //-------------------------------------------------------------------------
128 {
129  G4String ErrMessage = "Should only be called for composite solids... "
131  G4Exception("G4tgrVolume::GetVolume()", "InvalidCall",
132  FatalException, ErrMessage);
133  return 0;
134 }
135 
136 
137 //-------------------------------------------------------------
138 G4tgrPlace* G4tgrVolume::AddPlace( const std::vector<G4String>& wl )
139 {
140  //---------- Check for exact number of words read
141  G4tgrUtils::CheckWLsize( wl, 8, WLSIZE_EQ, " G4tgrVolume::AddPlace");
142  //---------- set G4tgrPlace
143  G4tgrPlaceSimple* pl = new G4tgrPlaceSimple( wl );
144  //---------- check that there is no previous placement in
145  // the same parent with the same copyNo
146  std::vector<G4tgrPlace*>::iterator ite;
147  for( ite = thePlacements.begin(); ite != thePlacements.end(); ite++)
148  {
149  if( ((*ite)->GetCopyNo() == pl->GetCopyNo())
150  && ((*ite)->GetParentName() == pl->GetParentName()) )
151  {
152  G4String ErrMessage = "Repeated placement. Volume "
153  + theName + " in " + pl->GetParentName();
154  G4Exception("G4tgrVolume::AddPlace()", "InvalidArgument",
155  FatalErrorInArgument, ErrMessage);
156  }
157  }
158 
159  pl->SetVolume( this );
160  thePlacements.push_back( pl );
161 
162 #ifdef G4VERBOSE
164  {
165  G4cout << " G4tgrVolume: New placement: " << thePlacements.size()
166  << " added for Volume " << theName
167  << " inside " << pl->GetParentName()
168  << " type " << pl->GetType() << G4endl;
169  }
170 #endif
171  //---------- register parent - child
173 
174  return pl;
175 }
176 
177 
178 //-------------------------------------------------------------
180 G4tgrVolume::AddPlaceReplica( const std::vector<G4String>& wl )
181 {
182  //---------- Check for exact number of words read
183  G4tgrUtils::CheckWLsize( wl, 6, WLSIZE_GE, " G4tgrVolume::AddPlaceReplica");
184  G4tgrUtils::CheckWLsize( wl, 7, WLSIZE_LE, " G4tgrVolume::AddPlaceReplica");
185 
186  if( (wl.size() == 7) && (G4tgrUtils::GetDouble(wl[6]) != 0.)
187  && (wl[3] != "PHI") )
188  {
189  G4Exception("G4tgrVolume::AddPlaceReplica",
190  "Offset set for replica not along PHI, it will not be used",
191  JustWarning,
192  G4String("Volume "+wl[1]+" in volume "+wl[2]).c_str());
193  }
194 
195  //---------- set G4tgrPlace
196  G4tgrPlaceDivRep* pl = new G4tgrPlaceDivRep( wl );
197  pl->SetType("PlaceReplica");
198  pl->SetVolume( this );
199  thePlacements.push_back( pl );
200 
201 #ifdef G4VERBOSE
203  {
204  G4cout << " G4tgrVolume: New placement replica: " << thePlacements.size()
205  << " added for Volume " << theName
206  << " inside " << pl->GetParentName() << G4endl;
207  }
208 #endif
209  //---------- register parent - child
211 
212  return pl;
213 }
214 
215 
216 //-------------------------------------------------------------
218 G4tgrVolume::AddPlaceParam( const std::vector<G4String>& wl )
219 {
220  //---------- set G4tgrPlaceParameterisation
222 
223  pl->SetVolume( this );
224  thePlacements.push_back( pl );
225 
226 #ifdef G4VERBOSE
228  {
229  G4cout << " G4tgrVolume: New placement Param: " << thePlacements.size()
230  << " added for Volume " << theName
231  << " inside " << pl->GetParentName() << G4endl;
232  }
233 #endif
234  //---------- register parent - child
236 
237  return pl;
238 }
239 
240 
241 //-------------------------------------------------------------
242 void G4tgrVolume::AddVisibility( const std::vector<G4String>& wl )
243 {
244  //---------- Check for exact number of words read
245  G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, " G4tgrVolume::AddVisibility");
246 
247  //---------- Set visibility
249 }
250 
251 
252 //-------------------------------------------------------------
253 void G4tgrVolume::AddRGBColour( const std::vector<G4String>& wl )
254 {
255  //---------- Check for exact number of words read
256  G4tgrUtils::CheckWLsize( wl, 5, WLSIZE_GE, " G4tgrVolume::AddRGBColour");
257 
258  //---------- Set RGB colour
259  theRGBColour[0] = G4tgrUtils::GetDouble( wl[2] );
260  theRGBColour[1] = G4tgrUtils::GetDouble( wl[3] );
261  theRGBColour[2] = G4tgrUtils::GetDouble( wl[4] );
263  if( wl.size() == 6 )
264  {
265  theRGBColour[3] = G4tgrUtils::GetDouble( wl[5] );
266  }
267 }
268 
269 
270 //-------------------------------------------------------------
271 void G4tgrVolume::AddCheckOverlaps( const std::vector<G4String>& wl )
272 {
273  //---------- Check for exact number of words read
274  G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_GE, " G4tgrVolume::AddCheckOverlaps");
275 
278 
279 }
280 
281 
282 // -------------------------------------------------------------------------
283 std::ostream& operator<<(std::ostream& os, const G4tgrVolume& obj)
284 {
285  os << "G4tgrVolume= " << obj.theName << " Type= " << obj.theType
286  << " Material= " << obj.theMaterialName
287  << " Visibility " << obj.theVisibility
288  << " Colour " << (obj.theRGBColour)[0] << " "
289  << (obj.theRGBColour)[1] << " "
290  << (obj.theRGBColour)[2] << " "
291  << (obj.theRGBColour)[3] << " "
292  << " CheckOverlaps " << obj.theCheckOverlaps
293  << " N placements " << obj.thePlacements.size() << G4endl;
294 
295  return os;
296 }
const std::vector< G4tgrPlace * > GetPlacements() const
Definition: G4tgrVolume.hh:95
G4tgrSolid * FindSolid(const G4String &name, G4bool exists=false)
G4bool GetCheckOverlaps() const
Definition: G4tgrVolume.hh:100
G4String theMaterialName
Definition: G4tgrVolume.hh:112
G4bool theVisibility
Definition: G4tgrVolume.hh:119
virtual G4tgrVolume * GetVolume(G4int ii) const
Definition: G4tgrVolume.cc:127
virtual ~G4tgrVolume()
Definition: G4tgrVolume.cc:58
G4tgrPlaceDivRep * AddPlaceReplica(const std::vector< G4String > &wl)
Definition: G4tgrVolume.cc:180
const G4String & GetType() const
Definition: G4tgrPlace.hh:61
static void CheckWLsize(const std::vector< G4String > &wl, unsigned int nWCheck, WLSIZEtype st, const G4String &methodName)
Definition: G4tgrUtils.cc:475
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:357
int G4int
Definition: G4Types.hh:78
G4String theType
Definition: G4tgrVolume.hh:110
void SetType(const G4String &typ)
Definition: G4tgrPlace.hh:63
void AddCheckOverlaps(const std::vector< G4String > &wl)
Definition: G4tgrVolume.cc:271
void AddVisibility(const std::vector< G4String > &wl)
Definition: G4tgrVolume.cc:242
G4tgrSolid * GetSolid() const
Definition: G4tgrVolume.hh:92
G4GLOB_DLL std::ostream G4cout
void SetVolume(G4tgrVolume *vol)
Definition: G4tgrPlace.hh:62
static G4int GetVerboseLevel()
std::vector< G4tgrPlace * > thePlacements
Definition: G4tgrVolume.hh:116
static G4tgrVolumeMgr * GetInstance()
G4tgrSolid * theSolid
Definition: G4tgrVolume.hh:114
G4String theName
Definition: G4tgrVolume.hh:108
const G4String & GetParentName() const
Definition: G4tgrPlace.hh:58
G4bool GetVisibility() const
Definition: G4tgrVolume.hh:96
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4double GetDouble(const G4String &str, G4double unitval=1.)
Definition: G4tgrUtils.cc:205
const G4String & GetType() const
Definition: G4tgrVolume.hh:91
void AddRGBColour(const std::vector< G4String > &wl)
Definition: G4tgrVolume.cc:253
static G4String GetString(const G4String &str)
Definition: G4tgrUtils.cc:180
unsigned int GetCopyNo() const
Definition: G4tgrPlace.hh:60
G4tgrSolid * CreateSolid(const std::vector< G4String > &wl, G4bool bVOLUtag)
void RegisterParentChild(const G4String &parentName, const G4tgrPlace *pl)
std::ostream & operator<<(std::ostream &os, const G4tgrVolume &obj)
Definition: G4tgrVolume.cc:283
#define G4endl
Definition: G4ios.hh:61
G4bool theCheckOverlaps
Definition: G4tgrVolume.hh:121
double G4double
Definition: G4Types.hh:76
G4tgrPlaceParameterisation * AddPlaceParam(const std::vector< G4String > &wl)
Definition: G4tgrVolume.cc:218
const G4String & GetName() const
Definition: G4tgrVolume.hh:89
G4double * theRGBColour
Definition: G4tgrVolume.hh:120
const G4String & GetMaterialName() const
Definition: G4tgrVolume.hh:93
G4double * GetRGBColour() const
Definition: G4tgrVolume.hh:98
virtual G4tgrPlace * AddPlace(const std::vector< G4String > &wl)
Definition: G4tgrVolume.cc:138
static G4bool GetBool(const G4String &str)
Definition: G4tgrUtils.cc:448