G4tgrLineProcessor.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 //
00028 // class G4tgrLineProcessor
00029 
00030 // History:
00031 // - Created.                                 P.Arce, CIEMAT (November 2007)
00032 // -------------------------------------------------------------------------
00033 
00034 #include "G4tgrLineProcessor.hh"
00035 
00036 #include "G4SystemOfUnits.hh"
00037 #include "G4tgrParameterMgr.hh"
00038 #include "G4tgrFileIn.hh"
00039 #include "G4tgrElementSimple.hh"
00040 #include "G4tgrElementFromIsotopes.hh"
00041 #include "G4tgrVolume.hh"
00042 #include "G4tgrVolumeDivision.hh"
00043 #include "G4tgrVolumeAssembly.hh"
00044 #include "G4tgrPlaceDivRep.hh"
00045 #include "G4tgrPlaceParameterisation.hh"
00046 #include "G4tgrVolumeMgr.hh"
00047 #include "G4tgrUtils.hh"
00048 #include "G4tgrMaterialFactory.hh"
00049 #include "G4tgrRotationMatrixFactory.hh"
00050 #include "G4tgrMessenger.hh"
00051 
00052 
00053 //---------------------------------------------------------------
00054 G4tgrLineProcessor::G4tgrLineProcessor()
00055 {
00056   volmgr = G4tgrVolumeMgr::GetInstance();
00057 }
00058 
00059 
00060 //---------------------------------------------------------------
00061 G4tgrLineProcessor::~G4tgrLineProcessor()
00062 {
00063 }
00064 
00065 
00066 //---------------------------------------------------------------
00067 G4bool G4tgrLineProcessor::ProcessLine( const std::vector<G4String>& wl )
00068 {
00069 #ifdef G4VERBOSE
00070   if( G4tgrMessenger::GetVerboseLevel() >= 1 )
00071   {
00072     G4tgrUtils::DumpVS(wl, "@@@ Processing input line");
00073   }
00074 #endif  
00075 
00076   G4String wl0 = wl[0];
00077   for( size_t ii = 0; ii < wl0.length(); ii++ )
00078   {
00079     wl0[ii] = toupper( wl0[ii] );
00080   }
00081 
00082   //------------------------------- parameter number
00083   if( wl0 == ":P" )
00084   {
00085     G4tgrParameterMgr::GetInstance()->AddParameterNumber( wl );
00086     
00087   //------------------------------- parameter string
00088   }
00089   else if( wl0 == ":PS" )
00090   {
00091     G4tgrParameterMgr::GetInstance()->AddParameterString( wl );
00092 
00093   //------------------------------- isotope
00094   }
00095   else if( wl0 == ":ISOT" )
00096   {
00097     G4tgrIsotope* isot = G4tgrMaterialFactory::GetInstance()
00098                        ->AddIsotope( wl );
00099     volmgr->RegisterMe( isot );
00100 
00101   //------------------------------- element
00102   }
00103   else if( wl0 == ":ELEM" )
00104   {
00105     G4tgrElementSimple* elem = G4tgrMaterialFactory::GetInstance()
00106                              ->AddElementSimple( wl );
00107     volmgr->RegisterMe( elem );
00108 
00109   //------------------------------- element from isotopes
00110   }
00111   else if( wl0 == ":ELEM_FROM_ISOT" )
00112   {
00113     //:ELEM_FROM_ISOT NAME SYMBOL N_ISOT (ISOT_NAME ISOT_ABUNDANCE)
00114     G4tgrElementFromIsotopes* elem = G4tgrMaterialFactory::GetInstance()
00115                                    ->AddElementFromIsotopes( wl );
00116     volmgr->RegisterMe( elem );
00117     
00118   //------------------------------- material
00119   }
00120   else if( wl0 == ":MATE" )
00121   {
00122 
00123     G4tgrMaterialSimple* mate = G4tgrMaterialFactory::GetInstance()
00124                               ->AddMaterialSimple( wl );
00125     volmgr->RegisterMe( mate );
00126     
00127     //------------------------------- material mixtures & by weight
00128   }
00129   else if( (wl0 == ":MIXT") || (wl0 == ":MIXT_BY_WEIGHT") )
00130   {
00131     G4tgrMaterialMixture* mate = G4tgrMaterialFactory::GetInstance()
00132                           ->AddMaterialMixture( wl, "MaterialMixtureByWeight" );
00133     volmgr->RegisterMe( mate );
00134 
00135     //------------------------------- material mixture by number of atoms
00136   }
00137   else if( wl0 == ":MIXT_BY_NATOMS" )
00138   {
00139     G4tgrMaterialMixture* mate = G4tgrMaterialFactory::GetInstance()
00140                           ->AddMaterialMixture(wl, "MaterialMixtureByNoAtoms");
00141     volmgr->RegisterMe( mate );
00142 
00143     //------------------------------- material mixture by volume
00144   }
00145   else if( wl0 == ":MIXT_BY_VOLUME" )
00146   {
00147     G4tgrMaterialMixture* mate = G4tgrMaterialFactory::GetInstance()
00148                           ->AddMaterialMixture( wl, "MaterialMixtureByVolume" );
00149     volmgr->RegisterMe( mate );
00150 
00151     //------------------------------- material Mean Excitation Energy of
00152     //                                Ionisation Potential
00153   }
00154   else if( wl0 == ":MATE_MEE" )
00155   {
00156     G4tgrMaterial* mate = G4tgrMaterialFactory::GetInstance()
00157                         ->FindMaterial( G4tgrUtils::GetString( wl[1] ) );
00158     if( mate == 0 )
00159     {
00160       G4Exception("G4tgrLineProcessor::ProcessLine()", "Material not found",
00161                   FatalException, G4tgrUtils::GetString( wl[1] ) );
00162       return false;
00163     }
00164     mate->SetIonisationMeanExcitationEnergy( G4tgrUtils::GetDouble( wl[2] ) );
00165 
00166     //------------------------------- material
00167   }
00168   else if( wl0 == ":MATE_STATE" )
00169   {
00170     G4tgrMaterial* mate = G4tgrMaterialFactory::GetInstance()
00171                         ->FindMaterial( G4tgrUtils::GetString( wl[1] ) );
00172     if( mate == 0 )
00173     {
00174       G4Exception("G4tgrLineProcessor::ProcessLine()", "Material not found",
00175                   FatalException, wl[1] );
00176     }
00177     mate->SetState( wl[2] );
00178 
00179     //------------------------------- material
00180   }
00181   else if( wl0 == ":MATE_TEMPERATURE" )
00182   {
00183     G4tgrMaterial* mate = G4tgrMaterialFactory::GetInstance()
00184                         ->FindMaterial( G4tgrUtils::GetString( wl[1] ) );
00185     if( mate == 0 )
00186     {
00187       G4Exception("G4tgrLineProcessor::ProcessLine()", "Material not found",
00188                   FatalException, wl[1] );
00189     }
00190     mate->SetTemperature( G4tgrUtils::GetDouble( wl[2], kelvin ) );
00191 
00192     //------------------------------- material
00193   }
00194   else if( wl0 == ":MATE_PRESSURE" )
00195   {
00196     G4tgrMaterial* mate = G4tgrMaterialFactory::GetInstance()
00197                         ->FindMaterial( G4tgrUtils::GetString( wl[1] ) );
00198     if( mate == 0 )
00199     {
00200       G4Exception("G4tgrLineProcessor::ProcessLine()", "Material not found",
00201                   FatalException, wl[1] );
00202     }
00203     mate->SetPressure( G4tgrUtils::GetDouble( wl[2], atmosphere ) );
00204 
00205     //------------------------------- solid
00206   }
00207   else if( wl0 == ":SOLID" )
00208   {                      // called from here or from G4tgrVolume::G4tgrVolume
00209     volmgr->CreateSolid( wl, 0 );
00210 
00211     //------------------------------- volume
00212   }
00213   else if( wl0 == ":VOLU" )
00214   {
00215     G4tgrVolume* vol = new G4tgrVolume( wl );
00216     volmgr->RegisterMe( vol );
00217     
00218     //--------------------------------- single placement
00219   }
00220   else if( wl0 == ":PLACE" )
00221   {
00222     G4tgrVolume* vol = FindVolume( G4tgrUtils::GetString( wl[1] ) );
00223     G4tgrPlace* vpl = vol->AddPlace( wl );
00224     volmgr->RegisterMe( vpl );
00225     
00226     //--------------------------------- parameterisation
00227   }
00228   else if( wl0 == ":PLACE_PARAM" )
00229   {
00230     G4tgrVolume* vol = FindVolume( G4tgrUtils::GetString( wl[1] ) );
00231     G4tgrPlaceParameterisation* vpl = vol->AddPlaceParam( wl );
00232     volmgr->RegisterMe( vpl );
00233 
00234     //--------------------------------- division
00235   }
00236   else if( (wl0 == ":DIV_NDIV") || (wl0 == ":DIV_WIDTH")
00237         || (wl0 == ":DIV_NDIV_WIDTH") )
00238   {
00239     //---------- Create G4tgrVolumeDivision and fill the volume params
00240     G4tgrVolumeDivision* vol = new G4tgrVolumeDivision( wl );
00241     volmgr->RegisterMe( vol );
00242 
00243     //--------------------------------- replica
00244   }
00245   else if( wl0 == ":REPL" )
00246   {
00247     G4tgrVolume* vol = FindVolume( G4tgrUtils::GetString( wl[1] ) );
00248     G4tgrPlaceDivRep* vpl = vol->AddPlaceReplica( wl );
00249     volmgr->RegisterMe( vpl );
00250     
00251     //----------------------------- assembly volume: definition of components
00252   }
00253   else if( wl0 == ":VOLU_ASSEMBLY" )
00254   {
00255     G4tgrVolumeAssembly* vol = new G4tgrVolumeAssembly( wl );
00256     volmgr->RegisterMe( vol );
00257     
00258     //----------------------------- assembly volume: definition of components
00259   }
00260   else if( wl0 == ":PLACE_ASSEMBLY" )
00261   {
00262     G4tgrVolume* vol = FindVolume( G4tgrUtils::GetString( wl[1] ) );
00263     G4tgrPlace* vpl = vol->AddPlace( wl );
00264     volmgr->RegisterMe( vpl );
00265 
00266     //---------------------------------  rotation matrix
00267   }
00268   else if( wl0 == ":ROTM" )
00269   {
00270     //---------- When second word is ':NEXT/:MNXT' it is used for defining a
00271     //           rotation matrix that will be used for the next placement/s
00272     G4tgrRotationMatrix* rm = G4tgrRotationMatrixFactory::GetInstance()
00273                             ->AddRotMatrix( wl );
00274     volmgr->RegisterMe( rm );
00275     
00276     //------------------------------- visualisation
00277   }
00278   else if( wl0 == ":VIS" )
00279   {
00280     std::vector<G4tgrVolume*> vols =
00281        volmgr->FindVolumes( G4tgrUtils::GetString( wl[1] ), 1 );
00282     for( size_t ii = 0; ii < vols.size(); ii++ )
00283     {
00284       vols[ii]->AddVisibility( wl );
00285     }
00286 
00287     //--------------------------------- colour
00288   }
00289   else if( (wl0 == ":COLOUR") || (wl0 == ":COLOR") )
00290   {
00291     std::vector<G4tgrVolume*> vols =
00292        volmgr->FindVolumes( G4tgrUtils::GetString( wl[1] ), 1 );
00293     for( size_t ii = 0; ii < vols.size(); ii++ )
00294     {
00295       vols[ii]->AddRGBColour( wl );
00296     }
00297 
00298     //--------------------------------- check overlaps
00299   }
00300   else if( wl0 == ":CHECK_OVERLAPS" )
00301   {
00302     std::vector<G4tgrVolume*> vols =
00303        volmgr->FindVolumes( G4tgrUtils::GetString( wl[1] ), 1 );
00304     for( size_t ii = 0; ii < vols.size(); ii++ )
00305     {
00306       vols[ii]->AddCheckOverlaps( wl );
00307     }
00308     //--------------------------------- ERROR
00309   }
00310   else
00311   {
00312     return 0;
00313   } 
00314 
00315   return 1;
00316 }
00317 
00318 
00319 //---------------------------------------------------------------
00320 G4tgrVolume* G4tgrLineProcessor::FindVolume( const G4String& volname )
00321 {
00322   G4tgrVolume* vol = volmgr->FindVolume( volname, 1);
00323 
00324   if( vol->GetType() == "VOLDivision" )
00325   {
00326     G4Exception("G4tgrLineProcessor::FindVolume()",
00327                 "InvalidSetup", FatalException,
00328                 "Using 'PLACE' for a volume created by a division !");
00329   }
00330 
00331   return vol;
00332 }

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