ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgrVolume.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4tgrVolume.cc
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 //
28 //
29 // class G4tgrVolume
30 
31 // History:
32 // - Created. P.Arce, CIEMAT (November 2007)
33 // -------------------------------------------------------------------------
34 
35 #include "G4tgrVolume.hh"
36 #include "G4tgrUtils.hh"
37 #include "G4tgrSolid.hh"
38 #include "G4tgrVolumeMgr.hh"
39 #include "G4tgrPlace.hh"
40 #include "G4tgrPlaceSimple.hh"
41 #include "G4tgrPlaceDivRep.hh"
43 #include "G4tgrFileReader.hh"
44 #include "G4tgrMessenger.hh"
45 #include "G4UIcommand.hh"
46 
47 //-------------------------------------------------------------
49  : theName(""), theType(""),
50  theMaterialName(""), theSolid(0), theVisibility(false),
51  theRGBColour(0), theCheckOverlaps(false)
52 {
53 }
54 
55 
56 //-------------------------------------------------------------
58 {
59  delete [] theRGBColour;
60 }
61 
62 
63 //-------------------------------------------------------------
64 G4tgrVolume::G4tgrVolume( const std::vector<G4String>& wl)
65 {
66  theType = "VOLSimple";
67 
68  //---------- set name
69  theName = G4tgrUtils::GetString( wl[1] );
70 
71  theVisibility = 1;
72  theRGBColour = new G4double[4];
73  for(size_t ii=0; ii<4; ii++) { theRGBColour[ii] = -1.; }
74  theCheckOverlaps = 0;
75 
76  if( wl.size() != 4 )
77  {
78  //:VOLU tag to build a volume creating solid and material
79  //---------- set material name
80  theMaterialName = G4tgrUtils::GetString( wl[wl.size()-1] );
81 
82  //---------- create only vector<double> of theSolidParams
84 
85 #ifdef G4VERBOSE
87  {
88  G4cout << "Created from new solid: "
89  << *this << G4endl;
90  }
91 #endif
92  }
93  else
94  {
95  //:VOLU tag to build a volume assigning material to solid
96  //---------- set material name
99 
100 #ifdef G4VERBOSE
102  {
103  G4cout << "Created from existing solid: "
104  << *this << G4endl;
105  }
106 #endif
107  }
108 }
109 
110 
111 //-------------------------------------------------------------------------
113 {
114  theName = vol.GetName();
115  theType = vol.GetType();
117  theSolid = vol.GetSolid();
120  theRGBColour = vol.GetRGBColour();
122 }
123 
124 
125 //-------------------------------------------------------------------------
127 {
128  G4String ErrMessage = "Should only be called for composite solids... "
130  G4Exception("G4tgrVolume::GetVolume()", "InvalidCall",
131  FatalException, ErrMessage);
132  return 0;
133 }
134 
135 
136 //-------------------------------------------------------------
137 G4tgrPlace* G4tgrVolume::AddPlace( const std::vector<G4String>& wl )
138 {
139  //---------- Check for exact number of words read
140  G4tgrUtils::CheckWLsize( wl, 8, WLSIZE_EQ, " G4tgrVolume::AddPlace");
141  //---------- set G4tgrPlace
142  G4tgrPlaceSimple* pl = new G4tgrPlaceSimple( wl );
143  //---------- check that there is no previous placement in
144  // the same parent with the same copyNo
145  std::vector<G4tgrPlace*>::iterator ite;
146  for( ite = thePlacements.begin(); ite != thePlacements.end(); ite++)
147  {
148  if( ((*ite)->GetCopyNo() == pl->GetCopyNo())
149  && ((*ite)->GetParentName() == pl->GetParentName()) )
150  {
151  G4String ErrMessage = "Repeated placement. Volume "
152  + theName + " in " + pl->GetParentName();
153  G4Exception("G4tgrVolume::AddPlace()", "InvalidArgument",
154  FatalErrorInArgument, ErrMessage);
155  }
156  }
157 
158  pl->SetVolume( this );
159  thePlacements.push_back( pl );
160 
161 #ifdef G4VERBOSE
163  {
164  G4cout << " G4tgrVolume: New placement: " << thePlacements.size()
165  << " added for Volume " << theName
166  << " inside " << pl->GetParentName()
167  << " type " << pl->GetType() << G4endl;
168  }
169 #endif
170  //---------- register parent - child
172 
173  return pl;
174 }
175 
176 
177 //-------------------------------------------------------------
179 G4tgrVolume::AddPlaceReplica( const std::vector<G4String>& wl )
180 {
181  //---------- Check for exact number of words read
182  G4tgrUtils::CheckWLsize( wl, 6, WLSIZE_GE, " G4tgrVolume::AddPlaceReplica");
183  G4tgrUtils::CheckWLsize( wl, 7, WLSIZE_LE, " G4tgrVolume::AddPlaceReplica");
184 
185  if( (wl.size() == 7) && (G4tgrUtils::GetDouble(wl[6]) != 0.)
186  && (wl[3] != "PHI") )
187  {
188  G4Exception("G4tgrVolume::AddPlaceReplica",
189  "Offset set for replica not along PHI, it will not be used",
190  JustWarning,
191  G4String("Volume "+wl[1]+" in volume "+wl[2]).c_str());
192  }
193 
194  //---------- set G4tgrPlace
195  G4tgrPlaceDivRep* pl = new G4tgrPlaceDivRep( wl );
196  pl->SetType("PlaceReplica");
197  pl->SetVolume( this );
198  thePlacements.push_back( pl );
199 
200 #ifdef G4VERBOSE
202  {
203  G4cout << " G4tgrVolume: New placement replica: " << thePlacements.size()
204  << " added for Volume " << theName
205  << " inside " << pl->GetParentName() << G4endl;
206  }
207 #endif
208  //---------- register parent - child
210 
211  return pl;
212 }
213 
214 
215 //-------------------------------------------------------------
217 G4tgrVolume::AddPlaceParam( const std::vector<G4String>& wl )
218 {
219  //---------- set G4tgrPlaceParameterisation
221 
222  pl->SetVolume( this );
223  thePlacements.push_back( pl );
224 
225 #ifdef G4VERBOSE
227  {
228  G4cout << " G4tgrVolume: New placement Param: " << thePlacements.size()
229  << " added for Volume " << theName
230  << " inside " << pl->GetParentName() << G4endl;
231  }
232 #endif
233  //---------- register parent - child
235 
236  return pl;
237 }
238 
239 
240 //-------------------------------------------------------------
241 void G4tgrVolume::AddVisibility( const std::vector<G4String>& wl )
242 {
243  //---------- Check for exact number of words read
244  G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, " G4tgrVolume::AddVisibility");
245 
246  //---------- Set visibility
248 }
249 
250 
251 //-------------------------------------------------------------
252 void G4tgrVolume::AddRGBColour( const std::vector<G4String>& wl )
253 {
254  //---------- Check for exact number of words read
255  G4tgrUtils::CheckWLsize( wl, 5, WLSIZE_GE, " G4tgrVolume::AddRGBColour");
256 
257  //---------- Set RGB colour
258  theRGBColour[0] = G4tgrUtils::GetDouble( wl[2] );
259  theRGBColour[1] = G4tgrUtils::GetDouble( wl[3] );
260  theRGBColour[2] = G4tgrUtils::GetDouble( wl[4] );
262  if( wl.size() == 6 )
263  {
264  theRGBColour[3] = G4tgrUtils::GetDouble( wl[5] );
265  }
266 }
267 
268 
269 //-------------------------------------------------------------
270 void G4tgrVolume::AddCheckOverlaps( const std::vector<G4String>& wl )
271 {
272  //---------- Check for exact number of words read
273  G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_GE, " G4tgrVolume::AddCheckOverlaps");
274 
277 
278 }
279 
280 
281 // -------------------------------------------------------------------------
282 std::ostream& operator<<(std::ostream& os, const G4tgrVolume& obj)
283 {
284  os << "G4tgrVolume= " << obj.theName << " Type= " << obj.theType
285  << " Material= " << obj.theMaterialName
286  << " Visibility " << obj.theVisibility
287  << " Colour " << (obj.theRGBColour)[0] << " "
288  << (obj.theRGBColour)[1] << " "
289  << (obj.theRGBColour)[2] << " "
290  << (obj.theRGBColour)[3] << " "
291  << " CheckOverlaps " << obj.theCheckOverlaps
292  << " N placements " << obj.thePlacements.size() << G4endl;
293 
294  return os;
295 }