src/BDSRunManager.cc

00001 /* BDSIM code.    Version 1.0
00002    Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    Last modified 24.7.2002
00004    Copyright (c) 2002 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 */
00006 // G.A.Blair, Royal Holloway Univ of London. 1.07.02
00007 // This class alters one part of the default G4RunManager to
00008 // avoid closing the geometry after each event - this was a significant
00009 // time overhead. 
00010 // >>>Whether there are other effects of this needs to be checked <<<
00011 //
00012 // SPM: Altered BeamOn function to account for Placet synchronisation
00013 //
00014 
00015 #include "BDSGlobalConstants.hh"
00016 #include "BDSExecOptions.hh"
00017 #include "G4Timer.hh"
00018 #include "CLHEP/Random/Random.h"
00019 
00020 #include "BDSRunManager.hh"
00021 #include "G4StateManager.hh"
00022 #include "G4UImanager.hh"
00023 
00024 #include "BDSDump.hh"
00025 #include "BDSWorld.hh"
00026 
00027 BDSRunManager* BDSRunManager::fRunManager = 0;
00028 
00029 BDSRunManager* BDSRunManager::GetRunManager() { 
00030   return fRunManager; 
00031 }
00032 
00033 BDSRunManager::BDSRunManager() { 
00034   fRunManager = this;
00035   nptwiss     = BDSExecOptions::Instance()->GetNPTwiss();
00036 }
00037 
00038 BDSRunManager::~BDSRunManager(){
00039 }
00040 
00041 void BDSRunManager::BeamOn(G4int n_event,const char* macroFile,G4int n_select)
00042 {
00043   // Print seed to try and recreate an event in a run
00044   G4cout << __METHOD_NAME__ << "> Random number generator's seed=" 
00045          << CLHEP::HepRandom::getTheSeed() << G4endl;
00046   // Print generator full state to output 
00047   G4cout << __METHOD_NAME__ << "Random number generator's state: " << G4endl;
00048   CLHEP::HepRandom::saveFullState(G4cout);
00049 
00050   G4bool cond = ConfirmBeamOnCondition();
00051   G4StackManager* SM;
00052   SM = G4EventManager::GetEventManager()->GetStackManager();
00053   SM->SetNumberOfAdditionalWaitingStacks(4);
00054   if(cond)
00055   {
00056     numberOfEventToBeProcessed = n_event;
00057     RunInitialization();
00058 
00059     if(BDSDump::GetNumberOfDumps()!=0){
00060       // Run reference bunch for dumps
00061       BDSGlobalConstants::Instance()->isReference=true;
00062       DoEventLoop(nptwiss,macroFile,0);
00063       BDSGlobalConstants::Instance()->isReference=false;
00064     }
00065 
00066     if(n_event>0) DoEventLoop(n_event,macroFile,n_select);
00067     RunTermination();
00068     while(!BDSGlobalConstants::Instance()->holdingQueue.empty()){
00069       BDSGlobalConstants::Instance()->setReadFromStack(true);
00070       SM->ClearPostponeStack();
00071 
00072       RunInitialization();
00073 //      DoEventLoop(n_event,macroFile,n_select);
00074       DoEventLoop(BDSGlobalConstants::Instance()->holdingQueue.size(),macroFile,n_select);
00075       RunTermination();
00076 
00077       BDSGlobalConstants::Instance()->setReadFromStack(false);
00078     }
00079     BDSGlobalConstants::Instance()->referenceQueue.clear();
00080   }
00081 }
00082 
00083 void BDSRunManager::DoEventLoop(G4int n_event,const char* macroFile,G4int n_select)
00084 {
00085   // Print seed to try and recreate an event in a run 
00086   G4cout << __METHOD_NAME__ << "Random number generator's seed=" 
00087          << CLHEP::HepRandom::getTheSeed() << G4endl;
00088 
00089  //G4StateManager* stateManager = G4StateManager::GetStateManager();
00090 
00091   if(verboseLevel>0) 
00092   { timer->Start(); }
00093 
00094   G4String msg;
00095   if(macroFile!=0)
00096   { 
00097     if(n_select<0) n_select = n_event;
00098     msg = "/control/execute ";
00099     msg += macroFile;
00100   }
00101   else
00102   { n_select = -1; }
00103 
00104   G4int i_event;
00105   for( i_event=0; i_event<n_event; i_event++ )
00106   {
00107     G4cout << __METHOD_NAME__ << "event="<<i_event<<G4endl;
00108 
00109     // Print seed to try and recreate an event in a run
00110     G4cout << __METHOD_NAME__ << "Random number generator's seed=" 
00111            << CLHEP::HepRandom::getTheSeed() << G4endl;
00112     // Print generator full state to output 
00113     G4cout << __METHOD_NAME__ << "Random number generator's state: " << G4endl;
00114     CLHEP::HepRandom::saveFullState(G4cout);
00115     G4cout.flush();
00116 
00117     //    stateManager->SetNewState(EventProc);
00118 
00119     currentEvent = GenerateEvent(i_event);
00120 
00121     if(currentEvent == NULL) G4cerr<<__FILE__<<" : "<<__LINE__<<"Event generation failed "<<G4endl;
00122 
00123     eventManager->ProcessOneEvent(currentEvent);
00124 
00125     AnalyzeEvent(currentEvent);
00126 
00127     //    if(i_event<n_select) G4UImanager::GetUIpointer()->ApplyCommand(msg);
00128 
00129     // gab: the following commented out - this is the only
00130     // difference between this and the normal G4 class
00131     // (significant time saving...)
00132     //stateManager->SetNewState(GeomClosed);
00133 
00134     StackPreviousEvent(currentEvent);
00135     currentEvent = 0;
00136     if(runAborted) break;
00137   }
00138 
00139   if(verboseLevel>0)
00140   {
00141     timer->Stop();
00142     G4cout << "Run terminated." << G4endl;
00143     G4cout << "Run Summary" << G4endl;
00144     if(runAborted)
00145     { G4cout << "  Run Aborted after " << i_event << " events processed." << G4endl; }
00146     else
00147     { G4cout << "  Number of events processed : " << n_event << G4endl; }
00148     G4cout << "  "  << *timer << G4endl;
00149   }
00150 }
00151 
00152 

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7