slic/src
diff -u -r1.61 -r1.62
--- G4Application.cc 19 Dec 2005 23:53:31 -0000 1.61
+++ G4Application.cc 20 Dec 2005 01:23:25 -0000 1.62
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/G4Application.cc,v 1.61 2005/12/19 23:53:31 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/G4Application.cc,v 1.62 2005/12/20 01:23:25 jeremy Exp $
#include "G4Application.hh"
// slic
@@ -21,9 +21,6 @@
#include "EventDebugger.hh"
#include "TrajectoryManager.hh"
-#include "PhysicsListFactory.hh"
-#include "LHEP.hh"
-
// lcdd
#include "LCDDParser.hh"
@@ -47,6 +44,7 @@
#endif
#endif // G4UI_NONE
+// std
#include <stdexcept>
using std::cerr;
@@ -66,39 +64,32 @@
m_setRunAbort(false),
m_isInitialized(false)
{
- // set app instance var
+ /* Set the G4Application instance variable. */
if ( 0 != m_instance ) {
G4Exception("G4Application constructed twice.");
}
m_instance = this;
- // init app messenger
+ /* Initialize the application messenger. */
m_appMessenger = new G4ApplicationMessenger(this);
- // init field messenger
- m_fieldMessenger = new FieldMessenger();
-
- // init log manager
+ /* Initialize the log manager. */
LogManager::instance();
- // init physics manager
- PhysicsListManager::instance();
-
- // init cmd manager
+ /* Initialize the command manager for handling command-line arguments. */
CmdManager::instance();
- // init event gen manager
+ /* Initialize the event generation manager. */
EventSourceManager::instance();
- registerCmdLineOpts();
-
- /* Setup the Geant4 command queue from the CL args. */
+ /* Setup the queue of Geant4 commands from the command-line arguments. */
setupFromCommandLine(argc, argv);
}
- /* FIXME: Are all deletions being done here??? */
G4Application::~G4Application()
{
+ /* FIXME: The ModuleManager should be handling these deletions. */
+
#ifdef G4VIS_USE
if ( sVisManager != 0 ) {
delete sVisManager;
@@ -143,18 +134,25 @@
void G4Application::setupFromCommandLine(int argc, char** argv)
{
+ /*
+ * Register the mappings of command line options to Geant4 commands
+ * with the CmdManager.
+ */
+ registerCmdLineOpts();
+
+ /* Get the command manager. */
CmdManager* mgr = CmdManager::instance();
- // tokenize args into std::string vector stored in command mgr
+ /* Tokenize the command line arguments. */
if ( argc > 1 ) {
mgr->fillCmdArgs( argc, argv );
}
- // didn't get any arguments, so just print usage
+ /* Did not get any arguments, so print usage. */
else {
mgr->getG4CmdQueue()->addCmd("/slic/usage");
}
- // make a queue of G4 commands to execute
+ /* Create a queue of G4 commands from the command-line arguments. */
mgr->fillG4CmdQueue();
}
@@ -168,26 +166,46 @@
std::cout << "SLIC verbose system is disabled." << std::endl;
#endif
- // create new Geant4 RunManager
+ /* Create a new RunManager. */
m_runManager = new RunManager();
- // DEBUG - setup a dummy physics list
- m_runManager->SetUserInitialization( PhysicsListFactory::create( "LHEP" ) );
+ /* Initialize the physics list manager. */
+ PhysicsListManager::instance();
- // DEBUG - setup the default event source after physics
+ /* Setup the default event source AFTER PHYSICS. */
EventSourceManager::instance()->setupEventSource();
- // print app splash screen
+ /* Print the SLIC splash screen. */
printSplashScreen( cout );
- // default user setups: DetConst, PrimGenAction, PhysicsList
- initializeDefaultSetup();
+ /* Initialize the LcioManager. */
+ LcioManager::instance();
+
+ /* Initialize the EventDebugger. */
+ EventDebugger::instance();
+
+ /* Initialize the magnetic field messenger. */
+ m_fieldMessenger = new FieldMessenger();
+
+ /* Construct and register the UserAction classes. */
+ setupUserActions();
+
+ /* Initialize visualization. */
+#ifdef G4VIS_USE
+ initializeVis();
+#endif
+
+ /* Initialize the UI. */
+#ifndef G4UI_NONE
+ initializeUI();
+#endif
/* Print list of registered modules. */
#ifdef SLIC_VERBOSE
ModuleRegistry::instance()->print(cout);
#endif
+ /* Set state variable. */
m_isInitialized = true;
}
else {
@@ -198,28 +216,29 @@
#ifndef G4UI_NONE
void G4Application::initializeUI()
{
- // tcsh setup
+ /* Use tcsh terminal. */
#ifdef G4UI_USE_TCSH
m_session = new G4UIterminal(new G4UItcsh);
- // csh setup
+ /* Use csh terminal. */
#elif G4UI_USE_CSH
m_session = new G4UIterminal(new G4UIcsh);
- // Gag setup
+ /* Use GAG. */
#elif G4UI_USE_GAG
session = new G4UIGAG;
- // Motif setup
+ /* Use Motif. */
#elif G4UI_USE_XM
m_session = new G4UIXm( 0, NULL );
- // add file and exit buttons
+ /* Add file and exit buttons to Motif UI. */
if ( m_session ) {
G4UImanager* ui = G4UImanager::GetUIpointer();
ui->ApplyCommand("/gui/addMenu file File");
ui->ApplyCommand("/gui/addButton file Exit \"exit\"");
}
+ /* Use a plain terminal. */
#else
m_session = new G4UIterminal();
#endif
@@ -227,9 +246,6 @@
if ( !m_session ) {
G4Exception( "Failed to initialize UI session." );
}
-
- // start the session
- m_session->SessionStart();
}
#endif
@@ -241,42 +257,24 @@
}
#endif
- void G4Application::initializeRunManager()
- {
- if ( m_runManager ) {
- m_runManager->Initialize();
- }
- }
-
- void G4Application::initializeDefaultSetup()
+ void G4Application::setupUserActions()
{
if ( m_runManager != 0 ) {
- // make sure LcioManager gets setup
- LcioManager::instance();
-
- // make sure EventDebugger gets setup
- EventDebugger::instance();
-
- // visualization
-#ifdef G4VIS_USE
- initializeVis();
-#endif
-
- // primary generator
+ /* Primary generator. */
m_runManager->SetUserAction(new PrimaryGeneratorAction);
- // geometry system
+ /* LCDD geometry subsystem. */
m_runManager->SetUserInitialization(new LCDDDetectorConstruction);
- // user action handlers
+ /* SLIC's UserAction handlers. */
m_runManager->SetUserAction(new RunAction);
m_runManager->SetUserAction(new EventAction);
m_runManager->SetUserAction(new TrackingAction);
m_runManager->SetUserAction(new SteppingAction);
}
else {
- G4Exception("G4Application::initializeDefaultSetup() - RunManager is NULL!");
+ G4Exception("G4Application::setupUserActions() - RunManager is NULL!");
}
}
@@ -300,19 +298,19 @@
if (!m_isInitialized) {
initialize();
}
-
- // exec cmd queue
cout << endl;
+
+ /* Execute the current queue of Geant4 commands. */
CmdManager::instance()->execCurrG4CmdQueue(true);
- // init UI and start session if interactive mode and not G4UI_NONE
+ /* Start the UI session if in interactive mode. */
#ifndef G4UI_NONE
if ( getMode() == eInteractive ) {
- initializeUI();
+ m_session->SessionStart();
}
#endif
- // return code = okay
+ /* Set the application return code. */
setReturnCode(0);
}
@@ -379,7 +377,7 @@
{
CmdManager* cmd_mgr = CmdManager::instance();
- // usage
+ /* Print application usage. */
CmdLineOpt* cmd_usage = new CmdLineOpt("h",
"help",
"Print SLIC usage.",
@@ -387,7 +385,7 @@
0);
cmd_mgr->addCmd(cmd_usage, "/slic/usage" );
- // interactive mode
+ /* Run in interactive mode. */
CmdLineOpt* cmd_iact = new CmdLineOpt("n",
"interactive",
"Start a Geant4 interactive session.",
@@ -395,7 +393,7 @@
0);
cmd_mgr->addCmd(cmd_iact, "/control/interactive");
- // print SLIC version info
+ /* Print SLIC version info. */
CmdLineOpt* cmd_version = new CmdLineOpt("v",
"version",
"Print SLIC version.",
@@ -403,7 +401,7 @@
0);
cmd_mgr->addCmd(cmd_version, "/slic/version");
- // exec macro
+ /* Execute the commands found in a macro file. */
CmdLineOpt* cmd_exec = new CmdLineOpt("m",
"macro",
"Execute Geant4 commands from a file.",
@@ -411,7 +409,7 @@
1);
cmd_mgr->addCmd(cmd_exec, "/control/execute" );
- // set LCDD URI
+ /* Set the URL of the input LCDD file. */
CmdLineOpt* cmd_lcddURL = new CmdLineOpt("g",
"lcdd-url",
"Set LCDD geometry file URL.",
@@ -419,7 +417,7 @@
1);
cmd_mgr->addCmd(cmd_lcddURL, "/lcdd/url" );
- // set the generator input file
+ /* Set the path to a generator file, e.g. StdHep or LCIO. */
CmdLineOpt* cmd_stdhep = new CmdLineOpt("i",
"event-file",
"Set event input file full path.",
@@ -428,7 +426,7 @@
cmd_mgr->addCmd(cmd_stdhep, "/generator/filename" );
- // set name of LCIO output file
+ /* Set the name of the LCIO output file. */
CmdLineOpt* cmd_lcio = new CmdLineOpt("o",
"lcio-file",
"Set name of LCIO output file.",
@@ -436,7 +434,7 @@
1);
cmd_mgr->addCmd(cmd_lcio, "/lcio/filename" );
- // set Lcio path
+ /* Set the path of output files. */
CmdLineOpt* cmd_lcio_path = new CmdLineOpt("p",
"lcio-path",
"Set directory for LCIO output.",
@@ -446,9 +444,8 @@
/*
* Automatically name the LCIO output file.
- *
- * Customization is supported, as long as
- * spaces are escaped.
+ * Customization syntax is supported, as long
+ * as spaces are escaped.
*/
CmdLineOpt* cmd_autoname = new CmdLineOpt("O",
"autoname",
@@ -457,7 +454,7 @@
1);
cmd_mgr->addCmd(cmd_autoname, "/lcio/autoname" );
- // overwrite an LCIO output file if it exists already
+ /* Overwrite an existing LCIO output file. */
CmdLineOpt* delLcio = new CmdLineOpt("x",
"lcio-delete",
"Delete an existing LCIO file.",
@@ -465,7 +462,7 @@
0);
cmd_mgr->addCmd(delLcio, "/lcio/fileExists delete");
- // beamOn
+ /* Do BeamOn. */
CmdLineOpt* cmd_beamon = new CmdLineOpt("r",
"run-events",
"Run # of events.",
@@ -473,7 +470,7 @@
1);
cmd_mgr->addCmd(cmd_beamon, "/run/beamOn");
- // set num input events to skip
+ /* Set number of events to skip in file-based source. */
CmdLineOpt* cmd_skip_evt = new CmdLineOpt("s",
"skip-events",
"Set number of events to skip.",
@@ -481,7 +478,7 @@
1);
cmd_mgr->addCmd(cmd_skip_evt, "/generator/skipEvents" );
- // set G4 physics list
+ /* Set the physics list. */
CmdLineOpt* cmd_phys = new CmdLineOpt("l",
"physics-list",
"Set G4 physics list.",
@@ -489,7 +486,7 @@
1);
cmd_mgr->addCmd(cmd_phys, "/physics/select");
- // logfile
+ /* Set the name of the log file. */
CmdLineOpt* cmd_log = new CmdLineOpt("L",
"log-file",
"Set logfile name.",
@@ -497,7 +494,7 @@
0);
cmd_mgr->addCmd(cmd_log, "/log/filename");
- // random seed
+ /* Seed the random engine. */
CmdLineOpt* rndSeed = new CmdLineOpt("d",
"seed",
"Set the random seed. (No argument seeds with time.)",