G4ErrorRunManagerHelper.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 // $Id: G4ErrorRunManagerHelper.cc 69766 2013-05-14 14:33:55Z gcosmo $
00027 //
00028 // ------------------------------------------------------------
00029 //      GEANT 4 class implementation file 
00030 // ------------------------------------------------------------
00031 //
00032 
00033 #include "G4Navigator.hh"
00034 
00035 #include "G4Timer.hh"
00036 
00037 #include "G4ErrorRunManagerHelper.hh"
00038 
00039 #include "G4RunManagerKernel.hh"
00040 #include "G4VUserDetectorConstruction.hh"
00041 #include "G4ErrorPhysicsList.hh"
00042 #include "G4TransportationManager.hh"
00043 #include "G4RunManager.hh"
00044 
00045 //-----------------------------------------------------------------------
00046 
00047 G4ErrorRunManagerHelper* G4ErrorRunManagerHelper::fRunManagerKernel = 0;
00048 
00049 //-----------------------------------------------------------------------
00050 G4ErrorRunManagerHelper* G4ErrorRunManagerHelper::GetRunManagerKernel()
00051 { return fRunManagerKernel; }
00052 
00053 
00054 //-----------------------------------------------------------------------
00055 G4ErrorRunManagerHelper::G4ErrorRunManagerHelper()
00056 {
00057   if(fRunManagerKernel) {
00058     G4Exception("G4ErrorRunManagerHelper::G4ErrorRunManagerHelper()",
00059                 "InvalidSetup", FatalException,
00060                 "G4eRunManageKernel constructed twice.");
00061   }
00062   fRunManagerKernel = this;
00063 
00064   //----- Look if somebody has created a G4RunManagerKernel
00065   theG4RunManagerKernel = G4RunManagerKernel::GetRunManagerKernel();
00066   if( theG4RunManagerKernel == 0 ) {
00067     //--- if not create it
00068     theG4RunManagerKernel = new G4RunManagerKernel();
00069     G4cout << " creating G4RunManagerKernel " <<  theG4RunManagerKernel << G4endl;
00070   }
00071     
00072   theG4RunManagerKernel->SetVerboseLevel(2);
00073   theUserPhysicsList = 0;
00074   theUserWorld = 0;
00075 
00076 }
00077 
00078 
00079 //-----------------------------------------------------------------------
00080 G4ErrorRunManagerHelper::~G4ErrorRunManagerHelper()
00081 {
00082 }
00083 
00084 
00085 //-----------------------------------------------------------------------
00086 void G4ErrorRunManagerHelper::SetUserInitialization(G4VUserDetectorConstruction* userInit)
00087 { 
00088   theUserWorld = userInit->Construct();
00089 }
00090 
00091 
00092 //-----------------------------------------------------------------------
00093 void G4ErrorRunManagerHelper::SetUserInitialization(G4VPhysicalVolume* userInit)
00094 {
00095   theUserWorld = userInit;
00096 }
00097 
00098 
00099 //-----------------------------------------------------------------------
00100 void G4ErrorRunManagerHelper::SetUserInitialization(G4VUserPhysicsList* userInit)
00101 {
00102   theUserPhysicsList = userInit;
00103 }
00104 
00105 
00106 //-----------------------------------------------------------------------
00107 void G4ErrorRunManagerHelper::InitializeGeometry()
00108 {
00109   //check if user world has been directly called or someone initialized the world volume already 
00110   //----- First option: geometry has been defined to GEANT4e 
00111   if( theUserWorld != 0 ) {
00112     theG4RunManagerKernel->DefineWorldVolume( theUserWorld );
00113     
00114     //----- Second option: geometry has been defined to GEANT4, do nothing GEANT4 should take care 
00115   } else {
00116     //  G4cerr << "G4 TM " << G4TransportationManager::GetTransportationManager() 
00117     //      << " NAV " << G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking() 
00118     //      << " WORLD " << G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume() << G4endl;
00119     //--- Check that indeed geometry has been defined to GEANT4
00120     if ( G4TransportationManager::GetTransportationManager()
00121          ->GetNavigatorForTracking()->GetWorldVolume() == 0 ) {
00122       G4Exception("G4ErrorRunManagerHelper::InitializeGeometry()",
00123                   "InvalisSetup", FatalException,
00124                   "No world defined in your geometry!" );
00125     }
00126     
00127   }
00128 }
00129 
00130 
00131 //-----------------------------------------------------------------------
00132 void G4ErrorRunManagerHelper::InitializePhysics()
00133 {
00134 
00135   G4cout << "  G4ErrorRunManagerHelper::InitializePhysics "  << G4endl;
00136 
00137   //----- First option: physics list has been defined to GEANT4e 
00138   if( theUserPhysicsList != 0 ) {
00139     theG4RunManagerKernel->SetPhysics(theUserPhysicsList);
00140     theG4RunManagerKernel->InitializePhysics();
00141   }else {
00142   //----- Second option: physics list has been defined to GEANT4, do nothing GEANT4 should take care 
00143     if( G4RunManager::GetRunManager() != 0 && G4RunManager::GetRunManager()->GetUserPhysicsList() != 0 ){ 
00144       //--- Physics should be G4ErrorPhysicsList, else send a warning
00145       if( static_cast<const G4ErrorPhysicsList*>(G4RunManager::GetRunManager()->GetUserPhysicsList()) == 0 ) {
00146         G4cerr << " WARNING G4ErrorRunManagerHelper::InitializePhysics() physics list is not G4ErrorPhysicsList. Are you sure? " << G4endl;
00147       }
00148     } else {
00149       //----- Third option: no physics list has been defined, define a G4ErrorPhysicsList
00150       theG4RunManagerKernel->SetPhysics(new G4ErrorPhysicsList);
00151       //    theG4RunManagerKernel->SetPhysics(new ExN02PhysicsList);
00152       theG4RunManagerKernel->InitializePhysics();
00153     }
00154   }
00155  
00156 }
00157 
00158 
00159 //-----------------------------------------------------------------------
00160 void G4ErrorRunManagerHelper::RunInitialization()
00161 {
00162   theG4RunManagerKernel->RunInitialization();
00163 }
00164 
00165 
00166 //-----------------------------------------------------------------------
00167 void G4ErrorRunManagerHelper::SetUserAction(G4UserTrackingAction* userAction)
00168 {
00169 
00170   G4EventManager::GetEventManager()->SetUserAction( userAction );
00171 }
00172 
00173 
00174 //-----------------------------------------------------------------------
00175 void G4ErrorRunManagerHelper::SetUserAction(G4UserSteppingAction* userAction)
00176 {
00177   G4EventManager::GetEventManager()->SetUserAction( userAction );
00178 }
00179 
00180 
00181 //-----------------------------------------------------------------------
00182 void G4ErrorRunManagerHelper::RunTermination()
00183 {
00184   theG4RunManagerKernel->RunTermination();
00185 }
00186 

Generated on Mon May 27 17:48:11 2013 for Geant4 by  doxygen 1.4.7