// comet-mc // // $Id: SimG4.cc,v 1.29 2009/08/31 20:07:07 mcgrew Exp $ #include #include #include #include #include "ICOMETLog.hxx" #include "G4RunManager.hh" #include "G4UImanager.hh" #include "G4UIterminal.hh" #include "G4UIcsh.hh" #include #include "COMETCreateRunManager.hh" #include "COMETPersistencyManager.hh" #include "COMETRootPersistencyManager.hh" //#include "COMETUIShell.hh" #include "COMETPhysicsList.hh" #ifdef G4VIS_USE #include #endif void Run(bool force_interactive,bool force_terminal, std::string execute_files, int argc, char** argv){ G4UIsession* session=NULL; G4UIExecutive* exec=NULL; if ( !force_interactive && argc > 0) { COMETLog("Using batch mode"); for(int i= 0; iGetSession(); // check we're valid; if(!session){ COMETError("No valid session type specified or requested type is not installed."); return; } // non-gui sessions don't automatically run the provided macros so we need // to force this if(!exec->IsGUI() ){ for(int i= 0; i>file){ UI->ApplyCommand(("/control/execute "+file).c_str()); } } // Run the session if we're interactive if(session){ session->SessionStart(); delete exec; } } void Usage(const char* program){ std::cout<<"usage: "< Profile event simulation every n_events for memory and speed. Default is off (n_events = 0).\n" " Profiling persisted to oaEvent file.\n" " -o Set the output filename. Overrides /db/open macro commands.\n" " -t Force use of a command-line style UI, over-riding any available GUI (if they've been installed).\n" " -i Force an interactive session even when macro files are provided. If they are provided, run them\n" " first and then return to an interactive command-prompt.\n" " -e Provide a macro file to be executed, before entering a UI\n" " -l Specify the hadronic physics model\n"; COMETPhysicsList::PrintAvailableHadronPhysicsLists(" "); } int main(int argc,char** argv) { G4String outputFilename; G4String physicsList = "QGSP_BERT_HP"; // Default G4int errflg = 0; G4int c = 0; G4bool force_terminal=false; G4bool force_interactive=false; G4int profile=0; G4String arg; char *endptr; std::string execute_files; while (!errflg && ((c=getopt(argc,argv,"k:e:gl:p:o:tinh?")) != -1)) { switch (c) { case 'g': physicsList = COMETPhysicsList::PListNameForGeomTest(); break; case 'l': // Option -g is prioritised. if(physicsList != COMETPhysicsList::PListNameForGeomTest()) physicsList = optarg; break; case 'p': profile = strtol(optarg, &endptr, 10); if (!optarg || *endptr) { G4cout << "Please enter a valid integer for event profiling" " rate" << G4endl; ++errflg; }; break; case 'o': outputFilename = optarg; break; case 't': // Don't use a tcsh-style command line interface force_terminal=true; break; case 'i': // make sure we use a command-line prompt (don't try to make a gui) force_interactive=true; break; case 'e': execute_files+=optarg; execute_files+=" "; break; default: errflg++; G4cout << "Option not implemented" << G4endl; case 'h': case '?': Usage(argv[0]); return 0; } } if(errflg) { Usage(argv[0]); return 1; } COMET::ICOMETLog::SetLogStream(&G4cout); COMET::ICOMETLog::SetDebugStream(&G4cerr); COMET::ICOMETLog::Configure(); // Set the mandatory initialization classes // Construct the default run manager G4RunManager* runManager = COMETCreateRunManager(physicsList, profile); #ifdef G4VIS_USE // Visualization. G4VisManager* visManager = new G4VisExecutive; visManager->Initialize(); #endif // Create the persistency manager. COMETPersistencyManager* persistencyManager = COMETRootPersistencyManager::GetInstance(); // Get the pointer to the UI manager G4UImanager* UI = G4UImanager::GetUIpointer(); // Set the defaults for the simulation. UI->ApplyCommand("/comet/conditions SimG4-defaults 1.0"); if (persistencyManager && outputFilename != "") { G4String command = "/db/open "; UI->ApplyCommand(command+outputFilename); } std::signal(SIGILL, SIG_DFL); std::signal(SIGBUS, SIG_DFL); std::signal(SIGSEGV, SIG_DFL); // Process requested macro or if none, open an interactive session Run(force_interactive,force_terminal, execute_files, argc-optind, argv+optind); // job termination #ifdef G4VIS_USE delete visManager; #endif if (persistencyManager) { persistencyManager->Close(); delete persistencyManager; } delete runManager; return 0; }