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