G4tgrVolume.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4tgrVolume.cc 69803 2013-05-15 15:24:50Z gcosmo $
00028 //
00029 //
00030 // class G4tgrVolume
00031 
00032 // History:
00033 // - Created.                                 P.Arce, CIEMAT (November 2007)
00034 // -------------------------------------------------------------------------
00035 
00036 #include "G4tgrVolume.hh"
00037 #include "G4tgrUtils.hh"
00038 #include "G4tgrSolid.hh"
00039 #include "G4tgrVolumeMgr.hh"
00040 #include "G4tgrPlace.hh"
00041 #include "G4tgrPlaceSimple.hh"
00042 #include "G4tgrPlaceDivRep.hh"
00043 #include "G4tgrPlaceParameterisation.hh"
00044 #include "G4tgrFileReader.hh"
00045 #include "G4tgrMessenger.hh"
00046 #include "G4UIcommand.hh"
00047 
00048 //-------------------------------------------------------------
00049 G4tgrVolume::G4tgrVolume()
00050   : theName(""), theType(""),
00051     theMaterialName(""), theSolid(0), theVisibility(false),
00052     theRGBColour(0), theCheckOverlaps(false)
00053 {
00054 }
00055 
00056 
00057 //-------------------------------------------------------------
00058 G4tgrVolume::~G4tgrVolume()
00059 {
00060   delete [] theRGBColour;
00061 }
00062 
00063 
00064 //-------------------------------------------------------------
00065 G4tgrVolume::G4tgrVolume( const std::vector<G4String>& wl) 
00066 {
00067   theType = "VOLSimple";
00068 
00069   //---------- set name 
00070   theName = G4tgrUtils::GetString( wl[1] ); 
00071 
00072   theVisibility = 1;
00073   theRGBColour = new G4double[4];
00074   for(size_t ii=0; ii<4; ii++)  { theRGBColour[ii] = -1.; }
00075   theCheckOverlaps = 0;
00076 
00077   if( wl.size() != 4 )
00078   {
00079     //:VOLU tag to build a volume creating solid and material
00080     //---------- set material name
00081     theMaterialName = G4tgrUtils::GetString( wl[wl.size()-1] );
00082     
00083     //---------- create only vector<double> of theSolidParams
00084     theSolid = G4tgrVolumeMgr::GetInstance()->CreateSolid( wl, 1 );
00085 
00086 #ifdef G4VERBOSE
00087     if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00088       {
00089         G4cout << "Created from new solid: " 
00090                << *this << G4endl;
00091       }
00092 #endif
00093   }
00094   else
00095     {
00096       //:VOLU tag to build a volume assigning material to solid
00097       //---------- set material name
00098       theMaterialName = G4tgrUtils::GetString( wl[3] );
00099       theSolid = G4tgrVolumeMgr::GetInstance()->FindSolid( wl[2], true );
00100       
00101 #ifdef G4VERBOSE
00102       if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00103         {
00104           G4cout << "Created from existing solid: " 
00105                  << *this << G4endl;
00106         }
00107 #endif
00108     }
00109 }
00110 
00111 
00112 //-------------------------------------------------------------------------
00113 G4tgrVolume::G4tgrVolume( const G4tgrVolume& vol )
00114 {
00115   theName = vol.GetName();   
00116   theType = vol.GetType();
00117   theMaterialName = vol.GetMaterialName();   
00118   theSolid = vol.GetSolid();
00119   thePlacements  = vol.GetPlacements();
00120   theVisibility   = vol.GetVisibility();
00121   theRGBColour   = vol.GetRGBColour();
00122   theCheckOverlaps = vol.GetCheckOverlaps();
00123 }
00124 
00125 
00126 //-------------------------------------------------------------------------
00127 G4tgrVolume* G4tgrVolume::GetVolume( G4int ii ) const
00128 {
00129   G4String ErrMessage = "Should only be called for composite solids... "
00130                       + G4UIcommand::ConvertToString(ii);
00131   G4Exception("G4tgrVolume::GetVolume()", "InvalidCall",
00132               FatalException, ErrMessage);
00133   return 0;
00134 }
00135 
00136 
00137 //-------------------------------------------------------------
00138 G4tgrPlace* G4tgrVolume::AddPlace( const std::vector<G4String>& wl )
00139 {
00140   //---------- Check for exact number of words read 
00141   G4tgrUtils::CheckWLsize( wl, 8, WLSIZE_EQ, " G4tgrVolume::AddPlace");
00142   //---------- set G4tgrPlace 
00143   G4tgrPlaceSimple* pl = new G4tgrPlaceSimple( wl );
00144   //---------- check that there is no previous placement in
00145   //           the same parent with the same copyNo 
00146   std::vector<G4tgrPlace*>::iterator ite;
00147   for( ite = thePlacements.begin(); ite != thePlacements.end(); ite++)
00148   {
00149     if( ((*ite)->GetCopyNo() == pl->GetCopyNo())
00150      && ((*ite)->GetParentName() == pl->GetParentName()) )
00151     {
00152       G4String ErrMessage = "Repeated placement. Volume "
00153                           + theName + " in " + pl->GetParentName();
00154       G4Exception("G4tgrVolume::AddPlace()", "InvalidArgument",
00155                   FatalErrorInArgument, ErrMessage);
00156     }
00157   } 
00158 
00159   pl->SetVolume( this );
00160   thePlacements.push_back( pl ); 
00161 
00162 #ifdef G4VERBOSE
00163   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00164   {
00165     G4cout << " G4tgrVolume:  New placement: " << thePlacements.size()
00166            << " added for Volume " << theName
00167            << " inside " << pl->GetParentName()
00168            << " type " << pl->GetType() << G4endl;
00169   }
00170 #endif
00171   //---------- register parent - child 
00172   G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl );
00173 
00174   return pl;
00175 }
00176 
00177 
00178 //-------------------------------------------------------------
00179 G4tgrPlaceDivRep*
00180 G4tgrVolume::AddPlaceReplica( const std::vector<G4String>& wl ) 
00181 {
00182   //---------- Check for exact number of words read 
00183   G4tgrUtils::CheckWLsize( wl, 6, WLSIZE_GE, " G4tgrVolume::AddPlaceReplica");
00184   G4tgrUtils::CheckWLsize( wl, 7, WLSIZE_LE, " G4tgrVolume::AddPlaceReplica");
00185 
00186   if( (wl.size() == 7) && (G4tgrUtils::GetDouble(wl[6]) != 0.)
00187                        && (wl[3] != "PHI") )
00188   {
00189     G4Exception("G4tgrVolume::AddPlaceReplica",
00190                 "Offset set for replica not along PHI, it will not be used",
00191                 JustWarning,
00192                 G4String("Volume "+wl[1]+" in volume "+wl[2]).c_str());
00193   }
00194   
00195   //---------- set G4tgrPlace 
00196   G4tgrPlaceDivRep* pl = new G4tgrPlaceDivRep( wl );
00197   pl->SetType("PlaceReplica");
00198   pl->SetVolume( this );
00199   thePlacements.push_back( pl ); 
00200 
00201 #ifdef G4VERBOSE
00202   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00203   {
00204     G4cout << " G4tgrVolume:  New placement replica: " << thePlacements.size()
00205            << " added for Volume " << theName
00206            << " inside " << pl->GetParentName() << G4endl;
00207   }
00208 #endif
00209   //---------- register parent - child 
00210   G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl );
00211 
00212   return pl;
00213 }
00214 
00215 
00216 //-------------------------------------------------------------
00217 G4tgrPlaceParameterisation*
00218 G4tgrVolume::AddPlaceParam( const std::vector<G4String>& wl )
00219 {
00220   //---------- set G4tgrPlaceParameterisation
00221   G4tgrPlaceParameterisation* pl = new G4tgrPlaceParameterisation( wl );
00222 
00223   pl->SetVolume( this );
00224   thePlacements.push_back( pl ); 
00225 
00226 #ifdef G4VERBOSE
00227   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00228   {
00229     G4cout << " G4tgrVolume:  New placement Param: " << thePlacements.size()
00230            << " added for Volume " << theName
00231            << " inside " << pl->GetParentName() << G4endl;
00232   }
00233 #endif
00234   //---------- register parent - child 
00235   G4tgrVolumeMgr::GetInstance()->RegisterParentChild( pl->GetParentName(), pl );
00236 
00237   return pl;
00238 }
00239 
00240 
00241 //-------------------------------------------------------------
00242 void G4tgrVolume::AddVisibility( const std::vector<G4String>& wl )
00243 {
00244   //---------- Check for exact number of words read 
00245   G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_EQ, " G4tgrVolume::AddVisibility");
00246 
00247   //---------- Set visibility
00248   theVisibility = G4tgrUtils::GetBool( wl[2] );
00249 }
00250 
00251 
00252 //-------------------------------------------------------------
00253 void G4tgrVolume::AddRGBColour( const std::vector<G4String>& wl )
00254 {
00255   //---------- Check for exact number of words read 
00256   G4tgrUtils::CheckWLsize( wl, 5, WLSIZE_GE, " G4tgrVolume::AddRGBColour");
00257   
00258   //---------- Set RGB colour
00259   theRGBColour[0] = G4tgrUtils::GetDouble( wl[2] );
00260   theRGBColour[1] = G4tgrUtils::GetDouble( wl[3] );
00261   theRGBColour[2] = G4tgrUtils::GetDouble( wl[4] );
00263   if( wl.size() == 6 )
00264   {
00265     theRGBColour[3] = G4tgrUtils::GetDouble( wl[5] );
00266   }
00267 }
00268 
00269 
00270 //-------------------------------------------------------------
00271 void G4tgrVolume::AddCheckOverlaps( const std::vector<G4String>& wl )
00272 {
00273   //---------- Check for exact number of words read 
00274   G4tgrUtils::CheckWLsize( wl, 3, WLSIZE_GE, " G4tgrVolume::AddCheckOverlaps");
00275   
00277   theCheckOverlaps = G4tgrUtils::GetBool( wl[2] );
00278 
00279 }
00280 
00281 
00282 // -------------------------------------------------------------------------
00283 std::ostream& operator<<(std::ostream& os, const G4tgrVolume& obj)
00284 {
00285   os << "G4tgrVolume= " << obj.theName << " Type= " << obj.theType
00286      << " Material= " << obj.theMaterialName
00287      << " Visibility " << obj.theVisibility 
00288      << " Colour " << (obj.theRGBColour)[0] << " "
00289                    << (obj.theRGBColour)[1] << " "
00290                    << (obj.theRGBColour)[2] << " "
00291                    << (obj.theRGBColour)[3] << " "
00292      << " CheckOverlaps " << obj.theCheckOverlaps
00293      << " N placements " << obj.thePlacements.size() << G4endl;
00294       
00295   return os;
00296 }

Generated on Mon May 27 17:49:59 2013 for Geant4 by  doxygen 1.4.7